Skip to content

Retained Gizmos #15473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
73c494e
weep
tim-blackbird Sep 27, 2024
1108152
draw split
tim-blackbird Sep 27, 2024
e8cdfc9
weep
tim-blackbird Sep 27, 2024
897d8b9
Merge branch 'retained-gizmos' into prepare-retained-gizmos
tim-blackbird Sep 27, 2024
cf2c6bc
chonky hurray
tim-blackbird Sep 27, 2024
95109dc
ssip
tim-blackbird Sep 30, 2024
1928322
doc fix
tim-blackbird Sep 30, 2024
7101672
:l
tim-blackbird Sep 30, 2024
6c2742c
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Sep 30, 2024
e9e96ea
Update example
tim-blackbird Sep 30, 2024
9234cdc
doc
tim-blackbird Sep 30, 2024
19d4298
revert
tim-blackbird Sep 30, 2024
85b6739
edit comment
tim-blackbird Sep 30, 2024
0f20b42
Add `LineGizmoAsset::new()`
tim-blackbird Sep 30, 2024
45b0976
nit
tim-blackbird Sep 30, 2024
add5f82
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Sep 30, 2024
ac94ffc
retained render world port attempt
tim-blackbird Sep 30, 2024
2543b26
I'm silly
tim-blackbird Sep 30, 2024
da0d2ae
Add `Transform` support
tim-blackbird Oct 7, 2024
76a47d1
More fixes
tim-blackbird Oct 7, 2024
14d626d
Fix docs
tim-blackbird Oct 7, 2024
70b1b7b
Undelete
tim-blackbird Oct 7, 2024
f107e8b
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Oct 10, 2024
7ed86ae
fix merge
tim-blackbird Oct 10, 2024
33fe13e
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Oct 10, 2024
7700685
Extract `MainEntity`
tim-blackbird Oct 10, 2024
fe1b824
Fix doc-example
tim-blackbird Oct 10, 2024
b08b2a0
Fix doc-example 🤞
tim-blackbird Oct 10, 2024
dbdb9ad
Rename
tim-blackbird Oct 12, 2024
da6931d
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Oct 12, 2024
dee6a28
Clean up imports, fix doc-test
tim-blackbird Oct 12, 2024
3342d8f
docs
tim-blackbird Oct 12, 2024
11c713a
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Dec 3, 2024
6e4eba3
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Dec 3, 2024
3cd1d62
Merge branch 'main' of https://github.com/bevyengine/bevy into prepar…
tim-blackbird Dec 3, 2024
f97ad43
Import `require` proc macro
tim-blackbird Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bevy_dev_tools/src/ui_debug_overlay/inset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ impl<'w, 's> InsetGizmo<'w, 's> {
Vec2::new(right, bottom),
Vec2::new(right, top),
Vec2::new(left, top),
];
self.draw
.linestrip_2d(strip.map(|v| self.relative(v)), color);
]
.map(|v| self.relative(v));
self.draw.linestrip_2d(strip, color);
Copy link
Contributor Author

@tim-blackbird tim-blackbird Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows an instance where the use of DerefMut can cause compilation errors.
This issue of partial borrows is already a problem for the Mut returned by mutable query items for example. (Polonius pls 🙏)

}
}
}
2 changes: 1 addition & 1 deletion crates/bevy_dev_tools/src/ui_debug_overlay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn outline_roots(
let line_width = outline
.gizmo_config
.get_config_dyn(&UiGizmosDebug.type_id())
.map_or(2., |(config, _)| config.line_width)
.map_or(2., |(config, _)| config.line.width)
/ window_scale;
let mut draw = InsetGizmo::new(draw, cam.debug_camera, line_width);
for (entity, trans, node, view_visibility, maybe_target_camera) in &roots {
Expand Down
49 changes: 23 additions & 26 deletions crates/bevy_gizmos/src/arcs.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
//! Additional [`Gizmos`] Functions -- Arcs
//! Additional [`GizmoBuffer`] Functions -- Arcs
//!
//! Includes the implementation of [`Gizmos::arc_2d`],
//! Includes the implementation of [`GizmoBuffer::arc_2d`],
//! and assorted support items.

use crate::{
circles::DEFAULT_CIRCLE_RESOLUTION,
prelude::{GizmoConfigGroup, Gizmos},
};
use crate::{circles::DEFAULT_CIRCLE_RESOLUTION, gizmos::GizmoBuffer, prelude::GizmoConfigGroup};
use bevy_color::Color;
use bevy_math::{Isometry2d, Isometry3d, Quat, Rot2, Vec2, Vec3};
use core::f32::consts::{FRAC_PI_2, TAU};

// === 2D ===

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
impl<Config, Clear> GizmoBuffer<Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand Down Expand Up @@ -54,7 +51,7 @@ where
arc_angle: f32,
radius: f32,
color: impl Into<Color>,
) -> Arc2dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc2dBuilder<'_, Config, Clear> {
Arc2dBuilder {
gizmos: self,
isometry: isometry.into(),
Expand All @@ -66,21 +63,21 @@ where
}
}

