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 https://github.com/bevyengine/bevy/pull/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
This commit is contained in:
parent
5a9cb7de3e
commit
a090e2fd47
@ -104,25 +104,22 @@ fn spawn_view_model(
|
|||||||
let arm = meshes.add(Cuboid::new(0.1, 0.1, 0.5));
|
let arm = meshes.add(Cuboid::new(0.1, 0.1, 0.5));
|
||||||
let arm_material = materials.add(Color::from(tailwind::TEAL_200));
|
let arm_material = materials.add(Color::from(tailwind::TEAL_200));
|
||||||
|
|
||||||
commands
|
commands.spawn((
|
||||||
.spawn((
|
|
||||||
Player,
|
Player,
|
||||||
CameraSensitivity::default(),
|
CameraSensitivity::default(),
|
||||||
Transform::from_xyz(0.0, 1.0, 0.0),
|
Transform::from_xyz(0.0, 1.0, 0.0),
|
||||||
Visibility::default(),
|
Visibility::default(),
|
||||||
))
|
children![
|
||||||
.with_children(|parent| {
|
(
|
||||||
parent.spawn((
|
|
||||||
WorldModelCamera,
|
WorldModelCamera,
|
||||||
Camera3d::default(),
|
Camera3d::default(),
|
||||||
Projection::from(PerspectiveProjection {
|
Projection::from(PerspectiveProjection {
|
||||||
fov: 90.0_f32.to_radians(),
|
fov: 90.0_f32.to_radians(),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
));
|
),
|
||||||
|
|
||||||
// Spawn view model camera.
|
// Spawn view model camera.
|
||||||
parent.spawn((
|
(
|
||||||
Camera3d::default(),
|
Camera3d::default(),
|
||||||
Camera {
|
Camera {
|
||||||
// Bump the order to render on top of the world model.
|
// Bump the order to render on top of the world model.
|
||||||
@ -135,10 +132,9 @@ fn spawn_view_model(
|
|||||||
}),
|
}),
|
||||||
// Only render objects belonging to the view model.
|
// Only render objects belonging to the view model.
|
||||||
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
|
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
|
||||||
));
|
),
|
||||||
|
|
||||||
// Spawn the player's right arm.
|
// Spawn the player's right arm.
|
||||||
parent.spawn((
|
(
|
||||||
Mesh3d(arm),
|
Mesh3d(arm),
|
||||||
MeshMaterial3d(arm_material),
|
MeshMaterial3d(arm_material),
|
||||||
Transform::from_xyz(0.2, -0.1, -0.25),
|
Transform::from_xyz(0.2, -0.1, -0.25),
|
||||||
@ -146,8 +142,9 @@ fn spawn_view_model(
|
|||||||
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
|
RenderLayers::layer(VIEW_MODEL_RENDER_LAYER),
|
||||||
// The arm is free-floating, so shadows would look weird.
|
// The arm is free-floating, so shadows would look weird.
|
||||||
NotShadowCaster,
|
NotShadowCaster,
|
||||||
|
),
|
||||||
|
],
|
||||||
));
|
));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_world_model(
|
fn spawn_world_model(
|
||||||
|
@ -123,8 +123,7 @@ fn setup(
|
|||||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||||
));
|
));
|
||||||
|
|
||||||
commands
|
commands.spawn((
|
||||||
.spawn((
|
|
||||||
Text::default(),
|
Text::default(),
|
||||||
Node {
|
Node {
|
||||||
position_type: PositionType::Absolute,
|
position_type: PositionType::Absolute,
|
||||||
@ -132,14 +131,14 @@ fn setup(
|
|||||||
left: Val::Px(12.0),
|
left: Val::Px(12.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
))
|
children![
|
||||||
.with_children(|p| {
|
TextSpan::new("Prepass Output: transparent\n"),
|
||||||
p.spawn(TextSpan::new("Prepass Output: transparent\n"));
|
TextSpan::new("\n\n"),
|
||||||
p.spawn(TextSpan::new("\n\n"));
|
TextSpan::new("Controls\n"),
|
||||||
p.spawn(TextSpan::new("Controls\n"));
|
TextSpan::new("---------------\n"),
|
||||||
p.spawn(TextSpan::new("---------------\n"));
|
TextSpan::new("Space - Change output\n"),
|
||||||
p.spawn(TextSpan::new("Space - Change output\n"));
|
],
|
||||||
});
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the struct that will be passed to your shader
|
// This is the struct that will be passed to your shader
|
||||||
|
@ -226,20 +226,19 @@ mod text {
|
|||||||
Transform::from_translation(dest + Vec3::Z),
|
Transform::from_translation(dest + Vec3::Z),
|
||||||
anchor,
|
anchor,
|
||||||
StateScoped(super::Scene::Text),
|
StateScoped(super::Scene::Text),
|
||||||
));
|
children![
|
||||||
text.with_children(|parent| {
|
(
|
||||||
parent.spawn((
|
|
||||||
TextSpan::new(format!("{}, {}\n", anchor.x, anchor.y)),
|
TextSpan::new(format!("{}, {}\n", anchor.x, anchor.y)),
|
||||||
TextFont::from_font_size(14.0),
|
TextFont::from_font_size(14.0),
|
||||||
TextColor(palettes::tailwind::BLUE_400.into()),
|
TextColor(palettes::tailwind::BLUE_400.into()),
|
||||||
));
|
),
|
||||||
parent.spawn((
|
(
|
||||||
TextSpan::new(format!("{justify:?}")),
|
TextSpan::new(format!("{justify:?}")),
|
||||||
TextFont::from_font_size(14.0),
|
TextFont::from_font_size(14.0),
|
||||||
TextColor(palettes::tailwind::GREEN_400.into()),
|
TextColor(palettes::tailwind::GREEN_400.into()),
|
||||||
|
),
|
||||||
|
],
|
||||||
));
|
));
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(bounds) = bounds {
|
if let Some(bounds) = bounds {
|
||||||
text.insert(bounds);
|
text.insert(bounds);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user