![]() # Objective It can sometimes be useful to transform actual `Mesh` data without needing to change the `Transform` of an entity. For example, one might want to spawn a circle mesh facing up instead of facing Z, or to spawn a mesh slightly offset without needing child entities. ## Solution Add `transform_by` and `transformed_by` methods to `Mesh`. They take a `Transform` and apply the translation, rotation, and scale to vertex positions, and the rotation to normals and tangents. In the `load_gltf` example, with this system: ```rust fn transform(time: Res<Time>, mut q: Query<&mut Handle<Mesh>>, mut meshes: ResMut<Assets<Mesh>>) { let sin = 0.0025 * time.elapsed_seconds().sin(); for mesh_handle in &mut q { if let Some(mesh) = meshes.get_mut(mesh_handle.clone_weak()) { let transform = Transform::from_rotation(Quat::from_rotation_y(0.75 * time.delta_seconds())) .with_scale(Vec3::splat(1.0 + sin)); mesh.transform_by(transform); } } } ``` it looks like this: https://github.com/bevyengine/bevy/assets/57632562/60432456-6d28-4d06-9c94-2f4148f5acd5 |
||
---|---|---|
.. | ||
macros | ||
src | ||
Cargo.toml |