/// A builder returned by [`Gizmos::arc_2d`].
pub struct Arc2dBuilder<'a, 'w, 's, Config, Clear>
/// A builder returned by [`GizmoBuffer::arc_2d`].
pub struct Arc2dBuilder<'a, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
{
gizmos: &'a mut Gizmos<'w, 's, Config, Clear>,
gizmos: &'a mut GizmoBuffer<Config, Clear>,
isometry: Isometry2d,
arc_angle: f32,
radius: f32,
color: Color,
resolution: Option<u32>,
}

impl<Config, Clear> Arc2dBuilder<'_, '_, '_, Config, Clear>
impl<Config, Clear> Arc2dBuilder<'_, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand All @@ -92,7 +89,7 @@ where
}
}

impl<Config, Clear> Drop for Arc2dBuilder<'_, '_, '_, Config, Clear>
impl<Config, Clear> Drop for Arc2dBuilder<'_, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand Down Expand Up @@ -122,7 +119,7 @@ fn arc_2d_inner(arc_angle: f32, radius: f32, resolution: u32) -> impl Iterator<I

// === 3D ===

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
impl<Config, Clear> GizmoBuffer<Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand Down Expand Up @@ -178,7 +175,7 @@ where
radius: f32,
isometry: impl Into<Isometry3d>,
color: impl Into<Color>,
) -> Arc3dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc3dBuilder<'_, Config, Clear> {
Arc3dBuilder {
gizmos: self,
start_vertex: Vec3::X,
Expand Down Expand Up @@ -233,7 +230,7 @@ where
from: Vec3,
to: Vec3,
color: impl Into<Color>,
) -> Arc3dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc3dBuilder<'_, Config, Clear> {
self.arc_from_to(center, from, to, color, |x| x)
}

Expand Down Expand Up @@ -279,7 +276,7 @@ where
from: Vec3,
to: Vec3,
color: impl Into<Color>,
) -> Arc3dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc3dBuilder<'_, Config, Clear> {
self.arc_from_to(center, from, to, color, |angle| {
if angle > 0.0 {
TAU - angle
Expand All @@ -299,7 +296,7 @@ where
to: Vec3,
color: impl Into<Color>,
angle_fn: impl Fn(f32) -> f32,
) -> Arc3dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc3dBuilder<'_, Config, Clear> {
// `from` and `to` can be the same here since in either case nothing gets rendered and the
// orientation ambiguity of `up` doesn't matter
let from_axis = (from - center).normalize_or_zero();
Expand Down Expand Up @@ -366,7 +363,7 @@ where
from: Vec2,
to: Vec2,
color: impl Into<Color>,
) -> Arc2dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc2dBuilder<'_, Config, Clear> {
self.arc_2d_from_to(center, from, to, color, core::convert::identity)
}

Expand Down Expand Up @@ -412,7 +409,7 @@ where
from: Vec2,
to: Vec2,
color: impl Into<Color>,
) -> Arc2dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc2dBuilder<'_, Config, Clear> {
self.arc_2d_from_to(center, from, to, color, |angle| angle - TAU)
}

Expand All @@ -424,7 +421,7 @@ where
to: Vec2,
color: impl Into<Color>,
angle_fn: impl Fn(f32) -> f32,
) -> Arc2dBuilder<'_, 'w, 's, Config, Clear> {
) -> Arc2dBuilder<'_, Config, Clear> {
// `from` and `to` can be the same here since in either case nothing gets rendered and the
// orientation ambiguity of `up` doesn't matter
let from_axis = (from - center).normalize_or_zero();
Expand All @@ -446,13 +443,13 @@ where
}
}

