-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 ruler mode to 3D #100162
Add ruler mode to 3D #100162
Conversation
cb57993
to
500ab10
Compare
500ab10
to
6e79f3f
Compare
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.
Tested locally, it works as expected. This is a great start 🙂
Some feedback:
- I suggest renaming the Measure tool to Ruler (also with its internal enum name), so that it matches the name in the 2D editor. This should also be done for the shortcut name.
- Draw the distance text with a black outline, and use the bold editor font with a slightly increased font size. Doing this will help a lot with visibility on mixed-color backgrounds, which can be an issue right now:
See the 2D editor for reference:
- Display a the unique with a
m
suffix for "meters" (e.g.123.456 m
), as 3D units are meters in Godot. - Round the display to 3 decimals using
String.pad_decimals()
, so there's always 3 decimals displayed (even if technically not needed in some cases). This prevents the text from jumping around as the ruler moves. - The ruler line occasionally disappears depending on which direction it's going towards:
ruler_disappear.mp4
This issue depends on the camera angle. It never occurs if the camera is looking straight down by pressing KP 7.
- You could look into replicating the rectangle and angle measurements from the 2D ruler in the 3D ruler, but this can be left for a future PR.
6e79f3f
to
57b2c3d
Compare
Done.
Done.
Done.
Done.
I can't reproduce this. Does the target mesh have a collision node associated with it? At the moment the end points snap to only collisions, since snapping to geometry is a different animal.
Will probably save this for another PR since there is a lot of different avenues this kind of functionality can take. Persisting measurements, more than one measurement on the screen, measuring volume, angles, etc. I think it makes sense to wait for feedback from the public on this initial step. |
See video below: In one instance the line does go behind the mesh and extends depth-wise in the viewport, but this is expected. 2024-12-09.10-32-03.mp4 |
I see, that makes sense. In this case, I'd do what the 3D selection box does:
This way, you can see the line going through objects at reduced opacity, giving it a x-ray look. |
57b2c3d
to
3cf4c98
Compare
Done. 2024-12-09.15-55-54.mp4 |
3cf4c98
to
d1299fd
Compare
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.
ruler_label = memnew(Label); | ||
ruler_label->add_theme_color_override(SceneStringName(font_color), Color(1.0, 0.9, 0.0, 1.0)); | ||
ruler_label->add_theme_color_override("font_outline_color", Color(0.0, 0.0, 0.0, 1.0)); | ||
ruler_label->add_theme_constant_override("outline_size", 4); |
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.
Scale the outline for hiDPI displays (otherwise, the outline looks thinner relative to the font size):
ruler_label->add_theme_constant_override("outline_size", 4); | |
ruler_label->add_theme_constant_override("outline_size", 4 * EDSCALE); |
if (ruler->is_inside_tree()) { | ||
if (!ruler_start_point->is_visible()) { | ||
ruler_end_point->set_global_position(ruler_start_point->get_global_position()); | ||
ruler_start_point->set_visible(true); | ||
ruler_end_point->set_visible(true); | ||
ruler_label->set_visible(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.
if (ruler->is_inside_tree()) { | |
if (!ruler_start_point->is_visible()) { | |
ruler_end_point->set_global_position(ruler_start_point->get_global_position()); | |
ruler_start_point->set_visible(true); | |
ruler_end_point->set_visible(true); | |
ruler_label->set_visible(true); | |
} | |
if (ruler->is_inside_tree() && !ruler_start_point->is_visible()) { | |
ruler_end_point->set_global_position(ruler_start_point->get_global_position()); | |
ruler_start_point->set_visible(true); | |
ruler_end_point->set_visible(true); | |
ruler_label->set_visible(true); |
@@ -35,9 +35,11 @@ | |||
#include "editor/plugins/editor_plugin.h" | |||
#include "editor/plugins/node_3d_editor_gizmos.h" | |||
#include "editor/themes/editor_scale.h" | |||
#include "scene/3d/mesh_instance_3d.h" |
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.
Forward declare this
d1299fd
to
e2ed286
Compare
Suggestions applied. |
Thanks! |
This PR is a way to solve this: #100415 |
Implements and closes: godotengine/godot-proposals#8839
Starts on mouse down and is cleared on mouse up. Uses collision detection functionality from #96740 to snap to objects.
2024-12-11.19-08-37.mp4