From 16e0c4d7dcb56cf9670b630c1ac987443651083d Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 11 Sep 2024 18:46:11 +0800 Subject: [PATCH 1/6] add repre_type as json element --- .../ayon_maya/plugins/create/create_layout.py | 6 +- .../plugins/publish/collect_layout_options.py | 19 ------ .../plugins/publish/extract_layout.py | 67 ++++++------------- 3 files changed, 23 insertions(+), 69 deletions(-) delete mode 100644 client/ayon_maya/plugins/publish/collect_layout_options.py diff --git a/client/ayon_maya/plugins/create/create_layout.py b/client/ayon_maya/plugins/create/create_layout.py index 956b3fcf..ac081c32 100644 --- a/client/ayon_maya/plugins/create/create_layout.py +++ b/client/ayon_maya/plugins/create/create_layout.py @@ -17,9 +17,5 @@ def get_instance_attr_defs(self): label="Group Loaded Assets", tooltip="Enable this when you want to publish group of " "loaded asset", - default=False), - EnumDef("layout_options", - items=["fbx", "abc"], - label="Export Layout Options", - default="fbx") + default=False) ] diff --git a/client/ayon_maya/plugins/publish/collect_layout_options.py b/client/ayon_maya/plugins/publish/collect_layout_options.py deleted file mode 100644 index 6d92d120..00000000 --- a/client/ayon_maya/plugins/publish/collect_layout_options.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -import pyblish.api -from ayon_maya.api import plugin - - -class CollectLayoutOptions(plugin.MayaInstancePlugin): - """Collect Camera for FBX export.""" - - order = pyblish.api.CollectorOrder + 0.2 - label = "Collect Layout Options" - families = ["layout"] - - def process(self, instance): - if instance.data.get("layout_options") == "fbx": - instance.data["families"] += ["layout.fbx"] - elif instance.data.get("layout_options") == "abc": - instance.data["families"] += ["layout.abc"] - else: - self.log.error("No layout options found.") diff --git a/client/ayon_maya/plugins/publish/extract_layout.py b/client/ayon_maya/plugins/publish/extract_layout.py index bf00d468..dc699e71 100644 --- a/client/ayon_maya/plugins/publish/extract_layout.py +++ b/client/ayon_maya/plugins/publish/extract_layout.py @@ -32,8 +32,8 @@ def convert_matrix_to_4x4_list( class ExtractLayout(plugin.MayaExtractorPlugin): """Extract a layout.""" - label = "Extract Layout(FBX)" - families = ["layout.fbx"] + label = "Extract Layout" + families = ["layout"] project_container = "AVALON_CONTAINERS" def process(self, instance): @@ -81,11 +81,8 @@ def process(self, instance): representation = get_representation_by_id( project_name, representation_id, - fields={"versionId", "context"} + fields={"versionId", "context", "name"} ) - - self.log.debug(representation) - version_id = representation["versionId"] # TODO use product entity to get product type rather than # data in representation 'context' @@ -99,13 +96,15 @@ def process(self, instance): "instance_name": cmds.getAttr( "{}.namespace".format(container)), "representation": str(representation_id), - "version": str(version_id) + "version": str(version_id), + "extension": representation["name"] } local_matrix = cmds.xform(asset, query=True, matrix=True) local_rotation = cmds.xform(asset, query=True, rotation=True, euler=True) - t_matrix = self.create_transformation_matrix(local_matrix, local_rotation) + t_matrix = self.create_transformation_matrix( + local_matrix, local_rotation, product_type, representation["name"]) json_element["transform_matrix"] = [ list(row) @@ -150,14 +149,25 @@ def process(self, instance): self.log.debug("Extracted instance '%s' to: %s", instance.name, json_representation) - def create_transformation_matrix(self, local_matrix, local_rotation): + def create_transformation_matrix(self, local_matrix, local_rotation, product_type, extension="abc"): matrix = om.MMatrix(local_matrix) - matrix = self.convert_transformation_matrix(matrix, local_rotation) + if extension == "fbx": + matrix = self.convert_transformation_matrix(matrix, local_rotation) + elif extension == "abc": + matrix = self.convert_abc_transformation_matrix(matrix, local_rotation) + elif extension == "ma": + if product_type == "rig": + matrix = self.convert_transformation_matrix(matrix, local_rotation) + else: + matrix = self.convert_abc_transformation_matrix(matrix, local_rotation) + else: + raise RuntimeError( + f"No convert transformation matrix found for the loaded asset in {extension}") t_matrix = convert_matrix_to_4x4_list(matrix) return t_matrix - def convert_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list) -> om.MMatrix: - """Convert matrix to list of transformation matrix for Unreal Engine import. + def convert_abc_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list) -> om.MMatrix: + """Convert matrix to list of transformation matrix for Unreal Engine alembic asset import. Args: transform_mm (om.MMatrix): Local Matrix for the asset @@ -179,36 +189,3 @@ def convert_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list convert_transform.setScale([convert_scale[0], convert_scale[2], convert_scale[1]], om.MSpace.kObject) return convert_transform.asMatrix() - - -class ExtractLayoutAbc(ExtractLayout): - """Extract a layout.""" - - label = "Extract Layout(Abc)" - families = ["layout.abc"] - project_container = "AVALON_CONTAINERS" - - def convert_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list) -> om.MMatrix: - """Convert matrix to list of transformation matrix for Unreal Engine import. - - Args: - transform_mm (om.MMatrix): Local Matrix for the asset - rotation (list): Rotations of the asset - - Returns: - List[om.MMatrix]: List of transformation matrix of the asset - """ - # TODO: need to find the correct implementation of layout for alembic - convert_transform = om.MTransformationMatrix(transform_mm) - - convert_translation = convert_transform.translation(om.MSpace.kWorld) - convert_translation = om.MVector(convert_translation.x, convert_translation.z, convert_translation.y) - convert_scale = convert_transform.scale(om.MSpace.kObject) - convert_transform.setTranslation(convert_translation, om.MSpace.kWorld) - converted_rotation = om.MEulerRotation( - math.radians(rotation[0]), math.radians(rotation[2]), math.radians(rotation[1]) - ) - convert_transform.setRotation(converted_rotation) - convert_transform.setScale([convert_scale[0], convert_scale[2], convert_scale[1]], om.MSpace.kObject) - - return convert_transform.asMatrix() \ No newline at end of file From 1f0628bf7470672648da5262476db81bf67fe8a2 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 11 Sep 2024 18:50:41 +0800 Subject: [PATCH 2/6] add comment --- client/ayon_maya/plugins/publish/extract_layout.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/ayon_maya/plugins/publish/extract_layout.py b/client/ayon_maya/plugins/publish/extract_layout.py index dc699e71..f1c7e9b0 100644 --- a/client/ayon_maya/plugins/publish/extract_layout.py +++ b/client/ayon_maya/plugins/publish/extract_layout.py @@ -176,6 +176,8 @@ def convert_abc_transformation_matrix(self, transform_mm: om.MMatrix, rotation: Returns: List[om.MMatrix]: List of transformation matrix of the asset """ + # TODO: Edit the function to make sure the rotation has been correct even in some extreme + # ocassions convert_transform = om.MTransformationMatrix(transform_mm) convert_translation = convert_transform.translation(om.MSpace.kWorld) From 2e54535c89821ba0b23346afb1c70a512f4f7b7e Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 11 Sep 2024 18:52:27 +0800 Subject: [PATCH 3/6] add convert_transformation_matrix --- .../plugins/publish/extract_layout.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/client/ayon_maya/plugins/publish/extract_layout.py b/client/ayon_maya/plugins/publish/extract_layout.py index f1c7e9b0..e2523586 100644 --- a/client/ayon_maya/plugins/publish/extract_layout.py +++ b/client/ayon_maya/plugins/publish/extract_layout.py @@ -191,3 +191,28 @@ def convert_abc_transformation_matrix(self, transform_mm: om.MMatrix, rotation: convert_transform.setScale([convert_scale[0], convert_scale[2], convert_scale[1]], om.MSpace.kObject) return convert_transform.asMatrix() + + + def convert_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list) -> om.MMatrix: + """Convert matrix to list of transformation matrix for Unreal Engine fbx asset import. + + Args: + transform_mm (om.MMatrix): Local Matrix for the asset + rotation (list): Rotations of the asset + + Returns: + List[om.MMatrix]: List of transformation matrix of the asset + """ + convert_transform = om.MTransformationMatrix(transform_mm) + + convert_translation = convert_transform.translation(om.MSpace.kWorld) + convert_translation = om.MVector(convert_translation.x, convert_translation.z, convert_translation.y) + convert_scale = convert_transform.scale(om.MSpace.kObject) + convert_transform.setTranslation(convert_translation, om.MSpace.kWorld) + converted_rotation = om.MEulerRotation( + math.radians(rotation[0]), math.radians(rotation[2]), math.radians(rotation[1]) + ) + convert_transform.setRotation(converted_rotation) + convert_transform.setScale([convert_scale[0], convert_scale[2], convert_scale[1]], om.MSpace.kObject) + + return convert_transform.asMatrix() From 4c2a141ddb0641e883b0a6408e95a2adf601fb51 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 11 Sep 2024 18:54:56 +0800 Subject: [PATCH 4/6] ruff cosmetic fix --- client/ayon_maya/plugins/create/create_layout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_maya/plugins/create/create_layout.py b/client/ayon_maya/plugins/create/create_layout.py index ac081c32..1d9bc2c1 100644 --- a/client/ayon_maya/plugins/create/create_layout.py +++ b/client/ayon_maya/plugins/create/create_layout.py @@ -1,5 +1,5 @@ from ayon_maya.api import plugin -from ayon_core.lib import BoolDef, EnumDef +from ayon_core.lib import BoolDef class CreateLayout(plugin.MayaCreator): From abbc22d7261e2a8ff2c69b3ce0c417c7a4cfe4a2 Mon Sep 17 00:00:00 2001 From: Kayla Man <64118225+moonyuet@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:52:20 +0800 Subject: [PATCH 5/6] Update client/ayon_maya/plugins/publish/extract_layout.py Co-authored-by: Roy Nieterau --- client/ayon_maya/plugins/publish/extract_layout.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_maya/plugins/publish/extract_layout.py b/client/ayon_maya/plugins/publish/extract_layout.py index e2523586..1a5c4fb1 100644 --- a/client/ayon_maya/plugins/publish/extract_layout.py +++ b/client/ayon_maya/plugins/publish/extract_layout.py @@ -192,7 +192,6 @@ def convert_abc_transformation_matrix(self, transform_mm: om.MMatrix, rotation: return convert_transform.asMatrix() - def convert_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list) -> om.MMatrix: """Convert matrix to list of transformation matrix for Unreal Engine fbx asset import. From 26a0d7053105f544902532e14a3245bf59b59023 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Mon, 16 Sep 2024 18:03:53 +0800 Subject: [PATCH 6/6] use repre_context['ext'] for extension --- .../plugins/publish/extract_layout.py | 46 ++----------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/client/ayon_maya/plugins/publish/extract_layout.py b/client/ayon_maya/plugins/publish/extract_layout.py index 1a5c4fb1..669510e6 100644 --- a/client/ayon_maya/plugins/publish/extract_layout.py +++ b/client/ayon_maya/plugins/publish/extract_layout.py @@ -97,14 +97,13 @@ def process(self, instance): "{}.namespace".format(container)), "representation": str(representation_id), "version": str(version_id), - "extension": representation["name"] + "extension": repre_context["ext"] } local_matrix = cmds.xform(asset, query=True, matrix=True) local_rotation = cmds.xform(asset, query=True, rotation=True, euler=True) - t_matrix = self.create_transformation_matrix( - local_matrix, local_rotation, product_type, representation["name"]) + t_matrix = self.create_transformation_matrix(local_matrix, local_rotation) json_element["transform_matrix"] = [ list(row) @@ -149,49 +148,12 @@ def process(self, instance): self.log.debug("Extracted instance '%s' to: %s", instance.name, json_representation) - def create_transformation_matrix(self, local_matrix, local_rotation, product_type, extension="abc"): + def create_transformation_matrix(self, local_matrix, local_rotation): matrix = om.MMatrix(local_matrix) - if extension == "fbx": - matrix = self.convert_transformation_matrix(matrix, local_rotation) - elif extension == "abc": - matrix = self.convert_abc_transformation_matrix(matrix, local_rotation) - elif extension == "ma": - if product_type == "rig": - matrix = self.convert_transformation_matrix(matrix, local_rotation) - else: - matrix = self.convert_abc_transformation_matrix(matrix, local_rotation) - else: - raise RuntimeError( - f"No convert transformation matrix found for the loaded asset in {extension}") + matrix = self.convert_transformation_matrix(matrix, local_rotation) t_matrix = convert_matrix_to_4x4_list(matrix) return t_matrix - def convert_abc_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list) -> om.MMatrix: - """Convert matrix to list of transformation matrix for Unreal Engine alembic asset import. - - Args: - transform_mm (om.MMatrix): Local Matrix for the asset - rotation (list): Rotations of the asset - - Returns: - List[om.MMatrix]: List of transformation matrix of the asset - """ - # TODO: Edit the function to make sure the rotation has been correct even in some extreme - # ocassions - convert_transform = om.MTransformationMatrix(transform_mm) - - convert_translation = convert_transform.translation(om.MSpace.kWorld) - convert_translation = om.MVector(convert_translation.x, convert_translation.z, convert_translation.y) - convert_scale = convert_transform.scale(om.MSpace.kObject) - convert_transform.setTranslation(convert_translation, om.MSpace.kWorld) - converted_rotation = om.MEulerRotation( - math.radians(rotation[0]), math.radians(rotation[2]), math.radians(rotation[1]) - ) - convert_transform.setRotation(converted_rotation) - convert_transform.setScale([convert_scale[0], convert_scale[2], convert_scale[1]], om.MSpace.kObject) - - return convert_transform.asMatrix() - def convert_transformation_matrix(self, transform_mm: om.MMatrix, rotation: list) -> om.MMatrix: """Convert matrix to list of transformation matrix for Unreal Engine fbx asset import.