2017-01-16 08:04:19 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* mesh_instance_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-01-16 08:04:19 +01:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-01-16 08:04:19 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2016-05-23 22:10:26 +02:00
|
|
|
#include "mesh_instance_editor_plugin.h"
|
|
|
|
|
2017-07-15 06:23:10 +02:00
|
|
|
#include "scene/3d/collision_shape.h"
|
2016-05-23 22:10:26 +02:00
|
|
|
#include "scene/3d/navigation_mesh.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/3d/physics_body.h"
|
|
|
|
#include "scene/gui/box_container.h"
|
2016-05-23 22:10:26 +02:00
|
|
|
#include "spatial_editor_plugin.h"
|
|
|
|
|
|
|
|
void MeshInstanceEditor::_node_removed(Node *p_node) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_node == node) {
|
|
|
|
node = NULL;
|
2016-05-23 22:10:26 +02:00
|
|
|
options->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshInstanceEditor::edit(MeshInstance *p_mesh) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
node = p_mesh;
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MeshInstanceEditor::_menu_option(int p_option) {
|
|
|
|
|
|
|
|
Ref<Mesh> mesh = node->get_mesh();
|
|
|
|
if (mesh.is_null()) {
|
|
|
|
err_dialog->set_text(TTR("Mesh is empty!"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_option) {
|
2016-05-23 22:10:26 +02:00
|
|
|
case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY:
|
|
|
|
case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool trimesh_shape = (p_option == MENU_OPTION_CREATE_STATIC_TRIMESH_BODY);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection();
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
if (selection.empty()) {
|
|
|
|
Ref<Shape> shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape();
|
|
|
|
if (shape.is_null())
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CollisionShape *cshape = memnew(CollisionShape);
|
2016-05-23 22:10:26 +02:00
|
|
|
cshape->set_shape(shape);
|
2017-03-05 16:44:50 +01:00
|
|
|
StaticBody *body = memnew(StaticBody);
|
2016-05-23 22:10:26 +02:00
|
|
|
body->add_child(cshape);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner();
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
if (trimesh_shape)
|
|
|
|
ur->create_action(TTR("Create Static Trimesh Body"));
|
|
|
|
else
|
|
|
|
ur->create_action(TTR("Create Static Convex Body"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_do_method(node, "add_child", body);
|
|
|
|
ur->add_do_method(body, "set_owner", owner);
|
|
|
|
ur->add_do_method(cshape, "set_owner", owner);
|
2016-05-23 22:10:26 +02:00
|
|
|
ur->add_do_reference(body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_undo_method(node, "remove_child", body);
|
2016-05-23 22:10:26 +02:00
|
|
|
ur->commit_action();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trimesh_shape)
|
|
|
|
ur->create_action(TTR("Create Static Trimesh Body"));
|
|
|
|
else
|
|
|
|
ur->create_action(TTR("Create Static Convex Body"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2016-05-23 22:10:26 +02:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
MeshInstance *instance = Object::cast_to<MeshInstance>(E->get());
|
2016-05-23 22:10:26 +02:00
|
|
|
if (!instance)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Ref<Mesh> m = instance->get_mesh();
|
|
|
|
if (m.is_null())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Ref<Shape> shape = trimesh_shape ? m->create_trimesh_shape() : m->create_convex_shape();
|
|
|
|
if (shape.is_null())
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CollisionShape *cshape = memnew(CollisionShape);
|
2016-05-23 22:10:26 +02:00
|
|
|
cshape->set_shape(shape);
|
2017-03-05 16:44:50 +01:00
|
|
|
StaticBody *body = memnew(StaticBody);
|
2016-05-23 22:10:26 +02:00
|
|
|
body->add_child(cshape);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *owner = instance == get_tree()->get_edited_scene_root() ? instance : instance->get_owner();
|
2016-05-23 22:10:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_do_method(instance, "add_child", body);
|
|
|
|
ur->add_do_method(body, "set_owner", owner);
|
|
|
|
ur->add_do_method(cshape, "set_owner", owner);
|
2016-05-23 22:10:26 +02:00
|
|
|
ur->add_do_reference(body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_undo_method(instance, "remove_child", body);
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ur->commit_action();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE:
|
|
|
|
case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (node == get_tree()->get_edited_scene_root()) {
|
2016-05-23 22:10:26 +02:00
|
|
|
err_dialog->set_text(TTR("This doesn't work on scene root!"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool trimesh_shape = (p_option == MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
Ref<Shape> shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape();
|
|
|
|
if (shape.is_null())
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CollisionShape *cshape = memnew(CollisionShape);
|
2016-05-23 22:10:26 +02:00
|
|
|
cshape->set_shape(shape);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *owner = node->get_owner();
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
|
|
|
|
if (trimesh_shape)
|
|
|
|
ur->create_action(TTR("Create Trimesh Shape"));
|
|
|
|
else
|
|
|
|
ur->create_action(TTR("Create Convex Shape"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_do_method(node->get_parent(), "add_child", cshape);
|
|
|
|
ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1);
|
|
|
|
ur->add_do_method(cshape, "set_owner", owner);
|
2016-05-23 22:10:26 +02:00
|
|
|
ur->add_do_reference(cshape);
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_undo_method(node->get_parent(), "remove_child", cshape);
|
2016-05-23 22:10:26 +02:00
|
|
|
ur->commit_action();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MENU_OPTION_CREATE_NAVMESH: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<NavigationMesh> nmesh = memnew(NavigationMesh);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
if (nmesh.is_null())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nmesh->create_from_mesh(mesh);
|
2017-03-05 16:44:50 +01:00
|
|
|
NavigationMeshInstance *nmi = memnew(NavigationMeshInstance);
|
2016-05-23 22:10:26 +02:00
|
|
|
nmi->set_navigation_mesh(nmesh);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner();
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
ur->create_action(TTR("Create Navigation Mesh"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_do_method(node, "add_child", nmi);
|
|
|
|
ur->add_do_method(nmi, "set_owner", owner);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
ur->add_do_reference(nmi);
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_undo_method(node, "remove_child", nmi);
|
2016-05-23 22:10:26 +02:00
|
|
|
ur->commit_action();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MENU_OPTION_CREATE_OUTLINE_MESH: {
|
|
|
|
|
|
|
|
outline_dialog->popup_centered(Vector2(200, 90));
|
|
|
|
} break;
|
2017-12-09 18:11:26 +01:00
|
|
|
case MENU_OPTION_CREATE_UV2: {
|
|
|
|
|
|
|
|
Ref<ArrayMesh> mesh = node->get_mesh();
|
|
|
|
if (!mesh.is_valid()) {
|
|
|
|
err_dialog->set_text(TTR("Contained Mesh is not of type ArrayMesh."));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error err = mesh->lightmap_unwrap(node->get_global_transform());
|
|
|
|
if (err != OK) {
|
|
|
|
err_dialog->set_text(TTR("UV Unwrap failed, mesh may not be manifold?"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case MENU_OPTION_DEBUG_UV1: {
|
|
|
|
Ref<Mesh> mesh = node->get_mesh();
|
|
|
|
if (!mesh.is_valid()) {
|
|
|
|
err_dialog->set_text(TTR("No mesh to debug."));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_create_uv_lines(0);
|
|
|
|
} break;
|
|
|
|
case MENU_OPTION_DEBUG_UV2: {
|
|
|
|
Ref<Mesh> mesh = node->get_mesh();
|
|
|
|
if (!mesh.is_valid()) {
|
|
|
|
err_dialog->set_text(TTR("No mesh to debug."));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_create_uv_lines(1);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MeshInstanceEditorEdgeSort {
|
|
|
|
|
|
|
|
Vector2 a;
|
|
|
|
Vector2 b;
|
|
|
|
|
|
|
|
bool operator<(const MeshInstanceEditorEdgeSort &p_b) const {
|
|
|
|
if (a == p_b.a)
|
|
|
|
return b < p_b.b;
|
|
|
|
else
|
|
|
|
return a < p_b.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
MeshInstanceEditorEdgeSort() {}
|
|
|
|
MeshInstanceEditorEdgeSort(const Vector2 &p_a, const Vector2 &p_b) {
|
|
|
|
if (p_a < p_b) {
|
|
|
|
a = p_a;
|
|
|
|
b = p_b;
|
|
|
|
} else {
|
|
|
|
b = p_a;
|
|
|
|
a = p_b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void MeshInstanceEditor::_create_uv_lines(int p_layer) {
|
|
|
|
|
|
|
|
Ref<Mesh> mesh = node->get_mesh();
|
|
|
|
ERR_FAIL_COND(!mesh.is_valid());
|
|
|
|
|
|
|
|
Set<MeshInstanceEditorEdgeSort> edges;
|
|
|
|
uv_lines.clear();
|
|
|
|
for (int i = 0; i < mesh->get_surface_count(); i++) {
|
|
|
|
if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
|
|
|
|
continue;
|
|
|
|
Array a = mesh->surface_get_arrays(i);
|
|
|
|
|
|
|
|
PoolVector<Vector2> uv = a[p_layer == 0 ? Mesh::ARRAY_TEX_UV : Mesh::ARRAY_TEX_UV2];
|
|
|
|
if (uv.size() == 0) {
|
|
|
|
err_dialog->set_text(TTR("Model has no UV in this layer"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolVector<Vector2>::Read r = uv.read();
|
|
|
|
|
|
|
|
PoolVector<int> indices = a[Mesh::ARRAY_INDEX];
|
|
|
|
PoolVector<int>::Read ri;
|
|
|
|
|
|
|
|
int ic;
|
|
|
|
bool use_indices;
|
|
|
|
|
|
|
|
if (indices.size()) {
|
|
|
|
ic = indices.size();
|
|
|
|
ri = indices.read();
|
|
|
|
use_indices = true;
|
|
|
|
} else {
|
|
|
|
ic = uv.size();
|
|
|
|
use_indices = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < ic; j += 3) {
|
|
|
|
|
|
|
|
for (int k = 0; k < 3; k++) {
|
|
|
|
|
|
|
|
MeshInstanceEditorEdgeSort edge;
|
|
|
|
if (use_indices) {
|
|
|
|
edge.a = r[ri[j + k]];
|
|
|
|
edge.b = r[ri[j + ((k + 1) % 3)]];
|
|
|
|
} else {
|
|
|
|
edge.a = r[j + k];
|
|
|
|
edge.b = r[j + ((k + 1) % 3)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edges.has(edge))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uv_lines.push_back(edge.a);
|
|
|
|
uv_lines.push_back(edge.b);
|
|
|
|
edges.insert(edge);
|
|
|
|
}
|
|
|
|
}
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
2017-12-09 18:11:26 +01:00
|
|
|
|
|
|
|
debug_uv_dialog->popup_centered_minsize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshInstanceEditor::_debug_uv_draw() {
|
|
|
|
|
|
|
|
if (uv_lines.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
debug_uv->set_clip_contents(true);
|
|
|
|
debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), Color(0.2, 0.2, 0.0));
|
|
|
|
debug_uv->draw_set_transform(Vector2(), 0, debug_uv->get_size());
|
|
|
|
debug_uv->draw_multiline(uv_lines, Color(1.0, 0.8, 0.7));
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MeshInstanceEditor::_create_outline_mesh() {
|
|
|
|
|
|
|
|
Ref<Mesh> mesh = node->get_mesh();
|
|
|
|
if (mesh.is_null()) {
|
|
|
|
err_dialog->set_text(TTR("MeshInstance lacks a Mesh!"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:57:21 +02:00
|
|
|
if (mesh->get_surface_count() == 0) {
|
|
|
|
err_dialog->set_text(TTR("Mesh has not surface to create outlines from!"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
2018-04-01 17:06:47 +02:00
|
|
|
return;
|
|
|
|
} else if (mesh->get_surface_count() == 1 && mesh->surface_get_primitive_type(0) != Mesh::PRIMITIVE_TRIANGLES) {
|
|
|
|
err_dialog->set_text(TTR("Mesh primitive type is not PRIMITIVE_TRIANGLES!"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
2016-06-21 00:57:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
Ref<Mesh> mesho = mesh->create_outline(outline_size->get_value());
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
if (mesho.is_null()) {
|
|
|
|
err_dialog->set_text(TTR("Could not create outline!"));
|
|
|
|
err_dialog->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MeshInstance *mi = memnew(MeshInstance);
|
2016-05-23 22:10:26 +02:00
|
|
|
mi->set_mesh(mesho);
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *owner = node->get_owner();
|
|
|
|
if (get_tree()->get_edited_scene_root() == node) {
|
|
|
|
owner = node;
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
|
|
|
|
ur->create_action(TTR("Create Outline"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_do_method(node, "add_child", mi);
|
|
|
|
ur->add_do_method(mi, "set_owner", owner);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
ur->add_do_reference(mi);
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_undo_method(node, "remove_child", mi);
|
2016-05-23 22:10:26 +02:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshInstanceEditor::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method("_menu_option", &MeshInstanceEditor::_menu_option);
|
|
|
|
ClassDB::bind_method("_create_outline_mesh", &MeshInstanceEditor::_create_outline_mesh);
|
2017-12-09 18:11:26 +01:00
|
|
|
ClassDB::bind_method("_debug_uv_draw", &MeshInstanceEditor::_debug_uv_draw);
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MeshInstanceEditor::MeshInstanceEditor() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
options = memnew(MenuButton);
|
2016-05-23 22:10:26 +02:00
|
|
|
SpatialEditor::get_singleton()->add_control_to_menu_panel(options);
|
|
|
|
|
2016-06-01 13:32:20 +02:00
|
|
|
options->set_text(TTR("Mesh"));
|
2017-03-05 16:44:50 +01:00
|
|
|
options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance", "EditorIcons"));
|
2016-05-23 22:10:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
options->get_popup()->add_item(TTR("Create Trimesh Static Body"), MENU_OPTION_CREATE_STATIC_TRIMESH_BODY);
|
|
|
|
options->get_popup()->add_item(TTR("Create Convex Static Body"), MENU_OPTION_CREATE_STATIC_CONVEX_BODY);
|
2016-05-23 22:10:26 +02:00
|
|
|
options->get_popup()->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
options->get_popup()->add_item(TTR("Create Trimesh Collision Sibling"), MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE);
|
|
|
|
options->get_popup()->add_item(TTR("Create Convex Collision Sibling"), MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE);
|
2016-05-23 22:10:26 +02:00
|
|
|
options->get_popup()->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
options->get_popup()->add_item(TTR("Create Navigation Mesh"), MENU_OPTION_CREATE_NAVMESH);
|
2016-05-23 22:10:26 +02:00
|
|
|
options->get_popup()->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
options->get_popup()->add_item(TTR("Create Outline Mesh.."), MENU_OPTION_CREATE_OUTLINE_MESH);
|
2017-12-09 18:11:26 +01:00
|
|
|
options->get_popup()->add_separator();
|
|
|
|
options->get_popup()->add_item(TTR("View UV1"), MENU_OPTION_DEBUG_UV1);
|
|
|
|
options->get_popup()->add_item(TTR("View UV2"), MENU_OPTION_DEBUG_UV2);
|
|
|
|
options->get_popup()->add_item(TTR("Unwrap UV2 for Lightmap/AO"), MENU_OPTION_CREATE_UV2);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
options->get_popup()->connect("id_pressed", this, "_menu_option");
|
2016-05-23 22:10:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
outline_dialog = memnew(ConfirmationDialog);
|
2016-05-23 22:10:26 +02:00
|
|
|
outline_dialog->set_title(TTR("Create Outline Mesh"));
|
|
|
|
outline_dialog->get_ok()->set_text(TTR("Create"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *outline_dialog_vbc = memnew(VBoxContainer);
|
2016-05-23 22:10:26 +02:00
|
|
|
outline_dialog->add_child(outline_dialog_vbc);
|
2017-01-10 05:49:55 +01:00
|
|
|
//outline_dialog->set_child_rect(outline_dialog_vbc);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
outline_size = memnew(SpinBox);
|
2016-05-23 22:10:26 +02:00
|
|
|
outline_size->set_min(0.001);
|
|
|
|
outline_size->set_max(1024);
|
|
|
|
outline_size->set_step(0.001);
|
2017-01-04 05:16:14 +01:00
|
|
|
outline_size->set_value(0.05);
|
2017-03-05 16:44:50 +01:00
|
|
|
outline_dialog_vbc->add_margin_child(TTR("Outline Size:"), outline_size);
|
2016-05-23 22:10:26 +02:00
|
|
|
|
|
|
|
add_child(outline_dialog);
|
2017-03-05 16:44:50 +01:00
|
|
|
outline_dialog->connect("confirmed", this, "_create_outline_mesh");
|
2016-05-23 22:10:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
err_dialog = memnew(AcceptDialog);
|
2016-05-23 22:10:26 +02:00
|
|
|
add_child(err_dialog);
|
2017-12-09 18:11:26 +01:00
|
|
|
|
|
|
|
debug_uv_dialog = memnew(AcceptDialog);
|
|
|
|
debug_uv_dialog->set_title("UV Channel Debug");
|
|
|
|
add_child(debug_uv_dialog);
|
|
|
|
debug_uv = memnew(Control);
|
|
|
|
debug_uv->set_custom_minimum_size(Size2(600, 600) * EDSCALE);
|
|
|
|
debug_uv->connect("draw", this, "_debug_uv_draw");
|
|
|
|
debug_uv_dialog->add_child(debug_uv);
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MeshInstanceEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
mesh_editor->edit(Object::cast_to<MeshInstance>(p_object));
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MeshInstanceEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
return p_object->is_class("MeshInstance");
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MeshInstanceEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
|
|
|
mesh_editor->options->show();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mesh_editor->options->hide();
|
|
|
|
mesh_editor->edit(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MeshInstanceEditorPlugin::MeshInstanceEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
editor = p_node;
|
|
|
|
mesh_editor = memnew(MeshInstanceEditor);
|
2016-05-23 22:10:26 +02:00
|
|
|
editor->get_viewport()->add_child(mesh_editor);
|
|
|
|
|
|
|
|
mesh_editor->options->hide();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MeshInstanceEditorPlugin::~MeshInstanceEditorPlugin() {
|
2016-05-23 22:10:26 +02:00
|
|
|
}
|