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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177 | class AlembicCameraLoader(load.LoaderPlugin):
"""
This will load a camera into script.
"""
product_base_types = {"camera"}
product_types = product_base_types
representations = {"*"}
extensions = {"abc"}
label = "Load Alembic Camera"
enabled = True
settings_category = "nuke"
icon = "camera"
color = "orange"
node_color = "0x3469ffff"
@undo_chunk("Load Alembic Camera")
def load(self, context, name, namespace, data):
# get main variables
version_entity = context["version"]
version_attributes = version_entity["attrib"]
first = version_attributes.get("frameStart")
last = version_attributes.get("frameEnd")
fps = version_attributes.get("fps") or nuke.root()["fps"].getValue()
namespace = namespace or context["folder"]["name"]
object_name = "{}_{}".format(name, namespace)
# prepare data for imprinting
# add additional metadata from the version to imprint to metadata knob
data_imprint = {
"frameStart": first,
"frameEnd": last,
"version": version_entity["version"],
"source": version_attributes["source"],
"fps": version_attributes["fps"]
}
# getting file path
file = self.filepath_from_context(context).replace("\\", "/")
with maintained_selection():
try:
camera_node = nuke.createNode(
"Camera3",
f"name {object_name}",
inpanel=False,
)
except RuntimeError: # older nuke version
camera_node = nuke.createNode(
"Camera2",
f"name {object_name}",
inpanel=False,
)
with knob_values({
camera_node["suppress_dialog"]: True,
}):
camera_node["read_from_file"].setValue(True)
camera_node["file"].setValue(file) # set file after making sure "read_from_file" is True # noqa: E501
camera_node["frame_rate"].setValue(float(fps))
# color node by correct color by actual version
self.node_version_color(
context["project"]["name"], version_entity, camera_node
)
return containerise(
node=camera_node,
name=name,
namespace=namespace,
context=context,
loader=self.__class__.__name__,
data=data_imprint)
@undo_chunk("Update Alembic Camera")
def update(self, container, context):
"""
Called by Scene Inventory when look should be updated to current
version.
If any reference edits cannot be applied, eg. shader renamed and
material not present, reference is unloaded and cleaned.
All failed edits are highlighted to the user via message box.
Args:
container: object that has look to be updated
representation: (dict): relationship data to get proper
representation from DB and persisted
data in .json
Returns:
None
"""
# Get version from io
version_entity = context["version"]
repre_entity = context["representation"]
# get main variables
version_attributes = version_entity["attrib"]
first = version_attributes.get("frameStart")
last = version_attributes.get("frameEnd")
fps = version_attributes.get("fps") or nuke.root()["fps"].getValue()
# prepare data for imprinting
data_imprint = {
"representation": repre_entity["id"],
"frameStart": first,
"frameEnd": last,
"version": version_entity["version"],
"source": version_attributes["source"],
"fps": version_attributes["fps"],
"project_name": context["project"]["name"],
}
# getting file path
file = get_representation_path(repre_entity).replace("\\", "/")
camera_node = container["node"]
with knob_values({
camera_node["suppress_dialog"]: True,
}):
camera_node["read_from_file"].setValue(True)
camera_node["file"].setValue(file)
camera_node["frame_rate"].setValue(float(fps))
# color node by correct color by actual version
self.node_version_color(
context["project"]["name"], version_entity, camera_node
)
self.log.info(
"updated to version: {}".format(version_entity["version"])
)
return update_container(camera_node, data_imprint)
def node_version_color(self, project_name, version_entity, node):
"""Coloring a node by correct color by actual version
"""
# get all versions in list
last_version_entity = ayon_api.get_last_version_by_product_id(
project_name, version_entity["productId"], fields={"id"}
)
# change color of node
if version_entity["id"] == last_version_entity["id"]:
color_value = self.node_color
else:
color_value = "0xd88467ff"
node["tile_color"].setValue(int(color_value, 16))
def switch(self, container, context):
self.update(container, context)
@undo_chunk("Remove Alembic Camera")
def remove(self, container):
node = container["node"]
nuke.delete(node)
|