引用SDK上的一段代码.

  捣鼓了快一个月FBX SDK.终于看到些适合我的东西了...在SDK上找到了一段代码,比较入门.简单改一下风格,就是我的作品了...接下来循序渐进地学习吧.直接这么copy代码是不是有点不好?也没什么,反正也没什么,....

// UseFBXSDK.cpp -- 2014/01/15-21:36
#include "stdafx.h"
#include <fbxsdk.h>

int numTabs = 0; 

void PrintTabs()
{
    for(int i = 0; i < numTabs; i++)
        printf("\t");
}

FbxString GetAttributeTypeName(FbxNodeAttribute::EType type)
{ 
    switch(type)
	{ 
        case FbxNodeAttribute::eUnknown: return "unidentified"; 
        case FbxNodeAttribute::eNull: return "null"; 
        case FbxNodeAttribute::eMarker: return "marker"; 
        case FbxNodeAttribute::eSkeleton: return "skeleton"; 
        case FbxNodeAttribute::eMesh: return "mesh"; 
        case FbxNodeAttribute::eNurbs: return "nurbs"; 
        case FbxNodeAttribute::ePatch: return "patch"; 
        case FbxNodeAttribute::eCamera: return "camera"; 
        case FbxNodeAttribute::eCameraStereo: return "stereo"; 
        case FbxNodeAttribute::eCameraSwitcher: return "camera switcher"; 
        case FbxNodeAttribute::eLight: return "light"; 
        case FbxNodeAttribute::eOpticalReference: return "optical reference"; 
        case FbxNodeAttribute::eOpticalMarker: return "marker"; 
        case FbxNodeAttribute::eNurbsCurve: return "nurbs curve"; 
        case FbxNodeAttribute::eTrimNurbsSurface: return "trim nurbs surface"; 
        case FbxNodeAttribute::eBoundary: return "boundary"; 
        case FbxNodeAttribute::eNurbsSurface: return "nurbs surface"; 
        case FbxNodeAttribute::eShape: return "shape"; 
        case FbxNodeAttribute::eLODGroup: return "lodgroup"; 
        case FbxNodeAttribute::eSubDiv: return "subdiv"; 
        default: return "unknown"; 
    } 
}

void PrintAttribute(FbxNodeAttribute* pAttribute)
{
    if(pAttribute == nullptr)
		return;
 
    FbxString typeName = GetAttributeTypeName(pAttribute->GetAttributeType());
    FbxString attrName = pAttribute->GetName();

    PrintTabs();

    printf("<attribute type='%s' name='%s'/>\n", typeName.Buffer(), attrName.Buffer());
}

void PrintNode(FbxNode* pNode)
{
    PrintTabs();
    const char* nodeName = pNode->GetName();
    FbxDouble3 translation = pNode->LclTranslation.Get(); 
    FbxDouble3 rotation = pNode->LclRotation.Get(); 
    FbxDouble3 scaling = pNode->LclScaling.Get();

    printf("<node name='%s' translation='(%f, %f, %f)' rotation='(%f, %f, %f)' scaling='(%f, %f, %f)'>\n", 
        nodeName, 
        translation[0], translation[1], translation[2],
        rotation[0], rotation[1], rotation[2],
        scaling[0], scaling[1], scaling[2]
        );

    numTabs++;

    for(int i = 0; i < pNode->GetNodeAttributeCount(); i++)
        PrintAttribute(pNode->GetNodeAttributeByIndex(i));

    for(int j = 0; j < pNode->GetChildCount(); j++)
        PrintNode(pNode->GetChild(j));

    numTabs--;
    PrintTabs();
    printf("</node>\n");
}

int main(int argc, char** argv) {

    const char* pFilename = "humanoid.fbx";
    
    FbxManager* pSdkManager = FbxManager::Create();
    
    FbxIOSettings *pIOSettings = FbxIOSettings::Create(pSdkManager, IOSROOT);
    pSdkManager->SetIOSettings(pIOSettings);

    FbxImporter* lImporter = FbxImporter::Create(pSdkManager,"");
    
    if(lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings()) == nullptr)
	{ 
        printf("Call to FbxImporter::Initialize() failed.\n"); 
        printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString());

		getchar() ;
 
        exit(-1); 
    }
    
    FbxScene* pScene = FbxScene::Create(pSdkManager,"myScene");

    lImporter->Import(pScene);

    lImporter->Destroy();
    
    FbxNode* pRootNode = pScene->GetRootNode();

    if(pRootNode != NULL)
	{
        for(int i = 0; i < pRootNode->GetChildCount(); i++)
            PrintNode(pRootNode->GetChild(i));
    }

	pSdkManager->Destroy();

	getchar() ;

    return 0;
}


你可能感兴趣的:(引用SDK上的一段代码.)