path_editor_plugin.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*************************************************************************/
  2. /* path_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "path_editor_plugin.h"
  31. #include "core/os/keyboard.h"
  32. #include "scene/resources/curve.h"
  33. #include "spatial_editor_plugin.h"
  34. String PathSpatialGizmo::get_handle_name(int p_idx) const {
  35. Ref<Curve3D> c = path->get_curve();
  36. if (c.is_null())
  37. return "";
  38. if (p_idx < c->get_point_count()) {
  39. return TTR("Curve Point #") + itos(p_idx);
  40. }
  41. p_idx = p_idx - c->get_point_count() + 1;
  42. int idx = p_idx / 2;
  43. int t = p_idx % 2;
  44. String n = TTR("Curve Point #") + itos(idx);
  45. if (t == 0)
  46. n += " In";
  47. else
  48. n += " Out";
  49. return n;
  50. }
  51. Variant PathSpatialGizmo::get_handle_value(int p_idx) {
  52. Ref<Curve3D> c = path->get_curve();
  53. if (c.is_null())
  54. return Variant();
  55. if (p_idx < c->get_point_count()) {
  56. original = c->get_point_position(p_idx);
  57. return original;
  58. }
  59. p_idx = p_idx - c->get_point_count() + 1;
  60. int idx = p_idx / 2;
  61. int t = p_idx % 2;
  62. Vector3 ofs;
  63. if (t == 0)
  64. ofs = c->get_point_in(idx);
  65. else
  66. ofs = c->get_point_out(idx);
  67. original = ofs + c->get_point_position(idx);
  68. return ofs;
  69. }
  70. void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) {
  71. Ref<Curve3D> c = path->get_curve();
  72. if (c.is_null())
  73. return;
  74. Transform gt = path->get_global_transform();
  75. Transform gi = gt.affine_inverse();
  76. Vector3 ray_from = p_camera->project_ray_origin(p_point);
  77. Vector3 ray_dir = p_camera->project_ray_normal(p_point);
  78. // Setting curve point positions
  79. if (p_idx < c->get_point_count()) {
  80. Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2));
  81. Vector3 inters;
  82. if (p.intersects_ray(ray_from, ray_dir, &inters)) {
  83. if (SpatialEditor::get_singleton()->is_snap_enabled()) {
  84. float snap = SpatialEditor::get_singleton()->get_translate_snap();
  85. inters.snap(Vector3(snap, snap, snap));
  86. }
  87. Vector3 local = gi.xform(inters);
  88. c->set_point_position(p_idx, local);
  89. }
  90. return;
  91. }
  92. p_idx = p_idx - c->get_point_count() + 1;
  93. int idx = p_idx / 2;
  94. int t = p_idx % 2;
  95. Vector3 base = c->get_point_position(idx);
  96. Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2));
  97. Vector3 inters;
  98. // Setting curve in/out positions
  99. if (p.intersects_ray(ray_from, ray_dir, &inters)) {
  100. if (!PathEditorPlugin::singleton->is_handle_clicked()) {
  101. orig_in_length = c->get_point_in(idx).length();
  102. orig_out_length = c->get_point_out(idx).length();
  103. PathEditorPlugin::singleton->set_handle_clicked(true);
  104. }
  105. Vector3 local = gi.xform(inters) - base;
  106. if (SpatialEditor::get_singleton()->is_snap_enabled()) {
  107. float snap = SpatialEditor::get_singleton()->get_translate_snap();
  108. local.snap(Vector3(snap, snap, snap));
  109. }
  110. if (t == 0) {
  111. c->set_point_in(idx, local);
  112. if (PathEditorPlugin::singleton->mirror_angle_enabled())
  113. c->set_point_out(idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length));
  114. } else {
  115. c->set_point_out(idx, local);
  116. if (PathEditorPlugin::singleton->mirror_angle_enabled())
  117. c->set_point_in(idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_in_length));
  118. }
  119. }
  120. }
  121. void PathSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) {
  122. Ref<Curve3D> c = path->get_curve();
  123. if (c.is_null())
  124. return;
  125. UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo();
  126. if (p_idx < c->get_point_count()) {
  127. if (p_cancel) {
  128. c->set_point_position(p_idx, p_restore);
  129. return;
  130. }
  131. ur->create_action(TTR("Set Curve Point Position"));
  132. ur->add_do_method(c.ptr(), "set_point_position", p_idx, c->get_point_position(p_idx));
  133. ur->add_undo_method(c.ptr(), "set_point_position", p_idx, p_restore);
  134. ur->commit_action();
  135. return;
  136. }
  137. p_idx = p_idx - c->get_point_count() + 1;
  138. int idx = p_idx / 2;
  139. int t = p_idx % 2;
  140. if (t == 0) {
  141. if (p_cancel) {
  142. c->set_point_in(p_idx, p_restore);
  143. return;
  144. }
  145. ur->create_action(TTR("Set Curve In Position"));
  146. ur->add_do_method(c.ptr(), "set_point_in", idx, c->get_point_in(idx));
  147. ur->add_undo_method(c.ptr(), "set_point_in", idx, p_restore);
  148. if (PathEditorPlugin::singleton->mirror_angle_enabled()) {
  149. ur->add_do_method(c.ptr(), "set_point_out", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -c->get_point_in(idx) : (-c->get_point_in(idx).normalized() * orig_out_length));
  150. ur->add_undo_method(c.ptr(), "set_point_out", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -static_cast<Vector3>(p_restore) : (-static_cast<Vector3>(p_restore).normalized() * orig_out_length));
  151. }
  152. ur->commit_action();
  153. } else {
  154. if (p_cancel) {
  155. c->set_point_out(idx, p_restore);
  156. return;
  157. }
  158. ur->create_action(TTR("Set Curve Out Position"));
  159. ur->add_do_method(c.ptr(), "set_point_out", idx, c->get_point_out(idx));
  160. ur->add_undo_method(c.ptr(), "set_point_out", idx, p_restore);
  161. if (PathEditorPlugin::singleton->mirror_angle_enabled()) {
  162. ur->add_do_method(c.ptr(), "set_point_in", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -c->get_point_out(idx) : (-c->get_point_out(idx).normalized() * orig_in_length));
  163. ur->add_undo_method(c.ptr(), "set_point_in", idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -static_cast<Vector3>(p_restore) : (-static_cast<Vector3>(p_restore).normalized() * orig_in_length));
  164. }
  165. ur->commit_action();
  166. }
  167. }
  168. void PathSpatialGizmo::redraw() {
  169. clear();
  170. Ref<SpatialMaterial> path_material = gizmo_plugin->get_material("path_material", this);
  171. Ref<SpatialMaterial> path_thin_material = gizmo_plugin->get_material("path_thin_material", this);
  172. Ref<SpatialMaterial> handles_material = gizmo_plugin->get_material("handles");
  173. Ref<Curve3D> c = path->get_curve();
  174. if (c.is_null())
  175. return;
  176. PoolVector<Vector3> v3a = c->tessellate();
  177. //PoolVector<Vector3> v3a=c->get_baked_points();
  178. int v3s = v3a.size();
  179. if (v3s == 0)
  180. return;
  181. Vector<Vector3> v3p;
  182. PoolVector<Vector3>::Read r = v3a.read();
  183. // BUG: the following won't work when v3s, avoid drawing as a temporary workaround.
  184. for (int i = 0; i < v3s - 1; i++) {
  185. v3p.push_back(r[i]);
  186. v3p.push_back(r[i + 1]);
  187. //v3p.push_back(r[i]);
  188. //v3p.push_back(r[i]+Vector3(0,0.2,0));
  189. }
  190. if (v3p.size() > 1) {
  191. add_lines(v3p, path_material);
  192. add_collision_segments(v3p);
  193. }
  194. if (PathEditorPlugin::singleton->get_edited_path() == path) {
  195. v3p.clear();
  196. Vector<Vector3> handles;
  197. Vector<Vector3> sec_handles;
  198. for (int i = 0; i < c->get_point_count(); i++) {
  199. Vector3 p = c->get_point_position(i);
  200. handles.push_back(p);
  201. if (i > 0) {
  202. v3p.push_back(p);
  203. v3p.push_back(p + c->get_point_in(i));
  204. sec_handles.push_back(p + c->get_point_in(i));
  205. }
  206. if (i < c->get_point_count() - 1) {
  207. v3p.push_back(p);
  208. v3p.push_back(p + c->get_point_out(i));
  209. sec_handles.push_back(p + c->get_point_out(i));
  210. }
  211. }
  212. if (v3p.size() > 1) {
  213. add_lines(v3p, path_thin_material);
  214. }
  215. if (handles.size()) {
  216. add_handles(handles, handles_material);
  217. }
  218. if (sec_handles.size()) {
  219. add_handles(sec_handles, handles_material, false, true);
  220. }
  221. }
  222. }
  223. PathSpatialGizmo::PathSpatialGizmo(Path *p_path) {
  224. path = p_path;
  225. set_spatial_node(p_path);
  226. }
  227. bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
  228. if (!path)
  229. return false;
  230. Ref<Curve3D> c = path->get_curve();
  231. if (c.is_null())
  232. return false;
  233. Transform gt = path->get_global_transform();
  234. Transform it = gt.affine_inverse();
  235. static const int click_dist = 10; //should make global
  236. Ref<InputEventMouseButton> mb = p_event;
  237. if (mb.is_valid()) {
  238. Point2 mbpos(mb->get_position().x, mb->get_position().y);
  239. if (!mb->is_pressed())
  240. set_handle_clicked(false);
  241. if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) {
  242. //click into curve, break it down
  243. PoolVector<Vector3> v3a = c->tessellate();
  244. int idx = 0;
  245. int rc = v3a.size();
  246. int closest_seg = -1;
  247. Vector3 closest_seg_point;
  248. float closest_d = 1e20;
  249. if (rc >= 2) {
  250. PoolVector<Vector3>::Read r = v3a.read();
  251. if (p_camera->unproject_position(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist)
  252. return false; //nope, existing
  253. for (int i = 0; i < c->get_point_count() - 1; i++) {
  254. //find the offset and point index of the place to break up
  255. int j = idx;
  256. if (p_camera->unproject_position(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist)
  257. return false; //nope, existing
  258. while (j < rc && c->get_point_position(i + 1) != r[j]) {
  259. Vector3 from = r[j];
  260. Vector3 to = r[j + 1];
  261. real_t cdist = from.distance_to(to);
  262. from = gt.xform(from);
  263. to = gt.xform(to);
  264. if (cdist > 0) {
  265. Vector2 s[2];
  266. s[0] = p_camera->unproject_position(from);
  267. s[1] = p_camera->unproject_position(to);
  268. Vector2 inters = Geometry::get_closest_point_to_segment_2d(mbpos, s);
  269. float d = inters.distance_to(mbpos);
  270. if (d < 10 && d < closest_d) {
  271. closest_d = d;
  272. closest_seg = i;
  273. Vector3 ray_from = p_camera->project_ray_origin(mbpos);
  274. Vector3 ray_dir = p_camera->project_ray_normal(mbpos);
  275. Vector3 ra, rb;
  276. Geometry::get_closest_points_between_segments(ray_from, ray_from + ray_dir * 4096, from, to, ra, rb);
  277. closest_seg_point = it.xform(rb);
  278. }
  279. }
  280. j++;
  281. }
  282. if (idx == j)
  283. idx++; //force next
  284. else
  285. idx = j; //swap
  286. if (j == rc)
  287. break;
  288. }
  289. }
  290. UndoRedo *ur = editor->get_undo_redo();
  291. if (closest_seg != -1) {
  292. //subdivide
  293. ur->create_action(TTR("Split Path"));
  294. ur->add_do_method(c.ptr(), "add_point", closest_seg_point, Vector3(), Vector3(), closest_seg + 1);
  295. ur->add_undo_method(c.ptr(), "remove_point", closest_seg + 1);
  296. ur->commit_action();
  297. return true;
  298. } else {
  299. Vector3 org;
  300. if (c->get_point_count() == 0)
  301. org = path->get_transform().get_origin();
  302. else
  303. org = gt.xform(c->get_point_position(c->get_point_count() - 1));
  304. Plane p(org, p_camera->get_transform().basis.get_axis(2));
  305. Vector3 ray_from = p_camera->project_ray_origin(mbpos);
  306. Vector3 ray_dir = p_camera->project_ray_normal(mbpos);
  307. Vector3 inters;
  308. if (p.intersects_ray(ray_from, ray_dir, &inters)) {
  309. ur->create_action(TTR("Add Point to Curve"));
  310. ur->add_do_method(c.ptr(), "add_point", it.xform(inters), Vector3(), Vector3(), -1);
  311. ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());
  312. ur->commit_action();
  313. return true;
  314. }
  315. //add new at pos
  316. }
  317. } else if (mb->is_pressed() && ((mb->get_button_index() == BUTTON_LEFT && curve_del->is_pressed()) || (mb->get_button_index() == BUTTON_RIGHT && curve_edit->is_pressed()))) {
  318. for (int i = 0; i < c->get_point_count(); i++) {
  319. real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_position(i))).distance_to(mbpos);
  320. 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);
  321. 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);
  322. // Find the offset and point index of the place to break up.
  323. // Also check for the control points.
  324. if (dist_to_p < click_dist) {
  325. UndoRedo *ur = editor->get_undo_redo();
  326. ur->create_action(TTR("Remove Path Point"));
  327. ur->add_do_method(c.ptr(), "remove_point", i);
  328. ur->add_undo_method(c.ptr(), "add_point", c->get_point_position(i), c->get_point_in(i), c->get_point_out(i), i);
  329. ur->commit_action();
  330. return true;
  331. } else if (dist_to_p_out < click_dist) {
  332. UndoRedo *ur = editor->get_undo_redo();
  333. ur->create_action(TTR("Remove Out-Control Point"));
  334. ur->add_do_method(c.ptr(), "set_point_out", i, Vector3());
  335. ur->add_undo_method(c.ptr(), "set_point_out", i, c->get_point_out(i));
  336. ur->commit_action();
  337. return true;
  338. } else if (dist_to_p_in < click_dist) {
  339. UndoRedo *ur = editor->get_undo_redo();
  340. ur->create_action(TTR("Remove In-Control Point"));
  341. ur->add_do_method(c.ptr(), "set_point_in", i, Vector3());
  342. ur->add_undo_method(c.ptr(), "set_point_in", i, c->get_point_in(i));
  343. ur->commit_action();
  344. return true;
  345. }
  346. }
  347. }
  348. }
  349. return false;
  350. }
  351. void PathEditorPlugin::edit(Object *p_object) {
  352. if (p_object) {
  353. path = Object::cast_to<Path>(p_object);
  354. if (path) {
  355. if (path->get_curve().is_valid()) {
  356. path->get_curve()->emit_signal("changed");
  357. }
  358. }
  359. } else {
  360. Path *pre = path;
  361. path = NULL;
  362. if (pre) {
  363. pre->get_curve()->emit_signal("changed");
  364. }
  365. }
  366. //collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
  367. }
  368. bool PathEditorPlugin::handles(Object *p_object) const {
  369. return p_object->is_class("Path");
  370. }
  371. void PathEditorPlugin::make_visible(bool p_visible) {
  372. if (p_visible) {
  373. curve_create->show();
  374. curve_edit->show();
  375. curve_del->show();
  376. curve_close->show();
  377. handle_menu->show();
  378. sep->show();
  379. } else {
  380. curve_create->hide();
  381. curve_edit->hide();
  382. curve_del->hide();
  383. curve_close->hide();
  384. handle_menu->hide();
  385. sep->hide();
  386. {
  387. Path *pre = path;
  388. path = NULL;
  389. if (pre && pre->get_curve().is_valid()) {
  390. pre->get_curve()->emit_signal("changed");
  391. }
  392. }
  393. }
  394. }
  395. void PathEditorPlugin::_mode_changed(int p_idx) {
  396. curve_create->set_pressed(p_idx == 0);
  397. curve_edit->set_pressed(p_idx == 1);
  398. curve_del->set_pressed(p_idx == 2);
  399. }
  400. void PathEditorPlugin::_close_curve() {
  401. Ref<Curve3D> c = path->get_curve();
  402. if (c.is_null())
  403. return;
  404. if (c->get_point_count() < 2)
  405. return;
  406. c->add_point(c->get_point_position(0), c->get_point_in(0), c->get_point_out(0));
  407. }
  408. void PathEditorPlugin::_handle_option_pressed(int p_option) {
  409. PopupMenu *pm;
  410. pm = handle_menu->get_popup();
  411. switch (p_option) {
  412. case HANDLE_OPTION_ANGLE: {
  413. bool is_checked = pm->is_item_checked(HANDLE_OPTION_ANGLE);
  414. mirror_handle_angle = !is_checked;
  415. pm->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);
  416. pm->set_item_disabled(HANDLE_OPTION_LENGTH, !mirror_handle_angle);
  417. } break;
  418. case HANDLE_OPTION_LENGTH: {
  419. bool is_checked = pm->is_item_checked(HANDLE_OPTION_LENGTH);
  420. mirror_handle_length = !is_checked;
  421. pm->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);
  422. } break;
  423. }
  424. }
  425. void PathEditorPlugin::_notification(int p_what) {
  426. if (p_what == NOTIFICATION_ENTER_TREE) {
  427. curve_create->connect("pressed", this, "_mode_changed", make_binds(0));
  428. curve_edit->connect("pressed", this, "_mode_changed", make_binds(1));
  429. curve_del->connect("pressed", this, "_mode_changed", make_binds(2));
  430. curve_close->connect("pressed", this, "_close_curve");
  431. }
  432. }
  433. void PathEditorPlugin::_bind_methods() {
  434. ClassDB::bind_method(D_METHOD("_mode_changed"), &PathEditorPlugin::_mode_changed);
  435. ClassDB::bind_method(D_METHOD("_close_curve"), &PathEditorPlugin::_close_curve);
  436. ClassDB::bind_method(D_METHOD("_handle_option_pressed"), &PathEditorPlugin::_handle_option_pressed);
  437. }
  438. PathEditorPlugin *PathEditorPlugin::singleton = NULL;
  439. PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
  440. path = NULL;
  441. editor = p_node;
  442. singleton = this;
  443. mirror_handle_angle = true;
  444. mirror_handle_length = true;
  445. Ref<PathSpatialGizmoPlugin> gizmo_plugin;
  446. gizmo_plugin.instance();
  447. SpatialEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);
  448. sep = memnew(VSeparator);
  449. sep->hide();
  450. SpatialEditor::get_singleton()->add_control_to_menu_panel(sep);
  451. curve_edit = memnew(ToolButton);
  452. curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit", "EditorIcons"));
  453. curve_edit->set_toggle_mode(true);
  454. curve_edit->hide();
  455. curve_edit->set_focus_mode(Control::FOCUS_NONE);
  456. curve_edit->set_tooltip(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point"));
  457. SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_edit);
  458. curve_create = memnew(ToolButton);
  459. curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate", "EditorIcons"));
  460. curve_create->set_toggle_mode(true);
  461. curve_create->hide();
  462. curve_create->set_focus_mode(Control::FOCUS_NONE);
  463. curve_create->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)"));
  464. SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_create);
  465. curve_del = memnew(ToolButton);
  466. curve_del->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete", "EditorIcons"));
  467. curve_del->set_toggle_mode(true);
  468. curve_del->hide();
  469. curve_del->set_focus_mode(Control::FOCUS_NONE);
  470. curve_del->set_tooltip(TTR("Delete Point"));
  471. SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_del);
  472. curve_close = memnew(ToolButton);
  473. curve_close->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveClose", "EditorIcons"));
  474. curve_close->hide();
  475. curve_close->set_focus_mode(Control::FOCUS_NONE);
  476. curve_close->set_tooltip(TTR("Close Curve"));
  477. SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_close);
  478. PopupMenu *menu;
  479. handle_menu = memnew(MenuButton);
  480. handle_menu->set_text(TTR("Options"));
  481. handle_menu->hide();
  482. SpatialEditor::get_singleton()->add_control_to_menu_panel(handle_menu);
  483. menu = handle_menu->get_popup();
  484. menu->add_check_item(TTR("Mirror Handle Angles"));
  485. menu->set_item_checked(HANDLE_OPTION_ANGLE, mirror_handle_angle);
  486. menu->add_check_item(TTR("Mirror Handle Lengths"));
  487. menu->set_item_checked(HANDLE_OPTION_LENGTH, mirror_handle_length);
  488. menu->connect("id_pressed", this, "_handle_option_pressed");
  489. curve_edit->set_pressed(true);
  490. /*
  491. collision_polygon_editor = memnew( PathEditor(p_node) );
  492. editor->get_viewport()->add_child(collision_polygon_editor);
  493. collision_polygon_editor->set_margin(MARGIN_LEFT,200);
  494. collision_polygon_editor->set_margin(MARGIN_RIGHT,230);
  495. collision_polygon_editor->set_margin(MARGIN_TOP,0);
  496. collision_polygon_editor->set_margin(MARGIN_BOTTOM,10);
  497. collision_polygon_editor->hide();
  498. */
  499. }
  500. PathEditorPlugin::~PathEditorPlugin() {
  501. }
  502. Ref<EditorSpatialGizmo> PathSpatialGizmoPlugin::create_gizmo(Spatial *p_spatial) {
  503. Ref<PathSpatialGizmo> ref;
  504. Path *path = Object::cast_to<Path>(p_spatial);
  505. if (path) ref = Ref<PathSpatialGizmo>(memnew(PathSpatialGizmo(path)));
  506. return ref;
  507. }
  508. String PathSpatialGizmoPlugin::get_name() const {
  509. return "Path";
  510. }
  511. int PathSpatialGizmoPlugin::get_priority() const {
  512. return -1;
  513. }
  514. PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() {
  515. Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8));
  516. create_material("path_material", path_color);
  517. create_material("path_thin_material", Color(0.5, 0.5, 0.5));
  518. create_handle_material("handles");
  519. }