Struct bevy::prelude::Gizmos

pub struct Gizmos<'w, 's, Config = DefaultGizmoConfigGroup, Clear = ()>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,
{ pub config: &'w GizmoConfig, pub config_ext: &'w Config, /* private fields */ }
Expand description

A SystemParam for drawing gizmos.

They are drawn in immediate mode, which means they will be rendered only for the frames, or ticks when in FixedMain, in which they are spawned.

A system in Main will be cleared each rendering frame, while a system in FixedMain will be cleared each time the RunFixedMainLoop schedule is run.

Gizmos should be spawned before the Last schedule to ensure they are drawn.

To set up your own clearing context (useful for custom scheduling similar to FixedMain):

use bevy_gizmos::{prelude::*, *, gizmos::GizmoStorage};
struct ClearContextSetup;
impl Plugin for ClearContextSetup {
    fn build(&self, app: &mut App) {
        app.init_resource::<GizmoStorage<DefaultGizmoConfigGroup, MyContext>>()
           // Make sure this context starts/ends cleanly if inside another context. E.g. it
           // should start after the parent context starts and end after the parent context ends.
           .add_systems(StartOfMyContext, start_gizmo_context::<DefaultGizmoConfigGroup, MyContext>)
           // If not running multiple times, put this with [`start_gizmo_context`].
           .add_systems(StartOfRun, clear_gizmo_context::<DefaultGizmoConfigGroup, MyContext>)
           // If not running multiple times, put this with [`end_gizmo_context`].
           .add_systems(EndOfRun, collect_requested_gizmos::<DefaultGizmoConfigGroup, MyContext>)
           .add_systems(EndOfMyContext, end_gizmo_context::<DefaultGizmoConfigGroup, MyContext>)
           .add_systems(
               Last,
               propagate_gizmos::<DefaultGizmoConfigGroup, MyContext>.before(UpdateGizmoMeshes),
           );
    }
}

Fields§

§config: &'w GizmoConfig

The currently used GizmoConfig

§config_ext: &'w Config

The currently used GizmoConfigGroup

Implementations§

§

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

pub fn arc_2d( &mut self, position: Vec2, direction_angle: f32, arc_angle: f32, radius: f32, color: impl Into<Color> ) -> Arc2dBuilder<'_, 'w, 's, Config, Clear>

Draw an arc, which is a part of the circumference of a circle, in 2D.

This should be called for each frame the arc needs to be rendered.

§Arguments
  • position sets the center of this circle.
  • direction_angle sets the clockwise angle in radians between Vec2::Y and the vector from position to the midpoint of the arc.
  • arc_angle sets the length of this arc, in radians.
  • radius controls the distance from position to this arc, and thus its curvature.
  • color sets the color to draw the arc.
§Example
fn system(mut gizmos: Gizmos) {
    gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., GREEN);

    // Arcs have 32 line-segments by default.
    // You may want to increase this for larger arcs.
    gizmos
        .arc_2d(Vec2::ZERO, 0., PI / 4., 5., RED)
        .segments(64);
}
Examples found in repository?
examples/gizmos/2d_gizmos.rs (line 85)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}
§

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

pub fn arc_3d( &mut self, angle: f32, radius: f32, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> Arc3dBuilder<'_, 'w, 's, Config, Clear>

Draw an arc, which is a part of the circumference of a circle, in 3D. For default values this is drawing a standard arc. A standard arc is defined as

  • an arc with a center at Vec3::ZERO
  • starting at Vec3::X
  • embedded in the XZ plane
  • rotates counterclockwise

This should be called for each frame the arc needs to be rendered.

§Arguments
  • angle: sets how much of a circle circumference is passed, e.g. PI is half a circle. This value should be in the range (-2 * PI..=2 * PI)
  • radius: distance between the arc and its center point
  • position: position of the arcs center point
  • rotation: defines orientation of the arc, by default we assume the arc is contained in a plane parallel to the XZ plane and the default starting point is (position + Vec3::X)
  • color: color of the arc
§Builder methods

The number of segments of the arc (i.e. the level of detail) can be adjusted with the .segments(...) method.

§Example
fn system(mut gizmos: Gizmos) {
    // rotation rotates normal to point in the direction of `Vec3::NEG_ONE`
    let rotation = Quat::from_rotation_arc(Vec3::Y, Vec3::NEG_ONE.normalize());

    gizmos
       .arc_3d(
         270.0_f32.to_radians(),
         0.25,
         Vec3::ONE,
         rotation,
         ORANGE
         )
         .segments(100);
}
Examples found in repository?
examples/gizmos/3d_gizmos.rs (lines 120-126)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn short_arc_3d_between( &mut self, center: Vec3, from: Vec3, to: Vec3, color: impl Into<Color> ) -> Arc3dBuilder<'_, 'w, 's, Config, Clear>

Draws the shortest arc between two points (from and to) relative to a specified center point.

§Arguments
  • center: The center point around which the arc is drawn.
  • from: The starting point of the arc.
  • to: The ending point of the arc.
  • color: color of the arc
§Builder methods

The number of segments of the arc (i.e. the level of detail) can be adjusted with the .segments(...) method.

§Examples
fn system(mut gizmos: Gizmos) {
    gizmos.short_arc_3d_between(
       Vec3::ONE,
       Vec3::ONE + Vec3::NEG_ONE,
       Vec3::ZERO,
       ORANGE
       )
       .segments(100);
}
§Notes
  • This method assumes that the points from and to are distinct from center. If one of the points is coincident with center, nothing is rendered.
  • The arc is drawn as a portion of a circle with a radius equal to the distance from the center to from. If the distance from center to to is not equal to the radius, then the results will behave as if this were the case

pub fn long_arc_3d_between( &mut self, center: Vec3, from: Vec3, to: Vec3, color: impl Into<Color> ) -> Arc3dBuilder<'_, 'w, 's, Config, Clear>

Draws the longest arc between two points (from and to) relative to a specified center point.

§Arguments
  • center: The center point around which the arc is drawn.
  • from: The starting point of the arc.
  • to: The ending point of the arc.
  • color: color of the arc
§Builder methods

The number of segments of the arc (i.e. the level of detail) can be adjusted with the .segments(...) method.

§Examples
fn system(mut gizmos: Gizmos) {
    gizmos.long_arc_3d_between(
       Vec3::ONE,
       Vec3::ONE + Vec3::NEG_ONE,
       Vec3::ZERO,
       ORANGE
       )
       .segments(100);
}
§Notes
  • This method assumes that the points from and to are distinct from center. If one of the points is coincident with center, nothing is rendered.
  • The arc is drawn as a portion of a circle with a radius equal to the distance from the center to from. If the distance from center to to is not equal to the radius, then the results will behave as if this were the case.
§

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

pub fn arrow( &mut self, start: Vec3, end: Vec3, color: impl Into<Color> ) -> ArrowBuilder<'_, 'w, 's, Config, Clear>

Draw an arrow in 3D, from start to end. Has four tips for convenient viewing from any direction.

This should be called for each frame the arrow needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.arrow(Vec3::ZERO, Vec3::ONE, GREEN);
}
Examples found in repository?
examples/transforms/align.rs (line 137)
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
fn draw_cube_axes(mut gizmos: Gizmos, query: Query<&Transform, With<Cube>>) {
    let cube_transform = query.single();

    // Local X-axis arrow
    let x_ends = arrow_ends(cube_transform, Vec3::X, 1.5);
    gizmos.arrow(x_ends.0, x_ends.1, RED);

    // local Y-axis arrow
    let y_ends = arrow_ends(cube_transform, Vec3::Y, 1.5);
    gizmos.arrow(y_ends.0, y_ends.1, Color::srgb(0.65, 0., 0.));
}

