PDA

View Full Version : Altering materials in a loop...

 cbass03-27-2008, 05:40 AMHi Everyone, I’m trying to figure out how to assign a material color to scripted objects. I got it to work in the following… ---------------------------------------------------------- for i=1 to 10 do ( b = box() move b [0,i*40,0] c=standardMaterial() c.Diffuse=color 250 (i*10) 75 b.Material=c ) ---------------------------------------------------------- However the following does not work… ---------------------------------------------------------- a = 1.0 b = 1.9 c = 1.0 d = 1.0 x = 0.1 y = 0.1 z = 0.1 for i = 1 to 220 do ( xnew = sin(y*b)+c*sin(x*b) ynew = sin(x*a)+d*sin(y*a) znew = cos(x*c)+d*sin(y*c) x = xnew*55 y = ynew*55 z = znew*55 s= Box length:(random 10 50) width:(random 10 50) height:(random 10 50) s.lengthsegs = 5 s.widthsegs = 5 s.heightsegs = 5 addModifier s (turbosmooth iterations: 2) move s [x,y,z] c=standardMaterial() c.Diffuse=color 250 (i*10) 75 s.Material=c ) ---------------------------------------------------------- I keep getting the error -- Error occurred in i loop -- No ""*"" function for Standardmaterial:Standard and I'm not sure why. If I remove the last three lines, it works fine (although obviously I don't get the color I'm looking for). Why would adding the material information cause an error in the loop? I’m sure it’s a simple explanation. Its just beyond me right now. Any suggestions? TIA, Carlo
Zbuffer
03-27-2008, 06:35 AM
that's because the variable c is used twice in the loop
first you say c = 1.0 (outside the loop), then
c=standardMaterial()

so it errors in the second iteration of the loop on line
znew = cos(x*c)+d*sin(y*c)
since now c is a standard material

cbass
03-27-2008, 07:36 AM
Zbuffer,

I can't believe I didn't spot that.

I guess such are the dangers of using "a" "b" "c" and other nondescript names for variables.

Thank you so much for your help. I will sleep well tonight!

Carlo

CGTalk Moderation
03-27-2008, 07:36 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.