Skip to main content

Transform

Struct Transform 

Source
pub struct Transform {
    pub translation: Vec3,
    pub rotation: Quat,
    pub scale: Vec3,
}
Expand description

Describe the position of an entity. If the entity has a parent, the position is relative to its parent position.

§Transform and GlobalTransform

Transform is the position of an entity relative to its parent position, or the reference frame if it doesn’t have a ChildOf component.

GlobalTransform is the position of an entity relative to the reference frame.

GlobalTransform is updated from Transform in the TransformSystems::Propagate system set.

This system runs during PostUpdate. If you update the Transform of an entity during this set or after, you will notice a 1 frame lag before the GlobalTransform is updated.

§Examples

Fields§

§translation: Vec3

Position of the entity. In 2d, the last value of the Vec3 is used for z-ordering.

See the translations example for usage.

§rotation: Quat

Rotation of the entity.

See the 3d_rotation example for usage.

§scale: Vec3

Scale of the entity.

See the scale example for usage.

Implementations§

Source§

impl Transform

Source

pub const IDENTITY: Transform

An identity Transform with no translation, rotation, and a scale of 1 on all axes.

Source

pub const fn from_xyz(x: f32, y: f32, z: f32) -> Transform

Creates a new Transform at the position (x, y, z). In 2d, the z component is used for z-ordering elements: higher z-value will be in front of lower z-value.

Examples found in repository?
examples/2d/move_sprite.rs (line 24)
19fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
20    commands.spawn(Camera2d);
21
22    commands.spawn((
23        Sprite::from_image(asset_server.load("branding/icon.png")),
24        Transform::from_xyz(0., 0., 0.),
25        Direction::Right,
26    ));
27}
More examples
Hide additional examples
examples/gltf/gltf_skinned_mesh.rs (line 24)
20fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
21    // Create a camera
22    commands.spawn((
23        Camera3d::default(),
24        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::new(0.0, 1.0, 0.0), Vec3::Y),
25    ));
26
27    // Spawn the first scene in `models/SimpleSkin/SimpleSkin.gltf`
28    commands.spawn(SceneRoot(asset_server.load(
29        GltfAssetLabel::Scene(0).from_asset("models/SimpleSkin/SimpleSkin.gltf"),
30    )));
31}
examples/shader/shader_material_wesl.rs (line 63)
51fn setup(
52    mut commands: Commands,
53    mut meshes: ResMut<Assets<Mesh>>,
54    mut materials: ResMut<Assets<CustomMaterial>>,
55) {
56    // cube
57    commands.spawn((
58        Mesh3d(meshes.add(Cuboid::default())),
59        MeshMaterial3d(materials.add(CustomMaterial {
60            time: Vec4::ZERO,
61            party_mode: false,
62        })),
63        Transform::from_xyz(0.0, 0.5, 0.0),
64    ));
65
66    // camera
67    commands.spawn((
68        Camera3d::default(),
69        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
70    ));
71}
examples/shader/fallback_image.rs (line 43)
25fn setup(
26    mut commands: Commands,
27    mut meshes: ResMut<Assets<Mesh>>,
28    mut materials: ResMut<Assets<FallbackTestMaterial>>,
29) {
30    commands.spawn((
31        Mesh3d(meshes.add(Cuboid::default())),
32        MeshMaterial3d(materials.add(FallbackTestMaterial {
33            image_1d: None,
34            image_2d: None,
35            image_2d_array: None,
36            image_cube: None,
37            image_cube_array: None,
38            image_3d: None,
39        })),
40    ));
41    commands.spawn((
42        Camera3d::default(),
43        Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::new(1.5, 0.0, 0.0), Vec3::Y),
44    ));
45}
examples/shader/shader_material.rs (line 32)
18fn setup(
19    mut commands: Commands,
20    mut meshes: ResMut<Assets<Mesh>>,
21    mut materials: ResMut<Assets<CustomMaterial>>,
22    asset_server: Res<AssetServer>,
23) {
24    // cube
25    commands.spawn((
26        Mesh3d(meshes.add(Cuboid::default())),
27        MeshMaterial3d(materials.add(CustomMaterial {
28            color: LinearRgba::BLUE,
29            color_texture: Some(asset_server.load("branding/icon.png")),
30            alpha_mode: AlphaMode::Blend,
31        })),
32        Transform::from_xyz(0.0, 0.5, 0.0),
33    ));
34
35    // camera
36    commands.spawn((
37        Camera3d::default(),
38        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
39    ));
40}
examples/shader/shader_material_glsl.rs (line 33)
19fn setup(
20    mut commands: Commands,
21    mut meshes: ResMut<Assets<Mesh>>,
22    mut materials: ResMut<Assets<CustomMaterial>>,
23    asset_server: Res<AssetServer>,
24) {
25    // cube
26    commands.spawn((
27        Mesh3d(meshes.add(Cuboid::default())),
28        MeshMaterial3d(materials.add(CustomMaterial {
29            color: LinearRgba::BLUE,
30            color_texture: Some(asset_server.load("branding/icon.png")),
31            alpha_mode: AlphaMode::Blend,
32        })),
33        Transform::from_xyz(0.0, 0.5, 0.0),
34    ));
35
36    // camera
37    commands.spawn((
38        Camera3d::default(),
39        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
40    ));
41}
Source

pub fn from_matrix(world_from_local: Mat4) -> Transform

Extracts the translation, rotation, and scale from matrix. It must be a 3d affine transformation matrix.

