commit a38fe4b29f3503d8e8031386131d2bdcc7e4f3e7
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Aug 20 23:46:03 2021 +0200

    Convert Rex Cube to the new scheme.

diff --git a/src/main/java/org/distorted/objects/TwistyRex.java b/src/main/java/org/distorted/objects/TwistyRex.java
index 76751594..64e73926 100644
--- a/src/main/java/org/distorted/objects/TwistyRex.java
+++ b/src/main/java/org/distorted/objects/TwistyRex.java
@@ -22,6 +22,7 @@ package org.distorted.objects;
 import android.content.res.Resources;
 
 import org.distorted.helpers.FactoryCubit;
+import org.distorted.helpers.ObjectShape;
 import org.distorted.helpers.ObjectSticker;
 import org.distorted.library.effect.MatrixEffectQuaternion;
 import org.distorted.library.main.DistortedEffects;
@@ -130,9 +131,9 @@ public class TwistyRex extends TwistyObject
 
   private static final float[][] STICKERS = new float[][]
           {
-             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.32f, -0.32f },
+             { -0.5f, 0.1428f, -0.1428f, 0.5f, 0.35f, -0.35f },
              { -0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f },
-             { -0.5f, 0.1f, 0.5f, 0.1f, 0.0f, -0.2f  }
+             { -0.525f, 0.105f, 0.525f, 0.105f, 0.000f, -0.210f  }
           };
   private static final int NUM_STICKERS = STICKERS.length;
 
@@ -146,7 +147,7 @@ public class TwistyRex extends TwistyObject
     final float R3= 0.06f;
     final float[][] angles = { { -F/2,F,F },null,{ F/10,-F,-F } };
     final float[][] radii  = { {R1,R1,R1},{R2,R2,R2,R2},{0,0,R3} };
