Autodesk FBX SDK Program 中文 (二)
这是Autodesk FBX SDK学习笔记第二篇。下面部分汉字翻译自Autodesk FBX SDK Program。翻译人:有道翻译。
上一篇讲了一些FBX SDK的基本操作。创建FbxManager这些,也写了我们第一个FBX SDK 的样例。
今天是FBX SDK指南的第二篇。创建一个FBX文件转换器,有什么用?
把FBX转换成DAE、Obj这些格式啦!
把FBX 二进制转换成文本格式啦。
这一篇的知识点:
1、FbxManager的创建与销毁
2、FbxImporter的创建与使用
3、FbxExporter的使用
4、Fbx SDK支持的文件格式
Autodesk FBX SDK document本篇地址:
http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html
官方样例执行效果:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHV1dHU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
不知道是MFC还是.Net 。这两个我一个都不会,所以还是写个控制台的……
#include<fbxsdk.h> #pragma comment(lib,"libfbxsdk.lib") FbxManager *g_pFbxManager=NULL; /*** 初始化FbxSDK ***/
bool InitializeFbxSDK()
{
bool bRet=false; do
{
//创建FbxManager
g_pFbxManager=FbxManager::Create(); //创建FbxIOSetting
FbxIOSettings *pFbxIOSettings=FbxIOSettings::Create(g_pFbxManager,IOSROOT); //绑定关系
g_pFbxManager->SetIOSettings(pFbxIOSettings); bRet=true; } while (0);
return bRet;
} /*** 获取Fbx SDK 支持读入的格式 ***/
void GetFileCanImport()
{
int count= g_pFbxManager->GetIOPluginRegistry()->GetReaderFormatCount(); printf("支持导入下面 %d 种文件格式:\n",count); FbxString s;
int i=0;
for (int i = 0; i <count; i++)
{
s+=g_pFbxManager->GetIOPluginRegistry()->GetReaderFormatDescription(i); //获取描写叙述
//s+=g_pFbxManager->GetIOPluginRegistry()->GetReaderFormatExtension(i); //获取文件后缀
s="%d : "+s+" \n";
printf(s.Buffer(),i);
s.Clear();
}
} /*** 获取Fbx SDK 可以导出的格式 ***/
void GetFileCanExport()
{
int count=g_pFbxManager->GetIOPluginRegistry()->GetWriterFormatCount();
printf("支持导出下面 %d 种文件格式:\n",count); FbxString s;
int i=0;
for (int i = 0; i < count; i++)
{
s+=g_pFbxManager->GetIOPluginRegistry()->GetWriterFormatDescription(i); //获取描写叙述
//s+=g_pFbxManager->GetIOPluginRegistry()->GetWriterFormatExtension(i);//获取文件后缀
s="%d : "+s+" \n";
printf(s.Buffer(),i);
s.Clear();
}
} /*** 读入一个Fbx文件到FbxScene ***/
bool ImportFbxModel(FbxScene* scene,const char* importfilename)
{
int fileVerMajorNum,fileVerMinorNum,fileVerRevision; //文件大版本号号、小版本号号,修正版本号号
int sdkVerMajorNum,sdkVerMinorNum,sdkVerRevision; //FBX SDK版本号号
int animStackCount; //动画的数量
bool bRet=false;
char password[1024]; //password。文件可能加密了须要输入password //获取FBX SDK的版本号号
FbxManager::GetFileFormatVersion(sdkVerMajorNum,sdkVerMinorNum,sdkVerRevision); //创建FbxImporter
FbxImporter *pFbxImporter=FbxImporter::Create(g_pFbxManager,importfilename); //初始化FbxImporter
const bool importret= pFbxImporter->Initialize(importfilename,-1,g_pFbxManager->GetIOSettings()); //获取Fbx文件的版本号号
pFbxImporter->GetFileVersion(fileVerMajorNum,fileVerMinorNum,fileVerRevision); if(!importret) //导入出错
{
FbxString errorStr=pFbxImporter->GetStatus().GetErrorString();
printf("\nFbxImporter初始化失败,错误原因:%s\n",errorStr.Buffer()); if(pFbxImporter->GetStatus().GetCode() == FbxStatus::eInvalidFileVersion) //假设是文件版本号不对
{
printf("\n FBX SDK 版本号:%d.%d.%d\n",sdkVerMajorNum,sdkVerMinorNum,sdkVerRevision);
printf("\nFBX 文件版本号 :%d.%d.%d\n",fileVerMajorNum,fileVerMinorNum,fileVerRevision);
}
return false;
} printf("\n ***** 导入文件成功****** \n"); printf("\n FBX SDK 版本号:%d.%d.%d \n",sdkVerMajorNum,sdkVerMinorNum,sdkVerRevision); if(pFbxImporter->IsFBX() ) //假设导入的文件是FBX格式
{
printf("\n FBX 文件版本号 :%d.%d.%d \n",fileVerMajorNum,fileVerMinorNum,fileVerRevision); //在FBX文件里,一个Scene中可能有一个或多个 "animation stack"。一个"animation stack"里面存放一个动画数据,假设想获取"animation stack"的信息。不必要加载所有的Scene printf("\n Animation stack 信息:\n");
animStackCount=pFbxImporter->GetAnimStackCount(); printf("数量:%d\n ",animStackCount);
printf("名称:%s\n ",pFbxImporter->GetActiveAnimStackName()); for (int i = 0; i < animStackCount; i++)
{
FbxTakeInfo *pFbxTakeInfo=pFbxImporter->GetTakeInfo(i);
printf("Animation Stack %d\n",i);
printf(" Name: %s\n",pFbxTakeInfo->mName.Buffer());
printf(" Description: %s\n",pFbxTakeInfo->mDescription.Buffer()); printf(" Import Name: %s\n",pFbxTakeInfo->mImportName.Buffer()); //导入进来的名字
printf(" Import State: %s\n",pFbxTakeInfo->mSelect ?"true":"false");
} //导入内容设置,默认导入所有内容
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_MATERIAL,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_TEXTURE,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_LINK,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_SHAPE,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_GOBO,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_ANIMATION,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_GLOBAL_SETTINGS,true);
} //假设导入的文件不是FBX格式,那就没有上面的逻辑 //导入Fbx到场景
bRet = pFbxImporter->Import(scene); //假设文件导入出错,而且是返回错误Code是password错误
if(bRet==false && pFbxImporter->GetStatus().GetCode()==FbxStatus::ePasswordError)
{
printf("请输入password:\n");
password[0]='\0';
FBXSDK_CRT_SECURE_NO_WARNING_BEGIN//这个宏是用来关闭4996警告。相似scanf strcpy strcat在vs下都会有警告
scanf("%s",password);
FBXSDK_CRT_SECURE_NO_WARNING_END
FbxString passwdStr(password); g_pFbxManager->GetIOSettings()->SetStringProp(IMP_FBX_PASSWORD,passwdStr);//对FbxIOSetting设置StringProp,即字符串属性,Prop这里指property
g_pFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_PASSWORD_ENABLE,true);//设置Bool属性,是否使用password bRet=pFbxImporter->Import(scene); //输入password后又一次Import
if(bRet==false && pFbxImporter->GetStatus().GetCode()==FbxStatus::ePasswordError)
{
printf("文件导入错误。password错误! ");
} }
pFbxImporter->Destroy();
return bRet;
} /*** 导出FbxScene到模型文件 ***/
bool ExportFbxSceneToModel(FbxScene* scene,const char* exportfilename,int exportformat,bool pexportmedia)
{
bool bRet=false; //创建FbxExporter
FbxExporter *pFbxExport = FbxExporter::Create(g_pFbxManager,""); if(exportformat<0 || exportformat>=g_pFbxManager->GetIOPluginRegistry()->GetWriterFormatCount())
{
//假设选择导出的文件格式不支持
printf(" 不支持导出该种格式!! \n");
return false; exportformat=g_pFbxManager->GetIOPluginRegistry()->GetNativeWriterFormat();
printf(" 尝试默认的格式(FBX)导出:%d ",exportformat); if(!pexportmedia) //假设不导出多媒体
{
int formatcount=g_pFbxManager->GetIOPluginRegistry()->GetWriterFormatCount(); //尝试导出FBX的 ascii文件,即能看到内容可以的
for (int i = 0; i < formatcount; i++)
{
if(g_pFbxManager->GetIOPluginRegistry()->WriterIsFBX(i))
{
FbxString desStr=g_pFbxManager->GetIOPluginRegistry()->GetWriterFormatDescription(i);
if(desStr.Find("ascii")>=0)
{
exportformat=i;
break;
}
}
} } } //选择导出格式正确的话就没有上面的逻辑
if(!pFbxExport->Initialize(exportfilename,-1,g_pFbxManager->GetIOSettings()))
{
printf("FbxExport->Initialize Faild \n");
printf("FbxExport 初始化失败原因:%s",pFbxExport->GetStatus().GetErrorString());
return false;
} if(g_pFbxManager->GetIOPluginRegistry()->WriterIsFBX(exportformat))
{
g_pFbxManager->GetIOSettings()->SetBoolProp(EXP_FBX_MATERIAL,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(EXP_FBX_TEXTURE,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(EXP_FBX_EMBEDDED,pexportmedia);
g_pFbxManager->GetIOSettings()->SetBoolProp(EXP_FBX_SHAPE,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(EXP_FBX_GOBO,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(EXP_FBX_ANIMATION,true);
g_pFbxManager->GetIOSettings()->SetBoolProp(EXP_FBX_GLOBAL_SETTINGS,true);
} bRet=pFbxExport->Export(scene); pFbxExport->Destroy(); return bRet;
} /*** 转换一个模型文件 ***/
void ConvertModelFile(const char *importfilename,const char *exportfilename,int writefileformat)
{
printf("导入文件路径:%s\n 导出文件路径:%s \n 导出文件格式:%d\n",importfilename,exportfilename,writefileformat); //创建FbxScene,名字就叫做宝箱吧 Baoxiang
FbxScene *pFbxScene=FbxScene::Create(g_pFbxManager,"Baoxiang"); printf("\n ****** 转换開始 ****** \n"); bool b=ImportFbxModel(pFbxScene,importfilename); if(b)
{
printf("\n** 模型文件加载成功 ****\n");
}
else
{
printf("\n** 模型文件加载失败 ****\n");
pFbxScene->Destroy();
return;
} printf("\n** 開始导出 ****\n"); b=ExportFbxSceneToModel(pFbxScene,exportfilename,writefileformat,false); if(b)
{
printf("\n** 导出模型文件成功 ****\n");
}
else
{
printf("\n** 导出模型文件失败 ****\n");
pFbxScene->Destroy();
return;
} } int main(int argc,char **argv)
{ InitializeFbxSDK(); GetFileCanImport(); GetFileCanExport(); char importfilename[1024];
int exportformat=0;
char exportfilename[1024]; printf("\n请输入导入文件路径:");
scanf("%s",importfilename); printf("\n请输入导出格式:");
scanf("%d",&exportformat); printf("\n请输入导出文件路径:");
scanf("%s",exportfilename); ConvertModelFile(importfilename,exportfilename,exportformat); system("pause"); return 0; }
项目打包下载:
http://code.taobao.org/svn/xgameengine/trunk/OtherProject/FbxDemo
Autodesk FBX SDK Program 中文 (二)的更多相关文章
- Autodesk FBX SDK Program 中文 (一)
这是我的FBX SDK学习笔记.如文有错误.麻烦各位大大指出 为什么要使用FBX SDK? 由于3D建模软件都被AutoDesk收购了.FBX能够在各个建模软件之间互相导入导出,在非常多游戏引擎中也用 ...
- autodesk fbx sdk sample里面的工程无法调试解决方法
1.项目属性->常规中的目标文件名改为1 2.链接器->调试中的生成程序数据库文件改成:$(OutDir)1.pdb 3.连接器->常规中的输出文件改成:$(OutDir)1.exe ...
- FBX SDK 从2012.1 到 2013.3 变化
==================================================== ============================== 译文 ...
- 基于FBX SDK的FBX模型解析与加载 -(四)
8. 骨骼蒙皮动画 骨骼蒙皮动画是当前游戏引擎中最常用的一种动画方式,关于其基本原理网络上的资料较多,关于到涉及的其它较复杂操作,如插值.融合等在这里也就先不再讨论了,而且其实现方式也与具体引擎的动作 ...
- mingw fbx sdk /浮点数精度
接下来要做一个linux下的程序了. 下载linux version fbx sdk tar zxvf ...gz 按照安装说明 提升权限并没什么用 还是,cannot execute bin ...
- 基于FBX SDK的FBX模型解析与加载 -(一)
http://blog.csdn.net/bugrunner/article/details/7210511 1. 简介 FBX是Autodesk的一个用于跨平台的免费三维数据交换的格式(最早不是由A ...
- Windows Mobile 6.0 SDK和中文模拟器下载
[转] Windows Mobile 6.0 SDK和中文模拟器下载 Windows Mobile 6.5 模拟器 2010年12月06日 星期一 07:48 转载自 zhangyanle86 终于编 ...
- FBX SDK在vs 2010下面的配置
1.下载FBS SDK.地址.因为我是vs2010,所以我下载的是FBX SDK 2016.1.2 VS2010.如果没有了,你可以找博主直接要,QQ1240957820. 2.下载下来的是一个exe ...
- js生成中文二维码
http://www.cnblogs.com/xcsn/archive/2013/08/14/3258035.html http://www.jb51.net/article/64928.htm 使用 ...
随机推荐
- JEECG开源团队招募新成员 2014年
JEECG开源团队招募新成员 2014年 截止日期:2014-06-01 JEECG开源项目 是一款基于代码生成器的微云高速开发平台.提供企业高速开发和採用微信实现移动应用的解决方式.J ...
- Codeforces Round #296 (Div. 2) A. Playing with Paper
A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...
- Linux shell中的I/O重定向相关(转)
1. 基本概念(这是理解后面的知识的前提,请务必理解) a. I/O重定向通常与 FD有关,shell的FD通常为10个,即 0-9: b. 常用FD有3个,为0(stdin,标准输入).1(std ...
- OCP读书笔记(5) - 使用RMAN创建备份
5.Creating Backups with RMAN 创建备份集 RMAN> backup as backupset format '/u01/app/oracle/backup/rmanb ...
- window.open()具体解释及浏览器兼容性问题
一.基本的语法:window.open(pageURL,name,parameters)当中:pageURL 为子窗体路径name 为子窗体名字parameters 为窗体參数(各參数用逗号分隔) ...
- 如何在cocos2d项目中enable ARC
如何在cocos2d项目中enable ARC 基本思想就是不支持ARC的代码用和支持ARC的分开,通过xcode中设置编译选项,让支持和不支持ARC的代码共存. cocos2d是ios app开发中 ...
- ASA QOS限速
cisco的Qos限速和H3C的有点区别,不过总体来说,H3C的比较渣,单位是不一样的,H3C 的CAR单位的是kpbs,而cisco police限速时的单位是Bits per seconds,H3 ...
- EXPORT_SYMBOL解析
一般我们编写C程序时,要调用某个文件中的函数,需要在本文件中包含声明有被调用函数的头文件,然后编译连接后,方能找到调用函数.对于模块依赖的情况,不能简单的使用上面的方法,内核提供了一个机制,就是EXP ...
- POJ 1018 【枚举+剪枝】.cpp
题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...
- Eclipse扩展点实践之添加快捷菜单项(Command方式实现)
有两种方式,一种是Action的方式,另一种是Command的方式(这两种方式的区别详见:http://wiki.eclipse.org/FAQ_What_is_the_difference_betw ...