summaryrefslogtreecommitdiffstats
path: root/editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-08-04 22:21:09 +0200
committerkobewi <kobewi4e@gmail.com>2023-09-12 18:08:02 +0200
commit015953a3d9089d48f57fd5c7dcdf9a03b416039a (patch)
tree8af03178dc824740794c24937d8dc6af9b722ac6 /editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp
parent3ed4497113fa10611b90290ce22a751fb9d26e2e (diff)
downloadredot-engine-015953a3d9089d48f57fd5c7dcdf9a03b416039a.tar.gz
Add helper for 3D gizmos and unify box
Diffstat (limited to 'editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp')
-rw-r--r--editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp81
1 files changed, 31 insertions, 50 deletions
diff --git a/editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp b/editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp
index d9c2316ce0..f4d524e39c 100644
--- a/editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp
+++ b/editor/plugins/gizmos/reflection_probe_gizmo_plugin.cpp
@@ -32,10 +32,12 @@
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
+#include "editor/plugins/gizmos/gizmo_3d_helper.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/reflection_probe.h"
ReflectionProbeGizmoPlugin::ReflectionProbeGizmoPlugin() {
+ helper.instantiate();
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5));
create_material("reflection_probe_material", gizmo_color);
@@ -50,6 +52,9 @@ ReflectionProbeGizmoPlugin::ReflectionProbeGizmoPlugin() {
create_handle_material("handles");
}
+ReflectionProbeGizmoPlugin::~ReflectionProbeGizmoPlugin() {
+}
+
bool ReflectionProbeGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<ReflectionProbe>(p_spatial) != nullptr;
}
@@ -63,21 +68,17 @@ int ReflectionProbeGizmoPlugin::get_priority() const {
}
String ReflectionProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
+ if (p_id < 6) {
+ return helper->box_get_handle_name(p_id);
+ }
switch (p_id) {
- case 0:
- return "Size X";
- case 1:
- return "Size Y";
- case 2:
- return "Size Z";
- case 3:
+ case 6:
return "Origin X";
- case 4:
+ case 7:
return "Origin Y";
- case 5:
+ case 8:
return "Origin Z";
}
-
return "";
}
@@ -86,47 +87,30 @@ Variant ReflectionProbeGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_
return AABB(probe->get_origin_offset(), probe->get_size());
}
+void ReflectionProbeGizmoPlugin::begin_handle_action(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) {
+ // The initial value is only used for resizing the box, so we only need AABB size.
+ AABB aabb = get_handle_value(p_gizmo, p_id, p_secondary);
+ helper->initialize_handle_action(aabb.size, p_gizmo->get_node_3d()->get_global_transform());
+}
+
void ReflectionProbeGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_node_3d());
- Transform3D gt = probe->get_global_transform();
- Transform3D gi = gt.affine_inverse();
+ Vector3 sg[2];
+ helper->get_segment(p_camera, p_point, sg);
- if (p_id < 3) {
+ if (p_id < 6) {
Vector3 size = probe->get_size();
-
- Vector3 ray_from = p_camera->project_ray_origin(p_point);
- Vector3 ray_dir = p_camera->project_ray_normal(p_point);
-
- Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) };
-
- Vector3 axis;
- axis[p_id] = 1.0;
-
- Vector3 ra, rb;
- Geometry3D::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
- float d = ra[p_id] * 2;
- if (Node3DEditor::get_singleton()->is_snap_enabled()) {
- d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
- }
-
- if (d < 0.001) {
- d = 0.001;
- }
-
- size[p_id] = d;
+ Vector3 position;
+ helper->box_set_handle(sg, p_id, size, position);
probe->set_size(size);
+ probe->set_global_position(position);
} else {
- p_id -= 3;
+ p_id -= 6;
Vector3 origin = probe->get_origin_offset();
origin[p_id] = 0;
- Vector3 ray_from = p_camera->project_ray_origin(p_point);
- Vector3 ray_dir = p_camera->project_ray_normal(p_point);
-
- Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) };
-
Vector3 axis;
axis[p_id] = 1.0;
@@ -146,6 +130,11 @@ void ReflectionProbeGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, in
void ReflectionProbeGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {
ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_node_3d());
+ if (p_id < 6) {
+ helper->box_commit_handle(TTR("Change Probe Size"), p_cancel, probe);
+ return;
+ }
+
AABB restore = p_restore;
if (p_cancel) {
@@ -155,10 +144,8 @@ void ReflectionProbeGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo,
}
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
- ur->create_action(TTR("Change Probe Size"));
- ur->add_do_method(probe, "set_size", probe->get_size());
+ ur->create_action(TTR("Change Probe Origin Offset"));
ur->add_do_method(probe, "set_origin_offset", probe->get_origin_offset());
- ur->add_undo_method(probe, "set_size", restore.size);
ur->add_undo_method(probe, "set_origin_offset", restore.position);
ur->commit_action();
}
@@ -189,13 +176,7 @@ void ReflectionProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
internal_lines.push_back(ep);
}
- Vector<Vector3> handles;
-
- for (int i = 0; i < 3; i++) {
- Vector3 ax;
- ax[i] = aabb.position[i] + aabb.size[i];
- handles.push_back(ax);
- }
+ Vector<Vector3> handles = helper->box_get_handles(probe->get_size());
for (int i = 0; i < 3; i++) {
Vector3 orig_handle = probe->get_origin_offset();