Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions addons/io_scene_gltf2/blender/exp/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ def recursive_node_traverse(
if parent_uuid is not None:
self.add_children(parent_uuid, node.uuid)

# 2 cases where we will need to store the fact that children are in collection or a real children
# 3 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
# 3. Instance collection
# 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_type !=
VExportNode.COLLECTION and self.nodes[parent_uuid].blender_object is not None and self.nodes[parent_uuid].blender_object.is_instancer is True):
Expand Down Expand Up @@ -414,19 +415,28 @@ def recursive_node_traverse(
is_collection=True)
else:
# Manage children objects
self.recursive_node_traverse(
blender_object.instance_collection,
None,
node.uuid,
node.matrix_world,
new_delta or delta,
blender_children,
is_collection=True,
is_children_in_collection=True)
# Do not loop on children of the instance collection,
# But on the children of the collection itself

ref_collection = blender_object.instance_collection
collection_objects = set(ref_collection.objects)
for child in _sort_by_name(collection_objects):
# On Collection, .objects returns all objects & instance collection
# Not only the direct children

# Keep only object if it has no parent, or parent is not in the collection
if child.parent is not None and len(child.parent.users_collection) > 0 \
and len(child.users_collection) > 0 \
and child.users_collection[0].name == child.parent.users_collection[0].name:
continue

self.recursive_node_traverse(child, None, node.uuid, node.matrix_world,
new_delta or delta, blender_children, is_children_in_collection=True)

# Some objects are parented to instance collection
for child in _sort_by_name(blender_children[blender_object]):
self.recursive_node_traverse(child, None, node.uuid, parent_coll_matrix_world,
new_delta or delta, blender_children, is_children_in_collection=True)
new_delta or delta, blender_children)
# Manage children collections
for child in _sort_by_name(blender_object.instance_collection.children):
self.recursive_node_traverse(
Expand Down
4 changes: 2 additions & 2 deletions tests/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ describe('Exporter', function () {
let gltfPath = path.resolve(outDirPath, '01_linked_collection.gltf');
const asset = JSON.parse(fs.readFileSync(gltfPath));

assert.strictEqual(asset.nodes.length, 4);
assert.strictEqual(asset.nodes.length, 3);
});

it('can export all collection instances', function () {
let gltfPath = path.resolve(outDirPath, '01_multiple_collection_instances.gltf');
const asset = JSON.parse(fs.readFileSync(gltfPath));

assert.strictEqual(asset.nodes.length, 9);
assert.strictEqual(asset.nodes.length, 7);
});

it('can export a base color', function () {
Expand Down
Loading