Struct ShapeCommands

Source
pub struct ShapeCommands<'w, 's> { /* private fields */ }
Expand description

A system param that allows ergonomic spawning of shape entities.

The ShapeConfig used is initially extracted from the BaseShapeConfig resource. Subsequent calls to reset() will reset the config back to whatever is currently stored within the BaseShapeConfig resource.

Shapes will be spawned with commands during the next instance of apply_deferred

Implementations§

Source§

impl<'w, 's> ShapeCommands<'w, 's>

Source

pub fn reset(&mut self)

Set the painter’s ShapeConfig to the current value of the BaseShapeConfig resource.

Methods from Deref<Target = ShapeConfig>§

Source

pub fn translate(&mut self, dir: Vec3)

Helper method to modify the configs transform taking into account rotation and scale.

Examples found in repository?
examples/healthbar_stress_test.rs (line 35)
34fn draw_health_bar(painter: &mut ShapePainter, hp: f32) {
35    painter.translate(Vec3::Y * 0.7);
36    painter.corner_radii = Vec4::splat(0.3);
37
38    painter.set_color(GREEN * hp + RED * (1. - hp));
39    painter.rect(Vec2::new(0.2 + 0.8 * hp, 0.2));
40
41    painter.thickness = 0.02;
42    painter.hollow = true;
43    painter.color = Color::WHITE;
44    painter.rect(Vec2::new(1.06, 0.26));
45}
More examples
Hide additional examples
examples/canvas_modes.rs (line 50)
42fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
43    let (canvas_e, canvas) = canvas.into_inner();
44    painter.image(canvas.image.clone(), Vec2::splat(20.));
45
46    painter.set_canvas(canvas_e);
47    painter.hollow = true;
48    painter.thickness = 6.0;
49    painter.set_color(CRIMSON);
50    painter.translate(Vec3::Y * time.elapsed_secs().sin() * 256.0);
51    painter.circle(48.0);
52
53    painter.reset();
54}
examples/textured.rs (line 36)
32fn draw_canvas(time: Res<Time>, mut painter: ShapePainter, canvas: Single<Entity, With<Canvas>>) {
33    painter.rotate_z(time.elapsed_secs().sin());
34    painter.set_canvas(*canvas);
35    painter.set_color(WHITE * 2.0);
36    painter.translate(Vec3::NEG_Y * 12.0 * 16.0);
37    painter.thickness = 16.0;
38
39    for _ in 0..12 {
40        painter.translate(Vec3::Y * 32.0);
41        painter.line(Vec3::NEG_X * 256.0, Vec3::X * 256.0);
42    }
43    painter.reset();
44}
45
46fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<&Canvas>) {
47    painter.texture = Some(canvas.image.clone());
48    painter.translate(Vec3::NEG_Y * 2.0);
49
50    gallery(painter, time.elapsed_secs(), 0..10);
51}
examples/alpha_mode.rs (line 36)
35fn draw_circles(painter: &mut ShapePainter, radius: f32) {
36    painter.translate(-(Vec3::X + Vec3::NEG_Y) * f32::sqrt(radius) * 0.5);
37    painter.color = Color::srgba(1.0, 0.0, 0.0, 0.5);
38    painter.circle(radius);
39
40    painter.rotate_z(-TAU / 3.0);
41    painter.translate(Vec3::Y * radius * 1.2 + Vec3::Z * 0.0001);
42    painter.color = Color::srgba(0.0, 1.0, 0.0, 0.5);
43    painter.circle(radius);
44
45    painter.rotate_z(-TAU / 3.0);
46    painter.translate(Vec3::Y * radius * 1.2 + Vec3::Z * 0.0001);
47    painter.color = Color::srgba(0.0, 0.0, 1.0, 0.5);
48    painter.circle(radius);
49}
50
51fn draw_gallery(mut painter: ShapePainter) {
52    let radius = 2.0;
53
54    painter.reset();
55    painter.translate(Vec3::X * radius * -4.0);
56    painter.alpha_mode = ShapeAlphaMode::Add;
57    draw_circles(&mut painter, radius);
58
59    painter.reset();
60    painter.alpha_mode = ShapeAlphaMode::Multiply;
61    draw_circles(&mut painter, radius);
62
63    painter.reset();
64    painter.translate(Vec3::X * radius * 4.0);
65    painter.alpha_mode = ShapeAlphaMode::Blend;
66    draw_circles(&mut painter, radius);
67}
examples/parenting_painter.rs (line 44)
34fn draw_tree(time: f32, painter: &mut ShapePainter, depth: u32) {
35    if depth == 0 {
36        return;
37    }
38
39    let line_a = Vec3::Y + Vec3::X * 0.5;
40    painter.rotate_z(time.sin() * 0.2);
41    painter
42        .line(Vec3::ZERO, line_a)
43        .with_children(|child_painter| {
44            child_painter.translate(line_a);
45
46            draw_tree(time, child_painter, depth - 1);
47        });
48
49    let line_b = Vec3::Y + Vec3::NEG_X * 0.5;
50    painter.rotate_z(-time.sin() * 0.4);
51    painter
52        .line(Vec3::ZERO, line_b)
53        .with_children(|child_painter| {
54            child_painter.translate(line_b);
55
56            draw_tree(time, child_painter, depth - 1);
57        });
58}
59
60fn draw_gallery(
61    time: Res<Time>,
62    mut painter: ShapePainter,
63    mut tree: Single<&mut Transform, With<Tree>>,
64) {
65    tree.rotation = Quat::from_rotation_z(time.elapsed_secs().sin() / 4.0);
66
67    // Position our painter relative to our tree entity
68    painter.transform = **tree;
69    painter.set_color(SEA_GREEN + WHITE * 0.25);
70    painter
71        .line(Vec3::ZERO, Vec3::Y)
72        .with_children(|child_painter| {
73            child_painter.translate(Vec3::Y);
74            draw_tree(time.elapsed_secs(), child_painter, 10);
75        });
76}
examples/render_layers.rs (line 112)
88fn draw_shapes(time: Res<Time>, mut painter: ShapePainter) {
89    painter.reset();
90    painter.render_layers = Some(RenderLayers::layer(1));
91    painter.hollow = true;
92    painter.transform.scale = Vec3::ONE * 3.0;
93
94    let meter_fill = (time.elapsed_secs().sin() + 1.0) / 2.0;
95    let meter_size = PI * 1.5;
96
97    let start_angle = -meter_size / 2.0;
98    let end_angle = -meter_size / 2.0 + meter_fill * meter_size;
99
100    painter.cap = Cap::Round;
101    painter.thickness = 0.4;
102    painter.set_color(CRIMSON * (1.0 / (0.5 + meter_fill)));
103    painter.arc(1.3, start_angle, end_angle);
104
105    painter.cap = Cap::None;
106    painter.thickness = 0.2;
107    painter.set_color(DARK_GRAY);
108    painter.arc(1.6, start_angle, -start_angle);
109    painter.arc(0.8, start_angle, -start_angle);
110
111    let offset = Quat::from_rotation_z(start_angle) * Vec3::Y * 1.1;
112    painter.translate(offset);
113    painter.arc(0.5, start_angle + PI * 1.5, start_angle + 2.5 * PI);
114    painter.translate(-offset);
115
116    painter.translate(Quat::from_rotation_z(-start_angle) * Vec3::Y * 1.1);
117    painter.arc(0.5, start_angle + PI, start_angle + 2.0 * PI);
118}
Source

