From cac33bdd8efba03e1ef7bb6ccef9cb091afd7be5 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 17 Jul 2024 13:27:18 +0200 Subject: [PATCH 1/7] Add a forced refresh before `exactWorldBoundingBox` call to avoid issue with certain rigs --- client/ayon_maya/plugins/load/load_reference.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index 92cee414..b0cfa6c7 100644 --- a/client/ayon_maya/plugins/load/load_reference.py +++ b/client/ayon_maya/plugins/load/load_reference.py @@ -214,11 +214,11 @@ def process_reference(self, context, name, namespace, options): green, blue ) - cmds.setAttr( "{}.displayHandle".format(group_name), display_handle ) # get bounding box + cmds.refresh() bbox = cmds.exactWorldBoundingBox(group_name) # get pivot position on world space pivot = cmds.xform(group_name, q=True, sp=True, ws=True) @@ -246,7 +246,7 @@ def process_reference(self, context, name, namespace, options): group_name = root_nodes[0] cmds.setAttr("{}.translate".format(group_name), *options["translate"]) - return new_nodes + return def switch(self, container, context): self.update(container, context) From c43504b760ddf67296d2c6ddd3694fc453b32609 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 17 Jul 2024 13:28:45 +0200 Subject: [PATCH 2/7] Only set display handle / select handle logic if it's enabled in settings --- .../ayon_maya/plugins/load/load_reference.py | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index b0cfa6c7..81acf5a1 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 ) @@ -214,26 +206,30 @@ def process_reference(self, context, name, namespace, options): green, blue ) - cmds.setAttr( - "{}.displayHandle".format(group_name), display_handle - ) - # get bounding box - 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 = 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: + cmds.setAttr(f"{group_name}.displayHandle", display_handle) + + # get bounding box + 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 = 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) if product_type == "rig": self._post_process_rig(namespace, context, options) From d9a4a181d382fcad60b1068c5b5b6cc12ba62355 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 17 Jul 2024 13:30:56 +0200 Subject: [PATCH 3/7] Add comment about the bugfix --- client/ayon_maya/plugins/load/load_reference.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index 81acf5a1..5300c617 100644 --- a/client/ayon_maya/plugins/load/load_reference.py +++ b/client/ayon_maya/plugins/load/load_reference.py @@ -212,8 +212,12 @@ def process_reference(self, context, name, namespace, options): ).get('display_handle', True) if display_handle: cmds.setAttr(f"{group_name}.displayHandle", display_handle) - # 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. cmds.refresh() bbox = cmds.exactWorldBoundingBox(group_name) # get pivot position on world space From 6f8296c71ef471e49e5956bde58f5447c36bd6e1 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 17 Jul 2024 13:47:45 +0200 Subject: [PATCH 4/7] Move setting of display handle into dedicated method for clarity --- .../ayon_maya/plugins/load/load_reference.py | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index 5300c617..65a43bed 100644 --- a/client/ayon_maya/plugins/load/load_reference.py +++ b/client/ayon_maya/plugins/load/load_reference.py @@ -211,29 +211,7 @@ def process_reference(self, context, name, namespace, options): 'reference_loader', {} ).get('display_handle', True) if display_handle: - cmds.setAttr(f"{group_name}.displayHandle", display_handle) - # 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. - 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 = 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) + 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 """ + 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. + 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""" From 8605bd71775f9b561ac24f40b1c0ff7fa2a58122 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 17 Jul 2024 13:48:18 +0200 Subject: [PATCH 5/7] Fix docstring --- client/ayon_maya/plugins/load/load_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index 65a43bed..baeb186b 100644 --- a/client/ayon_maya/plugins/load/load_reference.py +++ b/client/ayon_maya/plugins/load/load_reference.py @@ -261,7 +261,7 @@ def _lock_camera_transforms(self, nodes): " transforms of cameras.") def _set_display_handle(self, group_name: str): - """Enable display handle """ + """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 From dd77f461e3f139a9fcaec8ab92268b1bdae60f00 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 17 Jul 2024 13:55:33 +0200 Subject: [PATCH 6/7] Fix return value --- client/ayon_maya/plugins/load/load_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index baeb186b..c737d007 100644 --- a/client/ayon_maya/plugins/load/load_reference.py +++ b/client/ayon_maya/plugins/load/load_reference.py @@ -224,7 +224,7 @@ def process_reference(self, context, name, namespace, options): group_name = root_nodes[0] cmds.setAttr("{}.translate".format(group_name), *options["translate"]) - return + return new_nodes def switch(self, container, context): self.update(container, context) From e323f0c659803c2df90297c58e3bd7c4251491b3 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 17 Jul 2024 13:56:42 +0200 Subject: [PATCH 7/7] Improve comment + add todo --- client/ayon_maya/plugins/load/load_reference.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/ayon_maya/plugins/load/load_reference.py b/client/ayon_maya/plugins/load/load_reference.py index c737d007..d16f8085 100644 --- a/client/ayon_maya/plugins/load/load_reference.py +++ b/client/ayon_maya/plugins/load/load_reference.py @@ -264,11 +264,11 @@ 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. + # 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