Bases: ProductConvertorPlugin
Conversion of legacy instances in scene to new creators.
This convertor handles only instances created by core creators.
All instances that would be created using auto-creators are removed as at the moment of finding them would there already be existing instances.
Source code in client/ayon_tvpaint/plugins/create/convert_legacy.py
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
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 | class TVPaintLegacyConverted(ProductConvertorPlugin):
"""Conversion of legacy instances in scene to new creators.
This convertor handles only instances created by core creators.
All instances that would be created using auto-creators are removed as at
the moment of finding them would there already be existing instances.
"""
identifier = "tvpaint.legacy.converter"
def find_instances(self):
instances_by_identifier = cache_and_get_instances(
self, SHARED_DATA_KEY, self.host.list_instances
)
if instances_by_identifier[None]:
self.add_convertor_item("Convert legacy instances")
def convert(self):
current_instances = self.host.list_instances()
to_convert = collections.defaultdict(list)
converted = False
for instance in current_instances:
if instance.get("creator_identifier") is not None:
continue
converted = True
family = instance.get("family")
if family in (
"renderLayer",
"renderPass",
"renderScene",
"review",
"workfile",
):
to_convert[family].append(instance)
else:
instance["keep"] = False
# Skip if nothing was changed
if not converted:
self.remove_convertor_item()
return
self._convert_render_layers(
to_convert["renderLayer"], current_instances)
self._convert_render_passes(
to_convert["renderPass"], current_instances)
self._convert_render_scenes(
to_convert["renderScene"], current_instances)
self._convert_workfiles(
to_convert["workfile"], current_instances)
self._convert_reviews(
to_convert["review"], current_instances)
new_instances = [
instance
for instance in current_instances
if instance.get("keep") is not False
]
self.host.write_instances(new_instances)
# remove legacy item if all is fine
self.remove_convertor_item()
def _convert_render_layers(self, render_layers, current_instances):
if not render_layers:
return
# Look for possible existing render layers in scene
render_layers_by_group_id = {}
for instance in current_instances:
if instance.get("creator_identifier") == "render.layer":
group_id = instance["creator_identifier"]["group_id"]
render_layers_by_group_id[group_id] = instance
groups_by_id = {
group["group_id"]: group
for group in get_groups_data()
}
for render_layer in render_layers:
group_id = render_layer.pop("group_id")
# Just remove legacy instance if group is already occupied
if group_id in render_layers_by_group_id:
render_layer["keep"] = False
continue
# Add identifier
render_layer["creator_identifier"] = "render.layer"
# Change 'uuid' to 'instance_id'
render_layer["instance_id"] = render_layer.pop("uuid")
# Fill creator attributes
render_layer["creator_attributes"] = {
"group_id": group_id
}
render_layer["productType"] = "render"
group = groups_by_id[group_id]
# Use group name for variant
group["variant"] = group["name"]
def _convert_render_passes(self, render_passes, current_instances):
if not render_passes:
return
# Render passes must have available render layers so we look for render
# layers first
# - '_convert_render_layers' must be called before this method
render_layers_by_group_id = {}
for instance in current_instances:
if instance.get("creator_identifier") == "render.layer":
group_id = instance["creator_attributes"]["group_id"]
render_layers_by_group_id[group_id] = instance
for render_pass in render_passes:
group_id = render_pass.pop("group_id")
render_layer = render_layers_by_group_id.get(group_id)
if not render_layer:
render_pass["keep"] = False
continue
render_pass["creator_identifier"] = "render.pass"
render_pass["instance_id"] = render_pass.pop("uuid")
render_pass["productType"] = "render"
render_pass["creator_attributes"] = {
"render_layer_instance_id": render_layer["instance_id"]
}
render_pass["variant"] = render_pass.pop("pass")
render_pass.pop("renderlayer")
# Rest of instances are just marked for deletion
def _convert_render_scenes(self, render_scenes, current_instances):
for render_scene in render_scenes:
render_scene["keep"] = False
def _convert_workfiles(self, workfiles, current_instances):
for render_scene in workfiles:
render_scene["keep"] = False
def _convert_reviews(self, reviews, current_instances):
for render_scene in reviews:
render_scene["keep"] = False
|