// Draw the randomly generated axes
fn draw_random_axes(mut gizmos: Gizmos, query: Query<&RandomAxes>) {
    let RandomAxes(v1, v2) = query.single();
    gizmos.arrow(Vec3::ZERO, 1.5 * *v1, WHITE);
    gizmos.arrow(Vec3::ZERO, 1.5 * *v2, GRAY);
}
More examples
Hide additional examples
examples/gizmos/3d_gizmos.rs (line 139)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn arrow_2d( &mut self, start: Vec2, end: Vec2, color: impl Into<Color> ) -> ArrowBuilder<'_, 'w, 's, Config, Clear>

Draw an arrow in 2D (on the xy plane), from start to end.

This should be called for each frame the arrow needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.arrow_2d(Vec2::ZERO, Vec2::X, GREEN);
}
Examples found in repository?
examples/gizmos/2d_gizmos.rs (lines 87-91)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}
§

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

pub fn axes(&mut self, transform: impl TransformPoint, base_length: f32)

Draw a set of axes local to the given transform (transform), with length scaled by a factor of base_length.

This should be called for each frame the axes need to be rendered.

§Example
fn draw_axes(
    mut gizmos: Gizmos,
    query: Query<&Transform, With<MyComponent>>,
) {
    for &transform in &query {
        gizmos.axes(transform, 1.);
    }
}
Examples found in repository?
examples/gizmos/axes.rs (line 110)
107
108
109
110
111
112
fn draw_axes(mut gizmos: Gizmos, query: Query<(&Transform, &Aabb), With<ShowAxes>>) {
    for (&transform, &aabb) in &query {
        let length = aabb.half_extents.length();
        gizmos.axes(transform, length);
    }
}
§

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

pub fn ellipse( &mut self, position: Vec3, rotation: Quat, half_size: Vec2, color: impl Into<Color> ) -> EllipseBuilder<'_, 'w, 's, Config, Clear>

Draw an ellipse in 3D at position with the flat side facing normal.

This should be called for each frame the ellipse needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(1., 2.), GREEN);

    // Ellipses have 32 line-segments by default.
    // You may want to increase this for larger ellipses.
    gizmos
        .ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(5., 1.), RED)
        .segments(64);
}

pub fn ellipse_2d( &mut self, position: Vec2, angle: f32, half_size: Vec2, color: impl Into<Color> ) -> Ellipse2dBuilder<'_, 'w, 's, Config, Clear>

Draw an ellipse in 2D.

This should be called for each frame the ellipse needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(2., 1.), GREEN);

    // Ellipses have 32 line-segments by default.
    // You may want to increase this for larger ellipses.
    gizmos
        .ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(5., 1.), RED)
        .segments(64);
}
Examples found in repository?
examples/gizmos/2d_gizmos.rs (lines 74-79)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}

pub fn circle( &mut self, position: Vec3, normal: Dir3, radius: f32, color: impl Into<Color> ) -> EllipseBuilder<'_, 'w, 's, Config, Clear>

Draw a circle in 3D at position with the flat side facing normal.

This should be called for each frame the circle needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.circle(Vec3::ZERO, Dir3::Z, 1., GREEN);

    // Circles have 32 line-segments by default.
    // You may want to increase this for larger circles.
    gizmos
        .circle(Vec3::ZERO, Dir3::Z, 5., RED)
        .segments(64);
}
Examples found in repository?
examples/3d/3d_viewport_to_world.rs (line 40)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn draw_cursor(
    camera_query: Query<(&Camera, &GlobalTransform)>,
    ground_query: Query<&GlobalTransform, With<Ground>>,
    windows: Query<&Window>,
    mut gizmos: Gizmos,
) {
    let (camera, camera_transform) = camera_query.single();
    let ground = ground_query.single();

    let Some(cursor_position) = windows.single().cursor_position() else {
        return;
    };

    // Calculate a ray pointing from the camera into the world based on the cursor's position.
    let Some(ray) = camera.viewport_to_world(camera_transform, cursor_position) else {
        return;
    };

    // Calculate if and where the ray is hitting the ground plane.
    let Some(distance) =
        ray.intersect_plane(ground.translation(), InfinitePlane3d::new(ground.up()))
    else {
        return;
    };
    let point = ray.get_point(distance);

    // Draw a circle just above the ground plane at that position.
    gizmos.circle(point + ground.up() * 0.01, ground.up(), 0.2, Color::WHITE);
}
More examples
Hide additional examples
examples/gizmos/3d_gizmos.rs (line 130)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn circle_2d( &mut self, position: Vec2, radius: f32, color: impl Into<Color> ) -> Ellipse2dBuilder<'_, 'w, 's, Config, Clear>

