Use SpatialBundle/TransformBundle in examples (#6002)
				
					
				
			Does what it do Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
		
							parent
							
								
									000e6e2874
								
							
						
					
					
						commit
						92ba6224b9
					
				@ -102,15 +102,12 @@ fn star(
 | 
				
			|||||||
        ColoredMesh2d::default(),
 | 
					        ColoredMesh2d::default(),
 | 
				
			||||||
        // The `Handle<Mesh>` needs to be wrapped in a `Mesh2dHandle` to use 2d rendering instead of 3d
 | 
					        // The `Handle<Mesh>` needs to be wrapped in a `Mesh2dHandle` to use 2d rendering instead of 3d
 | 
				
			||||||
        Mesh2dHandle(meshes.add(star)),
 | 
					        Mesh2dHandle(meshes.add(star)),
 | 
				
			||||||
        // These other components are needed for 2d meshes to be rendered
 | 
					        // This bundle's components are needed for something to be rendered
 | 
				
			||||||
        Transform::default(),
 | 
					        SpatialBundle::VISIBLE_IDENTITY,
 | 
				
			||||||
        GlobalTransform::default(),
 | 
					 | 
				
			||||||
        Visibility::default(),
 | 
					 | 
				
			||||||
        ComputedVisibility::default(),
 | 
					 | 
				
			||||||
    ));
 | 
					    ));
 | 
				
			||||||
    commands
 | 
					
 | 
				
			||||||
        // And use an orthographic projection
 | 
					    // Spawn the camera
 | 
				
			||||||
        .spawn(Camera2dBundle::default());
 | 
					    commands.spawn(Camera2dBundle::default());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// A marker component for colored 2d meshes
 | 
					/// A marker component for colored 2d meshes
 | 
				
			||||||
 | 
				
			|||||||
@ -121,17 +121,14 @@ fn setup(
 | 
				
			|||||||
    for i in -5..5 {
 | 
					    for i in -5..5 {
 | 
				
			||||||
        // Create joint entities
 | 
					        // Create joint entities
 | 
				
			||||||
        let joint_0 = commands
 | 
					        let joint_0 = commands
 | 
				
			||||||
            .spawn((
 | 
					            .spawn(TransformBundle::from(Transform::from_xyz(
 | 
				
			||||||
                Transform::from_xyz(i as f32 * 1.5, 0.0, 0.0),
 | 
					                i as f32 * 1.5,
 | 
				
			||||||
                GlobalTransform::IDENTITY,
 | 
					                0.0,
 | 
				
			||||||
            ))
 | 
					                0.0,
 | 
				
			||||||
 | 
					            )))
 | 
				
			||||||
            .id();
 | 
					            .id();
 | 
				
			||||||
        let joint_1 = commands
 | 
					        let joint_1 = commands
 | 
				
			||||||
            .spawn((
 | 
					            .spawn((AnimatedJoint, TransformBundle::IDENTITY))
 | 
				
			||||||
                AnimatedJoint,
 | 
					 | 
				
			||||||
                Transform::IDENTITY,
 | 
					 | 
				
			||||||
                GlobalTransform::IDENTITY,
 | 
					 | 
				
			||||||
            ))
 | 
					 | 
				
			||||||
            .id();
 | 
					            .id();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Set joint_1 as a child of joint_0.
 | 
					        // Set joint_1 as a child of joint_0.
 | 
				
			||||||
 | 
				
			|||||||
@ -32,8 +32,7 @@ fn main() {
 | 
				
			|||||||
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
 | 
					fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
 | 
				
			||||||
    commands.spawn((
 | 
					    commands.spawn((
 | 
				
			||||||
        meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
 | 
					        meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
 | 
				
			||||||
        Transform::from_xyz(0.0, 0.0, 0.0),
 | 
					        SpatialBundle::VISIBLE_IDENTITY,
 | 
				
			||||||
        GlobalTransform::default(),
 | 
					 | 
				
			||||||
        InstanceMaterialData(
 | 
					        InstanceMaterialData(
 | 
				
			||||||
            (1..=10)
 | 
					            (1..=10)
 | 
				
			||||||
                .flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0)))
 | 
					                .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>>) {
 | 
				
			|||||||
                })
 | 
					                })
 | 
				
			||||||
                .collect(),
 | 
					                .collect(),
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
        Visibility::default(),
 | 
					 | 
				
			||||||
        ComputedVisibility::default(),
 | 
					 | 
				
			||||||
        // NOTE: Frustum culling is done based on the Aabb of the Mesh and the GlobalTransform.
 | 
					        // 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
 | 
					        // As the cube is at the origin, if its Aabb moves outside the view frustum, all the
 | 
				
			||||||
        // instanced cubes will be culled.
 | 
					        // instanced cubes will be culled.
 | 
				
			||||||
 | 
				
			|||||||
@ -111,10 +111,7 @@ fn setup(
 | 
				
			|||||||
        let (base_rotation, ring_direction) = ring_directions[ring_index % 2];
 | 
					        let (base_rotation, ring_direction) = ring_directions[ring_index % 2];
 | 
				
			||||||
        let ring_parent = commands
 | 
					        let ring_parent = commands
 | 
				
			||||||
            .spawn((
 | 
					            .spawn((
 | 
				
			||||||
                Transform::default(),
 | 
					                SpatialBundle::VISIBLE_IDENTITY,
 | 
				
			||||||
                GlobalTransform::default(),
 | 
					 | 
				
			||||||
                Visibility::default(),
 | 
					 | 
				
			||||||
                ComputedVisibility::default(),
 | 
					 | 
				
			||||||
                ring_direction,
 | 
					                ring_direction,
 | 
				
			||||||
                Ring { radius },
 | 
					                Ring { radius },
 | 
				
			||||||
            ))
 | 
					            ))
 | 
				
			||||||
 | 
				
			|||||||
@ -367,11 +367,7 @@ fn spawn_tree(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // insert root
 | 
					    // insert root
 | 
				
			||||||
    ents.push(
 | 
					    ents.push(commands.spawn(TransformBundle::from(root_transform)).id());
 | 
				
			||||||
        commands
 | 
					 | 
				
			||||||
            .spawn((root_transform, GlobalTransform::default()))
 | 
					 | 
				
			||||||
            .id(),
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let mut result = InsertResult::default();
 | 
					    let mut result = InsertResult::default();
 | 
				
			||||||
    let mut rng = rand::thread_rng();
 | 
					    let mut rng = rand::thread_rng();
 | 
				
			||||||
@ -417,7 +413,7 @@ fn spawn_tree(
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // only insert the components necessary for the transform propagation
 | 
					            // only insert the components necessary for the transform propagation
 | 
				
			||||||
            cmd.insert((transform, GlobalTransform::default()));
 | 
					            cmd.insert(TransformBundle::from(transform));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            cmd.id()
 | 
					            cmd.id()
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user