Skip to content

Commit a090e2f

Browse files
authored
Update shader_prepass, testbed_2d, and first_person_view_model examples to use children! macro (#18270)
# Objective Contributes to #18238 Updates the `shader_prepass`, `testbed_2d` and `first_person_view_model` examples to use the `children!` macro. I wanted to keep the PR small but chose to do 3 examples since they were all limited in scope ## Solution Updates examples to use the Improved Spawning API merged in #17521 ## Testing - Did you test these changes? If so, how? - Opened the examples before and after and verified the same behavior was observed. I did this on Ubuntu 24.04.2 LTS using `--features wayland`. - Are there any parts that need more testing? - Other OS's and features can't hurt, but this is such a small change it shouldn't be a problem. - How can other people (reviewers) test your changes? Is there anything specific they need to know? - Run the examples yourself with and without these changes. - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? - see above --- ## Showcase n/a ## Migration Guide n/a
1 parent 5a9cb7d commit a090e2f

File tree

3 files changed

+42
-47
lines changed

3 files changed

+42
-47
lines changed

examples/camera/first_person_view_model.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,22 @@ fn spawn_view_model(
104104
let arm = meshes.add(Cuboid::new(0.1, 0.1, 0.5));
105105
let arm_material = materials.add(Color::from(tailwind::TEAL_200));
106106

107-
commands
108-
.spawn((
109-
Player,
110-
CameraSensitivity::default(),
111-
Transform::from_xyz(0.0, 1.0, 0.0),
112-
Visibility::default(),
113-
))
114-
.with_children(|parent| {
115-
parent.spawn((
107+
commands.spawn((
108+
Player,
109+
CameraSensitivity::default(),
110+
Transform::from_xyz(0.0, 1.0, 0.0),
111+
Visibility::default(),
112+
children![
113+
(
116114
WorldModelCamera,
117115
Camera3d::default(),
118116
Projection::from(PerspectiveProjection {
119117
fov: 90.0_f32.to_radians(),
120118
..default()
121119
}),
122-
));
123-
120+
),
124121
// Spawn view model camera.
125-
parent.spawn((
122+
(
126123
Camera3d::default(),
127124
Camera {
128125
// Bump the order to render on top of the world model.
@@ -135,19 +132,19 @@ fn spawn_view_model(
135132
}),
136133
// Only render objects belonging to the view model.
137134
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
138-
));
139-
135+
),
140136
// Spawn the player's right arm.
141-
parent.spawn((
137+
(
142138
Mesh3d(arm),
143139
MeshMaterial3d(arm_material),
144140
Transform::from_xyz(0.2, -0.1, -0.25),
145141
// Ensure the arm is only rendered by the view model camera.
146142
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
147143
// The arm is free-floating, so shadows would look weird.
148144
NotShadowCaster,
149-
));
150-
});
145+
),
146+
],
147+
));
151148
}
152149

153150
fn spawn_world_model(

examples/shader/shader_prepass.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,22 @@ fn setup(
123123
Transform::from_xyz(4.0, 8.0, 4.0),
124124
));
125125

126-
commands
127-
.spawn((
128-
Text::default(),
129-
Node {
130-
position_type: PositionType::Absolute,
131-
top: Val::Px(12.0),
132-
left: Val::Px(12.0),
133-
..default()
134-
},
135-
))
136-
.with_children(|p| {
137-
p.spawn(TextSpan::new("Prepass Output: transparent\n"));
138-
p.spawn(TextSpan::new("\n\n"));
139-
p.spawn(TextSpan::new("Controls\n"));
140-
p.spawn(TextSpan::new("---------------\n"));
141-
p.spawn(TextSpan::new("Space - Change output\n"));
142-
});
126+
commands.spawn((
127+
Text::default(),
128+
Node {
129+
position_type: PositionType::Absolute,
130+
top: Val::Px(12.0),
131+
left: Val::Px(12.0),
132+
..default()
133+
},
134+
children![
135+
TextSpan::new("Prepass Output: transparent\n"),
136+
TextSpan::new("\n\n"),
137+
TextSpan::new("Controls\n"),
138+
TextSpan::new("---------------\n"),
139+
TextSpan::new("Space - Change output\n"),
140+
],
141+
));
143142
}
144143

145144
// This is the struct that will be passed to your shader

examples/testbed/2d.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,19 @@ mod text {
226226
Transform::from_translation(dest + Vec3::Z),
227227
anchor,
228228
StateScoped(super::Scene::Text),
229+
children![
230+
(
231+
TextSpan::new(format!("{}, {}\n", anchor.x, anchor.y)),
232+
TextFont::from_font_size(14.0),
233+
TextColor(palettes::tailwind::BLUE_400.into()),
234+
),
235+
(
236+
TextSpan::new(format!("{justify:?}")),
237+
TextFont::from_font_size(14.0),
238+
TextColor(palettes::tailwind::GREEN_400.into()),
239+
),
240+
],
229241
));
230-
text.with_children(|parent| {
231-
parent.spawn((
232-
TextSpan::new(format!("{}, {}\n", anchor.x, anchor.y)),
233-
TextFont::from_font_size(14.0),
234-
TextColor(palettes::tailwind::BLUE_400.into()),
235-
));
236-
parent.spawn((
237-
TextSpan::new(format!("{justify:?}")),
238-
TextFont::from_font_size(14.0),
239-
TextColor(palettes::tailwind::GREEN_400.into()),
240-
));
241-
});
242-
243242
if let Some(bounds) = bounds {
244243
text.insert(bounds);
245244

0 commit comments

Comments
 (0)