Draw a circle in 2D.

This should be called for each frame the circle needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.circle_2d(Vec2::ZERO, 1., GREEN);

    // Circles have 32 line-segments by default.
    // You may want to increase this for larger circles.
    gizmos
        .circle_2d(Vec2::ZERO, 5., RED)
        .segments(64);
}
Examples found in repository?
examples/2d/bounding_2d.rs (line 186)
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
fn render_volumes(mut gizmos: Gizmos, query: Query<(&CurrentVolume, &Intersects)>) {
    for (volume, intersects) in query.iter() {
        let color = if **intersects { AQUA } else { ORANGE_RED };
        match volume {
            CurrentVolume::Aabb(a) => {
                gizmos.rect_2d(a.center(), 0., a.half_size() * 2., color);
            }
            CurrentVolume::Circle(c) => {
                gizmos.circle_2d(c.center(), c.radius(), color);
            }
        }
    }
}

#[derive(Component, Deref, DerefMut, Default)]
struct Intersects(bool);

const OFFSET_X: f32 = 125.;
const OFFSET_Y: f32 = 75.;

fn setup(mut commands: Commands, loader: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(-OFFSET_X, OFFSET_Y, 0.),
            ..default()
        },
        Shape::Circle(Circle::new(45.)),
        DesiredVolume::Aabb,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(0., OFFSET_Y, 0.),
            ..default()
        },
        Shape::Rectangle(Rectangle::new(80., 80.)),
        Spin,
        DesiredVolume::Circle,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(OFFSET_X, OFFSET_Y, 0.),
            ..default()
        },
        Shape::Triangle(Triangle2d::new(
            Vec2::new(-40., -40.),
            Vec2::new(-20., 40.),
            Vec2::new(40., 50.),
        )),
        Spin,
        DesiredVolume::Aabb,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(-OFFSET_X, -OFFSET_Y, 0.),
            ..default()
        },
        Shape::Line(Segment2d::new(Dir2::from_xy(1., 0.3).unwrap(), 90.)),
        Spin,
        DesiredVolume::Circle,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(0., -OFFSET_Y, 0.),
            ..default()
        },
        Shape::Capsule(Capsule2d::new(25., 50.)),
        Spin,
        DesiredVolume::Aabb,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(OFFSET_X, -OFFSET_Y, 0.),
            ..default()
        },
        Shape::Polygon(RegularPolygon::new(50., 6)),
        Spin,
        DesiredVolume::Circle,
        Intersects::default(),
    ));

    commands.spawn(
        TextBundle::from_section(
            "",
            TextStyle {
                font: loader.load("fonts/FiraMono-Medium.ttf"),
                font_size: 26.0,
                ..default()
            },
        )
        .with_style(Style {
            position_type: PositionType::Absolute,
            bottom: Val::Px(10.0),
            left: Val::Px(10.0),
            ..default()
        }),
    );
}

fn draw_filled_circle(gizmos: &mut Gizmos, position: Vec2, color: Srgba) {
    for r in [1., 2., 3.] {
        gizmos.circle_2d(position, r, color);
    }
}

fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) {
    gizmos.line_2d(
        ray.ray.origin,
        ray.ray.origin + *ray.ray.direction * ray.max,
        WHITE,
    );
    draw_filled_circle(gizmos, ray.ray.origin, FUCHSIA);
}

fn get_and_draw_ray(gizmos: &mut Gizmos, time: &Time) -> RayCast2d {
    let ray = Vec2::new(time.elapsed_seconds().cos(), time.elapsed_seconds().sin());
    let dist = 150. + (0.5 * time.elapsed_seconds()).sin().abs() * 500.;

    let aabb_ray = Ray2d {
        origin: ray * 250.,
        direction: Dir2::new_unchecked(-ray),
    };
    let ray_cast = RayCast2d::from_ray(aabb_ray, dist - 20.);

    draw_ray(gizmos, &ray_cast);
    ray_cast
}

fn ray_cast_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let ray_cast = get_and_draw_ray(&mut gizmos, &time);

    for (volume, mut intersects) in volumes.iter_mut() {
        let toi = match volume {
            CurrentVolume::Aabb(a) => ray_cast.aabb_intersection_at(a),
            CurrentVolume::Circle(c) => ray_cast.circle_intersection_at(c),
        };
        **intersects = toi.is_some();
        if let Some(toi) = toi {
            draw_filled_circle(
                &mut gizmos,
                ray_cast.ray.origin + *ray_cast.ray.direction * toi,
                LIME,
            );
        }
    }
}

fn aabb_cast_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let ray_cast = get_and_draw_ray(&mut gizmos, &time);
    let aabb_cast = AabbCast2d {
        aabb: Aabb2d::new(Vec2::ZERO, Vec2::splat(15.)),
        ray: ray_cast,
    };

    for (volume, mut intersects) in volumes.iter_mut() {
        let toi = match *volume {
            CurrentVolume::Aabb(a) => aabb_cast.aabb_collision_at(a),
            CurrentVolume::Circle(_) => None,
        };

        **intersects = toi.is_some();
        if let Some(toi) = toi {
            gizmos.rect_2d(
                aabb_cast.ray.ray.origin + *aabb_cast.ray.ray.direction * toi,
                0.,
                aabb_cast.aabb.half_size() * 2.,
                LIME,
            );
        }
    }
}

fn bounding_circle_cast_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let ray_cast = get_and_draw_ray(&mut gizmos, &time);
    let circle_cast = BoundingCircleCast {
        circle: BoundingCircle::new(Vec2::ZERO, 15.),
        ray: ray_cast,
    };

    for (volume, mut intersects) in volumes.iter_mut() {
        let toi = match *volume {
            CurrentVolume::Aabb(_) => None,
            CurrentVolume::Circle(c) => circle_cast.circle_collision_at(c),
        };

        **intersects = toi.is_some();
        if let Some(toi) = toi {
            gizmos.circle_2d(
                circle_cast.ray.ray.origin + *circle_cast.ray.ray.direction * toi,
                circle_cast.circle.radius(),
                LIME,
            );
        }
    }
}

