Fused mesh after export from 3DSMax

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Fused mesh after export from 3DSMax

Post by MartinVee »

As part of the early tests I'm doing with Irrlicht, I had one of the 3D animator here create a simple mesh in 3D Studio Max. It's a simple 12-sided polygons, arranged in a wheel, with each side of the polygon independent from the other pieces. The goal is to ultimately be able to texture each of the 12 sides with a different textures.

The animator exported the mesh in OBJ format directly from 3DSMax. Here is the resulting file :

Code: Select all

 
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 02.08.2016 16:37:53
 
mtllib twelvesidedwheel.mtl
 
#
# object 12
#
 
v  12.5000 48.2963 -12.9410
v  12.5000 35.3553 -35.3554
v  -12.5000 35.3553 -35.3554
v  -12.5000 48.2963 -12.9410
# 4 vertices
 
vn 0.0000 0.8660 -0.5000
# 1 vertex normals
 
vt 0.0000 0.0000 1.0000
vt 0.0833 0.0000 1.0000
vt 0.0833 1.0000 1.0000
vt 0.0000 1.0000 1.0000
# 4 texture coords
 
g 12
usemtl wire_088199225
s 8
f 1/1/1 2/2/1 3/3/1 4/4/1 
# 1 polygons
 
#
# object 1
#
 
v  12.5000 48.2963 12.9409
v  12.5000 48.2963 -12.9410
v  -12.5000 48.2963 -12.9410
v  -12.5000 48.2963 12.9409
# 4 vertices
 
vn 0.0000 1.0000 -0.0000
# 1 vertex normals
 
vt 0.9167 0.0000 1.0000
vt 1.0000 0.0000 1.0000
vt 1.0000 1.0000 1.0000
vt 0.9167 1.0000 1.0000
# 4 texture coords
 
g 1
usemtl wire_088199225
s 8
f 5/5/2 6/6/2 7/7/2 8/8/2 
# 1 polygons
 
#
# object 2
#
 
v  12.5000 35.3554 35.3553
v  12.5000 48.2963 12.9409
v  -12.5000 48.2963 12.9409
v  -12.5000 35.3554 35.3553
# 4 vertices
 
vn 0.0000 0.8660 0.5000
# 1 vertex normals
 
vt 0.8333 0.0000 1.0000
vt 0.9167 0.0000 1.0000
vt 0.9167 1.0000 1.0000
vt 0.8333 1.0000 1.0000
# 4 texture coords
 
g 2
usemtl wire_088199225
s 8
f 9/9/3 10/10/3 11/11/3 12/12/3 
# 1 polygons
 
#
# object 3
#
 
v  12.5000 12.9410 48.2963
v  12.5000 35.3554 35.3553
v  -12.5000 35.3554 35.3553
v  -12.5000 12.9410 48.2963
# 4 vertices
 
vn 0.0000 0.5000 0.8660
# 1 vertex normals
 
vt 0.7500 0.0000 1.0000
vt 0.8333 0.0000 1.0000
vt 0.8333 1.0000 1.0000
vt 0.7500 1.0000 1.0000
# 4 texture coords
 
g 3
usemtl wire_088199225
s 8
f 13/13/4 14/14/4 15/15/4 16/16/4 
# 1 polygons
 
#
# object 4
#
 
v  12.5000 -12.9410 48.2963
v  12.5000 12.9410 48.2963
v  -12.5000 12.9410 48.2963
v  -12.5000 -12.9409 48.2963
# 4 vertices
 
vn -0.0000 0.0000 1.0000
# 1 vertex normals
 
vt 0.6667 0.0000 1.0000
vt 0.7500 0.0000 1.0000
vt 0.7500 1.0000 1.0000
vt 0.6667 1.0000 1.0000
# 4 texture coords
 
g 4
usemtl wire_088199225
s 8
f 17/17/5 18/18/5 19/19/5 20/20/5 
# 1 polygons
 
#
# object 5
#
 
v  12.5000 -35.3553 35.3553
v  12.5000 -12.9410 48.2963
v  -12.5000 -12.9409 48.2963
v  -12.5000 -35.3553 35.3553
# 4 vertices
 
vn -0.0000 -0.5000 0.8660
# 1 vertex normals
 
vt 0.5833 0.0000 1.0000
vt 0.6667 0.0000 1.0000
vt 0.6667 1.0000 1.0000
vt 0.5833 1.0000 1.0000
# 4 texture coords
 
