|
![](/i/fill.gif) |
I am working on some timple functions to make my own grass (I want the
challenge of making my own, I know there are some out there already). The
way I'm doing it right now gives me the results I want (it looks like I
want it to look), but the parsing process is very slow due to the nested
loops that I use. I am using splines to calculate the path I want. With
my spline, I simply draw triangles to make up the grass. There is a loops
the goes up the spline, while drawing triangles. This loop is contained in
another loop whose roll it is to create multiple blades. Heck, here is the
source code:
#declare counter=0;
#declare num_blades=12000;
#declare s_point1=<0,0,0>;
#declare s_point2=<0,0,0>;
#declare s_step=.1;
#declare blade_width = .025;
#while( counter < num_blades)
#declare num1=((rand(R2)-.5)*30) ;//-11 ;
#declare num2=0;
#declare num3=(rand(R2)-.5)*30;//- 11 ;
#declare rot = rand(R2)*360;
#declare ctr = 0;
#declare sway=cosd(clock)*.025;
#declare s = spline {quadratic_spline 0, <0,0,0> .5, <0, .5,0> 1, <0,1,.5>
}
#while (ctr < 1)
/*sphere {
<s(ctr).x,s(ctr).y,s(ctr).z>,.02
pigment { rgb <1-ctr,ctr,0> } */
#declare s_point1=s(ctr);
#declare s_point2=s(ctr+s_step);
triangle {<s_point1.x-blade_width,s_point1.y,s_point1.z>
<s_point1.x+blade_width,s_point1.y,s_point1.z>
<s_point1.x-blade_width,s_point2.y,s_point2.z> pigment {color rgb <0,ctr,0>
} finish {diffuse .5} translate <num1,0,num3> rotate y*rot}
triangle {<s_point1.x+blade_width,s_point1.y,s_point1.z>
<s_point1.x+blade_width,s_point2.y,s_point2.z>
<s_point1.x-blade_width,s_point2.y,s_point2.z> pigment {color rgb <0,ctr,0>
} finish {diffuse .5} translate <num1,0,num3> rotate y*rot}
//}
#declare ctr = ctr + s_step;
#end
#declare counter = counter + 1;
#end
As already stated, the parsing step is very slow and takes a lot of ram
(once it hits swap, the time required goes through the roof. Can someone
help me come up with a good optimization scheme?
Post a reply to this message
|
![](/i/fill.gif) |