fn get_intersection_position(time: &Time) -> Vec2 {
    let x = (0.8 * time.elapsed_seconds()).cos() * 250.;
    let y = (0.4 * time.elapsed_seconds()).sin() * 100.;
    Vec2::new(x, y)
}

fn aabb_intersection_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let center = get_intersection_position(&time);
    let aabb = Aabb2d::new(center, Vec2::splat(50.));
    gizmos.rect_2d(center, 0., aabb.half_size() * 2., YELLOW);

    for (volume, mut intersects) in volumes.iter_mut() {
        let hit = match volume {
            CurrentVolume::Aabb(a) => aabb.intersects(a),
            CurrentVolume::Circle(c) => aabb.intersects(c),
        };

        **intersects = hit;
    }
}

fn circle_intersection_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let center = get_intersection_position(&time);
    let circle = BoundingCircle::new(center, 50.);
    gizmos.circle_2d(center, circle.radius(), YELLOW);

    for (volume, mut intersects) in volumes.iter_mut() {
        let hit = match volume {
            CurrentVolume::Aabb(a) => circle.intersects(a),
            CurrentVolume::Circle(c) => circle.intersects(c),
        };

        **intersects = hit;
    }
}
More examples
Hide additional examples
examples/2d/2d_viewport_to_world.rs (line 29)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn draw_cursor(
    camera_query: Query<(&Camera, &GlobalTransform)>,
    windows: Query<&Window>,
    mut gizmos: Gizmos,
) {
    let (camera, camera_transform) = camera_query.single();

    let Some(cursor_position) = windows.single().cursor_position() else {
        return;
    };

    // Calculate a world position based on the cursor's position.
    let Some(point) = camera.viewport_to_world_2d(camera_transform, cursor_position) else {
        return;
    };

    gizmos.circle_2d(point, 10., WHITE);
}
examples/gizmos/2d_gizmos.rs (line 73)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}
§

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

pub fn line(&mut self, start: Vec3, end: Vec3, color: impl Into<Color>)

Draw a line in 3D from start to end.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.line(Vec3::ZERO, Vec3::X, GREEN);
}
Examples found in repository?
examples/stress_tests/many_gizmos.rs (line 67)
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn system(config: Res<Config>, time: Res<Time>, mut draw: Gizmos) {
    if !config.fancy {
        for _ in 0..(config.line_count / SYSTEM_COUNT) {
            draw.line(Vec3::NEG_Y, Vec3::Y, Color::BLACK);
        }
    } else {
        for i in 0..(config.line_count / SYSTEM_COUNT) {
            let angle = i as f32 / (config.line_count / SYSTEM_COUNT) as f32 * TAU;

            let vector = Vec2::from(angle.sin_cos()).extend(time.elapsed_seconds().sin());
            let start_color = LinearRgba::rgb(vector.x, vector.z, 0.5);
            let end_color = LinearRgba::rgb(-vector.z, -vector.y, 0.5);

            draw.line_gradient(vector, -vector, start_color, end_color);
        }
    }
}

pub fn line_gradient<C>( &mut self, start: Vec3, end: Vec3, start_color: C, end_color: C )
where C: Into<Color>,

Draw a line in 3D with a color gradient from start to end.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.line_gradient(Vec3::ZERO, Vec3::X, GREEN, RED);
}
Examples found in repository?
examples/stress_tests/many_gizmos.rs (line 77)
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn system(config: Res<Config>, time: Res<Time>, mut draw: Gizmos) {
    if !config.fancy {
        for _ in 0..(config.line_count / SYSTEM_COUNT) {
            draw.line(Vec3::NEG_Y, Vec3::Y, Color::BLACK);
        }
    } else {
        for i in 0..(config.line_count / SYSTEM_COUNT) {
            let angle = i as f32 / (config.line_count / SYSTEM_COUNT) as f32 * TAU;

            let vector = Vec2::from(angle.sin_cos()).extend(time.elapsed_seconds().sin());
            let start_color = LinearRgba::rgb(vector.x, vector.z, 0.5);
            let end_color = LinearRgba::rgb(-vector.z, -vector.y, 0.5);

            draw.line_gradient(vector, -vector, start_color, end_color);
        }
    }
}

pub fn ray(&mut self, start: Vec3, vector: Vec3, color: impl Into<Color>)

Draw a line in 3D from start to start + vector.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.ray(Vec3::Y, Vec3::X, GREEN);
}
Examples found in repository?
examples/gizmos/3d_gizmos.rs (lines 112-116)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn ray_gradient<C>( &mut self, start: Vec3, vector: Vec3, start_color: C, end_color: C )
where C: Into<Color>,

Draw a line in 3D with a color gradient from start to start + vector.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.ray_gradient(Vec3::Y, Vec3::X, GREEN, RED);
}

pub fn linestrip( &mut self, positions: impl IntoIterator<Item = Vec3>, color: impl Into<Color> )

Draw a line in 3D made of straight segments between the points.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.linestrip([Vec3::ZERO, Vec3::X, Vec3::Y], GREEN);
}
Examples found in repository?
examples/animation/cubic_curve.rs (line 81)
76
77
78
79
80
81
82
83
84
85
86
fn animate_cube(time: Res<Time>, mut query: Query<(&mut Transform, &Curve)>, mut gizmos: Gizmos) {
    let t = (time.elapsed_seconds().sin() + 1.) / 2.;

    for (mut transform, cubic_curve) in &mut query {
        // Draw the curve
        gizmos.linestrip(cubic_curve.0.iter_positions(50), WHITE);
        // position takes a point from the curve where 0 is the initial point
        // and 1 is the last point
        transform.translation = cubic_curve.0.position(t);
    }
}

pub fn linestrip_gradient<C>( &mut self, points: impl IntoIterator<Item = (Vec3, C)> )
where C: Into<Color>,

Draw a line in 3D made of straight segments between the points, with a color gradient.

This should be called for each frame the lines need to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.linestrip_gradient([
        (Vec3::ZERO, GREEN),
        (Vec3::X, RED),
        (Vec3::Y, BLUE)
    ]);
}

pub fn sphere( &mut self, position: Vec3, rotation: Quat, radius: f32, color: impl Into<Color> ) -> SphereBuilder<'_, 'w, 's, Config, Clear>