g 5
usemtl wire_088199225
s 8
f 21/21/6 22/22/6 23/23/6 24/24/6 
# 1 polygons
 
#
# object 6
#
 
v  12.5000 -48.2963 12.9410
v  12.5000 -35.3553 35.3553
v  -12.5000 -35.3553 35.3553
v  -12.5000 -48.2963 12.9410
# 4 vertices
 
vn -0.0000 -0.8660 0.5000
# 1 vertex normals
 
vt 0.5000 0.0000 1.0000
vt 0.5833 0.0000 1.0000
vt 0.5833 1.0000 1.0000
vt 0.5000 1.0000 1.0000
# 4 texture coords
 
g 6
usemtl wire_088199225
s 8
f 25/25/7 26/26/7 27/27/7 28/28/7 
# 1 polygons
 
#
# object 7
#
 
v  12.5000 -48.2963 -12.9409
v  12.5000 -48.2963 12.9410
v  -12.5000 -48.2963 12.9410
v  -12.5000 -48.2963 -12.9409
# 4 vertices
 
vn -0.0000 -1.0000 0.0000
# 1 vertex normals
 
vt 0.4167 0.0000 1.0000
vt 0.5000 0.0000 1.0000
vt 0.5000 1.0000 1.0000
vt 0.4167 1.0000 1.0000
# 4 texture coords
 
g 7
usemtl wire_088199225
s 8
f 29/29/8 30/30/8 31/31/8 32/32/8 
# 1 polygons
 
#
# object 8
#
 
v  12.5000 -35.3554 -35.3553
v  12.5000 -48.2963 -12.9409
v  -12.5000 -48.2963 -12.9409
v  -12.5000 -35.3554 -35.3553
# 4 vertices
 
vn -0.0000 -0.8660 -0.5000
# 1 vertex normals
 
vt 0.3333 0.0000 1.0000
vt 0.4167 0.0000 1.0000
vt 0.4167 1.0000 1.0000
vt 0.3333 1.0000 1.0000
# 4 texture coords
 
g 8
usemtl wire_088199225
s 8
f 33/33/9 34/34/9 35/35/9 36/36/9 
# 1 polygons
 
#
# object 9
#
 
v  12.5000 -12.9410 -48.2963
v  12.5000 -35.3554 -35.3553
v  -12.5000 -35.3554 -35.3553
v  -12.5000 -12.9410 -48.2963
# 4 vertices
 
vn -0.0000 -0.5000 -0.8660
# 1 vertex normals
 
vt 0.2500 0.0000 1.0000
vt 0.3333 0.0000 1.0000
vt 0.3333 1.0000 1.0000
vt 0.2500 1.0000 1.0000
# 4 texture coords
 
g 9
usemtl wire_088199225
s 8
f 37/37/10 38/38/10 39/39/10 40/40/10 
# 1 polygons
 
#
# object 10
#
 
v  12.5000 12.9409 -48.2963
v  12.5000 -12.9410 -48.2963
v  -12.5000 -12.9410 -48.2963
v  -12.5000 12.9409 -48.2963
# 4 vertices
 
vn 0.0000 -0.0000 -1.0000
# 1 vertex normals
 
vt 0.1667 0.0000 1.0000
vt 0.2500 0.0000 1.0000
vt 0.2500 1.0000 1.0000
vt 0.1667 1.0000 1.0000
# 4 texture coords
 
g 10
usemtl wire_088199225
s 8
f 41/41/11 42/42/11 43/43/11 44/44/11 
# 1 polygons
 
#
# object 11
#
 
v  12.5000 35.3553 -35.3554
v  12.5000 12.9409 -48.2963
v  -12.5000 12.9409 -48.2963
v  -12.5000 35.3553 -35.3554
# 4 vertices
 
vn 0.0000 0.5000 -0.8660
# 1 vertex normals
 
vt 0.0833 0.0000 1.0000
vt 0.1667 0.0000 1.0000
vt 0.1667 1.0000 1.0000
vt 0.0833 1.0000 1.0000
# 4 texture coords
 
g 11
usemtl wire_088199225
s 8
f 45/45/12 46/46/12 47/47/12 48/48/12 
# 1 polygons
 
The accompanying MTL file looks like this :

Code: Select all

 
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 02.08.2016 16:37:53
 
