|
|
Btw, I wonder if this kind of macro could be worth including in the
standard include files.
The only concern I have about it is that it uses the "trick" to calculate
the normal of the spline with the Spline(T+Epsilon)-Spline(T-Epsilon)
formula. What I'm not sure about is the value for 'Epsilon'. I used 1e-5,
but that might sometimes be either too big or too small (due to floating
point number inaccuracies).
The current macro is the following:
---------8<------------8<-------------8<------------8<-----------8<-----
#macro MeshLathe(Spline, VertSteps, HorSteps)
#ifndef(MeshLatheDebug) #local MeshLatheDebug=0; #end
#if(MeshLatheDebug=1 | MeshLatheDebug=2)
#ifndef(MeshLatheDebugRadius) #local MeshLatheDebugRadius=.05; #end
#ifndef(MeshLatheDebugNormalLength) #local MeshLatheDebugNormalLength=.2; #end
union
{ #local Ind1 = 0;
#while(Ind1 < VertSteps)
#local Time1 = Ind1/(VertSteps-1);
#local Coord1 = (Spline(Time1));
#local Tang = (Spline(Time1+1e-5)-Spline(Time1-1e-5));
#local Normal1 = vnormalize(<Tang.y, -Tang.x, 0>);
sphere { Coord1, MeshLatheDebugRadius }
sphere { Coord1*<-1,1,1>, MeshLatheDebugRadius }
#if(MeshLatheDebug=2)
cylinder
{ Coord1, Coord1+Normal1*MeshLatheDebugNormalLength,
MeshLatheDebugRadius*.5
#ifdef(MeshLatheDebugNormalColor)
pigment { rgb MeshLatheDebugNormalColor }
#end
}
#end
#if(Ind1>0)
cylinder { Coord1, oldCoord1, MeshLatheDebugRadius*.5 }
cylinder
{ Coord1*<-1,1,1>, oldCoord1*<-1,1,1>, MeshLatheDebugRadius*.5 }
#end
#local oldCoord1 = Coord1;
#local Ind1 = Ind1+1;
#end
}
#else
mesh
{ #local Ind1 = 0;
#while(Ind1 < VertSteps-1)
#local Time1 = Ind1/(VertSteps-1);
#local Time2 = (Ind1+1)/(VertSteps-1);
#local Coord1 = (Spline(Time1));
#local Tang = (Spline(Time1+1e-5)-Spline(Time1-1e-5));
#local Normal1 = vnormalize(<Tang.y, -Tang.x, 0>);
#local Coord2 = (Spline(Time2));
#local Tang = (Spline(Time2+1e-5)-Spline(Time2-1e-5));
#local Normal2 = vnormalize(<Tang.y, -Tang.x, 0>);
#local Ind2 = 0;
#while(Ind2 < HorSteps-1)
#local Angle1 = 360*Ind2/(HorSteps-1);
#local Angle2 = 360*(Ind2+1)/(HorSteps-1);
#local P1 = vrotate(Coord1, y*Angle1);
#local N1 = vrotate(Normal1, y*Angle1);
#local P2 = vrotate(Coord2, y*Angle1);
#local N2 = vrotate(Normal2, y*Angle1);
#local P3 = vrotate(Coord2, y*Angle2);
#local N3 = vrotate(Normal2, y*Angle2);
#local P4 = vrotate(Coord1, y*Angle2);
#local N4 = vrotate(Normal1, y*Angle2);
#if(MeshLatheDebug>2)
triangle { P1, P2, P3 }
triangle { P3, P4, P1 }
#else
smooth_triangle { P1,N1, P2,N2, P3,N3 }
smooth_triangle { P3,N3, P4,N4, P1,N1 }
#end
#local Ind2 = Ind2+1;
#end
#local Ind1 = Ind1+1;
#end
}
#end
#end
---------8<------------8<-------------8<------------8<-----------8<-----
--
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -
Post a reply to this message
|
|