commit 19f0f767ed1a5a1a85e289980b2ce7dbe32db8d2
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sat Jun 27 21:25:47 2020 +0100

    Re-introduce possibility to dynamically create object mesh.

diff --git a/src/main/java/org/distorted/objects/RubikObject.java b/src/main/java/org/distorted/objects/RubikObject.java
index 3abbcc30..d3206bcd 100644
--- a/src/main/java/org/distorted/objects/RubikObject.java
+++ b/src/main/java/org/distorted/objects/RubikObject.java
@@ -28,6 +28,7 @@ import android.graphics.Paint;
 import com.google.firebase.crashlytics.FirebaseCrashlytics;
 
 import org.distorted.library.effect.Effect;
+import org.distorted.library.effect.MatrixEffectMove;
 import org.distorted.library.effect.MatrixEffectQuaternion;
 import org.distorted.library.effect.MatrixEffectScale;
 import org.distorted.library.effect.VertexEffectQuaternion;
@@ -37,6 +38,7 @@ import org.distorted.library.main.DistortedNode;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.mesh.MeshFile;
+import org.distorted.library.mesh.MeshJoined;
 import org.distorted.library.mesh.MeshRectangles;
 import org.distorted.library.message.EffectListener;
 import org.distorted.library.type.Dynamic1D;
@@ -56,6 +58,8 @@ public abstract class RubikObject extends DistortedNode
   private static final float MAX_SIZE_CHANGE = 1.3f;
   private static final float MIN_SIZE_CHANGE = 0.8f;
 
+  private static boolean mCreateFromDMesh = true;
+
   private static final Static3D CENTER = new Static3D(0,0,0);
   static final int INTERIOR_COLOR = 0xff000000;
   private static final int POST_ROTATION_MILLISEC = 500;
@@ -126,39 +130,17 @@ public abstract class RubikObject extends DistortedNode
     mRotationAngleMiddle = new Static1D(0);
     mRotationAngleFinal  = new Static1D(0);
 
-    float scale = mObjectScreenRatio*mNodeSize/mSize;
-    mObjectScale= new Static3D(scale,scale,scale);
+    float scale  = mObjectScreenRatio*mNodeSize/mSize;
+    mObjectScale = new Static3D(scale,scale,scale);
     mScaleEffect = new MatrixEffectScale(mObjectScale);
     mQuatEffect  = new MatrixEffectQuaternion(quat, CENTER);
 
     MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
     nodeEffects.apply(nodeScaleEffect);
 
-    mCubits = new Cubit[NUM_CUBITS];
-    mTexture = new DistortedTexture();
-
-    int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize);
-    int resourceID= list.getResourceIDs()[sizeIndex];
-
-    InputStream is = res.openRawResource(resourceID);
-    DataInputStream dos = new DataInputStream(is);
-    mMesh = new MeshFile(dos);
-
-    try
-      {
-      is.close();
-      }
-    catch(IOException e)
-      {
-      android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
-      }
-
-    for(int i=0; i<NUM_CUBITS; i++)
-      {
-      mCubits[i] = new Cubit(this,mOrigPos[i]);
-      mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0);
-      }
+    createMeshAndCubits(list,res);
 
+    mTexture = new DistortedTexture();
     mEffects = new DistortedEffects();
 
     int num_quats = QUATS.length;
@@ -180,6 +162,53 @@ public abstract class RubikObject extends DistortedNode
     setProjection(fov, 0.1f);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void createMeshAndCubits(RubikObjectList list, Resources res)
+    {
+    mCubits = new Cubit[NUM_CUBITS];
+
+    if( mCreateFromDMesh )
+      {
+      int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize);
+      int resourceID= list.getResourceIDs()[sizeIndex];
+
+      InputStream is = res.openRawResource(resourceID);
+      DataInputStream dos = new DataInputStream(is);
+      mMesh = new MeshFile(dos);
+
+      try
+        {
+        is.close();
+        }
+      catch(IOException e)
+        {
+        android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
+        }
+
+      for(int i=0; i<NUM_CUBITS; i++)
+        {
+        mCubits[i] = new Cubit(this,mOrigPos[i]);
+        mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0);
+        }
+      }
+    else
+      {
+      MeshBase[] cubitMesh = new MeshBase[NUM_CUBITS];
+
+      for(int i=0; i<NUM_CUBITS; i++)
+        {
+        mCubits[i] = new Cubit(this,mOrigPos[i]);
+        cubitMesh[i] = createCubitMesh(i);
+        cubitMesh[i].apply(new MatrixEffectMove(mOrigPos[i]),1,0);
+        cubitMesh[i].setEffectAssociation(0, mCubits[i].computeAssociation(), 0);
+        }
+
+      mMesh = new MeshJoined(cubitMesh);
+      resetAllTextureMaps();
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void setObjectRatio(float sizeChange)
