|
 |
For some reason I'm unable to find the original article, so I'm responding
to this one.
I'm glad that someone has found the macro useful.
I noticed that it makes a pretty inefficient use of textures. For example,
if the MaxRecursionLevel is 10, it will create 19684 textures.
This modified version of the macro will create just 10 textures (as it
should):
#macro Tetrarecursion (Location, Normal, Vertex)
#ifndef(RecursionLevel) #declare RecursionLevel = 1; #end
#if(RecursionLevel=1)
#declare RecTexture = array[MaxRecursionLevel]
#local ind = 0;
#while(ind<MaxRecursionLevel)
#local Fact = ind/(MaxRecursionLevel-1);
#declare RecTexture[ind] =
texture
{ pigment { rgb FirstColor*(1-Fact)+LastColor*Fact }
finish { specular .5 }
}
#local ind=ind+1;
#end
#end
#local P1 = Location+Vertex;
#local P2 = Location+vaxis_rotate(Vertex,Normal,120);
#local P3 = Location+vaxis_rotate(Vertex,Normal,240);
#local P4 = Location+
vnormalize(Normal)*sqrt(pow(vlength(P2-P1),2)-pow(vlength(Vertex),2));
#local Mid = (P1+P2+P3+P4)/4;
#local newNormal = vcross(P2-P1,P4-P1)*(1-SmoothFactor);
smooth_triangle
{ P1,(P1-Mid)*SmoothFactor+newNormal,
P2,(P2-Mid)*SmoothFactor+newNormal,
P4,(P4-Mid)*SmoothFactor+newNormal
texture { RecTexture[RecursionLevel-1] }
}
#local newNormal = vcross(P3-P2,P4-P2)*(1-SmoothFactor);
smooth_triangle
{ P2,(P2-Mid)*SmoothFactor+newNormal,
P3,(P3-Mid)*SmoothFactor+newNormal,
P4,(P4-Mid)*SmoothFactor+newNormal
texture { RecTexture[RecursionLevel-1] }
}
#local newNormal = vcross(P1-P3,P4-P3)*(1-SmoothFactor);
smooth_triangle
{ P3,(P3-Mid)*SmoothFactor+newNormal,
P1,(P1-Mid)*SmoothFactor+newNormal,
P4,(P4-Mid)*SmoothFactor+newNormal
texture { RecTexture[RecursionLevel-1] }
}
#if(RecursionLevel<MaxRecursionLevel)
#declare RecursionLevel = RecursionLevel+1;
#local newLocation = (P1+P2+P4)/3;
#local newNormal = vcross(P2-P1,P4-P1);
#local newVertex = (P1+P2)/2-newLocation;
#local newVertex = vaxis_rotate
(vnormalize(newVertex)*(vlength(newVertex)/cos(radians(RotationAngle))),
newNormal, RotationAngle);
Tetrarecursion(newLocation, newNormal, newVertex)
#local newLocation = (P2+P3+P4)/3;
#local newNormal = vcross(P3-P2,P4-P2);
#local newVertex = (P2+P3)/2-newLocation;
#local newVertex = vaxis_rotate
(vnormalize(newVertex)*(vlength(newVertex)/cos(radians(RotationAngle))),
newNormal, RotationAngle);
Tetrarecursion(newLocation, newNormal, newVertex)
#local newLocation = (P3+P1+P4)/3;
#local newNormal = vcross(P1-P3,P4-P3);
#local newVertex = (P3+P1)/2-newLocation;
#local newVertex = vaxis_rotate
(vnormalize(newVertex)*(vlength(newVertex)/cos(radians(RotationAngle))),
newNormal, RotationAngle);
Tetrarecursion(newLocation, newNormal, newVertex)
#declare RecursionLevel = RecursionLevel-1;
#end
#end
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |