Page 1 of 1

Multitexturing?

Posted: Fri Jan 04, 2008 3:06 pm
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

Posted: Fri Jan 04, 2008 3:22 pm
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...

Posted: Fri Jan 04, 2008 3:53 pm
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?

Posted: Fri Jan 04, 2008 5:35 pm
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... ;)

Posted: Fri Jan 04, 2008 5:35 pm
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.

Posted: Fri Jan 04, 2008 7:56 pm
by LosNir
Whats the problem with modifying the texture image?

Posted: Fri Jan 04, 2008 8:35 pm
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.

Posted: Sat Jan 05, 2008 10:53 am
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.

Re: Multitexturing?

Posted: Sat Jan 05, 2008 11:58 am
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.


;-)

Re: Multitexturing?

Posted: Mon Jan 07, 2008 1:45 pm
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.