commit a40adec7c6bc7cc9ec7f767e4dd02c002dd6981a
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Aug 17 17:30:20 2021 +0200

    Convert the Ivy corner cubit to the new, 'universal' cubit creation method.
    
    This forces deep changes to 'createRoundSolid' and the underlying 'MeshPolygon' class to make them support arbitrary Polygon 'centers of face convexity'.
    
    Reason: the faces of this cubit are concave and such default 'center of face convexity' (which by default used to be (0,0)) turned to lie outside the face - which produces strange visual artifacts.

diff --git a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
index cf27c26..1ccfc93 100644
--- a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
+++ b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
@@ -835,19 +835,54 @@ class FactoryCubit
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void computeConvexityCenter(double[] out, float[] in, FaceTransform ft)
+    {
+    if( in==null )
+      {
+      out[0] = out[1] = 0.0f;
+      }
+    else
+      {
+      out[0] = in[0] - ft.vx;
+      out[1] = in[1] - ft.vy;
+      out[2] = in[2] - ft.vz;
+      out[3] = 1.0f;
+
+      mQuat1[0] =-ft.qx;
+      mQuat1[1] =-ft.qy;
+      mQuat1[2] =-ft.qz;
+      mQuat1[3] = ft.qw;
+
+      mQuat2[0] = -mQuat1[0];
+      mQuat2[1] = -mQuat1[1];
+      mQuat2[2] = -mQuat1[2];
+      mQuat2[3] = +mQuat1[3];
+
+      quatMultiply(mQuat1, out  , mQuat3);
+      quatMultiply(mQuat3, mQuat2, out  );
+
+      out[0] /= ft.scale;
+      out[1] /= ft.scale;
+      out[2] /= ft.scale;
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public MeshBase createRoundedSolid(final double[][] vertices, final int[][] vertIndexes,
                                      final float[][] bands    , final int[]   bandIndexes,
                                      final float[][] corners  , final int[]   cornerIndexes,
                                      final float[][] centers  , final int[]   centerIndexes,
-                                     final int numComponents )
+                                     final int numComponents  , final float[] convexityCenter )
     {
     int numFaces = vertIndexes.length;
     float[] band, bandsComputed;
     MeshBase[] meshes = new MeshBase[numFaces];
     FaceTransform fInfo;
     StickerCoords sInfo;
+    double[] convexXY = new double[4];
 
     for(int face=0; face<numFaces; face++)
       {
@@ -859,9 +894,11 @@ class FactoryCubit
       float[] vertsFloat = new float[lenVerts];
       for(int i=0; i<lenVerts; i++) vertsFloat[i] = (float)verts[i];
 
+      computeConvexityCenter(convexXY,convexityCenter,fInfo);
+
       band = bands[bandIndexes[face]];
       bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]);
-      meshes[face] = new MeshPolygon(vertsFloat,bandsComputed,(int)band[5],(int)band[6]);
+      meshes[face] = new MeshPolygon(vertsFloat,bandsComputed,(int)band[5],(int)band[6], (float)convexXY[0], (float)convexXY[1]);
       meshes[face].setEffectAssociation(0,(1<<face),0);
       }
 
diff --git a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
index aa7f8db..5147ea8 100644
--- a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
+++ b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
@@ -254,8 +254,8 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
 
     private void createMesh()
       {
-      int mode = 14;
-      int numComponents = 0;
+      int mode            = 5;
+      int numComponents   = 0;
       double[][] vertices = null;
       int[][] vertIndexes = null;
       float[][] bands     = null;
@@ -264,6 +264,7 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
       int[] cornerIndexes = null;
       float[][] centers   = null;
       int[] centerIndexes = null;
+      float[] convexCenter= null;
 
       ///// CUBE ////////////////////////////////////////////////////////////////////////////////
 
@@ -519,7 +520,7 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
 
       else if( mode==5 )
         {
-        int IVY_N = 3;
+        int IVY_N = 8;
         final float IVY_D = 0.003f;
         final double angle = Math.PI/(2*IVY_N);
         final double CORR  = 1.0 - 2*IVY_D;
@@ -625,6 +626,9 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
           centerIndexes[i] = -1;
           }
 
+        float C = 0.5f - SQ2/4;
+        convexCenter = new float[] {-C,-C,-C};
+
         numComponents = 6;
         }
 
@@ -1246,7 +1250,7 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
                                          bands, bandIndexes,
                                          corners, cornerIndexes,
                                          centers, centerIndexes,
-                                         numComponents );
+                                         numComponents, convexCenter );
 
       int numEff = mMesh.getNumEffComponents();
 
