Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2383 from Ellipsanime/add-options-to-not-group-re…
Browse files Browse the repository at this point in the history
…ference-for-referenceloader

Maya : add option to not group reference in ReferenceLoader
  • Loading branch information
antirotor authored Jan 4, 2022
2 parents bc81bfe + 21b6699 commit bc0b7f2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 56 deletions.
7 changes: 7 additions & 0 deletions openpype/hosts/maya/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ class ReferenceLoader(api.Loader):
"offset",
label="Position Offset",
help="Offset loaded models for easier selection."
),
qargparse.Boolean(
"attach_to_root",
label="Group imported asset",
default=True,
help="Should a group be created to encapsulate"
" imported representation ?"
)
]

Expand Down
115 changes: 59 additions & 56 deletions openpype/hosts/maya/plugins/load/load_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,85 +40,88 @@ def process_reference(self, context, name, namespace, options):
except ValueError:
family = "model"

group_name = "{}:_GRP".format(namespace)
# True by default to keep legacy behaviours
attach_to_root = options.get("attach_to_root", True)

with maya.maintained_selection():
groupName = "{}:_GRP".format(namespace)
cmds.loadPlugin("AbcImport.mll", quiet=True)
nodes = cmds.file(self.fname,
namespace=namespace,
sharedReferenceFile=False,
groupReference=True,
groupName=groupName,
reference=True,
returnNewNodes=True)

# namespace = cmds.referenceQuery(nodes[0], namespace=True)
returnNewNodes=True,
groupReference=attach_to_root,
groupName=group_name)

shapes = cmds.ls(nodes, shapes=True, long=True)

newNodes = (list(set(nodes) - set(shapes)))
new_nodes = (list(set(nodes) - set(shapes)))

current_namespace = pm.namespaceInfo(currentNamespace=True)

if current_namespace != ":":
groupName = current_namespace + ":" + groupName
group_name = current_namespace + ":" + group_name

self[:] = new_nodes

groupNode = pm.PyNode(groupName)
roots = set()
if attach_to_root:
group_node = pm.PyNode(group_name)
roots = set()

for node in newNodes:
try:
roots.add(pm.PyNode(node).getAllParents()[-2])
except: # noqa: E722
pass
for node in new_nodes:
try:
roots.add(pm.PyNode(node).getAllParents()[-2])
except: # noqa: E722
pass

if family not in ["layout", "setdress", "mayaAscii", "mayaScene"]:
if family not in ["layout", "setdress",
"mayaAscii", "mayaScene"]:
for root in roots:
root.setParent(world=True)

group_node.zeroTransformPivots()
for root in roots:
root.setParent(world=True)

groupNode.zeroTransformPivots()
for root in roots:
root.setParent(groupNode)

cmds.setAttr(groupName + ".displayHandle", 1)

settings = get_project_settings(os.environ['AVALON_PROJECT'])
colors = settings['maya']['load']['colors']
c = colors.get(family)
if c is not None:
groupNode.useOutlinerColor.set(1)
groupNode.outlinerColor.set(
(float(c[0])/255),
(float(c[1])/255),
(float(c[2])/255)
)

self[:] = newNodes

cmds.setAttr(groupName + ".displayHandle", 1)
# get bounding box
bbox = cmds.exactWorldBoundingBox(groupName)
# get pivot position on world space
pivot = cmds.xform(groupName, q=True, sp=True, ws=True)
# center of bounding box
cx = (bbox[0] + bbox[3]) / 2
cy = (bbox[1] + bbox[4]) / 2
cz = (bbox[2] + bbox[5]) / 2
# add pivot position to calculate offset
cx = cx + pivot[0]
cy = cy + pivot[1]
cz = cz + pivot[2]
# set selection handle offset to center of bounding box
cmds.setAttr(groupName + ".selectHandleX", cx)
cmds.setAttr(groupName + ".selectHandleY", cy)
cmds.setAttr(groupName + ".selectHandleZ", cz)
root.setParent(group_node)

cmds.setAttr(group_name + ".displayHandle", 1)

settings = get_project_settings(os.environ['AVALON_PROJECT'])
colors = settings['maya']['load']['colors']
c = colors.get(family)
if c is not None:
group_node.useOutlinerColor.set(1)
group_node.outlinerColor.set(
(float(c[0]) / 255),
(float(c[1]) / 255),
(float(c[2]) / 255))

cmds.setAttr(group_name + ".displayHandle", 1)
# get bounding box
bbox = cmds.exactWorldBoundingBox(group_name)
# get pivot position on world space
pivot = cmds.xform(group_name, q=True, sp=True, ws=True)
# center of bounding box
cx = (bbox[0] + bbox[3]) / 2
cy = (bbox[1] + bbox[4]) / 2
cz = (bbox[2] + bbox[5]) / 2
# add pivot position to calculate offset
cx = cx + pivot[0]
cy = cy + pivot[1]
cz = cz + pivot[2]
# set selection handle offset to center of bounding box
cmds.setAttr(group_name + ".selectHandleX", cx)
cmds.setAttr(group_name + ".selectHandleY", cy)
cmds.setAttr(group_name + ".selectHandleZ", cz)

if family == "rig":
self._post_process_rig(name, namespace, context, options)
else:

if "translate" in options:
cmds.setAttr(groupName + ".t", *options["translate"])
cmds.setAttr(group_name + ".t", *options["translate"])

return newNodes
return new_nodes

def switch(self, container, representation):
self.update(container, representation)
Expand Down

0 comments on commit bc0b7f2

Please sign in to comment.