AB4D Forum
Temporary replace material on MultiMaterialModelNode - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab4d.SharpEngine (https://forum.ab4d.com/forumdisplay.php?fid=12)
+--- Thread: Temporary replace material on MultiMaterialModelNode (/showthread.php?tid=4452)



Temporary replace material on MultiMaterialModelNode - BiMMate - 06-26-2024

Hi

I need to apply a new material to a MultiMaterialModelNode and later on come back to the materiales defined in the submeshes

But I see no way I can edit/replace the material array I provide to the constructor

Is this possible?


RE: Temporary replace material on MultiMaterialModelNode - zacfromaustinpowder - 07-05-2024

Here's an example that might be useful.

var subMesh = node.AddSubMesh(0, 3, StandardMaterials.Red);
subMesh.ChangeMaterial(StandardMaterials.Blue);


RE: Temporary replace material on MultiMaterialModelNode - abenedik - 07-05-2024

Thank you @zacfromaustinpowder for providing an example on how to change the material.

For MultiMaterialModelNode it is recommended to create all possible materials when the MultiMaterialModelNode is created (pass them to the constructor). After that you can simply change the material by changing the index of the material, for example:
Code:
subMesh.MaterialIndex = newMaterialIndex;

But as written by @zacfromaustinpowder, you can also use a new material - in this case call the ChangeMaterial and the code in MultiMaterialModelNode will check if this material was already used (assign an existing index) or create a new index for the new material.

See also the test code in this post to see how to change the materials.
zacfromaustinpowder