Autodesk FBX SDK Program 中文 (一)

來源:互聯網
上載者:User

標籤:opengl   autodesk   fbx   

這是我的FBX SDK學習筆記,如文有錯誤,麻煩各位大大指出


為什麼要使用FBX SDK?

因為3D建模軟體都被AutoDesk收購了,FBX可以在各個建模軟體之間互相匯入匯出,在很多遊戲引擎中也用FBX來直接匯入然後編輯。


學會使用FBX SDK後該幹什嗎?

用FBX SDK解析出在fbx檔案中儲存的頂點、骨骼、貼圖、燈光、法線等資訊後,儲存為自己的模型格式或者直接渲染出來。嗯,對。FBX是作為中介軟體存在,不會直接用在遊戲中。


Autodesk FBX SDK Program 中文 (一)

要直接貼代碼了。代碼中會有一些中文的解釋。出自有道翻譯……

首先看看環境配置,一個普通的空工程。

添加標頭檔路徑:



添加連結檔案目錄:



添加連結檔案:

阿嘞,沒有連結檔案。我們在代碼裡面把lib加進來就好了。


複製dll檔案到debug目錄:



還缺一個 fbx檔案……,從網上下一個吧,放到工程目錄(看各人設定吧,VS預設是這裡)


好了萬事具備,貼代碼!

#include<fbxsdk.h>#pragma comment(lib,"libfbxsdk.lib")int numTabs=0;void PrintTabs()  //列印tabs,造出像xml那樣的效果{for (int i = 0; i < numTabs; i++){printf("\t");}}/***根據節點屬性的不同,返回字串。就是返回節點屬性的名字**/FbxString GetAttributeTypeName(FbxNodeAttribute::EType type){switch (type){case FbxNodeAttribute::eUnknown: return "UnknownAttribute";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"; //Patch面片case FbxNodeAttribute::eCamera: return "Camera"; //攝像機case FbxNodeAttribute::eCameraStereo: return "CameraStereo"; //立體case FbxNodeAttribute::eCameraSwitcher: return "CameraSwitcher"; //切換器case FbxNodeAttribute::eLight: return "Light"; //燈光case FbxNodeAttribute::eOpticalReference: return "OpticalReference"; //光學基準case FbxNodeAttribute::eOpticalMarker: return "OpticalMarker";case FbxNodeAttribute::eNurbsCurve: return "Nurbs Curve";//NURBS曲線case FbxNodeAttribute::eTrimNurbsSurface: return "Trim Nurbs Surface"; //曲面剪下?case FbxNodeAttribute::eBoundary: return "Boundary"; //邊界case FbxNodeAttribute::eNurbsSurface: return "Nurbs Surface"; //Nurbs曲面case FbxNodeAttribute::eShape: return "Shape"; //形狀case FbxNodeAttribute::eLODGroup: return "LODGroup"; //case FbxNodeAttribute::eSubDiv: return "SubDiv";default: return "UnknownAttribute";}}/***列印一個屬性**/void PrintAttribute(FbxNodeAttribute* pattribute){if(!pattribute){return;}FbxString typeName=GetAttributeTypeName(pattribute->GetAttributeType());FbxString attrName=pattribute->GetName();PrintTabs();//FbxString.Buffer() 才是我們需要的字元數組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();//擷取這個node的位置、旋轉、縮放FbxDouble3 rotation=pnode->LclRotation.Get();FbxDouble3 scaling=pnode->LclScaling.Get();//列印出這個node的概覽屬性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++;//列印這個node 的所有屬性for (int i = 0; i < pnode->GetNodeAttributeCount(); i++){PrintAttribute(pnode->GetNodeAttributeByIndex(i));}//遞迴列印所有子node的屬性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* filename="City-1.fbx";//建立SDKManagerFbxManager* pSdkManager=FbxManager::Create();FbxIOSettings *pFbxIOSettings=FbxIOSettings::Create(pSdkManager,filename);//設定歸屬pSdkManager->SetIOSettings(pFbxIOSettings);//建立FbxImporter用來匯入fbx檔案FbxImporter* pImporter=FbxImporter::Create(pSdkManager,"");if(!pImporter->Initialize(filename,-1,pSdkManager->GetIOSettings())){printf("Call to FbxImporter::Initialize() failed");printf("Error returned :%s\n\n", pImporter->GetStatus().GetErrorString());return -1;}FbxScene* pScene=FbxScene::Create(pSdkManager,"city1");pImporter->Import(pScene);pImporter->Destroy();//遞迴列印出這個情境下面的節點的屬性//注意我們不會列印出Root節點因為root節點不包含任何屬性FbxNode* pRootNode=pScene->GetRootNode();if(pRootNode){int nodeCount=pRootNode->GetChildCount();for (int i = 0; i < nodeCount; i++){PrintNode(pRootNode->GetChild(i));}}pSdkManager->Destroy();return 0;}

運行結果:



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.