MMatrix python API problem

73 views
Skip to first unread message

Dilen Shah

unread,
Sep 3, 2014, 3:59:42 AM9/3/14
to python_in...@googlegroups.com
Hey guys,

I have 2 nodes in my scene.

I am using MMessage and creating a callback function, this function needs to take the worldmatrix of both nodes and apply one matrix to another so that the second node is the same exact position as the first node.

Can anyone explain how i can achieve it as they have groups as their parents so multiply the parentworldmatrix and their worldmatrix would be necessary can anyone help me with the math, or any link to resources would be appreciated.

Thanks in advance.

Dilen.

Marcus Ottosson

unread,
Sep 3, 2014, 4:22:37 AM9/3/14
to python_in...@googlegroups.com

Hi Dilen,

There is the “multMatrix” node which may help, it should be able to do what you’re looking for and output a new matrix for you. I’m using it in much the same way, its also helpful when cancelling one matrix with another.

cmds.createNode('multMatrix')


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/db8272fd-d1a2-4656-be91-f073a32ca35e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Dilen Shah

unread,
Sep 3, 2014, 5:56:58 AM9/3/14
to python_in...@googlegroups.com
well thats one way of doing it, but I am using python API and I want functionality like if i move node 1 node 2 should move in realtime with it.

Any ideas for that?

thanks

D.


On Wednesday, September 3, 2014 10:22:37 AM UTC+2, Marcus Ottosson wrote:

Hi Dilen,

There is the “multMatrix” node which may help, it should be able to do what you’re looking for and output a new matrix for you. I’m using it in much the same way, its also helpful when cancelling one matrix with another.

cmds.createNode('multMatrix')
On 3 September 2014 09:59, Dilen Shah <dilen...@gmail.com> wrote:
Hey guys,

I have 2 nodes in my scene.

I am using MMessage and creating a callback function, this function needs to take the worldmatrix of both nodes and apply one matrix to another so that the second node is the same exact position as the first node.

Can anyone explain how i can achieve it as they have groups as their parents so multiply the parentworldmatrix and their worldmatrix would be necessary can anyone help me with the math, or any link to resources would be appreciated.

Thanks in advance.

Dilen.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Sep 3, 2014, 6:02:08 AM9/3/14
to python_in...@googlegroups.com
That's precisely where you would use nodes instead of scripting. :) 

The node will update in real-time, like any other node. I'm using it in most of my rigs for just that purpose.


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ee6bebf4-80ae-46b5-9299-440d1cf83c1c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Sep 3, 2014, 6:15:15 AM9/3/14
to python_in...@googlegroups.com
If you can narrow down an example of what you're trying to accomplish, I might be able to provide an example for you.
--
Marcus Ottosson
konstr...@gmail.com

Eduardo Grana

unread,
Sep 3, 2014, 9:51:11 AM9/3/14
to python_in...@googlegroups.com
Hello Dilen,

Not sure if I'm getting this right, but it seems like you
are looking for the maths similar to a parentConstraint.
Am I right?
Maybe with that, and Marcus's suggestion you can get it done
without doing any maths your self.
Otherwise, you'll have to concatenate the inverse matrix of one and
the inlusive matrix of the other to make the trick.
Hope this makes sense, 
Cheers!
Eduardo



For more options, visit https://groups.google.com/d/optout.



--
Eduardo Graña
www.eduardograna.com.ar

Dilen Shah

unread,
Sep 3, 2014, 9:53:12 AM9/3/14
to python_in...@googlegroups.com
Hey,

Well the situation is that, I have an adapt rig and skinning in the file, at the moment wen i change the adpt rig the skinning rig moves with it and thus they are the moment having direct connection but I want to change it to MMessage thus when I move the adapt rig the node i am writing will calculate the world matrix and position rotation information and apply to skinning rig without any connections.

If you done understand lemme know i can elaborate.

Dilen.

On Wednesday, September 3, 2014 12:15:15 PM UTC+2, Marcus Ottosson wrote:
If you can narrow down an example of what you're trying to accomplish, I might be able to provide an example for you.
On 3 September 2014 12:02, Marcus Ottosson <konstr...@gmail.com> wrote:
That's precisely where you would use nodes instead of scripting. :) 

The node will update in real-time, like any other node. I'm using it in most of my rigs for just that purpose.
On 3 September 2014 11:56, Dilen Shah <dilen...@gmail.com> wrote:
well thats one way of doing it, but I am using python API and I want functionality like if i move node 1 node 2 should move in realtime with it.

Any ideas for that?

thanks

D.


On Wednesday, September 3, 2014 10:22:37 AM UTC+2, Marcus Ottosson wrote:

Hi Dilen,