Source

pub const fn from_translation(translation: Vec3) -> Transform

Creates a new Transform, with translation. Rotation will be 0 and scale 1 on all axes.

Examples found in repository?
examples/3d/animated_material.rs (line 40)
13fn setup(
14    mut commands: Commands,
15    asset_server: Res<AssetServer>,
16    mut meshes: ResMut<Assets<Mesh>>,
17    mut materials: ResMut<Assets<StandardMaterial>>,
18) {
19    commands.spawn((
20        Camera3d::default(),
21        Transform::from_xyz(3.0, 1.0, 3.0).looking_at(Vec3::new(0.0, -0.5, 0.0), Vec3::Y),
22        EnvironmentMapLight {
23            diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
24            specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
25            intensity: 2_000.0,
26            ..default()
27        },
28    ));
29
30    let cube = meshes.add(Cuboid::new(0.5, 0.5, 0.5));
31
32    const GOLDEN_ANGLE: f32 = 137.507_77;
33
34    let mut hsla = Hsla::hsl(0.0, 1.0, 0.5);
35    for x in -1..2 {
36        for z in -1..2 {
37            commands.spawn((
38                Mesh3d(cube.clone()),
39                MeshMaterial3d(materials.add(Color::from(hsla))),
40                Transform::from_translation(Vec3::new(x as f32, 0.0, z as f32)),
41            ));
42            hsla = hsla.rotate_hue(GOLDEN_ANGLE);
43        }
44    }
45}
More examples
Hide additional examples
examples/2d/bloom_2d.rs (line 47)
17fn setup(
18    mut commands: Commands,
19    mut meshes: ResMut<Assets<Mesh>>,
20    mut materials: ResMut<Assets<ColorMaterial>>,
21    asset_server: Res<AssetServer>,
22) {
23    commands.spawn((
24        Camera2d,
25        Camera {
26            clear_color: ClearColorConfig::Custom(Color::BLACK),
27            ..default()
28        },
29        Tonemapping::TonyMcMapface, // 1. Using a tonemapper that desaturates to white is recommended
30        Bloom::default(),           // 2. Enable bloom for the camera
31        DebandDither::Enabled,      // Optional: bloom causes gradients which cause banding
32    ));
33
34    // Sprite
35    commands.spawn(Sprite {
36        image: asset_server.load("branding/bevy_bird_dark.png"),
37        color: Color::srgb(5.0, 5.0, 5.0), // 3. Put something bright in a dark environment to see the effect
38        custom_size: Some(Vec2::splat(160.0)),
39        ..default()
40    });
41
42    // Circle mesh
43    commands.spawn((
44        Mesh2d(meshes.add(Circle::new(100.))),
45        // 3. Put something bright in a dark environment to see the effect
46        MeshMaterial2d(materials.add(Color::srgb(7.5, 0.0, 7.5))),
47        Transform::from_translation(Vec3::new(-200., 0., 0.)),
48    ));
49
50    // Hexagon mesh
51    commands.spawn((
52        Mesh2d(meshes.add(RegularPolygon::new(100., 6))),
53        // 3. Put something bright in a dark environment to see the effect
54        MeshMaterial2d(materials.add(Color::srgb(6.25, 9.4, 9.1))),
55        Transform::from_translation(Vec3::new(200., 0., 0.)),
56    ));
57
58    // UI
59    commands.spawn((
60        Text::default(),
61        Node {
62            position_type: PositionType::Absolute,
63            top: px(12),
64            left: px(12),
65            ..default()
66        },
67    ));
68}
examples/picking/dragdrop_picking.rs (line 93)
29fn setup(
30    mut commands: Commands,
31    mut meshes: ResMut<Assets<Mesh>>,
32    mut materials: ResMut<Assets<ColorMaterial>>,
33) {
34    commands.spawn(Camera2d);
35
36    commands
37        .spawn((
38            Node {
39                width: Val::Percent(100.0),
40                height: Val::Percent(100.0),
41                align_items: AlignItems::Center,
42                justify_content: JustifyContent::Start,
43                ..default()
44            },
45            Pickable::IGNORE,
46        ))
47        .with_children(|parent| {
48            parent
49                .spawn((
50                    DraggableButton,
51                    Node {
52                        width: Val::Px(BUTTON_WIDTH),
53                        height: Val::Px(BUTTON_HEIGHT),
54                        margin: UiRect::all(Val::Px(10.0)),
55                        justify_content: JustifyContent::Center,
56                        align_items: AlignItems::Center,
57                        ..default()
58                    },
59                    BackgroundColor(Color::srgb(1.0, 0.0, 0.0)),
60                ))
61                .with_child((
62                    Text::new("Drag from me"),
63                    TextColor(Color::WHITE),
64                    Pickable::IGNORE,
65                ))
66                .observe(
67                    |mut event: On<Pointer<DragStart>>,
68                     mut button_color: Single<&mut BackgroundColor, With<DraggableButton>>| {
69                        button_color.0 = Color::srgb(1.0, 0.5, 0.0);
70                        event.propagate(false);
71                    },
72                )
73                .observe(
74                    |mut event: On<Pointer<DragEnd>>,
75                     mut button_color: Single<&mut BackgroundColor, With<DraggableButton>>| {
76                        button_color.0 = Color::srgb(1.0, 0.0, 0.0);
77                        event.propagate(false);
78                    },
79                );
80        });
81
82    commands
83        .spawn((
84            DropArea,
85            Mesh2d(meshes.add(Rectangle::new(AREA_SIZE, AREA_SIZE))),
86            MeshMaterial2d(materials.add(Color::srgb(0.1, 0.4, 0.1))),
87            Transform::IDENTITY,
88            children![(
89                Text2d::new("Drop here"),
90                TextFont::from_font_size(50.),
91                TextColor(Color::BLACK),
92                Pickable::IGNORE,
93                Transform::from_translation(Vec3::Z),
94            )],
95        ))
96        .observe(on_drag_enter)
97        .observe(on_drag_over)
98        .observe(on_drag_drop)
99        .observe(on_drag_leave);
100}
101
102fn on_drag_enter(
103    mut event: On<Pointer<DragEnter>>,
104    button: Single<Entity, With<DraggableButton>>,
105    mut commands: Commands,
106    mut meshes: ResMut<Assets<Mesh>>,
107    mut materials: ResMut<Assets<ColorMaterial>>,
108) {
109    if event.dragged == *button {
110        let Some(position) = event.hit.position else {
111            return;
112        };
113        commands.spawn((
114            GhostPreview,
115            Mesh2d(meshes.add(Circle::new(ELEMENT_SIZE))),
116            MeshMaterial2d(materials.add(Color::srgba(1.0, 1.0, 0.6, 0.5))),
117            Transform::from_translation(position + 2. * Vec3::Z),
118            Pickable::IGNORE,
119        ));
120        event.propagate(false);
121    }
122}
123
124fn on_drag_over(
125    mut event: On<Pointer<DragOver>>,
126    button: Single<Entity, With<DraggableButton>>,
127    mut ghost_transform: Single<&mut Transform, With<GhostPreview>>,
128) {
129    if event.dragged == *button {
130        let Some(position) = event.hit.position else {
131            return;
132        };
133        ghost_transform.translation = position;
134        event.propagate(false);
135    }
136}
137
138fn on_drag_drop(
139    mut event: On<Pointer<DragDrop>>,
140    button: Single<Entity, With<DraggableButton>>,
141    mut commands: Commands,
142    ghost: Single<Entity, With<GhostPreview>>,
143    mut meshes: ResMut<Assets<Mesh>>,
144    mut materials: ResMut<Assets<ColorMaterial>>,
145) {
146    if event.dropped == *button {
147        commands.entity(*ghost).despawn();
148        let Some(position) = event.hit.position else {
149            return;
150        };
151        commands.spawn((
152            DroppedElement,
153            Mesh2d(meshes.add(Circle::new(ELEMENT_SIZE))),
154            MeshMaterial2d(materials.add(Color::srgb(1.0, 1.0, 0.6))),
155            Transform::from_translation(position + 2. * Vec3::Z),
156            Pickable::IGNORE,
157        ));
158        event.propagate(false);
159    }
160}
examples/2d/mesh2d_repeated_texture.rs (line 57)
25fn setup(
26    mut commands: Commands,
27    asset_server: Res<AssetServer>,
28    mut meshes: ResMut<Assets<Mesh>>,
29    mut materials: ResMut<Assets<ColorMaterial>>,
30) {
31    // #11111: We use a duplicated image so that it can be load with and without
32    // settings
33    let image_with_default_sampler =
34        asset_server.load("textures/fantasy_ui_borders/panel-border-010.png");
35    let image_with_repeated_sampler = asset_server.load_with_settings(
36        "textures/fantasy_ui_borders/panel-border-010-repeated.png",
37        |s: &mut _| {
38            *s = ImageLoaderSettings {
39                sampler: ImageSampler::Descriptor(ImageSamplerDescriptor {
40                    // rewriting mode to repeat image,
41                    address_mode_u: ImageAddressMode::Repeat,
42                    address_mode_v: ImageAddressMode::Repeat,
43                    ..default()
44                }),
45                ..default()
46            }
47        },
48    );
49
50    // central rectangle with not repeated texture
51    commands.spawn((
52        Mesh2d(meshes.add(Rectangle::new(RECTANGLE_SIDE, RECTANGLE_SIDE))),
53        MeshMaterial2d(materials.add(ColorMaterial {
54            texture: Some(image_with_default_sampler.clone()),
55            ..default()
56        })),
57        Transform::from_translation(Vec3::ZERO),
58        children![(
59            Text2d::new("Control"),
60            Transform::from_xyz(0., LABEL_OFFSET, 0.),
61        )],
62    ));
63
64    // left rectangle with repeated texture
65    commands.spawn((
66        Mesh2d(meshes.add(Rectangle::new(RECTANGLE_SIDE, RECTANGLE_SIDE))),
67        MeshMaterial2d(materials.add(ColorMaterial {
68            texture: Some(image_with_repeated_sampler),
69            // uv_transform used here for proportions only, but it is full Affine2
70            // that's why you can use rotation and shift also
71            uv_transform: Affine2::from_scale(Vec2::new(2., 3.)),
72            ..default()
73        })),
74        Transform::from_xyz(-RECTANGLE_OFFSET, 0.0, 0.0),
75        children![(
76            Text2d::new("Repeat On"),
77            Transform::from_xyz(0., LABEL_OFFSET, 0.),
78        )],
79    ));
80
81    // right rectangle with scaled texture, but with default sampler.
82    commands.spawn((
83        Mesh2d(meshes.add(Rectangle::new(RECTANGLE_SIDE, RECTANGLE_SIDE))),
84        MeshMaterial2d(materials.add(ColorMaterial {
85            // there is no sampler set, that's why
86            // by default you see only one small image in a row/column
87            // and other space is filled by image edge
88            texture: Some(image_with_default_sampler),
89
90            // uv_transform used here for proportions only, but it is full Affine2
91            // that's why you can use rotation and shift also
92            uv_transform: Affine2::from_scale(Vec2::new(2., 3.)),
93            ..default()
94        })),
95        Transform::from_xyz(RECTANGLE_OFFSET, 0.0, 0.0),
96        children![(
97            Text2d::new("Repeat Off"),
98            Transform::from_xyz(0., LABEL_OFFSET, 0.),
99        )],
100    ));
101
102    // camera
103    commands.spawn((
104        Camera2d,
105        Transform::default().looking_at(Vec3::ZERO, Vec3::Y),
106    ));
107}
Source