Draw a wireframe sphere in 3D made out of 3 circles around the axes.

This should be called for each frame the sphere needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.sphere(Vec3::ZERO, Quat::IDENTITY, 1., Color::BLACK);

    // Each circle has 32 line-segments by default.
    // You may want to increase this for larger spheres.
    gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 5., Color::BLACK)
        .circle_segments(64);
}
Examples found in repository?
examples/gizmos/3d_gizmos.rs (line 109)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn rect( &mut self, position: Vec3, rotation: Quat, size: Vec2, color: impl Into<Color> )

Draw a wireframe rectangle in 3D.

This should be called for each frame the rectangle needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.rect(Vec3::ZERO, Quat::IDENTITY, Vec2::ONE, GREEN);
}
Examples found in repository?
examples/gizmos/3d_gizmos.rs (lines 102-107)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn cuboid( &mut self, transform: impl TransformPoint, color: impl Into<Color> )

Draw a wireframe cube in 3D.

This should be called for each frame the cube needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.cuboid(Transform::IDENTITY, GREEN);
}
Examples found in repository?
examples/3d/irradiance_volumes.rs (line 635)
628
629
630
631
632
633
634
635
636
637
638
fn draw_gizmo(
    mut gizmos: Gizmos,
    irradiance_volume_query: Query<&GlobalTransform, With<IrradianceVolume>>,
    app_status: Res<AppStatus>,
) {
    if app_status.voxels_visible {
        for transform in irradiance_volume_query.iter() {
            gizmos.cuboid(*transform, GIZMO_COLOR);
        }
    }
}
More examples
Hide additional examples
examples/gizmos/3d_gizmos.rs (lines 98-101)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn line_2d(&mut self, start: Vec2, end: Vec2, color: impl Into<Color>)

Draw a line in 2D from start to end.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.line_2d(Vec2::ZERO, Vec2::X, GREEN);
}
Examples found in repository?
examples/2d/bounding_2d.rs (lines 294-298)
293
294
295
296
297
298
299
300
fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) {
    gizmos.line_2d(
        ray.ray.origin,
        ray.ray.origin + *ray.ray.direction * ray.max,
        WHITE,
    );
    draw_filled_circle(gizmos, ray.ray.origin, FUCHSIA);
}
More examples
Hide additional examples
examples/gizmos/2d_gizmos.rs (line 43)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}

pub fn line_gradient_2d<C>( &mut self, start: Vec2, end: Vec2, start_color: C, end_color: C )
where C: Into<Color>,

Draw a line in 2D with a color gradient from start to end.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.line_gradient_2d(Vec2::ZERO, Vec2::X, GREEN, RED);
}

pub fn linestrip_2d( &mut self, positions: impl IntoIterator<Item = Vec2>, color: impl Into<Color> )

Draw a line in 2D made of straight segments between the points.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.linestrip_2d([Vec2::ZERO, Vec2::X, Vec2::Y], GREEN);
}

pub fn linestrip_gradient_2d<C>( &mut self, positions: impl IntoIterator<Item = (Vec2, C)> )
where C: Into<Color>,

Draw a line in 2D made of straight segments between the points, with a color gradient.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.linestrip_gradient_2d([
        (Vec2::ZERO, GREEN),
        (Vec2::X, RED),
        (Vec2::Y, BLUE)
    ]);
}
Examples found in repository?
examples/gizmos/2d_gizmos.rs (lines 58-63)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}

pub fn ray_2d(&mut self, start: Vec2, vector: Vec2, color: impl Into<Color>)

Draw a line in 2D from start to start + vector.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.ray_2d(Vec2::Y, Vec2::X, GREEN);
}
Examples found in repository?
examples/gizmos/2d_gizmos.rs (line 44)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}

pub fn ray_gradient_2d<C>( &mut self, start: Vec2, vector: Vec2, start_color: C, end_color: C )
where C: Into<Color>,

Draw a line in 2D with a color gradient from start to start + vector.

This should be called for each frame the line needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.line_gradient(Vec3::Y, Vec3::X, GREEN, RED);
}

pub fn rect_2d( &mut self, position: Vec2, rotation: impl Into<Rotation2d>, size: Vec2, color: impl Into<Color> )

Draw a wireframe rectangle in 2D.

This should be called for each frame the rectangle needs to be rendered.

§Example
fn system(mut gizmos: Gizmos) {
    gizmos.rect_2d(Vec2::ZERO, 0., Vec2::ONE, GREEN);
}
Examples found in repository?
examples/2d/bounding_2d.rs (line 183)
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
fn render_volumes(mut gizmos: Gizmos, query: Query<(&CurrentVolume, &Intersects)>) {
    for (volume, intersects) in query.iter() {
        let color = if **intersects { AQUA } else { ORANGE_RED };
        match volume {
            CurrentVolume::Aabb(a) => {
                gizmos.rect_2d(a.center(), 0., a.half_size() * 2., color);
            }
            CurrentVolume::Circle(c) => {
                gizmos.circle_2d(c.center(), c.radius(), color);
            }
        }
    }
}

#[derive(Component, Deref, DerefMut, Default)]
struct Intersects(bool);

const OFFSET_X: f32 = 125.;
const OFFSET_Y: f32 = 75.;

