// Object Name: KnurledCylinder // Version: 1.0.1 for POV > 3.1 (revised 4/18/2009) // Description: Cylinder with knurled exterior. // Scale: User specified // Positioning: Cylinder starting at origin, extending in +y // Keywords: Knurl // Author: Christopher Shake, edited by Tim Attwood // This file is licensed under the terms of the CC-LGPL /* Call: KnurledCylinder(Radius,CylinderHeight,KnurlDepth,HorizontalSpacing,Vertic alSpacing,FlattenPercent,RaisePercent) Parameters: Radius - Mean radius of cylinder, measured to the middle of the knurling. CylinderHeight - Height of generated cylinder KnurlDepth - Depth of knurl, measured peak to valley. HorizontalSpacing - Distance between peaks around circumference. VerticalSpacing - Distance between peaks in the axial direction. FlattenPercent - Amount to flatten peaks. 0 is no flattening, 1 shaves all the way down to the mean radius. RaisePercent - Amount to raise valleys, 0 is no raising, 1 raises up to the mean radius. Generates: A knurled cylinder with no texture extending from the origin in the +y direction. Equivalent shape to 'cylinder{<0,0,0>,<0,CylinderHeight,0>,Radius}' Note: Generates a parse warning that patch objects are not allowed in intersection, but works as expected even with the warning. Edit: Intersection doesn't quite work perfect, the cylinder doesn't remove the ends properly because of the intersection. (1)Replaced CSG with difference version. (2)Placed inside_vector inside the object, instead of arbitrary. */ #ifndef(KNURLED_CYLINDER_INC_TEMP) #declare KNURLED_CYLINDER_INC_TEMP = version; #version 3.1; #macro KnurledCylinder(Radius,CylinderHeight,KnurlDepth,HorizontalSpacing,Vertic alSpacing,FlattenPercent,RaisePercent) #local horiz_spacing=HorizontalSpacing; #local vert_spacing=VerticalSpacing; #local mean_radius=Radius; #local knurl_depth=KnurlDepth; #local cylinder_length=CylinderHeight; #local flatten_percent=FlattenPercent; #local raise_percent=RaisePercent; #local divs=floor((pi*mean_radius*2/horiz_spacing)/2)*2+1; #local vert=(int(cylinder_length/vert_spacing)+1)+1; // Make mesh #declare knurlmesh= mesh2{ vertex_vectors{ divs*vert+2, #local horiziter=0; #while (horiziter, #else <(mean_radius+knurl_depth/2)*cos(2*pi*horiziter/divs),vert_spacing*vertit er,(mean_radius+knurl_depth/2)*sin(2*pi*horiziter/divs)>, #end #local vertiter=vertiter+1; #end #local horiziter=horiziter+1; #end <0,0,0>,<0,vert_spacing*(vert-1),0> } face_indices{ divs*(vert-1)*2+divs*2, #local iter=0; #local diag=1; #while(iter<(divs*vert)) #local pt1=iter; #local pt2=iter+1; #local pt3=iter+vert; #local pt4=iter+vert+1; #if(pt3>=divs*vert) #local pt3=mod(iter,vert); #local pt4=mod(iter,vert)+1; #end #if(diag=1) ,, #else ,, #end #local diag = -diag; #if(mod(iter,vert)=vert-2) #if(mod(vert,2)=1) #local diag=-diag; #end #local iter=iter+1; #end #local iter=iter+1; #end #local iter=0; #local bot3=divs*vert; #local top3=divs*vert+1; #while (iter=divs*vert) #local bot2=0; #local top2=vert-1; #end ,, #local iter=iter+1; #end } inside_vector <0,CylinderHeight*0.5,0> } // Create object with CSG for flattening and raising difference { union{ object{knurlmesh} cylinder{<0,-1,0>,<0,cylinder_length+1,0>,mean_radius-(1-raise_percent)*k nurl_depth/2} } cylinder{<0,0,0>,<0,cylinder_length,0>,mean_radius+(1-flatten_percent)*kn url_depth/2 inverse} } #end #version KNURLED_CYLINDER_INC_TEMP; #end