pub const fn from_rotation(rotation: Quat) -> Transform

Creates a new Transform, with rotation. Translation will be 0 and scale 1 on all axes.

Examples found in repository?
examples/remote/server.rs (line 35)
26fn setup(
27    mut commands: Commands,
28    mut meshes: ResMut<Assets<Mesh>>,
29    mut materials: ResMut<Assets<StandardMaterial>>,
30) {
31    // circular base
32    commands.spawn((
33        Mesh3d(meshes.add(Circle::new(4.0))),
34        MeshMaterial3d(materials.add(Color::WHITE)),
35        Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
36    ));
37
38    // cube
39    commands.spawn((
40        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
41        MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
42        Transform::from_xyz(0.0, 0.5, 0.0),
43        Cube(1.0),
44    ));
45
46    // test resource
47    commands.insert_resource(TestResource {
48        foo: Vec2::new(1.0, -1.0),
49        bar: false,
50    });
51
52    // light
53    commands.spawn((
54        PointLight {
55            shadows_enabled: true,
56            ..default()
57        },
58        Transform::from_xyz(4.0, 8.0, 4.0),
59    ));
60
61    // camera
62    commands.spawn((
63        Camera3d::default(),
64        Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
65    ));
66}
Source

pub const fn from_scale(scale: Vec3) -> Transform

