FBX SDK中的三种坐标转换矩阵

环境:
        Windows7 64bit
        VS2012
        FBX SDK 2015.1 VS 2012

FBX SDK 2015.1 VS 2012下载地址:
       CSDN下载地址:https://download.csdn.net/download/u012633319/10543087
       官网下载地址:   https://www.autodesk.com/developer-network/platform-technologies/fbx-sdk-2015

注:

Fbx中的矩阵为列主序

一、Fbx中每个node有3个转换矩阵,分别为:

1、GlobalTransform

全局变换矩阵:节点坐标系的坐标转换到世界坐标系的变换矩阵。

2、LocalTransform

本地变换矩阵:节点坐标系的坐标转换到父节点坐标系的变换矩阵。

3、GeometricTransform

物理变换矩阵:节点的几何数据相对于节点自身的坐标系的一个转换,可以看做节点中的Geometry坐标系到节点坐标系的变换矩阵。

在属性为mesh的节点中controlPoints的坐标就是geometry坐标系下的坐标,因此转换到世界坐标系需要先转换到节点坐标系再转换到世界坐标系。

在OpenGL中绘制,可以如下顺序调用:

// 伪代码,不保证参数类型的正确性
FbxMatrix globalMatrix = globalTransfrom * geometricTransform;
glPushMatrix();
glMultMatrixd(globalMatrix);
// 绘制内容
glPopMatrix();

以上伪代码调用顺序,同Fbx SDK自带示例程序中的ViewScene一致。

(二)3中类型矩阵的获取

FbxNode* pNode; //假设已赋值

FbxTime  time;  // 假设已赋值

1、GlobalTransform和LocalTransform的获取(和当前FbxAnimStack有关)

第一种方式:

FbxAnimEvaluator* pAnimEvaluator  = pNode->GetScene()->GetAnimationEvaluator();  
// GlobalTransform矩阵  
FbxAMatrix*       globalTransform = pAnimEvaluator->GetNodeGlobalTransform(pNode, time);  
// LocalTransform矩阵  
FbxAMatrix*       localTransform  = pAnimEvaluator->GetNodeLocalTransform(pNode, time);  

第二种方式:

// GlobalTransform矩阵
FbxAMatrix* globalTransform = pNode->EvaluateGlobalTransform(time);
// LocalTransform矩阵
FbxAMatrix* localTransform  = pNode->EvaluateLocalTransform(time);

注:

第二种方式本质上是对第一种方式的封装调用。

在存在动画信息的Fbx文件中,通过

pNode->GetScene()->GetAnimationEvaluator()获得的FbxAnimEvaluator*是和场景当前的FbxAnimStack关联的,

(1)仅一个FbxAnimStack或没有动画信息时,无影响;

(2)多个FbxAnimStack时,首先设置好当前需要的FbxAnimStack才能得到对应当前FbxAnimStack的变换矩阵。

在存在蒙皮变形信息的Fbx文件中,FbxCluster的Link,即骨骼,也为FbxNode类型,正是通过改变动画栈获取对应骨骼的变换矩阵。

FbxAnimStack的设置方式

// 获取索引 i 对应的FbxAnimStack
FbxAnimStack* pAnimStack = pFbxScene->GetSrcObject<FbxAnimStack>(i);
// 设置当前使用的FbxAnimStack
pFbxScene->SetCurrentAnimationStack(pAnimStack);

2、GeometricTransform的获取

GeometricTransform的获取较简单,如下:

// Fbx SDK示例程序ViewScene中源代码  
FbxAMatrix GetGeometry(FbxNode* pNode)  
{  
    const FbxVector4 lT = pNode->GetGeometricTranslation(FbxNode::eSourcePivot);  
    const FbxVector4 lR = pNode->GetGeometricRotation(FbxNode::eSourcePivot);  
    const FbxVector4 lS = pNode->GetGeometricScaling(FbxNode::eSourcePivot);  
  
    return FbxAMatrix(lT, lR, lS); // 返回GeometricTransform  
}  

猜你喜欢

转载自blog.csdn.net/u012633319/article/details/80927861