Scripting with the offset parent matrix

Scripting with the offset parent matrix

gngD3UXP
Explorer Explorer
2,817 Views
2 Replies
Message 1 of 3

Scripting with the offset parent matrix

gngD3UXP
Explorer
Explorer

Hello I am trying to run a script that orients an animation on a bone to a particular axis. I m just applying a -90 on the rotationZ on the composure offset matrix.  My preferences have a Z up world orientation, just an FYI.

 

Here is an example:

Screenshot 2023-01-05 094048.png

And I am applying the -90 here:

Screenshot 2023-01-05 094351.png

Now the offset is in the correct orientation. 

 

And then looking at the MEL script, maya doesn't output the rotation Z values. So I am wondering if a matrix needs to be created and how that would look like for a simple move on Z orientation. 

 

Screenshot 2023-01-05 095002.png

 

I have something in python that I am trying to work out, which is this:

import maya.cmds as mc


mc.xform(s, t= (0,0,0), ro = (0,0,-90), s= (1,1,1), os = True)
mc.setAttr("root.offsetParentMatrix" type = "matrix")

Not sure if this is in the right direction though. Wondering what would be the best approach. 

 

Thanks!

Accepted solutions (1)
2,818 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

You have to create a matrix.

 

matrices in maya code look like this:

 

ThisIsADefaultMatrix = [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]

 

So basically all 16 numbers of the matrix are in a single list.

So if you have the matrix that just turns a object 90 degrees in Z. Which you can easily look up by putting the value into the Composition Tab of a parent offset matrix on a new object and then switching to the matrix tab to look how the matrix actually looks like.You can set your parent offset Matrix like this:

 

ThisIsYourMatrix = [1,0,0,0,-1,0,0,0,0,0,1,0,0,0,0,1]
mc.setAttr("root.offsetParentMatrix",*ThisIsYourMatrix, type = "matrix")

 

 

Now, this works only if the parentOffsetMatrix is zeroed out. If it isn't, you would have to work out how to add the matrix to the existing OPM. But that goes into pretty advanced Math territory and it isn't one of the standard matrix calculations that you do often so I'm not quite sure how to do it right now.

 

I hope it helps!

Message 3 of 3

gngD3UXP
Explorer
Explorer

Thank you for helping out! This worked! I had to apply Matrix = [0,-1,0,0,1,0,0,0,0,0,1,0,0,0,0,1] for the offset to work. 

 

Much appreciated!

0 Likes