commit 54e47d9b35b8e9d9016db164cf5b84d372010e88
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Apr 1 23:53:52 2021 +0200

    Progress with any size Kilominx.

diff --git a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
index 06af9ab..9d5c481 100644
--- a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
+++ b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
@@ -46,6 +46,7 @@ class FactoryCubit
   private static final float IVY_M = 0.35f;
   private static final float REX_D = 0.2f;
   private static final int   REX_N = 5;
+  private static final float MEGA_D = 0.04f;
 
   static final float SIN18    = (SQ5-1)/4;
   static final float COS18    = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
@@ -773,15 +774,21 @@ class FactoryCubit
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  MeshBase createFacesMegaminxCorner()
+  MeshBase createFacesMinxCorner(int numLayers)
     {
     MeshBase[] meshes = new MeshPolygon[6];
 
     float Y = COS54/(2*SIN54);
 
     float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
-    float[] bands0 = computeBands(0.04f,34,0.3f,0.2f,5);
-    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,2);
+
+    int numBands0 = numLayers==3 ? 5 : 3;
+    int numBands1 = numLayers==3 ? 2 : 2;
+    float h       = numLayers==3 ? 0.04f : 0.03f;
+    int   e       = numLayers==3 ? 4 : 1;
+
+    float[] bands0 = computeBands(h    ,34,0.3f,0.2f, numBands0);
+    float[] bands1 = computeBands(0.00f,34,0.3f,0.2f, numBands1);
 
     meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
     meshes[0].setEffectAssociation(0, 1,0);
@@ -789,7 +796,7 @@ class FactoryCubit
     meshes[1].setEffectAssociation(0, 2,0);
     meshes[2] = meshes[0].copy(true);
     meshes[2].setEffectAssociation(0, 4,0);
-    meshes[3] = new MeshPolygon(vertices0, bands1, 1, 4);
+    meshes[3] = new MeshPolygon(vertices0, bands1, 1, e);
     meshes[3].setEffectAssociation(0, 8,0);
     meshes[4] = meshes[3].copy(true);
     meshes[4].setEffectAssociation(0,16,0);
@@ -799,6 +806,50 @@ class FactoryCubit
     return new MeshJoined(meshes);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createFacesKilominxEdge(int numLayers, float width, float height)