Creates a new Transform, with scale. Translation will be 0 and rotation 0 on all axes.

Examples found in repository?
examples/2d/sprite_sheet.rs (line 63)
42fn setup(
43    mut commands: Commands,
44    asset_server: Res<AssetServer>,
45    mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
46) {
47    let texture = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
48    let layout = TextureAtlasLayout::from_grid(UVec2::splat(24), 7, 1, None, None);
49    let texture_atlas_layout = texture_atlas_layouts.add(layout);
50    // Use only the subset of sprites in the sheet that make up the run animation
51    let animation_indices = AnimationIndices { first: 1, last: 6 };
52
53    commands.spawn(Camera2d);
54
55    commands.spawn((
56        Sprite::from_atlas_image(
57            texture,
58            TextureAtlas {
59                layout: texture_atlas_layout,
60                index: animation_indices.first,
61            },
62        ),
63        Transform::from_scale(Vec3::splat(6.0)),
64        animation_indices,
65        AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
66    ));
67}
Source

pub fn from_isometry(iso: Isometry3d) -> Transform

Creates a new Transform that is equivalent to the given isometry.

Source

pub fn looking_at(self, target: Vec3, up: impl TryInto<Dir3>) -> Transform

Returns this Transform with a new rotation so that Transform::forward points towards the target position and Transform::up points towards up.

In some cases it’s not possible to construct a rotation. Another axis will be picked in those cases:

  • if target is the same as the transform translation, Vec3::Z is used instead
  • if up fails converting to Dir3 (e.g if it is Vec3::ZERO), Dir3::Y is used instead
  • if the resulting forward direction is parallel with up, an orthogonal vector is used as the “right” direction
