#version 3.6; // ============================================================================ // global settings // ---------------------------------------------------------------------------- // +w640 +h480 +am2 +a0.1 #default{finish{ambient 0}} #global_settings{ assumed_gamma 1.0 max_trace_level 15 } // ============================================================================ // macros // ---------------------------------------------------------------------------- #declare f_I = function(SV, EV, K){SV*K+EV*(1-K)}; // interpolates between two values, can be float or vector // SV = start value // EV = end value // K = clock value from 0 to 1; // ---------------------------------------------------------------------------- // converts rectangular 'xyz' coordinates to polar coordinates, sort of... // assuming a cylinder with it's base at the origin and extending in the +y direection: // given a vector point as , the macro outputs the rotation vector needed // to point that cylinder toward that vector point. #macro m_orient(V) // V = vector ).z)*select(V.x,-1,1)), 0> #end // ---------------------------------------------------------------------------- // creates an object like a shpere_sweep, built from spheres & cylinders // less buggy & renders faster then sphere sweeps // useful for visualising spline paths used in animations #macro m_drawspline(Spline, SV, EV, R1, Q) // Spline = name of spline // SV = start clock value // EV = end clock value // R1 = radius // Q = quality union{ #local ca = 0; #while(ca<=Q) #local NP = Spline(f_I(SV, EV, ca/Q)); #if(ca>0) cylinder{NP, OP, R1} #end sphere{NP, R1} #local OP = NP; #local ca = ca+1; #end } #end // ---------------------------------------------------------------------------- // creates a spiral loop that follows a spline path, like a telephone cord #macro m_helicoil(Spline, SV, EV, NC, R1, R2, Q) // Spline = name of spline // SV = start clock value // EV = end clock value // NC = number & direction of coils (negative numbers go in opposite direction) // R1 = major radius // R2 = minor radius // Q = quality union{ #local ca = 0; #while(ca, <0, (ca/Q)*NC*360, 0>), D1)+P1; #if(ca>0) cylinder{OP, NP, R2} #end sphere{NP, R2} #local OP = NP; #local ca = ca+1; #end } #end // ---------------------------------------------------------------------------- // creates a mesh2 object similar to a sphere_sweep #macro m_mesh2sweep(Spline, SV, EV, R1, LP, RP) // Spline = name of spline // SV = start clock value // EV = end clock value // R1 = radius // LP = number of longitudinal points // RP = number of radial points #local tv = array[LP+1][RP]; // vectors array #local tn = array[LP+1][RP]; // normals array #local cl = 0; #while(cl<=LP) #local cr = 0; #while(cr, <0, (cr/RP)*360, 0>), D1)+P1; #local tn[cl][cr] = vnormalize(tv[cl][cr]-P1); #local cr = cr+1; #end #local cl = cl+1; #end mesh2{ vertex_vectors{ (LP+1)*RP, #local cl = 0; #while(cl<=LP) #local cr = 0; #while(cr, #local cr = cr+1; #end #local cl = cl+1; #end } face_indices{ LP*RP*2, #local cl = 0; #while(cl #local cr = cr+1; #end #local cl = cl+1; #end } uv_indices{ LP*RP*2, #local cl = 0; #while(cl #local cr = cr+1; #end #local cl = cl+1; #end } } #end // ============================================================================ // textures // ---------------------------------------------------------------------------- #declare t_white = texture{pigment{color rgb 1} finish{diffuse 1 brilliance 1}} // ============================================================================ // lights // ---------------------------------------------------------------------------- light_source{<-1, 1, 1>*10 color rgb 1.2 spotlight tightness 2 radius 5 falloff 10 point_at<0, 0, 0>} light_source{< 1, 1, -1>*10 color rgb <0.8, 0.5, 0.2>*0.5 shadowless} light_source{< 1, -1, 1>*10 color rgb <0.8, 0.5, 0.2>*0.5 shadowless} // ============================================================================ // scene // ---------------------------------------------------------------------------- #declare Myspline = spline{ //cubic_spline natural_spline -.25, <0,-0.5,-1> 0.00, <1,0,0> 0.25, <0,0.5,1> 0.50, <-1,1,0> 0.75, <0,1.3,-1> 1.00, <1,2,0> 1.25, <0,2.5,1> } // ---------------------------------------------------------------------------- plane{y,-0.3 texture{t_white}} object{m_drawspline(Myspline, 0, 1, 0.1, 100) texture{t_white}} object{m_helicoil(Myspline, 0, 1, 20, 0.3, 0.03, 1000) texture{t_white}} object{ m_mesh2sweep(Myspline, 0, 1, 0.2, 100, 16) texture{ pigment{ uv_mapping image_map{png "test.png" interpolate 2} scale <1, 1/10, 1> // scale the image map to repeat along the length of the spline } finish{diffuse 1} } } // ============================================================================ // camera // ---------------------------------------------------------------------------- #declare s_camerapos = 0; #switch(s_camerapos) // ---------------------------------------------------------------------------- #case(0) camera{ perspective location<5, 1.55, 5> up y*(image_height/image_width) right x sky y look_at<0, 1, 0> angle 36 } #break // ---------------------------------------------------------------------------- #end // ------------------------ end of file