You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-28 16:07:14 +00:00
Add helper for 3D gizmos and unify box
This commit is contained in:
@@ -32,10 +32,13 @@
|
||||
|
||||
#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/voxel_gi.h"
|
||||
|
||||
VoxelGIGizmoPlugin::VoxelGIGizmoPlugin() {
|
||||
helper.instantiate();
|
||||
|
||||
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/voxel_gi", Color(0.5, 1, 0.6));
|
||||
|
||||
create_material("voxel_gi_material", gizmo_color);
|
||||
@@ -51,6 +54,9 @@ VoxelGIGizmoPlugin::VoxelGIGizmoPlugin() {
|
||||
create_handle_material("handles");
|
||||
}
|
||||
|
||||
VoxelGIGizmoPlugin::~VoxelGIGizmoPlugin() {
|
||||
}
|
||||
|
||||
bool VoxelGIGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
||||
return Object::cast_to<VoxelGI>(p_spatial) != nullptr;
|
||||
}
|
||||
@@ -64,16 +70,7 @@ int VoxelGIGizmoPlugin::get_priority() const {
|
||||
}
|
||||
|
||||
String VoxelGIGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
|
||||
switch (p_id) {
|
||||
case 0:
|
||||
return "Size X";
|
||||
case 1:
|
||||
return "Size Y";
|
||||
case 2:
|
||||
return "Size Z";
|
||||
}
|
||||
|
||||
return "";
|
||||
return helper->box_get_handle_name(p_id);
|
||||
}
|
||||
|
||||
Variant VoxelGIGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
|
||||
@@ -81,52 +78,25 @@ Variant VoxelGIGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, i
|
||||
return probe->get_size();
|
||||
}
|
||||
|
||||
void VoxelGIGizmoPlugin::begin_handle_action(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) {
|
||||
helper->initialize_handle_action(get_handle_value(p_gizmo, p_id, p_secondary), p_gizmo->get_node_3d()->get_global_transform());
|
||||
}
|
||||
|
||||
void VoxelGIGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
|
||||
VoxelGI *probe = Object::cast_to<VoxelGI>(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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void VoxelGIGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {
|
||||
VoxelGI *probe = Object::cast_to<VoxelGI>(p_gizmo->get_node_3d());
|
||||
|
||||
Vector3 restore = p_restore;
|
||||
|
||||
if (p_cancel) {
|
||||
probe->set_size(restore);
|
||||
return;
|
||||
}
|
||||
|
||||
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
||||
ur->create_action(TTR("Change Probe Size"));
|
||||
ur->add_do_method(probe, "set_size", probe->get_size());
|
||||
ur->add_undo_method(probe, "set_size", restore);
|
||||
ur->commit_action();
|
||||
helper->box_commit_handle(TTR("Change Probe Size"), p_cancel, p_gizmo->get_node_3d());
|
||||
}
|
||||
|
||||
void VoxelGIGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
||||
@@ -191,13 +161,7 @@ void VoxelGIGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
||||
|
||||
p_gizmo->add_lines(lines, material_internal);
|
||||
|
||||
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());
|
||||
|
||||
if (p_gizmo->is_selected()) {
|
||||
Ref<Material> solid_material = get_material("voxel_gi_solid_material", p_gizmo);
|
||||
|
||||
Reference in New Issue
Block a user