Skip to content

Commit

Permalink
Merge pull request ynput#199 from ynput/bugfix/AY-7267_Loading-Maya-J…
Browse files Browse the repository at this point in the history
…SON-Layout-to-Maya-fails

Load Layout from the json exported from maya layout should have correct transform
  • Loading branch information
moonyuet authored Dec 16, 2024
2 parents b2e5920 + 952d95a commit cb1c5d2
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions client/ayon_maya/plugins/load/load_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ def set_transformation(self, assets, element):
self._set_transformation(asset, transform)
else:
transform = element["transform_matrix"]
rotation = element["rotation"]
# flatten matrix to a list
maya_transform_matrix = [element for row in transform for element in row]
self._convert_transformation_matrix(asset, maya_transform_matrix, rotation)
self._set_transformation_by_matrix(asset, maya_transform_matrix)

def _set_transformation(self, asset, transform):
translation = [
Expand All @@ -174,23 +173,33 @@ def _set_transformation(self, asset, transform):
scale=scale
)

def _convert_transformation_matrix(self, asset, transform, rotation):
"""Convert matrix to list of transformation matrix for Unreal Engine import.
def _set_transformation_by_matrix(self, asset, transform):
"""Set transformation with transform matrix and rotation data
for the imported asset.
Args:
transform (list): Transformations of the asset
rotation (list): Rotations of the asset
Returns:
List[om.MMatrix]: List of transformation matrix of the asset
"""
transform_mm = om.MMatrix(transform)
convert_transform = om.MTransformationMatrix(transform_mm)
converted_rotation = om.MEulerRotation(
math.radians(rotation["x"]), math.radians(rotation["y"]), math.radians(rotation["z"])
convert_translation = convert_transform.translation(om.MSpace.kWorld)
convert_scale = convert_transform.scale(om.MSpace.kWorld)
convert_rotation = convert_transform.rotation()
rotation_degrees = [om.MAngle(convert_rotation.x).asDegrees(),
om.MAngle(convert_rotation.z).asDegrees(),
om.MAngle(convert_rotation.y).asDegrees()]
translation = [
convert_translation.x,
convert_translation.z,
convert_translation.y
]
cmds.xform(
asset,
translation=translation,
rotation=rotation_degrees,
scale=[convert_scale[0], convert_scale[2], convert_scale[1]]
)
convert_transform.setRotation(converted_rotation)
cmds.xform(asset, matrix=convert_transform.asMatrix())


def load(self, context, name, namespace, options):
path = self.filepath_from_context(context)
Expand Down

0 comments on commit cb1c5d2

Please sign in to comment.