From 846738dc17bd48a060b9b8a3a60ab07ba7de1808 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Tue, 13 Aug 2024 18:37:35 +0200 Subject: [PATCH] Fix #2303 - children type check refactoring --- .../blender/exp/gltf2_blender_gather_tree.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py index f8bb8f568..176728f90 100644 --- a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py +++ b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py @@ -34,9 +34,7 @@ class VExportNode: COLLECTION = 6 INSTANCE = 7 # For instances of GN - INSTANCIER = 8 - NOT_INSTANCIER = 9 - INST_COLLECTION = 7 + INST_COLLECTION = 8 # Parent type, to be set on child regarding its parent @@ -89,7 +87,7 @@ def __init__(self): self.data = None self.materials = None - self.is_instancier = VExportNode.NOT_INSTANCIER + self.is_instancer = False def add_child(self, uuid): self.children.append(uuid) @@ -156,8 +154,17 @@ def recursive_node_traverse(self, blender_object, blender_bone, parent_uuid, par # add to parent if needed if parent_uuid is not None: self.add_children(parent_uuid, node.uuid) - if self.nodes[parent_uuid].blender_type == VExportNode.INST_COLLECTION or original_object is not None: + + # 2 cases where we will need to store the fact that children are in collection or a real children + # 1. GN instance + # 2. Old Dupli vertices feature + # For any other case, children are real children + if (self.nodes[parent_uuid].blender_type == VExportNode.INST_COLLECTION or original_object is not None) or \ + (self.nodes[parent_uuid].blender_object is not None and self.nodes[parent_uuid].blender_object.is_instancer is True): self.nodes[parent_uuid].children_type[node.uuid] = VExportNode.CHILDREN_IS_IN_COLLECTION if is_children_in_collection is True else VExportNode.CHILDREN_REAL + else: + # We are in a regular case where children are real children + self.nodes[parent_uuid].children_type[node.uuid] = VExportNode.CHILDREN_REAL else: self.roots.append(node.uuid) @@ -376,7 +383,7 @@ def recursive_node_traverse(self, blender_object, blender_bone, parent_uuid, par continue if type(inst.object.data).__name__ == "Mesh" and len(inst.object.data.vertices) == 0: continue # This is nested instances, and this mesh has no vertices, so is an instancier for other instances - node.is_instancier = VExportNode.INSTANCIER + node.is_instancer = True self.recursive_node_traverse(None, None, node.uuid, parent_coll_matrix_world, new_delta or delta, blender_children, dupli_world_matrix=inst.matrix_world.copy(), data=inst.object.data, original_object=blender_object, is_children_in_collection=True) def get_all_objects(self): @@ -459,7 +466,7 @@ def recursive_filter_tag(self, uuid, parent_keep_tag): self.export_settings['log'].error("This should not happen") for child in self.nodes[uuid].children: - if self.nodes[uuid].blender_type == VExportNode.INST_COLLECTION or self.nodes[uuid].is_instancier == VExportNode.INSTANCIER: + if self.nodes[uuid].blender_type == VExportNode.INST_COLLECTION or self.nodes[uuid].is_instancer == True: # We need to split children into 2 categories: real children, and objects inside the collection if self.nodes[uuid].children_type[child] == VExportNode.CHILDREN_IS_IN_COLLECTION: self.recursive_filter_tag(child, self.nodes[uuid].keep_tag)