Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® FBX® / FBX SDK / Getting the local transformation matrix for the vertices of a cluster?
  RSS 2.0 ATOM  

Getting the local transformation matrix for the vertices of a cluster?
Rate this thread
 
52723
 
Permlink of this thread  
avatar
  • CarstenF
  • Posted: 26 February 2011 12:07 AM
  • Total Posts: 8
  • Joined: 26 February 2011 07:16 AM

Hi all,

my name is Carsten Fuchs and I’m the main author of the Cafu game and graphics engine, an open-source 3D game engine for Windows and Linux with full networking support.

I’m currently working on a Model Editor for Cafu, so that we can import FBX files, then make engine specific settings and adjustments, and finally use the models in our map editors and the games.

I found loading the FBX nodes hierarchy quite easy, including loading the animation data from anim stacks, but I’m having problems with skin deformers and their clusters.

Please consider this chain of objects:

Node  // with an attribute of type eMESH
    
Mesh
        SkinDeformer
            Cluster
                LinkNode    
// (normally) some node of attribute type eSKELETON

The question is:
How can I find the coordinate of the control points affected by “Cluster” in the local space of “LinkNode”?

I studied the reference documentation for all related classes, but the texts are somewhat confusing. For example, from the description of KFbxCluster:

Transform refers to the global initial position of the node containing the link.

What is “initial” position?
What is the node containing the link? With the above example objects (regarding “LinkNode"), is it “Node”, or the parent of “LinkNode”?
etc.
(More similar questions with the other matrices of a cluster...)

For rendering (which cannot use and is independent of the FBX SDK), the implementation outline is to first compute the matrices of the skeleton nodes for the current point in time of the animation sequence, then use the above computed local coordinates to obtain the global coordinates by traversing “up” the hierarchy, doing the appropriate matrix multiplications, and finally doing the appropriate weighted sums.

In fact, the rendering part works already, all that I’m still missing is how I get the local coordinates in “LinkNode” space.

I’d be very grateful for your help!



Best regards,
Carsten

http://www.cafu.de

Replies: 0
avatar

Hello Carsten, we are really glad that FBX can be a part of Cafu engine :).
Sorry for the unclear document, we improved it recently and hope it can explain more.
The “initial position” means the transform at the binding moments, for the geometry or for the bones(links).
“The node containing the link” means the geometry that is bound with the bones, so it is the “Node” in your example.

So, given a mesh binding with several bones(links), Transform is the global transform of the mesh at the binding moment, TransformLink is the global transform of the bone(link) at the binding moment.

In FBX, to get the local coordinates in “LinkNode” space you need to do two steps:
1. Control points are stored as in the mesh’s object space. First move them from object space to world space.
Note: For all clusters related to one mesh, their Transform matrix is actually the same, because there is actually only one mesh.

int lVertexCount lMesh->GetControlPointsCount();
        
KFbxVector4lVertexArray = new KFbxVector4[lVertexCount];
        
memcpy(lVertexArraylMesh->GetControlPoints(), lVertexCount sizeof(KFbxVector4));

 for(
int i 0i<lVertexCount; ++i)
 
{
 KFbxVector4 lSrcVertex 
lVertexArray[i];
 
KFbxVector4lDstVertex lVertexArray[i];

 
KFbxXMatrix lMeshGlobal;

 
KFbxClusterlCluster =lSkin->GetCluster(0);
 
lCluster->GetTransformMatrix(lMeshGlobal);
 
KFbxXMatrix lMeshGeometry GetGeometry(pMesh->GetNode());
 
lMeshGlobal *= lMeshGeometry;

 
lDstVertex lMeshGlobal.MultT(lSrcVertex);
 
}

2. Transform control points from World Space to the Bone’s space at binding moment.

KFbxXMatrix lBoneBindingMatrix;
lCluster->GetTransformLinkMatrix(lBoneBindingMatrix);
lBoneBindingMatrix.Inverse() * lDstVertex;


Jiayang Xu
Maya Data Platform
Autodesk

Replies: 0
avatar
  • CarstenF
  • Posted: 01 March 2011 11:27 AM

Dear Jiayang Xu,

thank you very much for your reply, it was very helpful: exactly the information I was looking for!  (It would be wonderful if you included this kind of information in future editions of the documentation, because when you’re new to the FKX SDK, there are so many classes, terms, concepts, etc. that it’s easy to lose track of what is what. A few graphical sketches that help with forming clear mental images of the main concepts would be helpful, too.)

But back to topic: I got it working just as described, though I did some changes like factoring the matrix computations out of the loop in step 1., etc.

Some detail questions though [please confirm or correct ;-)]:

a) Function GetGeometry() is the one from the ViewScene example (file GetPosition.cxx)?

b) The multiplication in last line of step 2

lBoneBindingMatrix.Inverse() * lDstVertex;

should instead of operator * use method MultT()?

lBoneBindingMatrix.Inverse().MultT(lDstVertex);

c) Why is method GetTransformMatrix() a member of KFbxCluster?  (I would have expected it to be a member of e.g. the skin deformer class.)

d) Unrelated:
Why does signature of method

KFbxAnimEvaluator::GetNodeLocalTransform (KFbxNode *pNode, ...)

not use const KFbxNode *pNode for the first parameter?



Best regards,
Carsten

http://www.cafu.de

Replies: 1
/userdata/avatar/vx3501hqr_small.jpg

a) Yes. GetGeometry() is the one from the ViewScene example (file GetPosition.cxx).
b) Yes. It should be method MultT(). I just put lBoneBindingMatrix.Inverse() * lDstVertex as pseudo code, but I should made it clear, sorry.
c) It is a legacy issue. I am not sure why it is designed like this and I also would like to refactor and move it to skin deformer class because it is redundant in every clusters now. But the priority of this is not very high.
d) Yes, you are right, it should be const, I will log that.

Thanks for the reply and it is really a nice experience to answer your questions because you made them very clear.

Author: Jiayang Xu

Replied: 01 March 2011 02:44 PM  
avatar

I love the style~~Hope author will get more attention~~
wholesale girls dresses



Replies: 0