Repository: godotengine/godot
File: editor/plugins/mesh_instance_3d_editor_plugin.cpp (C++)

Code before:

void MeshInstance3DEditor::_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();
		return;
	}

	switch (p_option) {
		case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: {
			EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection();
			EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();

			List<Node *> selection = editor_selection->get_selected_node_list();

			if (selection.is_empty()) {
				Ref<ConcavePolygonShape3D> 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();
					return;
				}

				CollisionShape3D *cshape = memnew(CollisionShape3D);
				cshape->set_shape(shape);
				StaticBody3D *body = memnew(StaticBody3D);
				body->add_child(cshape, true);

				Node *owner = get_tree()->get_edited_scene_root();

				ur->create_action(TTR("Create Static Trimesh Body"));
				ur->add_do_method(node, "add_child", body, true);
				ur->add_do_method(body, "set_owner", owner);
				ur->add_do_method(cshape, "set_owner", owner);
				ur->add_do_method(Node3DEditor::get_singleton(), SceneStringNames::get_singleton()->_request_gizmo, body);
				ur->add_do_method(Node3DEditor::get_singleton(), SceneStringNames::get_singleton()->_request_gizmo, cshape);
				ur->add_do_reference(body);
				ur->add_undo_method(node, "remove_child", body);
				ur->commit_action();
				return;
			}

			ur->create_action(TTR("Create Static Trimesh Body"));

			for (Node *E : selection) {
				MeshInstance3D *instance = Object::cast_to<MeshInstance3D>(E);
				if (!instance) {
					continue;
				}


Review comment (suggestion):
```suggestion
				err_dialog->set_text(TTR("Couldn't create a simplified collision shape."));
```

Code after:

Vector<Ref<Shape3D>> MeshInstance3DEditor::create_shape_from_mesh(Ref<Mesh> p_mesh, int p_option, bool p_verbose) {
	Vector<Ref<Shape3D>> shapes;
	switch (p_option) {
		case SHAPE_TYPE_TRIMESH: {
			shapes.push_back(p_mesh->create_trimesh_shape());

			if (p_verbose && shapes.is_empty()) {
				err_dialog->set_text(TTR("Couldn't create a Trimesh collision shape."));
				err_dialog->popup_centered();
			}
		} break;

		case SHAPE_TYPE_SINGLE_CONVEX: {
			shapes.push_back(p_mesh->create_convex_shape(true, false));

			if (p_verbose && shapes.is_empty()) {
				err_dialog->set_text(TTR("Couldn't create a single collision shape."));
				err_dialog->popup_centered();
			}
		} break;

		case SHAPE_TYPE_SIMPLIFIED_CONVEX: {
			shapes.push_back(p_mesh->create_convex_shape(true, true));

			if (p_verbose && shapes.is_empty()) {
				err_dialog->set_text(TTR("Couldn't create a simplified collision shape."));
				err_dialog->popup_centered();
			}
		} break;

		case SHAPE_TYPE_MULTIPLE_CONVEX: {
			Ref<MeshConvexDecompositionSettings> settings;
			settings.instantiate();
			settings->set_max_convex_hulls(32);
			settings->set_max_concavity(0.001);

			shapes = p_mesh->convex_decompose(settings);

			if (p_verbose && shapes.is_empty()) {
				err_dialog->set_text(TTR("Couldn't create any collision shapes."));
				err_dialog->popup_centered();
			}
		} break;

		default:
			break;
	}
	return shapes;
}