fn setup(mut commands: Commands, loader: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(-OFFSET_X, OFFSET_Y, 0.),
            ..default()
        },
        Shape::Circle(Circle::new(45.)),
        DesiredVolume::Aabb,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(0., OFFSET_Y, 0.),
            ..default()
        },
        Shape::Rectangle(Rectangle::new(80., 80.)),
        Spin,
        DesiredVolume::Circle,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(OFFSET_X, OFFSET_Y, 0.),
            ..default()
        },
        Shape::Triangle(Triangle2d::new(
            Vec2::new(-40., -40.),
            Vec2::new(-20., 40.),
            Vec2::new(40., 50.),
        )),
        Spin,
        DesiredVolume::Aabb,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(-OFFSET_X, -OFFSET_Y, 0.),
            ..default()
        },
        Shape::Line(Segment2d::new(Dir2::from_xy(1., 0.3).unwrap(), 90.)),
        Spin,
        DesiredVolume::Circle,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(0., -OFFSET_Y, 0.),
            ..default()
        },
        Shape::Capsule(Capsule2d::new(25., 50.)),
        Spin,
        DesiredVolume::Aabb,
        Intersects::default(),
    ));

    commands.spawn((
        SpatialBundle {
            transform: Transform::from_xyz(OFFSET_X, -OFFSET_Y, 0.),
            ..default()
        },
        Shape::Polygon(RegularPolygon::new(50., 6)),
        Spin,
        DesiredVolume::Circle,
        Intersects::default(),
    ));

    commands.spawn(
        TextBundle::from_section(
            "",
            TextStyle {
                font: loader.load("fonts/FiraMono-Medium.ttf"),
                font_size: 26.0,
                ..default()
            },
        )
        .with_style(Style {
            position_type: PositionType::Absolute,
            bottom: Val::Px(10.0),
            left: Val::Px(10.0),
            ..default()
        }),
    );
}

fn draw_filled_circle(gizmos: &mut Gizmos, position: Vec2, color: Srgba) {
    for r in [1., 2., 3.] {
        gizmos.circle_2d(position, r, color);
    }
}

fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) {
    gizmos.line_2d(
        ray.ray.origin,
        ray.ray.origin + *ray.ray.direction * ray.max,
        WHITE,
    );
    draw_filled_circle(gizmos, ray.ray.origin, FUCHSIA);
}

fn get_and_draw_ray(gizmos: &mut Gizmos, time: &Time) -> RayCast2d {
    let ray = Vec2::new(time.elapsed_seconds().cos(), time.elapsed_seconds().sin());
    let dist = 150. + (0.5 * time.elapsed_seconds()).sin().abs() * 500.;

    let aabb_ray = Ray2d {
        origin: ray * 250.,
        direction: Dir2::new_unchecked(-ray),
    };
    let ray_cast = RayCast2d::from_ray(aabb_ray, dist - 20.);

    draw_ray(gizmos, &ray_cast);
    ray_cast
}

fn ray_cast_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let ray_cast = get_and_draw_ray(&mut gizmos, &time);

    for (volume, mut intersects) in volumes.iter_mut() {
        let toi = match volume {
            CurrentVolume::Aabb(a) => ray_cast.aabb_intersection_at(a),
            CurrentVolume::Circle(c) => ray_cast.circle_intersection_at(c),
        };
        **intersects = toi.is_some();
        if let Some(toi) = toi {
            draw_filled_circle(
                &mut gizmos,
                ray_cast.ray.origin + *ray_cast.ray.direction * toi,
                LIME,
            );
        }
    }
}

fn aabb_cast_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let ray_cast = get_and_draw_ray(&mut gizmos, &time);
    let aabb_cast = AabbCast2d {
        aabb: Aabb2d::new(Vec2::ZERO, Vec2::splat(15.)),
        ray: ray_cast,
    };

    for (volume, mut intersects) in volumes.iter_mut() {
        let toi = match *volume {
            CurrentVolume::Aabb(a) => aabb_cast.aabb_collision_at(a),
            CurrentVolume::Circle(_) => None,
        };

        **intersects = toi.is_some();
        if let Some(toi) = toi {
            gizmos.rect_2d(
                aabb_cast.ray.ray.origin + *aabb_cast.ray.ray.direction * toi,
                0.,
                aabb_cast.aabb.half_size() * 2.,
                LIME,
            );
        }
    }
}

fn bounding_circle_cast_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let ray_cast = get_and_draw_ray(&mut gizmos, &time);
    let circle_cast = BoundingCircleCast {
        circle: BoundingCircle::new(Vec2::ZERO, 15.),
        ray: ray_cast,
    };

    for (volume, mut intersects) in volumes.iter_mut() {
        let toi = match *volume {
            CurrentVolume::Aabb(_) => None,
            CurrentVolume::Circle(c) => circle_cast.circle_collision_at(c),
        };

        **intersects = toi.is_some();
        if let Some(toi) = toi {
            gizmos.circle_2d(
                circle_cast.ray.ray.origin + *circle_cast.ray.ray.direction * toi,
                circle_cast.circle.radius(),
                LIME,
            );
        }
    }
}

fn get_intersection_position(time: &Time) -> Vec2 {
    let x = (0.8 * time.elapsed_seconds()).cos() * 250.;
    let y = (0.4 * time.elapsed_seconds()).sin() * 100.;
    Vec2::new(x, y)
}

fn aabb_intersection_system(
    mut gizmos: Gizmos,
    time: Res<Time>,
    mut volumes: Query<(&CurrentVolume, &mut Intersects)>,
) {
    let center = get_intersection_position(&time);
    let aabb = Aabb2d::new(center, Vec2::splat(50.));
    gizmos.rect_2d(center, 0., aabb.half_size() * 2., YELLOW);

    for (volume, mut intersects) in volumes.iter_mut() {
        let hit = match volume {
            CurrentVolume::Aabb(a) => aabb.intersects(a),
            CurrentVolume::Circle(c) => aabb.intersects(c),
        };

        **intersects = hit;
    }
}
More examples
Hide additional examples
examples/gizmos/2d_gizmos.rs (lines 65-70)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}
§

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

pub fn grid( &mut self, position: Vec3, rotation: Quat, cell_count: UVec2, spacing: Vec2, color: impl Into<LinearRgba> ) -> GridBuilder2d<'_, 'w, 's, Config, Clear>

Draw a 2D grid in 3D.

This should be called for each frame the grid needs to be rendered.

§Arguments
  • position: The center point of the grid.
  • rotation: defines the orientation of the grid, by default we assume the grid is contained in a plane parallel to the XY plane.
  • cell_count: defines the amount of cells in the x and y axes
  • spacing: defines the distance between cells along the x and y axes
  • color: color of the grid
§Builder methods
  • The skew of the grid can be adjusted using the .skew(...), .skew_x(...) or .skew_y(...) methods. They behave very similar to their CSS equivalents.
  • All outer edges can be toggled on or off using .outer_edges(...). Alternatively you can use .outer_edges_x(...) or .outer_edges_y(...) to toggle the outer edges along an axis.
