# 3DS Max to DirectX Matrix

## Recommended Posts

Hello,

I'm building my own engine in directx and I came to the point where I'm trying to import meshes. I installed the FBX SDK and imported a mesh inside my framework. But, there is one small issue ... In 3DS max the Z-axis is the up axis and in my framework the Y-axis is the up axis. Is there some sort of algorithm to solve this issue. I thought that I could multiply my final transform matrix with another matrix according to what 3d software package the mesh came from. I don't like to swap the y and z axis inside my engine it's a bit dirty coding and it will not work when a mesh is exported form another 3d software package.

I already looked it up on google and found some kind of solution:

http://forum.devmaster.net/t/transform-matrix-from-3ds-max-to-right-handed/10295/2

But I don't really understand what he means, do I need to multiply every vertex, or just my final transformation matrix?

Also the reply on the solution tells me that he had to use a different matrix.
But in my entire programming carreer the x-axis is right, y-axis is up and z-axis is forward so what do I need to use and why?

Kind Regards,

Dyronix

##### Share on other sites

Do not swap the y and z axis inside your engine, just swap y and z when storing the object in whatever form in your engine.

Example: you have a list of vertices saved to some file, with y and z swapped, I suppose in your engine you have some sort of structure Mesh that contains a list of vertices and indices, so my idea is that when you write your load function (like Mesh* loadFrom3DS(char* filename)) just swap y and z. Pseudo-code:

Mesh* loadFrom3DS(char* filename)
{
//...stuff...
Mesh* temp= new Mesh();
float x,y,z;
for(all vertices in the file)
{
//suppose you read the current vertex's coords into x,y,z=>
}
//...stuff...
return temp;
}

Edited by lightxbulb

##### Share on other sites

... engine in directx ... inside my engine it's a bit dirty coding and it will not work when a mesh is exported form another 3d software package ...

You're trying to pack too many tasks into your import process. To avoid "dirty coding," your engine should have just a few generic routines for creating objects from file data, and that file data should be in just a few formats specific to your engine requirements, not the requirements of the modeling software which created the data.

You should be thinking in terms of converting data in modeling software format to data compatible with your engine. That converted data is then saved to another file in a format  from which data can be imported into your engine, without regard to the software originally used to create the data.

That is, start with a file format specification to be used for importing/creating objects by your engine. Then, code routines* for reading various software-specific file formats, convert and save that data in your engine import format. That leaves the "dirty coding" out of the engine, and becomes part of routines where it is needed.

*Those routines can be a part of your engine, but more commonly are a separate app for preparing assets for your game. By making asset preparation a separate app, you don't have to recompile/debug/test your game engine when you revise the FBX import/conversion process, or add other software-specific formats to your inventory. Also, that removes the requirement to link in (for instance) the FBX SDK to your game engine.

You may also want to look at Assimp which can read several popular formats, and would provide a single interface** for reading the imported data for conversion/saving to your "single" format.

** Rather than an interface for every format you want to be able to import.

Edited by Buckeye

##### Share on other sites

I just needed to muliply my vertex with the following matrix:

(1, 0, 0, 0);
(0, 0, -1, 0);//need to multiply by -1 because directx has a left handed coordinate system.
(0, 1, 0, 0);
(0, 0, 0, 1);

It was so obvious that just did not think about it.
Then again "Buckeye" you have a valid point, maybe I should write an application that imports meshes from several moddeling applications and then export it to a fileformat my engine can read, this way I can avoid dirty coding and just import my own format. I'll take that into account.
Edited by Dyronix

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628390
• Total Posts
2982411

• 10
• 9
• 19
• 24
• 11