newmtl wire_088199225
    Ns 32
    d 1
    Tr 0
    Tf 1 1 1
    illum 2
    Ka 0.3451 0.7804 0.8824
    Kd 0.3451 0.7804 0.8824
    Ks 0.3500 0.3500 0.3500
 
Then, I loaded the mesh from Irrlicht like this :

Code: Select all

 
    scene::IAnimatedMesh* wheelMesh = device->getSceneManager()->getMesh("./Resources/twelvesidedwheel.obj");
    IMeshSceneNode* wheel = smgr->addMeshSceneNode(wheelMesh->getMesh(0),
                                                  0, // parent
                                                  -1, // id
                                                  vector3df(0, 0, 0), // position
                                                  vector3df(0, 0, 0), //rotation
                                                  vector3df(4.0f, 4.0f, 4.0f) // scale
    );
 
    wheel->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
    for(int i = 0; i < wheel->getMaterialCount(); i++) // Material count value is 12
    {
      wheel->getMaterial(i).TextureLayer[0].Texture = driver->getTexture("./Resources/Test.png");
    }
 
Since I had 12 material count for the mesh, I was expecting to assign a texture to each material, and have each of the twelve side of the mesh showing the texture, but to my surprise, the effect achieved was that the TEST.PNG texture looked streched around the entire polygon, as if I had textured it with a single texture.

I finally got it to work by adding the following line inside my loop :

Code: Select all

wheel->getMaterial(i).getTextureMatrix(0).setTextureScale(12.0f, 1.0f);
That is, I had to scale each texture twelve-fold, coincidentally the number of materials I have for the mesh.

What I'm trying to achieve is to have a X-sided polygon that I can texture each side independently. Given that we're both inexperienced in 3D engines (I have a lot of experience in 2D that I'm trying to port to Irrlicht, and the animator is experienced in making high resolution models for prerendering in 2D games), I'm sure we did something wrong. The fact that I could import a polygon in Irrlicht and that it had the correct count of material encourages me, though.

Did we take the good approach? Is it default behaviour to have to scale each texture when there's that much material count? Should we have done something with our model in 3DSMax to have texture scaling working correctly once it's imported? Is OBJ a good exporting format, or should we use something else?

As a side question, is there a good tutorial aimed at 3DS Max animators who wish to create models for Irrlicht? I found a few in the forum, but it's more advanced, and we need to start from the base.

Any help would be appreciated. Thank you in advance!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Fused mesh after export from 3DSMax

Post by CuteAlien »

Hm, not seeing anything wrong in the .obj file on first view. I will need to find some time for debugging this. If you can triangulize before export it won't hurt. Seems to use quad faces right now. Irrlicht will try to triangulize those, but usually better to do that in the tool if possible (with quads nothing should go wrong, but if there are later also concave faces in the model then Irrlicht won't handle it correct).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Fused mesh after export from 3DSMax

Post by mongoose7 »

Have a look at your texture coordinates (vt). They should be 0 and 1 in the ideal case. The range (eg .25 - .33) is 1/12, which is why scaling by 12 works. But it is in the original assignment where the problem is.

No need to triangulate quads as the algorithm is really simple. Quads can't be concave!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Fused mesh after export from 3DSMax

Post by CuteAlien »

OK, just looked at it again and I noticed the uv-coordinates in the obj-file are a little strange (the 'vt' values). The v part is ok going from 0 to 1. But the u part is indeed each only describing 1/12th of the texture. If you want a full texture on each side that part should also go from 0 to 1. Can't really help with texturing or export in 3DsMax, but maybe helps to know that the .obj file already has the wrong values. Meaning inside Irrlicht you don't do anything wrong.

Also it exports with u,v,t - Irrlicht ignores the t currently (but it's always 1 in your case so that shouldn't matter).

edit: mongoose7 was a little faster ;-) And yeah - for quads it works as I said. But that is because it's a simple model that only has quads - so for more complicated models it's better to be save and triangulize on export.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Fused mesh after export from 3DSMax

Post by MartinVee »

Excellent! I am not familiar with the OBJ format, so thanks a lot for pointing that out!

We'll try to fiddle with 3DSMax's export options and see if we can get it to work. I'll also post the steps if we ever get it to work.

A little bit off-topic here, I'd like to say that so far, I'm really impressed by the forum, the quality of the answers we get there, and the friendliness of the community!
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: Fused mesh after export from 3DSMax

Post by AReichl »

It's only because of the picture of your avatar - evolution forces us to be friendly to such a nice guy.
Post Reply