Game Development Community

How to change material of an object by pressing a button?

by Ivan Mandzhukov · in Technical Issues · 07/07/2007 (4:05 am) · 7 replies

Hi , experts ,
i need youe help. does anybody know how to change in realtime the meterial of an object by oressing a button from a gui? i've tried to call AddMaterialMapping fron command line of the button but it didn't work. please help!!!

#1
07/07/2007 (5:37 am)
.
#2
07/07/2007 (6:37 am)
SetSkinName....try that, but your shape[dts] must be exported with textures following the code's naming conventions...base.texture.ext. As far as I know, only works with dts shapes, and not all classes either....
#3
07/09/2007 (11:46 am)
Barserk i tried with SetMaterialMapping. the console gives a warning "cannot find function SetMaterialMapping" . i am trying to change shader on an object. the object is a simple sphere exported from 3dsmax in dts format. the sphere is also an item object in Torque. i cannot understand why addMaterialMapping doesn't work in real time . i just use this code on the button function :addMaterialMapping("Sphere", "material: DynCubeSphere2");
and after pressing the button the console gives a warniong "Warning , overwriting material properties for : Sphere" but in fact my object doesn't change its material.
#4
07/09/2007 (12:29 pm)
In stock TGE-A (which it sounds like you are using since you are talking about shaders), materials are compiled just after startup and can't be changed in real time.

There is a patch/resource to activate dynamic material swapping, but you need a source code license to do that.
#5
07/09/2007 (1:24 pm)
AddMaterialMapping is for adding dust color and sound when a player walks over a terrain texture...WAY off :-)
#6
07/09/2007 (7:09 pm)
.
#7
07/14/2007 (10:23 am)
I see, thank you all for the replies. I intend to buy the license soon , Torque is really powerful. I was just exploring the engine capabilities and didn't know if material swapping is possible in real time.