From 263f0890405dfcfe47f5ec7196ec1b260c007f1c Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Mon, 26 Aug 2024 02:13:46 -0700 Subject: [PATCH] GLTF: Only create MeshInstance3D when needed --- ...ocument_extension_convert_importer_mesh.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp index 676f764c110..64117349e0b 100644 --- a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp +++ b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp @@ -52,24 +52,24 @@ Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref p_sta while (!queue.is_empty()) { List::Element *E = queue.front(); Node *node = E->get(); - ImporterMeshInstance3D *mesh_3d = cast_to(node); - if (mesh_3d) { - MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D); - Ref mesh = mesh_3d->get_mesh(); + ImporterMeshInstance3D *importer_mesh_3d = Object::cast_to(node); + if (importer_mesh_3d) { + Ref mesh = importer_mesh_3d->get_mesh(); if (mesh.is_valid()) { + MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D); Ref array_mesh = mesh->get_mesh(); 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_skin(mesh_3d->get_skin()); - mesh_instance_node_3d->set_skeleton_path(mesh_3d->get_skeleton_path()); + mesh_instance_node_3d->set_skin(importer_mesh_3d->get_skin()); + mesh_instance_node_3d->set_skeleton_path(importer_mesh_3d->get_skeleton_path()); 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()); delete_queue.push_back(node); node = mesh_instance_node_3d; } 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();