Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -34,4 +37,4 @@ features = [
]

[dev-dependencies]
bevy = "0.14"
bevy = "0.15"
50 changes: 21 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
75 changes: 30 additions & 45 deletions examples/depth.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -15,68 +14,54 @@ fn main() {
const TEXT_SCALE: Vec3 = Vec3::splat(0.0085);

fn setup_billboard(mut commands: Commands, asset_server: Res<AssetServer>) {
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(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
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<CameraHolder>>, time: Res<Time>) {
let mut camera = camera.single_mut();

camera.rotate_y(time.delta_seconds());
camera.rotate_y(time.delta_secs());
}
77 changes: 29 additions & 48 deletions examples/lock_rotation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;
use bevy_mod_billboard::BillboardLockAxis;

fn main() {
App::new()
Expand All @@ -13,69 +12,51 @@ fn main() {
}

fn setup_billboard(mut commands: Commands, asset_server: Res<AssetServer>) {
let fira_sans_regular_handle = asset_server.load("FiraSans-Regular.ttf");
commands.spawn((
BillboardTextBundle {
transform: Transform::from_scale(Vec3::splat(0.0085))
.looking_at(Vec3::splat(5.0), Vec3::Y),
text: Text::from_sections([
TextSection {
value: "LOCKED".to_string(),
style: TextStyle {
font_size: 60.0,
font: fira_sans_regular_handle.clone(),
color: Color::Srgba(palettes::css::ORANGE),
},
},
TextSection {
value: " text".to_string(),
style: TextStyle {
font_size: 60.0,
font: fira_sans_regular_handle.clone(),
color: Color::WHITE,
},
},
])
.with_justify(JustifyText::Center),
..default()
},
BillboardLockAxis {
rotation: true,
..default()
},
));
let text_font =
TextFont::from_font(asset_server.load("FiraSans-Regular.ttf")).with_font_size(60.0);

commands
.spawn((
BillboardText::default(),
TextLayout::new_with_justify(JustifyText::Center),
Transform::from_scale(Vec3::splat(0.0085)).looking_at(Vec3::splat(5.0), Vec3::Y),
BillboardLockAxis::from_lock_rotation(true),
))
.with_child((
TextSpan::new("LOCKED"),
text_font.clone(),
TextColor(Color::Srgba(palettes::css::ORANGE)),
))
.with_child((TextSpan::new(" text"), text_font, TextColor(Color::WHITE)));
}

// Important bits are above, the code below is for camera, reference cube and rotation

#[derive(Component)]
#[require(Transform)]
pub struct CameraHolder;

fn setup_scene(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
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::GRAY)),
transform: Transform::from_translation(Vec3::NEG_Y),
..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::GRAY))),
Transform::from_translation(Vec3::NEG_Y),
));
}

fn rotate_camera(mut camera: Query<&mut Transform, With<CameraHolder>>, time: Res<Time>) {
let mut camera = camera.single_mut();

camera.rotate_y(time.delta_seconds());
camera.rotate_y(time.delta_secs());
}
61 changes: 26 additions & 35 deletions examples/lock_y.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;
use bevy_mod_billboard::{BillboardLockAxis, BillboardLockAxisBundle};

fn main() {
App::new()
Expand All @@ -18,56 +17,48 @@ fn setup_billboard(
mut meshes: ResMut<Assets<Mesh>>,
) {
let image_handle = asset_server.load("tree.png");
commands.spawn(BillboardLockAxisBundle {
billboard_bundle: BillboardTextureBundle {
transform: Transform::from_translation(Vec3::new(2.0, 2.0, 0.0)),
texture: BillboardTextureHandle(image_handle.clone()),
mesh: BillboardMeshHandle(meshes.add(Rectangle::from_size(Vec2::new(2.0, 4.0)))),
..default()
},
lock_axis: BillboardLockAxis {
y_axis: true,
..Default::default()
},
});
commands.spawn(BillboardTextureBundle {
transform: Transform::from_translation(Vec3::new(-2.0, 2.0, 0.0)),
texture: BillboardTextureHandle(image_handle),
mesh: BillboardMeshHandle(meshes.add(Rectangle::from_size(Vec2::new(2.0, 4.0)))),
..default()
});

commands.spawn((
BillboardTexture(image_handle.clone()),
BillboardMesh(meshes.add(Rectangle::new(2.0, 4.0))),
Transform::from_xyz(2.0, 2.0, 0.0),
BillboardLockAxis::from_lock_y(true),
));

commands.spawn((
BillboardTexture(image_handle),
BillboardMesh(meshes.add(Rectangle::new(2.0, 4.0))),
Transform::from_xyz(-2.0, 2.0, 0.0),
));
}

// Important bits are above, the code below is for camera, reference plane and rotation

#[derive(Component)]
#[require(Transform)]
pub struct CameraHolder;

fn setup_scene(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(PbrBundle {
transform: Transform::from_scale(Vec3::splat(3.0)),
mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.5))),
material: materials.add(Color::Srgba(palettes::css::SILVER)),
..default()
});
commands.spawn((
Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.5)))),
MeshMaterial3d(materials.add(Color::Srgba(palettes::css::SILVER))),
Transform::from_scale(Vec3::splat(3.0)),
));

commands
.spawn((CameraHolder, Transform::IDENTITY, GlobalTransform::IDENTITY))
.with_children(|parent| {
parent.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0., 15., 2.))
.looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
});
commands.spawn(CameraHolder).with_children(|parent| {
parent.spawn((
Camera3d::default(),
Transform::from_xyz(0., 15., 2.).looking_at(Vec3::ZERO, Vec3::Y),
));
});
}

fn rotate_camera(mut camera: Query<&mut Transform, With<CameraHolder>>, time: Res<Time>) {
let mut camera = camera.single_mut();

camera.rotate_y(time.delta_seconds());
camera.rotate_y(time.delta_secs());
}
Loading