+    {
+    MeshBase[] meshes = new MeshPolygon[6];
+
+    float D = height/COS18;
+    float W = D*SIN18;
+    float X1 = height/2;
+    float Y1 = width/2;
+    float Y2 = (width+W)/2;
+    float X3 = D*SIN54;
+    float Y3 = D*COS54;
+    float X4 = height*SIN_HALFD;
+    float Y4 = height*COS_HALFD;
+
+    float[] vertices0 = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
+    float[] vertices1 = { -X1,-Y2, X1, -Y2, X1, Y2+W,-X1, Y2 };
+    float[] vertices2 = { -X3, 0.0f, 0.0f, -Y3, X3, 0.0f, 0.0f, Y3 };
+    float[] vertices3 = { -X4, 0.0f, 0.0f, -Y4, X4, 0.0f, 0.0f, Y4 };
+
+    int numBands0 = numLayers<=5 ? 5 : 3;
+    int numBands1 = numLayers<=5 ? 3 : 2;
+    float h       = numLayers<=5 ? 0.03f : 0.03f;
+
+    float[] bands0 = computeBands(h    ,34,0.2f,0.2f,numBands0);
+    float[] bands1 = computeBands(0.01f,34,0.3f,0.2f,numBands1);
+
+    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
+    meshes[0].setEffectAssociation(0, 1,0);
+    meshes[1] = meshes[0].copy(true);
+    meshes[1].setEffectAssociation(0, 2,0);
+    meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
+    meshes[2].setEffectAssociation(0, 4,0);
+    meshes[3] = meshes[2].copy(true);
+    meshes[3].setEffectAssociation(0, 8,0);
+    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 2);
+    meshes[4].setEffectAssociation(0,16,0);
+    meshes[5] = new MeshPolygon(vertices3, bands1, 1, 2);
+    meshes[5].setEffectAssociation(0,32,0);
+
+    return new MeshJoined(meshes);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   MeshBase createFacesMegaminxEdge(float width, float height)
@@ -1435,7 +1486,7 @@ class FactoryCubit
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  VertexEffect[] createVertexEffectsMegaminxCorner()
+  VertexEffect[] createVertexEffectsMinxCorner(float width)
     {
     VertexEffect[] effect = new VertexEffect[9];
 
@@ -1444,6 +1495,7 @@ class FactoryCubit
     float sinA = (2*SIN54*SIN54-1)/COS54;
     float cosA = (float)Math.sqrt(1-sinA*sinA);
     float LEN  = 0.5f/SIN54;
+    float scale= width/LEN;
 
     Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
     Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
@@ -1467,7 +1519,7 @@ class FactoryCubit
     effect[5] = new VertexEffectRotate(angleD, axisB, centerD);
     effect[6] = new VertexEffectRotate(angleF, axisX, centerD);
     effect[7] = new VertexEffectMove(move2);
-    effect[8] = new VertexEffectScale(SIN54);
+    effect[8] = new VertexEffectScale(scale);
 
     effect[0].setMeshAssociation(  3,-1);  // meshes 0,1
     effect[1].setMeshAssociation( 16,-1);  // mesh 4
@@ -1479,6 +1531,74 @@ class FactoryCubit
     return effect;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  VertexEffect[] createVertexEffectsKilominxEdge(float width, float height, boolean left)
+    {
+    VertexEffect[] effect = new VertexEffect[11 + (left ? 0:1)];
+
+    float D = height/COS18;
+    float W = D*SIN18;
+    float X1 = height/2;
+    float Y1 = width/2;
+    float Y2 = (width+W)/2;
+    float Y3 = D*COS54;
+    float Y4 = height*COS_HALFD;
+    float Z = 2*height*COS_HALFD;
+    float alpha = 90-DIHEDRAL1/2;
+    float beta  = DIHEDRAL2;
+
+    Static1D angle1 = new Static1D(alpha);
+    Static1D angle2 = new Static1D(180-alpha);
+    Static1D angle3 = new Static1D(beta);
+    Static1D angle4 = new Static1D(90);
+
+    Static3D move1 = new Static3D(+X1,-Y1,0);
+    Static3D move2 = new Static3D(-X1,-Y2+W,-Z);
+    Static3D move3 = new Static3D(0,+Y3,0);
+    Static3D move4 = new Static3D(0,-Y4-width,0);
+    Static3D scale = new Static3D(+1,+1,-1);
+
+    Static3D axisXplus = new Static3D(+1, 0, 0);
+    Static3D axisYplus = new Static3D( 0,+1, 0);
+
+    Static3D center1= new Static3D( 0, 0, 0);
+    Static3D center2= new Static3D( 0, 0,-Z);
+    Static3D center3= new Static3D( 0,-width, 0);
+
+    effect[ 0] = new VertexEffectMove(move1);
+    effect[ 1] = new VertexEffectMove(move2);
+    effect[ 2] = new VertexEffectMove(move3);
+    effect[ 3] = new VertexEffectMove(move4);
+    effect[ 4] = new VertexEffectScale(scale);
+    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
+    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
+    effect[ 7] = new VertexEffectRotate(angle1, axisYplus , center2);
+    effect[ 8] = new VertexEffectRotate(angle2, axisYplus , center2);
+    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center1);
+    effect[10] = new VertexEffectRotate(angle4, axisXplus , center3);
+
+    if( !left )
+      {
+      Static3D scale1 = new Static3D(+1,-1,+1);
+      effect[11] = new VertexEffectScale(scale1);
+      }
+
+    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
+    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
+    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
+    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
+    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
+    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
+    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
+    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
+    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
+    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
+    effect[10].setMeshAssociation(32,-1);  // mesh 5
+
+    return effect;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
@@ -1967,10 +2087,10 @@ class FactoryCubit
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  MeshBase createMegaminxCornerMesh()
+  MeshBase createKilominxEdgeMesh(int numLayers, float width, float height, boolean left)
     {
-    MeshBase mesh = createFacesMegaminxCorner();
-    VertexEffect[] effects = createVertexEffectsMegaminxCorner();
+    MeshBase mesh = createFacesKilominxEdge(numLayers,width,height);
+    VertexEffect[] effects = createVertexEffectsKilominxEdge(width,height,left);
     for( VertexEffect effect : effects ) mesh.apply(effect);
 
     float A = (2*SQ3/3)* SIN54;
@@ -1978,14 +2098,14 @@ class FactoryCubit
     float X = SIN_HALFD* SIN54 * COS54;
     float Y = SIN54 * SIN54 - 0.5f;
     float Z = COS_HALFD* SIN54 * COS54;
+    float S = 2*width;
 
     Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
-
     Static3D[] vertices = new Static3D[4];
-    vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f);
-    vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f);
-    vertices[2] = new Static3D(-X   , Y   ,-Z   );
-    vertices[3] = new Static3D(+X   , Y   ,-Z   );
+    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
+    vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f);
+    vertices[2] = new Static3D(-X*S , Y*S   ,-Z*S );
+    vertices[3] = new Static3D(+X*S , Y*S   ,-Z*S );
 
     roundCorners(mesh,center,vertices,0.04f,0.10f);
 
@@ -1994,6 +2114,29 @@ class FactoryCubit
     return mesh;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createMinxCornerMesh()
+    {
+    int numLayers = 9;
+    float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
+
+    MeshBase mesh = createFacesMinxCorner(numLayers);
+    VertexEffect[] effects = createVertexEffectsMinxCorner(width);
+    for( VertexEffect effect : effects ) mesh.apply(effect);
+
+    float A = (2*SQ3/3)* SIN54;
+    float B = 0.4f;
+    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
+    Static3D[] vertices = new Static3D[1];
+    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
+    roundCorners(mesh,center,vertices,0.04f,0.10f);
+
+    //mesh.mergeEffComponents();
+
+    return mesh;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   MeshBase createMegaminxEdgeMesh(float width, float height)
diff --git a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
index 87c9519..a463f2a 100644
--- a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
+++ b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
@@ -54,6 +54,8 @@ import javax.microedition.khronos.egl.EGLConfig;
 import javax.microedition.khronos.opengles.GL10;
 
 import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
+import static org.distorted.examples.meshfile.FactoryCubit.COS18;
+import static org.distorted.examples.meshfile.FactoryCubit.SIN18;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -328,10 +330,14 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
 
     private void createMesh()
       {
-      int[] dimensions = new int[] {1,1,3};
+      int type = 0;
+      int numLayers = 3;
+      float tmp   = (numLayers/3.0f)/(numLayers-1);
+      float height= tmp*COS18;
+      float width = tmp + type*height*SIN18/COS18;
 
       FactoryCubit factory = FactoryCubit.getInstance();
-      mMesh = factory.createCuboidMesh(dimensions);
+      mMesh = factory.createKilominxEdgeMesh(numLayers, width, height, (type%2)==0 );
 
       //mMesh = createStaticMesh();
 
