load 3D-Model in Xith3d

hi

I’ve downloaded really cool .max models of space ships. I would really like to load them in Xith3D. I know .max is a closed format, so I’ve loaded the 30day test version of 3DS-Max 8 to export them to a usable format. I tested the .3ds format but some model parts were moved a bit and the textures weren’t loaded steadily. So I tried the .obj format which I can also load in blender. The geometries were fine but the textures haven’t been loaded. I also tried the .ase format but the export was totally broken (or for some other reason not loadable by xith).

What is the best format to use with xith3d? What is the best way to convert a .max model (with textures)? What can I do to make the OBJLoader also load the textures (an .mtl file exists and was found by the loader!)?
Is there a page where I can download free suitable space ship models for non commercial use?

Thanks a lot in advance,

Qudus

Oh, by the way. Here is my coding to load the model:


File modelFile = new File("model.obj"); // there's a model.mtl in the same path (created by 3ds-max obj-export)
Scene model = null;
try
{
    model = (new OBJLoader2().load(modelFile.getAbsolutePath()));
}
catch(Exception e)
{
    e.printStackTrace();
}
myGroup.addChild(model.getSceneGroup());

AmbientLight light1 = new AmbientLight(true, new Color3f(0.5f, 0.5f, 0.5f));
DirectionalLight light2 = new DirectionalLight(true, new Color3f(Color.GRAY), new Vector3f(0, -1, 0));
myGroup.addChild(light1);
myGroup.addChild(light2);

In my experience, Wavefront OBJ is the best format for static geometry for compatibility between Blender3D and Xith3D. There are some issues like the name of the texture file isn’t included in the .mtl file, so you just have to add a line :


map_Kd your_texture_file.jpg

At the beginning of the .mtl file. It’s a bug in the Blender export and I think it can be fixed pretty easily (you just have to know where .mtl files are written in the python script and read blender doc to know which function is it to obtain texture’s filenames).

I exported it from 3DStudio Max. Well, anyway. thanks for the reply. I will try it this evening.

You can anyway check if this line is in the file exported by 3DS Max.

OK. I tried it. I put all image filenames I could find in the model folder into the mtl file.


# Max2Mtl Version 4.0 Mar 10th, 2001
map_Kd Antriebs.bmp
map_Kd antriebs.tif
map_Kd Bugbump.gif
map_Kd BugFbump.gif
...
#
# EOF

Now I seems to load the textures, but when I start my game and it loads the model, TextureLibLoader crashes with a NullPointerException ant line 158.


app.setTexture ( texture );

Of course app is the pointer which is null. I registered the model path on the TextureLoader.tf to be sure, that this is not the problem. Is it a failure in this class or am I doing something wrong?

How can I know from the .obj file which filenames to put in the .mtl file?

What TextureLibLoader are you talking about ? There’s TextureLoader and MaterialLibLoader, but no TextureLoader.

Open the .obj file in a text editor there’s a reference to the .mtl file.

[quote="<MagicSpark.org [ BlueSky ]>,post:6,topic:27530"]
What TextureLibLoader are you talking about ? There’s TextureLoader and MaterialLibLoader, but no TextureLoader.
How can I know from the .obj file which filenames to put in the .mtl file?
[/quote]
I’m talking about “org.xith3d.loaders.obj.MaterialLibLoader2” of Xith3D Version 0.7.1.

[quote="<MagicSpark.org [ BlueSky ]>,post:6,topic:27530"]
Open the .obj file in a text editor there’s a reference to the .mtl file.
[/quote]
Yes, I know, there’s a reference to the mtl file, but that looks like this:


# Max2Mtl Version 4.0 Mar 10th, 2001
#
# EOF

This is the whole file. So it’s actually empty, I think.

the .obj file looks like this:


