collision_polygon_3d_editor_plugin.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*************************************************************************/
  2. /* collision_polygon_3d_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 "collision_polygon_3d_editor_plugin.h"
  31. #include "canvas_item_editor_plugin.h"
  32. #include "core/input/input.h"
  33. #include "core/io/file_access.h"
  34. #include "core/math/geometry_2d.h"
  35. #include "core/os/keyboard.h"
  36. #include "editor/editor_settings.h"
  37. #include "node_3d_editor_plugin.h"
  38. #include "scene/3d/camera_3d.h"
  39. void CollisionPolygon3DEditor::_notification(int p_what) {
  40. switch (p_what) {
  41. case NOTIFICATION_READY: {
  42. button_create->set_icon(get_theme_icon("Edit", "EditorIcons"));
  43. button_edit->set_icon(get_theme_icon("MovePoint", "EditorIcons"));
  44. button_edit->set_pressed(true);
  45. get_tree()->connect("node_removed", callable_mp(this, &CollisionPolygon3DEditor::_node_removed));
  46. } break;
  47. case NOTIFICATION_PROCESS: {
  48. if (!node) {
  49. return;
  50. }
  51. if (_get_depth() != prev_depth) {
  52. _polygon_draw();
  53. prev_depth = _get_depth();
  54. }
  55. } break;
  56. }
  57. }
  58. void CollisionPolygon3DEditor::_node_removed(Node *p_node) {
  59. if (p_node == node) {
  60. node = nullptr;
  61. if (imgeom->get_parent() == p_node) {
  62. p_node->remove_child(imgeom);
  63. }
  64. hide();
  65. set_process(false);
  66. }
  67. }
  68. void CollisionPolygon3DEditor::_menu_option(int p_option) {
  69. switch (p_option) {
  70. case MODE_CREATE: {
  71. mode = MODE_CREATE;
  72. button_create->set_pressed(true);
  73. button_edit->set_pressed(false);
  74. } break;
  75. case MODE_EDIT: {
  76. mode = MODE_EDIT;
  77. button_create->set_pressed(false);
  78. button_edit->set_pressed(true);
  79. } break;
  80. }
  81. }
  82. void CollisionPolygon3DEditor::_wip_close() {
  83. undo_redo->create_action(TTR("Create Polygon3D"));
  84. undo_redo->add_undo_method(node, "set_polygon", node->call("get_polygon"));
  85. undo_redo->add_do_method(node, "set_polygon", wip);
  86. undo_redo->add_do_method(this, "_polygon_draw");
  87. undo_redo->add_undo_method(this, "_polygon_draw");
  88. wip.clear();
  89. wip_active = false;
  90. mode = MODE_EDIT;
  91. button_edit->set_pressed(true);
  92. button_create->set_pressed(false);
  93. edited_point = -1;
  94. undo_redo->commit_action();
  95. }
  96. bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) {
  97. if (!node) {
  98. return false;
  99. }
  100. Transform3D gt = node->get_global_transform();
  101. Transform3D gi = gt.affine_inverse();
  102. float depth = _get_depth() * 0.5;
  103. Vector3 n = gt.basis.get_axis(2).normalized();
  104. Plane p(gt.origin + n * depth, n);
  105. Ref<InputEventMouseButton> mb = p_event;
  106. if (mb.is_valid()) {
  107. Vector2 gpoint = mb->get_position();
  108. Vector3 ray_from = p_camera->project_ray_origin(gpoint);
  109. Vector3 ray_dir = p_camera->project_ray_normal(gpoint);
  110. Vector3 spoint;
  111. if (!p.intersects_ray(ray_from, ray_dir, &spoint)) {
  112. return false;
  113. }
  114. spoint = gi.xform(spoint);
  115. Vector2 cpoint(spoint.x, spoint.y);
  116. //DO NOT snap here, it's confusing in 3D for adding points.
  117. //Let the snap happen when the point is being moved, instead.
  118. //cpoint = CanvasItemEditor::get_singleton()->snap_point(cpoint);
  119. Vector<Vector2> poly = node->call("get_polygon");
  120. //first check if a point is to be added (segment split)
  121. real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius");
  122. switch (mode) {
  123. case MODE_CREATE: {
  124. if (mb->get_button_index() == MOUSE_BUTTON_LEFT && mb->is_pressed()) {
  125. if (!wip_active) {
  126. wip.clear();
  127. wip.push_back(cpoint);
  128. wip_active = true;
  129. edited_point_pos = cpoint;
  130. snap_ignore = false;
  131. _polygon_draw();
  132. edited_point = 1;
  133. return true;
  134. } else {
  135. if (wip.size() > 1 && p_camera->unproject_position(gt.xform(Vector3(wip[0].x, wip[0].y, depth))).distance_to(gpoint) < grab_threshold) {
  136. //wip closed
  137. _wip_close();
  138. return true;
  139. } else {
  140. wip.push_back(cpoint);
  141. edited_point = wip.size();
  142. snap_ignore = false;
  143. _polygon_draw();
  144. return true;
  145. }
  146. }
  147. } else if (mb->get_button_index() == MOUSE_BUTTON_RIGHT && mb->is_pressed() && wip_active) {
  148. _wip_close();
  149. }
  150. } break;
  151. case MODE_EDIT: {
  152. if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
  153. if (mb->is_pressed()) {
  154. if (mb->is_ctrl_pressed()) {
  155. if (poly.size() < 3) {
  156. undo_redo->create_action(TTR("Edit Poly"));
  157. undo_redo->add_undo_method(node, "set_polygon", poly);
  158. poly.push_back(cpoint);
  159. undo_redo->add_do_method(node, "set_polygon", poly);
  160. undo_redo->add_do_method(this, "_polygon_draw");
  161. undo_redo->add_undo_method(this, "_polygon_draw");
  162. undo_redo->commit_action();
  163. return true;
  164. }
  165. //search edges
  166. int closest_idx = -1;
  167. Vector2 closest_pos;
  168. real_t closest_dist = 1e10;
  169. for (int i = 0; i < poly.size(); i++) {
  170. Vector2 points[2] = {
  171. p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth))),
  172. p_camera->unproject_position(gt.xform(Vector3(poly[(i + 1) % poly.size()].x, poly[(i + 1) % poly.size()].y, depth)))
  173. };
  174. Vector2 cp = Geometry2D::get_closest_point_to_segment(gpoint, points);
  175. if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) {
  176. continue; //not valid to reuse point
  177. }
  178. real_t d = cp.distance_to(gpoint);
  179. if (d < closest_dist && d < grab_threshold) {
  180. closest_dist = d;
  181. closest_pos = cp;
  182. closest_idx = i;
  183. }
  184. }
  185. if (closest_idx >= 0) {
  186. pre_move_edit = poly;
  187. poly.insert(closest_idx + 1, cpoint);
  188. edited_point = closest_idx + 1;
  189. edited_point_pos = cpoint;
  190. node->call("set_polygon", poly);
  191. _polygon_draw();
  192. snap_ignore = true;
  193. return true;
  194. }
  195. } else {
  196. //look for points to move
  197. int closest_idx = -1;
  198. Vector2 closest_pos;
  199. real_t closest_dist = 1e10;
  200. for (int i = 0; i < poly.size(); i++) {
  201. Vector2 cp = p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth)));
  202. real_t d = cp.distance_to(gpoint);
  203. if (d < closest_dist && d < grab_threshold) {
  204. closest_dist = d;
  205. closest_pos = cp;
  206. closest_idx = i;
  207. }
  208. }
  209. if (closest_idx >= 0) {
  210. pre_move_edit = poly;
  211. edited_point = closest_idx;
  212. edited_point_pos = poly[closest_idx];
  213. _polygon_draw();
  214. snap_ignore = false;
  215. return true;
  216. }
  217. }
  218. } else {
  219. snap_ignore = false;
  220. if (edited_point != -1) {
  221. //apply
  222. ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
  223. poly.write[edited_point] = edited_point_pos;
  224. undo_redo->create_action(TTR("Edit Poly"));
  225. undo_redo->add_do_method(node, "set_polygon", poly);
  226. undo_redo->add_undo_method(node, "set_polygon", pre_move_edit);
  227. undo_redo->add_do_method(this, "_polygon_draw");
  228. undo_redo->add_undo_method(this, "_polygon_draw");
  229. undo_redo->commit_action();
  230. edited_point = -1;
  231. return true;
  232. }
  233. }
  234. }
  235. if (mb->get_button_index() == MOUSE_BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) {
  236. int closest_idx = -1;
  237. Vector2 closest_pos;
  238. real_t closest_dist = 1e10;
  239. for (int i = 0; i < poly.size(); i++) {
  240. Vector2 cp = p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth)));
  241. real_t d = cp.distance_to(gpoint);
  242. if (d < closest_dist && d < grab_threshold) {
  243. closest_dist = d;
  244. closest_pos = cp;
  245. closest_idx = i;
  246. }
  247. }
  248. if (closest_idx >= 0) {
  249. undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
  250. undo_redo->add_undo_method(node, "set_polygon", poly);
  251. poly.remove(closest_idx);
  252. undo_redo->add_do_method(node, "set_polygon", poly);
  253. undo_redo->add_do_method(this, "_polygon_draw");
  254. undo_redo->add_undo_method(this, "_polygon_draw");
  255. undo_redo->commit_action();
  256. return true;
  257. }
  258. }
  259. } break;
  260. }
  261. }
  262. Ref<InputEventMouseMotion> mm = p_event;
  263. if (mm.is_valid()) {
  264. if (edited_point != -1 && (wip_active || mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT)) {
  265. Vector2 gpoint = mm->get_position();
  266. Vector3 ray_from = p_camera->project_ray_origin(gpoint);
  267. Vector3 ray_dir = p_camera->project_ray_normal(gpoint);
  268. Vector3 spoint;
  269. if (!p.intersects_ray(ray_from, ray_dir, &spoint)) {
  270. return false;
  271. }
  272. spoint = gi.xform(spoint);
  273. Vector2 cpoint(spoint.x, spoint.y);
  274. if (snap_ignore && !Input::get_singleton()->is_key_pressed(KEY_CTRL)) {
  275. snap_ignore = false;
  276. }
  277. if (!snap_ignore && Node3DEditor::get_singleton()->is_snap_enabled()) {
  278. cpoint = cpoint.snapped(Vector2(
  279. Node3DEditor::get_singleton()->get_translate_snap(),
  280. Node3DEditor::get_singleton()->get_translate_snap()));
  281. }
  282. edited_point_pos = cpoint;
  283. _polygon_draw();
  284. }
  285. }
  286. return false;
  287. }
  288. float CollisionPolygon3DEditor::_get_depth() {
  289. if (bool(node->call("_has_editable_3d_polygon_no_depth"))) {
  290. return 0;
  291. }
  292. return float(node->call("get_depth"));
  293. }
  294. void CollisionPolygon3DEditor::_polygon_draw() {
  295. if (!node) {
  296. return;
  297. }
  298. Vector<Vector2> poly;
  299. if (wip_active) {
  300. poly = wip;
  301. } else {
  302. poly = node->call("get_polygon");
  303. }
  304. float depth = _get_depth() * 0.5;
  305. imgeom->clear();
  306. imgeom->set_material_override(line_material);
  307. imgeom->begin(Mesh::PRIMITIVE_LINES, Ref<Texture2D>());
  308. Rect2 rect;
  309. for (int i = 0; i < poly.size(); i++) {
  310. Vector2 p, p2;
  311. p = i == edited_point ? edited_point_pos : poly[i];
  312. if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) {
  313. p2 = edited_point_pos;
  314. } else {
  315. p2 = poly[(i + 1) % poly.size()];
  316. }
  317. if (i == 0) {
  318. rect.position = p;
  319. } else {
  320. rect.expand_to(p);
  321. }
  322. Vector3 point = Vector3(p.x, p.y, depth);
  323. Vector3 next_point = Vector3(p2.x, p2.y, depth);
  324. imgeom->set_color(Color(1, 0.3, 0.1, 0.8));
  325. imgeom->add_vertex(point);
  326. imgeom->set_color(Color(1, 0.3, 0.1, 0.8));
  327. imgeom->add_vertex(next_point);
  328. //Color col=Color(1,0.3,0.1,0.8);
  329. //vpc->draw_line(point,next_point,col,2);
  330. //vpc->draw_texture(handle,point-handle->get_size()*0.5);
  331. }
  332. rect = rect.grow(1);
  333. AABB r;
  334. r.position.x = rect.position.x;
  335. r.position.y = rect.position.y;
  336. r.position.z = depth;
  337. r.size.x = rect.size.x;
  338. r.size.y = rect.size.y;
  339. r.size.z = 0;
  340. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  341. imgeom->add_vertex(r.position);
  342. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  343. imgeom->add_vertex(r.position + Vector3(0.3, 0, 0));
  344. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  345. imgeom->add_vertex(r.position);
  346. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  347. imgeom->add_vertex(r.position + Vector3(0.0, 0.3, 0));
  348. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  349. imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0));
  350. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  351. imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0) - Vector3(0.3, 0, 0));
  352. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  353. imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0));
  354. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  355. imgeom->add_vertex(r.position + Vector3(r.size.x, 0, 0) + Vector3(0, 0.3, 0));
  356. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  357. imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0));
  358. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  359. imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0) - Vector3(0, 0.3, 0));
  360. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  361. imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0));
  362. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  363. imgeom->add_vertex(r.position + Vector3(0, r.size.y, 0) + Vector3(0.3, 0, 0));
  364. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  365. imgeom->add_vertex(r.position + r.size);
  366. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  367. imgeom->add_vertex(r.position + r.size - Vector3(0.3, 0, 0));
  368. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  369. imgeom->add_vertex(r.position + r.size);
  370. imgeom->set_color(Color(0.8, 0.8, 0.8, 0.2));
  371. imgeom->add_vertex(r.position + r.size - Vector3(0.0, 0.3, 0));
  372. imgeom->end();
  373. m->clear_surfaces();
  374. if (poly.size() == 0) {
  375. return;
  376. }
  377. Array a;
  378. a.resize(Mesh::ARRAY_MAX);
  379. Vector<Vector3> va;
  380. {
  381. va.resize(poly.size());
  382. Vector3 *w = va.ptrw();
  383. for (int i = 0; i < poly.size(); i++) {
  384. Vector2 p, p2;
  385. p = i == edited_point ? edited_point_pos : poly[i];
  386. Vector3 point = Vector3(p.x, p.y, depth);
  387. w[i] = point;
  388. }
  389. }
  390. a[Mesh::ARRAY_VERTEX] = va;
  391. m->add_surface_from_arrays(Mesh::PRIMITIVE_POINTS, a);
  392. m->surface_set_material(0, handle_material);
  393. }
  394. void CollisionPolygon3DEditor::edit(Node *p_collision_polygon) {
  395. if (p_collision_polygon) {
  396. node = Object::cast_to<Node3D>(p_collision_polygon);
  397. //Enable the pencil tool if the polygon is empty
  398. if (Vector<Vector2>(node->call("get_polygon")).size() == 0) {
  399. _menu_option(MODE_CREATE);
  400. }
  401. wip.clear();
  402. wip_active = false;
  403. edited_point = -1;
  404. p_collision_polygon->add_child(imgeom);
  405. _polygon_draw();
  406. set_process(true);
  407. prev_depth = -1;
  408. } else {
  409. node = nullptr;
  410. if (imgeom->get_parent()) {
  411. imgeom->get_parent()->remove_child(imgeom);
  412. }
  413. set_process(false);
  414. }
  415. }
  416. void CollisionPolygon3DEditor::_bind_methods() {
  417. ClassDB::bind_method(D_METHOD("_polygon_draw"), &CollisionPolygon3DEditor::_polygon_draw);
  418. }
  419. CollisionPolygon3DEditor::CollisionPolygon3DEditor(EditorNode *p_editor) {
  420. node = nullptr;
  421. editor = p_editor;
  422. undo_redo = EditorNode::get_undo_redo();
  423. add_child(memnew(VSeparator));
  424. button_create = memnew(Button);
  425. button_create->set_flat(true);
  426. add_child(button_create);
  427. button_create->connect("pressed", callable_mp(this, &CollisionPolygon3DEditor::_menu_option), varray(MODE_CREATE));
  428. button_create->set_toggle_mode(true);
  429. button_edit = memnew(Button);
  430. button_edit->set_flat(true);
  431. add_child(button_edit);
  432. button_edit->connect("pressed", callable_mp(this, &CollisionPolygon3DEditor::_menu_option), varray(MODE_EDIT));
  433. button_edit->set_toggle_mode(true);
  434. mode = MODE_EDIT;
  435. wip_active = false;
  436. imgeom = memnew(ImmediateGeometry3D);
  437. imgeom->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001)));
  438. line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  439. line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  440. line_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  441. line_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  442. line_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
  443. line_material->set_albedo(Color(1, 1, 1));
  444. handle_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
  445. handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  446. handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
  447. handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  448. handle_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  449. handle_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
  450. Ref<Texture2D> handle = editor->get_gui_base()->get_theme_icon("Editor3DHandle", "EditorIcons");
  451. handle_material->set_point_size(handle->get_width());
  452. handle_material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, handle);
  453. pointsm = memnew(MeshInstance3D);
  454. imgeom->add_child(pointsm);
  455. m.instance();
  456. pointsm->set_mesh(m);
  457. pointsm->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001)));
  458. snap_ignore = false;
  459. }
  460. CollisionPolygon3DEditor::~CollisionPolygon3DEditor() {
  461. memdelete(imgeom);
  462. }
  463. void Polygon3DEditorPlugin::edit(Object *p_object) {
  464. collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
  465. }
  466. bool Polygon3DEditorPlugin::handles(Object *p_object) const {
  467. return Object::cast_to<Node3D>(p_object) && bool(p_object->call("_is_editable_3d_polygon"));
  468. }
  469. void Polygon3DEditorPlugin::make_visible(bool p_visible) {
  470. if (p_visible) {
  471. collision_polygon_editor->show();
  472. } else {
  473. collision_polygon_editor->hide();
  474. collision_polygon_editor->edit(nullptr);
  475. }
  476. }
  477. Polygon3DEditorPlugin::Polygon3DEditorPlugin(EditorNode *p_node) {
  478. editor = p_node;
  479. collision_polygon_editor = memnew(CollisionPolygon3DEditor(p_node));
  480. Node3DEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor);
  481. collision_polygon_editor->hide();
  482. }
  483. Polygon3DEditorPlugin::~Polygon3DEditorPlugin() {
  484. }