diff --git a/Cargo.toml b/Cargo.toml index 325172c..da7743b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,11 @@ exclude = [ "images", "assets" ] smallvec = "1.11.0" bitflags = "2.3" +# see bevy #16563 +bevy_internal = { version = "0.15", features = ["bevy_image"] } + [dependencies.bevy] -version = "0.14" +version = "0.15" default-features = false features = [ "bevy_core_pipeline", @@ -34,4 +37,4 @@ features = [ ] [dev-dependencies] -bevy = "0.14" +bevy = "0.15" diff --git a/README.md b/README.md index 5f4dc24..6d744a0 100644 --- a/README.md +++ b/README.md @@ -40,39 +40,31 @@ App::new() Text: ```rs -commands.spawn(BillboardTextBundle { - transform: Transform::from_translation(Vec3::new(0., 2., 0.)) - .with_scale(Vec3::splat(0.0085)), - text: Text::from_sections([ - TextSection { - value: "IMPORTANT".to_string(), - style: TextStyle { - font_size: 60.0, - font: fira_sans_regular_handle.clone(), - color: Color::ORANGE, - } - }, - TextSection { - value: " text".to_string(), - style: TextStyle { - font_size: 60.0, - font: fira_sans_regular_handle.clone(), - color: Color::WHITE, - } - } - ]).with_alignment(TextAlignment::CENTER), - ..default() -}); +commands + .spawn(( + BillboardText::default(), + TextLayout::new_with_justify(JustifyText::Center), + Transform::from_scale(Vec3::splat(0.0085)), + )) + .with_child(( + TextSpan::new("IMPORTANT"), + TextFont::from_font(fira_sans_regular_handle.clone()).with_font_size(60.0), + TextColor::from(Color::Srgba(palettes::css::ORANGE)), + )) + .with_child(( + TextSpan::new(" text"), + TextFont::from_font(fira_sans_regular_handle.clone()).with_font_size(60.0), + TextColor::from(Color::WHITE), + )); ``` Texture: ```rs -commands.spawn(BillboardTextureBundle { - transform: Transform::from_translation(Vec3::new(0., 5., 0.)), - texture: BillboardTextureHandle(handle.clone()), - mesh: BillboardMeshHandle(meshes.add(Quad::new(Vec2::new(4.0, 4.0)).into()).into()), - ..default() -}); +commands.spawn(( + BillboardTexture(image_handle.clone()), + BillboardMesh(meshes.add(Rectangle::from_size(Vec2::splat(2.0)))), + Transform::from_xyz(0.0, 5.0, 0.0), +)); ``` Full examples at [examples](examples). diff --git a/examples/depth.rs b/examples/depth.rs index 7eef869..889669f 100644 --- a/examples/depth.rs +++ b/examples/depth.rs @@ -1,7 +1,6 @@ use bevy::color::palettes; use bevy::prelude::*; use bevy_mod_billboard::prelude::*; -use bevy_mod_billboard::BillboardDepth; fn main() { App::new() @@ -15,41 +14,31 @@ fn main() { const TEXT_SCALE: Vec3 = Vec3::splat(0.0085); fn setup_billboard(mut commands: Commands, asset_server: Res) { - let fira_sans_regular_handle = asset_server.load("FiraSans-Regular.ttf"); + let text_font = + TextFont::from_font(asset_server.load("FiraSans-Regular.ttf")).with_font_size(60.0); - commands.spawn(BillboardTextBundle { - transform: Transform::from_translation(Vec3::new(0., 0.5, 0.)).with_scale(TEXT_SCALE), - text: Text::from_section( - "depth enabled", - TextStyle { - font_size: 60.0, - font: fira_sans_regular_handle.clone(), - color: Color::WHITE, - }, - ) - .with_justify(JustifyText::Center), - ..default() - }); + commands.spawn(( + BillboardText::new("depth enabled"), + text_font.clone(), + TextColor(Color::WHITE), + TextLayout::new_with_justify(JustifyText::Center), + Transform::from_xyz(0.0, 0.5, 0.0).with_scale(TEXT_SCALE), + )); - commands.spawn(BillboardTextBundle { - transform: Transform::from_translation(Vec3::new(0., -0.5, 0.)).with_scale(TEXT_SCALE), - text: Text::from_section( - "depth disabled", - TextStyle { - font_size: 60.0, - font: fira_sans_regular_handle.clone(), - color: Color::WHITE, - }, - ) - .with_justify(JustifyText::Center), - billboard_depth: BillboardDepth(false), - ..default() - }); + commands.spawn(( + BillboardText::new("depth disabled"), + BillboardDepth(false), + text_font.clone(), + TextColor(Color::WHITE), + TextLayout::new_with_justify(JustifyText::Center), + Transform::from_xyz(0.0, -0.5, 0.0).with_scale(TEXT_SCALE), + )); } // Important bits are above, the code below is for camera, reference cube and rotation #[derive(Component)] +#[require(Transform)] pub struct CameraHolder; fn setup_scene( @@ -57,26 +46,22 @@ fn setup_scene( mut meshes: ResMut>, mut materials: ResMut>, ) { - commands - .spawn((CameraHolder, Transform::IDENTITY, GlobalTransform::IDENTITY)) - .with_children(|parent| { - parent.spawn(Camera3dBundle { - transform: Transform::from_translation(Vec3::new(5., 0., 0.)) - .looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); - }); - - commands.spawn(PbrBundle { - mesh: meshes.add(Cuboid::default()), - material: materials.add(Color::Srgba(palettes::css::BEIGE)), - transform: Transform::from_translation(Vec3::new(1., 0., 0.)), - ..default() + commands.spawn(CameraHolder).with_children(|parent| { + parent.spawn(( + Camera3d::default(), + Transform::from_xyz(5., 0., 0.).looking_at(Vec3::ZERO, Vec3::Y), + )); }); + + commands.spawn(( + Mesh3d(meshes.add(Cuboid::default())), + MeshMaterial3d(materials.add(Color::Srgba(palettes::css::BEIGE))), + Transform::from_xyz(1., 0., 0.), + )); } fn rotate_camera(mut camera: Query<&mut Transform, With>, time: Res