-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add axes_2d gizmo. #12334
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
Add axes_2d gizmo. #12334
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
I see that the build/CI are failing because the compiler says that impl From<Vec3> for Vec2 {
#[inline]
fn from(v: Vec3) -> Self {
(v.x, v.y)
}
} I am relatively new to rust though, so perhaps this isn't correct? Any pointers here would be great! The strange thing is that the example works just fine ( |
You can't implement a diff --git a/crates/bevy_gizmos/src/arrows.rs b/crates/bevy_gizmos/src/arrows.rs
index 899af3374..e9dad936c 100644
--- a/crates/bevy_gizmos/src/arrows.rs
+++ b/crates/bevy_gizmos/src/arrows.rs
@@ -199,7 +199,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
let end_x = transform.transform_point(base_length * Vec3::X);
let end_y = transform.transform_point(base_length * Vec3::Y);
- self.arrow_2d(start.into(), end_x.into(), RED);
- self.arrow_2d(start.into(), end_y.into(), GREEN);
+ self.arrow_2d(start.truncate(), end_x.truncate(), RED);
+ self.arrow_2d(start.truncate(), end_y.truncate(), GREEN);
}
} |
crates/bevy_gizmos/Cargo.toml
Outdated
bevy_sprite = { path = "../bevy_sprite", version = "0.14.0-dev", optional = true } | ||
bevy_pbr = { path = "../bevy_pbr", version = "0.14.0-dev", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should avoid changing this
examples/gizmos/2d_gizmos.rs
Outdated
@@ -87,6 +87,8 @@ fn draw_example_collection( | |||
Vec2::from_angle(sin / -10. + PI / 2.) * 50., | |||
YELLOW, | |||
); | |||
|
|||
gizmos.axes_2d(Transform::from_translation(Vec3::new(sin, 0.0, 0.0)), 25.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this example is already quite crowded. this will also put it on the grid gizmo already present, making it hard to read
crates/bevy_gizmos/src/arrows.rs
Outdated
self.arrow_2d(start.into(), end_x.into(), RED); | ||
self.arrow_2d(start.into(), end_y.into(), GREEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.arrow_2d(start.into(), end_x.into(), RED); | |
self.arrow_2d(start.into(), end_y.into(), GREEN); | |
self.arrow_2d(start.xy(), end_x.xy(), RED); | |
self.arrow_2d(start.xy(), end_y.xy(), GREEN); |
and you'll need to import bevy_math::Vec3Swizzles
crates/bevy_gizmos/src/arrows.rs
Outdated
let length = (end - start).length(); | ||
ArrowBuilder { | ||
gizmos: self, | ||
start: start.extend(0.), | ||
end: end.extend(0.), | ||
color: color.into(), | ||
tip_length: length / 10., | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to be consistent with the 3d arrow drawing method, but I realize now that was not a smart change.
…go.toml, remove From<Vec3> for Vec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change, thank you. Can you put this feature in the axes example? I think we can place it in the plane on the example? We can make the bevy logo bounce around in the floor I believe.
crates/bevy_gizmos/src/arrows.rs
Outdated
@@ -163,3 +163,36 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { | |||
self.arrow(start, end_z, BLUE); | |||
} | |||
} | |||
|
|||
impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should adress both methods in the same impl if possible and move this to the impl above this.
@pablo-lua I moved it into the same impl block as you suggested and added a 2D axis to the axes example. My first try at that caused there to be axes flying around in space and so I pinned them to the plane. Maybe this is not exactly illustrative of the capability of the 2D axes to transform though. |
Fair, I was thinking in placing this as a |
@pablo-lua ok reverted the example, but otherwise I hope its all good! |
Objective
This PR addresses #12222 (Fixes #12222). Simple addition to add a 2D axes gizmo.
Solution
The only thing I'm not sure about here is taking a 3D transform as an argument. It says in the transform comments that for 2D the z-axis is used for ordering, so I figured I'd keep it that way?
Changelog