Skip to content

Update shader_prepass, testbed_2d, and first_person_view_model examples to use children! macro #18270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 22, 2025
Merged
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
31 changes: 14 additions & 17 deletions examples/camera/first_person_view_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,22 @@ fn spawn_view_model(
let arm = meshes.add(Cuboid::new(0.1, 0.1, 0.5));
let arm_material = materials.add(Color::from(tailwind::TEAL_200));

commands
.spawn((
Player,
CameraSensitivity::default(),
Transform::from_xyz(0.0, 1.0, 0.0),
Visibility::default(),
))
.with_children(|parent| {
parent.spawn((
commands.spawn((
Player,
CameraSensitivity::default(),
Transform::from_xyz(0.0, 1.0, 0.0),
Visibility::default(),
children![
(
WorldModelCamera,
Camera3d::default(),
Projection::from(PerspectiveProjection {
fov: 90.0_f32.to_radians(),
..default()
}),
));

),
// Spawn view model camera.
parent.spawn((
(
Camera3d::default(),
Camera {
// Bump the order to render on top of the world model.
Expand All @@ -135,19 +132,19 @@ fn spawn_view_model(
}),
// Only render objects belonging to the view model.
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
));

),
// Spawn the player's right arm.
parent.spawn((
(
Mesh3d(arm),
MeshMaterial3d(arm_material),
Transform::from_xyz(0.2, -0.1, -0.25),
// Ensure the arm is only rendered by the view model camera.
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
// The arm is free-floating, so shadows would look weird.
NotShadowCaster,
));
});
),
],
));
}

fn spawn_world_model(
Expand Down
33 changes: 16 additions & 17 deletions examples/shader/shader_prepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,22 @@ fn setup(
Transform::from_xyz(4.0, 8.0, 4.0),
));

commands
.spawn((
Text::default(),
Node {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
},
))
.with_children(|p| {
p.spawn(TextSpan::new("Prepass Output: transparent\n"));
p.spawn(TextSpan::new("\n\n"));
p.spawn(TextSpan::new("Controls\n"));
p.spawn(TextSpan::new("---------------\n"));
p.spawn(TextSpan::new("Space - Change output\n"));
});
commands.spawn((
Text::default(),
Node {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
},
children![
TextSpan::new("Prepass Output: transparent\n"),
TextSpan::new("\n\n"),
TextSpan::new("Controls\n"),
TextSpan::new("---------------\n"),
TextSpan::new("Space - Change output\n"),
],
));
}

// This is the struct that will be passed to your shader
Expand Down
25 changes: 12 additions & 13 deletions examples/testbed/2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,19 @@ mod text {
Transform::from_translation(dest + Vec3::Z),
anchor,
StateScoped(super::Scene::Text),
children![
(
TextSpan::new(format!("{}, {}\n", anchor.x, anchor.y)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I resolved a merge conflict on these lines, I believe this line was the only delta but worth re-reviewing with a close eye.

TextFont::from_font_size(14.0),
TextColor(palettes::tailwind::BLUE_400.into()),
),
(
TextSpan::new(format!("{justify:?}")),
TextFont::from_font_size(14.0),
TextColor(palettes::tailwind::GREEN_400.into()),
),
],
));
text.with_children(|parent| {
parent.spawn((
TextSpan::new(format!("{}, {}\n", anchor.x, anchor.y)),
TextFont::from_font_size(14.0),
TextColor(palettes::tailwind::BLUE_400.into()),
));
parent.spawn((
TextSpan::new(format!("{justify:?}")),
TextFont::from_font_size(14.0),
TextColor(palettes::tailwind::GREEN_400.into()),
));
});

if let Some(bounds) = bounds {
text.insert(bounds);

Expand Down