best way to store multiple material sets

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
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

best way to store multiple material sets

Post by lumirion »

If I want to keep two or more sets of materials in my mesh, like different colors of clothing, and switch them while the program runs, the geometry remains the same.
what is the best way to store multiple sets of materials for a mesh's buffers?

Would it be best to store information to generate the materials on the fly when I switch sets?
Or should I store fully configured materials and index to them when I want to change suits?
Mitchell M
Posts: 15
Joined: Sat Jul 06, 2013 2:18 pm

Re: best way to store multiple material sets

Post by Mitchell M »

I'm not completely sure but shouldn't you be able to load a bunch of materials while the program is loading stuff a long with the mesh you are using like this.

Code: Select all

 
IAnimatedMesh *meshYouAreUsing = sceneManager -> getMesh("whereFileIs.b3d");
 
ITexture *texture1 = videoDriver -> getTexture("texture1");
ITexture *texture2 = videoDriver -> getTexture("texture2");
ITexture *texture3 = videoDriver -> getTexture("texture3");
 
IAnimatedMeshSceneNode *node = sceneManager -> addAnimatedMeshSceneNode(meshYouAreUsing);
 
//If we wanted to start the model off with the first texture
node -> setMaterialTexture(0, texture1);
 
 
and then in the animation loop whenever you want to switch to a different texture

Code: Select all

 
if(clothing==1)
{  node -> setMaterialTexutre(0, texture1);   }
else if(clothing==2)
{  node -> setMaterialTexutre(0, texture2);   }
else if(clothing==3)
{  node -> setMaterialTexutre(0, texture3);   }
 
 
NemoStein
Posts: 17
Joined: Mon Aug 11, 2008 12:04 am

Re: best way to store multiple material sets

Post by NemoStein »

I thought the exactly same thing...
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: best way to store multiple material sets

Post by lumirion »

Yes that can be done. I am considering doing that with the full SMaterial which includes all the textures and all blend, lighting, culling flags for a mesh's buffer. My mesh has several buffers / submeshes so I would need to store several SMaterials per mesh buffer for several mesh buffers.
Or is it better to store just the ITextures and store material atributes to be applied when an SMaterial is generated or converted at switch?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: best way to store multiple material sets

Post by CuteAlien »

One way you could also use is to create a node for each material. Meshes are shared anyway and IMeshSceneNode's by default overwrite the mesh-materials. It's a few bytes extra-data, but not that much that it should matter too much. Then you can add/remove the active nodes to the scenegraph (and not delete the removed nodes, but just grab() them and keep them around in some array for example).
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
Post Reply