Multitexturing?

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
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Multitexturing?

Post by sanctus2099 »

Okay... so I know how the ideea works just I don't know how to do this with irrlicht.
So i have a chracter... and it has skin hair bla bla bla...
The thing is I want to be able to choose the hair(that is modified my a texture). So how do I apply a texture to some polygons(not all just a surface).
Thank you
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

you can only apply textures to mesh buffers not to single vertices !!!
so your hair (for example) must be a mesh buffer, then you can get the mesh buffer with Irrlicht and apply a new texture to it...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Post by sanctus2099 »

You lost me :|
Could you please make a small example?
And if I have both the hair and the rest in file can I do that? And will they remain animated?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

sanctus2099 wrote:You lost me :|
Ohh, I'm sorry :lol:

sanctus2099 wrote:And if I have both the hair and the rest in file can I do that? And will they remain animated?
of course, if you create a mesh in an editor and you apply multiple textures to it then every texture uses a seperate mesh buffer, that's how multi texturing works... ;)
then you load the mesh as usual and create a node...
from this node you can get the mesh:

Code: Select all

IAnimatedMesh* mesh = node->getMesh();
then you can get the mesh buffers from this mesh:

Code: Select all

IMeshBuffer* mbuf = mesh->getMeshBuffer(0); // 0 for the first buffer (texture)
and finally you can set a new texture to this mesh buffer:

Code: Select all

mbuf->getMaterial().setTexture(0, texture);
this should work, but remember I did this all from the top of my head... ;)
Last edited by Acki on Fri Jan 04, 2008 5:36 pm, edited 1 time in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Split your character to "character" and "hair" (maybe more parts if you want to exchange other parts too) and then put them together in the engine - not in your 3d editor. Then just assign a different hair texture to your hair mesh buffer.
LosNir
Posts: 43
Joined: Wed Dec 19, 2007 6:38 pm
Location: Israel
Contact:

Post by LosNir »

Whats the problem with modifying the texture image?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Modifying the texture image would be slow, you'd be changing the pixels and uploading them. You'd also be editing all surfaces that have that texture. It would also be ugly unless you're doing a direct copy, so it's best to do texture manipulation on the hardware using a render target.
Acki's method is the simplest and best, just have a one pixel hair texture that you use for all your models, search for the dummy texture at load time and replace it with a custom one.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

If you assign different texture for hair and rest of the character in your modeling program than Irrlicht will create separate mesh buffers for them on its own. Only thing you then need to do is to find which mesh buffer contain hair texture which can be done by simple trial and error method.

Basic structure of mesh scene nodes is as follows:

scene node contain mesh (pointer to one)
mesh contain one or more mesh buffers
mesh buffer contain material (as well as vertices indices and bounding box)
material contain texture

You may look at this objects: SMaterial, IMeshBuffer, SMeshBuffer, IMesh, SMesh

IAnimatedMeshSceneNode which you are probably using have getMesh() function which returns pointer in to IAnimatedMesh use its interface to change texture.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Re: Multitexturing?

Post by dlangdev »

sanctus2099 wrote:Okay... so I know how the ideea works just I don't know how to do this with irrlicht.
So i have a chracter... and it has skin hair bla bla bla...
The thing is I want to be able to choose the hair(that is modified my a texture). So how do I apply a texture to some polygons(not all just a surface).
Thank you
in your modeling program, group your polygons into materials, by selecting vertices and setting a group name to these vertices, at the same time, do create a material to those vertices as well, then uv map those same vertices.

repeat the same steps until all your polygons have been assigned.

in your code, get a reference to your material and then load the texture to that material. with that, you can make it dynamic so much so that you can code it in such a way that any texture can be loaded on a material of your choice.

isn't that amazing? you should pat yourself on the back for doing that hard stuff.

but wait...

you can shorten your flow by simply using irredit to do the scene setup and from there you simply load the irr file later.


;-)
Image
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Multitexturing?

Post by christianclavet »

sanctus2099 wrote:Okay... so I know how the ideea works just I don't know how to do this with irrlicht.
So i have a chracter... and it has skin hair bla bla bla...
The thing is I want to be able to choose the hair(that is modified my a texture). So how do I apply a texture to some polygons(not all just a surface).
Thank you
Hi Sanctus2099.

This is pretty simple. You don't do it in IRRlicht! :wink:
You have to do it in a modeler software (Blender, 3Ds, Lightwave, etc.)
You select your polygons in the software, then create a new surface for them.

You will have to export it so that IRRlicht can read it. Surface definitions once defined in the modeler are available inside IRRlicht. So you could change the texture dynamicaly.
Post Reply