Skip to content

Commit

Permalink
Updated to Bevy 0.11 (#29)
Browse files Browse the repository at this point in the history
Updated to Bevy 0.11
  • Loading branch information
Cyannide authored Aug 5, 2023
1 parent f3d18c0 commit 5ad8ac7
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_text_mesh"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
description = "A bevy 3D text mesh generator for displaying text"
repository = "https://github.com/blaind/bevy_text_mesh"
Expand All @@ -16,15 +16,15 @@ anyhow = "1.0"
glyph_brush_layout = "0.2.3"

[dependencies.bevy]
version = "0.10.0"
version = "0.11.0"
default-features = false
features = ["bevy_render", "bevy_text", "bevy_pbr", "bevy_asset", "bevy_sprite"]

[dev-dependencies]
rand = "0.8.4"

[dev-dependencies.bevy]
version = "0.10.0"
version = "0.11.0"
default-features = false
features = [
"bevy_winit",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Consider this as a preview of the plugin for gathering feedback about the API:

| bevy | bevy_text_mesh |
| ---- | -------------- |
| 0.11 | 0.7.0 |
| 0.10 | 0.6.0 |
| 0.9 | 0.5.0 |
| 0.8 | 0.4.0 |
Expand Down Expand Up @@ -60,7 +61,7 @@ Add to Cargo.toml:

```
[dependencies]
bevy_text_mesh = "0.6.0"
bevy_text_mesh = "0.7.0"
```

Include the library:
Expand Down
4 changes: 2 additions & 2 deletions examples/2d_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(animate_rotation)
.add_systems(Startup, setup)
.add_systems(Update, animate_rotation)
.run();
}

Expand Down
24 changes: 18 additions & 6 deletions examples/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ use bevy_text_mesh::prelude::*;
fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugin(TextMeshPlugin)
.add_startup_system(setup)
.add_startup_system(setup_text_mesh)
.add_system(update_text_mesh)
.add_system(rotate_camera)
.add_plugins(
(
DefaultPlugins,
TextMeshPlugin,
)
)
.add_systems(Startup,
(
setup,
setup_text_mesh.after(setup),
)
)
.add_systems(Update,
(
update_text_mesh,
rotate_camera,
)
)
.run();
}

Expand Down
42 changes: 26 additions & 16 deletions examples/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use bevy::{
diagnostic::{
Diagnostic, DiagnosticId, Diagnostics, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin,
Diagnostic, DiagnosticId, Diagnostics, DiagnosticsStore, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin, RegisterDiagnostic
},
prelude::*,
render::camera::Camera,
Expand All @@ -28,16 +28,29 @@ const INITIAL_WAIT_MS: u64 = 500;
fn main() {
App::new()
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugin(TextMeshPlugin)
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_startup_system(setup)
.add_startup_system(setup_text_mesh)
.add_system(spawn_meshes)
.add_system(update_text_mesh)
.add_system(rotate_camera)
.add_system(update_frame_rate.in_base_set(CoreSet::PostUpdate))
.add_plugins((
DefaultPlugins,
TextMeshPlugin,
FrameTimeDiagnosticsPlugin::default(),
LogDiagnosticsPlugin::default(),
))
.register_diagnostic(
Diagnostic::new(TEXT_MESH_UPDATES, "text_mesh_updates", 20)
)
.add_systems(Startup,
(
setup,
setup_text_mesh,
)
)
.add_systems(Update,
(
spawn_meshes,
update_text_mesh,
rotate_camera,
)
)
.add_systems(PostUpdate, update_frame_rate)
.run();
}

Expand Down Expand Up @@ -69,13 +82,10 @@ pub const TEXT_MESH_UPDATES: DiagnosticId =
DiagnosticId::from_u128(1082410928401928501928509128509125);

fn setup_text_mesh(
mut diagnostics: ResMut<Diagnostics>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
diagnostics.add(Diagnostic::new(TEXT_MESH_UPDATES, "text_mesh_updates", 20));

let state = SceneState {
font: asset_server.load("fonts/FiraMono-Medium.ttf#mesh"),
text_count: 0,
Expand Down Expand Up @@ -187,7 +197,7 @@ fn spawn_meshes(
}

fn update_text_mesh(
mut diagnostics: ResMut<Diagnostics>,
mut diagnostics: Diagnostics,
mut text_meshes: Query<&mut TextMesh, With<EngineTime>>,
time: Res<Time>,
mut timer: ResMut<UpdateTimer>,
Expand Down Expand Up @@ -226,7 +236,7 @@ fn rotate_camera(mut camera: Query<&mut Transform, With<Camera>>, time: Res<Time
}

fn update_frame_rate(
diagnostics: Res<Diagnostics>,
diagnostics: Res<DiagnosticsStore>,
time: Res<Time>,
mut timer: ResMut<UpdateTimer>,
mut fps_text: Query<(Entity, &mut TextMesh, Option<&FPS>), Or<(With<FPS>, With<TextCount>)>>,
Expand Down
4 changes: 2 additions & 2 deletions src/font_loader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use bevy::asset::{AssetLoader, BoxedFuture, LoadContext, LoadedAsset};
use bevy::reflect::TypeUuid;
use bevy::reflect::{TypePath, TypeUuid};
use bevy::text::Font;

#[derive(Default)]
Expand Down Expand Up @@ -33,7 +33,7 @@ impl AssetLoader for FontLoader {
}
}

#[derive(TypeUuid)]
#[derive(TypeUuid, TypePath)]
#[uuid = "5415ac03-d009-471e-89ab-dc0d4e31a8c4"]
pub struct TextMeshFont {
pub(crate) ttf_font: ttf2mesh::TTFFile,
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ pub struct TextMeshPlugin;
impl Plugin for TextMeshPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<font_loader::TextMeshFont>()
.add_system(mesh_system::text_mesh)
.add_system(mesh_system::font_loaded)
.add_systems(Update,
(
mesh_system::text_mesh,
mesh_system::font_loaded,
)
)
.insert_resource(MeshCache::default())
.init_asset_loader::<font_loader::FontLoader>();
}
Expand Down
4 changes: 4 additions & 0 deletions src/mesh_data_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub(crate) fn generate_text_mesh(
if char == ' ' {
scaled_offset.x += 0.2 * scalar + spacing.x;
continue;
} else if char == '\n' {
scaled_offset.x = 0.;
scaled_offset.y -= scaled_row_y_max_height + spacing.y;
continue;
}

let key = CacheKey::new_3d(char, depth);
Expand Down

0 comments on commit 5ad8ac7

Please sign in to comment.