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 | class OxAlembicLoader(plugin.Loader):
"""Ornatrix Alembic Loader"""
product_types = {"oxcache", "oxrig"}
representations = {"abc"}
label = "Ornatrix Alembic Loader"
order = -10
icon = "code-fork"
color = "orange"
@classmethod
def get_options(cls, contexts):
return [
EnumDef(
"import_options",
label="Import Options for Ornatrix Cache",
items={
0: "Hair",
1: "Guide"
},
default=0
)
]
def load(self, context, name, namespace, options):
cmds.loadPlugin("Ornatrix", quiet=True)
# Build namespace
folder_name = context["folder"]["name"]
if namespace is None:
namespace = self.create_namespace(folder_name)
path = self.filepath_from_context(context)
path = path.replace("\\", "/")
ox_import_options = "; importAs={}".format(
options.get("import_options"))
group_name = "{}:{}".format(namespace, name)
project_name = context["project"]["name"]
with maintained_selection():
nodes = cmds.file(
path,
i=True,
type="Ornatrix Alembic Import",
namespace=namespace,
returnNewNodes=True,
groupName=group_name,
options=ox_import_options
)
nodes = cmds.ls(nodes)
group_node = cmds.group(nodes, name=group_name)
settings = get_project_settings(project_name)
product_type = context["product"]["productType"]
color = get_load_color_for_product_type(product_type, settings)
if color is not None:
red, green, blue = color
cmds.setAttr(group_node + ".useOutlinerColor", 1)
cmds.setAttr(group_node + ".outlinerColor", red, green, blue)
nodes.append(group_node)
self[:] = nodes
return containerise(
name=name,
namespace=namespace,
nodes=nodes,
context=context,
loader=self.__class__.__name__
)
def update(self, container, context):
path = self.filepath_from_context(context)
members = lib.get_container_members(container)
ox_nodes = cmds.ls(members, type="BakedHairNode", long=True)
for node in ox_nodes:
cmds.setAttr(f"{node}.sourceFilePath1", path, type="string")
def switch(self, container, context):
self.update(container, context)
def remove(self, container):
self.log.info("Removing '%s' from Maya.." % container["name"])
nodes = lib.get_container_members(container)
cmds.delete(nodes)
namespace = container["namespace"]
cmds.namespace(removeNamespace=namespace, deleteNamespaceContent=True)
def create_namespace(self, folder_name):
"""Create a unique namespace
Args:
folder_name (str): Folder name
Returns:
str: The unique namespace for the folder.
"""
asset_name = "{}_".format(folder_name)
prefix = "_" if asset_name[0].isdigit() else ""
namespace = unique_namespace(
asset_name,
prefix=prefix,
suffix="_"
)
return namespace
|