commit 72059460167316fc8cc32d48d4ae9ead3124eef9
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Sep 16 21:51:41 2020 +0100

    MeshFile.

diff --git a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
index 1188e7f..c10dbe5 100644
--- a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
+++ b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
@@ -35,7 +35,6 @@ import org.distorted.library.effect.VertexEffectDisappear;
 import org.distorted.library.effect.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectRotate;
 import org.distorted.library.effect.VertexEffectScale;
-import org.distorted.library.effect.VertexEffectSink;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedLibrary;
 import org.distorted.library.main.DistortedScreen;
@@ -44,7 +43,6 @@ import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.mesh.MeshFile;
 import org.distorted.library.mesh.MeshJoined;
 import org.distorted.library.mesh.MeshPolygon;
-import org.distorted.library.mesh.MeshTriangle;
 import org.distorted.library.type.DynamicQuat;
 import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static3D;
@@ -229,14 +227,13 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
                                                                          0xffff0000,
                                                                          0xff000000 };
                                    return createTetrahedronTexture(TET_COLORS5);
-          case  R.raw.dino       : final int[] TET_COLORS7 = new int[] { 0xffffff00,
+          case  R.raw.dino       : final int[] DINO_COLORS = new int[] { 0xffffff00,
                                                                          0xffffffff,
                                                                          0xff0000ff,
                                                                          0xff00ff00,
                                                                          0xffff0000,
-                                                                         0xffb5651d,
-                                                                         0xff000000 };
-                                   return createTetrahedronTexture(TET_COLORS7);
+                                                                         0xffb5651d };
+                                   return createDinoTexture(DINO_COLORS);
           case R.raw.skewb       : final int[] SKEW_COLORS = new int[] { 0xffffff00,
                                                                          0xffffffff,
                                                                          0xff0000ff,
@@ -430,133 +427,82 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private MeshBase createStaticMesh()
+  void createDinoFaceTexture(Canvas canvas, Paint paint, int[] faceColors, int face, int left, int top, int side)
     {
-    /*
-    final float SQ2 = (float)Math.sqrt(2);
-    final float SQ3 = (float)Math.sqrt(3);
-    final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
-    final int MESHES=4;
-
-    int association = 1;
-    MeshBase[] meshes;
-
-    float D = 0.0005f;
-    float E = SQ3/2 - 3*D*SQ2;
-    float F = 0.5f - D*SQ2*SQ3;
-
-    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
-    float[] bands = new float[] {    1.0f    ,-D,
-                                     1.0f  -D,-D*0.80f,
-                                     1.0f-2*D,-D*0.65f,
-                                     1.0f-4*D,+D*0.10f,
-                                     0.50f, 0.035f,
-                                     0.0f, 0.040f };
+    float STROKE = 0.04f*side;
+    float L= left;
+    float H= 0.333f*side;
+    float LEN = 0.5f*side;
+
+    paint.setAntiAlias(true);
+    paint.setStrokeWidth(STROKE);
+    paint.setColor(faceColors[face]);
+    paint.setStyle(Paint.Style.FILL);
+
+    canvas.drawRect(left,top,left+side,top+side,paint);
+
+    paint.setColor(0xff000000);
+    paint.setStyle(Paint.Style.STROKE);
+
+    canvas.drawLine( L      , H,  L+2*LEN, H    , paint);
+    canvas.drawLine( L      , H,  L+  LEN, H+LEN, paint);
+    canvas.drawLine( L+2*LEN, H,  L+  LEN, H+LEN, paint);
+
+    float S1 = 0.150f*side;
+    float S2 = 0.090f*side;
+    float X  = 0.7f*S2;
+    float Y  = 0.2f*S1;
+
+    float LA = left+0.500f*side;
+    float RA = left;
+    float TA = 0.333f*side;
+    float BA = 0.833f*side;
+
+    canvas.drawArc( RA+X        , TA     , RA+X+S2  , TA+S2, 135,135, false, paint);
+    canvas.drawArc( RA+side-S2-X, TA     , RA+side-X, TA+S2, 270,135, false, paint);
+    canvas.drawArc( LA-S1/2     , BA-S1-Y, LA+S1/2  , BA-Y ,  45, 90, false, paint);
+    }
 
-    meshes = new MeshPolygon[MESHES];
-    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
-    meshes[0].setEffectAssociation(0,association,0);
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    for(int i=1; i<MESHES; i++)
+    private Bitmap createDinoTexture(int[] faceColors)
       {
-      association <<= 1;
-      meshes[i] = meshes[0].copy(true);
-      meshes[i].setEffectAssociation(0,association,0);
-      }
-
-    MeshBase result = new MeshJoined(meshes);
-
-    Static3D a0 = new Static3D(         0,        1,       0 );
-    Static3D a1 = new Static3D(         0,  -1.0f/3, 2*SQ2/3 );
-    Static3D a2 = new Static3D(-SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
-    Static3D a3 = new Static3D( SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
-
-    float tetraHeight = SQ2*SQ3/3;
-    float d1 = (0.75f-2*SQ2*D)*tetraHeight;
-    float d2 =-0.06f*tetraHeight;
-    float d3 = 0.05f*tetraHeight;
-    float d4 = 0.70f*tetraHeight;
-    float d5 = 1.2f;
-
-    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
-    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
-    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
-    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
-
-    Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
-    Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
-    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
-    Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
-
-    Static4D dReg  = new Static4D(0,0,0,d3);
-    Static1D dRad  = new Static1D(1);
-    Static3D center= new Static3D(0,0,0);
-    Static4D sReg  = new Static4D(0,0,0,d4);
-    Static1D sink  = new Static1D(d5);
-
-    Static1D angle  = new Static1D(angleFaces);
-    Static3D axis1  = new Static3D(  -1, 0,      0);
-    Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
-    Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
-    Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
-    Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
-
-    VertexEffectRotate  effect1 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), center );
-    VertexEffectMove    effect2 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,0) );
-    VertexEffectRotate  effect3 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
-    VertexEffectRotate  effect4 = new VertexEffectRotate( angle, axis1, center1 );
-    VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis2, center2 );
-    VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis3, center2 );
-
-    VertexEffectDeform  effect7 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
-    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
-    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
-    VertexEffectDeform  effect10= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
-
-    VertexEffectSink    effect11= new VertexEffectSink(sink,center, sReg);
-
-    effect3.setMeshAssociation(14,-1);  // apply to mesh[1], [2] and [3]
-    effect4.setMeshAssociation( 2,-1);  // apply only to mesh[1]
-    effect5.setMeshAssociation( 4,-1);  // apply only to mesh[2]
-    effect6.setMeshAssociation( 8,-1);  // apply only to mesh[3]
+      final int TEXTURE_HEIGHT = 256;
+      final int NUM_TEXTURES = 6;
+      Bitmap bitmap;
 
-    result.apply(effect1);
-    result.apply(effect2);
-    result.apply(effect3);
-    result.apply(effect4);
-    result.apply(effect5);
-    result.apply(effect6);
+      Paint paint = new Paint();
+      bitmap = Bitmap.createBitmap( (NUM_TEXTURES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
+      Canvas canvas = new Canvas(bitmap);
 
-    result.apply(effect7);
-    result.apply(effect8);
-    result.apply(effect9);
-    result.apply(effect10);
+      paint.setAntiAlias(true);
+      paint.setTextAlign(Paint.Align.CENTER);
+      paint.setStyle(Paint.Style.FILL);
 
-    result.apply(effect11);
+      paint.setColor(0xff000000);
+      canvas.drawRect(0, 0, (NUM_TEXTURES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint);
 
-    final float ratio = 0.2f;
-    final Static4D[] maps = new Static4D[MESHES];
+      for(int i=0; i<NUM_TEXTURES; i++)
+        {
+        createDinoFaceTexture(canvas, paint, faceColors, i, i*TEXTURE_HEIGHT, 0, TEXTURE_HEIGHT);
+        }
 
-    for(int mesh=0; mesh<MESHES; mesh++)
-      {
-      maps[mesh] = new Static4D( mesh*ratio, 0.0f, ratio, 1.0f);
+      return bitmap;
       }
 
-    result.setTextureMap(maps,0);
-    result.setShowNormals(true);
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    return result;
-     */
+  private MeshBase createStaticMesh()
+    {
     final float SQ2 = (float)Math.sqrt(2);
     final float SQ3 = (float)Math.sqrt(3);
+    final float ANGLE_FACES = (float)((180/Math.PI)*(Math.atan(SQ2)));
 
-    final int FACES_PER_CUBIT=6;
+    final int MESHES=4;
 
     float D = 0.02f;
-    float E = 0.5f;
-    float F = SQ2/2;
-
-    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
+    float E = 0.5f*SQ2;
+    float F = 0.5f;
 
     float[] bands0 = { 1.0f    , 0,
                        1.0f-2*D, D*0.25f,
@@ -566,93 +512,95 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
                        0.30f   , D*1.375f,
                        0.0f    , D*1.4f };
 
-    MeshBase[] meshes = new MeshBase[FACES_PER_CUBIT];
+    float[] vertices0 = { -F,F/3, 0,-2*F/3, +F,F/3 };
 
-    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
+    MeshBase[] meshes = new MeshPolygon[MESHES];
+    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 5);
     meshes[0].setEffectAssociation(0,1,0);
     meshes[1] = meshes[0].copy(true);
     meshes[1].setEffectAssociation(0,2,0);
-    meshes[2] = meshes[0].copy(true);
-    meshes[2].setEffectAssociation(0,4,0);
 
-    float[] vertices1 = { 0,0, F,0, F/2,(SQ3/2)*F };
-    float[] bands1 = { 1.0f, 0.0f, 0.0f, 0.0f };
+    float[] bands1 = { 1.0f    , 0,
+                       0.50f   , 0,
+                       0.0f    , 0 };
+
+    float[] vertices1 = { -E/2,-E*(SQ3/6), E/2,-E*(SQ3/6), 0,E*(SQ3/3) };
 
-    meshes[3] = new MeshPolygon(vertices1,bands1,0,0);
+    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
+    meshes[2].setEffectAssociation(0,4,0);
+    meshes[3] = meshes[2].copy(true);
     meshes[3].setEffectAssociation(0,8,0);
-    meshes[4] = meshes[3].copy(true);
-    meshes[4].setEffectAssociation(0,16,0);
-    meshes[5] = meshes[3].copy(true);
-    meshes[5].setEffectAssociation(0,32,0);
 
     MeshBase result = new MeshJoined(meshes);
 
+    Static3D a0 = new Static3D(     0,-3*F,    0 );
+    Static3D a1 = new Static3D(     0,   0, -3*F );
+    Static3D a2 = new Static3D(  -3*F,   0,    0 );
+    Static3D a3 = new Static3D(  +3*F,   0,    0 );
+
+    Static3D v0 = new Static3D(     0,-3*F/2, 3*F/2 );
+    Static3D v1 = new Static3D(     0, 3*F/2,-3*F/2 );
+    Static3D v2 = new Static3D(  -3*F, 3*F/2, 3*F/2 );
+    Static3D v3 = new Static3D(  +3*F, 3*F/2, 3*F/2 );
+
+    float d1 = 1.0f;
+    float d2 =-0.10f;
+    float d3 =-0.10f;
+    float d4 = 0.40f;
+
+    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
+    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
+    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
+    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
+
+    Static3D dVec0 = new Static3D( d3*v0.get0(), d3*v0.get1(), d3*v0.get2() );
+    Static3D dVec1 = new Static3D( d3*v1.get0(), d3*v1.get1(), d3*v1.get2() );
+    Static3D dVec2 = new Static3D( d2*v2.get0(), d2*v2.get1(), d2*v2.get2() );
+    Static3D dVec3 = new Static3D( d2*v3.get0(), d2*v3.get1(), d2*v3.get2() );
+
+    Static4D dReg  = new Static4D(0,0,0,d4);
+    Static1D dRad  = new Static1D(1);
+
+    Static1D angle1 = new Static1D(+ANGLE_FACES);
+    Static1D angle2 = new Static1D(-ANGLE_FACES);
+
     Static3D axisX  = new Static3D(1,0,0);
     Static3D axisY  = new Static3D(0,1,0);
-    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
-    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
-    Static1D angle1 = new Static1D(+90);
-    Static1D angle2 = new Static1D(-90);
-    Static1D angle3 = new Static1D(-15);
-    Static1D angle4 = new Static1D((float)((180.0f/Math.PI)*Math.acos(SQ3/3)));
-    Static1D angle5 = new Static1D(120);
-    Static1D angle6 = new Static1D(240);
-    Static3D center1= new Static3D(0,0,0);
-    Static3D center2= new Static3D(-0.5f,-0.5f,-0.5f);
-    Static3D move1  = new Static3D(-E/4,-E/4,0);
-    Static3D move2  = new Static3D(-0.5f,-0.5f,-0.5f);
-
-    float d0 =-0.04f;
-    float d1 = 0.04f;
-    float r0 = 0.15f;
-    float r1 = 0.10f;
-
-    Static3D vec0   = new Static3D(d0*(+SQ3/3),d0*(+SQ3/3),d0*(+SQ3/3));
-    Static3D vec1   = new Static3D(d1*(+SQ3/3),d1*(-SQ3/3),d1*(-SQ3/3));
-    Static3D vec2   = new Static3D(d1*(-SQ3/3),d1*(+SQ3/3),d1*(-SQ3/3));
-    Static3D vec3   = new Static3D(d1*(-SQ3/3),d1*(-SQ3/3),d1*(+SQ3/3));
-
-    Static1D radius = new Static1D(0.5f);
-
-    Static3D cent0  = new Static3D( 0.0f, 0.0f, 0.0f);
-    Static3D cent1  = new Static3D(-0.5f, 0.0f, 0.0f);
-    Static3D cent2  = new Static3D( 0.0f,-0.5f, 0.0f);
-    Static3D cent3  = new Static3D( 0.0f, 0.0f,-0.5f);
-
-    Static4D reg0   = new Static4D(0,0,0,r0);
-    Static4D reg1   = new Static4D(0,0,0,r1);
-
-    VertexEffectMove   effect0 = new VertexEffectMove(move1);
-    VertexEffectScale  effect1 = new VertexEffectScale(new Static3D(1,1,-1));
-    VertexEffectRotate effect2 = new VertexEffectRotate(angle1,axisX,center1);
-    VertexEffectRotate effect3 = new VertexEffectRotate(angle2,axisY,center1);
-    VertexEffectMove   effect4 = new VertexEffectMove(move2);
-    VertexEffectRotate effect5 = new VertexEffectRotate(angle1,axisX,center2);
-    VertexEffectRotate effect6 = new VertexEffectRotate(angle3,axisY,center2);
-    VertexEffectRotate effect7 = new VertexEffectRotate(angle4,axis0,center2);
-    VertexEffectRotate effect8 = new VertexEffectRotate(angle5,axis1,center2);
-    VertexEffectRotate effect9 = new VertexEffectRotate(angle6,axis1,center2);
-
-    VertexEffectDeform effect10= new VertexEffectDeform(vec0,radius,cent0,reg0);
-    VertexEffectDeform effect11= new VertexEffectDeform(vec1,radius,cent1,reg1);
-    VertexEffectDeform effect12= new VertexEffectDeform(vec2,radius,cent2,reg1);
-    VertexEffectDeform effect13= new VertexEffectDeform(vec3,radius,cent3,reg1);
-
-    effect0.setMeshAssociation( 7,-1);  // meshes 0,1,2
-    effect1.setMeshAssociation( 6,-1);  // meshes 1,2
-    effect2.setMeshAssociation( 2,-1);  // mesh 1
-    effect3.setMeshAssociation( 4,-1);  // mesh 2
-    effect4.setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect5.setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect6.setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect7.setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect8.setMeshAssociation(16,-1);  // mesh 4
-    effect9.setMeshAssociation(32,-1);  // mesh 5
-
-    effect10.setMeshAssociation(63,-1); // all meshes
-    effect11.setMeshAssociation(63,-1); // all meshes
-    effect12.setMeshAssociation(63,-1); // all meshes
-    effect13.setMeshAssociation(63,-1); // all meshes
+    Static3D axisZ  = new Static3D(0,-1,1);
+
+    Static3D center0= new Static3D(0,0,0);
+    Static3D center1= new Static3D(0,-3*F,0);
+
+    VertexEffectScale   effect0 = new VertexEffectScale ( new Static3D(3,3,3) );
+    VertexEffectMove    effect1 = new VertexEffectMove  ( new Static3D(0,-F,0) );
+    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), axisX, center0 );
+    VertexEffectScale   effect3 = new VertexEffectScale ( new Static3D(1,-1,1) );
+    VertexEffectMove    effect4 = new VertexEffectMove  ( new Static3D(3*E/2,E*(SQ3/2)-3*F,0) );
+    VertexEffectRotate  effect5 = new VertexEffectRotate( new Static1D(+90), axisY, center1 );
+    VertexEffectScale   effect6 = new VertexEffectScale ( new Static3D(-1,1,1) );
+    VertexEffectRotate  effect7 = new VertexEffectRotate( new Static1D( 45), axisX, center1 );
+    VertexEffectRotate  effect8 = new VertexEffectRotate( angle1           , axisZ, center1 );
+    VertexEffectRotate  effect9 = new VertexEffectRotate( angle2           , axisZ, center1 );
+
+    VertexEffectDeform  effect10= new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
+    VertexEffectDeform  effect11= new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
+    VertexEffectDeform  effect12= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
+    VertexEffectDeform  effect13= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
+
+    effect0.setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
+    effect1.setMeshAssociation( 3,-1);  // apply to meshes 0,1
+    effect2.setMeshAssociation( 2,-1);  // apply to mesh 1
+    effect3.setMeshAssociation( 2,-1);  // apply to mesh 0
+    effect4.setMeshAssociation(12,-1);  // apply to meshes 2,3
+    effect5.setMeshAssociation(12,-1);  // apply to meshes 2,3
+    effect6.setMeshAssociation( 8,-1);  // apply to mesh 3
+    effect7.setMeshAssociation(12,-1);  // apply to meshes 2,3
+    effect8.setMeshAssociation( 4,-1);  // apply to mesh 2
+    effect9.setMeshAssociation( 8,-1);  // apply to mesh 3
+    effect10.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
+    effect11.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
+    effect12.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
+    effect13.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
 
     result.apply(effect0);
     result.apply(effect1);
@@ -665,13 +613,10 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
     result.apply(effect8);
     result.apply(effect9);
     result.apply(effect10);
-
     result.apply(effect11);
     result.apply(effect12);
     result.apply(effect13);
 
-//result.setShowNormals(true);
-
     return result;
     }
 
diff --git a/src/main/res/raw/dino.dmesh b/src/main/res/raw/dino.dmesh
index 09aa2c1..b14b436 100644
Binary files a/src/main/res/raw/dino.dmesh and b/src/main/res/raw/dino.dmesh differ
