Skip to content

collect_instance

CollectBlenderInstanceData

Bases: BlenderInstancePlugin

Validator to verify that the instance is not empty

Source code in client/ayon_blender/plugins/publish/collect_instance.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class CollectBlenderInstanceData(plugin.BlenderInstancePlugin):
    """Validator to verify that the instance is not empty"""

    order = pyblish.api.CollectorOrder
    hosts = ["blender"]
    families = ["model", "pointcache", "animation", "rig", "camera", "layout",
                "blendScene", "usd"]
    label = "Collect Instance"

    def process(self, instance):
        instance_node = instance.data["transientData"]["instance_node"]

        # Collect members of the instance
        members = [instance_node]
        if isinstance(instance_node, bpy.types.Collection):
            members.extend(instance_node.objects)
            members.extend(instance_node.children)

            # Special case for animation instances, include armatures
            if instance.data["productType"] == "animation":
                for obj in instance_node.objects:
                    if obj.type == 'EMPTY' and obj.get(AVALON_PROPERTY):
                        members.extend(
                            child for child in obj.children
                            if child.type == 'ARMATURE'
                        )
        elif isinstance(instance_node, bpy.types.Object):
            members.extend(instance_node.children_recursive)
        else:
            raise KnownPublishError(
                f"Unsupported instance node type '{type(instance_node)}' "
                f"for instance '{instance}'"
            )

        instance[:] = members