Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MultiNodeEdit support to MeshInstance3D editor #91620

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions editor/plugins/mesh_instance_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/multi_node_edit.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "scene/3d/navigation_region_3d.h"
Expand Down Expand Up @@ -188,8 +189,7 @@ void MeshInstance3DEditor::_create_collision_shape() {
cshape->set_shape(shape);
cshape->set_name("CollisionShape3D");
cshape->set_transform(node->get_transform());
ur->add_do_method(E->get_parent(), "add_child", cshape);
ur->add_do_method(E->get_parent(), "move_child", cshape, E->get_index() + 1);
ur->add_do_method(E, "add_sibling", cshape, true);
ur->add_do_method(cshape, "set_owner", owner);
ur->add_do_method(Node3DEditor::get_singleton(), SceneStringNames::get_singleton()->_request_gizmo, cshape);
ur->add_do_reference(cshape);
Expand Down Expand Up @@ -612,11 +612,48 @@ MeshInstance3DEditor::MeshInstance3DEditor() {
}

void MeshInstance3DEditorPlugin::edit(Object *p_object) {
mesh_editor->edit(Object::cast_to<MeshInstance3D>(p_object));
{
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_object);
if (mi) {
mesh_editor->edit(mi);
return;
}
}

Ref<MultiNodeEdit> mne = Ref<MultiNodeEdit>(p_object);
Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
if (mne.is_valid() && edited_scene) {
for (int i = 0; i < mne->get_node_count(); i++) {
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(edited_scene->get_node(mne->get_node(i)));
if (mi) {
mesh_editor->edit(mi);
return;
}
}
}
mesh_editor->edit(nullptr);
}

bool MeshInstance3DEditorPlugin::handles(Object *p_object) const {
return p_object->is_class("MeshInstance3D");
if (Object::cast_to<MeshInstance3D>(p_object)) {
return true;
}

Ref<MultiNodeEdit> mne = Ref<MultiNodeEdit>(p_object);
Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
if (mne.is_valid() && edited_scene) {
bool has_mesh = false;
for (int i = 0; i < mne->get_node_count(); i++) {
if (Object::cast_to<MeshInstance3D>(edited_scene->get_node(mne->get_node(i)))) {
if (has_mesh) {
return true;
} else {
has_mesh = true;
}
}
}
}
return false;
}

void MeshInstance3DEditorPlugin::make_visible(bool p_visible) {
Expand Down
Loading