Skip to content

Commit 03438fc

Browse files
tim-blackbirdItsDoot
authored andcommitted
Use SpatialBundle/TransformBundle in examples (bevyengine#6002)
Does what it do Co-authored-by: devil-ira <[email protected]>
1 parent 89db0e6 commit 03438fc

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

examples/2d/mesh2d_manual.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,12 @@ fn star(
102102
ColoredMesh2d::default(),
103103
// The `Handle<Mesh>` needs to be wrapped in a `Mesh2dHandle` to use 2d rendering instead of 3d
104104
Mesh2dHandle(meshes.add(star)),
105-
// These other components are needed for 2d meshes to be rendered
106-
Transform::default(),
107-
GlobalTransform::default(),
108-
Visibility::default(),
109-
ComputedVisibility::default(),
105+
// This bundle's components are needed for something to be rendered
106+
SpatialBundle::VISIBLE_IDENTITY,
110107
));
111-
commands
112-
// And use an orthographic projection
113-
.spawn(Camera2dBundle::default());
108+
109+
// Spawn the camera
110+
commands.spawn(Camera2dBundle::default());
114111
}
115112

116113
/// A marker component for colored 2d meshes

examples/animation/custom_skinned_mesh.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,14 @@ fn setup(
121121
for i in -5..5 {
122122
// Create joint entities
123123
let joint_0 = commands
124-
.spawn((
125-
Transform::from_xyz(i as f32 * 1.5, 0.0, 0.0),
126-
GlobalTransform::IDENTITY,
127-
))
124+
.spawn(TransformBundle::from(Transform::from_xyz(
125+
i as f32 * 1.5,
126+
0.0,
127+
0.0,
128+
)))
128129
.id();
129130
let joint_1 = commands
130-
.spawn((
131-
AnimatedJoint,
132-
Transform::IDENTITY,
133-
GlobalTransform::IDENTITY,
134-
))
131+
.spawn((AnimatedJoint, TransformBundle::IDENTITY))
135132
.id();
136133

137134
// Set joint_1 as a child of joint_0.

examples/shader/shader_instancing.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ fn main() {
3232
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
3333
commands.spawn((
3434
meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
35-
Transform::from_xyz(0.0, 0.0, 0.0),
36-
GlobalTransform::default(),
35+
SpatialBundle::VISIBLE_IDENTITY,
3736
InstanceMaterialData(
3837
(1..=10)
3938
.flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0)))
@@ -44,8 +43,6 @@ fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
4443
})
4544
.collect(),
4645
),
47-
Visibility::default(),
48-
ComputedVisibility::default(),
4946
// NOTE: Frustum culling is done based on the Aabb of the Mesh and the GlobalTransform.
5047
// As the cube is at the origin, if its Aabb moves outside the view frustum, all the
5148
// instanced cubes will be culled.

examples/stress_tests/many_foxes.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ fn setup(
111111
let (base_rotation, ring_direction) = ring_directions[ring_index % 2];
112112
let ring_parent = commands
113113
.spawn((
114-
Transform::default(),
115-
GlobalTransform::default(),
116-
Visibility::default(),
117-
ComputedVisibility::default(),
114+
SpatialBundle::VISIBLE_IDENTITY,
118115
ring_direction,
119116
Ring { radius },
120117
))

examples/stress_tests/transform_hierarchy.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,7 @@ fn spawn_tree(
367367
}
368368

369369
// insert root
370-
ents.push(
371-
commands
372-
.spawn((root_transform, GlobalTransform::default()))
373-
.id(),
374-
);
370+
ents.push(commands.spawn(TransformBundle::from(root_transform)).id());
375371

376372
let mut result = InsertResult::default();
377373
let mut rng = rand::thread_rng();
@@ -417,7 +413,7 @@ fn spawn_tree(
417413
};
418414

419415
// only insert the components necessary for the transform propagation
420-
cmd.insert((transform, GlobalTransform::default()));
416+
cmd.insert(TransformBundle::from(transform));
421417

422418
cmd.id()
423419
};

0 commit comments

Comments
 (0)