# Max2Obj Version 4.0 Mar 10th, 2001
#
mtllib ./mymodel.mtl
g
# object PART.33_fa to come ...
#
v  139.225555 -4.167515 -654.796082
v  139.225555 11.052685 -654.796082
v  139.225555 -4.167515 -534.725647
v  267.972839 11.052685 -654.796082
v  139.225555 11.052685 -534.725647
v  268.844269 0.957668 -534.725647
v  278.669678 -4.167530 -592.962769
v  267.771332 -4.167515 -654.796082
v  268.538055 4.581276 -654.796082
v  278.878021 11.052670 -592.975525
v  269.169556 4.682167 -534.725647
v  268.396637 -4.167530 -534.725647
v  275.653473 -4.167530 -575.864075
v  268.611267 11.052685 -534.725647
# 14 vertices

vn  0.000000 0.000000 1.000000
vn  0.000000 0.000000 1.000000
vn  0.000000 0.000000 -1.000000
vn  0.000000 0.000000 1.000000
vn  0.000000 0.000000 -1.000000
vn  0.000000 0.000000 -1.000000
vn  0.000000 1.000000 0.000000
vn  0.000000 0.000000 1.000000
vn  0.000000 0.000000 1.000000
vn  0.000000 -1.000000 -0.000000
vn  0.000000 0.000000 -1.000000
vn  0.000000 0.000000 -1.000000
vn  0.000000 1.000000 0.000000
vn  0.000000 0.000000 -1.000000
# 14 vertex normals

g PART.33_fa
usemtl MAT3
f 6//6 3//3 5//5
f 3//3 6//6 12//12
f 11//11 5//5 14//14
...

I think, I’ll have to put these MAT3 references into the .mtl file. But I don’t know the syntax.

Just do like that :slight_smile: :


# Blender MTL File: tente.blend
# Material Count: 4
newmtl Herbe_herbe.png
Ns 96.0
Ka 0.0 0.0 0.0
Kd 0.64 0.64 0.64
Ks 0.0 0.0 0.0
Ni 1.0
d 1.0
illum 1
map_Kd herbe.png


newmtl Affiche_Embleme2+titre.jpg
Ns 96.0
Ka 0.0 0.0 0.0
Kd 0.64 0.64 0.64
Ks 0.5 0.5 0.5
Ni 1.0
d 1.0
illum 2
map_Kd Embleme2+titre.jpg


newmtl Tente
Ns 18.0
Ka 0.0 0.0 0.0
Kd 0.8 0.8 0.8
Ks 1.033557 1.033557 1.033557
Ni 1.0
d 1.0
illum 2


newmtl Wood_Wood.jpg
Ns 96.0
Ka 0.0 0.0 0.0
Kd 0.425879 0.18532 0.064957
Ks 0.19824 0.194584 0.194584
Ni 1.0
d 1.0
illum 2
map_Kd Wood.jpg

I really thank you very much for your bothering. But I don’t understand that. Could you please comment the lines.

Excuse me I could have been clearer. So your .mtl file is empty, then big deal, you have to fill it yourself (bloody export script, don’t mind).
So your actual .mtl file looks like this :


# Max2Mtl Version 4.0 Mar 10th, 2001
#
# EOF

And your .obj file do a reference to something named MAT3… So the first thing to do is to declare a new material… Your .mtl file just looks like this now :


# Max2Mtl Version 4.0 Mar 10th, 2001
#
newmtl MTL3
# EOF

Then you can add the following lines to adjust the material settings :


Ns 96.0 // Shininess
Ka 0.0 0.0 0.0        // \
Kd 0.64 0.64 0.64 // These three are probably for light (ambient, diffuse, specular)
Ks 0.0 0.0 0.0        // /
Ni 1.0 // Don't know what does it mean
d 1.0 // Alpha value : 1 means completely opaque
illum 1 // Don't know what does it mean
map_Kd texture.jpg // Your texture file, path relative to your .mtl file

(inspired by this page : http://zoo.cs.yale.edu/classes/cs490/00-01a/mcnamara.antoine.amm43/mtl.html and my very own knowledge ^^)

Good luck !

Thank you very much.

I think. I will come to grips with that. Except one thing.