multiple textures on one mesh

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
Stedy80
Posts: 5
Joined: Mon Jun 11, 2012 7:00 pm

multiple textures on one mesh

Post by Stedy80 »

Hi everybody,
(sorry for my English ahead, it's not my main language:))

I'm a quiet experienced C++ programmer, but new to Irrlicht
I made the tutorials and little own games with the default media and everything worked just fine.

Now I created a simple mesh with Google Sketchup and exported it as Collada.
It couldn't be loaded direct (maybe too new Collada version or something), so I imported and exported it as Maya .obj in Cobbercube.
My problem is, there is one mesh, but multiple textures, which are at different locations (vertices) of the mesh.
In the things I tried before, there was always one texture and one mesh (like Sydney in media).

How can I apply the diffent textures to one mesh in Irrlicht?

The member function ISceneNode::setMaterialTexture() has an argument "layer", but I don't think I need different layers, it's just multiple textures all in the same layer.

Thanks for any help!

regards Stedy
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Re: multiple textures on one mesh

Post by nespa »

you can have multiple materials on the mesh;
if your mesh is a solid material one, each material has 1 texture layer;

if you have n materials :

ISceneNode* Entity=......// your mesh node;
ITexture* Texture_0 = ....//your texture 0;
ITexture* Texture_1 = ....//your texture 1;
..................................................

ITexture* Texture_n = ....//your texture n;

then:

Entity->getMaterial(0).setTexture(0,Texture_0);
Entity->getMaterial(1).setTexture(0,Texture_1);
..........................................................

Entity->getMaterial(n).setTexture(0,Texture_n);
Stedy80
Posts: 5
Joined: Mon Jun 11, 2012 7:00 pm

Re: multiple textures on one mesh

Post by Stedy80 »

Thanks, that helped.

But in my simple Sketchup model there were 11 Materials exported. Dunno why, I just made a very basic house with the walls and the roof.
I found out, that my walls were Material at index 2, and the roof was index 3 (at sceneNode->getMaterial())

I wonder, how I can easily find out which Material index belongs to what part of the Model.
I there some kind of information (about texture) applied to different materials when I load the mesh via ISceneManager::getMesh ?
I am not an expert in 3d mesh file formats, but I think in some formats there is a direct binding between mesh and texture, so can I somehow find out this information (without writing an own mesh loader)?
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: multiple textures on one mesh

Post by CuteAlien »

Iff you have for example 2 different textures at different places in your mesh then there are 2 materials created (or n materials for n textures). The mesh is made of meshbuffers - and each meshbuffer has exactly one materials. So you have to find the right meshbuffer (for example checking for the texturenames of it's material) and then you can change the texture of that material.

The texture layers are needed when you have more than one texture at the same place which are then combined (for example for more details or for lightmaps).

Also if you have non-working collada I'm always glad to check them if you send those to me. If you tried with Irrlicht 1.7 you could also try using svn trunk as Collada support already has improved a lot since 1.7.
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
Stedy80
Posts: 5
Joined: Mon Jun 11, 2012 7:00 pm

Re: multiple textures on one mesh

Post by Stedy80 »

So you have to find the right meshbuffer (for example checking for the texturenames of it's material) and then you can change the texture of that material.
I'm loading the .obj mesh, but there are no textures set at all. So I cannot check the texturenames, can I? (If yes, how?)
There are just -in my case- 11 Materials created.

Code: Select all

 
IMesh* mesh = sm->getMesh("../../irrlicht/media/add/sketchupteil.obj");
n = sm->addMeshSceneNode(mesh);
printf("matcount: %i",n->getMaterialCount());   // matcount: 11
for (int i = 0; i < n->getMaterialCount(); ++i){
                        ITexture* t =
                        n->getMaterial(i).getTexture(0);
                        if (t) // t is always 0 in my case
                          printf("name: %s\n",t->getName().c_str());
}
 
So I tried a bit and found out, ok, Material index 2 belongs to texture A, and index 3 belongs to B.
With this knowledge I can set Material 2 and 3 to the right textures.
The only thing, I don't know now, is how to find this thing out, without trying around.
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: multiple textures on one mesh

Post by CuteAlien »

You mean there should be textures and they are not loaded at all? With .obj files the textures are defined in a .mtl file. That .mtl file should be in the same folder. That should already be sufficient - are there any error messages on the console?
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
Stedy80
Posts: 5
Joined: Mon Jun 11, 2012 7:00 pm

Re: multiple textures on one mesh

Post by Stedy80 »

the textures aren't loaded by getMesh. If they should, it's not done.
Yes, there is a mtl file in the same directory as the .obj file.


About the collada: I was not correct when I said, it's not loaded at all. It does load, but there is only 1 Material (this ugly person figure of Sketchup).

I use Irrlicht 1.6.1, maybe I should use a newer version?

edit: there are no errors on the console when loading the files and the pointers (ISceneNode* etc.) are set.

edit2: I looked in the .mtl file; there are only 3 Materials defined (2 Materials of mine and this Sketchup figure, which is ok).
But in the .obj it seems like, there are 11 Materials defined.
Maybe there was a problem while CobberCube exported to Maya
Post Reply