Examples found in repository?
examples/gltf/gltf_skinned_mesh.rs (line 24)
20fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
21    // Create a camera
22    commands.spawn((
23        Camera3d::default(),
24        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::new(0.0, 1.0, 0.0), Vec3::Y),
25    ));
26
27    // Spawn the first scene in `models/SimpleSkin/SimpleSkin.gltf`
28    commands.spawn(SceneRoot(asset_server.load(
29        GltfAssetLabel::Scene(0).from_asset("models/SimpleSkin/SimpleSkin.gltf"),
30    )));
31}
More examples
Hide additional examples
examples/shader/shader_material_wesl.rs (line 69)
51fn setup(
52    mut commands: Commands,
53    mut meshes: ResMut<Assets<Mesh>>,
54    mut materials: ResMut<Assets<CustomMaterial>>,
55) {
56    // cube
57    commands.spawn((
58        Mesh3d(meshes.add(Cuboid::default())),
59        MeshMaterial3d(materials.add(CustomMaterial {
60            time: Vec4::ZERO,
61            party_mode: false,
62        })),
63        Transform::from_xyz(0.0, 0.5, 0.0),
64    ));
65
66    // camera
67    commands.spawn((
68        Camera3d::default(),
69        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
70    ));
71}
examples/shader/fallback_image.rs (line 43)
25fn setup(
26    mut commands: Commands,
27    mut meshes: ResMut<Assets<Mesh>>,
28    mut materials: ResMut<Assets<FallbackTestMaterial>>,
29) {
30    commands.spawn((
31        Mesh3d(meshes.add(Cuboid::default())),
32        MeshMaterial3d(materials.add(FallbackTestMaterial {
33            image_1d: None,
34            image_2d: None,
35            image_2d_array: None,
36            image_cube: None,
37            image_cube_array: None,
38            image_3d: None,
39        })),
40    ));
41    commands.spawn((
42        Camera3d::default(),
43        Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::new(1.5, 0.0, 0.0), Vec3::Y),
44    ));
45}
examples/shader/shader_material.rs (line 38)
18fn setup(
19    mut commands: Commands,
20    mut meshes: ResMut<Assets<Mesh>>,
21    mut materials: ResMut<Assets<CustomMaterial>>,
22    asset_server: Res<AssetServer>,
23) {
24    // cube
25    commands.spawn((
26        Mesh3d(meshes.add(Cuboid::default())),
27        MeshMaterial3d(materials.add(CustomMaterial {
28            color: LinearRgba::BLUE,
29            color_texture: Some(asset_server.load("branding/icon.png")),
30            alpha_mode: AlphaMode::Blend,
31        })),
32        Transform::from_xyz(0.0, 0.5, 0.0),
33    ));
34
35    // camera
36    commands.spawn((
37        Camera3d::default(),
38        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
39    ));
40}
examples/shader/shader_material_glsl.rs (line 39)
19fn setup(
20    mut commands: Commands,
21    mut meshes: ResMut<Assets<Mesh>>,
22    mut materials: ResMut<Assets<CustomMaterial>>,
23    asset_server: Res<AssetServer>,
24) {
25    // cube
26    commands.spawn((
27        Mesh3d(meshes.add(Cuboid::default())),
28        MeshMaterial3d(materials.add(CustomMaterial {
29            color: LinearRgba::BLUE,
30            color_texture: Some(asset_server.load("branding/icon.png")),
31            alpha_mode: AlphaMode::Blend,
32        })),
33        Transform::from_xyz(0.0, 0.5, 0.0),
34    ));
35
36    // camera
37    commands.spawn((
38        Camera3d::default(),
39        Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
40    ));
41}
examples/asset/hot_asset_reloading.rs (line 30)
17fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
18    // Load our mesh:
19    let scene_handle =
20        asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/torus/torus.gltf"));
21
22    // Any changes to the mesh will be reloaded automatically! Try making a change to torus.gltf.
23    // You should see the changes immediately show up in your app.
24
25    // mesh
26    commands.spawn(SceneRoot(scene_handle));
27    // light
28    commands.spawn((
29        DirectionalLight::default(),
30        Transform::from_xyz(4.0, 5.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
31    ));
32    // camera
33    commands.spawn((
34        Camera3d::default(),
35        Transform::from_xyz(2.0, 2.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
36    ));
37}
Source

pub fn looking_to( self, direction: impl TryInto<Dir3>, up: impl TryInto<Dir3>, ) -> Transform

Returns this Transform with a new rotation so that Transform::forward points in the given direction and Transform::up points towards up.

In some cases it’s not possible to construct a rotation. Another axis will be picked in those cases:

  • if direction fails converting to Dir3 (e.g if it is Vec3::ZERO), Dir3::Z is used instead
  • if up fails converting to Dir3, Dir3::Y is used instead
  • if direction is parallel with up, an orthogonal vector is used as the “right” direction
Source

pub fn aligned_by( self, main_axis: impl TryInto<Dir3>, main_direction: impl TryInto<Dir3>, secondary_axis: impl TryInto<Dir3>, secondary_direction: impl TryInto<Dir3>, ) -> Transform

Rotates this Transform so that the main_axis vector, reinterpreted in local coordinates, points in the given main_direction, while secondary_axis points towards secondary_direction. For example, if a spaceship model has its nose pointing in the X-direction in its own local coordinates and its dorsal fin pointing in the Y-direction, then align(Dir3::X, v, Dir3::Y, w) will make the spaceship’s nose point in the direction of v, while the dorsal fin does its best to point in the direction w.

In some cases a rotation cannot be constructed. Another axis will be picked in those cases:

  • if main_axis or main_direction fail converting to Dir3 (e.g are zero), Dir3::X takes their place
  • if secondary_axis or secondary_direction fail converting, Dir3::Y takes their place
  • if main_axis is parallel with secondary_axis or main_direction is parallel with secondary_direction, a rotation is constructed which takes main_axis to main_direction along a great circle, ignoring the secondary counterparts

See Transform::align for additional details.

Source

pub const fn with_translation(self, translation: Vec3) -> Transform

Returns this Transform with a new translation.

Source

pub const fn with_rotation(self, rotation: Quat) -> Transform

Returns this Transform with a new rotation.

Source

pub const fn with_scale(self, scale: Vec3) -> Transform

Returns this Transform with a new scale.

Examples found in repository?
examples/shader/shader_material_2d.rs (line 41)
25fn setup(
26    mut commands: Commands,
27    mut meshes: ResMut<Assets<Mesh>>,
28    mut materials: ResMut<Assets<CustomMaterial>>,
29    asset_server: Res<AssetServer>,
30) {
31    // camera
32    commands.spawn(Camera2d);
33
34    // quad
35    commands.spawn((
36        Mesh2d(meshes.add(Rectangle::default())),
37        MeshMaterial2d(materials.add(CustomMaterial {
38            color: LinearRgba::BLUE,
39            color_texture: Some(asset_server.load("branding/icon.png")),
40        })),
41        Transform::default().with_scale(Vec3::splat(128.)),
42    ));
43}
More examples
Hide additional examples
examples/3d/spherical_area_lights.rs (line 58)
16fn setup(
17    mut commands: Commands,
18    mut meshes: ResMut<Assets<Mesh>>,
19    mut materials: ResMut<Assets<StandardMaterial>>,
20) {
21    // camera
22    commands.spawn((
23        Camera3d::default(),
24        Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y),
25    ));
26
27    // plane
28    commands.spawn((
29        Mesh3d(meshes.add(Plane3d::default().mesh().size(100.0, 100.0))),
30        MeshMaterial3d(materials.add(StandardMaterial {
31            base_color: Color::srgb(0.2, 0.2, 0.2),
32            perceptual_roughness: 0.08,
33            ..default()
34        })),
35    ));
36
37    const COUNT: usize = 6;
38    let position_range = -2.0..2.0;
39    let radius_range = 0.0..0.4;
40    let pos_len = position_range.end - position_range.start;
41    let radius_len = radius_range.end - radius_range.start;
42    let mesh = meshes.add(Sphere::new(1.0).mesh().uv(120, 64));
43
44    for i in 0..COUNT {
45        let percent = i as f32 / COUNT as f32;
46        let radius = radius_range.start + percent * radius_len;
47
48        // sphere light
49        commands
50            .spawn((
51                Mesh3d(mesh.clone()),
52                MeshMaterial3d(materials.add(StandardMaterial {
53                    base_color: Color::srgb(0.5, 0.5, 1.0),
54                    unlit: true,
55                    ..default()
56                })),
57                Transform::from_xyz(position_range.start + percent * pos_len, 0.3, 0.0)
58                    .with_scale(Vec3::splat(radius)),
59            ))
60            .with_child(PointLight {
61                radius,
62                color: Color::srgb(0.2, 0.2, 1.0),
63                ..default()
64            });
65    }
66}
Source

