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 / Code to obtain node's local position matrix
  RSS 2.0 ATOM  

Code to obtain node's local position matrix
Rate this thread
 
24453
 
Permlink of this thread  
avatar
  • Total Posts: 585
  • Joined: 18 February 2008 07:25 PM

Attached is the code to calculate the node’s postition matrix.  The two calls of interest are:

GetLocalPositionFromTake - Computes the node position at a specific time in a given take
GetDefaultLocalPosition - Computes the node’s default position (set bUseDefaultPosition to true)

KFbxXMatrix GetLocalPositionFromTake(KFbxNodepNodeKFbxTakeNodelCurrentTakeNodeKTimepTime);
KFbxXMatrix GetDefaultLocalPosition(KFbxNodepNodebool bUseDefaultPosition);


Attachment Attachment
Replies: 1
/img/forum/dark/default_avatar.png

Big thank you!
You saved a lot of my time.

Author: Brzeg

Replied: 24 June 2009 09:02 AM  
avatar

I’ve been trying to get the local matrix for a while as well, and I ended up solving it by multiplying the parent node global matrix inverse by the child node’s global matrix.



Replies: 0
avatar

clevijoki 23 March 2009 02:55 PM

I’ve been trying to get the local matrix for a while as well, and I ended up solving it by multiplying the parent node global matrix inverse by the child node’s global matrix.

That is a great solution.  Unfortuntely, this is far slower than the code I posted. The humanoid models takes several times longer to load.
There really should be a function that returns this. But this works and should be always correct.

// Get the local position from the default take node.
KFbxXMatrix GetDefaultLocalPosition(KFbxNodepNode)
{

  KFbxNode
pParent pNode->GetParent();

  
KFbxXMatrix lLocalPosition;


  if (
pParent)
  
{
      KFbxXMatrix lParentGlobalPosition 
pParent->GetGlobalFromDefaultTake();
      
KFbxXMatrix lGlobalPosition pNode->GetGlobalFromDefaultTake();
      
lLocalPosition lParentGlobalPosition.Inverse() * lGlobalPosition;
  
}
  
else
  
{
      lLocalPosition 
pNode->GetGlobalFromDefaultTake();
    
  
}
  
return lLocalPosition;
}

// Get the local position from the current take node.
// Need to set current take
KFbxXMatrix GetLocalPositionFromCurrentTake(KFbxNodepNodeKTimepTime)
{
  KFbxNode
pParent pNode->GetParent();

  
KFbxXMatrix lLocalPosition;


  if (
pParent)
  
{
      KFbxXMatrix lParentGlobalPosition 
pParent->GetGlobalFromCurrentTake(pTime);
      
KFbxXMatrix lGlobalPosition pNode->GetGlobalFromCurrentTake(pTime);
      
lLocalPosition lParentGlobalPosition.Inverse() * lGlobalPosition;
  
}
  
else
  
{
      lLocalPosition 
pNode->GetGlobalFromCurrentTake(pTime);
    
  
}
  
return lLocalPosition;
}


Replies: 0
avatar

hi there,

i am writing my first importer using fbx sdk and i am still a bit confused about a couple of issues.

After struggling a bit around transformations matrices, i came across this post,
and it solved a lot of problems. I have implemented a couple of functions,
following the example of

KFbxXMatrix GetLocalPositionFromTake(KFbxNodepNodeKFbxTakeNodelCurrentTakeNodeKTimepTime)
KFbxXMatrix GetDefaultLocalPosition(KFbxNode
pNodebool bUseDefaultPosition)

Whenever i convert a static scene, or an animated scene where the animations are attached directly to the geometries, the code works like a charm.

Eventually i tried an fbx exported from 3dmax. It’s a model that uses helpers to translate/rotate different geometries. The scene has it’s own hierarchy, something like:

mainHelper (translation, rotation)
|
|- groupHelper01 (translation, rotation)
| |
| |- geo01 (small translation)
| |- geo02
|
|- groupHelper02
| |

Now, with this file I can’t retrieve any correct transformation. My best guess is that i am missing something important about transformation combination. When i call
GetLocalPositionFromTake do i retrieve the tranformation matrix relative to the node parent? Or i retrieve the global tranform (and so, if i push all the transformations toghether i end up appling multiple times the same transformations).

Thanks for any help

edited:
solved it was just a trivial quaternion conversion problem. My fault....



Replies: 0