commit 2077dd1828a25cd1b81b279d48b481969dbf806f
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Aug 20 23:31:25 2021 +0200

    Convert Redi Cube to the new scheme.

diff --git a/src/main/java/org/distorted/objects/TwistyRedi.java b/src/main/java/org/distorted/objects/TwistyRedi.java
index 44a1aa0c..14fa8c58 100644
--- a/src/main/java/org/distorted/objects/TwistyRedi.java
+++ b/src/main/java/org/distorted/objects/TwistyRedi.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;
@@ -274,7 +275,46 @@ public class TwistyRedi extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private Static4D getQuat(int cubit)
+  ObjectShape getObjectShape(int cubit, int numLayers)
+    {
+    int variant = getCubitVariant(cubit,numLayers);
+
+    if( variant==0 )
+      {
+      float[][] bands= new float[][]
+          {
+            {0.06f,35,0.5f,0.7f,5,2,2},
+            {0.01f,35,0.2f,0.4f,5,2,2}
+          };
+      int[] bandIndices   = new int[] { 0,0,0,1,1,1,1,1,1 };
+      float[][] corners   = new float[][] { {0.06f,0.12f} };
+      int[] cornerIndices = new int[]  { -1,0,-1,0,0,0,-1,-1 };
+      float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
+      int[] centerIndices = new int[] { -1,0,-1,0,0,0,-1,-1 };
+
+      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
+      }
+    else
+      {
+      float[][] bands= new float[][]
+          {
+            {0.038f,35,0.250f,0.7f, 7,2,2},
+            {0.020f,35,0.125f,0.2f, 3,1,2},
+            {0.020f,35,0.125f,0.2f, 3,1,1}
+          };
+      int[] bandIndices   = new int[] { 0,0,1,1,2,2 };
+      float[][] corners   = new float[][] { {0.06f,0.20f} };
+      int[] cornerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
+      float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
+      int[] centerIndices = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
+
+      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private Static4D getQuat(int cubit, int numLayers)
     {
     switch(cubit)
       {
@@ -304,72 +344,43 @@ public class TwistyRedi extends TwistyObject
     return null;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int getNumCubitVariants(int numLayers)
+    {
+    return 2;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getCubitVariant(int cubit, int numLayers)
+    {
+    return cubit<8 ? 0:1;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   MeshBase createCubitMesh(int cubit, int numLayers)
     {
+    int variant = getCubitVariant(cubit,numLayers);
+
     if( mMeshes==null )
       {
       FactoryCubit factory = FactoryCubit.getInstance();
       factory.clear();
-      mMeshes = new MeshBase[2];
+      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
       }
 
-    MeshBase mesh;
-
-    if( cubit<8 )
+    if( mMeshes[variant]==null )
       {
-      if( mMeshes[0]==null )
-        {
-        float[][] bands= new float[][]
-          {
-             {0.06f,35,0.5f,0.7f,5,2,2},
-             {0.01f,35,0.2f,0.4f,5,2,2}
-          };
-        int[] bandIndexes   = new int[] { 0,0,0,1,1,1,1,1,1 };
-        float[][] corners   = new float[][] { {0.06f,0.12f} };
-        int[] cornerIndexes = new int[]  { -1,0,-1,0,0,0,-1,-1 };
-        float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
-        int[] centerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
-
-        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(), null );
-        }
-      mesh = mMeshes[0].copy(true);
-      }
-    else
-      {
-      if( mMeshes[1]==null )
-        {
-        float[][] bands= new float[][]
-          {
-            {0.038f,35,0.250f,0.7f, 7,2,2},
-            {0.020f,35,0.125f,0.2f, 3,1,2},
-            {0.020f,35,0.125f,0.2f, 3,1,1}
-          };
-        int[] bandIndexes   = new int[] { 0,0,1,1,2,2 };
-        float[][] corners   = new float[][] { {0.06f,0.20f} };
-        int[] cornerIndexes = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
-        float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
-        int[] centerIndexes = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
-
-        FactoryCubit factory = FactoryCubit.getInstance();
-        factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
-        mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
-                                                bands, bandIndexes,
-                                                corners, cornerIndexes,
-                                                centers, centerIndexes,
-                                                getNumCubitFaces(), null );
-        }
-      mesh = mMeshes[1].copy(true);
+      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;