pub fn to_matrix(&self) -> Mat4

Computes the 3d affine transformation matrix from this transform’s translation, rotation, and scale.

Source

pub fn compute_affine(&self) -> Affine3A

Returns the 3d affine transformation matrix from this transforms translation, rotation, and scale.

Source

pub fn local_x(&self) -> Dir3

Get the unit vector in the local X direction.

Source

pub fn left(&self) -> Dir3

Equivalent to -local_x()

Source

pub fn right(&self) -> Dir3

Equivalent to local_x()

Source

pub fn local_y(&self) -> Dir3

Get the unit vector in the local Y direction.

Source

pub fn up(&self) -> Dir3

Equivalent to local_y()

Source

pub fn down(&self) -> Dir3

Equivalent to -local_y()

Source

pub fn local_z(&self) -> Dir3

Get the unit vector in the local Z direction.

Source

pub fn forward(&self) -> Dir3

Equivalent to -local_z()

Source

pub fn back(&self) -> Dir3

Equivalent to local_z()

Source

pub fn rotate(&mut self, rotation: Quat)

Rotates this Transform by the given rotation.

If this Transform has a parent, the rotation is relative to the rotation of the parent.

§Examples
Examples found in repository?
examples/shader/shader_material_wesl.rs (line 87)
73fn update(
74    time: Res<Time>,
75    mut query: Query<(&MeshMaterial3d<CustomMaterial>, &mut Transform)>,
76    mut materials: ResMut<Assets<CustomMaterial>>,
77    keys: Res<ButtonInput<KeyCode>>,
78) {
79    for (material, mut transform) in query.iter_mut() {
80        let material = materials.get_mut(material).unwrap();
81        material.time.x = time.elapsed_secs();
82        if keys.just_pressed(KeyCode::Space) {
83            material.party_mode = !material.party_mode;
84        }
85
86        if material.party_mode {
87            transform.rotate(Quat::from_rotation_y(0.005));
88        }
89    }
90}
Source

pub fn rotate_axis(&mut self, axis: Dir3, angle: f32)

Rotates this Transform around the given axis by angle (in radians).

If this Transform has a parent, the axis is relative to the rotation of the parent.

§Warning

If you pass in an axis based on the current rotation (e.g. obtained via Transform::local_x), floating point errors can accumulate exponentially when applying rotations repeatedly this way. This will result in a denormalized rotation. In this case, it is recommended to normalize the Transform::rotation after each call to this method.

Source

pub fn rotate_x(&mut self, angle: f32)

Rotates this Transform around the X axis by angle (in radians).

If this Transform has a parent, the axis is relative to the rotation of the parent.

Examples found in repository?
examples/3d/parenting.rs (line 21)
19fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Rotator>>) {
20    for mut transform in &mut query {
21        transform.rotate_x(3.0 * time.delta_secs());
22    }
23}
Source

pub fn rotate_y(&mut self, angle: f32)

Rotates this Transform around the Y axis by angle (in radians).

If this Transform has a parent, the axis is relative to the rotation of the parent.

Source

pub fn rotate_z(&mut self, angle: f32)

Rotates this Transform around the Z axis by angle (in radians).

If this Transform has a parent, the axis is relative to the rotation of the parent.

Source

pub fn rotate_local(&mut self, rotation: Quat)

Rotates this Transform by the given rotation.

The rotation is relative to this Transform’s current rotation.

Source

pub fn rotate_local_axis(&mut self, axis: Dir3, angle: f32)

Rotates this Transform around its local axis by angle (in radians).

§Warning

