LM: Skeletons, bones and matrices.

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
anigreator
Posts: 36
Joined: Tue Mar 22, 2005 11:47 am

LM: Skeletons, bones and matrices.

Post by anigreator »

Hello LM,

I've been developing a script to 'bake' the scale of a Moho character. I'm doing this because my artists provide tracing images at different scales, and when various characters are imported onto their backgrounds, their line thicknesses are different due to scale compensation. I do, however, need scale compensation hence the baking script.

Whilst the section of the script that deals with vector layers is working fine (via GetFullTransform()), I am a little lost with regards to how Moho deals with co-ordinate spaces within bone layers. The results of my experiments have been whacky to say the least :lol: .

It would be great if you could provide us with a 'Bones 101', or something along those lines.

Cheers!

Chris
anigreator
Posts: 36
Joined: Tue Mar 22, 2005 11:47 am

Post by anigreator »

To put things more specifically:

I'm trying to apply the GetFullTransform matrix to each individual bone in a bone layer without affecting the points that the bone is bound to. So far, I've been able to correctly translate the fAnimPos and fLength of the parent bone, which drags all of the child bones along with it.

Is there an easy way of moving a parent bone without moving the child bones?

I've tried mutliplying the fRestMatrix of various bones by the GetFullTransform matrix, but nothing seems to happen, even after calling UpdateBoneMatrix on the affected bones. What am I doing wrong? Do I still need to manually calculate a fPos etc etc for the child bones ie, they do not automatically respond to a new fRestMatrix?

What do fTempPos etc really do? Are they simply temp storage or do they interact in some hidden fashion?

Con you provide a step-by-step account of how to calculate a bone's position, including the relationship between the various co-ordinate spaces?

I'll probably bombard you with some more questions, but some simple pointers would be appreciated.

Cheers,

Chris
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

I'm going to have to come back to these questions later today, but for now I may have a quicker solution to your problem.

Instead of rearranging bones and all that complex work, what if you just made a script that could scale a layer down (the bone layer), and then automatically adjust the line thickness of all shapes in the vector layers beneath it?
anigreator
Posts: 36
Joined: Tue Mar 22, 2005 11:47 am

Post by anigreator »

A very good point, and I might just do that too! However, I've started building complex 3D scences using 2D layers that are positioned and rotated according to the scene's requirements. When it comes to the positioning or tweaking of these layers it is very convenient to have a consistent co-ordinate and scaling system across the various layers.

Hope that makes sense!

Cheers,

Chris
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

Yeah, that makes sense. I just thought I throw that out there as a possible (easier) solution. Let's see...

No, there isn't a particularly easy way of moving a parent bone without moving the children. A bone's setup (base point and angle) is relative to its parent's coordinate system. So, when you move a parent bone, the children don't have to be modified at all if they are to follow along with the parent.

The way to move the parent without moving the children would be to transform the children's position into world coordinates (using the inverse of the parent's fRestMatrix), move the parent, and then transform the children bones from world coordinates back to the parent's coordinates using the new fRestMatrix.

So yes, you would need to compute a new fPos for the children. They do respond automatically to a new fRestMatrix, but in the opposite way you're trying to go - the children respond in such a way to move with the parent, not to be independent from it. What you're trying to do is kind of moving the hieracrhy backwards, so you have to do more manual labor.

Variables like fTempPos are just temporary storage. In this case you could use it to temporarily store the children bones' positions in world coordinates before transofrming them back to the parent's new coordinate system.

I hope that helps somewhat.
Post Reply