pub fn set_translation(&mut self, translation: Vec3)

Helper method to set the configs transform.

Examples found in repository?
examples/minimal_3d.rs (line 23)
21fn draw(mut painter: ShapePainter) {
22    // Move the painter so it's not inside the camera
23    painter.set_translation(Vec3::NEG_Z);
24    // Draw a circle
25    painter.circle(0.1);
26}
More examples
Hide additional examples
examples/origin.rs (line 38)
24fn draw(mut painter: ShapePainter) {
25    // Render the background
26    painter.color = Color::BLACK.with_alpha(0.9);
27    painter.corner_radii = Vec4::splat(0.1);
28    painter.rect(Vec2::new(2.0, 1.0));
29
30    // Set the circle color
31    painter.color = Color::WHITE;
32
33    // Set the origin of the circles in front of the background
34    // Without this, the left circle is blended in the wrong order
35    painter.origin = Some(Vec3::Z * 0.01);
36
37    // Render the left circle
38    painter.set_translation(Vec3::X * -0.5);
39    painter.circle(0.2);
40
41    // Render the right circle
42    painter.set_translation(Vec3::X * 0.5);
43    painter.circle(0.2);
44}
Source

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

Helper method to rotate the configs transform by a given Quat.

Source

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

Helper method to set the configs rotation.

