// gear.inc // // April 19,2004 // // Ryan Budge #macro MakeGear ( outer_radius, inner_radius, outer_width, inner_width, tooth_num, tooth_height, tooth_padding, tooth_flat_fraction, helix_angle, hole_num, hole_radius, inner_texture, outer_texture, quality ) /* Parameter Explanation : outer_radius - outer radius of entire gear, including gear teeth (x,y) inner_radius - cylindrical hole radius cut from center of gear (x,y) outer_width - width of gear teeth (outer section) (z) inner_width - width of hub (inner section) (z) tooth_num - number of gear teeth tooth_height - self explanatory tooth_padding - distance between tooth troughs and inner section tooth_flat_fraction - fraction of tooth surface to be made flat ex TFF=0 makes sawtooth shaped teeth (no flat at all, all slope) TFF=1 makes square shaped teeth (all flat, no slope) TFF=1/2 makes equal sections of flat and slope helix_angle - twist of teeth in degrees per unit z width ex HA = 50, outer_width=1 --> total helical twist = 50 deg HA = 50, outer_width=2 --> total helical twist = 100 deg hole_num - number of holes cut into hub hole_radius - radius of holes in hub inner_texture - texture of hub outer_texture - texture of teeth quality - equates to max_gradient in isosurface object. Higher number makes for slower renders Check your render messages to see if your quality level is too high or too low. You will get a warning about the max_gradient of your gear object which will tell you exactly the setting you need to make sure the tooth surface doesn't get holes in it. Generally speaking between 2 and 10 should cover most gears. */ #local Inner_Part = difference { cylinder { 0, <0,0,inner_width>, outer_radius - tooth_height - tooth_padding } cylinder { <0,0,-1>, <0,0,inner_width+1>, inner_radius } union { #local hole=0; #while (hole < hole_num) cylinder { <0,0,-1> <0,0,outer_width>, hole_radius translate x*(inner_radius+outer_radius-tooth_height-tooth_padding)/2 rotate z*360*hole/hole_num} #local hole=hole+1; #end } } //end local Inner_Part #local Outer_Part = #local freq=tooth_num; difference { //tooth_function// #local tooth_function = function { #local depth=tooth_height; #local twist=(helix_angle)*pi/180/outer_width; #local flat=tooth_flat_fraction*pi/freq; sqrt(pow(x,2)+pow(y,2))- ( outer_radius- ( /*( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0)),2*pi/freq) > 0 ) * ( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0)),2*pi/freq) < flat ) * ( 0 ) +*/ ( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq) > flat ) * ( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq) < pi/freq ) * ( (mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq)-flat)/((pi/freq)-flat)*depth ) + ( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq) > pi/freq ) * ( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq) < (pi/freq)+flat ) * ( depth ) + ( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq) > (pi/freq)+flat ) * ( mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq) < 2*pi/freq ) * ( (mod(atan2(y,x)+( (twist>0)*(z*twist) + (twist<0)*(abs(twist)*(1-z)) + pi*(1+mod(freq,2)/freq)*(y<0) ),2*pi/freq)-(2*pi/freq))/(flat-(pi/freq))*depth ) ) ) } //tooth_function// isosurface { function { tooth_function(x,y,z) } contained_by { box { <-outer_radius,-outer_radius, 0>, } } max_gradient quality accuracy .0005 } // cylinder { <0,0,-1>,<0,0,outer_width+1>, outer_radius - tooth_height - tooth_padding } } //end local Outer_Part union { object { Inner_Part translate <0,0,(outer_width-inner_width)/2> texture { inner_texture } } object { Outer_Part texture { outer_texture } } } #end //MakeGear ( outer_radius, inner_radius, outer_width, inner_width, tooth_num, // tooth_height, tooth_padding, tooth_flat_fraction, helix_angle, // hole_num, hole_radius, inner_texture, outer_texture, quality ) //MakeGear ( outer_radius, inner_radius, outer_width, inner_width, tooth_num, // tooth_height, tooth_padding, tooth_flat_fraction, helix_angle, // hole_num, hole_radius, inner_texture, outer_texture, quality )