Merge pull request #113206 from aaronfranke/import-settings-multi-mesh

Support MultiMesh objects in the scene Advanced Import Settings dialog
This commit is contained in:
Rémi Verschelde 2025-12-02 14:16:36 +01:00
commit 9f761d50fc
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -40,6 +40,7 @@
#include "editor/settings/editor_settings.h" #include "editor/settings/editor_settings.h"
#include "editor/themes/editor_scale.h" #include "editor/themes/editor_scale.h"
#include "scene/3d/importer_mesh_instance_3d.h" #include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/multimesh_instance_3d.h"
#include "scene/animation/animation_player.h" #include "scene/animation/animation_player.h"
#include "scene/gui/subviewport_container.h" #include "scene/gui/subviewport_container.h"
#include "scene/main/timer.h" #include "scene/main/timer.h"
@ -474,6 +475,12 @@ void SceneImportSettingsDialog::_fill_scene(Node *p_node, TreeItem *p_parent_ite
for (int i = 0; i < p_node->get_child_count(); i++) { for (int i = 0; i < p_node->get_child_count(); i++) {
_fill_scene(p_node->get_child(i), item); _fill_scene(p_node->get_child(i), item);
} }
Transform3D accum_xform;
Node3D *base = Object::cast_to<Node3D>(p_node);
while (base) {
accum_xform = base->get_transform() * accum_xform;
base = Object::cast_to<Node3D>(base->get_parent());
}
MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(p_node); MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(p_node);
if (mesh_node && mesh_node->get_mesh().is_valid()) { if (mesh_node && mesh_node->get_mesh().is_valid()) {
// This controls the display of mesh resources in the import settings dialog tree (the white mesh icon). // This controls the display of mesh resources in the import settings dialog tree (the white mesh icon).
@ -489,13 +496,6 @@ void SceneImportSettingsDialog::_fill_scene(Node *p_node, TreeItem *p_parent_ite
mesh_node->add_child(collider_view, true); mesh_node->add_child(collider_view, true);
collider_view->set_owner(mesh_node); collider_view->set_owner(mesh_node);
Transform3D accum_xform;
Node3D *base = mesh_node;
while (base) {
accum_xform = base->get_transform() * accum_xform;
base = Object::cast_to<Node3D>(base->get_parent());
}
AABB aabb = accum_xform.xform(mesh_node->get_mesh()->get_aabb()); AABB aabb = accum_xform.xform(mesh_node->get_mesh()->get_aabb());
if (first_aabb) { if (first_aabb) {
@ -505,20 +505,27 @@ void SceneImportSettingsDialog::_fill_scene(Node *p_node, TreeItem *p_parent_ite
contents_aabb.merge_with(aabb); contents_aabb.merge_with(aabb);
} }
} }
MultiMeshInstance3D *multi_mesh_node = Object::cast_to<MultiMeshInstance3D>(p_node);
if (multi_mesh_node && multi_mesh_node->get_multimesh().is_valid()) {
const Ref<MultiMesh> multi_mesh = multi_mesh_node->get_multimesh();
const Ref<Mesh> mm_mesh = multi_mesh->get_mesh();
if (mm_mesh.is_valid()) {
_fill_mesh(scene_tree, mm_mesh, item);
}
const AABB aabb = accum_xform.xform(multi_mesh->get_aabb());
if (first_aabb) {
contents_aabb = aabb;
first_aabb = false;
} else {
contents_aabb.merge_with(aabb);
}
}
Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node); Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node);
if (skeleton) { if (skeleton) {
Ref<ArrayMesh> bones_mesh = Skeleton3DGizmoPlugin::get_bones_mesh(skeleton, -1, true); Ref<ArrayMesh> bones_mesh = Skeleton3DGizmoPlugin::get_bones_mesh(skeleton, -1, true);
bones_mesh_preview->set_mesh(bones_mesh); bones_mesh_preview->set_mesh(bones_mesh);
Transform3D accum_xform;
Node3D *base = skeleton;
while (base) {
accum_xform = base->get_transform() * accum_xform;
base = Object::cast_to<Node3D>(base->get_parent());
}
bones_mesh_preview->set_transform(accum_xform * skeleton->get_transform()); bones_mesh_preview->set_transform(accum_xform * skeleton->get_transform());
AABB aabb = accum_xform.xform(bones_mesh->get_aabb()); AABB aabb = accum_xform.xform(bones_mesh->get_aabb());