//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
#declare A1=spline {
   cubic_spline
   -0.5, < 1,-1, 0>
    0.0, < 1, 0, 0> //first point
    0.5, < 2, 1, 0>
    1.0, < 1, 2, 0> //last point
    1.5, < 1, 3, 0>
}
#declare A2=spline {
   cubic_spline
   -0.5, < 0,-1, 1>
    0.0, < 0, 0, 1> //first point
    0.5, < 0, 1, 2>
    1.0, < 0, 3, 1> //last point
    1.5, < 0, 4, 1>
}
#declare A3=spline {
   cubic_spline
   -0.5, <-1,-1, 0>
    0.0, <-1, 0, 0> //first point
    0.5, <-2, 1, 0>
    1.0, <-1, 3, 0> //last point
    1.5, <-2, 3, 0>
}
#declare A4=spline {
   cubic_spline
   -1/3, < 0,-1,-1>
    0.0, < 0, 0,-1>  //first point
    1/3, < 0, 1,-0.5>
    2/3, < 0, 2,-1.6>
    1.0, < 0, 2.5,-1.5> //last point
    4/3, < 0, 3,-1>
}
//--------------------------------------------- 
#declare An=array[7]{   // array of splines
   spline{A4},
   spline{A1}, //first point
   spline{A2},
   spline{A3},
   spline{A4},
   spline{A1}, //last point (closes the shape)
   spline{A2}
}
//----------------------------------------------
//----------------------------------------------------------------------------------------------------
#include "meshmaker.inc"
//----------------------------------------------------------------------------------------------------
object { // MSM(SplineArray, SplRes, Interp_type, InterpRes, FileName) 
         // Generates a surface from an array of splines, (the white curves).
         // From these input splines the points with the same t-values are 
         // connected by newly generated splines (red curves).
         // From these the surface is build. 
    MSM(  An, // array of splines
         100, // amount of triangles, in the direction of the input splines. 
         "c", //  type of interpolation ( string!) 
              // "C" or "c": cubic_spline; "L" or "l": linear_spline; 
              // "N" or "n": natural_spline; "Q" or "q": quadratic_spline 
         100, // amount of triangles, in the direction of the new splines.
          ""  // FileName: ""= non, "NAME.obj'= Wavefront objectfile, "NAME.pcm" compressed mesh file 
              // "NAME.arr" include file with arrays to build a mesh2 from,
              //  others: includefile with a mesh2 object 
       ) // ------------------------------------------------------------------------------------------
   texture{          // outside texture
     uv_mapping
     pigment {checker color rgb <0.3,0.2,0.6> rgb <1,1,1> scale <0.035,0.1,1>}
     finish{specular 0.5}
   } // 
   interior_texture{   // inside texture
     uv_mapping
     pigment {checker color rgb <0.0,0,0.0> rgb <1,0.8,0.8> scale <0.035,0.1,1>}
     finish{specular 0.5}
   } // 

   rotate <0,45,0>
   translate <2,0,0>
} // end of object 
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------



//----------------------------------------------------------------
// uncomment to view splines: ------------------------------------
#declare N=dimension_size(An,1);
#declare M=500;
#declare I=0;
union {
  #while (I<N)
     #declare Spl=spline{An[I]};
     #declare J=0;
     #while (J<=M)
        sphere {Spl(J/M), 0.045 no_shadow pigment {rgb <1,1,0> }}
        #declare J=J+1;
     #end
     #declare I=I+1;
  #end
  rotate <0,45,0>
  translate <-2,0,0>
}

#declare N=dimension_size(An,1);

#declare TempSplArr=array[N];
#declare Pos=0.0;
union {
  #while(Pos<=1)   
     #declare I=0;
     #while (I<N)
        #declare Spl=spline{An[I]}
        #declare PP=<0,0,0>+Spl(Pos);
        #declare TempSplArr[I]=PP;
        #declare I=I+1;
     #end
     #declare S1=BuildSpline(TempSplArr, "c")
     #declare J=0;
     #declare M=500;
     #while (J<=M)
        sphere {S1(J/M), 0.03 no_shadow pigment {rgb <0.8,0,0>}}
        #declare J=J+1;
     #end
     #declare Pos=Pos+0.05;
  #end
  rotate <0,45,0>
  translate <-2,0,0>
} //--------------------------------------------------------------
//----------------------------------------------------------------
//----------------------------------------------------------------







