summaryrefslogtreecommitdiffstats
path: root/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
diff options
context:
space:
mode:
authorHolonProduction <holonproduction@gmail.com>2024-09-27 12:55:42 +0200
committerHolonProduction <holonproduction@gmail.com>2024-10-11 18:38:36 +0200
commit9ea357af20c7e55413f459c70d913b7b42a56228 (patch)
treeaad3280c68e154b30315afc20778fcbecc776c85 /editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
parent92e51fca7247c932f95a1662aefc28aca96e8de6 (diff)
downloadredot-engine-9ea357af20c7e55413f459c70d913b7b42a56228.tar.gz
Editor: Improve cylinder gizmos 🌈
Diffstat (limited to 'editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp')
-rw-r--r--editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp57
1 files changed, 10 insertions, 47 deletions
diff --git a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
index 01492c1dd0..4a784be064 100644
--- a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
+++ b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
@@ -93,7 +93,7 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g
}
if (Object::cast_to<CylinderShape3D>(*s)) {
- return p_id == 0 ? "Radius" : "Height";
+ return helper->cylinder_get_handle_name(p_id);
}
if (Object::cast_to<SeparationRayShape3D>(*s)) {
@@ -219,25 +219,15 @@ void CollisionShape3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, i
}
if (Object::cast_to<CylinderShape3D>(*s)) {
- Vector3 axis;
- axis[p_id == 0 ? 0 : 1] = 1.0;
Ref<CylinderShape3D> cs2 = s;
- Vector3 ra, rb;
- Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
- float d = axis.dot(ra);
- if (Node3DEditor::get_singleton()->is_snap_enabled()) {
- d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
- }
- if (d < 0.001) {
- d = 0.001;
- }
-
- if (p_id == 0) {
- cs2->set_radius(d);
- } else if (p_id == 1) {
- cs2->set_height(d * 2.0);
- }
+ real_t height = cs2->get_height();
+ real_t radius = cs2->get_radius();
+ Vector3 position;
+ helper->cylinder_set_handle(sg, p_id, height, radius, position);
+ cs2->set_height(height);
+ cs2->set_radius(radius);
+ cs->set_global_position(position);
}
}
@@ -293,31 +283,7 @@ void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo
if (Object::cast_to<CylinderShape3D>(*s)) {
Ref<CylinderShape3D> ss = s;
- if (p_cancel) {
- if (p_id == 0) {
- ss->set_radius(p_restore);
- } else {
- ss->set_height(p_restore);
- }
- return;
- }
-
- EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
- if (p_id == 0) {
- ur->create_action(TTR("Change Cylinder Shape Radius"));
- ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius());
- ur->add_undo_method(ss.ptr(), "set_radius", p_restore);
- } else {
- ur->create_action(
- ///
-
- ////////
- TTR("Change Cylinder Shape Height"));
- ur->add_do_method(ss.ptr(), "set_height", ss->get_height());
- ur->add_undo_method(ss.ptr(), "set_height", p_restore);
- }
-
- ur->commit_action();
+ helper->cylinder_commit_handle(p_id, TTR("Change Cylinder Shape Radius"), TTR("Change Cylinder Shape Height"), p_cancel, cs, *ss, *ss);
}
if (Object::cast_to<SeparationRayShape3D>(*s)) {
@@ -534,10 +500,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->add_collision_segments(collision_segments);
- Vector<Vector3> handles = {
- Vector3(cs2->get_radius(), 0, 0),
- Vector3(0, cs2->get_height() * 0.5, 0)
- };
+ Vector<Vector3> handles = helper->cylinder_get_handles(cs2->get_height(), cs2->get_radius());
p_gizmo->add_handles(handles, handles_material);
}