Skip to content

load_usd

GeoImportLoader

Bases: LoaderPlugin

This will load files to GeoImport node.

Source code in client/ayon_nuke/plugins/load/load_usd.py
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
class GeoImportLoader(load.LoaderPlugin):
    """This will load files to GeoImport node."""

    product_types = {"*"}
    representations = {"*"}
    extensions = {"abc", "usd", "usda", "usdc"}
    order = 2

    settings_category = "nuke"

    label = "Load GeoImport"
    icon = "cube"
    color = "orange"
    node_color = "0x4ecd91ff"

    node_class = "GeoImport"
    node_file_knob = "file"

    def load(self, context, name, namespace, data):
        namespace = namespace or context["folder"]["name"]
        object_name = "{}_{}".format(name, namespace)

        filepath = self.filepath_from_context(context).replace("\\", "/")

        with maintained_selection():
            file_knob: str = self.node_file_knob
            node = nuke.createNode(
                self.node_class,
                f"name {object_name} {file_knob} {filepath}",
                inpanel=False,
            )
            node.forceValidate()

        # color node by correct color by actual version
        self.set_node_version_color(node, context)

        return containerise(
            node=node,
            name=name,
            namespace=namespace,
            context=context,
            loader=self.__class__.__name__,
        )

    def update(self, container, context):
        node: nuke.Node = container["node"]
        file = self.filepath_from_context(context).replace("\\", "/")
        node[self.node_file_knob].setValue(file)

        # color node by correct color by actual version
        self.set_node_version_color(node, context)

        # update representation id
        return update_container(
            node,
            {
                "representation": context["representation"]["id"],
            },
        )

    def set_node_version_color(self, node: nuke.Node, context: dict):
        """Coloring a node by correct color by actual version"""
        is_latest_version = ayon_api.version_is_latest(
            context["project"]["name"], context["version"]["id"]
        )
        color_value = self.node_color if is_latest_version else "0xd88467ff"
        node["tile_color"].setValue(int(color_value, 16))

    def switch(self, container, context):
        self.update(container, context)

    def remove(self, container):
        node = nuke.toNode(container["objectName"])
        with viewer_update_and_undo_stop():
            nuke.delete(node)

set_node_version_color(node, context)

Coloring a node by correct color by actual version

Source code in client/ayon_nuke/plugins/load/load_usd.py
73
74
75
76
77
78
79
def set_node_version_color(self, node: nuke.Node, context: dict):
    """Coloring a node by correct color by actual version"""
    is_latest_version = ayon_api.version_is_latest(
        context["project"]["name"], context["version"]["id"]
    )
    color_value = self.node_color if is_latest_version else "0xd88467ff"
    node["tile_color"].setValue(int(color_value, 16))

GeoReferenceLoader

Bases: GeoImportLoader

This will load files to GeoReference node.

Source code in client/ayon_nuke/plugins/load/load_usd.py
90
91
92
93
94
95
96
class GeoReferenceLoader(GeoImportLoader):
    """This will load files to GeoReference node."""
    label = "Load GeoReference"
    order = 3

    node_class = "GeoReference"
    node_file_knob = "file_path"