diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2020-02-10 10:49:05 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-10 10:49:05 +0100 | 
| commit | 37432587f90cc666e3a6d361ac5c0bea723cb44c (patch) | |
| tree | 17c9a22e11281132e50324d491de4121fdff1276 | |
| parent | 052118afa68ff01e45aafcbf67b854e03fb737f0 (diff) | |
| parent | 90af009f2ea637e5944a12b85c58018187c0de16 (diff) | |
Merge pull request #35787 from Calinou/editor-expose-create-single-convex-shape
Re-add a way to generate a single convex shape from the editor
| -rw-r--r-- | editor/plugins/mesh_instance_editor_plugin.cpp | 70 | ||||
| -rw-r--r-- | editor/plugins/mesh_instance_editor_plugin.h | 4 | 
2 files changed, 55 insertions, 19 deletions
diff --git a/editor/plugins/mesh_instance_editor_plugin.cpp b/editor/plugins/mesh_instance_editor_plugin.cpp index 25329906a9..6e5307cebe 100644 --- a/editor/plugins/mesh_instance_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_editor_plugin.cpp @@ -60,10 +60,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {  	}  	switch (p_option) { -		case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: -		case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: { - -			bool trimesh_shape = (p_option == MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); +		case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: {  			EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection();  			UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); @@ -71,9 +68,12 @@ void MeshInstanceEditor::_menu_option(int p_option) {  			List<Node *> selection = editor_selection->get_selected_node_list();  			if (selection.empty()) { -				Ref<Shape> shape = trimesh_shape ? mesh->create_trimesh_shape() : mesh->create_convex_shape(); -				if (shape.is_null()) +				Ref<Shape> shape = mesh->create_trimesh_shape(); +				if (shape.is_null()) { +					err_dialog->set_text(TTR("Couldn't create a Trimesh collision shape.")); +					err_dialog->popup_centered_minsize();  					return; +				}  				CollisionShape *cshape = memnew(CollisionShape);  				cshape->set_shape(shape); @@ -82,11 +82,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {  				Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner(); -				if (trimesh_shape) -					ur->create_action(TTR("Create Static Trimesh Body")); -				else -					ur->create_action(TTR("Create Static Convex Body")); - +				ur->create_action(TTR("Create Static Trimesh Body"));  				ur->add_do_method(node, "add_child", body);  				ur->add_do_method(body, "set_owner", owner);  				ur->add_do_method(cshape, "set_owner", owner); @@ -108,7 +104,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {  				if (m.is_null())  					continue; -				Ref<Shape> shape = trimesh_shape ? m->create_trimesh_shape() : m->create_convex_shape(); +				Ref<Shape> shape = m->create_trimesh_shape();  				if (shape.is_null())  					continue; @@ -158,10 +154,44 @@ void MeshInstanceEditor::_menu_option(int p_option) {  			ur->add_undo_method(node->get_parent(), "remove_child", cshape);  			ur->commit_action();  		} break; -		case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { +		case MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE: {  			if (node == get_tree()->get_edited_scene_root()) { -				err_dialog->set_text(TTR("This doesn't work on scene root!")); +				err_dialog->set_text(TTR("Can't create a single convex collision shape for the scene root.")); +				err_dialog->popup_centered_minsize(); +				return; +			} + +			Ref<Shape> shape = mesh->create_convex_shape(); + +			if (shape.is_null()) { +				err_dialog->set_text(TTR("Couldn't create a single convex collision shape.")); +				err_dialog->popup_centered_minsize(); +				return; +			} +			UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + +			ur->create_action(TTR("Create Single Convex Shape")); + +			CollisionShape *cshape = memnew(CollisionShape); +			cshape->set_shape(shape); +			cshape->set_transform(node->get_transform()); + +			Node *owner = node->get_owner(); + +			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); +			ur->add_do_reference(cshape); +			ur->add_undo_method(node->get_parent(), "remove_child", cshape); + +			ur->commit_action(); + +		} break; +		case MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES: { + +			if (node == get_tree()->get_edited_scene_root()) { +				err_dialog->set_text(TTR("Can't create multiple convex collision shapes for the scene root."));  				err_dialog->popup_centered_minsize();  				return;  			} @@ -169,13 +199,13 @@ void MeshInstanceEditor::_menu_option(int p_option) {  			Vector<Ref<Shape> > shapes = mesh->convex_decompose();  			if (!shapes.size()) { -				err_dialog->set_text(TTR("Failed creating shapes!")); +				err_dialog->set_text(TTR("Couldn't create any collision shapes."));  				err_dialog->popup_centered_minsize();  				return;  			}  			UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); -			ur->create_action(TTR("Create Convex Shape(s)")); +			ur->create_action(TTR("Create Multiple Convex Shapes"));  			for (int i = 0; i < shapes.size(); i++) { @@ -421,13 +451,19 @@ MeshInstanceEditor::MeshInstanceEditor() {  	options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MeshInstance", "EditorIcons"));  	options->get_popup()->add_item(TTR("Create Trimesh Static Body"), MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); +	options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a StaticBody and assigns a polygon-based collision shape to it automatically.\nThis is the most accurate (but slowest) option for collision detection."));  	options->get_popup()->add_separator();  	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(s)"), MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE); +	options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a polygon-based collision shape.\nThis is the most accurate (but slowest) option for collision detection.")); +	options->get_popup()->add_item(TTR("Create Single Convex Collision Siblings"), MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE); +	options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a single convex collision shape.\nThis is the fastest (but least accurate) option for collision detection.")); +	options->get_popup()->add_item(TTR("Create Multiple Convex Collision Siblings"), MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES); +	options->get_popup()->set_item_tooltip(options->get_popup()->get_item_count() - 1, TTR("Creates a polygon-based collision shape.\nThis is a performance middle-ground between the two above options."));  	options->get_popup()->add_separator();  	options->get_popup()->add_item(TTR("Create Navigation Mesh"), MENU_OPTION_CREATE_NAVMESH);  	options->get_popup()->add_separator();  	options->get_popup()->add_item(TTR("Create Outline Mesh..."), MENU_OPTION_CREATE_OUTLINE_MESH); +	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 SpatialMaterial Grow property when using that property isn't possible."));  	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); diff --git a/editor/plugins/mesh_instance_editor_plugin.h b/editor/plugins/mesh_instance_editor_plugin.h index 5c95676fc4..5ca9aa3fec 100644 --- a/editor/plugins/mesh_instance_editor_plugin.h +++ b/editor/plugins/mesh_instance_editor_plugin.h @@ -43,9 +43,9 @@ class MeshInstanceEditor : public Control {  	enum Menu {  		MENU_OPTION_CREATE_STATIC_TRIMESH_BODY, -		MENU_OPTION_CREATE_STATIC_CONVEX_BODY,  		MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE, -		MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE, +		MENU_OPTION_CREATE_SINGLE_CONVEX_COLLISION_SHAPE, +		MENU_OPTION_CREATE_MULTIPLE_CONVEX_COLLISION_SHAPES,  		MENU_OPTION_CREATE_NAVMESH,  		MENU_OPTION_CREATE_OUTLINE_MESH,  		MENU_OPTION_CREATE_UV2,  |