There is the “multMatrix” node which may help, it should be able to do what you’re looking for and output a new matrix for you. I’m using it in much the same way, its also helpful when cancelling one matrix with another.

cmds.createNode('multMatrix')
On 3 September 2014 09:59, Dilen Shah <dilen...@gmail.com> wrote:
Hey guys,

I have 2 nodes in my scene.

I am using MMessage and creating a callback function, this function needs to take the worldmatrix of both nodes and apply one matrix to another so that the second node is the same exact position as the first node.

Can anyone explain how i can achieve it as they have groups as their parents so multiply the parentworldmatrix and their worldmatrix would be necessary can anyone help me with the math, or any link to resources would be appreciated.

Thanks in advance.

Dilen.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com




--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Sep 3, 2014, 9:57:49 AM9/3/14
to python_in...@googlegroups.com

Well the situation is that, I have an adapt rig..

Could you elaborate a little on what an “adapt rig” is? What is the relation between the adapt rig and the skinned character? Do you mean a guide rig of sorts?

It might be easier if you can distil your issue into a minimal scene with a cube and some joints.



To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1088e1cf-a781-4729-b060-f197b56f78fd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Dilen Shah

unread,
Sep 3, 2014, 10:56:16 AM9/3/14
to python_in...@googlegroups.com
Hey,

Well its a autoRig thing, wer i place all the adapt rig before and then build the rig but the adapt rig is not deleted until i delete it manually, so if i move the adapt rig now like for example the shoulder, the skeleton also moves and changes its position to the adapt shoulder. Thus helping me change pivots easily without recreating the skeleton. So these joints are directly connected from adapt to the skeleton and thats why I need to do the calculation and match them.

I am at work so making the scene might take some time. But will post wen i can.

Thanks

Dilen.



--
Marcus Ottosson
konstr...@gmail.com




--
Marcus Ottosson
konstr...@gmail.com

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Sep 3, 2014, 11:34:08 AM9/3/14
to python_in...@googlegroups.com

Thanks for that.

If I understand you correctly, you’re looking to change the pivot of controls that have already been connected to a skeleton. If so, then it might be the case of having painting oneself into a corner. If we take a step back and look at what is actually in control of the pivot, the controllers themselves, there might be an easier way.

I’m attaching a scene with four objects; a skeleton, two controllers and a driving locator.

The locator is ultimately controlling the skeleton and it is parented under a controller. The other controller has a slightly different pivot.

Try this:

  1. Move the “clavicle_CTL” around, see that it moves the skeleton, and note its pivot and orientation
  2. Reparent the “driver_LOC” onto “new_CTL”. The new controller has a different pivot and orientation, but the skeleton doesn’t move.
  3. Move the “new_CTL”, see that the skeleton does move and respect the new pivot and orientation
  4. Remove “clavicle_CTL”, rename “new_CTL” to “clavicle_CTL” and you’re done.

When you publish the rig once more, the control will appear to have changed its pivot from one place to another, along with having gotten a new orientation, without having moved the skeleton. Animation will be preserved too, unless the change was so great it invalidated previous animation.

If this isn’t what you were after, then could you perhaps try and provide a step-by-step of what you expect to have happen once you’ve found a solution? E.g.

  1. Setup a callback between the adapt source and skeleton target
  2. Moving the adapt source doesn’t move the skeleton
  3. ?
  4. Profit!

Best,
Marcus

moving_pivot.ma

Dilen Shah

unread,
Sep 3, 2014, 11:39:22 AM9/3/14
to python_in...@googlegroups.com
This is awesome, and you got it right, now I am working on a callback function but I am stuck in a part.

well the eventCallback i am using "selectionChanged", is there any event where I can sue which call callback when I change the position or rotation? similar to the compute function if plug == "something" changes and thus process is done.

Is there anything like that in callback that I can use for realtime?

Thank you.

D.

Marcus Ottosson

unread,
Sep 4, 2014, 4:13:51 AM9/4/14
to python_in...@googlegroups.com
I'm not so sure we're getting through to each other. :) If you could produce a minimal example scene of your issue, I might be able to help you more.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a785b736-3209-4be6-8033-179f64d1ea79%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Dilen Shah

unread,
Sep 4, 2014, 4:34:34 AM9/4/14
to python_in...@googlegroups.com
Hey,

Found the solution, i got the matrix calculations now and also in MEventMessage i was looking for "dragRelease" option. So got it.

Thank you for all ur help!

D.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Sep 4, 2014, 4:47:21 AM9/4/14
to python_in...@googlegroups.com
I'm glad you got it! If you could share your findings, I'd very much like to have a look at it!


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/325c5081-636e-4bed-85b4-c55a62298f30%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages