BUG MTransformationMatrix.scale()

BUG MTransformationMatrix.scale()

AdamBakerArt
Explorer Explorer
530 Views
2 Replies
Message 1 of 3

BUG MTransformationMatrix.scale()

AdamBakerArt
Explorer
Explorer

HI, 

 

Looks like MTransformationMatrix.scale(space) has a bug inside maya that it doesn't return the correct output when trying to get om2.MSpace.kWorld. 

 

Testing in Maya 2022 (windows) and it works as expected but once running in maya 2023 it returns only the local values. 

 

Here is some test code

import maya.api.OpenMaya as om2
import maya.cmds as cmds

# Node name
node = 'cube'

# Lets make a simple cube and put it into a gorup
maya.cmds.polyCube(name=node)
group = maya.cmds.group()

# Scale the group x2 
maya.cmds.scale(2,2,2, group)

selection_list = om2.MSelectionList()
selection_list.add(node)
dag_path = selection_list.getDagPath(0)

# Create an MFnTransform object for the node
transform_fn = om2.MFnTransform(dag_path)

# Get the MTransformationMatrix for the node
transform_matrix = transform_fn.transformation()

# Get the scale values in world space
scale_vector = transform_matrix.scale(om2.MSpace.kWorld)

# Print out scale
print('Object Scale in world space:', scale_vector)
"""
Returns:
Object Scale in world space: [1.0, 1.0, 1.0]
Expected Return:
Object Scale in world space: [2.0, 2.0, 2.0]
"""

 

Not sure if I have totally glossed over something here but it is not working when it comes to getting local scale.

0 Likes
Accepted solutions (1)
531 Views
2 Replies
Replies (2)
Message 2 of 3

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

 

On line 22 you are getting the local transformation matrix of the cube, not the world matrix. Try this instead:

transform_matrix = om2.MTransformationMatrix(dag_path.inclusiveMatrix())


P.S. I also tested you script in Maya 2022 and got the same result. Were you testing on the latest update release or an earlier one because I don't think the behaviour of transform_fn.transformation() has changed.

Brent McPherson
Principle Engineer
0 Likes
Message 3 of 3

AdamBakerArt
Explorer
Explorer

Thanks Brent, 

You are correct, I was not getting world Matrix, check in with that is going on in Maya 2022 and get back with that information. 

I am going to approve your reply and respond with more information. 

0 Likes