If you pass in an axis based on the current rotation (e.g. obtained via Transform::local_x), floating point errors can accumulate exponentially when applying rotations repeatedly this way. This will result in a denormalized rotation. In this case, it is recommended to normalize the Transform::rotation after each call to this method.

Source

pub fn rotate_local_x(&mut self, angle: f32)

Rotates this Transform around its local X axis by angle (in radians).

Source

pub fn rotate_local_y(&mut self, angle: f32)

Rotates this Transform around its local Y axis by angle (in radians).

Source

pub fn rotate_local_z(&mut self, angle: f32)

Rotates this Transform around its local Z axis by angle (in radians).

Source

pub fn translate_around(&mut self, point: Vec3, rotation: Quat)

Translates this Transform around a point in space.

If this Transform has a parent, the point is relative to the Transform of the parent.

Source

pub fn rotate_around(&mut self, point: Vec3, rotation: Quat)

Rotates this Transform around a point in space.

If this Transform has a parent, the point is relative to the Transform of the parent.

Source

pub fn look_at(&mut self, target: Vec3, up: impl TryInto<Dir3>)

Rotates this Transform so that Transform::forward points towards the target position, and Transform::up points towards up.

In some cases it’s not possible to construct a rotation. Another axis will be picked in those cases:

  • if target is the same as the transform translation, Vec3::Z is used instead
  • if up fails converting to Dir3 (e.g if it is Vec3::ZERO), Dir3::Y is used instead
  • if the resulting forward direction is parallel with up, an orthogonal vector is used as the “right” direction
Source

pub fn look_to(&mut self, direction: impl TryInto<Dir3>, up: impl TryInto<Dir3>)

Rotates this Transform so that Transform::forward points in the given direction and Transform::up points towards up.

In some cases it’s not possible to construct a rotation. Another axis will be picked in those cases:

  • if direction fails converting to Dir3 (e.g if it is Vec3::ZERO), Dir3::NEG_Z is used instead
  • if up fails converting to Dir3, Dir3::Y is used instead
  • if direction is parallel with up, an orthogonal vector is used as the “right” direction
Source

pub fn align( &mut self, main_axis: impl TryInto<Dir3>, main_direction: impl TryInto<Dir3>, secondary_axis: impl TryInto<Dir3>, secondary_direction: impl TryInto<Dir3>, )

Rotates this Transform so that the main_axis vector, reinterpreted in local coordinates, points in the given main_direction, while secondary_axis points towards secondary_direction.

For example, if a spaceship model has its nose pointing in the X-direction in its own local coordinates and its dorsal fin pointing in the Y-direction, then align(Dir3::X, v, Dir3::Y, w) will make the spaceship’s nose point in the direction of v, while the dorsal fin does its best to point in the direction w.

More precisely, the Transform::rotation produced will be such that:

  • applying it to main_axis results in main_direction
  • applying it to secondary_axis produces a vector that lies in the half-plane generated by main_direction and secondary_direction (with positive contribution by secondary_direction)

Transform::look_to is recovered, for instance, when main_axis is Dir3::NEG_Z (the Transform::forward direction in the default orientation) and secondary_axis is Dir3::Y (the Transform::up direction in the default orientation). (Failure cases may differ somewhat.)

In some cases a rotation cannot be constructed. Another axis will be picked in those cases:

  • if main_axis or main_direction fail converting to Dir3 (e.g are zero), Dir3::X takes their place
  • if secondary_axis or secondary_direction fail converting, Dir3::Y takes their place
  • if main_axis is parallel with secondary_axis or main_direction is parallel with secondary_direction, a rotation is constructed which takes main_axis to main_direction along a great circle, ignoring the secondary counterparts

Example

t1.align(Dir3::X, Dir3::Y, Vec3::new(1., 1., 0.), Dir3::Z);
let main_axis_image = t1.rotation * Dir3::X;
let secondary_axis_image = t1.rotation * Vec3::new(1., 1., 0.);
assert!(main_axis_image.abs_diff_eq(Vec3::Y, 1e-5));
assert!(secondary_axis_image.abs_diff_eq(Vec3::new(0., 1., 1.), 1e-5));

t1.align(Vec3::ZERO, Dir3::Z, Vec3::ZERO, Dir3::X);
t2.align(Dir3::X, Dir3::Z, Dir3::Y, Dir3::X);
assert_eq!(t1.rotation, t2.rotation);

t1.align(Dir3::X, Dir3::Z, Dir3::X, Dir3::Y);
assert_eq!(t1.rotation, Quat::from_rotation_arc(Vec3::X, Vec3::Z));
Source

pub fn mul_transform(&self, transform: Transform) -> Transform

Multiplies self with transform component by component, returning the resulting Transform

Source

pub fn transform_point(&self, point: Vec3) -> Vec3

Transforms the given point, applying scale, rotation and translation.

If this Transform has an ancestor entity with a Transform component, Transform::transform_point will transform a point in local space into its parent transform’s space.

If this Transform does not have a parent, Transform::transform_point will transform a point in local space into worldspace coordinates.

If you always want to transform a point in local space to worldspace, or if you need the inverse transformations, see GlobalTransform::transform_point().

Source

pub fn is_finite(&self) -> bool

Returns true if, and only if, translation, rotation and scale all are finite. If any of them contains a NaN, positive or negative infinity, this will return false.

Source

pub fn to_isometry(&self) -> Isometry3d

Get the isometry defined by this transform’s rotation and translation, ignoring scale.

Trait Implementations§

Source§

impl Animatable for Transform

Source§