Source

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

Helper method to rotate the configs transform around the x axis.

Source

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

Helper method to rotate the configs transform around the y axis.

Source

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

Helper method to rotate the configs transform around the z axis.

Examples found in repository?
examples/textured.rs (line 33)
32fn draw_canvas(time: Res<Time>, mut painter: ShapePainter, canvas: Single<Entity, With<Canvas>>) {
33    painter.rotate_z(time.elapsed_secs().sin());
34    painter.set_canvas(*canvas);
35    painter.set_color(WHITE * 2.0);
36    painter.translate(Vec3::NEG_Y * 12.0 * 16.0);
37    painter.thickness = 16.0;
38
39    for _ in 0..12 {
40        painter.translate(Vec3::Y * 32.0);
41        painter.line(Vec3::NEG_X * 256.0, Vec3::X * 256.0);
42    }
43    painter.reset();
44}
More examples
Hide additional examples
examples/retained.rs (line 28)
18fn setup(mut commands: Commands, mut shapes: ShapeCommands) {
19    commands.spawn((
20        Camera3d::default(),
21        Transform::from_xyz(0., 0.0, 16.).looking_at(Vec3::ZERO, Vec3::Y),
22        Msaa::Off,
23    ));
24
25    // The ShapeCommands API is identical to the ShapePainter API so can be used almost interchangeably
26    shapes.circle(1.0).with_children(|parent| {
27        for _ in 0..4 {
28            parent.rotate_z(PI / 2.0);
29            parent.line(Vec3::ZERO, Vec3::Y * 2.0);
30        }
31    });
32}
examples/canvas_recursion.rs (line 37)
27fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
28    let (canvas_e, canvas) = canvas.into_inner();
29    painter.image(canvas.image.clone(), Vec2::splat(12.));
30
31    painter.set_canvas(canvas_e);
32    painter.hollow = true;
33    painter.thickness = 16.0;
34    painter.set_color(SEA_GREEN + Srgba::WHITE * 0.25);
35    painter.rect(Vec2::splat(1024.0));
36
37    painter.rotate_z(time.elapsed_secs().sin());
38    painter.image(canvas.image.clone(), Vec2::splat(980.0));
39
40    painter.reset();
41}
examples/alpha_mode.rs (line 40)
35fn draw_circles(painter: &mut ShapePainter, radius: f32) {
36    painter.translate(-(Vec3::X + Vec3::NEG_Y) * f32::sqrt(radius) * 0.5);
37    painter.color = Color::srgba(1.0, 0.0, 0.0, 0.5);
38    painter.circle(radius);
39
40    painter.rotate_z(-TAU / 3.0);
41    painter.translate(Vec3::Y * radius * 1.2 + Vec3::Z * 0.0001);
42    painter.color = Color::srgba(0.0, 1.0, 0.0, 0.5);
43    painter.circle(radius);
44
45    painter.rotate_z(-TAU / 3.0);
46    painter.translate(Vec3::Y * radius * 1.2 + Vec3::Z * 0.0001);
47    painter.color = Color::srgba(0.0, 0.0, 1.0, 0.5);
48    painter.circle(radius);
49}
examples/parenting_painter.rs (line 40)
34fn draw_tree(time: f32, painter: &mut ShapePainter, depth: u32) {
35    if depth == 0 {
36        return;
37    }
38
39    let line_a = Vec3::Y + Vec3::X * 0.5;
40    painter.rotate_z(time.sin() * 0.2);
41    painter
42        .line(Vec3::ZERO, line_a)
43        .with_children(|child_painter| {
44            child_painter.translate(line_a);
45
46            draw_tree(time, child_painter, depth - 1);
47        });
48
49    let line_b = Vec3::Y + Vec3::NEG_X * 0.5;
50    painter.rotate_z(-time.sin() * 0.4);
51    painter
52        .line(Vec3::ZERO, line_b)
53        .with_children(|child_painter| {
54            child_painter.translate(line_b);
55
56            draw_tree(time, child_painter, depth - 1);
57        });
58}
examples/parenting_commands.rs (line 38)
24fn setup(mut commands: Commands, mut shapes: ShapeCommands, mut meshes: ResMut<Assets<Mesh>>) {
25    commands.spawn((
26        Camera3d::default(),
27        Transform::from_xyz(0., 0.0, 16.).looking_at(Vec3::ZERO, Vec3::Y),
28        Msaa::Off,
29    ));
30
31    // When spawning shapes as children of non-shape entities you can use `with_shape_children`
32    // This requires passing in a ShapeConfig, you can construct one yourself or
33    // take an existing one from a ShapePainter or ShapeCommands with .config()
34    commands
35        .spawn((Target, Transform::default(), Visibility::default()))
36        .with_shape_children(shapes.config(), |child_builder| {
37            for _ in 0..4 {
38                child_builder.rotate_z(PI / 2.0);
39                child_builder.line(Vec3::Y, Vec3::Y * 2.0);
40            }
41        });
42
43    let cube_handle = meshes.add(Mesh::from(Cuboid::new(0.2, 0.2, 0.2)));
44
45    // When spawning non-shapes as children of shapes you can use `with_children` like normal
46    shapes
47        .circle(0.2)
48        .insert((Target, Transform::default(), Visibility::default()))
49        .with_children(|child_builder| {
50            for i in 0..4 {
51                let transform = Transform::from_translation(
52                    Quat::from_rotation_z(PI / 2.0 * i as f32 + PI / 4.0)
53                        * Vec3::new(0.0, 1.0, 0.0),
54                );
55                child_builder.spawn((
56                    Mesh3d(cube_handle.clone()),
57                    MeshMaterial3d::<StandardMaterial>::default(),
58                    transform,
59                ));
60            }
61        });
62}
Source

