Merge pull request #96133 from aaronfranke/gltf-imp-mesh-inst-create

GLTF: Only create MeshInstance3D when needed
This commit is contained in:
Rémi Verschelde 2024-08-27 16:55:15 +02:00
commit 93f241bcd2
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 9 additions and 9 deletions

View File

@ -52,24 +52,24 @@ Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref<GLTFState> p_sta
while (!queue.is_empty()) { while (!queue.is_empty()) {
List<Node *>::Element *E = queue.front(); List<Node *>::Element *E = queue.front();
Node *node = E->get(); Node *node = E->get();
ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node); ImporterMeshInstance3D *importer_mesh_3d = Object::cast_to<ImporterMeshInstance3D>(node);
if (mesh_3d) { if (importer_mesh_3d) {
MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D); Ref<ImporterMesh> mesh = importer_mesh_3d->get_mesh();
Ref<ImporterMesh> mesh = mesh_3d->get_mesh();
if (mesh.is_valid()) { if (mesh.is_valid()) {
MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D);
Ref<ArrayMesh> array_mesh = mesh->get_mesh(); Ref<ArrayMesh> array_mesh = mesh->get_mesh();
mesh_instance_node_3d->set_name(node->get_name()); mesh_instance_node_3d->set_name(node->get_name());
mesh_instance_node_3d->set_transform(mesh_3d->get_transform()); mesh_instance_node_3d->set_transform(importer_mesh_3d->get_transform());
mesh_instance_node_3d->set_mesh(array_mesh); mesh_instance_node_3d->set_mesh(array_mesh);
mesh_instance_node_3d->set_skin(mesh_3d->get_skin()); mesh_instance_node_3d->set_skin(importer_mesh_3d->get_skin());
mesh_instance_node_3d->set_skeleton_path(mesh_3d->get_skeleton_path()); mesh_instance_node_3d->set_skeleton_path(importer_mesh_3d->get_skeleton_path());
node->replace_by(mesh_instance_node_3d); node->replace_by(mesh_instance_node_3d);
_copy_meta(mesh_3d, mesh_instance_node_3d); _copy_meta(importer_mesh_3d, mesh_instance_node_3d);
_copy_meta(mesh.ptr(), array_mesh.ptr()); _copy_meta(mesh.ptr(), array_mesh.ptr());
delete_queue.push_back(node); delete_queue.push_back(node);
node = mesh_instance_node_3d; node = mesh_instance_node_3d;
} else { } else {
memdelete(mesh_instance_node_3d); WARN_PRINT("glTF: ImporterMeshInstance3D does not have a valid mesh. This should not happen. Continuing anyway.");
} }
} }
int child_count = node->get_child_count(); int child_count = node->get_child_count();