How to: Convert, Load and animate NWN models in Irrlicht.

A forum to store posts deemed exceptionally wise and useful
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

How to: Convert, Load and animate NWN models in Irrlicht.

Post by MasterGod »

Updated: 07.09.2007 - (dd.mm.yyyy)

I know this is a problem a lot of people encounter and sometimes (like me) after a moth of searching fell into despair.
After weeks trying anything I can think of to convert the NWN .mdl format to something Irrlicht support, just before I quit trying I found the way. Then, when I loaded it into Irrlicht I saw I cant animate the animated meshes. After getting frustrated from no success I quit trying and accepted failure, then, a few days later I said to myself "give it One more shot, so you can say you have covered every option" and guess what? IT WORKED! I found the way to to animate the NWN (converted) meshes without any problem just as if they were any other animated mesh.
So, I thought to myself, here is your chance to contribute the community and help all who is still lost and don't know how to do it.
The whole journey can be found here (shorter then it sounds - I really recommend to check it out!):
Converting NWN .mdl mesh to 3DS - Click Here.
Converting NWN 3DS meshes to .X and Animating the NWN converted .X format meshes - Click Here.

This is the final product you should get following my instructions:
http://rapidshare.com/files/54073043/Ir ... 1.3.1_.rar

O.K, lets get to work:
What you need:
To Convert the NWN .mdl format to 3DS:
3ds Max - You can get the 30-Day Trial Here.
NWmax 0.8 3ds max v6 Installer (1.1MB) - NWmax .8 Homesite.
NWmax is a suite of import, export and modeling scripts and utilities for Discreet’s free gmax 3D modeling software. Unlike the previous scripts available to the community, NWmax is a no compromise full implementation of all features available to NWN 3d models. Skinmesh, Aura Lights, Emitters, animations, danglymesh… it’s all there and it exports and saves without any copy+pasting required. NWmax offers the user a suite of custom utilities to use while importing, creating and exporting NWN weapons, creatures, placeables, tiles and VFX creations.
To Convert the NWN 3DS meshes to .X:
Panda Directx Exporter (4.9.63.0) for 3DS Max - Click Here.
Some free-for-testing models from BioWare:
- Click Here - Note: The effects which are in .mdl format should be made in your game in another way - after reading all of this try use one of the effects and see what you get.

In short what is everything:
3DS Max is a modeling application.
NWmax is a plug-in to MAX which converts NWN .mdl format to 3DS - with animation and everything.
Panda Directx Exporter - as its name - an exporter to .X format - WITH animations!

O.k - Install Max, NWmax, Panda Directx Exporter and at least 1 model from BioWare's site - I'll use the Iron Golem model.
Enter Max - If you installed NWmax right you should get the following screen:
Image

Press MDL Loading -> Browse -> Locate the Iron_Golem.mdl (make sure all its textures are in the same folder as it is) -> Press Import.
You should get something like this:
Image

Now press File -> Export - in the "Save as type" if you installed the Panda's exporter right you should have (last one) "Panda DirectX (*.X)" like in here:
Image

Call it "Iron_Golem_X" or anything else you want and press "Save".
Now just change few configurations:
Image

And you will get 3 files where you saved it:
Iron_Golem_X.x - The mesh with animations.
c_golem_iron.tga - Texture A (for the body except the sword)
W_metal_tex.tga - Texture B (for the sword)

From now its few lines of code to show it on screen. This is how it should be done in your application:

Code: Select all

scene::IAnimatedMesh* mesh = smgr->getMesh("Iron_Golem_X.x");
scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
if (node)
{
		node->setMaterialFlag(video::EMF_LIGHTING, false);
		node->setMaterialTexture(0,driver->getTexture("c_golem_iron.tga"));
		node->setPosition(core::vector3df(0.0f , 0.0f , 0.0f));
		node->setRotation(core::vector3df(-90.0f , 0.0f , 0.0f));
		
		node->setFrameLoop(0, 625);
		node->setAnimationSpeed(20);
		node->setLoopMode(true);
} 
Note: To add the SkyBox like in IrrEdit use the following code:

Code: Select all

smgr->addSkyBoxSceneNode(
		driver->getTexture("default_skyboxup.jpg"),
		driver->getTexture("default_skyboxdn.jpg"),
		driver->getTexture("default_skybox3.jpg"),
		driver->getTexture("default_skybox1.jpg"),
		driver->getTexture("default_skybox2.jpg"),
		driver->getTexture("default_skybox0.jpg"),0);
The jpegs are in the IrrEdit folder, under textures directory I think.
Special Note:
* I don't know why but you "Have" to change two parameters:
1 - Rotate the model on the X-Axis by 90 (-90) : node->setRotation(core::vector3df(-90.0f , 0.0f , 0.0f));
2 - Change the speed of the animation - as much as you need, I suggest 20.

This is the final product you should get following my instructions:
http://rapidshare.com/files/54073043/Ir ... 1.3.1_.rar

After playing with it a bit more I made something nice with 3 different models - it uses DirectX9.
http://rapidshare.com/files/53451416/AT ... orOGL_.rar

I hope it solves a Lot of people a big Massive headache about how to do it.
Big thanks to all who helped me through this journey to NWN<->Irrlicht Land :D

I'll appreciate making this Sticky if people finds it helpful :wink: .

PS: Anyone knows maybe why there is the X-Axis "problem"?
Last edited by MasterGod on Fri Sep 07, 2007 7:32 pm, edited 6 times in total.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
deesine
Posts: 104
Joined: Fri May 12, 2006 9:19 am

Re: How to: Convert, Load and animate NWN models in Irrlicht

Post by deesine »