/// A builder returned by [`Gizmos::arc_2d`].
pub struct Arc3dBuilder<'a, 'w, 's, Config, Clear>
/// A builder returned by [`GizmoBuffer::arc_2d`].
pub struct Arc3dBuilder<'a, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
{
gizmos: &'a mut Gizmos<'w, 's, Config, Clear>,
gizmos: &'a mut GizmoBuffer<Config, Clear>,
// this is the vertex the arc starts on in the XZ plane. For the normal arc_3d method this is
// always starting at Vec3::X. For the short/long arc methods we actually need a way to start
// at the from position and this is where this internal field comes into play. Some implicit
Expand All @@ -470,7 +467,7 @@ where
resolution: Option<u32>,
}

impl<Config, Clear> Arc3dBuilder<'_, '_, '_, Config, Clear>
impl<Config, Clear> Arc3dBuilder<'_, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand All @@ -482,7 +479,7 @@ where
}
}

impl<Config, Clear> Drop for Arc3dBuilder<'_, '_, '_, Config, Clear>
impl<Config, Clear> Drop for Arc3dBuilder<'_, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand Down
26 changes: 13 additions & 13 deletions crates/bevy_gizmos/src/arrows.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
//! Additional [`Gizmos`] Functions -- Arrows
//! Additional [`GizmoBuffer`] Functions -- Arrows
//!
//! Includes the implementation of [`Gizmos::arrow`] and [`Gizmos::arrow_2d`],
//! Includes the implementation of [`GizmoBuffer::arrow`] and [`GizmoBuffer::arrow_2d`],
//! and assorted support items.

use crate::prelude::{GizmoConfigGroup, Gizmos};
use crate::{gizmos::GizmoBuffer, prelude::GizmoConfigGroup};
use bevy_color::{
palettes::basic::{BLUE, GREEN, RED},
Color,
};
use bevy_math::{Quat, Vec2, Vec3, Vec3Swizzles};
use bevy_transform::TransformPoint;

/// A builder returned by [`Gizmos::arrow`] and [`Gizmos::arrow_2d`]
pub struct ArrowBuilder<'a, 'w, 's, Config, Clear>
/// A builder returned by [`GizmoBuffer::arrow`] and [`GizmoBuffer::arrow_2d`]
pub struct ArrowBuilder<'a, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
{
gizmos: &'a mut Gizmos<'w, 's, Config, Clear>,
gizmos: &'a mut GizmoBuffer<Config, Clear>,
start: Vec3,
end: Vec3,
color: Color,
double_ended: bool,
tip_length: f32,
}

impl<Config, Clear> ArrowBuilder<'_, '_, '_, Config, Clear>
impl<Config, Clear> ArrowBuilder<'_, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand Down Expand Up @@ -58,12 +58,12 @@ where
}
}

impl<Config, Clear> Drop for ArrowBuilder<'_, '_, '_, Config, Clear>
impl<Config, Clear> Drop for ArrowBuilder<'_, Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
{
/// Draws the arrow, by drawing lines with the stored [`Gizmos`]
/// Draws the arrow, by drawing lines with the stored [`GizmoBuffer`]
fn drop(&mut self) {
if !self.gizmos.enabled {
return;
Expand Down Expand Up @@ -101,7 +101,7 @@ where
}
}

impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear>
impl<Config, Clear> GizmoBuffer<Config, Clear>
where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
Expand All @@ -125,7 +125,7 @@ where
start: Vec3,
end: Vec3,
color: impl Into<Color>,
) -> ArrowBuilder<'_, 'w, 's, Config, Clear> {
) -> ArrowBuilder<'_, Config, Clear> {
let length = (end - start).length();
ArrowBuilder {
gizmos: self,
Expand Down Expand Up @@ -156,12 +156,12 @@ where
start: Vec2,
end: Vec2,
color: impl Into<Color>,
) -> ArrowBuilder<'_, 'w, 's, Config, Clear> {
) -> ArrowBuilder<'_, Config, Clear> {
self.arrow(start.extend(0.), end.extend(0.), color)
}
}

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