//========================================= // Spline extrusion macro // Pov-Ray 3.1 // Feb 26 1999 // Gilles Tran (with a macro spline by Steve Sloan) // Feel free to use //========================================= #include "colors.inc" #include "textures.inc" #include "metals.inc" //========================================= // Point of view //========================================= #declare PdV=<0, 0.1 , -40>; #declare PdA=<0,0,0>; camera { location PdV direction <0.0 , 0.0 , 1 > up <0 , 1 , 0> right <4/3 , 0.0 , 0.0> look_at PdA } //========================================= // Lights //========================================= light_source{PdV color White*0.2 shadowless} light_source{<130,40,-200> color Orange*2 } light_source{<-30,140,-200> color rgb<0.6,0.6,1.2>} //========================================= // Macros spline by Steve Sloan //========================================= #macro SplinePoint(P,oldt) #local n = dimension_size(P,1); #local n = n - 1; #if (oldt<1) #local segment = int(oldt*(n - 2)) + 1; #local i = segment + 2; #local c = array[4] #local c[0] = -P[i-3] + 3*P[i-2] - 3*P[i-1] + P[i]; #local c[1] = 2*P[i-3] - 5*P[i-2] + 4*P[i-1] - P[i]; #local c[2] = -P[i-3] + P[i-1]; #local c[3] = 2*P[i-2]; #local t1 = oldt*(n - 2) - segment + 1; #local t2 = t1*t1; #local t3 = t2*t1; #local answer = 0.5*(c[0]*t3 + c[1]*t2 + c[2]*t1 + c[3]); #else #if (oldt>1) #local answer=P[n]; #else #local answer=P[n-1]; #end #end answer; #end //======================================= // makeMesh is macro that extrudes a shape along a path // nI = number of shape steps // nJ = nombre of path steps // the more steps the smoother it is (and the longer it takes to parse) // // arrI = shape spline // arrJ = path spline // // doSmooth = true : smooths the triangles // loopMesh = true : calculates the same normal for the first and last point of the shape (for closed shapes) // makeLine = true : makeLine creates a test dummy object // // Requires a makePoint macro : makePoint(i,j,nI,nJ,Shape,Path) // Use : union{makeMesh(10,20,Shape,Path, true,true,false)} // I'm not sure about the smoothing algorithm, but it works // note that only the makePoint macro makes use of the splines (so you can modify //======================================= #macro makeMesh(nI,nJ,arrI,arrJ,doSmooth,loopMesh,makeLine) #local nP=nI*nJ; #local P = array[nP] // Points //======================================= // Fills the P array of points //======================================= #local q = 0; #while (q0)#if (vlength(P[q]-P[q-1])>0) cylinder{P[q],P[q-1],0.1} #end #end #end #local q=q+1;#end #if (makeLine=false) //======================================= // If makeLine=false, writes a mesh //======================================= //======================================= // smoothing if doSmooth = true //======================================= #if (doSmooth=true) #local N = array[nP] // Normals #local q=0; #while (q; #local k=0; #if (V5>-1 & V8>-1) #local N[q]=N[q]+vcross(P[V4]-P[V5],P[V8]-P[V4]);#local k=k+1;#end #if (V2>-1 & V5>-1) #local N[q]=N[q]+vcross(P[V4]-P[V2],P[V5]-P[V4]);#local k=k+1;#end #if (V1>-1 & V2>-1) #local N[q]=N[q]+vcross(P[V4]-P[V1],P[V2]-P[V4]);#local k=k+1;#end #if (V0>-1 & V1>-1) #local N[q]=N[q]+vcross(P[V4]-P[V0],P[V1]-P[V4]);#local k=k+1;#end #if (V3>-1 & V0>-1) #local N[q]=N[q]+vcross(P[V4]-P[V3],P[V0]-P[V4]);#local k=k+1;#end #if (V6>-1 & V3>-1) #local N[q]=N[q]+vcross(P[V4]-P[V6],P[V3]-P[V4]);#local k=k+1;#end #if (V7>-1 & V6>-1) #local N[q]=N[q]+vcross(P[V4]-P[V7],P[V6]-P[V4]);#local k=k+1;#end #if (V8>-1 & V7>-1) #local N[q]=N[q]+vcross(P[V4]-P[V8],P[V7]-P[V4]);#local k=k+1;#end #local N[q]=N[q]/k; #local q=q+1;#end #end //======================================= // write the triangles //======================================= mesh{ #local q=0; #while (q<(nI*(nJ-1)-1)) #local i=mod(q,nI);#local j=(q-i)/nI; #if (i ; answer; #end //======================================= // end of makePoint //======================================= //======================================= // Examples //======================================= // Pipe #declare Path = array[9] {<-20,-3,-4>,<-15,-1,-5>,<-10,1,2>,<-5,2,0>,<0,2,2>,<5,-1,4>,<10,-2,0>,<15,0,-1>,<20,0,0>} #declare Shape = array[7] {<4,0,0>,<0,0,-2>,<-4,0,0>,<0,0,3>,<4,0,0>,<0,0,-2>,<-4,0,0>} // "Drape" //#declare Path = array[5] {<-25,0,0>,<-15,-5,1>,<1,0,-5>,<15,0,0>,<25,0,0>} //#declare Shape = array[5] {<0,3,-40>,<0,4,-35>,<0,1,5>,<0,-1,35>,<0,0,40>} //smooth low-res //union{makeMesh(10,10,Shape,Path,true,true,false) texture{pigment{Red}finish {phong 1}}} //smooth higher-res union{makeMesh(20,20,Shape,Path,true,true,false) texture{pigment{Red}finish {phong 1}}} //not smooth higher-res //union{makeMesh(20,20,Shape,Path,false,false,false) texture{pigment{Red}finish {phong 1}}} //skeleton //union{makeMesh(20,20,Shape,Path,false,false,true) texture{pigment{Red}finish {phong 1}}}