-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdepth.rs
82 lines (71 loc) · 2.5 KB
/
depth.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use bevy::color::palettes;
use bevy::prelude::*;
use bevy_mod_billboard::prelude::*;
use bevy_mod_billboard::BillboardDepth;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(BillboardPlugin)
.add_systems(Startup, (setup_billboard, setup_scene))
.add_systems(Update, rotate_camera)
.run();
}
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");
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(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()
});
}
// Important bits are above, the code below is for camera, reference cube and rotation
#[derive(Component)]
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()
});
}
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());
}