Skip to content

Commit

Permalink
Use SpatialBundle/TransformBundle in examples (bevyengine#6002)
Browse files Browse the repository at this point in the history
Does what it do

Co-authored-by: devil-ira <[email protected]>
  • Loading branch information
2 people authored and ItsDoot committed Feb 1, 2023
1 parent 89db0e6 commit 03438fc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
13 changes: 5 additions & 8 deletions examples/2d/mesh2d_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,12 @@ fn star(
ColoredMesh2d::default(),
// The `Handle<Mesh>` needs to be wrapped in a `Mesh2dHandle` to use 2d rendering instead of 3d
Mesh2dHandle(meshes.add(star)),
// These other components are needed for 2d meshes to be rendered
Transform::default(),
GlobalTransform::default(),
Visibility::default(),
ComputedVisibility::default(),
// This bundle's components are needed for something to be rendered
SpatialBundle::VISIBLE_IDENTITY,
));
commands
// And use an orthographic projection
.spawn(Camera2dBundle::default());

// Spawn the camera
commands.spawn(Camera2dBundle::default());
}

/// A marker component for colored 2d meshes
Expand Down
15 changes: 6 additions & 9 deletions examples/animation/custom_skinned_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,14 @@ fn setup(
for i in -5..5 {
// Create joint entities
let joint_0 = commands
.spawn((
Transform::from_xyz(i as f32 * 1.5, 0.0, 0.0),
GlobalTransform::IDENTITY,
))
.spawn(TransformBundle::from(Transform::from_xyz(
i as f32 * 1.5,
0.0,
0.0,
)))
.id();
let joint_1 = commands
.spawn((
AnimatedJoint,
Transform::IDENTITY,
GlobalTransform::IDENTITY,
))
.spawn((AnimatedJoint, TransformBundle::IDENTITY))
.id();

// Set joint_1 as a child of joint_0.
Expand Down
5 changes: 1 addition & 4 deletions examples/shader/shader_instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ fn main() {
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
commands.spawn((
meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
Transform::from_xyz(0.0, 0.0, 0.0),
GlobalTransform::default(),
SpatialBundle::VISIBLE_IDENTITY,
InstanceMaterialData(
(1..=10)
.flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0)))
Expand All @@ -44,8 +43,6 @@ fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
})
.collect(),
),
Visibility::default(),
ComputedVisibility::default(),
// NOTE: Frustum culling is done based on the Aabb of the Mesh and the GlobalTransform.
// As the cube is at the origin, if its Aabb moves outside the view frustum, all the
// instanced cubes will be culled.
Expand Down
5 changes: 1 addition & 4 deletions examples/stress_tests/many_foxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ fn setup(
let (base_rotation, ring_direction) = ring_directions[ring_index % 2];
let ring_parent = commands
.spawn((
Transform::default(),
GlobalTransform::default(),
Visibility::default(),
ComputedVisibility::default(),
SpatialBundle::VISIBLE_IDENTITY,
ring_direction,
Ring { radius },
))
Expand Down
8 changes: 2 additions & 6 deletions examples/stress_tests/transform_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,7 @@ fn spawn_tree(
}

// insert root
ents.push(
commands
.spawn((root_transform, GlobalTransform::default()))
.id(),
);
ents.push(commands.spawn(TransformBundle::from(root_transform)).id());

let mut result = InsertResult::default();
let mut rng = rand::thread_rng();
Expand Down Expand Up @@ -417,7 +413,7 @@ fn spawn_tree(
};

// only insert the components necessary for the transform propagation
cmd.insert((transform, GlobalTransform::default()));
cmd.insert(TransformBundle::from(transform));

cmd.id()
};
Expand Down

0 comments on commit 03438fc

Please sign in to comment.