GLTF: Only create MeshInstance3D when needed

This commit is contained in:
Aaron Franke 2024-08-26 02:13:46 -07:00
parent db76de5de8
commit 263f089040
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
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()) {
List<Node *>::Element *E = queue.front();
Node *node = E->get();
ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node);
if (mesh_3d) {
MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D);
Ref<ImporterMesh> mesh = mesh_3d->get_mesh();
ImporterMeshInstance3D *importer_mesh_3d = Object::cast_to<ImporterMeshInstance3D>(node);
if (importer_mesh_3d) {
Ref<ImporterMesh> mesh = importer_mesh_3d->get_mesh();
if (mesh.is_valid()) {
MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D);
Ref<ArrayMesh> 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();