FBX static & skin mesh loader for Irrlicht-1.7.2
This example shows us how to write a FBX file parser with FBX SDK. The mainly parts are how to retrieve vertexes, uv, normal, polygons, polygons' material, textures, skin animation data and so on.
To make the source code as easy as possible, I assume that the FBX file will contain only one mesh node. Why? For game play models, we MUST combine all those meshes into only one mesh. That means one big mesh may work with multiple materials. Less mesh may cause less draw call happen, we could avoid submit the small meshes frequently. All this will improve the GPU frame rate. When you download some model from the web site, you will notice that there are lots of separated mesh node exists. In such situation, you need to do some additional work with Maya. Good Luck for you!
Project Setting
To set up the FBX SDK(here FBX SDK 2009.3 version used) in your project, on best solution is copy them from the sdk example projects or create a empty project first and do a beyond comparing with the example project files. Of course, the first thing you always need to do before use other external libraries is set the correct include & lib directories. For FBX project, there are some additional settings:
1) You need to add those macros in your project property “Preprocessor Definition”:
KFBX_PLUGIN
KFBX_FBXSDK
KFBX_NODLL
2) You need to add those items under the “Additional Dependencies” property:
wininet.lib
For more details about how to configure the FBX sdk using settings, you could check my project file.
Export function Name Correctly
In this example, I use Irrlicht-1.7.2 to display the static mesh and skin mesh. But in this version, it does not expose some animation implementation header files to us. For example, here I need to use CSkinnedMesh.h in my own code to hold some animation data. But Irrlicht-1.7.2 library does not put this file into it’s include directory. That means I could not use this file in some project that using Irrlicht library.
To address this issue, you need to move CSkinnedMesh.h to include directory, and open source file, modify it’s class declaration like following to expose this class to outside.:
class IRRLICHT_API CSkinnedMesh: public ISkinnedMesh { public:
IRRLICHT_API will make sure we could access and use class CSkinnedMesh from outside of Irrlicht library. For more details about export class or function name from DLL, you could google on the web. As I know there are two ways to manage to do that: the first one is that you place key word __declspec(dllexport) before your output class or function name, and the other way is design your class as interface that just some class with pure virtual functions.
With these modification in Irrlicht library, then you need to re-build the whole irrlicht library.
Compile & Run Demo
The full source code can be downloaded from here. To recompile and run the demo, you need to install the following stuffs on your computer:
1) Install FBX SDK, here I used FBX SDK 2009.3; At the same time, you need to install Maya on your computer to check whether this program load and display the FBX file correct or not;
2) Irrlicht 1.7.2 and with IRRLICHT_API modification in CSkinnedMesh.h, then re-build the library;
3) I use VisualStudio 2008, Of course you could use other IDE if you wish. But you need to translate those include & library settings from VS to your IDE settings.