Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where maya rig behaves different when loaded due to display handle logic #27

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions client/ayon_maya/plugins/load/load_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ def process_reference(self, context, name, namespace, options):
cmds.xform(group_name, zeroTransformPivots=True)

settings = get_project_settings(project_name)

display_handle = settings['maya']['load'].get(
'reference_loader', {}
).get('display_handle', True)
cmds.setAttr(
"{}.displayHandle".format(group_name), display_handle
)

color = plugin.get_load_color_for_product_type(
product_type, settings
)
Expand All @@ -215,25 +207,11 @@ def process_reference(self, context, name, namespace, options):
blue
)

cmds.setAttr(
"{}.displayHandle".format(group_name), display_handle
)
# 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("{}.selectHandleX".format(group_name), cx)
cmds.setAttr("{}.selectHandleY".format(group_name), cy)
cmds.setAttr("{}.selectHandleZ".format(group_name), cz)
display_handle = settings['maya']['load'].get(
'reference_loader', {}
).get('display_handle', True)
if display_handle:
self._set_display_handle(group_name)

if product_type == "rig":
self._post_process_rig(namespace, context, options)
Expand Down Expand Up @@ -282,6 +260,32 @@ def _lock_camera_transforms(self, nodes):
self.log.warning("This version of Maya does not support locking of"
" transforms of cameras.")

def _set_display_handle(self, group_name: str):
"""Enable display handle and move select handle to object center"""
cmds.setAttr(f"{group_name}.displayHandle", True)
# get bounding box
# Bugfix: We force a refresh here because there is a reproducable case
# with Advanced Skeleton rig where the call to `exactWorldBoundingBox`
# directly after the reference without it breaks the behavior of the
# rigs making it appear as if parts of the mesh are static.
# TODO: Preferably we have a better fix than requiring refresh on loads
cmds.refresh()
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 += pivot[0]
cy += pivot[1]
cz += pivot[2]
# set selection handle offset to center of bounding box
cmds.setAttr(f"{group_name}.selectHandleX", cx)
cmds.setAttr(f"{group_name}.selectHandleY", cy)
cmds.setAttr(f"{group_name}.selectHandleZ", cz)


class MayaUSDReferenceLoader(ReferenceLoader):
"""Reference USD file to native Maya nodes using MayaUSDImport reference"""
Expand Down