pub fn scale(&mut self, scale: Vec3)

Helper method to scale the configs transform.

Examples found in repository?
examples/gallery_2d.rs (line 24)
23fn draw_gallery(time: Res<Time>, mut painter: ShapePainter) {
24    painter.scale(Vec3::ONE * 34.0);
25    gallery(painter, time.elapsed_secs(), 0..15);
26}
Source

pub fn set_scale(&mut self, scale: Vec3)

Helper method to set the configs scale.

Examples found in repository?
examples/canvas_basic.rs (line 35)
30fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
31    let (canvas_e, canvas) = canvas.into_inner();
32    painter.image(canvas.image.clone(), Vec2::splat(20.));
33
34    painter.set_canvas(canvas_e);
35    painter.set_scale(Vec3::ONE * 48.0);
36
37    gallery(painter, time.elapsed_secs(), 0..15);
38}
More examples
Hide additional examples
examples/canvas_bloom.rs (line 47)
42fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
43    let (canvas_e, canvas) = canvas.into_inner();
44    painter.image(canvas.image.clone(), Vec2::splat(20.));
45
46    painter.set_canvas(canvas_e);
47    painter.set_scale(Vec3::ONE * 12.0);
48
49    gallery(painter, time.elapsed_secs(), 0..15);
50}
examples/canvas_low_res.rs (line 39)
34fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
35    let (canvas_e, canvas) = canvas.into_inner();
36    painter.image(canvas.image.clone(), Vec2::splat(20.));
37
38    painter.set_canvas(canvas_e);
39    painter.set_scale(Vec3::ONE * 12.0);
40
41    gallery(painter, time.elapsed_secs(), 0..15);
42}
Source

pub fn set_canvas(&mut self, canvas: Entity)

Helper method to change shape render target to a canvas.

Also sets pipeline to Shape2d.

