[SOLVED] Two textures in the same 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
endless_dark
Posts: 18
Joined: Mon May 04, 2009 12:18 am

[SOLVED] Two textures in the same mesh

Post by endless_dark »

Good afternoon!
Basically what I want to achieve is this:
https://www.youtube.com/watch?v=vQdMTgfCRaQ
I know that this has been asked a thousand of times but for some reason I don't understand or I'm not able to get what is answered.

My artist gave me some .obj house models with a texture (in its .mtl). Then he has provided my with some .tga alpha files showing the windows with the lights on. The goal is to get the effect that the lights are turning on using that texture. If I could even set LIGHTING to false for this lights texture then it would be awesome.

As far as I know, for achieving this I should have 2 SMaterials attached to the node, but I have just one, so If I do this:

Code: Select all

auxNode->getMaterial(0) = someOtherMaterial;
The material changes and everything its ok.

But if I do this:

Code: Select all

auxNode->getMaterial(1) = layerOnTopMaterial;
The material is not shown.

And if I also do this after that:

Code: Select all

printf("matcount: %i\n",auxNode->getMaterialCount());
I always get "1"

I think that the problem is that the node has just 1 material and I'm not able to append the lights material to the material list of the node.

How can this be done? Should I do this coding or should I ask the artist to make the obj models with mutliple materials?
Thank you very much!
Last edited by endless_dark on Sun Aug 24, 2014 5:52 pm, edited 1 time in total.
JLouisB
Posts: 67
Joined: Tue Jul 24, 2012 12:36 pm
Location: France

Re: Two textures in the same mesh

Post by JLouisB »

You can't add a material like this (you can have only one material per mesh buffer), so if your mesh have only one mesh buffer (one material), you can't add a material without add a mesh buffer for your window.
The easiest solution to add a second material is to do this in your 3D modeling software.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Two textures in the same mesh

Post by mongoose7 »

Change the texture in the material. Or have two materials and set the node material to one or the other depending on whether the light is off or on.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Two textures in the same mesh

Post by CuteAlien »

I think you are mixing up materials and textures. Each polygon (or polygon group) has exactly 1 material. You never have 2 materials on the same polygon. Having more materials in a mesh means that you split up your mesh into several meshbuffers (meshbuffer = a bunch of polygons sharing the same material). You use this if you want for example a cube where each side has different textures - then you give each side it's own material.

What you seem to want is something different. As far as I understand you want 2 textures on the same polygon. You can put more than one texture into a material. If you check video::SMaterial you will see functions to do that: http://irrlicht.sourceforge.net/docu/cl ... erial.html
Now you also have to tell the material what it should do with the different textures. The simplest solution is to use one of the existing material-types: http://irrlicht.sourceforge.net/docu/na ... 0cbc5430f1
Those describe in which way the textures are combined. If those easy combinations are not sufficient you have to switch to shaders which allow you to program how exactly the textures are combined yourself (you probably don't need this yet).
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
endless_dark
Posts: 18
Joined: Mon May 04, 2009 12:18 am

Re: Two textures in the same mesh

Post by endless_dark »

I finally got it. Thank everyone who posted.

The solution was to edit directly the .obj and .mlt files to copy and paste the main material several times but changing the JPG or TGA files associated to them. Then in my code I can switch them on/off, individually.
Post Reply