fn interpolate(a: &Transform, b: &Transform, t: f32) -> Transform

Interpolates between a and b with an interpolation factor of time. Read more
Source§

fn blend(inputs: impl Iterator<Item = BlendInput<Transform>>) -> Transform

Blends one or more values together. Read more
Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for Transform
where Transform: Send + Sync + 'static,

Required Components: GlobalTransform, TransformTreeChanged.

A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have Component<Mutability = Mutable>, while immutable components will instead have Component<Mutability = Immutable>. Read more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§

fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Transform>>

Returns ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read more
Source§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add ComponentHook for this Component if one is defined.
Source§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert ComponentHook for this Component if one is defined.
Source§

fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_replace ComponentHook for this Component if one is defined.
Source§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove ComponentHook for this Component if one is defined.
Source§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn ComponentHook for this Component if one is defined.
Source§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given EntityMapper. This is used to remap entities in contexts like scenes and entity cloning. When deriving Component, this is populated by annotating fields containing entities with #[entities] Read more
Source§

impl Debug for Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Transform

Source§

fn default() -> Transform

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Transform

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Transform, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<GlobalTransform> for Transform

The transform is expected to be non-degenerate and without shearing, or the output will be invalid.

Source§

fn from(transform: GlobalTransform) -> Transform

Converts to this type from the input type.
Source§

impl From<Transform> for GlobalTransform

Source§

fn from(transform: Transform) -> GlobalTransform

Converts to this type from the input type.
Source§

impl FromArg for Transform

Source§

type This<'from_arg> = Transform

The type to convert into. Read more
Source§

fn from_arg(arg: Arg<'_>) -> Result<<Transform as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromReflect for Transform

Source§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Transform>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetOwnership for Transform

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetTypeRegistration for Transform

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl IntoReturn for Transform

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where Transform: 'into_return,

Converts Self into a Return value.
Source§

impl Mul<GlobalTransform> for Transform

Source§

type Output = GlobalTransform

The resulting type after applying the * operator.
Source§

fn mul( self, global_transform: GlobalTransform, ) -> <Transform as Mul<GlobalTransform>>::Output

Performs the * operation. Read more
Source§

impl Mul<Mesh> for Transform

Source§

type Output = Mesh

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mesh) -> <Transform as Mul<Mesh>>::Output

Performs the * operation. Read more
Source§

impl Mul<Transform> for GlobalTransform

Source§

type Output = GlobalTransform

The resulting type after applying the * operator.
Source§

fn mul( self, transform: Transform, ) -> <GlobalTransform as Mul<Transform>>::Output

Performs the * operation. Read more
Source§

impl Mul<Vec3> for Transform

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

fn mul(self, value: Vec3) -> <Transform as Mul<Vec3>>::Output

Performs the * operation. Read more
Source§

impl Mul for Transform

Source§

type Output = Transform

The resulting type after applying the * operator.
Source§

fn mul(self, transform: Transform) -> <Transform as Mul>::Output

Performs the * operation. Read more
Source§

impl PartialEq for Transform

Source§

fn eq(&self, other: &Transform) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialReflect for Transform

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<Transform>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn try_into_reflect( self: Box<Transform>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>

Attempts to cast this type to a boxed, fully-reflected value.
Source§

fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>

Attempts to cast this type to a fully-reflected value.
Source§

fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>

Attempts to cast this type to a mutable, fully-reflected value.
Source§

fn into_partial_reflect(self: Box<Transform>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)

Casts this type to a reflected value. Read more
Source§

fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)

Casts this type to a mutable, reflected value. Read more
Source§

fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Debug formatter for the value. Read more
Source§

fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>

Attempts to clone Self using reflection. Read more
Source§

fn apply(&mut self, value: &(dyn PartialReflect + 'static))

Applies a reflected value to this value. Read more
Source§

fn to_dynamic(&self) -> Box<dyn PartialReflect>

Converts this reflected value into its dynamic representation based on its kind. Read more
Source§

fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
where T: 'static, Self: Sized + TypePath,

For a type implementing PartialReflect, combines reflect_clone and take in a useful fashion, automatically constructing an appropriate ReflectCloneError if the downcast fails. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Reflect for Transform

Source§

fn into_any(self: Box<Transform>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<Transform>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a fully-reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl Serialize for Transform

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Struct for Transform

Source§

fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field named name as a &dyn PartialReflect.
Source§

fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field named name as a &mut dyn PartialReflect.
Source§

fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn PartialReflect.
Source§

fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field with index index as a &mut dyn PartialReflect.
Source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
Source§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
Source§

fn to_dynamic_struct(&self) -> DynamicStruct

Creates a new DynamicStruct from this struct.
Source§

fn get_represented_struct_info(&self) -> Option<&'static StructInfo>

Will return None if TypeInfo is not available.
Source§

impl TransformPoint for Transform

Source§

fn transform_point(&self, point: impl Into<Vec3>) -> Vec3

Transform a point.
Source§

impl TypePath for Transform

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
Source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for Transform

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.
Source§

impl Copy for Transform

Source§

impl StructuralPartialEq for Transform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>

Source§

fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>

Return a iterator over this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<C> BundleFromComponents for C
where C: Component,

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
Source§

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
Source§

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> DynamicTyped for T
where T: Typed,

Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<S> GetField for S
where S: Struct,

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
Source§

fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
Source§

fn path<'p, T>( &self, path: impl ReflectPath<'p>, ) -> Result<&T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
Source§

fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Reflectable for T

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,