§Example
fn system(mut gizmos: Gizmos) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::IDENTITY,
        UVec2::new(10, 10),
        Vec2::splat(2.),
        GREEN
        )
        .skew_x(0.25)
        .outer_edges();
}
Examples found in repository?
examples/gizmos/3d_gizmos.rs (lines 89-96)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    gizmos.grid(
        Vec3::ZERO,
        Quat::from_rotation_x(PI / 2.),
        UVec2::splat(20),
        Vec2::new(2., 2.),
        // Light gray
        LinearRgba::gray(0.65),
    );

    gizmos.cuboid(
        Transform::from_translation(Vec3::Y * 0.5).with_scale(Vec3::splat(1.25)),
        BLACK,
    );
    gizmos.rect(
        Vec3::new(time.elapsed_seconds().cos() * 2.5, 1., 0.),
        Quat::from_rotation_y(PI / 2.),
        Vec2::splat(2.),
        LIME,
    );

    my_gizmos.sphere(Vec3::new(1., 0.5, 0.), Quat::IDENTITY, 0.5, RED);

    for y in [0., 0.5, 1.] {
        gizmos.ray(
            Vec3::new(1., y, 0.),
            Vec3::new(-3., (time.elapsed_seconds() * 3.).sin(), 0.),
            BLUE,
        );
    }

    my_gizmos
        .arc_3d(
            180.0_f32.to_radians(),
            0.2,
            Vec3::ONE,
            Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()),
            ORANGE,
        )
        .segments(10);

    // Circles have 32 line-segments by default.
    my_gizmos.circle(Vec3::ZERO, Dir3::Y, 3., BLACK);
    // You may want to increase this for larger circles or spheres.
    my_gizmos
        .circle(Vec3::ZERO, Dir3::Y, 3.1, NAVY)
        .segments(64);
    my_gizmos
        .sphere(Vec3::ZERO, Quat::IDENTITY, 3.2, BLACK)
        .circle_segments(64);

    gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW);

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED)
        .with_double_end()
        .with_tip_length(0.5);
}

pub fn grid_3d( &mut self, position: Vec3, rotation: Quat, cell_count: UVec3, spacing: Vec3, color: impl Into<LinearRgba> ) -> GridBuilder3d<'_, 'w, 's, Config, Clear>

Draw a 3D grid of voxel-like cells.

This should be called for each frame the grid needs to be rendered.

§Arguments
  • position: The center point of the grid.
  • rotation: defines the orientation of the grid, by default we assume the grid is contained in a plane parallel to the XY plane.
  • cell_count: defines the amount of cells in the x, y and z axes
  • spacing: defines the distance between cells along the x, y and z axes
  • color: color of the grid
§Builder methods
  • The skew of the grid can be adjusted using the .skew(...), .skew_x(...), .skew_y(...) or .skew_z(...) methods. They behave very similar to their CSS equivalents.
  • All outer edges can be toggled on or off using .outer_edges(...). Alternatively you can use .outer_edges_x(...), .outer_edges_y(...) or .outer_edges_z(...) to toggle the outer edges along an axis.
§Example
fn system(mut gizmos: Gizmos) {
    gizmos.grid_3d(
        Vec3::ZERO,
        Quat::IDENTITY,
        UVec3::new(10, 2, 10),
        Vec3::splat(2.),
        GREEN
        )
        .skew_x(0.25)
        .outer_edges();
}

pub fn grid_2d( &mut self, position: Vec2, rotation: f32, cell_count: UVec2, spacing: Vec2, color: impl Into<LinearRgba> ) -> GridBuilder2d<'_, 'w, 's, Config, Clear>

Draw a grid in 2D.

This should be called for each frame the grid needs to be rendered.

§Arguments
  • position: The center point of the grid.
  • rotation: defines the orientation of the grid.
  • cell_count: defines the amount of cells in the x and y axes
  • spacing: defines the distance between cells along the x and y axes
  • color: color of the grid
§Builder methods
  • The skew of the grid can be adjusted using the .skew(...), .skew_x(...) or .skew_y(...) methods. They behave very similar to their CSS equivalents.
  • All outer edges can be toggled on or off using .outer_edges(...). Alternatively you can use .outer_edges_x(...) or .outer_edges_y(...) to toggle the outer edges along an axis.
§Example
fn system(mut gizmos: Gizmos) {
    gizmos.grid_2d(
        Vec2::ZERO,
        0.0,
        UVec2::new(10, 10),
        Vec2::splat(1.),
        GREEN
        )
        .skew_x(0.25)
        .outer_edges();
}
Examples found in repository?
examples/gizmos/2d_gizmos.rs (lines 47-54)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fn draw_example_collection(
    mut gizmos: Gizmos,
    mut my_gizmos: Gizmos<MyRoundGizmos>,
    time: Res<Time>,
) {
    let sin = time.elapsed_seconds().sin() * 50.;
    gizmos.line_2d(Vec2::Y * -sin, Vec2::splat(-80.), RED);
    gizmos.ray_2d(Vec2::Y * sin, Vec2::splat(80.), LIME);

    gizmos
        .grid_2d(
            Vec2::ZERO,
            0.0,
            UVec2::new(16, 12),
            Vec2::new(60., 60.),
            // Light gray
            LinearRgba::gray(0.65),
        )
        .outer_edges();

    // Triangle
    gizmos.linestrip_gradient_2d([
        (Vec2::Y * 300., BLUE),
        (Vec2::new(-255., -155.), RED),
        (Vec2::new(255., -155.), LIME),
        (Vec2::Y * 300., BLUE),
    ]);

    gizmos.rect_2d(
        Vec2::ZERO,
        time.elapsed_seconds() / 3.,
        Vec2::splat(300.),
        BLACK,
    );

    // The circles have 32 line-segments by default.
    my_gizmos.circle_2d(Vec2::ZERO, 120., BLACK);
    my_gizmos.ellipse_2d(
        Vec2::ZERO,
        time.elapsed_seconds() % TAU,
        Vec2::new(100., 200.),
        YELLOW_GREEN,
    );
    // You may want to increase this for larger circles.
    my_gizmos.circle_2d(Vec2::ZERO, 300., NAVY).segments(64);

    // Arcs default amount of segments is linearly interpolated between
    // 1 and 32, using the arc length as scalar.
    my_gizmos.arc_2d(Vec2::ZERO, sin / 10., PI / 2., 350., ORANGE_RED);

    gizmos.arrow_2d(
        Vec2::ZERO,
        Vec2::from_angle(sin / -10. + PI / 2.) * 50.,
        YELLOW,
    );

    // You can create more complex arrows using the arrow builder.
    gizmos
        .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN)
        .with_double_end()
        .with_tip_length(10.);
}

