Swap Material IDs

Hi people! i am stuck trying to randomly change the materialid id of an editable poly at certain moments. Im attempting to do a piano that change materials of it keys when is animated.

the listener shows this --$.EditablePoly.setMaterialIndex 1 when i do it manually

but doesnt work.

Any body pls?

THANKS!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

afaik Face Material ID can't be animated, use animated Material modifier instead.

ivan3d32's picture

animate material

oh! i was hoping to animate the keys with mis script and add the material animation at the same time. ill have to use a material modifier within the script. thanks man

jahman's picture

You can also wire the value

You can also wire the value of Material modifier to some animated node like helper or use script controller to set the value dynamically. Here's the example:

delete objects
 
mtl = Multimaterial()
for i=1 to 10 do (
 
	m = Standardmaterial()
	m.diffuse = ([25,25,25] * i) as color
	mtl.materialList[i] = m)
 
pt = point pos:[0,0,10] centermarker:on cross:off wirecolor:yellow
animate on (
 
	at time 0f  pt.pos = [0,0,10]
	at time 99f pt.pos = [400,0,10]
 
)
 
mtlMod = Materialmodifier()
mtlMod.materialID.controller = float_script()
mtlMod.materialID.controller.script = "self = refs.dependentNodes this firstOnly:true
if self == undefined then 1 else (
 
	id = (distance self.pos $point001.pos)/10.0
	id = if id > 10 then 10 else (int)id	
 
)"
 
for i=0 to 20 collect (
 
	b = box width:18 length:50 height:5
	b.pos = i * [20,0,0]
	b.material = mtl
	convertToMesh b
	addModifier b (copy mtlMod)	
	b
 
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.