summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
authortamas <tamas@xndu.net>2024-01-25 11:01:56 -0600
committertamas <tamas@xndu.net>2024-06-18 12:39:34 -0500
commite19f0042caddb7d0ceb260e9ba9f5e5ee08a9f44 (patch)
treeaee8a963d58a649c19d6fa3898031fd6b9404d79 /editor
parent0a83e7c5dac550afb26e26684cbb6e4d6c139f5e (diff)
downloadredot-engine-e19f0042caddb7d0ceb260e9ba9f5e5ee08a9f44.tar.gz
Retain meta data set on imported nodes
During the import process, many importer nodes are replaced with their engine node counterparts. For example, ImporterMeshInstance3D is replaced with a MeshInstance3D node. Any meta data set on these importer nodes, i.e. through a GLTFDocumentExtension, are lost during the conversion. This change copies over any meta data set on these importer nodes to their engine counterparts.
Diffstat (limited to 'editor')
-rw-r--r--editor/import/3d/resource_importer_scene.cpp22
-rw-r--r--editor/import/3d/resource_importer_scene.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp
index c0d38af26a..55a7208169 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, HashMap<R
StaticBody3D *col = memnew(StaticBody3D);
col->set_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, HashMap<R
StaticBody3D *sb = memnew(StaticBody3D);
sb->set_name(fixed_name);
Object::cast_to<Node3D>(sb)->set_transform(Object::cast_to<Node3D>(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, HashMap<R
RigidBody3D *rigid_body = memnew(RigidBody3D);
rigid_body->set_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<R
Ref<NavigationMesh> nmesh = mesh->create_navigation_mesh();
nmi->set_navigation_mesh(nmesh);
Object::cast_to<Node3D>(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, HashMap<R
VehicleBody3D *bv = memnew(VehicleBody3D);
String n = _fixstr(p_node->get_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, HashMap<R
VehicleWheel3D *bv = memnew(VehicleWheel3D);
String n = _fixstr(p_node->get_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<Ref<Shape3D>>
}
}
+void ResourceImporterScene::_copy_meta(Object *p_src_object, Object *p_dst_object) {
+ List<StringName> 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<StringName> 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 bbf2d20163..cd6a725231 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<uint8_t> &p_src_lightmap_cache, Vector<Vector<uint8_t>> &r_lightmap_caches);
void _add_shapes(Node *p_node, const Vector<Ref<Shape3D>> &p_shapes);
+ void _copy_meta(Object *p_src_object, Object *p_dst_object);
enum AnimationImportTracks {
ANIMATION_IMPORT_TRACKS_IF_PRESENT,