| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | /*  path_3d_editor_plugin.cpp                                            */ | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2022-01-03 21:27:34 +01:00
										 |  |  | /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* 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 20:20:45 +03: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"
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | #include "node_3d_editor_plugin.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "scene/resources/curve.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | static bool _is_in_handle(int p_id, int p_num_points) { | 
					
						
							|  |  |  | 	int t = (p_id + 1) % 2; | 
					
						
							|  |  |  | 	int idx = (p_id + 1) / 2; | 
					
						
							|  |  |  | 	// order of points is [out_0, out_1, in_1, out_2, in_2, ... out_n-1, in_n-1, in_n]
 | 
					
						
							|  |  |  | 	if (idx == 0) { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} else if (idx == (p_num_points - 1)) { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return (t == 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-11 12:33:37 +01:00
										 |  |  | String Path3DGizmo::get_handle_name(int p_id, bool p_secondary) const { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	Ref<Curve3D> c = path->get_curve(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (c.is_null()) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		return ""; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 15:00:40 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 	// (p_id + 1) Accounts for the first point only having an "out" handle
 | 
					
						
							|  |  |  | 	int idx = (p_id + 1) / 2; | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	String n = TTR("Curve Point #") + itos(idx); | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 	if (_is_in_handle(p_id, c->get_point_count())) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		n += " In"; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		n += " Out"; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return n; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											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 15:00:40 -03:00
										 |  |  | 	Ref<Curve3D> c = path->get_curve(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (c.is_null()) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		return Variant(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 15:00:40 -03:00
										 |  |  | 		return original; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 	// (p_id + 1) Accounts for the first point only having an "out" handle
 | 
					
						
							|  |  |  | 	int idx = (p_id + 1) / 2; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector3 ofs; | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 	if (_is_in_handle(p_id, c->get_point_count())) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		ofs = c->get_point_in(idx); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		ofs = c->get_point_out(idx); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	original = ofs + c->get_point_position(idx); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03: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 15:00:40 -03:00
										 |  |  | 	Ref<Curve3D> c = path->get_curve(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (c.is_null()) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	Transform3D gt = path->get_global_transform(); | 
					
						
							|  |  |  | 	Transform3D gi = gt.affine_inverse(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	Vector3 ray_from = p_camera->project_ray_origin(p_point); | 
					
						
							|  |  |  | 	Vector3 ray_dir = p_camera->project_ray_normal(p_point); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 12:11:12 +02:00
										 |  |  | 	// Setting curve point positions
 | 
					
						
							| 
									
										
										
										
											2022-01-11 12:33:37 +01:00
										 |  |  | 	if (!p_secondary) { | 
					
						
							| 
									
										
										
										
											2022-05-03 07:50:35 -05:00
										 |  |  | 		const Plane p = Plane(p_camera->get_transform().basis.get_column(2), gt.xform(original)); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Vector3 inters; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		if (p.intersects_ray(ray_from, ray_dir, &inters)) { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 			if (Node3DEditor::get_singleton()->is_snap_enabled()) { | 
					
						
							|  |  |  | 				float snap = Node3DEditor::get_singleton()->get_translate_snap(); | 
					
						
							| 
									
										
										
										
											2017-06-30 14:47:17 -04:00
										 |  |  | 				inters.snap(Vector3(snap, snap, snap)); | 
					
						
							| 
									
										
										
										
											2016-11-14 14:46:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-24 16:47:34 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			Vector3 local = gi.xform(inters); | 
					
						
							| 
									
										
										
										
											2021-06-23 16:49:50 +02:00
										 |  |  | 			c->set_point_position(p_id, local); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 	// (p_id + 1) Accounts for the first point only having an "out" handle
 | 
					
						
							|  |  |  | 	int idx = (p_id + 1) / 2; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 	Vector3 base = c->get_point_position(idx); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-03 07:50:35 -05:00
										 |  |  | 	Plane p(p_camera->get_transform().basis.get_column(2), gt.xform(original)); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector3 inters; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 12:11:12 +02:00
										 |  |  | 	// Setting curve in/out positions
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	if (p.intersects_ray(ray_from, ray_dir, &inters)) { | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 		if (!Path3DEditorPlugin::singleton->is_handle_clicked()) { | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 			orig_in_length = c->get_point_in(idx).length(); | 
					
						
							|  |  |  | 			orig_out_length = c->get_point_out(idx).length(); | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 			Path3DEditorPlugin::singleton->set_handle_clicked(true); | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		Vector3 local = gi.xform(inters) - base; | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 		if (Node3DEditor::get_singleton()->is_snap_enabled()) { | 
					
						
							|  |  |  | 			float snap = Node3DEditor::get_singleton()->get_translate_snap(); | 
					
						
							| 
									
										
										
										
											2019-07-03 12:11:12 +02:00
										 |  |  | 			local.snap(Vector3(snap, snap, snap)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 		if (_is_in_handle(p_id, c->get_point_count())) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 			c->set_point_in(idx, local); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) { | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 				c->set_point_out(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length)); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 			c->set_point_out(idx, local); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) { | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 				c->set_point_in(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_in_length)); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03: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 15:00:40 -03:00
										 |  |  | 	Ref<Curve3D> c = path->get_curve(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (c.is_null()) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-11 12:33:37 +01:00
										 |  |  | 	if (!p_secondary) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		if (p_cancel) { | 
					
						
							| 
									
										
										
										
											2021-06-23 16:49:50 +02:00
										 |  |  | 			c->set_point_position(p_id, p_restore); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 		ur->create_action(TTR("Set Curve Point Position")); | 
					
						
							| 
									
										
										
										
											2021-06-23 16:49:50 +02:00
										 |  |  | 		ur->add_do_method(c.ptr(), "set_point_position", p_id, c->get_point_position(p_id)); | 
					
						
							|  |  |  | 		ur->add_undo_method(c.ptr(), "set_point_position", p_id, p_restore); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 	// (p_id + 1) Accounts for the first point only having an "out" handle
 | 
					
						
							|  |  |  | 	int idx = (p_id + 1) / 2; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-03 16:13:54 +12:00
										 |  |  | 	if (_is_in_handle(p_id, c->get_point_count())) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		if (p_cancel) { | 
					
						
							| 
									
										
										
										
											2021-06-23 16:49:50 +02:00
										 |  |  | 			c->set_point_in(p_id, p_restore); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-21 22:35:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 		ur->create_action(TTR("Set Curve In Position")); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		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-05-01 11:13:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +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)); | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		ur->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (p_cancel) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 			c->set_point_out(idx, p_restore); | 
					
						
							| 
									
										
										
										
											2018-04-21 22:35:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-21 22:35:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 		ur->create_action(TTR("Set Curve Out Position")); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		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 11:13:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +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)); | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		ur->commit_action(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 12:40:52 +02:00
										 |  |  | void Path3DGizmo::redraw() { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-15 01:01:52 -03: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); | 
					
						
							|  |  |  | 	Ref<StandardMaterial3D> handles_material = gizmo_plugin->get_material("handles"); | 
					
						
							| 
									
										
										
										
											2020-11-08 22:16:26 -05:00
										 |  |  | 	Ref<StandardMaterial3D> sec_handles_material = gizmo_plugin->get_material("sec_handles"); | 
					
						
							| 
									
										
										
										
											2018-07-25 00:08:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	Ref<Curve3D> c = path->get_curve(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (c.is_null()) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	Vector<Vector3> v3a = c->tessellate(); | 
					
						
							|  |  |  | 	//Vector<Vector3> v3a=c->get_baked_points();
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int v3s = v3a.size(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (v3s == 0) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	Vector<Vector3> v3p; | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 	const Vector3 *r = v3a.ptr(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 16:47:34 -05:00
										 |  |  | 	// BUG: the following won't work when v3s, avoid drawing as a temporary workaround.
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	for (int i = 0; i < v3s - 1; i++) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		v3p.push_back(r[i]); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		v3p.push_back(r[i + 1]); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		//v3p.push_back(r[i]);
 | 
					
						
							|  |  |  | 		//v3p.push_back(r[i]+Vector3(0,0.2,0));
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 15:11:16 -03:00
										 |  |  | 	if (v3p.size() > 1) { | 
					
						
							| 
									
										
										
										
											2018-07-25 00:08:49 +02:00
										 |  |  | 		add_lines(v3p, path_material); | 
					
						
							| 
									
										
										
										
											2017-08-18 15:11:16 -03:00
										 |  |  | 		add_collision_segments(v3p); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	if (Path3DEditorPlugin::singleton->get_edited_path() == path) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		v3p.clear(); | 
					
						
							|  |  |  | 		Vector<Vector3> handles; | 
					
						
							|  |  |  | 		Vector<Vector3> sec_handles; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		for (int i = 0; i < c->get_point_count(); i++) { | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 			Vector3 p = c->get_point_position(i); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			handles.push_back(p); | 
					
						
							| 
									
										
										
										
											2022-06-02 21:15:15 +12:00
										 |  |  | 			// push Out points first so they get selected if the In and Out points are on top of each other.
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 			if (i < c->get_point_count() - 1) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 				v3p.push_back(p); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 				v3p.push_back(p + c->get_point_out(i)); | 
					
						
							|  |  |  | 				sec_handles.push_back(p + c->get_point_out(i)); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-06-02 21:15:15 +12:00
										 |  |  | 			if (i > 0) { | 
					
						
							|  |  |  | 				v3p.push_back(p); | 
					
						
							|  |  |  | 				v3p.push_back(p + c->get_point_in(i)); | 
					
						
							|  |  |  | 				sec_handles.push_back(p + c->get_point_in(i)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 15:11:16 -03:00
										 |  |  | 		if (v3p.size() > 1) { | 
					
						
							| 
									
										
										
										
											2018-07-25 00:08:49 +02:00
										 |  |  | 			add_lines(v3p, path_thin_material); | 
					
						
							| 
									
										
										
										
											2017-08-18 15:11:16 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (handles.size()) { | 
					
						
							| 
									
										
										
										
											2018-07-25 00:08:49 +02:00
										 |  |  | 			add_handles(handles, handles_material); | 
					
						
							| 
									
										
										
										
											2017-08-18 15:11:16 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (sec_handles.size()) { | 
					
						
							| 
									
										
										
										
											2021-06-23 16:49:50 +02:00
										 |  |  | 			add_handles(sec_handles, sec_handles_material, Vector<int>(), false, true); | 
					
						
							| 
									
										
										
										
											2017-08-18 15:11:16 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 12:40:52 +02:00
										 |  |  | Path3DGizmo::Path3DGizmo(Path3D *p_path) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	path = p_path; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	set_spatial_node(p_path); | 
					
						
							| 
									
										
										
										
											2020-11-24 10:12:55 +01:00
										 |  |  | 	orig_in_length = 0; | 
					
						
							|  |  |  | 	orig_out_length = 0; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | EditorPlugin::AfterGUIInput Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!path) { | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 		return EditorPlugin::AFTER_GUI_INPUT_PASS; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	Ref<Curve3D> c = path->get_curve(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (c.is_null()) { | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 		return EditorPlugin::AFTER_GUI_INPUT_PASS; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	Transform3D gt = path->get_global_transform(); | 
					
						
							|  |  |  | 	Transform3D it = gt.affine_inverse(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	static const int click_dist = 10; //should make global
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 16:47:34 -05: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 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (!mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 			set_handle_clicked(false); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 		if (mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->is_ctrl_pressed()))) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			//click into curve, break it down
 | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 			Vector<Vector3> v3a = c->tessellate(); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 			int rc = v3a.size(); | 
					
						
							|  |  |  | 			int closest_seg = -1; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			Vector3 closest_seg_point; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 			if (rc >= 2) { | 
					
						
							| 
									
										
										
										
											2022-04-07 13:23:40 +03:00
										 |  |  | 				int idx = 0; | 
					
						
							| 
									
										
										
										
											2020-02-17 18:06:54 -03:00
										 |  |  | 				const Vector3 *r = v3a.ptr(); | 
					
						
							| 
									
										
										
										
											2022-04-07 13:23:40 +03:00
										 |  |  | 				float closest_d = 1e20; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (p_camera->unproject_position(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist) { | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 					return EditorPlugin::AFTER_GUI_INPUT_PASS; //nope, existing
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 				for (int i = 0; i < c->get_point_count() - 1; i++) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 					//find the offset and point index of the place to break up
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 					int j = idx; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					if (p_camera->unproject_position(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist) { | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 						return EditorPlugin::AFTER_GUI_INPUT_PASS; //nope, existing
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 					while (j < rc && c->get_point_position(i + 1) != r[j]) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 						Vector3 from = r[j]; | 
					
						
							|  |  |  | 						Vector3 to = r[j + 1]; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 						real_t cdist = from.distance_to(to); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 						from = gt.xform(from); | 
					
						
							|  |  |  | 						to = gt.xform(to); | 
					
						
							|  |  |  | 						if (cdist > 0) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 							Vector2 s[2]; | 
					
						
							|  |  |  | 							s[0] = p_camera->unproject_position(from); | 
					
						
							|  |  |  | 							s[1] = p_camera->unproject_position(to); | 
					
						
							| 
									
										
										
										
											2020-05-25 20:20:45 +03:00
										 |  |  | 							Vector2 inters = Geometry2D::get_closest_point_to_segment(mbpos, s); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 							float d = inters.distance_to(mbpos); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 							if (d < 10 && d < closest_d) { | 
					
						
							|  |  |  | 								closest_d = d; | 
					
						
							|  |  |  | 								closest_seg = i; | 
					
						
							|  |  |  | 								Vector3 ray_from = p_camera->project_ray_origin(mbpos); | 
					
						
							|  |  |  | 								Vector3 ray_dir = p_camera->project_ray_normal(mbpos); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 								Vector3 ra, rb; | 
					
						
							| 
									
										
										
										
											2020-05-25 20:20:45 +03:00
										 |  |  | 								Geometry3D::get_closest_points_between_segments(ray_from, ray_from + ray_dir * 4096, from, to, ra, rb); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 								closest_seg_point = it.xform(rb); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						j++; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					if (idx == j) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 						idx++; //force next
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 						idx = j; //swap
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					if (j == rc) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-27 10:36:51 +01:00
										 |  |  | 			UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 			if (closest_seg != -1) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 				//subdivide
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 				ur->create_action(TTR("Split Path")); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05: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 17:20:26 +09:00
										 |  |  | 				return EditorPlugin::AFTER_GUI_INPUT_STOP; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03: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 07:50:35 -05:00
										 |  |  | 				Plane p(p_camera->get_transform().basis.get_column(2), origin); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 				Vector3 ray_from = p_camera->project_ray_origin(mbpos); | 
					
						
							|  |  |  | 				Vector3 ray_dir = p_camera->project_ray_normal(mbpos); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				Vector3 inters; | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 				if (p.intersects_ray(ray_from, ray_dir, &inters)) { | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 					ur->create_action(TTR("Add Point to Curve")); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05: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 17:20:26 +09:00
										 |  |  | 					return EditorPlugin::AFTER_GUI_INPUT_STOP; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				//add new at pos
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05: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-24 17:11:20 -05:00
										 |  |  | 			for (int i = 0; i < c->get_point_count(); i++) { | 
					
						
							| 
									
										
										
										
											2017-09-10 15:37:49 +02:00
										 |  |  | 				real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_position(i))).distance_to(mbpos); | 
					
						
							|  |  |  | 				real_t dist_to_p_out = p_camera->unproject_position(gt.xform(c->get_point_position(i) + c->get_point_out(i))).distance_to(mbpos); | 
					
						
							|  |  |  | 				real_t dist_to_p_in = p_camera->unproject_position(gt.xform(c->get_point_position(i) + c->get_point_in(i))).distance_to(mbpos); | 
					
						
							| 
									
										
										
										
											2016-10-26 23:18:18 -07: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-01-27 10:36:51 +01:00
										 |  |  | 					UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); | 
					
						
							| 
									
										
										
										
											2016-10-26 23:18:18 -07:00
										 |  |  | 					ur->create_action(TTR("Remove Path Point")); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05: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-26 23:18:18 -07:00
										 |  |  | 					ur->commit_action(); | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 					return EditorPlugin::AFTER_GUI_INPUT_STOP; | 
					
						
							| 
									
										
										
										
											2016-10-26 23:18:18 -07:00
										 |  |  | 				} else if (dist_to_p_out < click_dist) { | 
					
						
							| 
									
										
										
										
											2022-01-27 10:36:51 +01:00
										 |  |  | 					UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); | 
					
						
							| 
									
										
										
										
											2016-10-26 23:18:18 -07:00
										 |  |  | 					ur->create_action(TTR("Remove Out-Control Point")); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05: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-26 23:18:18 -07:00
										 |  |  | 					ur->commit_action(); | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 					return EditorPlugin::AFTER_GUI_INPUT_STOP; | 
					
						
							| 
									
										
										
										
											2016-10-26 23:18:18 -07:00
										 |  |  | 				} else if (dist_to_p_in < click_dist) { | 
					
						
							| 
									
										
										
										
											2022-01-27 10:36:51 +01:00
										 |  |  | 					UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); | 
					
						
							| 
									
										
										
										
											2016-10-26 23:18:18 -07:00
										 |  |  | 					ur->create_action(TTR("Remove In-Control Point")); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05: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-26 23:18:18 -07:00
										 |  |  | 					ur->commit_action(); | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 					return EditorPlugin::AFTER_GUI_INPUT_STOP; | 
					
						
							| 
									
										
										
										
											2016-10-26 23:18:18 -07:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 17:20:26 +09:00
										 |  |  | 	return EditorPlugin::AFTER_GUI_INPUT_PASS; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void Path3DEditorPlugin::edit(Object *p_object) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	if (p_object) { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 		path = Object::cast_to<Path3D>(p_object); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		if (path) { | 
					
						
							|  |  |  | 			if (path->get_curve().is_valid()) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 				path->get_curve()->emit_signal(SNAME("changed")); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 		Path3D *pre = path; | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 		path = nullptr; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		if (pre) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			pre->get_curve()->emit_signal(SNAME("changed")); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-24 22:58:51 +02:00
										 |  |  | 	//collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | bool Path3DEditorPlugin::handles(Object *p_object) const { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	return p_object->is_class("Path3D"); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void Path3DEditorPlugin::make_visible(bool p_visible) { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	if (p_visible) { | 
					
						
							|  |  |  | 		curve_create->show(); | 
					
						
							|  |  |  | 		curve_edit->show(); | 
					
						
							|  |  |  | 		curve_del->show(); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		curve_close->show(); | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 		handle_menu->show(); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		sep->show(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		curve_create->hide(); | 
					
						
							|  |  |  | 		curve_edit->hide(); | 
					
						
							|  |  |  | 		curve_del->hide(); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		curve_close->hide(); | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 		handle_menu->hide(); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		sep->hide(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 			Path3D *pre = path; | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 			path = nullptr; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			if (pre && pre->get_curve().is_valid()) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 				pre->get_curve()->emit_signal(SNAME("changed")); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void Path3DEditorPlugin::_mode_changed(int p_idx) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	curve_create->set_pressed(p_idx == 0); | 
					
						
							|  |  |  | 	curve_edit->set_pressed(p_idx == 1); | 
					
						
							|  |  |  | 	curve_del->set_pressed(p_idx == 2); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void Path3DEditorPlugin::_close_curve() { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	Ref<Curve3D> c = path->get_curve(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (c.is_null()) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (c->get_point_count() < 2) { | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-09-14 21:24:55 -04:00
										 |  |  | 	if (c->get_point_position(0) == c->get_point_position(c->get_point_count() - 1)) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-27 10:36:51 +01:00
										 |  |  | 	UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); | 
					
						
							| 
									
										
										
										
											2021-09-14 21:24:55 -04: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 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void Path3DEditorPlugin::_handle_option_pressed(int p_option) { | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01: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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-28 20:21:50 +03:00
										 |  |  | void Path3DEditorPlugin::_update_theme() { | 
					
						
							|  |  |  | 	// TODO: Split the EditorPlugin instance from the UI instance and connect this properly.
 | 
					
						
							|  |  |  | 	// See the 2D path editor for inspiration.
 | 
					
						
							|  |  |  | 	curve_edit->set_icon(Node3DEditor::get_singleton()->get_theme_icon(SNAME("CurveEdit"), SNAME("EditorIcons"))); | 
					
						
							|  |  |  | 	curve_create->set_icon(Node3DEditor::get_singleton()->get_theme_icon(SNAME("CurveCreate"), SNAME("EditorIcons"))); | 
					
						
							|  |  |  | 	curve_del->set_icon(Node3DEditor::get_singleton()->get_theme_icon(SNAME("CurveDelete"), SNAME("EditorIcons"))); | 
					
						
							|  |  |  | 	curve_close->set_icon(Node3DEditor::get_singleton()->get_theme_icon(SNAME("CurveClose"), SNAME("EditorIcons"))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void Path3DEditorPlugin::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2022-01-28 20:21:50 +03:00
										 |  |  | 	switch (p_what) { | 
					
						
							|  |  |  | 		case NOTIFICATION_ENTER_TREE: { | 
					
						
							|  |  |  | 			curve_create->connect("pressed", callable_mp(this, &Path3DEditorPlugin::_mode_changed), make_binds(0)); | 
					
						
							|  |  |  | 			curve_edit->connect("pressed", callable_mp(this, &Path3DEditorPlugin::_mode_changed), make_binds(1)); | 
					
						
							|  |  |  | 			curve_del->connect("pressed", callable_mp(this, &Path3DEditorPlugin::_mode_changed), make_binds(2)); | 
					
						
							|  |  |  | 			curve_close->connect("pressed", callable_mp(this, &Path3DEditorPlugin::_close_curve)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			_update_theme(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case NOTIFICATION_READY: { | 
					
						
							|  |  |  | 			Node3DEditor::get_singleton()->connect("theme_changed", callable_mp(this, &Path3DEditorPlugin::_update_theme)); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void Path3DEditorPlugin::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | Path3DEditorPlugin *Path3DEditorPlugin::singleton = nullptr; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-27 10:36:51 +01:00
										 |  |  | Path3DEditorPlugin::Path3DEditorPlugin() { | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	path = nullptr; | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	singleton = this; | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 	mirror_handle_angle = true; | 
					
						
							|  |  |  | 	mirror_handle_length = true; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 12:40:52 +02:00
										 |  |  | 	Ref<Path3DGizmoPlugin> gizmo_plugin; | 
					
						
							| 
									
										
										
										
											2021-06-17 16:03:09 -06:00
										 |  |  | 	gizmo_plugin.instantiate(); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Node3DEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	sep = memnew(VSeparator); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	sep->hide(); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Node3DEditor::get_singleton()->add_control_to_menu_panel(sep); | 
					
						
							| 
									
										
										
										
											2022-01-28 20:21:50 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	curve_edit = memnew(Button); | 
					
						
							|  |  |  | 	curve_edit->set_flat(true); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	curve_edit->set_toggle_mode(true); | 
					
						
							|  |  |  | 	curve_edit->hide(); | 
					
						
							|  |  |  | 	curve_edit->set_focus_mode(Control::FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	curve_edit->set_tooltip(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string((Key)KeyModifierMask::CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point")); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Node3DEditor::get_singleton()->add_control_to_menu_panel(curve_edit); | 
					
						
							| 
									
										
										
										
											2022-01-28 20:21:50 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	curve_create = memnew(Button); | 
					
						
							|  |  |  | 	curve_create->set_flat(true); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	curve_create->set_toggle_mode(true); | 
					
						
							|  |  |  | 	curve_create->hide(); | 
					
						
							|  |  |  | 	curve_create->set_focus_mode(Control::FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2017-05-24 17:11:20 -05:00
										 |  |  | 	curve_create->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)")); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Node3DEditor::get_singleton()->add_control_to_menu_panel(curve_create); | 
					
						
							| 
									
										
										
										
											2022-01-28 20:21:50 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	curve_del = memnew(Button); | 
					
						
							|  |  |  | 	curve_del->set_flat(true); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	curve_del->set_toggle_mode(true); | 
					
						
							|  |  |  | 	curve_del->hide(); | 
					
						
							|  |  |  | 	curve_del->set_focus_mode(Control::FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2016-05-19 00:08:12 +02:00
										 |  |  | 	curve_del->set_tooltip(TTR("Delete Point")); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Node3DEditor::get_singleton()->add_control_to_menu_panel(curve_del); | 
					
						
							| 
									
										
										
										
											2022-01-28 20:21:50 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:49:04 +02:00
										 |  |  | 	curve_close = memnew(Button); | 
					
						
							|  |  |  | 	curve_close->set_flat(true); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	curve_close->hide(); | 
					
						
							|  |  |  | 	curve_close->set_focus_mode(Control::FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	curve_close->set_tooltip(TTR("Close Curve")); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Node3DEditor::get_singleton()->add_control_to_menu_panel(curve_close); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 	PopupMenu *menu; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handle_menu = memnew(MenuButton); | 
					
						
							|  |  |  | 	handle_menu->set_text(TTR("Options")); | 
					
						
							|  |  |  | 	handle_menu->hide(); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Node3DEditor::get_singleton()->add_control_to_menu_panel(handle_menu); | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	menu = handle_menu->get_popup(); | 
					
						
							|  |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	menu->connect("id_pressed", callable_mp(this, &Path3DEditorPlugin::_handle_option_pressed)); | 
					
						
							| 
									
										
										
										
											2018-05-01 11:13:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 	curve_edit->set_pressed(true); | 
					
						
							| 
									
										
										
										
											2018-07-25 00:08:49 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | Path3DEditorPlugin::~Path3DEditorPlugin() { | 
					
						
							| 
									
										
										
										
											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 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	Path3D *path = Object::cast_to<Path3D>(p_spatial); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (path) { | 
					
						
							| 
									
										
										
										
											2020-05-10 12:56:01 +02:00
										 |  |  | 		ref = Ref<Path3DGizmo>(memnew(Path3DGizmo(path))); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 00:08:49 +02:00
										 |  |  | 	return ref; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 18:39:21 -04: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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 12:40:52 +02:00
										 |  |  | int Path3DGizmoPlugin::get_priority() const { | 
					
						
							| 
									
										
										
										
											2019-03-12 00:30:50 +01:00
										 |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-06 12:40:52 +02:00
										 |  |  | Path3DGizmoPlugin::Path3DGizmoPlugin() { | 
					
						
							| 
									
										
										
										
											2018-07-25 00:08:49 +02:00
										 |  |  | 	Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8)); | 
					
						
							| 
									
										
										
										
											2018-09-02 22:31:03 +02:00
										 |  |  | 	create_material("path_material", path_color); | 
					
						
							| 
									
										
										
										
											2019-08-18 22:18:57 +02:00
										 |  |  | 	create_material("path_thin_material", Color(0.5, 0.5, 0.5)); | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	create_handle_material("handles", false, Node3DEditor::get_singleton()->get_theme_icon(SNAME("EditorPathSmoothHandle"), SNAME("EditorIcons"))); | 
					
						
							|  |  |  | 	create_handle_material("sec_handles", false, Node3DEditor::get_singleton()->get_theme_icon(SNAME("EditorCurveHandle"), SNAME("EditorIcons"))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:00:40 -03:00
										 |  |  | } |