Skip to content

Commit

Permalink
Merge pull request #2311 from KhronosGroup/fix_2302
Browse files Browse the repository at this point in the history
Fix #2303 - children type check refactoring
  • Loading branch information
julienduroure committed Aug 30, 2024
2 parents ddb422f + b4af89f commit efaa4ba
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions addons/io_scene_gltf2/blender/exp/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -377,7 +384,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):
Expand Down Expand Up @@ -460,7 +467,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)
Expand Down

0 comments on commit efaa4ba

Please sign in to comment.