[Closed] Script Request – Material ID Cycler
Hi i’m wondering if anyone could help me and construct a modifier script that allows me to cycle Material IDs over time?
Let’s say i have a stair were each step is an unique material ID and colour (with multiSub material.) For each frame (or given interval of frames) each material ID (step) should cycle to the next Material ID number (or by given value perhaps,) and the last ID in the cycle should start from the beginning again creating an animated loop.
If you could apply it like a modifier to any object would be great!
I searched for such a script but couldn’t find any, it surprises me no one has made one like that, or at least made one public, since i imagine it wouldn’t take too much work to create such script if you got the knowledge.
Thanks in advance and i hope someone can help me out. If i had got more time i would figure it out myself but since i’m in a hurry i don’t have time for that now :bowdown:
The problem with this script is that neither assignment of polygon material IDs nor the ID values in a Multi/Sub-Object material are animatable. Potentially, there might be some complicated hacks arounds this, but I imagine this is the reason why you have not found anything like it already.
You can use the “Material” modifier, and set keyframes for switch the material IDs. For example, assign a multisub material to an object, apply the material modifier to that object, and then you can just autokey changes to the material at frame n.
for example, here’s a script that just creates a teapot, and animates/changes the material ideas of the object,
refObj = teapot wirecolor: [0,0,124]
addModifier refObj (Materialmodifier())
multiMatforObj = meditMaterials[8] = Multimaterial numsubs: 3
multiMatforObj[1] = meditMaterials[9] = standard diffuse:[255,0,0]
multiMatforObj[2] = meditMaterials[10] = standard diffuse:[0,255,0]
multiMatforObj[3] = meditMaterials[11] = standard diffuse:[0,0,255]
refObj.material = multiMatforObj
with animate on at time 20
(
refObj.modifiers[#Material].materialID = 1
)
with animate on at time 60
(
refObj.modifiers[#Material].materialID = 2
)
with animate on at time 80
(
refObj.modifiers[#Material].materialID = 3
)
Hopefully this helps.
Good day :)
Yes i know that one, but a stair with all the steps separated and all with unique modifiers that are animated is a bit tedious to handle.
Perhaps it is. It would be useful none the less.
Another approach to this is through UV’s.
If you map all the faces of the stairs per stair to 1 pixel, then you could animate the UV coordinates over a texture where the offset changes the color.
Maybe best explained with a sample file: colorByUV_max2010.zip
Steps:
- planer map
- break all edges in unwrapUVW
- scale each face to zero (or something very small)
- animate offset with UVWxform
The distance between the UV “dots” offcourse determines the color it gets from the texture (gradient ramp set to step in this instance), but it could get color from every source. Something like this can be scripted easily I think. But if it’s just one instance, you could do it manually and it gives you “artistic freedom”
Hope it helps,
-Johan