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?
best way to store multiple material sets
-
- Posts: 15
- Joined: Sat Jul 06, 2013 2:18 pm
Re: best way to store multiple material sets
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.
and then in the animation loop whenever you want to switch to a different texture
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);
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); }
Re: best way to store multiple material sets
I thought the exactly same thing...
Re: best way to store multiple material sets
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?
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?
Re: best way to store multiple material sets
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm