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(),
 | 
			
		||||
        // 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
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
 | 
			
		||||
@ -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)))
 | 
			
		||||
@ -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.
 | 
			
		||||
 | 
			
		||||
@ -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 },
 | 
			
		||||
            ))
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
@ -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()
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user