Skip to content

load_ornatrix_rig

OxRigLoader

Bases: ReferenceLoader

This loader will load Ornatrix rig.

Source code in client/ayon_maya/plugins/load/load_ornatrix_rig.py
 9
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class OxRigLoader(plugin.ReferenceLoader):
    """This loader will load Ornatrix rig."""

    product_types = {"oxrig"}
    representations = {"ma"}

    label = "Load Ornatrix Rig"
    order = -11
    icon = "code-fork"
    color = "orange"

    # From settings
    create_cache_instance_on_load = True

    def process_reference(
        self, context, name=None, namespace=None, options=None
    ):
        cmds.loadPlugin("Ornatrix", quiet=True)

        attach_to_root = options.get("attach_to_root", True)
        group_name = options["group_name"]

        # no group shall be created
        if not attach_to_root:
            group_name = namespace

        path = self.filepath_from_context(context)
        file_url = self.prepare_root_value(path, context["project"]["name"])
        with lib.maintained_selection():
            nodes = cmds.file(
                file_url,
                namespace=namespace,
                reference=True,
                returnNewNodes=True,
                groupReference=attach_to_root,
                groupName=group_name
            )

        color = plugin.get_load_color_for_product_type("oxrig")
        if color is not None:
            red, green, blue = color
            cmds.setAttr(group_name + ".useOutlinerColor", 1)
            cmds.setAttr(
                group_name + ".outlinerColor", red, green, blue
            )

        self[:] = nodes

        if self.create_cache_instance_on_load:
            self._create_ox_cache_instance(nodes, variant=namespace)

        return nodes

    def _create_ox_cache_instance(self, nodes: List[str], variant: str):
        """Create an ornatrixcache product type instance to publish the output.

        This is similar to how loading animation rig will automatically create
        an animation instance for publishing any loaded character rigs, but
        then for Ornatrix rigs.

        Args:
            nodes (List[str]): Nodes generated on load.
            variant (str): Variant for the ornatrix cache instance to create.

        """

        # Check of the nodes connect to the ornatrix-related nodes
        ox_node_types = (
            "HairFromGuidesNode", "GuidesFromMeshNode",
            "MeshFromStrandsNode", "SurfaceCombNode"
        )
        # Check of the nodes connect to the ornatrix-related nodes
        ox_nodes = cmds.ls(nodes, type=ox_node_types)
        assert ox_nodes, "No Ornatrix nodes in rig, this is a bug."

        ox_geo_nodes = cmds.ls(nodes, assemblies=True, long=True)

        self.log.info("Creating variant: {}".format(variant))

        creator_identifier = "io.ayon.creators.maya.oxcache"

        host = registered_host()
        create_context = CreateContext(host)

        with lib.maintained_selection():
            cmds.select(ox_geo_nodes, noExpand=True)
            create_context.create(
                creator_identifier=creator_identifier,
                variant=variant,
                pre_create_data={"use_selection": True}
            )