Skip to content

Commit

Permalink
Merge pull request #27 from BigRoy/bugfix/load_refresh_before_boundin…
Browse files Browse the repository at this point in the history
…gbox_rig

Fix bug where maya rig behaves different when loaded due to display handle logic
  • Loading branch information
BigRoy authored Jul 19, 2024
2 parents 4b7302f + e323f0c commit d0a787d
Showing 1 changed file with 31 additions and 27 deletions.
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

0 comments on commit d0a787d

Please sign in to comment.