-    final float[] strokes = { 0.06f, 0.07f, 0.04f };
+    final float[] strokes = { 0.06f, 0.07f, 0.05f };
 
     for(int s=0; s<NUM_STICKERS; s++)
       {
@@ -273,7 +274,90 @@ public class TwistyRex extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private Static4D getQuat(int cubit)
+  ObjectShape getObjectShape(int cubit, int numLayers)
+    {
+    int variant = getCubitVariant(cubit,numLayers);
+
+    if( variant==0 )
+      {
+      float G = (1-REX_D)*SQ2/2;
+
+      double[][] vertices =
+         {
+             {  -0.033333f, 0.23333f, 0.0f },
+             {  -0.233333f, 0.03333f, 0.0f },
+             {  +0.216666f,-0.23666f, 0.0f },
+             {  +0.236666f,-0.21666f, 0.0f }
+         };
+
+      int[][] vertIndexes = { {0,1,2,3},{3,2,1,0} };
+      float[][] centers= new float[][] { {0.0f,0.0f,-G/3} };
+      float[][] corners= new float[][] { {0.03f,0.10f} };
+      int[] indices= {-1,-1,0,0};
+      int[] bandIndices= new int[] { 0,1 };
+
+      float[][] bands =
+        {
+            {+0.016f,10,G/3,0.5f,5,1,1},
+            {+0.230f,45,G/3,0.0f,2,0,0}
+        };
+      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
+      }
+    else if( variant==1 )
+      {
+      double[][] vertices =
+        {
+            { -REX_D,   0.0f, 0.0f },
+            {   0.0f, -REX_D, 0.0f },
+            { +REX_D,   0.0f, 0.0f },
+            {   0.0f, +REX_D, 0.0f }
+        };
+
+      int[][] vertIndexes= { {0,1,2,3},{3,2,1,0} };
+      int[] indices= {-1,-1,-1,-1};
+      int[] bandIndices= new int[] { 0,1 };
+
+      float[][] bands =
+        {
+            {0.025f,10,REX_D/2,0.5f,5,0,0},
+            {0.000f,45,REX_D/2,0.0f,2,0,0}
+        };
+
+      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,null,indices,null,indices,getNumCubitFaces(), null);
+      }
+    else
+      {
+      float E = 0.5f - REX_D;
+      float F = 0.5f;
+      float G = (float)Math.sqrt(E*E+F*F);
+
+      double[][] vertices =
+         {
+             { -F, 0, 0 },
+             {  0,-E, 0 },
+             { +F, 0, 0 },
+             {  0, 0,-E },
+         };
+
+      int[][] vertIndexes = { {0,1,2}, {0,2,3}, {0,3,1}, {1,3,2} };
+      float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} };
+      float[][] corners= new float[][] { {0.06f,0.10f} };
+      int[] indices= {0,-1,0,-1};
+      int[] bandIndices= new int[] { 0,0,1,1 };
+
+      float[][] bands =
+        {
+           {0.03f,27,F/3,0.8f,5,2,3},
+           {0.01f,45,G/3,0.2f,3,1,2}
+        };
+
+      return new ObjectShape(vertices,vertIndexes,bands,bandIndices,corners,indices,centers,indices,getNumCubitFaces(), null);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private Static4D getQuat(int cubit, int numLayers)
     {
     switch(cubit)
       {
@@ -328,144 +412,41 @@ public class TwistyRex extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  MeshBase createCubitMesh(int cubit, int numLayers)
+  private int getNumCubitVariants(int numLayers)
     {
-    if( mMeshes==null )
-      {
-      FactoryCubit factory = FactoryCubit.getInstance();
-      factory.clear();
-      mMeshes = new MeshBase[3];
-      }
-
-    MeshBase mesh;
-
-    if( cubit<24 )
-      {
-      if( mMeshes[0]==null )
-        {
-        float G = (1-REX_D)*SQ2/2;
-
-        double[][] vertices =
-           {
-             {  -0.033333f, 0.23333f, 0.0f },
-             {  -0.233333f, 0.03333f, 0.0f },
-             {  +0.216666f,-0.23666f, 0.0f },
-             {  +0.236666f,-0.21666f, 0.0f }
-           };
+    return 3;
+    }
 
-        int[][] vertIndexes =
-           {
-             {0,1,2,3},
-             {3,2,1,0}
-           };
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-        float[][] centers= new float[][] { {0.0f,0.0f,-G/3} };
-        float[][] corners= new float[][] { {0.03f,0.10f} };
-        int[] indexes= {-1,-1,0,0};
+  int getCubitVariant(int cubit, int numLayers)
+    {
+    return cubit<24 ? 0 : (cubit<30?1:2);
+    }
 
-        int[] bandIndexes= new int[] { 0,1 };
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-        float[][] bands =
-          {
-               {+0.016f,10,G/3,0.5f,5,1,1},
-               {+0.230f,45,G/3,0.0f,2,0,0}
-          };
+  MeshBase createCubitMesh(int cubit, int numLayers)
+    {
+    int variant = getCubitVariant(cubit,numLayers);
 
-        FactoryCubit factory = FactoryCubit.getInstance();
-        factory.createNewFaceTransform(vertices,vertIndexes);
-        mMeshes[0] = factory.createRoundedSolid(vertices, vertIndexes,
-                                                bands, bandIndexes,
-                                                corners, indexes,
-                                                centers, indexes,
-                                                getNumCubitFaces(), null );
-        }
-      mesh = mMeshes[0].copy(true);
-      }
-    else if( cubit<30 )
+    if( mMeshes==null )
       {
-      if( mMeshes[1]==null )
-        {
-        double[][] vertices =
-          {
-            { -REX_D,   0.0f, 0.0f },
-            {   0.0f, -REX_D, 0.0f },
-            { +REX_D,   0.0f, 0.0f },
-            {   0.0f, +REX_D, 0.0f }
-          };
-
-        int[][] vertIndexes=
-          {
-            {0,1,2,3},
-            {3,2,1,0}
-          };
-
-        float[][] bands =
-          {
-            {0.025f,10,REX_D/2,0.5f,5,0,0},
-            {0.000f,45,REX_D/2,0.0f,2,0,0}
-          };
-
-        int[] indexes= {-1,-1,-1,-1};
-        int[] bandIndexes= new int[] { 0,1 };
-
-        FactoryCubit factory = FactoryCubit.getInstance();
-        factory.createNewFaceTransform(vertices,vertIndexes);
-        mMeshes[1] = factory.createRoundedSolid(vertices, vertIndexes,
-                                               bands, bandIndexes,
-                                               null, indexes,
-                                               null, indexes,
-                                               getNumCubitFaces(), null );
-        }
-      mesh = mMeshes[1].copy(true);
+      FactoryCubit factory = FactoryCubit.getInstance();
+      factory.clear();
+      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
       }
-    else
-      {
-      if( mMeshes[2]==null )
-        {
-        float E = 0.5f - REX_D;
-        float F = 0.5f;
-        float G = (float)Math.sqrt(E*E+F*F);
 
-        double[][] vertices =
-           {
-             { -F, 0, 0 },
-             {  0,-E, 0 },
-             { +F, 0, 0 },
-             {  0, 0,-E },
-           };
-
-        int[][] vertIndexes =
-           {
-             {0,1,2},
-             {0,2,3},
-             {0,3,1},
-             {1,3,2}
-           };
-
-        float[][] centers= new float[][] { {0.0f,-0.5f,-0.5f} };
-        float[][] corners= new float[][] { {0.06f,0.10f} };
-        int[] indexes= {0,-1,0,-1};
-
-        int[] bandIndexes= new int[] { 0,0,1,1 };
-
-        float[][] bands =
-          {
-               {0.03f,27,F/3,0.8f,5,2,3},
-               {0.01f,45,G/3,0.2f,3,1,2}
-          };
-
-        FactoryCubit factory = FactoryCubit.getInstance();
-        factory.createNewFaceTransform(vertices,vertIndexes);
-        mMeshes[2] = factory.createRoundedSolid(vertices, vertIndexes,
-                                                bands, bandIndexes,
-                                                corners, indexes,
-                                                centers, indexes,
-                                                getNumCubitFaces(), null );
-        }
-      mesh = mMeshes[2].copy(true);
+    if( mMeshes[variant]==null )
+      {
+      ObjectShape shape = getObjectShape(cubit,numLayers);
+      FactoryCubit factory = FactoryCubit.getInstance();
+      factory.createNewFaceTransform(shape);
+      mMeshes[variant] = factory.createRoundedSolid(shape);
       }
 
-    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
+    MeshBase mesh = mMeshes[variant].copy(true);
+    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
     mesh.apply(quat,0xffffffff,0);
 
     return mesh;
