path_editor_plugin.cpp 21 KB

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