path_editor_plugin.cpp 20 KB

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