Path: blob/master/editor/scene/3d/path_3d_editor_plugin.cpp
9912 views
/**************************************************************************/1/* path_3d_editor_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "path_3d_editor_plugin.h"3132#include "core/math/geometry_2d.h"33#include "core/math/geometry_3d.h"34#include "core/os/keyboard.h"35#include "editor/editor_node.h"36#include "editor/editor_string_names.h"37#include "editor/editor_undo_redo_manager.h"38#include "editor/scene/3d/node_3d_editor_plugin.h"39#include "editor/settings/editor_settings.h"40#include "scene/gui/dialogs.h"41#include "scene/gui/menu_button.h"42#include "scene/resources/curve.h"4344String Path3DGizmo::get_handle_name(int p_id, bool p_secondary) const {45Ref<Curve3D> c = path->get_curve();46if (c.is_null()) {47return "";48}4950// Primary handles: position.51if (!p_secondary) {52return TTR("Curve Point #") + itos(p_id);53}5455// Secondary handles: in, out, tilt.56const HandleInfo info = _secondary_handles_info[p_id];57switch (info.type) {58case HandleType::HANDLE_TYPE_IN:59return TTR("Handle In #") + itos(info.point_idx);60case HandleType::HANDLE_TYPE_OUT:61return TTR("Handle Out #") + itos(info.point_idx);62case HandleType::HANDLE_TYPE_TILT:63return TTR("Handle Tilt #") + itos(info.point_idx);64}6566return "";67}6869Variant Path3DGizmo::get_handle_value(int p_id, bool p_secondary) const {70Ref<Curve3D> c = path->get_curve();71if (c.is_null()) {72return Variant();73}7475// Primary handles: position.76if (!p_secondary) {77original = c->get_point_position(p_id);78return original;79}8081// Secondary handles: in, out, tilt.82const HandleInfo info = _secondary_handles_info[p_id];83Vector3 ofs;84switch (info.type) {85case HandleType::HANDLE_TYPE_TILT:86return c->get_point_tilt(info.point_idx);87case HandleType::HANDLE_TYPE_IN:88ofs = c->get_point_in(info.point_idx);89break;90case HandleType::HANDLE_TYPE_OUT:91ofs = c->get_point_out(info.point_idx);92break;93}9495original = ofs + c->get_point_position(info.point_idx);96return ofs;97}9899void Path3DGizmo::set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {100Ref<Curve3D> c = path->get_curve();101if (c.is_null()) {102return;103}104105const Transform3D gt = path->get_global_transform();106const Transform3D gi = gt.affine_inverse();107const Vector3 ray_from = p_camera->project_ray_origin(p_point);108const Vector3 ray_dir = p_camera->project_ray_normal(p_point);109const Plane p = Plane(p_camera->get_transform().basis.get_column(2), gt.xform(original));110111// Primary handles: position.112if (!p_secondary) {113Vector3 inters;114// Special case for primary handle, the handle id equals control point id.115const int idx = p_id;116if (p.intersects_ray(ray_from, ray_dir, &inters)) {117if (Node3DEditor::get_singleton()->is_snap_enabled()) {118float snap = Node3DEditor::get_singleton()->get_translate_snap();119inters.snapf(snap);120}121122Vector3 local = gi.xform(inters);123c->set_point_position(idx, local);124}125126return;127}128129// Secondary handles: in, out, tilt.130const HandleInfo info = _secondary_handles_info[p_id];131switch (info.type) {132case HandleType::HANDLE_TYPE_OUT:133case HandleType::HANDLE_TYPE_IN: {134const int idx = info.point_idx;135const Vector3 base = c->get_point_position(idx);136137Vector3 inters;138if (p.intersects_ray(ray_from, ray_dir, &inters)) {139if (!Path3DEditorPlugin::singleton->is_handle_clicked()) {140orig_in_length = c->get_point_in(idx).length();141orig_out_length = c->get_point_out(idx).length();142Path3DEditorPlugin::singleton->set_handle_clicked(true);143}144145Vector3 local = gi.xform(inters) - base;146if (Node3DEditor::get_singleton()->is_snap_enabled()) {147float snap = Node3DEditor::get_singleton()->get_translate_snap();148local.snapf(snap);149}150151// Determine if control points should be swapped based on delta movement.152// Only run on the next update after an overlap is detected, to get proper delta movement.153if (control_points_overlapped) {154control_points_overlapped = false;155Vector3 delta = local - (info.type == HANDLE_TYPE_IN ? c->get_point_in(idx) : c->get_point_out(idx));156Vector3 p0 = c->get_point_position(idx - 1) - base;157Vector3 p1 = c->get_point_position(idx + 1) - base;158HandleType new_type = Math::abs(delta.angle_to(p0)) < Math::abs(delta.angle_to(p1)) ? HANDLE_TYPE_IN : HANDLE_TYPE_OUT;159if (info.type != new_type) {160swapped_control_points_idx = idx;161}162}163164// Detect control points overlap.165bool control_points_equal = c->get_point_in(idx).is_equal_approx(c->get_point_out(idx));166if (idx > 0 && idx < (c->get_point_count() - 1) && control_points_equal) {167control_points_overlapped = true;168}169170HandleType control_type = info.type;171if (swapped_control_points_idx == idx) {172control_type = info.type == HANDLE_TYPE_IN ? HANDLE_TYPE_OUT : HANDLE_TYPE_IN;173}174175if (control_type == HandleType::HANDLE_TYPE_IN) {176c->set_point_in(idx, local);177if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {178c->set_point_out(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length));179}180} else {181c->set_point_out(idx, local);182if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {183c->set_point_in(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_in_length));184}185}186}187break;188}189case HandleType::HANDLE_TYPE_TILT: {190const int idx = info.point_idx;191const Vector3 position = c->get_point_position(idx);192const Basis posture = c->get_point_baked_posture(idx);193const Vector3 tangent = -posture.get_column(2);194const Vector3 up = posture.get_column(1);195const Plane tilt_plane_global = gt.xform(Plane(tangent, position));196197Vector3 intersection;198199if (tilt_plane_global.intersects_ray(ray_from, ray_dir, &intersection)) {200Vector3 direction = gi.xform(intersection) - position;201real_t tilt_angle = up.signed_angle_to(direction, tangent);202203if (Node3DEditor::get_singleton()->is_snap_enabled()) {204real_t snap_degrees = Node3DEditor::get_singleton()->get_rotate_snap();205tilt_angle = Math::deg_to_rad(Math::snapped(Math::rad_to_deg(tilt_angle), snap_degrees));206}207208c->set_point_tilt(idx, tilt_angle);209}210break;211}212}213}214215void Path3DGizmo::commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {216swapped_control_points_idx = -1;217control_points_overlapped = false;218219Ref<Curve3D> c = path->get_curve();220if (c.is_null()) {221return;222}223224EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();225226// Primary handles: position.227if (!p_secondary && !Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {228// Special case for primary handle, the handle id equals control point id.229const int idx = p_id;230if (p_cancel) {231c->set_point_position(idx, p_restore);232return;233}234ur->create_action(TTR("Set Curve Point Position"));235ur->add_do_method(c.ptr(), "set_point_position", idx, c->get_point_position(idx));236ur->add_undo_method(c.ptr(), "set_point_position", idx, p_restore);237ur->commit_action();238239return;240}241242// Secondary handles: in, out, tilt.243const HandleInfo info = _secondary_handles_info[p_id];244const int idx = info.point_idx;245switch (info.type) {246case HandleType::HANDLE_TYPE_OUT: {247if (p_cancel) {248c->set_point_out(idx, p_restore);249250return;251}252253ur->create_action(TTR("Set Curve Out Position"));254ur->add_do_method(c.ptr(), "set_point_out", idx, c->get_point_out(idx));255ur->add_undo_method(c.ptr(), "set_point_out", idx, p_restore);256257if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {258ur->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));259ur->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));260}261262ur->commit_action();263break;264}265case HandleType::HANDLE_TYPE_IN: {266if (p_cancel) {267c->set_point_in(idx, p_restore);268return;269}270271ur->create_action(TTR("Set Curve In Position"));272ur->add_do_method(c.ptr(), "set_point_in", idx, c->get_point_in(idx));273ur->add_undo_method(c.ptr(), "set_point_in", idx, p_restore);274275if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {276ur->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));277ur->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));278}279280ur->commit_action();281break;282}283case HandleType::HANDLE_TYPE_TILT: {284if (p_cancel) {285c->set_point_tilt(idx, p_restore);286return;287}288ur->create_action(TTR("Set Curve Point Tilt"));289ur->add_do_method(c.ptr(), "set_point_tilt", idx, c->get_point_tilt(idx));290ur->add_undo_method(c.ptr(), "set_point_tilt", idx, p_restore);291292ur->commit_action();293break;294}295}296}297298void Path3DGizmo::redraw() {299clear();300301Ref<StandardMaterial3D> path_thin_material = gizmo_plugin->get_material("path_thin_material", this);302Ref<StandardMaterial3D> path_tilt_material = gizmo_plugin->get_material("path_tilt_material", this);303Ref<StandardMaterial3D> path_tilt_muted_material = gizmo_plugin->get_material("path_tilt_muted_material", this);304Ref<StandardMaterial3D> handles_material = gizmo_plugin->get_material("handles");305Ref<StandardMaterial3D> first_pt_handle_material = gizmo_plugin->get_material("first_pt_handle");306Ref<StandardMaterial3D> last_pt_handle_material = gizmo_plugin->get_material("last_pt_handle");307Ref<StandardMaterial3D> closed_pt_handle_material = gizmo_plugin->get_material("closed_pt_handle");308Ref<StandardMaterial3D> sec_handles_material = gizmo_plugin->get_material("sec_handles");309310first_pt_handle_material->set_albedo(Color(0.2, 1.0, 0.0));311last_pt_handle_material->set_albedo(Color(1.0, 0.2, 0.0));312closed_pt_handle_material->set_albedo(Color(1.0, 0.8, 0.0));313314Ref<Curve3D> c = path->get_curve();315if (c.is_null()) {316return;317}318319debug_material = gizmo_plugin->get_material("path_material", this);320321Color path_color = path->get_debug_custom_color();322if (path_color != Color(0.0, 0.0, 0.0)) {323debug_material.instantiate();324debug_material->set_albedo(path_color);325debug_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);326debug_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);327debug_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);328debug_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);329debug_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);330}331332real_t interval = 0.1;333const real_t length = c->get_baked_length();334335// 1. Draw curve and bones if it is visible (alpha > 0.0).336if (length > CMP_EPSILON && path_color.a > 0.0) {337const int sample_count = int(length / interval) + 2;338interval = length / (sample_count - 1); // Recalculate real interval length.339340Vector<Transform3D> frames;341frames.resize(sample_count);342343{344Transform3D *w = frames.ptrw();345346for (int i = 0; i < sample_count; i++) {347w[i] = c->sample_baked_with_rotation(i * interval, true, true);348}349}350351const Transform3D *r = frames.ptr();352353Vector<Vector3> _collision_segments;354_collision_segments.resize((sample_count - 1) * 2);355Vector3 *_collisions_ptr = _collision_segments.ptrw();356357Vector<Vector3> bones;358bones.resize(sample_count * 4);359Vector3 *bones_ptr = bones.ptrw();360361Vector<Vector3> ribbon;362ribbon.resize(sample_count);363Vector3 *ribbon_ptr = ribbon.ptrw();364365for (int i = 0; i < sample_count; i++) {366const Vector3 p1 = r[i].origin;367const Vector3 side = r[i].basis.get_column(0);368const Vector3 up = r[i].basis.get_column(1);369const Vector3 forward = r[i].basis.get_column(2);370371// Collision segments.372if (i != sample_count - 1) {373const Vector3 p2 = r[i + 1].origin;374_collisions_ptr[(i * 2)] = p1;375_collisions_ptr[(i * 2) + 1] = p2;376}377378// Path3D as a ribbon.379ribbon_ptr[i] = p1;380381if (i % 4 == 0) {382// Draw fish bone every 4 points to reduce visual noise and performance impact383// (compared to drawing it for every point).384const Vector3 p_left = p1 + (side + forward - up * 0.3) * 0.06;385const Vector3 p_right = p1 + (-side + forward - up * 0.3) * 0.06;386387const int bone_idx = i * 4;388389bones_ptr[bone_idx] = p1;390bones_ptr[bone_idx + 1] = p_left;391bones_ptr[bone_idx + 2] = p1;392bones_ptr[bone_idx + 3] = p_right;393}394}395396add_collision_segments(_collision_segments);397add_lines(bones, debug_material);398add_vertices(ribbon, debug_material, Mesh::PRIMITIVE_LINE_STRIP);399}400401// 2. Draw handles when selected.402if (Path3DEditorPlugin::singleton->get_edited_path() == path) {403PackedVector3Array handle_lines;404PackedVector3Array tilt_handle_lines;405PackedVector3Array primary_handle_points;406PackedVector3Array secondary_handle_points;407PackedInt32Array collected_secondary_handle_ids; // Avoid shadowing member on Node3DEditorGizmo.408409_secondary_handles_info.resize(c->get_point_count() * 3);410411for (int idx = 0; idx < c->get_point_count(); idx++) {412// Collect primary-handles.413const Vector3 pos = c->get_point_position(idx);414primary_handle_points.append(pos);415416HandleInfo info;417info.point_idx = idx;418419// Collect in-handles except for the first point.420if (idx > (c->is_closed() ? -1 : 0) && Path3DEditorPlugin::singleton->curve_edit_curve->is_pressed()) {421const Vector3 in = c->get_point_in(idx);422423info.type = HandleType::HANDLE_TYPE_IN;424const int handle_idx = idx * 3 + 0;425collected_secondary_handle_ids.append(handle_idx);426_secondary_handles_info.write[handle_idx] = info;427428secondary_handle_points.append(pos + in);429handle_lines.append(pos);430handle_lines.append(pos + in);431}432433// Collect out-handles except for the last point.434if (idx < (c->is_closed() ? c->get_point_count() : c->get_point_count() - 1) && Path3DEditorPlugin::singleton->curve_edit_curve->is_pressed()) {435const Vector3 out = c->get_point_out(idx);436437info.type = HandleType::HANDLE_TYPE_OUT;438const int handle_idx = idx * 3 + 1;439collected_secondary_handle_ids.append(handle_idx);440_secondary_handles_info.write[handle_idx] = info;441442secondary_handle_points.append(pos + out);443handle_lines.append(pos);444handle_lines.append(pos + out);445}446447// Collect tilt-handles.448if (Path3DEditorPlugin::singleton->curve_edit_tilt->is_pressed()) {449// Tilt handle.450{451info.type = HandleType::HANDLE_TYPE_TILT;452const int handle_idx = idx * 3 + 2;453collected_secondary_handle_ids.append(handle_idx);454_secondary_handles_info.write[handle_idx] = info;455456const Basis posture = c->get_point_baked_posture(idx, true);457const Vector3 up = posture.get_column(1);458secondary_handle_points.append(pos + up * disk_size);459tilt_handle_lines.append(pos);460tilt_handle_lines.append(pos + up * disk_size);461}462463// Tilt disk.464{465const Basis posture = c->get_point_baked_posture(idx, false);466const Vector3 up = posture.get_column(1);467const Vector3 side = posture.get_column(0);468469PackedVector3Array disk;470disk.append(pos);471472const int n = 36;473for (int i = 0; i <= n; i++) {474const float a = Math::TAU * i / n;475const Vector3 edge = std::sin(a) * side + std::cos(a) * up;476disk.append(pos + edge * disk_size);477}478add_vertices(disk, debug_material, Mesh::PRIMITIVE_LINE_STRIP);479}480}481}482483if (handle_lines.size() > 1) {484add_lines(handle_lines, path_thin_material);485}486487if (tilt_handle_lines.size() > 1) {488add_lines(tilt_handle_lines, path_tilt_material);489}490491if (!Path3DEditorPlugin::singleton->curve_edit->is_pressed() && primary_handle_points.size()) {492// Need to define indices separately.493// Point count.494const int pc = primary_handle_points.size();495Vector<int> idx;496idx.resize(pc);497int *idx_ptr = idx.ptrw();498for (int j = 0; j < pc; j++) {499idx_ptr[j] = j;500}501502// Initialize arrays for first point.503PackedVector3Array first_pt_handle_point;504Vector<int> first_pt_id;505first_pt_handle_point.append(primary_handle_points[0]);506first_pt_id.append(idx[0]);507508// Initialize arrays and add handle for last point if needed.509if (pc > 1) {510PackedVector3Array last_pt_handle_point;511Vector<int> last_pt_id;512last_pt_handle_point.append(primary_handle_points[pc - 1]);513last_pt_id.append(idx[pc - 1]);514primary_handle_points.remove_at(pc - 1);515idx.remove_at(pc - 1);516add_handles(last_pt_handle_point, c->is_closed() ? handles_material : last_pt_handle_material, last_pt_id);517}518519// Add handle for first point.520primary_handle_points.remove_at(0);521idx.remove_at(0);522add_handles(first_pt_handle_point, c->is_closed() ? closed_pt_handle_material : first_pt_handle_material, first_pt_id);523524// Add handles for remaining intermediate points.525if (!primary_handle_points.is_empty()) {526add_handles(primary_handle_points, handles_material, idx);527}528}529if (secondary_handle_points.size()) {530add_handles(secondary_handle_points, sec_handles_material, collected_secondary_handle_ids, false, true);531}532// Draw the gizmo plugin manually, because handles are registered. In which case, the caller code skips drawing the gizmo plugin.533gizmo_plugin->redraw(this);534}535}536537void Path3DGizmo::_update_transform_gizmo() {538Node3DEditor::get_singleton()->update_transform_gizmo();539}540541Path3DGizmo::Path3DGizmo(Path3D *p_path, float p_disk_size) {542path = p_path;543disk_size = p_disk_size;544set_node_3d(p_path);545orig_in_length = 0;546orig_out_length = 0;547548// Connecting to a signal once, rather than plaguing the implementation with calls to `Node3DEditor::update_transform_gizmo`.549path->connect("curve_changed", callable_mp(this, &Path3DGizmo::_update_transform_gizmo));550path->connect("debug_color_changed", callable_mp(this, &Path3DGizmo::redraw));551552Path3DEditorPlugin::singleton->curve_edit->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));553Path3DEditorPlugin::singleton->curve_edit_curve->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));554Path3DEditorPlugin::singleton->curve_create->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));555Path3DEditorPlugin::singleton->curve_del->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));556Path3DEditorPlugin::singleton->curve_closed->connect(SceneStringName(pressed), callable_mp(this, &Path3DGizmo::redraw));557}558559EditorPlugin::AfterGUIInput Path3DEditorPlugin::forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) {560if (!path) {561return EditorPlugin::AFTER_GUI_INPUT_PASS;562}563Ref<Curve3D> c = path->get_curve();564if (c.is_null()) {565return EditorPlugin::AFTER_GUI_INPUT_PASS;566}567Transform3D gt = path->get_global_transform();568Transform3D it = gt.affine_inverse();569570static const int click_dist = 10; //should make global571572Ref<InputEventMouseButton> mb = p_event;573574if (mb.is_valid()) {575Point2 mbpos(mb->get_position().x, mb->get_position().y);576577Node3DEditorViewport *viewport = nullptr;578for (uint32_t i = 0; i < Node3DEditor::VIEWPORTS_COUNT; i++) {579Node3DEditorViewport *vp = Node3DEditor::get_singleton()->get_editor_viewport(i);580if (vp->get_camera_3d() == p_camera) {581viewport = vp;582break;583}584}585586ERR_FAIL_NULL_V(viewport, EditorPlugin::AFTER_GUI_INPUT_PASS);587588if (!mb->is_pressed()) {589set_handle_clicked(false);590}591592if (mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->is_command_or_control_pressed()))) {593//click into curve, break it down594Vector<Vector3> v3a = c->tessellate();595int rc = v3a.size();596int closest_seg = -1;597Vector3 closest_seg_point;598599if (rc >= 2) {600int idx = 0;601const Vector3 *r = v3a.ptr();602float closest_d = 1e20;603604if (viewport->point_to_screen(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist) {605return EditorPlugin::AFTER_GUI_INPUT_PASS; //nope, existing606}607608for (int i = 0; i < c->get_point_count() - 1; i++) {609//find the offset and point index of the place to break up610int j = idx;611if (viewport->point_to_screen(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist) {612return EditorPlugin::AFTER_GUI_INPUT_PASS; //nope, existing613}614615while (j < rc && c->get_point_position(i + 1) != r[j]) {616Vector3 from = r[j];617Vector3 to = r[j + 1];618real_t cdist = from.distance_to(to);619from = gt.xform(from);620to = gt.xform(to);621if (cdist > 0) {622const Vector2 segment_a = viewport->point_to_screen(from);623const Vector2 segment_b = viewport->point_to_screen(to);624Vector2 inters = Geometry2D::get_closest_point_to_segment(mbpos, segment_a, segment_b);625float d = inters.distance_to(mbpos);626627if (d < 10 && d < closest_d) {628closest_d = d;629closest_seg = i;630Vector3 ray_from = viewport->get_ray_pos(mbpos);631Vector3 ray_dir = viewport->get_ray(mbpos);632633Vector3 ra, rb;634Geometry3D::get_closest_points_between_segments(ray_from, ray_from + ray_dir * 4096, from, to, ra, rb);635636closest_seg_point = it.xform(rb);637}638}639j++;640}641if (idx == j) {642idx++; //force next643} else {644idx = j; //swap645}646647if (j == rc) {648break;649}650}651}652653EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();654if (closest_seg != -1) {655//subdivide656657ur->create_action(TTR("Split Path"));658ur->add_do_method(c.ptr(), "add_point", closest_seg_point, Vector3(), Vector3(), closest_seg + 1);659ur->add_undo_method(c.ptr(), "remove_point", closest_seg + 1);660ur->commit_action();661return EditorPlugin::AFTER_GUI_INPUT_STOP;662663} else {664Vector3 origin;665if (c->get_point_count() == 0) {666origin = path->get_transform().get_origin();667} else {668origin = gt.xform(c->get_point_position(c->get_point_count() - 1));669}670Plane p(p_camera->get_transform().basis.get_column(2), origin);671Vector3 ray_from = viewport->get_ray_pos(mbpos);672Vector3 ray_dir = viewport->get_ray(mbpos);673674Vector3 inters;675if (p.intersects_ray(ray_from, ray_dir, &inters)) {676ur->create_action(TTR("Add Point to Curve"));677ur->add_do_method(c.ptr(), "add_point", it.xform(inters), Vector3(), Vector3(), -1);678ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());679ur->commit_action();680return EditorPlugin::AFTER_GUI_INPUT_STOP;681}682683//add new at pos684}685686} 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()))) {687for (int i = 0; i < c->get_point_count(); i++) {688real_t dist_to_p = viewport->point_to_screen(gt.xform(c->get_point_position(i))).distance_to(mbpos);689real_t dist_to_p_out = viewport->point_to_screen(gt.xform(c->get_point_position(i) + c->get_point_out(i))).distance_to(mbpos);690real_t dist_to_p_in = viewport->point_to_screen(gt.xform(c->get_point_position(i) + c->get_point_in(i))).distance_to(mbpos);691real_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);692693// Find the offset and point index of the place to break up.694// Also check for the control points.695if (dist_to_p < click_dist) {696EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();697ur->create_action(TTR("Remove Path Point"));698ur->add_do_method(c.ptr(), "remove_point", i);699ur->add_undo_method(c.ptr(), "add_point", c->get_point_position(i), c->get_point_in(i), c->get_point_out(i), i);700ur->commit_action();701return EditorPlugin::AFTER_GUI_INPUT_STOP;702} else if (dist_to_p_out < click_dist) {703EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();704ur->create_action(TTR("Reset Out-Control Point"));705ur->add_do_method(c.ptr(), "set_point_out", i, Vector3());706ur->add_undo_method(c.ptr(), "set_point_out", i, c->get_point_out(i));707ur->commit_action();708return EditorPlugin::AFTER_GUI_INPUT_STOP;709} else if (dist_to_p_in < click_dist) {710EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();711ur->create_action(TTR("Reset In-Control Point"));712ur->add_do_method(c.ptr(), "set_point_in", i, Vector3());713ur->add_undo_method(c.ptr(), "set_point_in", i, c->get_point_in(i));714ur->commit_action();715return EditorPlugin::AFTER_GUI_INPUT_STOP;716} else if (dist_to_p_up < click_dist) {717EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();718ur->create_action(TTR("Reset Point Tilt"));719ur->add_do_method(c.ptr(), "set_point_tilt", i, 0.0f);720ur->add_undo_method(c.ptr(), "set_point_tilt", i, c->get_point_tilt(i));721ur->commit_action();722return EditorPlugin::AFTER_GUI_INPUT_STOP;723}724}725}726}727728return EditorPlugin::AFTER_GUI_INPUT_PASS;729}730731void Path3DEditorPlugin::edit(Object *p_object) {732if (p_object) {733path = Object::cast_to<Path3D>(p_object);734if (path) {735if (path->get_curve().is_valid()) {736path->get_curve()->emit_signal(CoreStringName(changed));737}738_update_toolbar();739}740} else {741Path3D *pre = path;742path = nullptr;743if (pre && pre->get_curve().is_valid()) {744pre->get_curve()->emit_signal(CoreStringName(changed));745}746}747748update_overlays();749//collision_polygon_editor->edit(Object::cast_to<Node>(p_object));750}751752bool Path3DEditorPlugin::handles(Object *p_object) const {753return p_object->is_class("Path3D");754}755756void Path3DEditorPlugin::make_visible(bool p_visible) {757if (p_visible) {758topmenu_bar->show();759} else {760topmenu_bar->hide();761762{763Path3D *pre = path;764path = nullptr;765if (pre && pre->get_curve().is_valid()) {766pre->get_curve()->emit_signal(CoreStringName(changed));767}768}769}770}771772void Path3DEditorPlugin::_mode_changed(int p_mode) {773curve_create->set_pressed_no_signal(p_mode == MODE_CREATE);774curve_edit_curve->set_pressed_no_signal(p_mode == MODE_EDIT_CURVE);775curve_edit_tilt->set_pressed_no_signal(p_mode == MODE_EDIT_TILT);776curve_edit->set_pressed_no_signal(p_mode == MODE_EDIT);777curve_del->set_pressed_no_signal(p_mode == MODE_DELETE);778779Node3DEditor::get_singleton()->clear_subgizmo_selection();780}781782void Path3DEditorPlugin::_toggle_closed_curve() {783Ref<Curve3D> c = path->get_curve();784if (c.is_null()) {785return;786}787if (c->get_point_count() < 2) {788return;789}790EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();791ur->create_action(TTR("Toggle Open/Closed Curve"));792ur->add_do_method(c.ptr(), "set_closed", !c.ptr()->is_closed());793ur->add_undo_method(c.ptr(), "set_closed", c.ptr()->is_closed());794ur->commit_action();795}796797void Path3DEditorPlugin::_handle_option_pressed(int p_option) {798PopupMenu *pm;799pm = handle_menu->get_popup();800801switch (p_option) {802case HANDLE_OPTION_ANGLE: {803bool is_checked = pm->is_item_checked(HANDLE_OPTION_ANGLE);804mirror_handle_angle = !is_checked;805pm->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);806pm->set_item_disabled(HANDLE_OPTION_LENGTH, !mirror_handle_angle);807} break;808case HANDLE_OPTION_LENGTH: {809bool is_checked = pm->is_item_checked(HANDLE_OPTION_LENGTH);810mirror_handle_length = !is_checked;811pm->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);812} break;813}814}815816void Path3DEditorPlugin::_create_curve() {817ERR_FAIL_NULL(path);818819Ref<Curve3D> new_curve;820new_curve.instantiate();821822EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();823undo_redo->create_action(TTR("Create Curve in Path3D"));824undo_redo->add_do_property(path, "curve", new_curve);825undo_redo->add_undo_property(path, "curve", Ref<Curve3D>());826undo_redo->add_do_method(this, "_update_toolbar");827undo_redo->add_undo_method(this, "_update_toolbar");828undo_redo->commit_action();829}830831void Path3DEditorPlugin::_confirm_clear_points() {832if (!path || path->get_curve().is_null() || path->get_curve()->get_point_count() == 0) {833return;834}835clear_points_dialog->reset_size();836clear_points_dialog->popup_centered();837}838839void Path3DEditorPlugin::_clear_points() {840EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();841PackedVector3Array points = path->get_curve()->get_points().duplicate();842843undo_redo->create_action(TTR("Clear Curve Points"));844undo_redo->add_do_method(this, "_clear_curve_points");845undo_redo->add_undo_method(this, "_restore_curve_points", points);846undo_redo->commit_action();847}848849void Path3DEditorPlugin::_clear_curve_points() {850if (!path || path->get_curve().is_null() || path->get_curve()->get_point_count() == 0) {851return;852}853Ref<Curve3D> curve = path->get_curve();854curve->set_closed(false);855curve->clear_points();856}857858void Path3DEditorPlugin::_restore_curve_points(const PackedVector3Array &p_points) {859if (!path || path->get_curve().is_null()) {860return;861}862Ref<Curve3D> curve = path->get_curve();863864if (curve->get_point_count() > 0) {865curve->clear_points();866}867868for (int i = 0; i < p_points.size(); i += 3) {869curve->add_point(p_points[i + 2], p_points[i], p_points[i + 1]);870}871}872873void Path3DEditorPlugin::_update_theme() {874curve_edit->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveEdit")));875curve_edit_curve->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveCurve")));876curve_edit_tilt->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveTilt")));877curve_create->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveCreate")));878curve_del->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveDelete")));879curve_closed->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("CurveClose")));880curve_clear_points->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("Clear")));881create_curve_button->set_button_icon(topmenu_bar->get_editor_theme_icon(SNAME("Curve3D")));882}883884void Path3DEditorPlugin::_update_toolbar() {885if (!path) {886return;887}888bool has_curve = path->get_curve().is_valid();889toolbar->set_visible(has_curve);890create_curve_button->set_visible(!has_curve);891}892893void Path3DEditorPlugin::_bind_methods() {894ClassDB::bind_method(D_METHOD("_update_toolbar"), &Path3DEditorPlugin::_update_toolbar);895ClassDB::bind_method(D_METHOD("_clear_curve_points"), &Path3DEditorPlugin::_clear_curve_points);896ClassDB::bind_method(D_METHOD("_restore_curve_points"), &Path3DEditorPlugin::_restore_curve_points);897}898899Path3DEditorPlugin::Path3DEditorPlugin() {900singleton = this;901mirror_handle_angle = true;902mirror_handle_length = true;903904disk_size = EDITOR_GET("editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size");905906Ref<Path3DGizmoPlugin> gizmo_plugin = memnew(Path3DGizmoPlugin(disk_size));907Node3DEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);908path_3d_gizmo_plugin = gizmo_plugin;909910topmenu_bar = memnew(HBoxContainer);911topmenu_bar->hide();912913toolbar = memnew(HBoxContainer);914topmenu_bar->add_child(toolbar);915916curve_edit = memnew(Button);917curve_edit->set_theme_type_variation(SceneStringName(FlatButton));918curve_edit->set_toggle_mode(true);919curve_edit->set_focus_mode(Control::FOCUS_ACCESSIBILITY);920curve_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"));921curve_edit->set_accessibility_name(TTRC("Select Points"));922toolbar->add_child(curve_edit);923curve_edit->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT));924925curve_edit_curve = memnew(Button);926curve_edit_curve->set_theme_type_variation(SceneStringName(FlatButton));927curve_edit_curve->set_toggle_mode(true);928curve_edit_curve->set_focus_mode(Control::FOCUS_ACCESSIBILITY);929curve_edit_curve->set_tooltip_text(TTR("Select Control Points") + "\n" + TTR("Shift+Click: Drag out Control Points"));930curve_edit_curve->set_accessibility_name(TTRC("Select Control Points"));931toolbar->add_child(curve_edit_curve);932curve_edit_curve->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_CURVE));933934curve_edit_tilt = memnew(Button);935curve_edit_tilt->set_theme_type_variation(SceneStringName(FlatButton));936curve_edit_tilt->set_toggle_mode(true);937curve_edit_tilt->set_focus_mode(Control::FOCUS_ACCESSIBILITY);938curve_edit_tilt->set_tooltip_text(TTR("Select Tilt Handles"));939toolbar->add_child(curve_edit_tilt);940curve_edit_tilt->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_EDIT_TILT));941942curve_create = memnew(Button);943curve_create->set_theme_type_variation(SceneStringName(FlatButton));944curve_create->set_toggle_mode(true);945curve_create->set_focus_mode(Control::FOCUS_ACCESSIBILITY);946curve_create->set_tooltip_text(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)"));947curve_create->set_accessibility_name(TTRC("Add Point (in empty space)"));948toolbar->add_child(curve_create);949curve_create->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_CREATE));950951curve_del = memnew(Button);952curve_del->set_theme_type_variation(SceneStringName(FlatButton));953curve_del->set_toggle_mode(true);954curve_del->set_focus_mode(Control::FOCUS_ACCESSIBILITY);955curve_del->set_tooltip_text(TTR("Delete Point"));956toolbar->add_child(curve_del);957curve_del->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_mode_changed).bind(MODE_DELETE));958959curve_closed = memnew(Button);960curve_closed->set_theme_type_variation(SceneStringName(FlatButton));961curve_closed->set_focus_mode(Control::FOCUS_ACCESSIBILITY);962curve_closed->set_tooltip_text(TTR("Close Curve"));963toolbar->add_child(curve_closed);964curve_closed->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_toggle_closed_curve));965966curve_clear_points = memnew(Button);967curve_clear_points->set_theme_type_variation(SceneStringName(FlatButton));968curve_clear_points->set_focus_mode(Control::FOCUS_ACCESSIBILITY);969curve_clear_points->set_tooltip_text(TTR("Clear Points"));970curve_clear_points->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_confirm_clear_points));971toolbar->add_child(curve_clear_points);972973clear_points_dialog = memnew(ConfirmationDialog);974clear_points_dialog->set_title(TTR("Please Confirm..."));975clear_points_dialog->set_text(TTR("Remove all curve points?"));976clear_points_dialog->connect(SceneStringName(confirmed), callable_mp(this, &Path3DEditorPlugin::_clear_points));977toolbar->add_child(clear_points_dialog);978979handle_menu = memnew(MenuButton);980handle_menu->set_flat(false);981handle_menu->set_theme_type_variation("FlatMenuButton");982handle_menu->set_text(TTR("Options"));983toolbar->add_child(handle_menu);984985create_curve_button = memnew(Button);986create_curve_button->set_text(TTR("Create Curve"));987create_curve_button->hide();988topmenu_bar->add_child(create_curve_button);989create_curve_button->connect(SceneStringName(pressed), callable_mp(this, &Path3DEditorPlugin::_create_curve));990991PopupMenu *menu = handle_menu->get_popup();992menu->add_check_item(TTR("Mirror Handle Angles"));993menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);994menu->add_check_item(TTR("Mirror Handle Lengths"));995menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);996menu->connect(SceneStringName(id_pressed), callable_mp(this, &Path3DEditorPlugin::_handle_option_pressed));997998curve_edit->set_pressed_no_signal(true);9991000topmenu_bar->connect(SceneStringName(theme_changed), callable_mp(this, &Path3DEditorPlugin::_update_theme));1001Node3DEditor::get_singleton()->add_control_to_menu_panel(topmenu_bar);1002}10031004Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) {1005Ref<Path3DGizmo> ref;10061007Path3D *path = Object::cast_to<Path3D>(p_spatial);1008if (path) {1009ref.instantiate(path, disk_size);1010}10111012return ref;1013}10141015bool Path3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {1016return Object::cast_to<Path3D>(p_spatial) != nullptr;1017}10181019String Path3DGizmoPlugin::get_gizmo_name() const {1020return "Path3D";1021}10221023void Path3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {1024Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());1025ERR_FAIL_NULL(path);10261027Ref<Curve3D> curve = path->get_curve();10281029Ref<StandardMaterial3D> handle_material = get_material("handles", p_gizmo);1030Ref<StandardMaterial3D> first_pt_handle_material = get_material("first_pt_handle", p_gizmo);1031Ref<StandardMaterial3D> last_pt_handle_material = get_material("last_pt_handle", p_gizmo);1032Ref<StandardMaterial3D> closed_pt_handle_material = get_material("closed_pt_handle", p_gizmo);10331034first_pt_handle_material->set_albedo(Color(0.2, 1.0, 0.0));1035last_pt_handle_material->set_albedo(Color(1.0, 0.2, 0.0));1036closed_pt_handle_material->set_albedo(Color(1.0, 0.8, 0.0));10371038PackedVector3Array handles;10391040if (Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {1041for (int idx = 0; idx < curve->get_point_count(); ++idx) {1042// Collect handles.1043const Vector3 pos = curve->get_point_position(idx);10441045handles.append(pos);1046}1047}10481049if (handles.size()) {1050// Point count.1051const int pc = handles.size();10521053// Initialize arrays for first point.1054PackedVector3Array first_pt;1055first_pt.append(handles[0]);10561057// Initialize arrays and add handle for last point if needed.1058if (pc > 1) {1059PackedVector3Array last_pt;1060last_pt.append(handles[handles.size() - 1]);1061handles.remove_at(handles.size() - 1);1062if (curve->is_closed()) {1063p_gizmo->add_vertices(last_pt, handle_material, Mesh::PRIMITIVE_POINTS);1064} else {1065p_gizmo->add_vertices(last_pt, last_pt_handle_material, Mesh::PRIMITIVE_POINTS);1066}1067}10681069// Add handle for first point.1070handles.remove_at(0);1071if (curve->is_closed()) {1072p_gizmo->add_vertices(first_pt, closed_pt_handle_material, Mesh::PRIMITIVE_POINTS);1073} else {1074p_gizmo->add_vertices(first_pt, first_pt_handle_material, Mesh::PRIMITIVE_POINTS);1075}10761077// Add handles for remaining intermediate points.1078if (!handles.is_empty()) {1079p_gizmo->add_vertices(handles, handle_material, Mesh::PRIMITIVE_POINTS);1080}1081}1082}10831084int Path3DGizmoPlugin::subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const {1085Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());1086ERR_FAIL_NULL_V(path, -1);1087Ref<Curve3D> curve = path->get_curve();1088ERR_FAIL_COND_V(curve.is_null(), -1);10891090if (Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {1091for (int idx = 0; idx < curve->get_point_count(); ++idx) {1092Vector3 pos = path->get_global_transform().xform(curve->get_point_position(idx));1093if (p_camera->unproject_position(pos).distance_to(p_point) < 20) {1094return idx;1095}1096}1097}1098return -1;1099}11001101Vector<int> Path3DGizmoPlugin::subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const {1102Vector<int> contained_points;11031104Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());1105ERR_FAIL_NULL_V(path, contained_points);1106Ref<Curve3D> curve = path->get_curve();1107ERR_FAIL_COND_V(curve.is_null(), contained_points);11081109if (Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {1110for (int idx = 0; idx < curve->get_point_count(); ++idx) {1111Vector3 pos = path->get_global_transform().xform(curve->get_point_position(idx));1112bool is_contained_in_frustum = true;1113for (int i = 0; i < p_frustum.size(); ++i) {1114if (p_frustum[i].distance_to(pos) > 0) {1115is_contained_in_frustum = false;1116break;1117}1118}11191120if (is_contained_in_frustum) {1121contained_points.push_back(idx);1122}1123}1124}11251126return contained_points;1127}11281129Transform3D Path3DGizmoPlugin::get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const {1130Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());1131ERR_FAIL_NULL_V(path, Transform3D());1132Ref<Curve3D> curve = path->get_curve();1133ERR_FAIL_COND_V(curve.is_null(), Transform3D());1134ERR_FAIL_INDEX_V(p_id, curve->get_point_count(), Transform3D());11351136Basis basis = transformation_locked_basis.has(p_id) ? transformation_locked_basis[p_id] : curve->get_point_baked_posture(p_id, true);1137Vector3 pos = curve->get_point_position(p_id);11381139Transform3D t = Transform3D(basis, pos);1140return t;1141}11421143void Path3DGizmoPlugin::set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) {1144Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());1145ERR_FAIL_NULL(path);1146Ref<Curve3D> curve = path->get_curve();1147ERR_FAIL_COND(curve.is_null());1148ERR_FAIL_INDEX(p_id, curve->get_point_count());11491150if (!transformation_locked_basis.has(p_id)) {1151transformation_locked_basis[p_id] = Basis(curve->get_point_baked_posture(p_id, true));1152}1153curve->set_point_position(p_id, p_transform.origin);1154}11551156void Path3DGizmoPlugin::commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) {1157Path3D *path = Object::cast_to<Path3D>(p_gizmo->get_node_3d());1158ERR_FAIL_NULL(path);1159Ref<Curve3D> curve = path->get_curve();1160ERR_FAIL_COND(curve.is_null());11611162transformation_locked_basis.clear();11631164if (p_cancel) {1165for (int i = 0; i < p_ids.size(); ++i) {1166curve->set_point_position(p_ids[i], p_restore[i].origin);1167}1168return;1169}11701171EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();11721173undo_redo->create_action(TTR("Set Curve Point Position"));11741175for (int i = 0; i < p_ids.size(); ++i) {1176const int idx = p_ids[i];1177undo_redo->add_do_method(curve.ptr(), "set_point_position", idx, curve->get_point_position(idx));1178undo_redo->add_undo_method(curve.ptr(), "set_point_position", idx, p_restore[i].origin);1179}1180undo_redo->commit_action();1181}11821183int Path3DGizmoPlugin::get_priority() const {1184return -1;1185}11861187Path3DGizmoPlugin::Path3DGizmoPlugin(float p_disk_size) {1188Color path_color = SceneTree::get_singleton()->get_debug_paths_color();1189Color path_tilt_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/path_tilt");1190disk_size = p_disk_size;11911192create_material("path_material", path_color);1193create_material("path_thin_material", Color(0.6, 0.6, 0.6));1194create_material("path_tilt_material", path_tilt_color);1195create_material("path_tilt_muted_material", path_tilt_color * 0.7);1196create_handle_material("handles", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorPathSmoothHandle"), EditorStringName(EditorIcons)));1197create_handle_material("first_pt_handle", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorPathSmoothHandle"), EditorStringName(EditorIcons)));1198create_handle_material("last_pt_handle", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorPathSmoothHandle"), EditorStringName(EditorIcons)));1199create_handle_material("closed_pt_handle", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorPathSmoothHandle"), EditorStringName(EditorIcons)));1200create_handle_material("sec_handles", false, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("EditorCurveHandle"), EditorStringName(EditorIcons)));1201}120212031204