MasterGod wrote:PS: Anyone knows maybe why there is the X-Axis "problem"?
Probably caused by the axis you're using as the "up-axis" when modeling and exporting.

I noticed you're modeling with Z-up, try changing it to Y-up and see if it helps; note that if you rotate it around X you change the models' upwards-direction between Y and Z et.c.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

On the thread below it says that you can get NWN tools for GMax aswell, so that you dont have to get the 30 day trial of 3DS Max. (GMax is a free download from turbosquid.com)

Then obtain the Tempest pack for GMax which allows you to export to md3 which is recently supported by Irrlicht.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

BlindSide wrote:On the thread below it says that you can get NWN tools for GMax aswell, so that you dont have to get the 30 day trial of 3DS Max. (GMax is a free download from turbosquid.com)

Then obtain the Tempest pack for GMax which allows you to export to md3 which is recently supported by Irrlicht.
So you say I can use GMax with NWN Tools from http://turbosquid.com (Get them both there?) to convert from NWN .mdl to md3 with animation working in Irrlicht?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Haven't tried it, I will try it and report back if it works or not.

I can see no reason why it wouldn't work however, MD3 is not as troublesome a format as .X to get working (I say this because I think nothing is as troublesome as .X :P ) and there are many working animation-enabled Irrlicht MD3 implementations available. There is also a blender importer for MD3 if you want to import it into blender and export it from there.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

The MD3 is working great but there is a problem in irrlicht that you cant position, scale and rotate MD3 models.
There is only One problem (that I'm looking for a solution for it now) with the .X format that I can't fully control the animation - yet.

Edit: O.K, fixed it. the thing is that I need to change the settings when exporting in the animation tab from 3DS ticks to Key Frames.
I'll fix it in the first post.
Last edited by MasterGod on Fri Sep 07, 2007 8:19 pm, edited 1 time in total.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

O.K changed it in the first post.
This is how it should be done in code:

Code: Select all

scene::IAnimatedMesh* mesh = smgr->getMesh("Iron_Golem_X.x");
scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
if (node)
{
		node->setMaterialFlag(video::EMF_LIGHTING, true);
		node->setMaterialTexture(0,driver->getTexture("c_golem_iron.tga"));
		node->setPosition(core::vector3df(0.0f,0.0f,0.0f));
		node->setRotation(core::vector3df(x,x,x));
		node->setScale(core::vector3df(x,x,x));
		
		node->setFrameLoop(0, 625);
		node->setAnimationSpeed(20);
		node->setLoopMode(true);
} 
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
de3000
Posts: 20
Joined: Tue Sep 19, 2006 4:57 pm
Location: South Africa

Animation sequences

Post by de3000 »

This might be a beginner question. :?

I would like to know how would you store and/or get animation sequences from the model like the NWN model viewer ie. how to get the specific models attack animation or stand animation without hardcoding the animation frames for each model and each sequence.

:arrow: I did do a forum search but could not find a good answer and yes im lazy to browse all the results (i did the first page).
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Create a enum of each range of frames you want and make a function which sets the right frame loop according to the enum:

Code: Select all

enum E_ANIM {E_ATTACK, E_RUN};

void function(E_ANIM anim)
{
	switch(anim)
	{
	case E_ATTACK: node->setFrameLoop(start frame, end frame); break;
	case E_RUN: node->setFrameLoop(start frame, end frame); break;
	}
}
This is the only idea I can think of right now, but it looks pretty convenient.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
de3000
Posts: 20
Joined: Tue Sep 19, 2006 4:57 pm
Location: South Africa

Post by de3000 »

I think either you misunderstood or I explained wrong. (think its the latter :roll: )

I know how to playback animations, the thing I am trying to find out is getting the start frame and end frame without specifying them in code.

I don't want

Code: Select all

enum E_ANIM {E_ATTACK, E_RUN}; 

void function(E_ANIM anim) 
{ 
   switch(anim) 
   { 
   case E_ATTACK: node->setFrameLoop(0, 50); break; 
   case E_RUN: node->setFrameLoop(60, 80); break; 
   } 
}
I want

Code: Select all

enum E_ANIM {E_ATTACK, E_RUN}; 

void function(E_ANIM anim) 
{ 
   switch(anim) 
   { 
   case E_ATTACK: node->setFrameLoop(getAttackAnimStartFrame(node), getAttackAnimEndFrame(node)); break; 
   } 
}
Where getAttackAnimEndFrame(node) would get the attack animation start frame for me by somehow working with the mesh to find it. I need somehow code.

I have an idea as to how to do it but not sure how to implement it.
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

You could create an extra file (XML?) for every model where those framenumbers are stored. Load this data file after loading the model and save the numbers into an array or a structure. This way it wouldn't be hardcoded.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

shogun's way sounds good but I think XML isn't required here, a simple text file would suffice.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Hmm, I cant seem to load the mdl model into max. It just hangs when I click import.

I tried it with several different mdl files straight from that site you pointed me to and from nwvault.

*Edit*
Import seems to only work if warnings are allowed in that NWMAX menu.

*Edit*
It seems that my animations didnt transfer over. Oh well! I love it!

MasterGod, you are now my hero for the next 24 hours :)
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I'm glad to hear you found my guide useful. :)
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
de3000
Posts: 20
Joined: Tue Sep 19, 2006 4:57 pm
Location: South Africa

Irrlicht mdl loader

Post by de3000 »

I was looking at the .mdl format and looking at some .mdl viewers, one of which was written in java. Since im using Jirr i wrote a .mdl model loader for Jirr but not using the standard irrlicht interfaces and such.

I was just wondering if anyone would want the code (Im not re-writing in to c++ :P)
and also if someone can help me with interpolation with .mdl as it does not use frames per say to animate.
Post Reply