diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp index c0d38af26aa..55a72081692 100644 --- a/editor/import/3d/resource_importer_scene.cpp +++ b/editor/import/3d/resource_importer_scene.cpp @@ -762,6 +762,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMapset_transform(mi->get_transform()); col->set_name(fixed_name); + _copy_meta(p_node, col); p_node->replace_by(col); p_node->set_owner(nullptr); memdelete(p_node); @@ -776,6 +777,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMapset_name(fixed_name); Object::cast_to(sb)->set_transform(Object::cast_to(p_node)->get_transform()); + _copy_meta(p_node, sb); p_node->replace_by(sb); p_node->set_owner(nullptr); memdelete(p_node); @@ -820,6 +822,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMapset_name(_fixstr(name, "rigid_body")); + _copy_meta(p_node, rigid_body); p_node->replace_by(rigid_body); rigid_body->set_transform(mi->get_transform()); p_node = rigid_body; @@ -884,6 +887,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMap nmesh = mesh->create_navigation_mesh(); nmi->set_navigation_mesh(nmesh); Object::cast_to(nmi)->set_transform(mi->get_transform()); + _copy_meta(p_node, nmi); p_node->replace_by(nmi); p_node->set_owner(nullptr); memdelete(p_node); @@ -924,6 +928,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMapget_name(), "vehicle"); bv->set_name(n); + _copy_meta(p_node, bv); p_node->replace_by(bv); p_node->set_name(n); bv->add_child(p_node); @@ -943,6 +948,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMapget_name(), "wheel"); bv->set_name(n); + _copy_meta(p_node, bv); p_node->replace_by(bv); p_node->set_name(n); bv->add_child(p_node); @@ -1550,6 +1556,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap< case MESH_PHYSICS_RIGID_BODY_AND_MESH: { RigidBody3D *rigid_body = memnew(RigidBody3D); rigid_body->set_name(p_node->get_name()); + _copy_meta(p_node, rigid_body); p_node->replace_by(rigid_body); rigid_body->set_transform(mi->get_transform() * get_collision_shapes_transform(node_settings)); rigid_body->set_position(p_applied_root_scale * rigid_body->get_position()); @@ -1568,6 +1575,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap< col->set_transform(mi->get_transform() * get_collision_shapes_transform(node_settings)); col->set_position(p_applied_root_scale * col->get_position()); col->set_name(p_node->get_name()); + _copy_meta(p_node, col); p_node->replace_by(col); p_node->set_owner(nullptr); memdelete(p_node); @@ -1583,6 +1591,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap< area->set_transform(mi->get_transform() * get_collision_shapes_transform(node_settings)); area->set_position(p_applied_root_scale * area->get_position()); area->set_name(p_node->get_name()); + _copy_meta(p_node, area); p_node->replace_by(area); p_node->set_owner(nullptr); memdelete(p_node); @@ -1626,6 +1635,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap< if (navmesh_mode == NAVMESH_NAVMESH_ONLY) { nmi->set_transform(mi->get_transform()); + _copy_meta(p_node, nmi); p_node->replace_by(nmi); p_node->set_owner(nullptr); memdelete(p_node); @@ -2553,6 +2563,7 @@ Node *ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_ } if (mesh.is_valid()) { + _copy_meta(src_mesh_node->get_mesh().ptr(), mesh.ptr()); mesh_node->set_mesh(mesh); for (int i = 0; i < mesh->get_surface_count(); i++) { mesh_node->set_surface_override_material(i, src_mesh_node->get_surface_material(i)); @@ -2581,6 +2592,8 @@ Node *ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_ mesh_node->set_visibility_range_end_margin(src_mesh_node->get_visibility_range_end_margin()); mesh_node->set_visibility_range_fade_mode(src_mesh_node->get_visibility_range_fade_mode()); + _copy_meta(p_node, mesh_node); + p_node->replace_by(mesh_node); p_node->set_owner(nullptr); memdelete(p_node); @@ -2604,6 +2617,15 @@ void ResourceImporterScene::_add_shapes(Node *p_node, const Vector> } } +void ResourceImporterScene::_copy_meta(Object *p_src_object, Object *p_dst_object) { + List meta_list; + p_src_object->get_meta_list(&meta_list); + for (const StringName &meta_key : meta_list) { + Variant meta_value = p_src_object->get_meta(meta_key); + p_dst_object->set_meta(meta_key, meta_value); + } +} + void ResourceImporterScene::_optimize_track_usage(AnimationPlayer *p_player, AnimationImportTracks *p_track_actions) { List anims; p_player->get_animation_list(&anims); diff --git a/editor/import/3d/resource_importer_scene.h b/editor/import/3d/resource_importer_scene.h index bbf2d20163e..cd6a7252318 100644 --- a/editor/import/3d/resource_importer_scene.h +++ b/editor/import/3d/resource_importer_scene.h @@ -219,6 +219,7 @@ class ResourceImporterScene : public ResourceImporter { void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner); Node *_generate_meshes(Node *p_node, const Dictionary &p_mesh_data, bool p_generate_lods, bool p_create_shadow_meshes, LightBakeMode p_light_bake_mode, float p_lightmap_texel_size, const Vector &p_src_lightmap_cache, Vector> &r_lightmap_caches); void _add_shapes(Node *p_node, const Vector> &p_shapes); + void _copy_meta(Object *p_src_object, Object *p_dst_object); enum AnimationImportTracks { ANIMATION_IMPORT_TRACKS_IF_PRESENT, 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 1e64a6daa43..07faee3dfcd 100644 --- a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp +++ b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp @@ -37,6 +37,15 @@ void GLTFDocumentExtensionConvertImporterMesh::_bind_methods() { } +void GLTFDocumentExtensionConvertImporterMesh::_copy_meta(Object *p_src_object, Object *p_dst_object) { + List meta_list; + p_src_object->get_meta_list(&meta_list); + for (const StringName &meta_key : meta_list) { + Variant meta_value = p_src_object->get_meta(meta_key); + p_dst_object->set_meta(meta_key, meta_value); + } +} + Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref p_state, Node *p_root) { ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER); ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); @@ -58,6 +67,8 @@ Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref p_sta mesh_instance_node_3d->set_skin(mesh_3d->get_skin()); mesh_instance_node_3d->set_skeleton_path(mesh_3d->get_skeleton_path()); node->replace_by(mesh_instance_node_3d); + _copy_meta(mesh_3d, mesh_instance_node_3d); + _copy_meta(mesh.ptr(), array_mesh.ptr()); delete_queue.push_back(node); node = mesh_instance_node_3d; } else { diff --git a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h index 1147c2af388..ca10444eb57 100644 --- a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h +++ b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h @@ -38,6 +38,7 @@ class GLTFDocumentExtensionConvertImporterMesh : public GLTFDocumentExtension { protected: static void _bind_methods(); + static void _copy_meta(Object *p_src_object, Object *p_dst_object); public: Error import_post(Ref p_state, Node *p_root) override;