2015-10-08 20:00:40 +02:00
|
|
|
/**************************************************************************/
|
2020-03-27 08:44:44 +01:00
|
|
|
/* path_3d_editor_plugin.cpp */
|
2015-10-08 20:00:40 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "path_3d_editor_plugin.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2020-05-25 19:20:45 +02:00
|
|
|
#include "core/math/geometry_2d.h"
|
|
|
|
#include "core/math/geometry_3d.h"
|
2018-09-04 11:30:04 +02:00
|
|
|
#include "core/os/keyboard.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "editor/editor_node.h"
|
2022-07-31 20:14:15 +02:00
|
|
|
#include "editor/editor_settings.h"
|
2023-09-13 13:14:07 +02:00
|
|
|
#include "editor/editor_string_names.h"
|
2022-03-25 18:06:46 +01:00
|
|
|
#include "editor/editor_undo_redo_manager.h"
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "node_3d_editor_plugin.h"
|
2024-03-27 05:40:30 +01:00
|
|
|
#include "scene/gui/dialogs.h"
|
2022-11-19 12:45:49 +01:00
|
|
|
#include "scene/gui/menu_button.h"
|
2015-10-08 20:00:40 +02:00
|
|
|
#include "scene/resources/curve.h"
|
|
|
|
|
2022-01-11 12:33:37 +01:00
|
|
|
String Path3DGizmo::get_handle_name(int p_id, bool p_secondary) const {
|
2015-10-08 20:00:40 +02:00
|
|
|
Ref<Curve3D> c = path->get_curve();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.is_null()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return "";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Primary handles: position.
|
2022-01-11 12:33:37 +01:00
|
|
|
if (!p_secondary) {
|
2021-06-23 16:49:50 +02:00
|
|
|
return TTR("Curve Point #") + itos(p_id);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Secondary handles: in, out, tilt.
|
|
|
|
const HandleInfo info = _secondary_handles_info[p_id];
|
|
|
|
switch (info.type) {
|
|
|
|
case HandleType::HANDLE_TYPE_IN:
|
|
|
|
return TTR("Handle In #") + itos(info.point_idx);
|
|
|
|
case HandleType::HANDLE_TYPE_OUT:
|
|
|
|
return TTR("Handle Out #") + itos(info.point_idx);
|
|
|
|
case HandleType::HANDLE_TYPE_TILT:
|
|
|
|
return TTR("Handle Tilt #") + itos(info.point_idx);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
return "";
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2022-01-11 12:33:37 +01:00
|
|
|
Variant Path3DGizmo::get_handle_value(int p_id, bool p_secondary) const {
|
2015-10-08 20:00:40 +02:00
|
|
|
Ref<Curve3D> c = path->get_curve();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.is_null()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return Variant();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Primary handles: position.
|
2022-01-11 12:33:37 +01:00
|
|
|
if (!p_secondary) {
|
2021-06-23 16:49:50 +02:00
|
|
|
original = c->get_point_position(p_id);
|
2015-10-08 20:00:40 +02:00
|
|
|
return original;
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Secondary handles: in, out, tilt.
|
|
|
|
const HandleInfo info = _secondary_handles_info[p_id];
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector3 ofs;
|
2022-11-17 16:42:00 +01:00
|
|
|
switch (info.type) {
|
|
|
|
case HandleType::HANDLE_TYPE_TILT:
|
|
|
|
return c->get_point_tilt(info.point_idx);
|
|
|
|
case HandleType::HANDLE_TYPE_IN:
|
|
|
|
ofs = c->get_point_in(info.point_idx);
|
|
|
|
break;
|
|
|
|
case HandleType::HANDLE_TYPE_OUT:
|
|
|
|
ofs = c->get_point_out(info.point_idx);
|
|
|
|
break;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
original = ofs + c->get_point_position(info.point_idx);
|
2015-10-08 20:00:40 +02:00
|
|
|
return ofs;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2022-01-11 12:33:37 +01:00
|
|
|
void Path3DGizmo::set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Ref<Curve3D> c = path->get_curve();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.is_null()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
const Transform3D gt = path->get_global_transform();
|
|
|
|
const Transform3D gi = gt.affine_inverse();
|
|
|
|
const Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
const Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
|
|
|
const Plane p = Plane(p_camera->get_transform().basis.get_column(2), gt.xform(original));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Primary handles: position.
|
2022-01-11 12:33:37 +01:00
|
|
|
if (!p_secondary) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector3 inters;
|
2024-03-24 13:43:17 +01:00
|
|
|
// Special case for primary handle, the handle id equals control point id.
|
2022-11-17 16:42:00 +01:00
|
|
|
const int idx = p_id;
|
2017-05-25 00:11:20 +02:00
|
|
|
if (p.intersects_ray(ray_from, ray_dir, &inters)) {
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
float snap = Node3DEditor::get_singleton()->get_translate_snap();
|
2024-03-03 14:37:52 +01:00
|
|
|
inters.snapf(snap);
|
2016-11-14 15:46:08 +01:00
|
|
|
}
|
2017-05-24 23:47:34 +02:00
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector3 local = gi.xform(inters);
|
2022-11-17 16:42:00 +01:00
|
|
|
c->set_point_position(idx, local);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Secondary handles: in, out, tilt.
|
|
|
|
const HandleInfo info = _secondary_handles_info[p_id];
|
|
|
|
switch (info.type) {
|
|
|
|
case HandleType::HANDLE_TYPE_OUT:
|
|
|
|
case HandleType::HANDLE_TYPE_IN: {
|
|
|
|
const int idx = info.point_idx;
|
|
|
|
const Vector3 base = c->get_point_position(idx);
|
|
|
|
|
|
|
|
Vector3 inters;
|
|
|
|
if (p.intersects_ray(ray_from, ray_dir, &inters)) {
|
|
|
|
if (!Path3DEditorPlugin::singleton->is_handle_clicked()) {
|
|
|
|
orig_in_length = c->get_point_in(idx).length();
|
|
|
|
orig_out_length = c->get_point_out(idx).length();
|
|
|
|
Path3DEditorPlugin::singleton->set_handle_clicked(true);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
Vector3 local = gi.xform(inters) - base;
|
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
float snap = Node3DEditor::get_singleton()->get_translate_snap();
|
2024-03-03 14:37:52 +01:00
|
|
|
local.snapf(snap);
|
2022-11-17 16:42:00 +01:00
|
|
|
}
|
2018-05-01 12:13:29 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
if (info.type == HandleType::HANDLE_TYPE_IN) {
|
|
|
|
c->set_point_in(idx, local);
|
|
|
|
if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {
|
|
|
|
c->set_point_out(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c->set_point_out(idx, local);
|
|
|
|
if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {
|
|
|
|
c->set_point_in(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_in_length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
2022-11-17 16:42:00 +01:00
|
|
|
case HandleType::HANDLE_TYPE_TILT: {
|
|
|
|
const int idx = info.point_idx;
|
|
|
|
const Vector3 position = c->get_point_position(idx);
|
|
|
|
const Basis posture = c->get_point_baked_posture(idx);
|
|
|
|
const Vector3 tangent = -posture.get_column(2);
|
|
|
|
const Vector3 up = posture.get_column(1);
|
2024-04-24 16:02:01 +02:00
|
|
|
const Plane tilt_plane_global = gt.xform(Plane(tangent, position));
|
2022-11-17 16:42:00 +01:00
|
|
|
|
|
|
|
Vector3 intersection;
|
|
|
|
|
2024-04-24 16:02:01 +02:00
|
|
|
if (tilt_plane_global.intersects_ray(ray_from, ray_dir, &intersection)) {
|
|
|
|
Vector3 direction = gi.xform(intersection) - position;
|
2022-11-17 16:42:00 +01:00
|
|
|
real_t tilt_angle = up.signed_angle_to(direction, tangent);
|
|
|
|
|
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
2024-04-24 16:02:01 +02:00
|
|
|
real_t snap_degrees = Node3DEditor::get_singleton()->get_rotate_snap();
|
|
|
|
tilt_angle = Math::deg_to_rad(Math::snapped(Math::rad_to_deg(tilt_angle), snap_degrees));
|
2022-11-17 16:42:00 +01:00
|
|
|
}
|
2019-07-03 12:11:12 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
c->set_point_tilt(idx, tilt_angle);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-11-17 16:42:00 +01:00
|
|
|
break;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 12:33:37 +01:00
|
|
|
void Path3DGizmo::commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Ref<Curve3D> c = path->get_curve();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.is_null()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
// Primary handles: position.
|
|
|
|
if (!p_secondary && !Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {
|
|
|
|
// Special case for primary handle, the handle id equals control point id.
|
|
|
|
const int idx = p_id;
|
|
|
|
if (p_cancel) {
|
|
|
|
c->set_point_position(idx, p_restore);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ur->create_action(TTR("Set Curve Point Position"));
|
|
|
|
ur->add_do_method(c.ptr(), "set_point_position", idx, c->get_point_position(idx));
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_position", idx, p_restore);
|
|
|
|
ur->commit_action();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Secondary handles: in, out, tilt.
|
|
|
|
const HandleInfo info = _secondary_handles_info[p_id];
|
|
|
|
const int idx = info.point_idx;
|
|
|
|
switch (info.type) {
|
|
|
|
case HandleType::HANDLE_TYPE_OUT: {
|
|
|
|
if (p_cancel) {
|
|
|
|
c->set_point_out(idx, p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-04-21 16:35:23 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
ur->create_action(TTR("Set Curve Out Position"));
|
|
|
|
ur->add_do_method(c.ptr(), "set_point_out", idx, c->get_point_out(idx));
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_out", idx, p_restore);
|
2018-05-01 12:13:29 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {
|
|
|
|
ur->add_do_method(c.ptr(), "set_point_in", idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -c->get_point_out(idx) : (-c->get_point_out(idx).normalized() * orig_in_length));
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_in", idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -static_cast<Vector3>(p_restore) : (-static_cast<Vector3>(p_restore).normalized() * orig_in_length));
|
|
|
|
}
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
ur->commit_action();
|
|
|
|
break;
|
2018-05-01 12:13:29 +02:00
|
|
|
}
|
2022-11-17 16:42:00 +01:00
|
|
|
case HandleType::HANDLE_TYPE_IN: {
|
|
|
|
if (p_cancel) {
|
|
|
|
c->set_point_in(idx, p_restore);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
ur->create_action(TTR("Set Curve In Position"));
|
|
|
|
ur->add_do_method(c.ptr(), "set_point_in", idx, c->get_point_in(idx));
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_in", idx, p_restore);
|
2018-04-21 16:35:23 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {
|
|
|
|
ur->add_do_method(c.ptr(), "set_point_out", idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -c->get_point_in(idx) : (-c->get_point_in(idx).normalized() * orig_out_length));
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_out", idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -static_cast<Vector3>(p_restore) : (-static_cast<Vector3>(p_restore).normalized() * orig_out_length));
|
|
|
|
}
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
ur->commit_action();
|
|
|
|
break;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2022-11-17 16:42:00 +01:00
|
|
|
case HandleType::HANDLE_TYPE_TILT: {
|
|
|
|
if (p_cancel) {
|
|
|
|
c->set_point_tilt(idx, p_restore);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ur->create_action(TTR("Set Curve Point Tilt"));
|
|
|
|
ur->add_do_method(c.ptr(), "set_point_tilt", idx, c->get_point_tilt(idx));
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_tilt", idx, p_restore);
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
ur->commit_action();
|
|
|
|
break;
|
2018-05-01 12:13:29 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Path3DGizmo::redraw() {
|
2015-10-08 20:00:40 +02:00
|
|
|
clear();
|
|
|
|
|
2019-09-15 06:01:52 +02:00
|
|
|
Ref<StandardMaterial3D> path_material = gizmo_plugin->get_material("path_material", this);
|
|
|
|
Ref<StandardMaterial3D> path_thin_material = gizmo_plugin->get_material("path_thin_material", this);
|
2023-08-20 01:41:53 +02:00
|
|
|
Ref<StandardMaterial3D> path_tilt_material = gizmo_plugin->get_material("path_tilt_material", this);
|
2024-02-01 20:18:42 +01:00
|
|
|
Ref<StandardMaterial3D> path_tilt_muted_material = gizmo_plugin->get_material("path_tilt_muted_material", this);
|
2024-03-24 13:43:17 +01:00
|
|
|
Ref<StandardMaterial3D> handles_material = gizmo_plugin->get_material("handles");
|
2020-11-09 04:16:26 +01:00
|
|
|
Ref<StandardMaterial3D> sec_handles_material = gizmo_plugin->get_material("sec_handles");
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
Ref<Curve3D> c = path->get_curve();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.is_null()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-13 01:24:54 +01:00
|
|
|
real_t interval = 0.1;
|
|
|
|
const real_t length = c->get_baked_length();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-13 01:24:54 +01:00
|
|
|
// 1. Draw curve and bones.
|
|
|
|
if (length > CMP_EPSILON) {
|
|
|
|
const int sample_count = int(length / interval) + 2;
|
|
|
|
interval = length / (sample_count - 1); // Recalculate real interval length.
|
|
|
|
|
|
|
|
Vector<Transform3D> frames;
|
|
|
|
frames.resize(sample_count);
|
|
|
|
|
|
|
|
{
|
|
|
|
Transform3D *w = frames.ptrw();
|
|
|
|
|
|
|
|
for (int i = 0; i < sample_count; i++) {
|
|
|
|
w[i] = c->sample_baked_with_rotation(i * interval, true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Transform3D *r = frames.ptr();
|
2023-10-21 19:03:57 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
Vector<Vector3> _collision_segments;
|
2023-10-21 19:03:57 +02:00
|
|
|
_collision_segments.resize((sample_count - 1) * 2);
|
|
|
|
Vector3 *_collisions_ptr = _collision_segments.ptrw();
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
Vector<Vector3> bones;
|
2023-10-21 19:03:57 +02:00
|
|
|
bones.resize(sample_count * 4);
|
|
|
|
Vector3 *bones_ptr = bones.ptrw();
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
Vector<Vector3> ribbon;
|
2023-10-21 19:03:57 +02:00
|
|
|
ribbon.resize(sample_count);
|
|
|
|
Vector3 *ribbon_ptr = ribbon.ptrw();
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
for (int i = 0; i < sample_count; i++) {
|
2022-11-13 01:24:54 +01:00
|
|
|
const Vector3 p1 = r[i].origin;
|
|
|
|
const Vector3 side = r[i].basis.get_column(0);
|
|
|
|
const Vector3 up = r[i].basis.get_column(1);
|
|
|
|
const Vector3 forward = r[i].basis.get_column(2);
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// Collision segments.
|
2023-10-21 19:03:57 +02:00
|
|
|
if (i != sample_count - 1) {
|
2022-11-17 16:42:00 +01:00
|
|
|
const Vector3 p2 = r[i + 1].origin;
|
2023-10-21 19:03:57 +02:00
|
|
|
_collisions_ptr[(i * 2)] = p1;
|
|
|
|
_collisions_ptr[(i * 2) + 1] = p2;
|
2022-11-17 16:42:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Path3D as a ribbon.
|
2023-10-21 19:03:57 +02:00
|
|
|
ribbon_ptr[i] = p1;
|
2022-11-13 01:24:54 +01:00
|
|
|
|
|
|
|
// Fish Bone.
|
2022-11-17 16:42:00 +01:00
|
|
|
const Vector3 p_left = p1 + (side + forward - up * 0.3) * 0.06;
|
|
|
|
const Vector3 p_right = p1 + (-side + forward - up * 0.3) * 0.06;
|
2022-11-13 01:24:54 +01:00
|
|
|
|
2023-10-21 19:03:57 +02:00
|
|
|
const int bone_idx = i * 4;
|
|
|
|
|
|
|
|
bones_ptr[bone_idx] = p1;
|
|
|
|
bones_ptr[bone_idx + 1] = p_left;
|
|
|
|
bones_ptr[bone_idx + 2] = p1;
|
|
|
|
bones_ptr[bone_idx + 3] = p_right;
|
2022-11-13 01:24:54 +01:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
add_collision_segments(_collision_segments);
|
|
|
|
add_lines(bones, path_material);
|
|
|
|
add_vertices(ribbon, path_material, Mesh::PRIMITIVE_LINE_STRIP);
|
2017-08-18 20:11:16 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
// 2. Draw handles when selected.
|
2020-03-27 08:44:44 +01:00
|
|
|
if (Path3DEditorPlugin::singleton->get_edited_path() == path) {
|
2022-11-17 16:42:00 +01:00
|
|
|
PackedVector3Array handle_lines;
|
2023-08-20 01:41:53 +02:00
|
|
|
PackedVector3Array tilt_handle_lines;
|
2024-03-24 13:43:17 +01:00
|
|
|
PackedVector3Array primary_handle_points;
|
2022-11-17 16:42:00 +01:00
|
|
|
PackedVector3Array secondary_handle_points;
|
|
|
|
PackedInt32Array collected_secondary_handle_ids; // Avoid shadowing member on Node3DEditorGizmo.
|
|
|
|
|
|
|
|
_secondary_handles_info.resize(c->get_point_count() * 3);
|
|
|
|
|
|
|
|
for (int idx = 0; idx < c->get_point_count(); idx++) {
|
2024-03-24 13:43:17 +01:00
|
|
|
// Collect primary-handles.
|
2022-11-17 16:42:00 +01:00
|
|
|
const Vector3 pos = c->get_point_position(idx);
|
2024-03-24 13:43:17 +01:00
|
|
|
primary_handle_points.append(pos);
|
2022-11-17 16:42:00 +01:00
|
|
|
|
|
|
|
HandleInfo info;
|
|
|
|
info.point_idx = idx;
|
|
|
|
|
|
|
|
// Collect in-handles except for the first point.
|
2024-03-24 13:43:17 +01:00
|
|
|
if (idx > 0 && Path3DEditorPlugin::singleton->curve_edit_curve->is_pressed()) {
|
2022-11-17 16:42:00 +01:00
|
|
|
const Vector3 in = c->get_point_in(idx);
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
info.type = HandleType::HANDLE_TYPE_IN;
|
|
|
|
const int handle_idx = idx * 3 + 0;
|
|
|
|
collected_secondary_handle_ids.append(handle_idx);
|
|
|
|
_secondary_handles_info.write[handle_idx] = info;
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
secondary_handle_points.append(pos + in);
|
|
|
|
handle_lines.append(pos);
|
|
|
|
handle_lines.append(pos + in);
|
2022-11-17 16:42:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect out-handles except for the last point.
|
2024-03-24 13:43:17 +01:00
|
|
|
if (idx < c->get_point_count() - 1 && Path3DEditorPlugin::singleton->curve_edit_curve->is_pressed()) {
|
2022-11-17 16:42:00 +01:00
|
|
|
const Vector3 out = c->get_point_out(idx);
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
info.type = HandleType::HANDLE_TYPE_OUT;
|
|
|
|
const int handle_idx = idx * 3 + 1;
|
|
|
|
collected_secondary_handle_ids.append(handle_idx);
|
|
|
|
_secondary_handles_info.write[handle_idx] = info;
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
secondary_handle_points.append(pos + out);
|
|
|
|
handle_lines.append(pos);
|
|
|
|
handle_lines.append(pos + out);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2022-11-17 16:42:00 +01:00
|
|
|
|
|
|
|
// Collect tilt-handles.
|
2024-03-24 13:43:17 +01:00
|
|
|
if (Path3DEditorPlugin::singleton->curve_edit_tilt->is_pressed()) {
|
2024-02-01 20:18:42 +01:00
|
|
|
// Tilt handle.
|
2022-11-17 16:42:00 +01:00
|
|
|
{
|
|
|
|
info.type = HandleType::HANDLE_TYPE_TILT;
|
|
|
|
const int handle_idx = idx * 3 + 2;
|
|
|
|
collected_secondary_handle_ids.append(handle_idx);
|
|
|
|
_secondary_handles_info.write[handle_idx] = info;
|
|
|
|
|
|
|
|
const Basis posture = c->get_point_baked_posture(idx, true);
|
|
|
|
const Vector3 up = posture.get_column(1);
|
2023-08-20 01:41:53 +02:00
|
|
|
secondary_handle_points.append(pos + up * disk_size);
|
|
|
|
tilt_handle_lines.append(pos);
|
|
|
|
tilt_handle_lines.append(pos + up * disk_size);
|
2022-11-17 16:42:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tilt disk.
|
|
|
|
{
|
|
|
|
const Basis posture = c->get_point_baked_posture(idx, false);
|
|
|
|
const Vector3 up = posture.get_column(1);
|
|
|
|
const Vector3 side = posture.get_column(0);
|
|
|
|
|
|
|
|
PackedVector3Array disk;
|
|
|
|
disk.append(pos);
|
|
|
|
|
2023-08-20 01:41:53 +02:00
|
|
|
const int n = 36;
|
2022-11-17 16:42:00 +01:00
|
|
|
for (int i = 0; i <= n; i++) {
|
|
|
|
const float a = Math_TAU * i / n;
|
|
|
|
const Vector3 edge = sin(a) * side + cos(a) * up;
|
2023-08-20 01:41:53 +02:00
|
|
|
disk.append(pos + edge * disk_size);
|
2022-11-17 16:42:00 +01:00
|
|
|
}
|
2024-03-24 13:43:17 +01:00
|
|
|
add_vertices(disk, path_tilt_material, Mesh::PRIMITIVE_LINE_STRIP);
|
2022-11-17 16:42:00 +01:00
|
|
|
}
|
2022-06-02 11:15:15 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2022-11-17 16:42:00 +01:00
|
|
|
if (handle_lines.size() > 1) {
|
|
|
|
add_lines(handle_lines, path_thin_material);
|
2017-08-18 20:11:16 +02:00
|
|
|
}
|
2023-08-20 01:41:53 +02:00
|
|
|
|
|
|
|
if (tilt_handle_lines.size() > 1) {
|
|
|
|
add_lines(tilt_handle_lines, path_tilt_material);
|
|
|
|
}
|
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
if (!Path3DEditorPlugin::singleton->curve_edit->is_pressed() && primary_handle_points.size()) {
|
|
|
|
add_handles(primary_handle_points, handles_material);
|
|
|
|
}
|
2022-11-17 16:42:00 +01:00
|
|
|
if (secondary_handle_points.size()) {
|
|
|
|
add_handles(secondary_handle_points, sec_handles_material, collected_secondary_handle_ids, false, true);
|
2017-08-18 20:11:16 +02:00
|
|
|
}
|
2024-02-01 20:18:42 +01:00
|
|
|
// Draw the gizmo plugin manually, because handles are registered. In which case, the caller code skips drawing the gizmo plugin.
|
|
|
|
gizmo_plugin->redraw(this);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-01 20:18:42 +01:00
|
|
|
void Path3DGizmo::_update_transform_gizmo() {
|
|
|
|
Node3DEditor::get_singleton()->update_transform_gizmo();
|
|
|
|
}
|
|
|
|
|
2023-08-20 01:41:53 +02:00
|
|
|
Path3DGizmo::Path3DGizmo(Path3D *p_path, float p_disk_size) {
|
2017-05-25 00:11:20 +02:00
|
|
|
path = p_path;
|
2023-08-20 01:41:53 +02:00
|
|
|
disk_size = p_disk_size;
|
2022-09-08 18:38:33 +02:00
|
|
|
set_node_3d(p_path);
|
2020-11-24 10:12:55 +01:00
|
|
|
orig_in_length = 0;
|
|
|
|
orig_out_length = 0;
|
2024-02-01 20:18:42 +01:00
|
|
|
|
|
|
|
// Connecting to a signal once, rather than plaguing the implementation with calls to `Node3DEditor::update_transform_gizmo`.
|
|
|
|
path->connect("curve_changed", callable_mp(this, &Path3DGizmo::_update_transform_gizmo));
|
2024-03-24 13:43:17 +01:00
|
|
|
|
2024-05-14 09:40:21 +02:00
|
|
|
Path3DEditorPlugin::singleton->curve_edit->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));
|
|
|
|
Path3DEditorPlugin::singleton->curve_edit_curve->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));
|
|
|
|
Path3DEditorPlugin::singleton->curve_create->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));
|
|
|
|
Path3DEditorPlugin::singleton->curve_del->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));
|
|
|
|
Path3DEditorPlugin::singleton->curve_close->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2022-09-08 18:38:33 +02:00
|
|
|
EditorPlugin::AfterGUIInput Path3DEditorPlugin::forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!path) {
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_PASS;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-05-25 00:11:20 +02:00
|
|
|
Ref<Curve3D> c = path->get_curve();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.is_null()) {
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_PASS;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-10-17 07:08:21 +02:00
|
|
|
Transform3D gt = path->get_global_transform();
|
|
|
|
Transform3D it = gt.affine_inverse();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
static const int click_dist = 10; //should make global
|
|
|
|
|
2017-05-24 23:47:34 +02:00
|
|
|
Ref<InputEventMouseButton> mb = p_event;
|
|
|
|
|
|
|
|
if (mb.is_valid()) {
|
2017-06-03 10:54:24 +02:00
|
|
|
Point2 mbpos(mb->get_position().x, mb->get_position().y);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2024-03-26 10:24:41 +01:00
|
|
|
Node3DEditorViewport *viewport = nullptr;
|
|
|
|
for (uint32_t i = 0; i < Node3DEditor::VIEWPORTS_COUNT; i++) {
|
|
|
|
Node3DEditorViewport *vp = Node3DEditor::get_singleton()->get_editor_viewport(i);
|
|
|
|
if (vp->get_camera_3d() == p_camera) {
|
|
|
|
viewport = vp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_NULL_V(viewport, EditorPlugin::AFTER_GUI_INPUT_PASS);
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!mb->is_pressed()) {
|
2018-05-01 12:13:29 +02:00
|
|
|
set_handle_clicked(false);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-05-01 12:13:29 +02:00
|
|
|
|
2023-06-08 23:24:00 +02:00
|
|
|
if (mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->is_command_or_control_pressed()))) {
|
2015-10-08 20:00:40 +02:00
|
|
|
//click into curve, break it down
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector3> v3a = c->tessellate();
|
2017-05-25 00:11:20 +02:00
|
|
|
int rc = v3a.size();
|
|
|
|
int closest_seg = -1;
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector3 closest_seg_point;
|
|
|
|
|
2017-05-25 00:11:20 +02:00
|
|
|
if (rc >= 2) {
|
2022-04-07 12:23:40 +02:00
|
|
|
int idx = 0;
|
2020-02-17 22:06:54 +01:00
|
|
|
const Vector3 *r = v3a.ptr();
|
2022-04-07 12:23:40 +02:00
|
|
|
float closest_d = 1e20;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2024-03-26 10:24:41 +01:00
|
|
|
if (viewport->point_to_screen(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist) {
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_PASS; //nope, existing
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-05-25 00:11:20 +02:00
|
|
|
for (int i = 0; i < c->get_point_count() - 1; i++) {
|
2015-10-08 20:00:40 +02:00
|
|
|
//find the offset and point index of the place to break up
|
2017-05-25 00:11:20 +02:00
|
|
|
int j = idx;
|
2024-03-26 10:24:41 +01:00
|
|
|
if (viewport->point_to_screen(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist) {
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_PASS; //nope, existing
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
while (j < rc && c->get_point_position(i + 1) != r[j]) {
|
2017-05-25 00:11:20 +02:00
|
|
|
Vector3 from = r[j];
|
|
|
|
Vector3 to = r[j + 1];
|
2015-10-08 20:00:40 +02:00
|
|
|
real_t cdist = from.distance_to(to);
|
2017-05-25 00:11:20 +02:00
|
|
|
from = gt.xform(from);
|
|
|
|
to = gt.xform(to);
|
|
|
|
if (cdist > 0) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector2 s[2];
|
2024-03-26 10:24:41 +01:00
|
|
|
s[0] = viewport->point_to_screen(from);
|
|
|
|
s[1] = viewport->point_to_screen(to);
|
2020-05-25 19:20:45 +02:00
|
|
|
Vector2 inters = Geometry2D::get_closest_point_to_segment(mbpos, s);
|
2015-10-08 20:00:40 +02:00
|
|
|
float d = inters.distance_to(mbpos);
|
|
|
|
|
2017-05-25 00:11:20 +02:00
|
|
|
if (d < 10 && d < closest_d) {
|
|
|
|
closest_d = d;
|
|
|
|
closest_seg = i;
|
2024-03-26 10:24:41 +01:00
|
|
|
Vector3 ray_from = viewport->get_ray_pos(mbpos);
|
|
|
|
Vector3 ray_dir = viewport->get_ray(mbpos);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-05-25 00:11:20 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(ray_from, ray_from + ray_dir * 4096, from, to, ra, rb);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-05-25 00:11:20 +02:00
|
|
|
closest_seg_point = it.xform(rb);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
if (idx == j) {
|
2015-10-08 20:00:40 +02:00
|
|
|
idx++; //force next
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-05-25 00:11:20 +02:00
|
|
|
idx = j; //swap
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (j == rc) {
|
2015-10-08 20:00:40 +02:00
|
|
|
break;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
2017-05-25 00:11:20 +02:00
|
|
|
if (closest_seg != -1) {
|
2015-10-08 20:00:40 +02:00
|
|
|
//subdivide
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
ur->create_action(TTR("Split Path"));
|
2017-05-25 00:11:20 +02:00
|
|
|
ur->add_do_method(c.ptr(), "add_point", closest_seg_point, Vector3(), Vector3(), closest_seg + 1);
|
|
|
|
ur->add_undo_method(c.ptr(), "remove_point", closest_seg + 1);
|
2017-01-14 18:03:38 +01:00
|
|
|
ur->commit_action();
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_STOP;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
} else {
|
2021-04-08 16:26:14 +02:00
|
|
|
Vector3 origin;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c->get_point_count() == 0) {
|
2021-04-08 16:26:14 +02:00
|
|
|
origin = path->get_transform().get_origin();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2021-04-08 16:26:14 +02:00
|
|
|
origin = gt.xform(c->get_point_position(c->get_point_count() - 1));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-05-03 14:50:35 +02:00
|
|
|
Plane p(p_camera->get_transform().basis.get_column(2), origin);
|
2024-03-26 10:24:41 +01:00
|
|
|
Vector3 ray_from = viewport->get_ray_pos(mbpos);
|
|
|
|
Vector3 ray_dir = viewport->get_ray(mbpos);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector3 inters;
|
2017-05-25 00:11:20 +02:00
|
|
|
if (p.intersects_ray(ray_from, ray_dir, &inters)) {
|
2016-05-04 03:25:37 +02:00
|
|
|
ur->create_action(TTR("Add Point to Curve"));
|
2017-05-25 00:11:20 +02:00
|
|
|
ur->add_do_method(c.ptr(), "add_point", it.xform(inters), Vector3(), Vector3(), -1);
|
|
|
|
ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());
|
2017-01-14 18:03:38 +01:00
|
|
|
ur->commit_action();
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_STOP;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//add new at pos
|
|
|
|
}
|
|
|
|
|
2021-08-13 23:31:57 +02:00
|
|
|
} else if (mb->is_pressed() && ((mb->get_button_index() == MouseButton::LEFT && curve_del->is_pressed()) || (mb->get_button_index() == MouseButton::RIGHT && curve_edit->is_pressed()))) {
|
2017-05-25 00:11:20 +02:00
|
|
|
for (int i = 0; i < c->get_point_count(); i++) {
|
2024-03-26 10:24:41 +01:00
|
|
|
real_t dist_to_p = viewport->point_to_screen(gt.xform(c->get_point_position(i))).distance_to(mbpos);
|
|
|
|
real_t dist_to_p_out = viewport->point_to_screen(gt.xform(c->get_point_position(i) + c->get_point_out(i))).distance_to(mbpos);
|
|
|
|
real_t dist_to_p_in = viewport->point_to_screen(gt.xform(c->get_point_position(i) + c->get_point_in(i))).distance_to(mbpos);
|
|
|
|
real_t dist_to_p_up = viewport->point_to_screen(gt.xform(c->get_point_position(i) + c->get_point_baked_posture(i, true).get_column(1) * disk_size)).distance_to(mbpos);
|
2016-10-27 08:18:18 +02:00
|
|
|
|
|
|
|
// Find the offset and point index of the place to break up.
|
|
|
|
// Also check for the control points.
|
|
|
|
if (dist_to_p < click_dist) {
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
2016-10-27 08:18:18 +02:00
|
|
|
ur->create_action(TTR("Remove Path Point"));
|
2017-05-25 00:11:20 +02:00
|
|
|
ur->add_do_method(c.ptr(), "remove_point", i);
|
2017-09-10 15:37:49 +02:00
|
|
|
ur->add_undo_method(c.ptr(), "add_point", c->get_point_position(i), c->get_point_in(i), c->get_point_out(i), i);
|
2016-10-27 08:18:18 +02:00
|
|
|
ur->commit_action();
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_STOP;
|
2016-10-27 08:18:18 +02:00
|
|
|
} else if (dist_to_p_out < click_dist) {
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
2022-11-17 16:42:00 +01:00
|
|
|
ur->create_action(TTR("Reset Out-Control Point"));
|
2017-05-25 00:11:20 +02:00
|
|
|
ur->add_do_method(c.ptr(), "set_point_out", i, Vector3());
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_out", i, c->get_point_out(i));
|
2016-10-27 08:18:18 +02:00
|
|
|
ur->commit_action();
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_STOP;
|
2016-10-27 08:18:18 +02:00
|
|
|
} else if (dist_to_p_in < click_dist) {
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
2022-11-17 16:42:00 +01:00
|
|
|
ur->create_action(TTR("Reset In-Control Point"));
|
2017-05-25 00:11:20 +02:00
|
|
|
ur->add_do_method(c.ptr(), "set_point_in", i, Vector3());
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_in", i, c->get_point_in(i));
|
2016-10-27 08:18:18 +02:00
|
|
|
ur->commit_action();
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_STOP;
|
2022-11-17 16:42:00 +01:00
|
|
|
} else if (dist_to_p_up < click_dist) {
|
|
|
|
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
|
|
|
ur->create_action(TTR("Reset Point Tilt"));
|
|
|
|
ur->add_do_method(c.ptr(), "set_point_tilt", i, 0.0f);
|
|
|
|
ur->add_undo_method(c.ptr(), "set_point_tilt", i, c->get_point_tilt(i));
|
|
|
|
ur->commit_action();
|
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_STOP;
|
2016-10-27 08:18:18 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 09:20:26 +01:00
|
|
|
return EditorPlugin::AFTER_GUI_INPUT_PASS;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
void Path3DEditorPlugin::edit(Object *p_object) {
|
2015-10-08 20:00:40 +02:00
|
|
|
if (p_object) {
|
2020-03-26 22:49:16 +01:00
|
|
|
path = Object::cast_to<Path3D>(p_object);
|
2015-10-08 20:00:40 +02:00
|
|
|
if (path) {
|
|
|
|
if (path->get_curve().is_valid()) {
|
2024-05-13 16:56:03 +02:00
|
|
|
path->get_curve()->emit_signal(CoreStringName(changed));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2024-09-05 20:07:16 +02:00
|
|
|
_update_toolbar();
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-26 22:49:16 +01:00
|
|
|
Path3D *pre = path;
|
2020-04-02 01:20:12 +02:00
|
|
|
path = nullptr;
|
2015-10-08 20:00:40 +02:00
|
|
|
if (pre) {
|
2024-05-13 16:56:03 +02:00
|
|
|
pre->get_curve()->emit_signal(CoreStringName(changed));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-17 16:42:00 +01:00
|
|
|
|
|
|
|
update_overlays();
|
2017-08-24 22:58:51 +02:00
|
|
|
//collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
bool Path3DEditorPlugin::handles(Object *p_object) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
return p_object->is_class("Path3D");
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
void Path3DEditorPlugin::make_visible(bool p_visible) {
|
2015-10-08 20:00:40 +02:00
|
|
|
if (p_visible) {
|
2023-09-11 23:50:10 +02:00
|
|
|
topmenu_bar->show();
|
2015-10-08 20:00:40 +02:00
|
|
|
} else {
|
2023-09-11 23:50:10 +02:00
|
|
|
topmenu_bar->hide();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
{
|
2020-03-26 22:49:16 +01:00
|
|
|
Path3D *pre = path;
|
2020-04-02 01:20:12 +02:00
|
|
|
path = nullptr;
|
2015-10-08 20:00:40 +02:00
|
|
|
if (pre && pre->get_curve().is_valid()) {
|
2024-05-13 16:56:03 +02:00
|
|
|
pre->get_curve()->emit_signal(CoreStringName(changed));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-05 04:54:48 +02:00
|
|
|
void Path3DEditorPlugin::_mode_changed(int p_mode) {
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_create->set_pressed_no_signal(p_mode == MODE_CREATE);
|
|
|
|
curve_edit_curve->set_pressed_no_signal(p_mode == MODE_EDIT_CURVE);
|
|
|
|
curve_edit_tilt->set_pressed_no_signal(p_mode == MODE_EDIT_TILT);
|
|
|
|
curve_edit->set_pressed_no_signal(p_mode == MODE_EDIT);
|
|
|
|
curve_del->set_pressed_no_signal(p_mode == MODE_DELETE);
|
2024-03-24 13:43:17 +01:00
|
|
|
|
|
|
|
Node3DEditor::get_singleton()->clear_subgizmo_selection();
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
void Path3DEditorPlugin::_close_curve() {
|
2017-05-25 00:11:20 +02:00
|
|
|
Ref<Curve3D> c = path->get_curve();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (c.is_null()) {
|
2017-05-25 00:11:20 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (c->get_point_count() < 2) {
|
2017-05-25 00:11:20 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-09-15 03:24:55 +02:00
|
|
|
if (c->get_point_position(0) == c->get_point_position(c->get_point_count() - 1)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
|
2021-09-15 03:24:55 +02:00
|
|
|
ur->create_action(TTR("Close Curve"));
|
|
|
|
ur->add_do_method(c.ptr(), "add_point", c->get_point_position(0), c->get_point_in(0), c->get_point_out(0), -1);
|
|
|
|
ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());
|
|
|
|
ur->commit_action();
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
void Path3DEditorPlugin::_handle_option_pressed(int p_option) {
|
2018-05-01 12:13:29 +02:00
|
|
|
PopupMenu *pm;
|
|
|
|
pm = handle_menu->get_popup();
|
|
|
|
|
|
|
|
switch (p_option) {
|
|
|
|
case HANDLE_OPTION_ANGLE: {
|
|
|
|
bool is_checked = pm->is_item_checked(HANDLE_OPTION_ANGLE);
|
|
|
|
mirror_handle_angle = !is_checked;
|
|
|
|
pm->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);
|
|
|
|
pm->set_item_disabled(HANDLE_OPTION_LENGTH, !mirror_handle_angle);
|
|
|
|
} break;
|
|
|
|
case HANDLE_OPTION_LENGTH: {
|
|
|
|
bool is_checked = pm->is_item_checked(HANDLE_OPTION_LENGTH);
|
|
|
|
mirror_handle_length = !is_checked;
|
|
|
|
pm->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-05 20:07:16 +02:00
|
|
|
void Path3DEditorPlugin::_create_curve() {
|
|
|
|
ERR_FAIL_NULL(path);
|
|
|
|
|
|
|
|
Ref<Curve3D> new_curve;
|
|
|
|
new_curve.instantiate();
|
|
|
|
|
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
|
|
|
undo_redo->create_action(TTR("Create Curve in Path3D"));
|
|
|
|
undo_redo->add_do_property(path, "curve", new_curve);
|
|
|
|
undo_redo->add_undo_property(path, "curve", Ref<Curve3D>());
|
|
|
|
undo_redo->add_do_method(this, "_update_toolbar");
|
|
|
|
undo_redo->add_undo_method(this, "_update_toolbar");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2024-03-27 05:40:30 +01:00
|
|
|
void Path3DEditorPlugin::_confirm_clear_points() {
|
|
|
|
if (!path || path->get_curve().is_null() || path->get_curve()->get_point_count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clear_points_dialog->reset_size();
|
|
|
|
clear_points_dialog->popup_centered();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Path3DEditorPlugin::_clear_points() {
|
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
|
|
|
PackedVector3Array points = path->get_curve()->get_points().duplicate();
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Clear Curve Points"));
|
|
|
|
undo_redo->add_do_method(this, "_clear_curve_points");
|
|
|
|
undo_redo->add_undo_method(this, "_restore_curve_points", points);
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Path3DEditorPlugin::_clear_curve_points() {
|
|
|
|
if (!path || path->get_curve().is_null() || path->get_curve()->get_point_count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
curve->clear_points();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Path3DEditorPlugin::_restore_curve_points(const PackedVector3Array &p_points) {
|
|
|
|
if (!path || path->get_curve().is_null()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
|
|
|
|
if (curve->get_point_count() > 0) {
|
|
|
|
curve->clear_points();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < p_points.size(); i += 3) {
|
|
|
|
curve->add_point(p_points[i + 2], p_points[i], p_points[i + 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 18:21:50 +01:00
|
|
|
void Path3DEditorPlugin::_update_theme() {
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_edit->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveEdit")));
|
|
|
|
curve_edit_curve->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveCurve")));
|
|
|
|
curve_edit_tilt->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveTilt")));
|
|
|
|
curve_create->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveCreate")));
|
|
|
|
curve_del->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveDelete")));
|
|
|
|
curve_close->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveClose")));
|
|
|
|
curve_clear_points->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("Clear")));
|
|
|
|
create_curve_button->set_icon(topmenu_bar->get_editor_theme_icon(SNAME("Curve3D")));
|
2024-09-05 20:07:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Path3DEditorPlugin::_update_toolbar() {
|
|
|
|
if (!path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool has_curve = path->get_curve().is_valid();
|
|
|
|
toolbar->set_visible(has_curve);
|
|
|
|
create_curve_button->set_visible(!has_curve);
|
2022-01-28 18:21:50 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
void Path3DEditorPlugin::_bind_methods() {
|
2024-09-05 20:07:16 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_update_toolbar"), &Path3DEditorPlugin::_update_toolbar);
|
2024-03-27 05:40:30 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_clear_curve_points"), &Path3DEditorPlugin::_clear_curve_points);
|
|
|
|
ClassDB::bind_method(D_METHOD("_restore_curve_points"), &Path3DEditorPlugin::_restore_curve_points);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2022-01-27 10:36:51 +01:00
|
|
|
Path3DEditorPlugin::Path3DEditorPlugin() {
|
2017-05-25 00:11:20 +02:00
|
|
|
singleton = this;
|
2023-08-20 01:41:53 +02:00
|
|
|
disk_size = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8);
|
|
|
|
|
|
|
|
Ref<Path3DGizmoPlugin> gizmo_plugin = memnew(Path3DGizmoPlugin(disk_size));
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3DEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);
|
2024-03-24 13:43:17 +01:00
|
|
|
path_3d_gizmo_plugin = gizmo_plugin;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2023-09-11 23:50:10 +02:00
|
|
|
topmenu_bar = memnew(HBoxContainer);
|
|
|
|
topmenu_bar->hide();
|
2022-01-28 18:21:50 +01:00
|
|
|
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar = memnew(HBoxContainer);
|
|
|
|
topmenu_bar->add_child(toolbar);
|
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
curve_edit = memnew(Button);
|
2023-09-19 18:03:10 +02:00
|
|
|
curve_edit->set_theme_type_variation("FlatButton");
|
2015-10-08 20:00:40 +02:00
|
|
|
curve_edit->set_toggle_mode(true);
|
|
|
|
curve_edit->set_focus_mode(Control::FOCUS_NONE);
|
2024-03-24 13:43:17 +01:00
|
|
|
curve_edit->set_tooltip_text(TTR("Select Points") + "\n" + TTR("Shift+Click: Select multiple Points") + "\n" + keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point"));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(curve_edit);
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_edit->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT));
|
2022-01-28 18:21:50 +01:00
|
|
|
|
2023-06-05 04:54:48 +02:00
|
|
|
curve_edit_curve = memnew(Button);
|
2023-09-19 18:03:10 +02:00
|
|
|
curve_edit_curve->set_theme_type_variation("FlatButton");
|
2023-06-05 04:54:48 +02:00
|
|
|
curve_edit_curve->set_toggle_mode(true);
|
|
|
|
curve_edit_curve->set_focus_mode(Control::FOCUS_NONE);
|
2024-03-24 13:43:17 +01:00
|
|
|
curve_edit_curve->set_tooltip_text(TTR("Select Control Points") + "\n" + TTR("Shift+Click: Drag out Control Points"));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(curve_edit_curve);
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_edit_curve->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_CURVE));
|
2023-06-05 04:54:48 +02:00
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
curve_edit_tilt = memnew(Button);
|
|
|
|
curve_edit_tilt->set_theme_type_variation("FlatButton");
|
|
|
|
curve_edit_tilt->set_toggle_mode(true);
|
|
|
|
curve_edit_tilt->set_focus_mode(Control::FOCUS_NONE);
|
|
|
|
curve_edit_tilt->set_tooltip_text(TTR("Select Tilt Handles"));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(curve_edit_tilt);
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_edit_tilt->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_TILT));
|
2024-03-24 13:43:17 +01:00
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
curve_create = memnew(Button);
|
2023-09-19 18:03:10 +02:00
|
|
|
curve_create->set_theme_type_variation("FlatButton");
|
2015-10-08 20:00:40 +02:00
|
|
|
curve_create->set_toggle_mode(true);
|
|
|
|
curve_create->set_focus_mode(Control::FOCUS_NONE);
|
2022-08-25 12:42:17 +02:00
|
|
|
curve_create->set_tooltip_text(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)"));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(curve_create);
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_create->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_CREATE));
|
2022-01-28 18:21:50 +01:00
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
curve_del = memnew(Button);
|
2023-09-19 18:03:10 +02:00
|
|
|
curve_del->set_theme_type_variation("FlatButton");
|
2015-10-08 20:00:40 +02:00
|
|
|
curve_del->set_toggle_mode(true);
|
|
|
|
curve_del->set_focus_mode(Control::FOCUS_NONE);
|
2022-08-25 12:42:17 +02:00
|
|
|
curve_del->set_tooltip_text(TTR("Delete Point"));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(curve_del);
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_del->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_DELETE));
|
2022-01-28 18:21:50 +01:00
|
|
|
|
2020-06-19 20:49:04 +02:00
|
|
|
curve_close = memnew(Button);
|
2023-09-19 18:03:10 +02:00
|
|
|
curve_close->set_theme_type_variation("FlatButton");
|
2015-10-08 20:00:40 +02:00
|
|
|
curve_close->set_focus_mode(Control::FOCUS_NONE);
|
2022-08-25 12:42:17 +02:00
|
|
|
curve_close->set_tooltip_text(TTR("Close Curve"));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(curve_close);
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_close->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_close_curve));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2024-03-27 05:40:30 +01:00
|
|
|
curve_clear_points = memnew(Button);
|
|
|
|
curve_clear_points->set_theme_type_variation("FlatButton");
|
|
|
|
curve_clear_points->set_focus_mode(Control::FOCUS_NONE);
|
|
|
|
curve_clear_points->set_tooltip_text(TTR("Clear Points"));
|
2024-05-14 09:40:21 +02:00
|
|
|
curve_clear_points->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_confirm_clear_points));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(curve_clear_points);
|
2024-03-27 05:40:30 +01:00
|
|
|
|
|
|
|
clear_points_dialog = memnew(ConfirmationDialog);
|
|
|
|
clear_points_dialog->set_title(TTR("Please Confirm..."));
|
|
|
|
clear_points_dialog->set_text(TTR("Remove all curve points?"));
|
2024-05-14 14:28:18 +02:00
|
|
|
clear_points_dialog->connect(SceneStringName(confirmed), callable_mp(this, &Path3DEditorPlugin::_clear_points));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(clear_points_dialog);
|
2018-05-01 12:13:29 +02:00
|
|
|
|
|
|
|
handle_menu = memnew(MenuButton);
|
2023-09-19 18:03:10 +02:00
|
|
|
handle_menu->set_flat(false);
|
|
|
|
handle_menu->set_theme_type_variation("FlatMenuButton");
|
2018-05-01 12:13:29 +02:00
|
|
|
handle_menu->set_text(TTR("Options"));
|
2024-09-05 20:07:16 +02:00
|
|
|
toolbar->add_child(handle_menu);
|
|
|
|
|
|
|
|
create_curve_button = memnew(Button);
|
|
|
|
create_curve_button->set_text(TTR("Create Curve"));
|
|
|
|
create_curve_button->hide();
|
|
|
|
topmenu_bar->add_child(create_curve_button);
|
|
|
|
create_curve_button->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_create_curve));
|
2018-05-01 12:13:29 +02:00
|
|
|
|
2024-09-06 16:01:02 +02:00
|
|
|
PopupMenu *menu = handle_menu->get_popup();
|
2018-05-01 12:13:29 +02:00
|
|
|
menu->add_check_item(TTR("Mirror Handle Angles"));
|
|
|
|
menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);
|
|
|
|
menu->add_check_item(TTR("Mirror Handle Lengths"));
|
|
|
|
menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);
|
2024-05-14 14:13:31 +02:00
|
|
|
menu->connect(SceneStringName(id_pressed), callable_mp(this, &Path3DEditorPlugin::_handle_option_pressed));
|
2018-05-01 12:13:29 +02:00
|
|
|
|
2024-09-06 16:01:02 +02:00
|
|
|
curve_edit->set_pressed_no_signal(true);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2024-09-06 16:01:02 +02:00
|
|
|
topmenu_bar->connect(SceneStringName(theme_changed), callable_mp(this, &Path3DEditorPlugin::_update_theme));
|
|
|
|
Node3DEditor::get_singleton()->add_control_to_menu_panel(topmenu_bar);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) {
|
|
|
|
Ref<Path3DGizmo> ref;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Path3D *path = Object::cast_to<Path3D>(p_spatial);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (path) {
|
2023-08-20 01:41:53 +02:00
|
|
|
ref = Ref<Path3DGizmo>(memnew(Path3DGizmo(path, disk_size)));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
return ref;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2024-02-01 20:18:42 +01:00
|
|
|
bool Path3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
|
|
|
return Object::cast_to<Path3D>(p_spatial) != nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String Path3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "Path3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2024-02-01 20:18:42 +01:00
|
|
|
void Path3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|
|
|
Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());
|
|
|
|
ERR_FAIL_NULL(path);
|
|
|
|
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
|
|
|
|
Ref<StandardMaterial3D> handle_material = get_material("handles", p_gizmo);
|
|
|
|
PackedVector3Array handles;
|
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
if (Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {
|
|
|
|
for (int idx = 0; idx < curve->get_point_count(); ++idx) {
|
|
|
|
// Collect handles.
|
|
|
|
const Vector3 pos = curve->get_point_position(idx);
|
2024-02-01 20:18:42 +01:00
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
handles.append(pos);
|
|
|
|
}
|
2024-02-01 20:18:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (handles.size()) {
|
|
|
|
p_gizmo->add_vertices(handles, handle_material, Mesh::PRIMITIVE_POINTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Path3DGizmoPlugin::subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const {
|
|
|
|
Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());
|
|
|
|
ERR_FAIL_NULL_V(path, -1);
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
ERR_FAIL_COND_V(curve.is_null(), -1);
|
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
if (Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {
|
|
|
|
for (int idx = 0; idx < curve->get_point_count(); ++idx) {
|
|
|
|
Vector3 pos = path->get_global_transform().xform(curve->get_point_position(idx));
|
|
|
|
if (p_camera->unproject_position(pos).distance_to(p_point) < 20) {
|
|
|
|
return idx;
|
|
|
|
}
|
2024-02-01 20:18:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<int> Path3DGizmoPlugin::subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const {
|
|
|
|
Vector<int> contained_points;
|
|
|
|
|
|
|
|
Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());
|
|
|
|
ERR_FAIL_NULL_V(path, contained_points);
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
ERR_FAIL_COND_V(curve.is_null(), contained_points);
|
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
if (Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {
|
|
|
|
for (int idx = 0; idx < curve->get_point_count(); ++idx) {
|
|
|
|
Vector3 pos = path->get_global_transform().xform(curve->get_point_position(idx));
|
|
|
|
bool is_contained_in_frustum = true;
|
|
|
|
for (int i = 0; i < p_frustum.size(); ++i) {
|
|
|
|
if (p_frustum[i].distance_to(pos) > 0) {
|
|
|
|
is_contained_in_frustum = false;
|
|
|
|
break;
|
|
|
|
}
|
2024-02-01 20:18:42 +01:00
|
|
|
}
|
|
|
|
|
2024-03-24 13:43:17 +01:00
|
|
|
if (is_contained_in_frustum) {
|
|
|
|
contained_points.push_back(idx);
|
|
|
|
}
|
2024-02-01 20:18:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return contained_points;
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform3D Path3DGizmoPlugin::get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const {
|
|
|
|
Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());
|
|
|
|
ERR_FAIL_NULL_V(path, Transform3D());
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
ERR_FAIL_COND_V(curve.is_null(), Transform3D());
|
|
|
|
ERR_FAIL_INDEX_V(p_id, curve->get_point_count(), Transform3D());
|
|
|
|
|
|
|
|
Basis basis = transformation_locked_basis.has(p_id) ? transformation_locked_basis[p_id] : curve->get_point_baked_posture(p_id, true);
|
|
|
|
Vector3 pos = curve->get_point_position(p_id);
|
|
|
|
|
|
|
|
Transform3D t = Transform3D(basis, pos);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Path3DGizmoPlugin::set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) {
|
|
|
|
Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());
|
|
|
|
ERR_FAIL_NULL(path);
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
ERR_FAIL_COND(curve.is_null());
|
|
|
|
ERR_FAIL_INDEX(p_id, curve->get_point_count());
|
|
|
|
|
|
|
|
if (!transformation_locked_basis.has(p_id)) {
|
|
|
|
transformation_locked_basis[p_id] = Basis(curve->get_point_baked_posture(p_id, true));
|
|
|
|
}
|
|
|
|
curve->set_point_position(p_id, p_transform.origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Path3DGizmoPlugin::commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) {
|
|
|
|
Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());
|
|
|
|
ERR_FAIL_NULL(path);
|
|
|
|
Ref<Curve3D> curve = path->get_curve();
|
|
|
|
ERR_FAIL_COND(curve.is_null());
|
|
|
|
|
|
|
|
transformation_locked_basis.clear();
|
|
|
|
|
|
|
|
if (p_cancel) {
|
|
|
|
for (int i = 0; i < p_ids.size(); ++i) {
|
|
|
|
curve->set_point_position(p_ids[i], p_restore[i].origin);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Set Curve Point Position"));
|
|
|
|
|
|
|
|
for (int i = 0; i < p_ids.size(); ++i) {
|
|
|
|
const int idx = p_ids[i];
|
|
|
|
undo_redo->add_do_method(curve.ptr(), "set_point_position", idx, curve->get_point_position(idx));
|
|
|
|
undo_redo->add_undo_method(curve.ptr(), "set_point_position", idx, p_restore[i].origin);
|
|
|
|
}
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int Path3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-08-20 01:41:53 +02:00
|
|
|
Path3DGizmoPlugin::Path3DGizmoPlugin(float p_disk_size) {
|
2024-04-21 00:40:45 +02:00
|
|
|
Color path_color = SceneTree::get_singleton()->get_debug_paths_color();
|
2023-08-20 01:41:53 +02:00
|
|
|
Color path_tilt_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/path_tilt", Color(1.0, 1.0, 0.4, 0.9));
|
|
|
|
disk_size = p_disk_size;
|
|
|
|
|
2018-09-02 22:31:03 +02:00
|
|
|
create_material("path_material", path_color);
|
2023-08-20 01:41:53 +02:00
|
|
|
create_material("path_thin_material", Color(0.6, 0.6, 0.6));
|
|
|
|
create_material("path_tilt_material", path_tilt_color);
|
2024-02-01 20:18:42 +01:00
|
|
|
create_material("path_tilt_muted_material", path_tilt_color * 0.7);
|
2023-09-13 13:14:07 +02:00
|
|
|
create_handle_material("handles", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorPathSmoothHandle"), EditorStringName(EditorIcons)));
|
|
|
|
create_handle_material("sec_handles", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorCurveHandle"), EditorStringName(EditorIcons)));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|