Trait Implementations§

§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Annulus> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Annulus, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Annulus>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<BoxedPolygon> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: BoxedPolygon, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<BoxedPolygon>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<BoxedPolyline2d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: BoxedPolyline2d, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<BoxedPolyline2d>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Capsule2d, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Capsule2d>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Circle> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Circle, position: Vec2, _angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Circle>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Dir2> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Dir2, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Dir2>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Ellipse> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Ellipse, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Ellipse>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Line2d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = Line2dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Line2d, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Line2d>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Plane2d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Plane2d, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Plane2d>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive2d<Polygon<N>> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Polygon<N>, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Polygon<N>>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive2d<Polyline2d<N>> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Polyline2d<N>, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Polyline2d<N>>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Rectangle> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Rectangle, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Rectangle>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<RegularPolygon> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: RegularPolygon, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<RegularPolygon>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Segment2d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = Segment2dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Segment2d, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Segment2d>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive2d<Triangle2d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_2d. This is a builder to set non-default values.
§

fn primitive_2d( &mut self, primitive: Triangle2d, position: Vec2, angle: f32, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive2d<Triangle2d>>::Output<'_>

Renders a 2D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<BoxedPolyline3d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: BoxedPolyline3d, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<BoxedPolyline3d>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Capsule3d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = Capsule3dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Capsule3d, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Capsule3d>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Cone> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = Cone3dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Cone, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Cone>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<ConicalFrustum> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = ConicalFrustum3dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: ConicalFrustum, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<ConicalFrustum>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Cuboid> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Cuboid, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Cuboid>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Cylinder> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = Cylinder3dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Cylinder, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Cylinder>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Dir3> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Dir3, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Dir3>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Line3d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Line3d, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Line3d>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Plane3d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = Plane3dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Plane3d, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Plane3d>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive3d<Polyline3d<N>> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Polyline3d<N>, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Polyline3d<N>>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Segment3d> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = () where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Segment3d, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Segment3d>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Sphere> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = SphereBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Sphere, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Sphere>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, T> GizmoPrimitive3d<Tetrahedron> for Gizmos<'w, 's, T>

§

type Output<'a> = () where Gizmos<'w, 's, T>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Tetrahedron, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, T> as GizmoPrimitive3d<Tetrahedron>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<'w, 's, Config, Clear> GizmoPrimitive3d<Torus> for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type Output<'a> = Torus3dBuilder<'a, 'w, 's, Config, Clear> where Gizmos<'w, 's, Config, Clear>: 'a

The output of primitive_3d. This is a builder to set non-default values.
§

fn primitive_3d( &mut self, primitive: Torus, position: Vec3, rotation: Quat, color: impl Into<Color> ) -> <Gizmos<'w, 's, Config, Clear> as GizmoPrimitive3d<Torus>>::Output<'_>

Renders a 3D primitive with its associated details.
§

impl<Config, Clear> SystemParam for Gizmos<'_, '_, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync,

§

type State = GizmosFetchState<Config, Clear>

Used to store data which persists across invocations of a system.
§

type Item<'w, 's> = Gizmos<'w, 's, Config, Clear>

The item type returned when constructing this system param. The value of this associated type should be Self, instantiated with new lifetimes. Read more
§

fn init_state( world: &mut World, system_meta: &mut SystemMeta ) -> <Gizmos<'_, '_, Config, Clear> as SystemParam>::State

Registers any World access used by this SystemParam and creates a new instance of this param’s State.
§

unsafe fn new_archetype( state: &mut <Gizmos<'_, '_, Config, Clear> as SystemParam>::State, archetype: &Archetype, system_meta: &mut SystemMeta )

For the specified Archetype, registers the components accessed by this SystemParam (if applicable).a Read more
§

fn apply( state: &mut <Gizmos<'_, '_, Config, Clear> as SystemParam>::State, system_meta: &SystemMeta, world: &mut World )

Applies any deferred mutations stored in this SystemParam’s state. This is used to apply Commands during apply_deferred.
§

unsafe fn get_param<'w, 's>( state: &'s mut <Gizmos<'_, '_, Config, Clear> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick ) -> <Gizmos<'_, '_, Config, Clear> as SystemParam>::Item<'w, 's>

Creates a parameter to be passed into a SystemParamFunction. Read more
§

impl<'w, 's, Config, Clear> ReadOnlySystemParam for Gizmos<'w, 's, Config, Clear>
where Config: GizmoConfigGroup, Clear: 'static + Send + Sync, Deferred<'s, GizmoBuffer<Config, Clear>>: ReadOnlySystemParam, Res<'w, GizmoConfigStore>: ReadOnlySystemParam,

Auto Trait Implementations§

§

impl<'w, 's, Config, Clear> Freeze for Gizmos<'w, 's, Config, Clear>

§

impl<'w, 's, Config, Clear> RefUnwindSafe for Gizmos<'w, 's, Config, Clear>
where Config: RefUnwindSafe, Clear: RefUnwindSafe,

§

impl<'w, 's, Config, Clear> Send for Gizmos<'w, 's, Config, Clear>

§

impl<'w, 's, Config, Clear> Sync for Gizmos<'w, 's, Config, Clear>

§

impl<'w, 's, Config, Clear> Unpin for Gizmos<'w, 's, Config, Clear>

§

impl<'w, 's, Config = DefaultGizmoConfigGroup, Clear = ()> !UnwindSafe for Gizmos<'w, 's, Config, Clear>

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
§

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

§

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

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

§

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.
§

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.
§

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.
§

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.
§

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

§

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

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

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

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
§

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

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

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

§

fn to_sample_(self) -> U

source§

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

§

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>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

§

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

§

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

§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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