[Closed] Script for material changes
Hello,
Hope that somebody wil help me. I need to know how to make script which woud automaticly assign materials to all obj. It shoud be called on beggining of every frame. Where it shoud be created ? Do I need some “scriptholder” for this? I am new in scripting so please help. I only know that ther will be some deffinition for state of thos slats /Some sort of IF comand/ and definition on which material it shoud change /Some sort of … then $obj.material = $objA.material …/ But how I make it run in scene and care for changes ? / Something as a loop maybe? / How shoud it be done? I am more interrested in philosophy of scripting so please help.
Why I need to do it: I woud like to make advice board made from 126 slats. I woud like to create 3-4 for every position /Then I woud like to do only animations./ and let the script care for changes of materials. So first slat /with material no.1/ becomes slat no.5 /with material no.5 on it/ after it will do his job. Hope I made myself clear. And Thanks for help.
Please help. This script will not control any value so where shoud I put it? I allready know how to make script like this but to what shoud I attatch it to? Is it possible? Help.
So I made it with registertimecallback.
Something to put things clear:
I woud like to do this. I have 126 slats on 126 paths and I woud like to change theyr materials every time they come over end of path. This is allready done. And work well /5 days of learning and triing/. But I have trouble to use this rig in renderer.
This is script:
callbacks.removeScripts id:#zmenMaterial
funkcia = ” A = $A* as array
“
funkcia += ” for obj in A do
“
funkcia += ” case of
“
funkcia += ” (
“
funkcia += ” (obj.pos.controller.Path_Constraint.controller.percent <= 90) : obj.material = $Vzor1.material
“
funkcia += ” (obj.pos.controller.Path_Constraint.controller.percent <= 190) : obj.material = $Vzor5.material
“
funkcia += ” (obj.pos.controller.Path_Constraint.controller.percent <= 290) : obj.material = $Vzor9.material
“
funkcia += ” (obj.pos.controller.Path_Constraint.controller.percent <= 390) : obj.material = $Vzor13.material
“
funkcia += ” (obj.pos.controller.Path_Constraint.controller.percent <= 490) : obj.material = $Vzor17.material
“
funkcia += ” (obj.pos.controller.Path_Constraint.controller.percent <= 590) : obj.material = $Vzor21.material
“
funkcia += ” )”
callbacks.addscript #postRenderFrame funkcia id:#zmenMaterial
This change material only after last frame is rendered. What did I do wrong? And what can I do bether? is it possible?
I read in the documentation that we cannot change an object in the #postRenderFrame callback…
But intrigued by this problem, I looked for a function which modifies the scene in every frame. Here is what I found:
Here is a script that change the color of the objects along a path:
callbacks.removescripts id:#changeMat
txt=
"for obj in geometry do
(
if obj.material!=undefined do
(
if classOf obj.pos.controller==Path_Constraint do
(
comp=(obj.pos.controller.percent)*2.55
newColor=color comp comp comp
obj.material.diffuse=newColor
)
)
)"
callbacks.addscript #preRenderEval txt id:#changeMat
hope this helps!
Hi stefan. There may be an easier way to do this other than max script. Did you know you can change textures every frame just with the material editor?
If you set up a .ifl file with the texture list, you can use this as a slot in your material.
Have you used them before? Even if it doesn’t work this way, you could probably use that with a script.
Thanks All for response and help.
prettyPixel: I tried this and do not know if I did something wrong. But looks like this is also called affter geom /and Materials/ are send to render. Also After render callbacks is called after render but not affter frame was rendered. But thanks.
erilaz: I thougt about this. Do not know why I did not choose this way. I had my reasons but can’t remember what whey were. Thanks.
But with help of frends here we putted together material change script with per frame render. It will not work on server machines but it is OK /not long render times./ Not wrong for first script in my live /Hard 7 days/.