How to collect bone transformations on points?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

How to collect bone transformations on points?

Post by Breinmeester »

Hello,

In a layer script i need to set the fPos on a number of points in the layer, but i need to take in account the transformations on those points that have been made bij bone deformations and smartbone actions, ideally seperately. Does anybody know if there's a matrix or how to retrieve a vector of the difference between a point's fAnimPos and the fPos that includes all the bone transformations?
I've found the fPtMatrx, but this is a Bone property and i wouldn't know how to use this to calculate the actual influence in translation a bone has over a point. Can anyone help?
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: How to collect bone transformations on points?

Post by heyvern »

The points position or fPos on a frame would include all transformations including bones smart bones etc. If you want to "add" to that position you could but watch out, as this could get pretty crazy! If you move a point based on the position on a frame, then the script would keep running and keep moving the point as the position changes over and over and over and basically "fly off the screen". The script would be accessing the current frame fPos. Once it's changed the old value is gone and the new value is used in the same script calculation. You would need to store the original position of that frame before you change it. I have always had a ton of trouble trying to script point motion like this because of all the things that move points and the potential for that cumulative position change.

In my humble opinion, if you need to move points with a script, it might be easier to bind those points to a bone or bones and script the bone movement. Scripting bones is "easier" in many ways. Points can be influenced by one or many bones. A bone isn't (unless using constraints or physics but you can simply avoid that). Bones can be rotated easily. Points can't be rotated the same way. You would have to create your own function to determine a specific origin to rotate a point.

Another issue is that generally there are many more points than bones, and points don't have "names". Finding the exact point you want to move with a script can be VERY tricky because you can't select a point and see what it is or where it is in the point list. Imagine you had a script to move a specific point isolated by counting and targeting a point ID number. If the vectors were changed, points added, deleted, new shapes drawn, then the script wouldn't work as expected since the point ID's change. You could make point groups for every single point but that would be a ton of work and also point groups can get lost when editing a vector layer. Trying to move an exact point on a vector layer is very difficult because you can't get any information about that point from the document.

Bones on the other hand can be named and targeted easily in a script. You can see exactly what bone you want to control based on the name. The bone name doesn't "get lost" when copying and pasting like point groups. You can add or delete bones in the bone layer and it has no effect on named bones. So, even if you had several points each bound to it's own named bone, the scripting to move it would be easier.

A long time ago I worked with a forum member on a cool "3d" script that automatically created one bone for every point. It seemed like a lot of bones but in reality this was probably the only way to move and control the points and rotate the vectors in 3d.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Re: How to collect bone transformations on points?

Post by Genete »

but i need to take in account the transformations on those points that have been made bij bone deformations and smartbone actions
I don't know if there is script interface of smartbones influence over points. But for classical bone influence you can do this:

1) Take the Point's parent ID: fParent. If it is -2 then it is flexi bound to all bones in bone layer. -1 means not bound and any other number means the bone's ID.
2) Based on the above calculate the compound matrix influence by doing this:
a) For each bone that has influence on the point, extract the fPtMatrix and the strength.
b) Calculate the weighted average matrix result of multiply each matrix by the strength of each bone and divide it by the sum of the strengths.

That result matrix multiplied by the current animated point position would give you the bone influence part.

I hope it still like that now, but IIRC it was like that in the past.
-G
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Re: How to collect bone transformations on points?

Post by Breinmeester »

Thanks, Genete. That sounds very complex and specific to only the bone distortion effect on a point. I take it smartbone influence isnt stored in the fPtMatrix, which would mean it's out of our reach.

Do you have an example script you did these calculations for? I expect many scripters must have encountered this problem. Thanks again! 8)
Post Reply