Examples found in repository?
examples/canvas_basic.rs (line 34)
30fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
31    let (canvas_e, canvas) = canvas.into_inner();
32    painter.image(canvas.image.clone(), Vec2::splat(20.));
33
34    painter.set_canvas(canvas_e);
35    painter.set_scale(Vec3::ONE * 48.0);
36
37    gallery(painter, time.elapsed_secs(), 0..15);
38}
More examples
Hide additional examples
examples/canvas_bloom.rs (line 46)
42fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
43    let (canvas_e, canvas) = canvas.into_inner();
44    painter.image(canvas.image.clone(), Vec2::splat(20.));
45
46    painter.set_canvas(canvas_e);
47    painter.set_scale(Vec3::ONE * 12.0);
48
49    gallery(painter, time.elapsed_secs(), 0..15);
50}
examples/canvas_low_res.rs (line 38)
34fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
35    let (canvas_e, canvas) = canvas.into_inner();
36    painter.image(canvas.image.clone(), Vec2::splat(20.));
37
38    painter.set_canvas(canvas_e);
39    painter.set_scale(Vec3::ONE * 12.0);
40
41    gallery(painter, time.elapsed_secs(), 0..15);
42}
examples/canvas_modes.rs (line 46)
42fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
43    let (canvas_e, canvas) = canvas.into_inner();
44    painter.image(canvas.image.clone(), Vec2::splat(20.));
45
46    painter.set_canvas(canvas_e);
47    painter.hollow = true;
48    painter.thickness = 6.0;
49    painter.set_color(CRIMSON);
50    painter.translate(Vec3::Y * time.elapsed_secs().sin() * 256.0);
51    painter.circle(48.0);
52
53    painter.reset();
54}
examples/textured.rs (line 34)
32fn draw_canvas(time: Res<Time>, mut painter: ShapePainter, canvas: Single<Entity, With<Canvas>>) {
33    painter.rotate_z(time.elapsed_secs().sin());
34    painter.set_canvas(*canvas);
35    painter.set_color(WHITE * 2.0);
36    painter.translate(Vec3::NEG_Y * 12.0 * 16.0);
37    painter.thickness = 16.0;
38
39    for _ in 0..12 {
40        painter.translate(Vec3::Y * 32.0);
41        painter.line(Vec3::NEG_X * 256.0, Vec3::X * 256.0);
42    }
43    painter.reset();
44}
examples/canvas_recursion.rs (line 31)
27fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
28    let (canvas_e, canvas) = canvas.into_inner();
29    painter.image(canvas.image.clone(), Vec2::splat(12.));
30
31    painter.set_canvas(canvas_e);
32    painter.hollow = true;
33    painter.thickness = 16.0;
34    painter.set_color(SEA_GREEN + Srgba::WHITE * 0.25);
35    painter.rect(Vec2::splat(1024.0));
36
37    painter.rotate_z(time.elapsed_secs().sin());
38    painter.image(canvas.image.clone(), Vec2::splat(980.0));
39
40    painter.reset();
41}
Source

pub fn set_3d(&mut self)

Helper method to change the target pipeline to the 3d pipeline.

Source

pub fn set_2d(&mut self)

Helper method to change the target pipeline to the 2d pipeline.

Source

pub fn without_transform(&self) -> Self

Helper method to clone the config without it’s transform, useful when parenting.

Source

pub fn set_color(&mut self, color: impl Into<Color>)

Examples found in repository?
examples/healthbar_stress_test.rs (line 38)
34fn draw_health_bar(painter: &mut ShapePainter, hp: f32) {
35    painter.translate(Vec3::Y * 0.7);
36    painter.corner_radii = Vec4::splat(0.3);
37
38    painter.set_color(GREEN * hp + RED * (1. - hp));
39    painter.rect(Vec2::new(0.2 + 0.8 * hp, 0.2));
40
41    painter.thickness = 0.02;
42    painter.hollow = true;
43    painter.color = Color::WHITE;
44    painter.rect(Vec2::new(1.06, 0.26));
45}
46
47fn draw_spheres(time: Res<Time>, mut painter: ShapePainter) {
48    for x in 0..SHAPES_PER_AXIS {
49        for y in 0..SHAPES_PER_AXIS {
50            let (x, y) = (x as f32, y as f32);
51            let offset = time.elapsed_secs() + x + 100. * y;
52            let position = Vec3::new(x * 2.0, offset.sin(), y * 2.0);
53
54            painter.hollow = false;
55            painter.set_color(GRAY);
56            painter.alignment = Alignment::Billboard;
57            painter.transform.translation = position;
58            painter.corner_radii = Vec4::splat(1.0);
59            painter.rect(Vec2::splat(1.0));
60
61            let hp = (offset.sin() + 1.) / 2.0;
62            draw_health_bar(&mut painter, hp);
63        }
64    }
65}
More examples
Hide additional examples
examples/canvas_modes.rs (line 49)
42fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
43    let (canvas_e, canvas) = canvas.into_inner();
44    painter.image(canvas.image.clone(), Vec2::splat(20.));
45
46    painter.set_canvas(canvas_e);
47    painter.hollow = true;
48    painter.thickness = 6.0;
49    painter.set_color(CRIMSON);
50    painter.translate(Vec3::Y * time.elapsed_secs().sin() * 256.0);
51    painter.circle(48.0);
52
53    painter.reset();
54}
examples/textured.rs (line 35)
32fn draw_canvas(time: Res<Time>, mut painter: ShapePainter, canvas: Single<Entity, With<Canvas>>) {
33    painter.rotate_z(time.elapsed_secs().sin());
34    painter.set_canvas(*canvas);
35    painter.set_color(WHITE * 2.0);
36    painter.translate(Vec3::NEG_Y * 12.0 * 16.0);
37    painter.thickness = 16.0;
38
39    for _ in 0..12 {
40        painter.translate(Vec3::Y * 32.0);
41        painter.line(Vec3::NEG_X * 256.0, Vec3::X * 256.0);
42    }
43    painter.reset();
44}
examples/canvas_recursion.rs (line 34)
27fn draw_shapes(time: Res<Time>, mut painter: ShapePainter, canvas: Single<(Entity, &Canvas)>) {
28    let (canvas_e, canvas) = canvas.into_inner();
29    painter.image(canvas.image.clone(), Vec2::splat(12.));
30
31    painter.set_canvas(canvas_e);
32    painter.hollow = true;
33    painter.thickness = 16.0;
34    painter.set_color(SEA_GREEN + Srgba::WHITE * 0.25);
35    painter.rect(Vec2::splat(1024.0));
36
37    painter.rotate_z(time.elapsed_secs().sin());
38    painter.image(canvas.image.clone(), Vec2::splat(980.0));
39
40    painter.reset();
41}
examples/parenting_painter.rs (line 69)
60fn draw_gallery(
61    time: Res<Time>,
62    mut painter: ShapePainter,
63    mut tree: Single<&mut Transform, With<Tree>>,
64) {
65    tree.rotation = Quat::from_rotation_z(time.elapsed_secs().sin() / 4.0);
66
67    // Position our painter relative to our tree entity
68    painter.transform = **tree;
69    painter.set_color(SEA_GREEN + WHITE * 0.25);
70    painter
71        .line(Vec3::ZERO, Vec3::Y)
72        .with_children(|child_painter| {
73            child_painter.translate(Vec3::Y);
74            draw_tree(time.elapsed_secs(), child_painter, 10);
75        });
76}
examples/render_layers.rs (line 102)
88fn draw_shapes(time: Res<Time>, mut painter: ShapePainter) {
89    painter.reset();
90    painter.render_layers = Some(RenderLayers::layer(1));
91    painter.hollow = true;
92    painter.transform.scale = Vec3::ONE * 3.0;
93
94    let meter_fill = (time.elapsed_secs().sin() + 1.0) / 2.0;
95    let meter_size = PI * 1.5;
96
97    let start_angle = -meter_size / 2.0;
98    let end_angle = -meter_size / 2.0 + meter_fill * meter_size;
99
100    painter.cap = Cap::Round;
101    painter.thickness = 0.4;
102    painter.set_color(CRIMSON * (1.0 / (0.5 + meter_fill)));
103    painter.arc(1.3, start_angle, end_angle);
104
105    painter.cap = Cap::None;
106    painter.thickness = 0.2;
107    painter.set_color(DARK_GRAY);
108    painter.arc(1.6, start_angle, -start_angle);
109    painter.arc(0.8, start_angle, -start_angle);
110
111    let offset = Quat::from_rotation_z(start_angle) * Vec3::Y * 1.1;
112    painter.translate(offset);
113    painter.arc(0.5, start_angle + PI * 1.5, start_angle + 2.5 * PI);
114    painter.translate(-offset);
115
116    painter.translate(Quat::from_rotation_z(-start_angle) * Vec3::Y * 1.1);
117    painter.arc(0.5, start_angle + PI, start_angle + 2.0 * PI);
118}

