#VRML V2.0 utf8

Transform 
  {
  children 
    [
    Shape 
      {
      appearance       Appearance 
	{
	material 	Material 
	  {
	  }
	}
      geometry       DEF IndexedFaceSet1 IndexedFaceSet 
	{
	coord 	DEF Coordinate1 Coordinate 
	  {
	  }
	ccw FALSE
	creaseAngle 0.709999
	}
      }
    ]
  rotation -0.491309 -0.860261 -0.136252 0.623705
  }

DEF Script1 Script 
  {
  eventIn SFFloat n1_in
  eventIn SFFloat n2_in
  eventIn SFInt32 uTessellation_in
  eventIn SFInt32 vTessellation_in
  eventOut MFInt32 coordindex_out
  eventOut MFVec3f vertices_out
  field SFFloat n1 1
  field SFFloat n2 1
  field SFInt32 uTessellation 16
  field SFInt32 vTessellation 16
  field MFFloat s1xy []
  field MFFloat s1z []
  field MFFloat s2x []
  field MFFloat s2y []
  url 
    [
    "javascript:

 // field SFInt32 uTessellation //
 // field SFInt32 vTessellation //

 // field SFFloat n1 //
 // field SFFloat n2 //

 // eventOut MFInt32 coordindex_out //
 // eventOut MFVec3f vertices_out //


 function sign(f)
    {
    if (f>=0)
       return 1;
    else
       return -1;
    }

 function superellipse1xy(angle1)
    {
    var c1 = Math.cos(angle1);
    return sign(c1)*Math.pow(Math.abs(c1),n2);
    }

 function superellipse1z(angle1)
    {
    var s1 = Math.sin(angle1);
    return sign(s1)*Math.pow(Math.abs(s1),n2);
    }

 function superellipse2x(angle2)
    {
    var c2 = Math.cos(angle2);
    return sign(c2)*Math.pow(Math.abs(c2),n1);
    }

 function superellipse2y(angle2)
    {
    var s2 = Math.sin(angle2);
    return sign(s2)*Math.pow(Math.abs(s2),n1);
    }

 function account()
    {
    var inc1=Math.PI/(uTessellation-1);
    var inc2=Math.PI/(vTessellation-1)*2.0;
    coordindex_out=new MFInt32();
//    coordindex_out[uTessellation*vTessellation*6]=0;
    vertices_out=new MFVec3f();
//    vertices_out[uTessellation*vTessellation].x=0.0;
//    vertices_out[uTessellation*vTessellation].y=0.0;
//    vertices_out[uTessellation*vTessellation].z=0.0;
    var index=0;
    var cindex=0;
    var angle1;
    var angle2;
    var i;
    var a1=0;
    var a2=0;
    s1xy[uTessellation]=0;
    s1z[uTessellation]=0;
    angle1=-Math.PI/2.0;
    for (a1=0;a1<uTessellation;a1++)
       {
       s1xy[a1]=superellipse1xy(angle1);
       s1z[a1]=superellipse1z(angle1);
       angle1+=inc1;
       }
    s2x[vTessellation]=0;
    s2y[vTessellation]=0;
    angle2=-Math.PI;
    for (a2=0;a2<vTessellation;a2++)
       {
       s2x[a2]=superellipse2x(angle2);
       s2y[a2]=superellipse2y(angle2);
       angle2+=inc2;
       }
    for (a1=0;a1<uTessellation-1;a1++)
       {
       for (a2=0;a2<vTessellation-1;a2++)
          {
          vertices_out[index].x = s1xy[a1]*s2x[a2];
          vertices_out[index].y = s1xy[a1]*s2y[a2];
          vertices_out[index].z = s1z[a1];

          vertices_out[index+1].x = s1xy[a1+1]*s2x[a2];
          vertices_out[index+1].y = s1xy[a1+1]*s2y[a2];
          vertices_out[index+1].z = s1z[a1+1];

          vertices_out[index+2].x = s1xy[a1+1]*s2x[a2+1];
          vertices_out[index+2].y = s1xy[a1+1]*s2y[a2+1];
          vertices_out[index+2].z = s1z[a1+1];

          vertices_out[index+3].x = s1xy[a1]*s2x[a2+1];
          vertices_out[index+3].y = s1xy[a1]*s2y[a2+1];
          vertices_out[index+3].z = s1z[a1];

          for (i=0;i<4;i++)
             {
             coordindex_out[cindex+i]=index+i;
             }
          coordindex_out[cindex+4]=-1;
          index+=4;
          cindex+=5;
          }
       }
    vertices_out[index].x = s1xy[uTesselation]*s2x[vTessellation];
    vertices_out[index].y = s1xy[uTessellation]*s2y[vTessellation];
    vertices_out[index].z = s1z[uTessellation];
     
    vertices_out[index+3].x = s1xy[0]*s2x[vTessellation];
    vertices_out[index+3].y = s1xy[0]*s2y[vTessellation];
    vertices_out[index+3].z = s1z[0];

    vertices_out[index+2].x = s1xy[0]*s2x[0];
    vertices_out[index+2].y = s1xy[0]*s2y[0];
    vertices_out[index+2].z = s1z[0];

    vertices_out[index+1].x = s1xy[uTessellation]*s2x[0];
    vertices_out[index+1].y = s1xy[uTessellation]*s2y[0];
    vertices_out[index+1].z = s1z[uTessellation];

    for (i=0;i<4;i++)
        {
        coordindex_out[cindex+i]=index+i;
        }
    coordindex_out[cindex+4]=-1;
    index+=4;
    cindex+=5;
    vertices_out=new MFVec3f(vertices_out);
    coordindex_out=new MFInt32(coordindex_out);
    }


 function initialize()
    {
    account();
    }

 function n1_in(value)
    {
    n1 = value;
    account();
    }

 function n2_in(value)
    {
    n2 = value;
    account();
    }

 function uTessellation_in(value)
    {
    uTessellation = value;
    account();
    }

 function vTessellation_in(value)
    {
    vTessellation = value;
    account();
    }

"
    ]
  }

ROUTE Script1.vertices_out TO Coordinate1.set_point
ROUTE Script1.coordindex_out TO IndexedFaceSet1.set_coordIndex



DEF TimeSensor1 TimeSensor 
  {
  cycleInterval 20
  loop TRUE
  }

DEF ScalarInterpolator1 ScalarInterpolator 
  {
  key 
    [
    0 
    0.500000 
    1 
    ]
  keyValue 
    [
    1 
    1 
    0.03
    ]
  }

ROUTE TimeSensor1.fraction_changed TO ScalarInterpolator1.set_fraction
ROUTE ScalarInterpolator1.value_changed TO Script1.n2_in

Viewpoint 
  {
  }

DEF TimeSensor2 TimeSensor 
  {
  cycleInterval 10
  loop TRUE
  }

DEF ScalarInterpolator2 ScalarInterpolator 
  {
  key 
    [
    0 
    0.500000 
    0.5
    ]
  keyValue 
    [
    0.03 
    1 
    0.03
    ]
  }

ROUTE TimeSensor2.fraction_changed TO ScalarInterpolator2.set_fraction
ROUTE ScalarInterpolator2.value_changed TO Script1.n1_in
