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 | class VRaySceneLoader(plugin.Loader):
"""Load Vray scene"""
product_types = {"vrayscene_layer"}
representations = {"vrscene"}
label = "Import VRay Scene"
order = -10
icon = "code-fork"
color = "orange"
def load(self, context, name, namespace, data):
product_type = context["product"]["productType"]
folder_name = context["folder"]["name"]
namespace = namespace or unique_namespace(
folder_name + "_",
prefix="_" if folder_name[0].isdigit() else "",
suffix="_",
)
# Ensure V-Ray for Maya is loaded.
cmds.loadPlugin("vrayformaya", quiet=True)
with maintained_selection():
cmds.namespace(addNamespace=namespace)
with namespaced(namespace, new=False):
nodes, root_node = self.create_vray_scene(
name,
filename=self.filepath_from_context(context)
)
self[:] = nodes
if not nodes:
return
# colour the group node
project_name = context["project"]["name"]
settings = get_project_settings(project_name)
color = get_load_color_for_product_type(product_type, settings)
if color is not None:
red, green, blue = color
cmds.setAttr("{0}.useOutlinerColor".format(root_node), 1)
cmds.setAttr(
"{0}.outlinerColor".format(root_node), red, green, blue
)
return containerise(
name=name,
namespace=namespace,
nodes=nodes,
context=context,
loader=self.__class__.__name__)
def update(self, container, context):
node = container['objectName']
assert cmds.objExists(node), "Missing container"
members = cmds.sets(node, query=True) or []
vraymeshes = cmds.ls(members, type="VRayScene")
assert vraymeshes, "Cannot find VRayScene in container"
repre_entity = context["representation"]
filename = get_representation_path(repre_entity)
for vray_mesh in vraymeshes:
cmds.setAttr("{}.FilePath".format(vray_mesh),
filename,
type="string")
# Update metadata
cmds.setAttr("{}.representation".format(node),
repre_entity["id"],
type="string")
def remove(self, container):
# Delete container and its contents
if cmds.objExists(container['objectName']):
members = cmds.sets(container['objectName'], query=True) or []
cmds.delete([container['objectName']] + members)
# Remove the namespace, if empty
namespace = container['namespace']
if cmds.namespace(exists=namespace):
members = cmds.namespaceInfo(namespace, listNamespace=True)
if not members:
cmds.namespace(removeNamespace=namespace)
else:
self.log.warning("Namespace not deleted because it "
"still has members: %s", namespace)
def switch(self, container, context):
self.update(container, context)
def create_vray_scene(self, name, filename):
"""Re-create the structure created by VRay to support vrscenes
Args:
name(str): name of the asset
Returns:
nodes(list)
"""
# Create nodes
mesh_node_name = "VRayScene_{}".format(name)
trans = cmds.createNode(
"transform", name=mesh_node_name)
vray_scene = cmds.createNode(
"VRayScene", name="{}_VRSCN".format(mesh_node_name), parent=trans)
mesh = cmds.createNode(
"mesh", name="{}_Shape".format(mesh_node_name), parent=trans)
cmds.connectAttr(
"{}.outMesh".format(vray_scene), "{}.inMesh".format(mesh))
cmds.setAttr("{}.FilePath".format(vray_scene), filename, type="string")
# Lock the shape nodes so the user cannot delete these
cmds.lockNode(mesh, lock=True)
cmds.lockNode(vray_scene, lock=True)
# Create important connections
cmds.connectAttr("time1.outTime",
"{0}.inputTime".format(trans))
# Connect mesh to initialShadingGroup
cmds.sets([mesh], forceElement="initialShadingGroup")
nodes = [trans, vray_scene, mesh]
# Fix: Force refresh so the mesh shows correctly after creation
cmds.refresh()
return nodes, trans
|