mesh_instance_3d_editor_plugin.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*************************************************************************/
  2. /* mesh_instance_3d_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "mesh_instance_3d_editor_plugin.h"
  31. #include "editor/editor_node.h"
  32. #include "editor/editor_scale.h"
  33. #include "editor/editor_undo_redo_manager.h"
  34. #include "node_3d_editor_plugin.h"
  35. #include "scene/3d/collision_shape_3d.h"
  36. #include "scene/3d/navigation_region_3d.h"
  37. #include "scene/3d/physics_body_3d.h"
  38. #include "scene/gui/box_container.h"
  39. void MeshInstance3DEditor::_node_removed(Node *p_node) {
  40. if (p_node == node) {
  41. node = nullptr;
  42. options->hide();
  43. }
  44. }
  45. void MeshInstance3DEditor::edit(MeshInstance3D *p_mesh) {
  46. node = p_mesh;
  47. }
  48. void MeshInstance3DEditor::_menu_option(int p_option) {
  49. Ref<Mesh> mesh = node->get_mesh();
  50. if (mesh.is_null()) {
  51. err_dialog->set_text(TTR("Mesh is empty!"));
  52. err_dialog->popup_centered();
  53. return;
  54. }
  55. switch (p_option) {
  56. case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: {
  57. EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection();
  58. Ref<EditorUndoRedoManager> &ur = EditorNode::get_singleton()->get_undo_redo();
  59. List<Node *> selection = editor_selection->get_selected_node_list();
  60. if (selection.is_empty()) {
  61. Ref<Shape3D> shape = mesh->create_trimesh_shape();
  62. if (shape.is_null()) {
  63. err_dialog->set_text(TTR("Couldn't create a Trimesh collision shape."));
  64. err_dialog->popup_centered();
  65. return;
  66. }
  67. CollisionShape3D *cshape = memnew(CollisionShape3D);
  68. cshape->set_shape(shape);
  69. StaticBody3D *body = memnew(StaticBody3D);
  70. body->add_child(cshape, true);
  71. Node *owner = get_tree()->get_edited_scene_root();
  72. ur->create_action(TTR("Create Static Trimesh Body"));
  73. ur->add_do_method(node, "add_child", body, true);
  74. ur->add_do_method(body, "set_owner", owner);
  75. ur->add_do_method(cshape, "set_owner", owner);
  76. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", body);
  77. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", cshape);
  78. ur->add_do_reference(body);
  79. ur->add_undo_method(node, "remove_child", body);
  80. ur->commit_action();
  81. return;
  82. }
  83. ur->create_action(TTR("Create Static Trimesh Body"));
  84. for (Node *E : selection) {
  85. MeshInstance3D *instance = Object::cast_to<MeshInstance3D>(E);
  86. if (!instance) {
  87. continue;
  88. }
  89. Ref<Mesh> m = instance->get_mesh();
  90. if (m.is_null()) {
  91. continue;
  92. }
  93. Ref<Shape3D> shape = m->create_trimesh_shape();
  94. if (shape.is_null()) {
  95. continue;
  96. }
  97. CollisionShape3D *cshape = memnew(CollisionShape3D);
  98. cshape->set_shape(shape);
  99. StaticBody3D *body = memnew(StaticBody3D);
  100. body->add_child(cshape, true);
  101. Node *owner = get_tree()->get_edited_scene_root();
  102. ur->add_do_method(instance, "add_child", body, true);
  103. ur->add_do_method(body, "set_owner", owner);
  104. ur->add_do_method(cshape, "set_owner", owner);
  105. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", body);
  106. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", cshape);
  107. ur->add_do_reference(body);
  108. ur->add_undo_method(instance, "remove_child", body);
  109. }
  110. ur->commit_action();
  111. } break;
  112. case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: {
  113. if (node == get_tree()->get_edited_scene_root()) {
  114. err_dialog->set_text(TTR("This doesn't work on scene root!"));
  115. err_dialog->popup_centered();
  116. return;
  117. }
  118. Ref<Shape3D> shape = mesh->create_trimesh_shape();
  119. if (shape.is_null()) {
  120. return;
  121. }
  122. CollisionShape3D *cshape = memnew(CollisionShape3D);
  123. cshape->set_shape(shape);
  124. cshape->set_transform(node->get_transform());
  125. Node *owner = get_tree()->get_edited_scene_root();
  126. Ref<EditorUndoRedoManager> &ur = EditorNode::get_singleton()->get_undo_redo();
  127. ur->create_action(TTR("Create Trimesh Static Shape"));
  128. ur->add_do_method(node->get_parent(), "add_child", cshape, true);
  129. ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1);
  130. ur->add_do_method(cshape, "set_owner", owner);
  131. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", cshape);
  132. ur->add_do_reference(cshape);
  133. ur->add_undo_method(node->get_parent(), "remove_child", cshape);
  134. ur->commit_action();
  135. } break;
  136. case MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE:
  137. case MENU_OPTION_CREATE_SIMPLIFIED_CONVEX_COLLISION_SHAPE: {
  138. if (node == get_tree()->get_edited_scene_root()) {
  139. err_dialog->set_text(TTR("Can't create a single convex collision shape for the scene root."));
  140. err_dialog->popup_centered();
  141. return;
  142. }
  143. bool simplify = (p_option == MENU_OPTION_CREATE_SIMPLIFIED_CONVEX_COLLISION_SHAPE);
  144. Ref<Shape3D> shape = mesh->create_convex_shape(true, simplify);
  145. if (shape.is_null()) {
  146. err_dialog->set_text(TTR("Couldn't create a single convex collision shape."));
  147. err_dialog->popup_centered();
  148. return;
  149. }
  150. Ref<EditorUndoRedoManager> &ur = EditorNode::get_singleton()->get_undo_redo();
  151. if (simplify) {
  152. ur->create_action(TTR("Create Simplified Convex Shape"));
  153. } else {
  154. ur->create_action(TTR("Create Single Convex Shape"));
  155. }
  156. CollisionShape3D *cshape = memnew(CollisionShape3D);
  157. cshape->set_shape(shape);
  158. cshape->set_transform(node->get_transform());
  159. Node *owner = get_tree()->get_edited_scene_root();
  160. ur->add_do_method(node->get_parent(), "add_child", cshape, true);
  161. ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1);
  162. ur->add_do_method(cshape, "set_owner", owner);
  163. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", cshape);
  164. ur->add_do_reference(cshape);
  165. ur->add_undo_method(node->get_parent(), "remove_child", cshape);
  166. ur->commit_action();
  167. } break;
  168. case MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES: {
  169. if (node == get_tree()->get_edited_scene_root()) {
  170. err_dialog->set_text(TTR("Can't create multiple convex collision shapes for the scene root."));
  171. err_dialog->popup_centered();
  172. return;
  173. }
  174. Mesh::ConvexDecompositionSettings settings;
  175. Vector<Ref<Shape3D>> shapes = mesh->convex_decompose(settings);
  176. if (!shapes.size()) {
  177. err_dialog->set_text(TTR("Couldn't create any collision shapes."));
  178. err_dialog->popup_centered();
  179. return;
  180. }
  181. Ref<EditorUndoRedoManager> &ur = EditorNode::get_singleton()->get_undo_redo();
  182. ur->create_action(TTR("Create Multiple Convex Shapes"));
  183. for (int i = 0; i < shapes.size(); i++) {
  184. CollisionShape3D *cshape = memnew(CollisionShape3D);
  185. cshape->set_name("CollisionShape3D");
  186. cshape->set_shape(shapes[i]);
  187. cshape->set_transform(node->get_transform());
  188. Node *owner = get_tree()->get_edited_scene_root();
  189. ur->add_do_method(node->get_parent(), "add_child", cshape);
  190. ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1);
  191. ur->add_do_method(cshape, "set_owner", owner);
  192. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", cshape);
  193. ur->add_do_reference(cshape);
  194. ur->add_undo_method(node->get_parent(), "remove_child", cshape);
  195. }
  196. ur->commit_action();
  197. } break;
  198. case MENU_OPTION_CREATE_NAVMESH: {
  199. Ref<NavigationMesh> nmesh = memnew(NavigationMesh);
  200. if (nmesh.is_null()) {
  201. return;
  202. }
  203. nmesh->create_from_mesh(mesh);
  204. NavigationRegion3D *nmi = memnew(NavigationRegion3D);
  205. nmi->set_navigation_mesh(nmesh);
  206. Node *owner = get_tree()->get_edited_scene_root();
  207. Ref<EditorUndoRedoManager> &ur = EditorNode::get_singleton()->get_undo_redo();
  208. ur->create_action(TTR("Create Navigation Mesh"));
  209. ur->add_do_method(node, "add_child", nmi, true);
  210. ur->add_do_method(nmi, "set_owner", owner);
  211. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", nmi);
  212. ur->add_do_reference(nmi);
  213. ur->add_undo_method(node, "remove_child", nmi);
  214. ur->commit_action();
  215. } break;
  216. case MENU_OPTION_CREATE_OUTLINE_MESH: {
  217. outline_dialog->popup_centered(Vector2(200, 90));
  218. } break;
  219. case MENU_OPTION_CREATE_UV2: {
  220. Ref<ArrayMesh> mesh2 = node->get_mesh();
  221. if (!mesh2.is_valid()) {
  222. err_dialog->set_text(TTR("Contained Mesh is not of type ArrayMesh."));
  223. err_dialog->popup_centered();
  224. return;
  225. }
  226. String path = mesh2->get_path();
  227. int srpos = path.find("::");
  228. if (srpos != -1) {
  229. String base = path.substr(0, srpos);
  230. if (ResourceLoader::get_resource_type(base) == "PackedScene") {
  231. if (!get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->get_scene_file_path() != base) {
  232. err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it does not belong to the edited scene. Make it unique first."));
  233. err_dialog->popup_centered();
  234. return;
  235. }
  236. } else {
  237. if (FileAccess::exists(path + ".import")) {
  238. err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it belongs to another resource which was imported from another file type. Make it unique first."));
  239. err_dialog->popup_centered();
  240. return;
  241. }
  242. }
  243. } else {
  244. if (FileAccess::exists(path + ".import")) {
  245. err_dialog->set_text(TTR("Mesh cannot unwrap UVs because it was imported from another file type. Make it unique first."));
  246. err_dialog->popup_centered();
  247. return;
  248. }
  249. }
  250. Ref<ArrayMesh> unwrapped_mesh = mesh2->duplicate(false);
  251. Error err = unwrapped_mesh->lightmap_unwrap(node->get_global_transform());
  252. if (err != OK) {
  253. err_dialog->set_text(TTR("UV Unwrap failed, mesh may not be manifold?"));
  254. err_dialog->popup_centered();
  255. return;
  256. }
  257. Ref<EditorUndoRedoManager> &ur = EditorNode::get_singleton()->get_undo_redo();
  258. ur->create_action(TTR("Unwrap UV2"));
  259. ur->add_do_method(node, "set_mesh", unwrapped_mesh);
  260. ur->add_do_reference(node);
  261. ur->add_do_reference(mesh2.ptr());
  262. ur->add_undo_method(node, "set_mesh", mesh2);
  263. ur->add_undo_reference(unwrapped_mesh.ptr());
  264. ur->commit_action();
  265. } break;
  266. case MENU_OPTION_DEBUG_UV1: {
  267. Ref<Mesh> mesh2 = node->get_mesh();
  268. if (!mesh2.is_valid()) {
  269. err_dialog->set_text(TTR("No mesh to debug."));
  270. err_dialog->popup_centered();
  271. return;
  272. }
  273. _create_uv_lines(0);
  274. } break;
  275. case MENU_OPTION_DEBUG_UV2: {
  276. Ref<Mesh> mesh2 = node->get_mesh();
  277. if (!mesh2.is_valid()) {
  278. err_dialog->set_text(TTR("No mesh to debug."));
  279. err_dialog->popup_centered();
  280. return;
  281. }
  282. _create_uv_lines(1);
  283. } break;
  284. }
  285. }
  286. struct MeshInstance3DEditorEdgeSort {
  287. Vector2 a;
  288. Vector2 b;
  289. static uint32_t hash(const MeshInstance3DEditorEdgeSort &p_edge) {
  290. uint32_t h = hash_murmur3_one_32(HashMapHasherDefault::hash(p_edge.a));
  291. return hash_fmix32(hash_murmur3_one_32(HashMapHasherDefault::hash(p_edge.b), h));
  292. }
  293. bool operator==(const MeshInstance3DEditorEdgeSort &p_b) const {
  294. return a == p_b.a && b == p_b.b;
  295. }
  296. MeshInstance3DEditorEdgeSort() {}
  297. MeshInstance3DEditorEdgeSort(const Vector2 &p_a, const Vector2 &p_b) {
  298. if (p_a < p_b) {
  299. a = p_a;
  300. b = p_b;
  301. } else {
  302. b = p_a;
  303. a = p_b;
  304. }
  305. }
  306. };
  307. void MeshInstance3DEditor::_create_uv_lines(int p_layer) {
  308. Ref<Mesh> mesh = node->get_mesh();
  309. ERR_FAIL_COND(!mesh.is_valid());
  310. HashSet<MeshInstance3DEditorEdgeSort, MeshInstance3DEditorEdgeSort> edges;
  311. uv_lines.clear();
  312. for (int i = 0; i < mesh->get_surface_count(); i++) {
  313. if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
  314. continue;
  315. }
  316. Array a = mesh->surface_get_arrays(i);
  317. Vector<Vector2> uv = a[p_layer == 0 ? Mesh::ARRAY_TEX_UV : Mesh::ARRAY_TEX_UV2];
  318. if (uv.size() == 0) {
  319. err_dialog->set_text(vformat(TTR("Mesh has no UV in layer %d."), p_layer + 1));
  320. err_dialog->popup_centered();
  321. return;
  322. }
  323. const Vector2 *r = uv.ptr();
  324. Vector<int> indices = a[Mesh::ARRAY_INDEX];
  325. const int *ri = nullptr;
  326. int ic;
  327. if (indices.size()) {
  328. ic = indices.size();
  329. ri = indices.ptr();
  330. } else {
  331. ic = uv.size();
  332. }
  333. for (int j = 0; j < ic; j += 3) {
  334. for (int k = 0; k < 3; k++) {
  335. MeshInstance3DEditorEdgeSort edge;
  336. if (ri) {
  337. edge.a = r[ri[j + k]];
  338. edge.b = r[ri[j + ((k + 1) % 3)]];
  339. } else {
  340. edge.a = r[j + k];
  341. edge.b = r[j + ((k + 1) % 3)];
  342. }
  343. if (edges.has(edge)) {
  344. continue;
  345. }
  346. uv_lines.push_back(edge.a);
  347. uv_lines.push_back(edge.b);
  348. edges.insert(edge);
  349. }
  350. }
  351. }
  352. debug_uv_dialog->popup_centered();
  353. }
  354. void MeshInstance3DEditor::_debug_uv_draw() {
  355. if (uv_lines.size() == 0) {
  356. return;
  357. }
  358. debug_uv->set_clip_contents(true);
  359. debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), get_theme_color(SNAME("dark_color_3"), SNAME("Editor")));
  360. debug_uv->draw_set_transform(Vector2(), 0, debug_uv->get_size());
  361. // Use a translucent color to allow overlapping triangles to be visible.
  362. debug_uv->draw_multiline(uv_lines, get_theme_color(SNAME("mono_color"), SNAME("Editor")) * Color(1, 1, 1, 0.5), Math::round(EDSCALE));
  363. }
  364. void MeshInstance3DEditor::_create_outline_mesh() {
  365. Ref<Mesh> mesh = node->get_mesh();
  366. if (mesh.is_null()) {
  367. err_dialog->set_text(TTR("MeshInstance3D lacks a Mesh."));
  368. err_dialog->popup_centered();
  369. return;
  370. }
  371. if (mesh->get_surface_count() == 0) {
  372. err_dialog->set_text(TTR("Mesh has no surface to create outlines from."));
  373. err_dialog->popup_centered();
  374. return;
  375. } else if (mesh->get_surface_count() == 1 && mesh->surface_get_primitive_type(0) != Mesh::PRIMITIVE_TRIANGLES) {
  376. err_dialog->set_text(TTR("Mesh primitive type is not PRIMITIVE_TRIANGLES."));
  377. err_dialog->popup_centered();
  378. return;
  379. }
  380. Ref<Mesh> mesho = mesh->create_outline(outline_size->get_value());
  381. if (mesho.is_null()) {
  382. err_dialog->set_text(TTR("Could not create outline."));
  383. err_dialog->popup_centered();
  384. return;
  385. }
  386. MeshInstance3D *mi = memnew(MeshInstance3D);
  387. mi->set_mesh(mesho);
  388. Node *owner = get_tree()->get_edited_scene_root();
  389. Ref<EditorUndoRedoManager> &ur = EditorNode::get_singleton()->get_undo_redo();
  390. ur->create_action(TTR("Create Outline"));
  391. ur->add_do_method(node, "add_child", mi, true);
  392. ur->add_do_method(mi, "set_owner", owner);
  393. ur->add_do_method(Node3DEditor::get_singleton(), "_request_gizmo", mi);
  394. ur->add_do_reference(mi);
  395. ur->add_undo_method(node, "remove_child", mi);
  396. ur->commit_action();
  397. }
  398. void MeshInstance3DEditor::_bind_methods() {
  399. }
  400. MeshInstance3DEditor::MeshInstance3DEditor() {
  401. options = memnew(MenuButton);
  402. options->set_switch_on_hover(true);
  403. Node3DEditor::get_singleton()->add_control_to_menu_panel(options);
  404. options->set_text(TTR("Mesh"));
  405. options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("MeshInstance3D"), SNAME("EditorIcons")));
  406. options->get_popup()->add_item(TTR("Create Trimesh Static Body"), MENU_OPTION_CREATE_STATIC_TRIMESH_BODY);
  407. options->get_popup()->set_item_tooltip(-1, TTR("Creates a StaticBody3D and assigns a polygon-based collision shape to it automatically.\nThis is the most accurate (but slowest) option for collision detection."));
  408. options->get_popup()->add_separator();
  409. options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"), MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE);
  410. options->get_popup()->set_item_tooltip(-1, TTR("Creates a polygon-based collision shape.\nThis is the most accurate (but slowest) option for collision detection."));
  411. options->get_popup()->add_item(TTR("Create Single Convex Collision Sibling"), MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE);
  412. options->get_popup()->set_item_tooltip(-1, TTR("Creates a single convex collision shape.\nThis is the fastest (but least accurate) option for collision detection."));
  413. options->get_popup()->add_item(TTR("Create Simplified Convex Collision Sibling"), MENU_OPTION_CREATE_SIMPLIFIED_CONVEX_COLLISION_SHAPE);
  414. options->get_popup()->set_item_tooltip(-1, TTR("Creates a simplified convex collision shape.\nThis is similar to single collision shape, but can result in a simpler geometry in some cases, at the cost of accuracy."));
  415. options->get_popup()->add_item(TTR("Create Multiple Convex Collision Siblings"), MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES);
  416. options->get_popup()->set_item_tooltip(-1, TTR("Creates a polygon-based collision shape.\nThis is a performance middle-ground between a single convex collision and a polygon-based collision."));
  417. options->get_popup()->add_separator();
  418. options->get_popup()->add_item(TTR("Create Navigation Mesh"), MENU_OPTION_CREATE_NAVMESH);
  419. options->get_popup()->add_separator();
  420. options->get_popup()->add_item(TTR("Create Outline Mesh..."), MENU_OPTION_CREATE_OUTLINE_MESH);
  421. options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a static outline mesh. The outline mesh will have its normals flipped automatically.\nThis can be used instead of the StandardMaterial Grow property when using that property isn't possible."));
  422. options->get_popup()->add_separator();
  423. options->get_popup()->add_item(TTR("View UV1"), MENU_OPTION_DEBUG_UV1);
  424. options->get_popup()->add_item(TTR("View UV2"), MENU_OPTION_DEBUG_UV2);
  425. options->get_popup()->add_item(TTR("Unwrap UV2 for Lightmap/AO"), MENU_OPTION_CREATE_UV2);
  426. options->get_popup()->connect("id_pressed", callable_mp(this, &MeshInstance3DEditor::_menu_option));
  427. outline_dialog = memnew(ConfirmationDialog);
  428. outline_dialog->set_title(TTR("Create Outline Mesh"));
  429. outline_dialog->set_ok_button_text(TTR("Create"));
  430. VBoxContainer *outline_dialog_vbc = memnew(VBoxContainer);
  431. outline_dialog->add_child(outline_dialog_vbc);
  432. //outline_dialog->set_child_rect(outline_dialog_vbc);
  433. outline_size = memnew(SpinBox);
  434. outline_size->set_min(0.001);
  435. outline_size->set_max(1024);
  436. outline_size->set_step(0.001);
  437. outline_size->set_value(0.05);
  438. outline_dialog_vbc->add_margin_child(TTR("Outline Size:"), outline_size);
  439. add_child(outline_dialog);
  440. outline_dialog->connect("confirmed", callable_mp(this, &MeshInstance3DEditor::_create_outline_mesh));
  441. err_dialog = memnew(AcceptDialog);
  442. add_child(err_dialog);
  443. debug_uv_dialog = memnew(AcceptDialog);
  444. debug_uv_dialog->set_title(TTR("UV Channel Debug"));
  445. add_child(debug_uv_dialog);
  446. debug_uv = memnew(Control);
  447. debug_uv->set_custom_minimum_size(Size2(600, 600) * EDSCALE);
  448. debug_uv->connect("draw", callable_mp(this, &MeshInstance3DEditor::_debug_uv_draw));
  449. debug_uv_dialog->add_child(debug_uv);
  450. }
  451. void MeshInstance3DEditorPlugin::edit(Object *p_object) {
  452. mesh_editor->edit(Object::cast_to<MeshInstance3D>(p_object));
  453. }
  454. bool MeshInstance3DEditorPlugin::handles(Object *p_object) const {
  455. return p_object->is_class("MeshInstance3D");
  456. }
  457. void MeshInstance3DEditorPlugin::make_visible(bool p_visible) {
  458. if (p_visible) {
  459. mesh_editor->options->show();
  460. } else {
  461. mesh_editor->options->hide();
  462. mesh_editor->edit(nullptr);
  463. }
  464. }
  465. MeshInstance3DEditorPlugin::MeshInstance3DEditorPlugin() {
  466. mesh_editor = memnew(MeshInstance3DEditor);
  467. EditorNode::get_singleton()->get_main_control()->add_child(mesh_editor);
  468. mesh_editor->options->hide();
  469. }
  470. MeshInstance3DEditorPlugin::~MeshInstance3DEditorPlugin() {
  471. }