Gmax and Irrlicht (part 1)
When I started to use Irrlicht, I searched a lot to find a good and free modeler (with animation support) that can be used with Irrlicht. I found that it was more difficult than what I thought. To model, I normally use Wings3d but it doesn't support animations and Blender is also very difficult to use and absolutely not user-friendly (and I saw people having problems to export to the directx .x format with it).
I finally found Gmax. It's a free program that is very powerful because it's a stripped version of the professional tool 3d Studio Max 4. The only problem is that with Gmax you can't export your work without using gamepacks . So you can only make content for few professional games that include a gamepack.
But I found a way to export from Gmax into the .x format that Irrlicht recognize :)
1- Download and install Gmax (if it's not already done)
2- Go Here
and download the FS2004 Gmax gamepack SDK . Install it anywhere you want (for
example c:/fs2004sdk ).
You can also install it in the gmax folder if you want to make models for
Flight Simulator 2004 (but I don't have it) but you will still need to follow
the next steps because it won't put the plugins in the right places...
3- Go in the folder where you installed the fs2004sdk gamepak
(for example c:/fs2004sdk), open the folder gamepacks/fs2004/plugins
Copy the files FSModelExp.dle and makemdl.exe
to C:/Program Files/Gmax/plugins (of course remplace it by another path if
you installed Gmax anywhere else... ;)
4- Download MDL Commander and Middleman and unzip them.
5- (I hope that I will be clear, because this step is
a bit complicated... Read the MDL Commander help file for more information...)
Go in the Gmax plugin folder, rename makemdl.exe (the program
you copied in the step3) to mkmdl.exe . Then copy mdlcommander.exe
to this folder and rename it makem.exe . Finally copy, again
to the same plugin folder, the middleman utility (it's called makemdl.exe)
. Now the middleman program will bypass the microsoft one because you changed
its name...
Your Gmax plugins folder should now look like something like that:
6- Ok now the plugins are installed (you won't need to do
steps 1 to 5 the next time...) So now we can start to model... For this tutorial,
we will create a box with a texture.
Copy the following texture in your work folder:
(*VERY IMPORTANT*) You will need to make 2 copies of this picture. One in
the JPEG format called smile.jpg and another one in the BMP format called
smile.bmp (fortunately the bmp one won't need to be released to the end-user,
it's only for the conversion...)
7-Open Gmax. Create a box (Read the documention if you don't
know how...)
8- Open the material editor. Click on the New button.
Click on the button next to the diffuse color (see below). It opens the material
navigator. Choose Bitmap.
9- Go to the folder where you saved the texture and open
smile.jpg
The Texture is added to the material.
Select the box, click on the Apply button in the material editor.
Click on the blue button called "show map in viewport"
(see below) to see the texture on the box
10- Click on File/Export... Choose a folder. Choose MDL
Aircraft Object (*.MDL) for the type and name the file box .
Click on the save button.
11- The middleman utility automatically opens. Click on the
Options tab. Check Save X File and No Compile (unless
you want also the compiled Flight Simulator MDL file... But anyway Irrlicht
doesn't import it...) and Click on the GO! button.
Now we have our .X file! COOL! ^_^
But we have a problem... Irrlicht 0.6 can't load it! I know, Irrlicht is supposed to support more than 99% of .x files. So, we exported to the 1% that don't work...
But it's not a Gmax bug because this .x file can be opened by other programs like 3D Exploration... So it must be an Irrlicht bug... Anyway, don't bother with this because I found a solution! Follow the next steps...
12- Download and unzip MeshView. It is a tool that come with the Directx9 SDK. If you don't want to download the 220MB SDK just for this little tool, don't worry because I uploaded it to my site: DOWNLOAD IT HERE.
13- Open MeshView (mview.exe) and open your model (File/Open
Mesh File), then re-save it (File/Save Mesh As...). Choose Text
for the X File Format and name your file box2.x (don't forget the
.x because MeshView don't add the extension automatically)
We now have a valid .X file that Irrlicht can import!
You can load it with the following code: (I won't explain it because it's the same thing as the HelloWorld tutorial on the Irrlicht page)
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
int main()
{
//start Irrlicht
IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(500,
400), 16, false, false, 0);
device -> setWindowCaption(L"Irrlicht ");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* s_manager = device->getSceneManager();
//load the model
IAnimatedMesh* model = s_manager->getMesh("box2.x");
IAnimatedMeshSceneNode* node = s_manager->addAnimatedMeshSceneNode( model
);
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMaterialTexture( 0, driver->getTexture("smile.jpg")
);
node->setPosition(core::vector3df(100,-30,100));
}
//add a camera
s_manager -> addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
while(device->run())
{
driver -> beginScene(true, true, SColor(200,10,10,100));
//draw all
s_manager -> drawAll();
driver -> endScene();
}
device -> drop();
return 0;
}
It gives your the following result:
Here is another test I did with another model:
Notes: