www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Aksiom on May 16, 2014, 01:55:34 pm

Title: Load materials to a OBJ model
Post by: Aksiom on May 16, 2014, 01:55:34 pm
Hi,

first I want to say that jPCT rocks. I really appreciate your work!
The problem I have is this:

I load an .obj model together with the .mtl file but the I cant find a way to apply the materials:

This is my code:
Code: [Select]
        try {
       object = loadModel("untitled.obj", "untitled.mtl", 0.1F);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextureManager.getInstance().addTexture("carpaint");

object.build();
world.addObject(object);

I saw many solutions on how to load textures but I cant find a way to load materials that are no textures. I want to know how it is done.
The documentation says:

Quote
If the materials used in the file are not using textures, small, single colored textures will be generated that represent the diffuse colors of the materials

I hope my question is clear. I have no images that i want to use as materials, so when i create a Texture I dont know what path should i input. I tried several combination but nothing worked.

This is how the material looks lik in the mtl file:
Code: [Select]
newmtl carpaint
Ns 52.941176
Ka 0.000000 0.000000 0.000000
Kd 0.627200 0.627200 0.627200
Ks 0.900000 0.900000 0.900000
Ni 1.000000
d 1.000000
illum 2

The logcat shows that it loads all the materials:

Code: [Select]
05-16 14:04:29.328: I/jPCT-AE(30571): GL context is 1095754872
05-16 14:04:29.328: I/jPCT-AE(30571): OpenGL vendor:     ARM
05-16 14:04:29.328: I/jPCT-AE(30571): OpenGL renderer:   Mali-400 MP
05-16 14:04:29.328: I/jPCT-AE(30571): OpenGL version:    OpenGL ES-CM 1.1
05-16 14:04:29.328: I/jPCT-AE(30571): OpenGL renderer initialized (using 2/8 texture stages)
05-16 14:04:29.333: I/jPCT-AE(30571): Adding Lightsource: 0
05-16 14:04:29.333: I/jPCT-AE(30571): Loading file from InputStream
05-16 14:04:29.338: I/jPCT-AE(30571): Text file from InputStream loaded...1991 bytes
05-16 14:04:29.338: I/jPCT-AE(30571): Processing new material black!
05-16 14:04:29.343: I/jPCT-AE(30571): Processing new material blue!
05-16 14:04:29.348: I/jPCT-AE(30571): Processing new material carpaint!
05-16 14:04:29.348: I/jPCT-AE(30571): Processing new material chrome!
05-16 14:04:29.348: I/jPCT-AE(30571): Processing new material clearglass!
05-16 14:04:29.353: I/jPCT-AE(30571): Processing new material interior!
05-16 14:04:29.358: I/jPCT-AE(30571): Processing new material mattemetal!
05-16 14:04:29.358: I/jPCT-AE(30571): Processing new material mirror!
05-16 14:04:29.358: I/jPCT-AE(30571): Processing new material redglass!
05-16 14:04:29.363: I/jPCT-AE(30571): Processing new material rim!
05-16 14:04:29.363: I/jPCT-AE(30571): Processing new material tire!
05-16 14:04:29.363: I/jPCT-AE(30571): Processing new material white!
05-16 14:04:29.368: I/jPCT-AE(30571): Processing new material windowglass!
05-16 14:04:29.368: I/jPCT-AE(30571): Loading file from InputStream
Title: Re: Load materials to a OBJ model
Post by: Aksiom on May 16, 2014, 02:31:18 pm
I found the solution. I feel really stupid now.

I had the ambientLight of the world set to dark.

Code: [Select]
world.setAmbientLight(20, 20, 20);
so I couldnt see the materials at all, after I changed it to

Code: [Select]
world.setAmbientLight(250, 250, 250);
it all worked fine without needing to load any materials. It seems that the jPTC load method loads the materials automatically if it is not a texture image.