Dynamically changing Materials
by Vincent BILLET · in Torque Game Engine Advanced · 04/18/2006 (9:06 am) · 4 replies
I have a material defined like this :
How can I change "On the fly" (with scripts) the specular color ? (somthing like specular[0] = "1 1 1 1";)
*Edit : Or specularPower.
new Material(grass2)
{
baseTex[0] = "grass2";
translucent[0] = true;
translucentZWrite = true;
emissive = true;
specular[0] = "0.5 0.5 0.5 0.5";
specularPower[0] = 32.0;
};How can I change "On the fly" (with scripts) the specular color ? (somthing like specular[0] = "1 1 1 1";)
*Edit : Or specularPower.
#2
05/10/2006 (9:50 am)
This is untested, but does this work?%myGrassMaterial = new Material(grass2)
{
baseTex[0] = "grass2";
translucent[0] = true;
translucentZWrite = true;
emissive = true;
specular[0] = "0.5 0.5 0.5 0.5";
specularPower[0] = 32.0;
};
%myGrassMaterial.specular[0] = "1 1 1 1";
#3
05/11/2006 (8:29 am)
Thanks, but no that doesnt work, at least not entirely. I tried something similar, adding functions inside the material script to change material flags, specular, textures, etc. I can turn on some things. I can toggle glow on and off for instance (reloadMaterials()), but some things like a texture change to the material never take effect. I am looking at the waterblock code and monkeying with that . All of the water block data members I have tried so far are accessible through script at runtime.
#4
www.garagegames.com/mg/forums/result.thread.php?qt=44485
05/20/2006 (12:54 pm)
Look here to see if this helps. I have the toggleshader funtion turning the sahder and all properties off/on. If you look closely you will see that there is a reinit() function call. You probably have to call this after changing the specular[0] value. www.garagegames.com/mg/forums/result.thread.php?qt=44485
Torque Owner JPaxson
I also have need of this sort of functionality. I'd rather not delete my object and create a new one with a different material if there is a way around it. Surely someone in the community has done this. Any pointers would be appreciated.