diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index 92cee414..d16f8085 100644 --- a/client/ayon_maya/plugins/load/load_reference.py +++ b/client/ayon_maya/plugins/load/load_reference.py @@ -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 ) @@ -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) @@ -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"""