commit 7dc57f89fb4dc01641759703372ab66a6611e96a
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Apr 15 01:16:06 2021 +0200

    Convert the Skewb.

diff --git a/src/main/java/org/distorted/helpers/FactoryCubit.java b/src/main/java/org/distorted/helpers/FactoryCubit.java
index 7dd308bd..033dba7a 100644
--- a/src/main/java/org/distorted/helpers/FactoryCubit.java
+++ b/src/main/java/org/distorted/helpers/FactoryCubit.java
@@ -238,66 +238,6 @@ public class FactoryCubit
       }
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  MeshBase createFacesSkewbCorner()
-    {
-    MeshBase[] meshes = new MeshBase[6];
-
-    float E = 0.5f;
-    float F = SQ2/2;
-    float G = SQ6/16;
-    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
-    float[] bands0 = computeBands(0.028f,35,E/3,0.7f,7);
-
-    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
-    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 = { -F/2,-2*G, F/2,-2*G, 3*F/8,-G, 1*F/8,G, 0,2*G };
-    float[] bands1 = computeBands(0,0,1,0,3);
-
-    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
-    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);
-
-    return new MeshJoined(meshes);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  MeshBase createFacesSkewbFace()
-    {
-    MeshBase[] meshes = new MeshBase[5];
-
-    float E = SQ2/4;
-    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
-    float[] bands0 = computeBands(0.051f,35,E/2,0.9f,7);
-
-    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
-    meshes[0].setEffectAssociation(0,1,0);
-
-    float[] vertices1 = { -E,-SQ3*E, -E*0.7f,-SQ3*E, +E*0.7f,-SQ3*E, +E,-SQ3*E, 0,0 };
-    float[] bands1 = computeBands(0,0,1,0,3);
-
-    meshes[1] = new MeshPolygon(vertices1,bands1,0,0);
-    meshes[1].setEffectAssociation(0,2,0);
-    meshes[2] = meshes[1].copy(true);
-    meshes[2].setEffectAssociation(0,4,0);
-    meshes[3] = meshes[1].copy(true);
-    meshes[3].setEffectAssociation(0,8,0);
-    meshes[4] = meshes[1].copy(true);
-    meshes[4].setEffectAssociation(0,16,0);
-
-    return new MeshJoined(meshes);
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   MeshBase createFacesHelicopterCorner()
@@ -813,84 +753,6 @@ public class FactoryCubit
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // EFFECTS
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  VertexEffect[] createVertexEffectsSkewbCorner()
-    {
-    float E = 0.5f;
-
-    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+SQ2/4,-0.5f+SQ6/8,-0.5f);
-
-    VertexEffect[] effect = new VertexEffect[10];
-
-    effect[0] = new VertexEffectMove(move1);
-    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
-    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
-    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
-    effect[4] = new VertexEffectMove(move2);
-    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
-    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
-    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
-    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
-    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
-
-    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
-    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
-    effect[2].setMeshAssociation( 2,-1);  // mesh 1
-    effect[3].setMeshAssociation( 4,-1);  // mesh 2
-    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
-    effect[8].setMeshAssociation(16,-1);  // mesh 4
-    effect[9].setMeshAssociation(32,-1);  // mesh 5
-
-    return effect;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  VertexEffect[] createVertexEffectsSkewbFace()
-    {
-    Static3D center = new Static3D(0,0,0);
-    Static3D axisX  = new Static3D(1,0,0);
-    Static3D axisZ  = new Static3D(0,0,1);
-    float angle = -(float)((180.0f/Math.PI)*Math.acos(SQ3/3));
-
-    VertexEffect[] effect = new VertexEffect[6];
-
-    effect[0] = new VertexEffectRotate( new Static1D(angle), axisX, center);
-    effect[1] = new VertexEffectRotate( new Static1D(  135), axisZ, center);
-    effect[2] = new VertexEffectRotate( new Static1D(   45), axisZ, center);
-    effect[3] = new VertexEffectRotate( new Static1D(  -45), axisZ, center);
-    effect[4] = new VertexEffectRotate( new Static1D( -135), axisZ, center);
-    effect[5] = new VertexEffectMove( new Static3D(0,0,-0.5f) );
-
-    effect[0].setMeshAssociation(30,-1);  // meshes 1,2,3,4
-    effect[1].setMeshAssociation( 2,-1);  // mesh 1
-    effect[2].setMeshAssociation( 5,-1);  // meshes 0,2
-    effect[3].setMeshAssociation( 8,-1);  // mesh 3
-    effect[4].setMeshAssociation(16,-1);  // mesh 4
-    effect[5].setMeshAssociation(30,-1);  // meshes 1,2,3,4
-
-    return effect;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   VertexEffect[] createVertexEffectsHelicopterCorner()
@@ -1468,56 +1330,6 @@ public class FactoryCubit
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// SKEWB
-
-  public MeshBase createSkewbCornerMesh()
-    {
-    MeshBase mesh = createFacesSkewbCorner();
-    VertexEffect[] effects = createVertexEffectsSkewbCorner();
-    for( VertexEffect effect : effects ) mesh.apply(effect);
-
-    float E = 0.5f;
-    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
-
-    Static3D[] verticesType1 = new Static3D[1];
-    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
-    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
-
-    Static3D[] verticesType2 = new Static3D[3];
-    verticesType2[0] = new Static3D(-E, 0, 0);
-    verticesType2[1] = new Static3D( 0,-E, 0);
-    verticesType2[2] = new Static3D( 0, 0,-E);
-    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
-
-    mesh.mergeEffComponents();
-
-    return mesh;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public MeshBase createSkewbFaceMesh()
-    {
-    MeshBase mesh = createFacesSkewbFace();
-    VertexEffect[] effects = createVertexEffectsSkewbFace();
-    for( VertexEffect effect : effects ) mesh.apply(effect);
-
-    Static3D roundingCenter = new Static3D(0,0,-0.2f);
-    float E = SQ2/4;
-    Static3D[] vertices = new Static3D[4];
-    vertices[0] = new Static3D(-E*SQ2,      0, 0);
-    vertices[1] = new Static3D(+E*SQ2,      0, 0);
-    vertices[2] = new Static3D(     0, -E*SQ2, 0);
-    vertices[3] = new Static3D(     0, +E*SQ2, 0);
-    roundCorners(mesh,roundingCenter,vertices,0.06f,0.10f);
-
-    mesh.mergeEffComponents();
-    mesh.addEmptyTexComponent();
-
-    return mesh;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Helicopter
 
@@ -2367,13 +2179,17 @@ public class FactoryCubit
       staticVert[0] = new Static3D( (float)vertices[v][0], (float)vertices[v][1], (float)vertices[v][2]);
 
       int cent = centerIndexes[v];
-      center.set( centers[cent][0], centers[cent][1], centers[cent][2]);
 
-      int corn = cornerIndexes[v];
-      float strength = corners[corn][0];
-      float radius   = corners[corn][1];
+      if( cent>=0 )
+        {
+        center.set( centers[cent][0], centers[cent][1], centers[cent][2]);
+
+        int corn = cornerIndexes[v];
+        float strength = corners[corn][0];
+        float radius   = corners[corn][1];
 
-      roundCorners(mesh, center, staticVert, strength, radius);
+        roundCorners(mesh, center, staticVert, strength, radius);
+        }
       }
     }
 
diff --git a/src/main/java/org/distorted/objects/TwistySkewb.java b/src/main/java/org/distorted/objects/TwistySkewb.java
index 8cbb4b09..9e8a1f1f 100644
--- a/src/main/java/org/distorted/objects/TwistySkewb.java
+++ b/src/main/java/org/distorted/objects/TwistySkewb.java
@@ -116,12 +116,21 @@ public class TwistySkewb extends TwistyObject
 
   private static final double[][] VERTICES_CORNER = new double[][]
           {
-             // TODO
+              {-0.5f, 0.0f, 0.0f},
+              { 0.0f,-0.5f, 0.0f},
+              { 0.0f, 0.0f,-0.5f},
+              {-0.5f,-0.5f,-0.5f},
+              { 0.0f, 0.0f, 0.0f}
           };
 
   private static final int[][] VERT_INDEXES_CORNER = new int[][]
           {
-             // TODO
+              {0,1,4},
+              {2,0,4},
+              {1,2,4},
+              {3,1,0},
+              {3,2,1},
+              {3,0,2}
           };
 
   private static final double[][] VERTICES_EDGE = new double[][]
@@ -142,12 +151,28 @@ public class TwistySkewb extends TwistyObject
 
   private static final double[][] VERTICES_FACE = new double[][]
           {
-             // TODO
+             {-0.5f, 0.0f, 0.0f },
+             { 0.0f,-0.5f, 0.0f },
+             { 0.5f, 0.0f, 0.0f },
+             { 0.0f, 0.5f, 0.0f },
+             { 0.0f, 0.0f,-0.5f }
           };
 
   private static final int[][] VERT_INDEXES_FACE = new int[][]
           {
-             // TODO
+             {0,1,2,3},
+             {4,1,0},
+             {4,2,1},
+             {4,3,2},
+             {4,0,3}
+          };
+
+
+  private static final float[][] STICKERS = new float[][]
+          {
+             { -0.5f,   0.25f, 0.25f,  -0.5f, 0.25f, 0.25f  },
+             {  0.0f, -1.0f/3, 0.50f, 1.0f/6, -0.5f, 1.0f/6 },
+             { -0.5f,    0.0f, 0.00f,  -0.5f, 0.50f, 0.0f, 0.0f, 0.5f }
           };
 
   private static MeshBase[] mMeshes;
@@ -478,7 +503,25 @@ public class TwistySkewb extends TwistyObject
       {
       if( mMeshes[0]==null )
         {
-        mMeshes[0] = FactoryCubit.getInstance().createSkewbCornerMesh();
+        float[][] bands= new float[][]
+          {
+             {0.028f,35,0.16f,0.7f,7,3,3},
+             {0.000f, 0,1.00f,0.0f,3,1,5}
+          };
+        int[] bandIndexes   = new int[] { 0,0,0,1,1,1 };
+        float[][] corners   = new float[][] { {0.08f,0.15f}, {0.08f,0.20f} };
+        int[] cornerIndexes = new int[] { 1,1,1,0,0 };
+        float[][] centers   = new float[][] { {-0.25f, -0.25f, -0.25f} };
+        int[] centerIndexes = new int[] { 0,0,0,-1,0 };
+
+        FactoryCubit factory = FactoryCubit.getInstance();
+        factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
+        mMeshes[0] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
+                                                bands, bandIndexes,
+                                                corners, cornerIndexes,
+                                                centers, centerIndexes,
+                                                getNumCubitFaces() );
+        //mMeshes[0] = FactoryCubit.getInstance().createSkewbCornerMesh();
         }
       mesh = mMeshes[0].copy(true);
       }
@@ -511,7 +554,24 @@ public class TwistySkewb extends TwistyObject
       {
       if( mMeshes[2]==null )
         {
-        mMeshes[2] = FactoryCubit.getInstance().createSkewbFaceMesh();
+        float[][] bands= new float[][]
+          {
+             {0.051f,35,SQ2/8,0.9f, 7,3,3},
+             {0.000f, 0,    1,0.0f, 3,0,0}
+          };
+        int[] bandIndexes   = new int[] { 0,1,1,1,1 };
+        float[][] corners   = new float[][] { {0.06f,0.10f} };
+        int[] cornerIndexes = new int[] { 0,0,0,0,0 };
+        float[][] centers   = new float[][] { {0,0,-0.2f} };
+        int[] centerIndexes = new int[] { 0,0,0,0,-1 };
+
+        FactoryCubit factory = FactoryCubit.getInstance();
+        factory.createNewFaceTransform(VERTICES_FACE,VERT_INDEXES_FACE);
+        mMeshes[2] = factory.createRoundedSolid(VERTICES_FACE, VERT_INDEXES_FACE,
+                                                bands, bandIndexes,
+                                                corners, cornerIndexes,
+                                                centers, centerIndexes,
+                                                getNumCubitFaces() );
         }
       mesh = mMeshes[2].copy(true);
       }
@@ -550,33 +610,18 @@ public class TwistySkewb extends TwistyObject
   void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
     {
     int COLORS = FACE_COLORS.length;
-    float R,S;
-    float[] vertices;
+    float R=0.0f,S=0.0f;
+    int cubitType = face/COLORS;
 
-    if( face<COLORS )
-      {
-      float E = 0.5f;
-      R = 0.023f;
-      S = 0.035f;
-      vertices = new float[] { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
-      }
-    else if( face<2*COLORS )
-      {
-      float E = 0.5f;
-      R = 0.025f;
-      S = 0.05f;
-      vertices = new float[] { -E,E/3, 0,-2*E/3, +E,E/3 };
-      }
-    else
+    switch(cubitType)
       {
-      float E = SQ2/4;
-      R = 0.055f;
-      S = 0.035f;
-      vertices = new float[] { -E,-E, +E,-E, +E,+E, -E,+E };
+      case 0: R = 0.025f; S = 0.045f; break;
+      case 1: R = 0.025f; S = 0.035f; break;
+      case 2: R = 0.055f; S = 0.035f; break;
       }
 
     FactorySticker factory = FactorySticker.getInstance();
-    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face%COLORS], R);
+    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[cubitType], S, FACE_COLORS[face%COLORS], R);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
