Skip to content

Commit ef07ace

Browse files
committed
u
1 parent e96b21a commit ef07ace

File tree

6 files changed

+50
-68
lines changed

6 files changed

+50
-68
lines changed

examples/2d/mesh2d_manual.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,17 @@ fn star(
9797
star.set_indices(Some(Indices::U32(indices)));
9898

9999
// We can now spawn the entities for the star and the camera
100-
commands.spawn_bundle((
101-
// We use a marker component to identify the custom colored meshes
102-
ColoredMesh2d::default(),
103-
// The `Handle<Mesh>` needs to be wrapped in a `Mesh2dHandle` to use 2d rendering instead of 3d
104-
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(),
110-
));
111100
commands
112-
// And use an orthographic projection
113-
.spawn_bundle(Camera2dBundle::default());
101+
.spawn_bundle((
102+
// We use a marker component to identify the custom colored meshes
103+
ColoredMesh2d::default(),
104+
// The `Handle<Mesh>` needs to be wrapped in a `Mesh2dHandle` to use 2d rendering instead of 3d
105+
Mesh2dHandle(meshes.add(star)),
106+
)) // This bundle's components are needed for something to be rendered
107+
.insert_bundle(SpatialBundle::VISIBLE_IDENTITY);
108+
109+
// And don't forget to spawn the camera
110+
commands.spawn_bundle(Camera2dBundle::default());
114111
}
115112

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

examples/animation/custom_skinned_mesh.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,15 @@ fn setup(
121121
for i in -5..5 {
122122
// Create joint entities
123123
let joint_0 = commands
124-
.spawn_bundle((
125-
Transform::from_xyz(i as f32 * 1.5, 0.0, 0.0),
126-
GlobalTransform::IDENTITY,
127-
))
124+
.spawn_bundle(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_bundle((
131-
AnimatedJoint,
132-
Transform::IDENTITY,
133-
GlobalTransform::IDENTITY,
134-
))
131+
.spawn_bundle(TransformBundle::IDENTITY)
132+
.insert(AnimatedJoint)
135133
.id();
136134

137135
// Set joint_1 as a child of joint_0.

examples/shader/animate_shader.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use bevy::{
2424
},
2525
render_resource::*,
2626
renderer::{RenderDevice, RenderQueue},
27-
view::{ComputedVisibility, ExtractedView, Msaa, Visibility},
27+
view::{ExtractedView, Msaa},
2828
RenderApp, RenderStage,
2929
},
3030
};
@@ -39,14 +39,10 @@ fn main() {
3939

4040
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
4141
// cube
42-
commands.spawn().insert_bundle((
43-
meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
44-
Transform::from_xyz(0.0, 0.5, 0.0),
45-
GlobalTransform::default(),
46-
CustomMaterial,
47-
Visibility::default(),
48-
ComputedVisibility::default(),
49-
));
42+
commands
43+
.spawn()
44+
.insert_bundle(SpatialBundle::from(Transform::from_xyz(0.0, 0.5, 0.0)))
45+
.insert(meshes.add(Mesh::from(shape::Cube { size: 1.0 })));
5046

5147
// camera
5248
commands.spawn_bundle(Camera3dBundle {

examples/shader/shader_instancing.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,30 @@ fn main() {
3030
}
3131

3232
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
33-
commands.spawn().insert_bundle((
34-
meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
35-
Transform::from_xyz(0.0, 0.0, 0.0),
36-
GlobalTransform::default(),
37-
InstanceMaterialData(
38-
(1..=10)
39-
.flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0)))
40-
.map(|(x, y)| InstanceData {
41-
position: Vec3::new(x * 10.0 - 5.0, y * 10.0 - 5.0, 0.0),
42-
scale: 1.0,
43-
color: Color::hsla(x * 360., y, 0.5, 1.0).as_rgba_f32(),
44-
})
45-
.collect(),
46-
),
47-
Visibility::default(),
48-
ComputedVisibility::default(),
49-
// NOTE: Frustum culling is done based on the Aabb of the Mesh and the GlobalTransform.
50-
// As the cube is at the origin, if its Aabb moves outside the view frustum, all the
51-
// instanced cubes will be culled.
52-
// The InstanceMaterialData contains the 'GlobalTransform' information for this custom
53-
// instancing, and that is not taken into account with the built-in frustum culling.
54-
// We must disable the built-in frustum culling by adding the `NoFrustumCulling` marker
55-
// component to avoid incorrect culling.
56-
NoFrustumCulling,
57-
));
33+
commands
34+
.spawn()
35+
.insert_bundle(SpatialBundle::from(Transform::from_xyz(0.0, 0.0, 0.0)))
36+
.insert_bundle((
37+
meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
38+
InstanceMaterialData(
39+
(1..=10)
40+
.flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0)))
41+
.map(|(x, y)| InstanceData {
42+
position: Vec3::new(x * 10.0 - 5.0, y * 10.0 - 5.0, 0.0),
43+
scale: 1.0,
44+
color: Color::hsla(x * 360., y, 0.5, 1.0).as_rgba_f32(),
45+
})
46+
.collect(),
47+
),
48+
// NOTE: Frustum culling is done based on the Aabb of the Mesh and the GlobalTransform.
49+
// As the cube is at the origin, if its Aabb moves outside the view frustum, all the
50+
// instanced cubes will be culled.
51+
// The InstanceMaterialData contains the 'GlobalTransform' information for this custom
52+
// instancing, and that is not taken into account with the built-in frustum culling.
53+
// We must disable the built-in frustum culling by adding the `NoFrustumCulling` marker
54+
// component to avoid incorrect culling.
55+
NoFrustumCulling,
56+
));
5857

5958
// camera
6059
commands.spawn_bundle(Camera3dBundle {

examples/stress_tests/many_foxes.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,8 @@ fn setup(
110110
while foxes_remaining > 0 {
111111
let (base_rotation, ring_direction) = ring_directions[ring_index % 2];
112112
let ring_parent = commands
113-
.spawn_bundle((
114-
Transform::default(),
115-
GlobalTransform::default(),
116-
Visibility::default(),
117-
ComputedVisibility::default(),
118-
ring_direction,
119-
Ring { radius },
120-
))
113+
.spawn_bundle(SpatialBundle::VISIBLE_IDENTITY)
114+
.insert_bundle((ring_direction, Ring { radius }))
121115
.id();
122116

123117
let circumference = PI * 2. * radius;

examples/stress_tests/transform_hierarchy.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ fn spawn_tree(
369369
// insert root
370370
ents.push(
371371
commands
372-
.spawn()
373-
.insert(root_transform)
374-
.insert(GlobalTransform::default())
372+
.spawn_bundle(TransformBundle::from(root_transform))
375373
.id(),
376374
);
377375

@@ -419,7 +417,7 @@ fn spawn_tree(
419417
};
420418

421419
// only insert the components necessary for the transform propagation
422-
cmd.insert(transform).insert(GlobalTransform::default());
420+
cmd.insert_bundle(TransformBundle::from(transform));
423421

424422
cmd.id()
425423
};

0 commit comments

Comments
 (0)