ScriptSpot

Forum topic · Scripts Wanted

Swap Material IDs

By ivan3d32 · 2017-09-09

Description

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 (4)

.

jahman · 2017-09-14

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

animate material

ivan3d32 · 2017-09-15

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 · 2017-09-15

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
	
)

ivan3d32 · 2018-06-13

thanks a lot man! really helped me!