Trait Implementations§

Source§

impl<'w, 's> Deref for ShapeCommands<'w, 's>

Source§

type Target = ShapeConfig

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'w, 's> DerefMut for ShapeCommands<'w, 's>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'w, 's> ShapeSpawner<'w> for ShapeCommands<'w, 's>

Source§

fn spawn_shape(&mut self, bundle: impl Bundle) -> ShapeEntityCommands<'_, '_>

Note: ShapeBundle does not include RenderLayers as there is no support for optional components so instead it is inserted in this function conditionally depending on the ShapeConfig in self Prefer the function for the shape you want over ShapeSpawner::spawn_shape, e.g. commands.rect(...)
Source§

fn config(&self) -> &ShapeConfig

Source§

fn set_config(&mut self, config: ShapeConfig)

Source§

impl SystemParam for ShapeCommands<'_, '_>

Source§

type State = FetchState

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

type Item<'w, 's> = ShapeCommands<'w, 's>

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

fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State

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

unsafe fn new_archetype( state: &mut Self::State, archetype: &Archetype, system_meta: &mut SystemMeta, )

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

fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)

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

fn queue( state: &mut Self::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )

Queues any deferred mutations to be applied at the next ApplyDeferred.
Source§

unsafe fn validate_param<'w, 's>( state: &'s Self::State, _system_meta: &SystemMeta, _world: UnsafeWorldCell<'w>, ) -> Result<(), SystemParamValidationError>

Validates that the param can be acquired by the get_param. Read more
Source§

unsafe fn get_param<'w, 's>( state: &'s mut Self::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Self::Item<'w, 's>

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

impl<'w, 's> ReadOnlySystemParam for ShapeCommands<'w, 's>

Auto Trait Implementations§

§

impl<'w, 's> Freeze for ShapeCommands<'w, 's>

§

impl<'w, 's> !RefUnwindSafe for ShapeCommands<'w, 's>

§

impl<'w, 's> Send for ShapeCommands<'w, 's>

§

impl<'w, 's> Sync for ShapeCommands<'w, 's>

§

impl<'w, 's> Unpin for ShapeCommands<'w, 's>

§

impl<'w, 's> !UnwindSafe for ShapeCommands<'w, 's>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

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

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

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<'w, T> DiscSpawner<'w> for T
where T: ShapeSpawner<'w>,

Source§

fn circle(&mut self, radius: f32) -> ShapeEntityCommands<'_, '_>

Source§

fn arc( &mut self, radius: f32, start_angle: f32, end_angle: f32, ) -> ShapeEntityCommands<'_, '_>

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

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

Source§

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

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

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

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

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

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

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

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

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

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

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

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

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

impl<'w, T> LineSpawner<'w> for T
where T: ShapeSpawner<'w>,

Source§

fn line(&mut self, start: Vec3, end: Vec3) -> ShapeEntityCommands<'_, '_>

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<'w, T> RectangleSpawner<'w> for T
where T: ShapeSpawner<'w>,

Source§

fn rect(&mut self, size: Vec2) -> ShapeEntityCommands<'_, '_>

Source§

impl<'w, T> RegularPolygonSpawner<'w> for T
where T: ShapeSpawner<'w>,

Source§

fn ngon(&mut self, sides: f32, radius: f32) -> ShapeEntityCommands<'_, '_>

Source§

impl<'w, T> TriangleSpawner<'w> for T
where T: ShapeSpawner<'w>,

Source§

fn triangle( &mut self, v_a: Vec2, v_b: Vec2, v_c: Vec2, ) -> ShapeEntityCommands<'_, '_>

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

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

Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

Source§

impl<T> SatisfyTraits<dyn None> for T

Source§

impl<T> SatisfyTraits<dyn Send> for T
where T: Send,

Source§

impl<T> SatisfyTraits<dyn Sync + Send> for T
where T: Send + Sync,

Source§

impl<T> SatisfyTraits<dyn Sync> for T
where T: Sync,

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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