commit da36b97e3bcf34aa1676d8ccff54a01602032b86
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Dec 16 15:31:10 2020 +0100

    Rex Cube - new mesh, textures and icon.

diff --git a/src/main/java/org/distorted/objects/FactoryCubit.java b/src/main/java/org/distorted/objects/FactoryCubit.java
index f19bc072..76a9260e 100644
--- a/src/main/java/org/distorted/objects/FactoryCubit.java
+++ b/src/main/java/org/distorted/objects/FactoryCubit.java
@@ -38,14 +38,13 @@ class FactoryCubit
   static final float IVY_D = 0.003f;
   static final float IVY_C = 0.59f;
   static final float IVY_M = 0.35f;
-  static final float REX_D = 0.003f;
+  static final float REX_D = 0.2f;
 
   private static final float SQ2 = (float)Math.sqrt(2);
   private static final float SQ3 = (float)Math.sqrt(3);
   private static final float SQ6 = (float)Math.sqrt(6);
 
   private static final int IVY_N = 8;
-  private static final int REX_N = 5;
   private static final Static1D RADIUS = new Static1D(1);
   private static FactoryCubit mThis;
 
@@ -606,35 +605,15 @@ class FactoryCubit
     {
     MeshBase[] meshes = new MeshBase[2];
 
-    final float angle = (float)Math.PI/(6*REX_N);
-    float[] vertices = new float[6*REX_N];
-    final float D = 0.5f - REX_D;
-    final float F = D*SQ2*(SQ3-1);
-    final float B = 2.5f;
-
-    final float V1x = -F*0.5f;
-    final float V1y = -F*SQ3/6;
-    final float V2x = -V1x;
-    final float V2y = V1y;
-    final float V3x = 0.0f;
-    final float V3y = -2*V1y;
-
-    final float C1x = 0.0f;
-    final float C1y = -F*(1+2*SQ3/3);
-    final float C2x = B*V1x;
-    final float C2y = B*V1y;
-    final float C3x = B*V2x;
-    final float C3y = B*V2y;
-
-    for(int i=0; i<REX_N; i++)
-      {
-      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
-      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
-      writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
-      }
+    float F = REX_D*SQ2;
+    float G = (1-REX_D)*SQ2/2;
+    float H = 0.1f;
+    float J = +2*G/3 - H*G;
+
+    float[] vertices = { -F/2, -G/3, +F/2, -G/3, H*F/2, J, -H*F/2, J};
 
-    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
-    float[] bands1 = computeBands(-0.05f,45,0.5f,0.0f,2);
+    float[] bands0 = computeBands(+0.016f,10,G/3,0.5f,5);
+    float[] bands1 = computeBands(-0.230f,45,G/3,0.0f,2);
 
     meshes[0] = new MeshPolygon(vertices,bands0,1,1);
     meshes[0].setEffectAssociation(0,1,0);
@@ -650,39 +629,10 @@ class FactoryCubit
     {
     MeshBase[] meshes = new MeshBase[2];
 
-    final float angle = (float)Math.PI/(6*REX_N);
-    float[] vertices = new float[8*REX_N];
-    final float D = 0.5f - REX_D;
-    final float F = D*(SQ3-1);
-
-    final float V1x = 0.0f;
-    final float V1y = +F;
-    final float V2x = -F;
-    final float V2y = 0.0f;
-    final float V3x = 0.0f;
-    final float V3y = -F;
-    final float V4x = +F;
-    final float V4y = 0.0f;
-
-    final float C1x = +D;
-    final float C1y = -D;
-    final float C2x = +D;
-    final float C2y = +D;
-    final float C3x = -D;
-    final float C3y = +D;
-    final float C4x = -D;
-    final float C4y = -D;
-
-    for(int i=0; i<REX_N; i++)
-      {
-      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
-      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
-      writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
-      writeVertex(C4x,C4y,V4x,V4y, i*angle, vertices, 2*i + 6*REX_N);
-      }
+    float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
 
-    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
-    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
+    float[] bands0 = computeBands(0.016f,10,REX_D/2,0.5f,5);
+    float[] bands1 = computeBands(0.000f,45,REX_D/2,0.0f,2);
 
     meshes[0] = new MeshPolygon(vertices,bands0,0,0);
     meshes[0].setEffectAssociation(0,1,0);
@@ -696,48 +646,30 @@ class FactoryCubit
 
   MeshBase createFacesRexEdge()
     {
-    MeshBase[] meshes = new MeshBase[4];
-
-    final float angle = (float)Math.PI/(6*REX_N);
-    float[] vertices = new float[4*REX_N + 6];
-    final float H = 1.0f - SQ3/2;
-    final float D = 0.5f - REX_D;
-    final float F = 0.5f*(0.5f - D*(SQ3-1));
-
-    final float V1x = -D;
-    final float V1y = +D + F - 0.5f;
-    final float V2x = 0.0f;
-    final float V2y = -F;
-
-    final float C1x = -D;
-    final float C1y = -D + F - 0.5f;
-    final float C2x = +D;
-    final float C2y = C1y;
-
-    for(int i=0; i<REX_N; i++)
-      {
-      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
-      writeVertex(C2x,C2y,V2x,V2y,-i*angle, vertices, 2*i + 2*REX_N);
-      }
-
-    vertices[4*REX_N  ] = +D;
-    vertices[4*REX_N+1] = +F-REX_D;
-    vertices[4*REX_N+2] = +D;
-    vertices[4*REX_N+3] = +F;
-    vertices[4*REX_N+4] = -D;
-    vertices[4*REX_N+5] = +F;
+    MeshBase[] meshes = new MeshPolygon[6];
 
-    float[] bands0 = computeBands(+0.02f, 9,0.5f,0.5f,5);
-    float[] bands1 = computeBands( 0.00f,45,0.5f,0.0f,2);
+    float E = 0.5f - REX_D;
+    float F = 0.5f;
+    float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 };
+    float[] bands0 = computeBands(0.03f,27,F/3,0.8f,5);
 
-    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
+    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3);
     meshes[0].setEffectAssociation(0,1,0);
     meshes[1] = meshes[0].copy(true);
     meshes[1].setEffectAssociation(0,2,0);
-    meshes[2] = new MeshPolygon(vertices,bands1,0,0);
+
+    float G = (float)Math.sqrt(E*E+F*F);
+    float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 };
+    float[] bands1 = computeBands(0.00f,45,G/3,0.2f,3);
+
+    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
     meshes[2].setEffectAssociation(0,4,0);
     meshes[3] = meshes[2].copy(true);
     meshes[3].setEffectAssociation(0,8,0);
+    meshes[4] = meshes[2].copy(true);
+    meshes[4].setEffectAssociation(0,16,0);
+    meshes[5] = meshes[2].copy(true);
+    meshes[5].setEffectAssociation(0,32,0);
 
     return new MeshJoined(meshes);
     }
@@ -949,7 +881,7 @@ class FactoryCubit
     effect[0].setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
     effect[1].setMeshAssociation( 3,-1);  // apply to meshes 0,1
     effect[2].setMeshAssociation( 2,-1);  // apply to mesh 1
-    effect[3].setMeshAssociation( 2,-1);  // apply to mesh 0
+    effect[3].setMeshAssociation( 2,-1);  // apply to mesh 1
     effect[4].setMeshAssociation(12,-1);  // apply to meshes 2,3
     effect[5].setMeshAssociation(12,-1);  // apply to meshes 2,3
     effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
@@ -1173,25 +1105,54 @@ class FactoryCubit
 
   VertexEffect[] createVertexEffectsRexEdge()
     {
-    final float D = 0.5f - REX_D;
-    final float F = 0.5f*(0.5f - D*(SQ3-1));
+    float E = 0.5f - REX_D;
+    float F = 0.5f;
+    float G = (float)Math.sqrt(E*E+F*F);
+    float A = (float)((180/Math.PI)*Math.asin(E/G));
 
-    Static3D move  = new Static3D(0.0f,   -F, 0.0f);
-    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
-    Static3D axisX = new Static3D(1.0f, 0.0f, 0.0f);
-    Static3D axisY = new Static3D(0.0f, 1.0f, 0.0f);
+    Static3D move1 = new Static3D(    0.0f, -E/3, 0.0f);
+    Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f);
+
+    Static3D center0= new Static3D(0.0f, 0.0f, 0.0f);
+    Static3D center1= new Static3D(  -F, 0.0f, 0.0f);
+    Static3D center2= new Static3D(  +F, 0.0f, 0.0f);
+    Static3D axisX  = new Static3D(1.0f, 0.0f, 0.0f);
+    Static3D axisY  = new Static3D(0.0f, 1.0f, 0.0f);
+    Static3D axisZ  = new Static3D(0.0f, 0.0f, 1.0f);
 
     Static1D angle180 = new Static1D(180);
     Static1D angle90  = new Static1D( 90);
+    Static1D angle270 = new Static1D(270);
+    Static1D angle1   = new Static1D(+A);
+    Static1D angle2   = new Static1D(-A);
 
-    VertexEffect[] effect = new VertexEffect[3];
-
-    effect[0] = new VertexEffectMove(move);
-    effect[1] = new VertexEffectRotate(angle180, axisY, center);
-    effect[2] = new VertexEffectRotate(angle90 , axisX, center);
+    VertexEffect[] effect = new VertexEffect[12];
 
-    effect[1].setMeshAssociation(10,-1);  // meshes 1 & 3
-    effect[2].setMeshAssociation(10,-1);  // meshes 1 & 3
+    effect[0] = new VertexEffectMove(move1);
+    effect[1] = new VertexEffectMove(move2);
+    effect[2] = new VertexEffectRotate(  angle90, axisX, center0 );
+    effect[3] = new VertexEffectRotate( angle270, axisX, center0 );
+    effect[4] = new VertexEffectRotate( angle180, axisX, center0 );
+    effect[5] = new VertexEffectRotate( angle180, axisY, center0 );
+    effect[6] = new VertexEffectScale ( new Static3D(-1, 1, 1) );
+    effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) );
+    effect[8] = new VertexEffectRotate(   angle1, axisY, center1);
+    effect[9] = new VertexEffectRotate(   angle2, axisY, center2);
+    effect[10]= new VertexEffectRotate(   angle2, axisZ, center1);
+    effect[11]= new VertexEffectRotate(   angle1, axisZ, center2);
+
+    effect[0].setMeshAssociation( 3,-1);  // meshes 0 & 1
+    effect[1].setMeshAssociation(60,-1);  // meshes 2,3,4,5
+    effect[2].setMeshAssociation( 2,-1);  // meshes 1
+    effect[3].setMeshAssociation(12,-1);  // meshes 2,3
+    effect[4].setMeshAssociation(48,-1);  // meshes 4,5
+    effect[5].setMeshAssociation(32,-1);  // mesh 5
+    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
+    effect[7].setMeshAssociation( 2,-1);  // apply to mesh 1
+    effect[8].setMeshAssociation(16,-1);  // apply to mesh 4
+    effect[9].setMeshAssociation(32,-1);  // apply to mesh 5
+    effect[10].setMeshAssociation(4,-1);  // apply to mesh 2
+    effect[11].setMeshAssociation(8,-1);  // apply to mesh 3
 
     return effect;
     }
@@ -1514,18 +1475,17 @@ class FactoryCubit
     VertexEffect[] effects = createVertexEffectsRexCorner();
     for( VertexEffect effect : effects ) mesh.apply(effect);
 
-    final float F = (0.5f-REX_D)*SQ2*(SQ3-1);
-    final float H = F*SQ3/3;
-    final float G = H*SQ2/2;
-
-    Static3D center = new Static3D(0.0f,0.0f,-H);
+    final float G = (1-REX_D)/3;
+    Static3D center = new Static3D(0.0f,0.0f,-G*SQ2/2);
     Static3D[] vertices = new Static3D[1];
     vertices[0] = new Static3D(+G,-G,+0.0f);
-    roundCorners(mesh,center,vertices,0.08f,0.10f);
+    roundCorners(mesh,center,vertices,0.10f,0.10f);
 
     mesh.mergeEffComponents();
     mesh.addEmptyTexComponent();
     mesh.addEmptyTexComponent();
+    mesh.addEmptyTexComponent();
+    mesh.addEmptyTexComponent();
 
     return mesh;
     }
@@ -1539,6 +1499,8 @@ class FactoryCubit
     mesh.mergeEffComponents();
     mesh.addEmptyTexComponent();
     mesh.addEmptyTexComponent();
+    mesh.addEmptyTexComponent();
+    mesh.addEmptyTexComponent();
 
     return mesh;
     }
diff --git a/src/main/java/org/distorted/objects/FactorySticker.java b/src/main/java/org/distorted/objects/FactorySticker.java
index 3707badd..fe234640 100644
--- a/src/main/java/org/distorted/objects/FactorySticker.java
+++ b/src/main/java/org/distorted/objects/FactorySticker.java
@@ -34,10 +34,24 @@ import static org.distorted.objects.FactoryCubit.REX_D;
 class FactorySticker
   {
   private static final float SQ2 = (float)Math.sqrt(2);
-  private static final float SQ3 = (float)Math.sqrt(3);
-
+  private static final float REX_X,REX_R,REX_B,REX_A, REX_P, REX_T, REX_C, REX_S;
   private static FactorySticker mThis;
 
+  static
+    {
+    float F = REX_D*SQ2;
+    float G = (1-REX_D)*SQ2/2;
+
+    REX_X = (0.5f-REX_D*REX_D)/(2*REX_D);
+    REX_R = (float)Math.sqrt(2*REX_X*REX_X+0.5f);
+    REX_B = (float) ((180/Math.PI)*(2*Math.asin( Math.sqrt(REX_D*REX_D-REX_D+0.5f) / (2*REX_R) )));
+    REX_A = (float) ((180/Math.PI)*Math.acos(REX_X/REX_R)) - 45;
+    REX_P = 45 + REX_B/2 + REX_A;
+    REX_T = (float) ( Math.tan( (Math.PI/180)*(45-REX_P/2) ) );
+    REX_C = (float)(REX_R/Math.cos((Math.PI/180)*REX_B/2) );
+    REX_S = (float)(1/Math.sqrt(1+4*G*G/(F*F)));
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private FactorySticker()
@@ -246,7 +260,7 @@ class FactorySticker
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  void drawRexCornerSticker(Canvas canvas, Paint paint, int left, int top, int color, float stroke, float radius)
+  void drawRexCornerSticker(Canvas canvas, Paint paint, int left, int top, int color, float stroke, float radius1, float radius2)
     {
     paint.setColor(color);
     paint.setStyle(Paint.Style.FILL);
@@ -256,74 +270,35 @@ class FactorySticker
     paint.setStyle(Paint.Style.STROKE);
     paint.setStrokeWidth(stroke*TEXTURE_HEIGHT);
 
-    float F  = (0.5f-REX_D)*SQ2*(SQ3-1);
-    float H1 = F*(1.0f + 2*SQ3/3);
-    float H2 = F*(0.5f +   SQ3/6);
-    float D  = H2*SQ3;
-
-    float cx1 = left+ TEXTURE_HEIGHT*0.5f;
-    float cy1 = top + TEXTURE_HEIGHT*(0.5f+H1);
-    float cx2 = left+ TEXTURE_HEIGHT*(0.5f-D);
-    float cy2 = top + TEXTURE_HEIGHT*(0.5f+H2);
-    float cx3 = left+ TEXTURE_HEIGHT*(0.5f+D);
-    float cy3 = top + TEXTURE_HEIGHT*(0.5f+H2);
-
-    float R1= TEXTURE_HEIGHT*(1-2*REX_D);
-
-    canvas.drawArc( cx1-R1, cy1-R1, cx1+R1, cy1+R1, 255, 30, false ,paint);
-    canvas.drawArc( cx2-R1, cy2-R1, cx2+R1, cy2+R1, 315, 30, false ,paint);
-    canvas.drawArc( cx3-R1, cy3-R1, cx3+R1, cy3+R1, 195, 30, false ,paint);
-
-    float cx   = left+ TEXTURE_HEIGHT*0.5f;
-    float cy   = top + TEXTURE_HEIGHT*0.5f;
-    float R2   = radius*TEXTURE_HEIGHT;
-    float dist = ( (SQ3/3)*F - SQ2*radius )*TEXTURE_HEIGHT;
-    float dist2= 1.0f*(SQ3/3)*F*TEXTURE_HEIGHT;
-    float tmp  = SQ2*radius*TEXTURE_HEIGHT;
-    float distX= (SQ3/2)*dist2 - 1.05f*tmp;
-    float distY= (0.5f )*dist2 - 0.90f*tmp;
-
-    canvas.drawArc( cx      -R2, cy-dist -R2, cx      +R2, cy-dist +R2, 225, 90, false ,paint);
-    canvas.drawArc( cx-distX-R2, cy+distY-R2, cx-distX+R2, cy+distY+R2,  75,120, false ,paint);
-    canvas.drawArc( cx+distX-R2, cy+distY-R2, cx+distX+R2, cy+distY+R2, 345,120, false ,paint);
-    }
+    float F = REX_D*SQ2;
+    float G = (1-REX_D)*SQ2/2;
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
+    float cx1 = left + (0.5f-F/2)*TEXTURE_HEIGHT;
+    float cx2 = left + (0.5f+F/2)*TEXTURE_HEIGHT;
+    float cy  = top  + (0.5f+G/3)*TEXTURE_HEIGHT;
 
-  void drawRexFaceSticker(Canvas canvas, Paint paint, int left, int top, int color, float stroke, float radius)
-    {
-    paint.setColor(color);
-    paint.setStyle(Paint.Style.FILL);
-    canvas.drawRect(left,top,left+TEXTURE_HEIGHT,top+TEXTURE_HEIGHT,paint);
+    canvas.drawLine(cx1, cy, cx2, cy, paint);
 
-    paint.setColor(COLOR_BLACK);
-    paint.setStyle(Paint.Style.STROKE);
-    paint.setStrokeWidth(stroke*TEXTURE_HEIGHT);
+    float X   = REX_C-F/2;
+    float R1  = TEXTURE_HEIGHT*(REX_R + 0.5f*stroke);
+    float cx3 = left + (0.5f-X)*TEXTURE_HEIGHT;
+    float cx4 = left + (0.5f+X)*TEXTURE_HEIGHT;
 
-    float cx1 = left+ TEXTURE_HEIGHT*REX_D;
-    float cy1 = top + TEXTURE_HEIGHT*(1-REX_D);
-    float cx2 = left+ TEXTURE_HEIGHT*REX_D;
-    float cy2 = top + TEXTURE_HEIGHT*REX_D;
-    float cx3 = left+ TEXTURE_HEIGHT*(1-REX_D);
-    float cy3 = top + TEXTURE_HEIGHT*REX_D;
-    float cx4 = left+ TEXTURE_HEIGHT*(1-REX_D);
-    float cy4 = top + TEXTURE_HEIGHT*(1-REX_D);
-    float R1  = TEXTURE_HEIGHT*(1-2*REX_D);
-
-    canvas.drawArc( cx1-R1, cy1-R1, cx1+R1, cy1+R1, 300, 30, false ,paint);
-    canvas.drawArc( cx2-R1, cy2-R1, cx2+R1, cy2+R1,  30, 30, false ,paint);
-    canvas.drawArc( cx3-R1, cy3-R1, cx3+R1, cy3+R1, 120, 30, false ,paint);
-    canvas.drawArc( cx4-R1, cy4-R1, cx4+R1, cy4+R1, 210, 30, false ,paint);
-
-    float cx   = left+ TEXTURE_HEIGHT*0.5f;
-    float cy   = top + TEXTURE_HEIGHT*0.5f;
-    float R2   = radius*TEXTURE_HEIGHT;
-    float dist = ( (0.5f-REX_D)*(SQ3-1) - (2*SQ3/3)*radius )*TEXTURE_HEIGHT;
-
-    canvas.drawArc( cx+dist-R2, cy-R2, cx+dist+R2, cy+R2, 330, 60, false ,paint);
-    canvas.drawArc( cx-R2, cy+dist-R2, cx+R2, cy+dist+R2,  60, 60, false ,paint);
-    canvas.drawArc( cx-dist-R2, cy-R2, cx-dist+R2, cy+R2, 150, 60, false ,paint);
-    canvas.drawArc( cx-R2, cy-dist-R2, cx+R2, cy-dist+R2, 240, 60, false ,paint);
+    canvas.drawArc( cx3-R1, cy-R1, cx3+R1, cy+R1, 360-REX_B/2, REX_B/2, false ,paint);
+    canvas.drawArc( cx4-R1, cy-R1, cx4+R1, cy+R1, 180        , REX_B/2, false ,paint);
+
+    float cx5 = left + (0.5f+F/2-radius2)*TEXTURE_HEIGHT;
+    float cx6 = left + (0.5f-F/2+radius2)*TEXTURE_HEIGHT;
+    float cy1 = top  + (0.5f+G/3-radius2)*TEXTURE_HEIGHT;;
+    float R2  = TEXTURE_HEIGHT*radius2;
+
+    canvas.drawArc( cx5-R2, cy1-R2, cx5+R2, cy1+R2,  0, 90, false ,paint);
+    canvas.drawArc( cx6-R2, cy1-R2, cx6+R2, cy1+R2, 90, 90, false ,paint);
+
+    float cx7 = left + 0.5f*TEXTURE_HEIGHT;
+    float cy2 = top  + (0.5f-2*G/3 + radius1/REX_S)*TEXTURE_HEIGHT;
+    float R3  = TEXTURE_HEIGHT*(radius1 + 0.5f*stroke);
+    canvas.drawArc( cx7-R3, cy2-R3, cx7+R3, cy2+R3, 270-(90-REX_B/2), 180-REX_B, false ,paint);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -338,26 +313,38 @@ class FactorySticker
     paint.setStyle(Paint.Style.STROKE);
     paint.setStrokeWidth(stroke*TEXTURE_HEIGHT);
 
-    final float D = 0.5f - REX_D;
-    final float F = 0.5f*(0.5f - D*(SQ3-1));
+    final float D = ( 0.5f - (0.5f-REX_D)/3);
+    float cx1 = left+ TEXTURE_HEIGHT*(0.5f-REX_X);
+    float cy1 = top + TEXTURE_HEIGHT*(0.5f+REX_X+D);
+    float cx2 = left+ TEXTURE_HEIGHT*(0.5f+REX_X);
+    float R1  = TEXTURE_HEIGHT*REX_R;
+
+    canvas.drawArc( cx1-R1, cy1-R1, cx1+R1, cy1+R1, 315-REX_A-REX_B, REX_B, false ,paint);
+    canvas.drawArc( cx2-R1, cy1-R1, cx2+R1, cy1+R1, 225+REX_A      , REX_B, false ,paint);
 
-    float cx1 = left+ TEXTURE_HEIGHT*REX_D;
-    float cy  = top + TEXTURE_HEIGHT*(1-REX_D-F+0.5f);
-    float cx2 = left+ TEXTURE_HEIGHT*(1-REX_D);
-    float R1  = 1.0f*TEXTURE_HEIGHT*(1-2*REX_D);
+    float CORR_Y = radius/12;
+    float CORR_A = 10;
+    float sin = (float)Math.sin(Math.PI*REX_P/180);
+    float cx = left + 0.5f*TEXTURE_HEIGHT;
+    float cy = top  + ( 0.5f + 2*(0.5f-REX_D)/3 -CORR_Y -radius/sin )*TEXTURE_HEIGHT;
+    float R2  = TEXTURE_HEIGHT*radius;
 
-    canvas.drawArc( cx1-R1, cy-R1, cx1+R1, cy+R1, 270, 30, false ,paint);
-    canvas.drawArc( cx2-R1, cy-R1, cx2+R1, cy+R1, 240, 30, false ,paint);
+    canvas.drawArc( cx-R2, cy-R2, cx+R2, cy+R2, 90-(REX_P-CORR_A), 2*(REX_P-CORR_A), false ,paint);
 
-    float cx = left + TEXTURE_HEIGHT*0.5f;
-    float R2 = radius*TEXTURE_HEIGHT;
-    cy       = top + TEXTURE_HEIGHT*(0.5f+F-(2*SQ3/3)*radius);
+    float F = 0.1f;
+    float G = 0.6f;
+    float R3  = TEXTURE_HEIGHT*radius*G*0.9f;
+    float X = G*radius/REX_T;
+    float cx4 = left + X*TEXTURE_HEIGHT;
+    float cx3 = left + (1-X)*TEXTURE_HEIGHT;
+    float cy3 = top + (0.5f - (0.5f-REX_D)/3 + G*radius - F*stroke)*TEXTURE_HEIGHT;
 
-    canvas.drawArc( cx-R2, cy-R2, cx+R2, cy+R2, 60, 60, false ,paint);
+    canvas.drawArc( cx3-R3, cy3-R3, cx3+R3, cy3+R3, 270           , 90+REX_P, false ,paint);
+    canvas.drawArc( cx4-R3, cy3-R3, cx4+R3, cy3+R3, 270-(90+REX_P), 90+REX_P, false ,paint);
 
-    cy = top + (0.5f-F)*TEXTURE_HEIGHT;
+    float cy5 = top + D*TEXTURE_HEIGHT;
 
-    paint.setStrokeWidth(0.6f*stroke*TEXTURE_HEIGHT);
-    canvas.drawLine(left, cy, left+TEXTURE_HEIGHT, cy, paint);
+    paint.setStrokeWidth((1-2*F)*stroke*TEXTURE_HEIGHT);
+    canvas.drawLine(left, cy5, left+TEXTURE_HEIGHT, cy5, paint);
     }
   }
diff --git a/src/main/java/org/distorted/objects/TwistyObject.java b/src/main/java/org/distorted/objects/TwistyObject.java
index c6f94c41..17cef100 100644
--- a/src/main/java/org/distorted/objects/TwistyObject.java
+++ b/src/main/java/org/distorted/objects/TwistyObject.java
@@ -78,7 +78,7 @@ public abstract class TwistyObject extends DistortedNode
   private static final float MAX_SIZE_CHANGE = 1.35f;
   private static final float MIN_SIZE_CHANGE = 0.75f;
 
-  private static final boolean mCreateFromDMesh = true;
+  private static final boolean mCreateFromDMesh = false;
 
   private static final Static3D CENTER = new Static3D(0,0,0);
   private static final int POST_ROTATION_MILLISEC = 500;
diff --git a/src/main/java/org/distorted/objects/TwistyRex.java b/src/main/java/org/distorted/objects/TwistyRex.java
index e673c9d8..653f39e5 100644
--- a/src/main/java/org/distorted/objects/TwistyRex.java
+++ b/src/main/java/org/distorted/objects/TwistyRex.java
@@ -42,7 +42,7 @@ import static org.distorted.objects.FactoryCubit.REX_D;
 
 public class TwistyRex extends TwistyObject
 {
-  private static final int FACES_PER_CUBIT =4;
+  private static final int FACES_PER_CUBIT =6;
 
   // the four rotation axis of a RubikRex. Must be normalized.
   static final Static3D[] ROT_AXIS = new Static3D[]
@@ -80,50 +80,50 @@ public class TwistyRex extends TwistyObject
 
   private static final int[][] mFaceMap =
          {
-           {  0, 18,18,18 },
-           {  0, 18,18,18 },
-           {  0, 18,18,18 },
-           {  0, 18,18,18 },
-           {  1, 18,18,18 },
-           {  1, 18,18,18 },
-           {  1, 18,18,18 },
-           {  1, 18,18,18 },
-           {  2, 18,18,18 },
-           {  2, 18,18,18 },
-           {  2, 18,18,18 },
-           {  2, 18,18,18 },
-           {  3, 18,18,18 },
-           {  3, 18,18,18 },
-           {  3, 18,18,18 },
-           {  3, 18,18,18 },
-           {  4, 18,18,18 },
-           {  4, 18,18,18 },
-           {  4, 18,18,18 },
-           {  4, 18,18,18 },
-           {  5, 18,18,18 },
-           {  5, 18,18,18 },
-           {  5, 18,18,18 },
-           {  5, 18,18,18 },
-
-           {  6, 18,18,18 },
-           {  7, 18,18,18 },
-           {  8, 18,18,18 },
-           {  9, 18,18,18 },
-           { 10, 18,18,18 },
-           { 11, 18,18,18 },
-
-           { 16,14, 18,18 },
-           { 16,12, 18,18 },
-           { 16,15, 18,18 },
-           { 16,13, 18,18 },
-           { 12,14, 18,18 },
-           { 15,12, 18,18 },
-           { 15,13, 18,18 },
-           { 13,14, 18,18 },
-           { 14,17, 18,18 },
-           { 12,17, 18,18 },
-           { 17,15, 18,18 },
-           { 13,17, 18,18 },
+           {  0, 18,18,18,18,18 },
+           {  0, 18,18,18,18,18 },
+           {  0, 18,18,18,18,18 },
+           {  0, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  1, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  2, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  3, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  4, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+           {  5, 18,18,18,18,18 },
+
+           {  6, 18,18,18,18,18 },
+           {  7, 18,18,18,18,18 },
+           {  8, 18,18,18,18,18 },
+           {  9, 18,18,18,18,18 },
+           { 10, 18,18,18,18,18 },
+           { 11, 18,18,18,18,18 },
+
+           { 16,14, 18,18,18,18 },
+           { 16,12, 18,18,18,18 },
+           { 16,15, 18,18,18,18 },
+           { 16,13, 18,18,18,18 },
+           { 12,14, 18,18,18,18 },
+           { 15,12, 18,18,18,18 },
+           { 15,13, 18,18,18,18 },
+           { 13,14, 18,18,18,18 },
+           { 14,17, 18,18,18,18 },
+           { 12,17, 18,18,18,18 },
+           { 17,15, 18,18,18,18 },
+           { 13,17, 18,18,18,18 },
          };
 
   private static MeshBase mCornerMesh, mFaceMesh, mEdgeMesh;
@@ -192,7 +192,7 @@ public class TwistyRex extends TwistyObject
   Static3D[] getCubitPositions(int numLayers)
     {
     final float DIST = 0.50f;
-    final float DIST2= SQ3/6*(1.0f-2*REX_D);
+    final float DIST2= (1+2*REX_D)/6;
 
     final Static3D[] CENTERS = new Static3D[42];
 
@@ -245,18 +245,6 @@ public class TwistyRex extends TwistyObject
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// 1  +90 ( 1, 0, 0) = Static4D(+SQ2/2,     0,     0, SQ2/2);
-// 2  -90 ( 1, 0, 0) = Static4D(-SQ2/2,     0,     0, SQ2/2);
-// 3  +90 ( 0, 1, 0) = Static4D(     0,+SQ2/2,     0, SQ2/2);
-// 4  -90 ( 0, 1, 0) = Static4D(     0,-SQ2/2,     0, SQ2/2);
-// 5  +90 ( 0, 0, 1) = Static4D(     0,     0,+SQ2/2, SQ2/2);
-// 6  -90 ( 0, 0, 1) = Static4D(     0,     0,-SQ2/2, SQ2/2);
-// 7  180 ( 1, 0, 1) = Static4D(+SQ2/2,     0,+SQ2/2,     0);
-// 8  180 (-1, 0, 1) = Static4D(-SQ2/2,     0,+SQ2/2,     0);
-// 9  180 ( 0, 1, 1) = Static4D(     0,+SQ2/2,+SQ2/2,     0);
-//10  180 ( 0,-1, 1) = Static4D(     0,-SQ2/2,+SQ2/2,     0);
-//11  180 ( 1, 1, 0) = Static4D(+SQ2/2,+SQ2/2,     0,     0);
-//12  180 ( 1,-1, 0) = Static4D(+SQ2/2,-SQ2/2,     0,     0);
 
   private Static4D getQuat(int cubit)
     {
@@ -352,18 +340,21 @@ public class TwistyRex extends TwistyObject
     {
     int COLORS = FACE_COLORS.length;
     FactorySticker factory = FactorySticker.getInstance();
-    float S1 = 0.05f;
-    float S2 = 0.04f;
-    float R1 = 0.12f;
-    float R2 = 0.06f;
+    float S1 = 0.050f;
+    float S2 = 0.051f;
+    float R1 = 0.07f;
+    float R2 = 0.02f;
+    float R3 = 0.06f;
+    float R4 = 0.04f;
 
     if( face<COLORS )
       {
-      factory.drawRexCornerSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S1, R2);
+      factory.drawRexCornerSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S1, R2, R3);
       }
     else if( face<2*COLORS )
       {
-      factory.drawRexFaceSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S1, R1);
+      float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
+      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S1, FACE_COLORS[face%COLORS], R4);
       }
     else
       {
diff --git a/src/main/res/drawable-nodpi/ui_big_rex.png b/src/main/res/drawable-nodpi/ui_big_rex.png
index 4e985ce8..7703be3d 100644
Binary files a/src/main/res/drawable-nodpi/ui_big_rex.png and b/src/main/res/drawable-nodpi/ui_big_rex.png differ
diff --git a/src/main/res/drawable-nodpi/ui_huge_rex.png b/src/main/res/drawable-nodpi/ui_huge_rex.png
index b65c797a..7b352855 100644
Binary files a/src/main/res/drawable-nodpi/ui_huge_rex.png and b/src/main/res/drawable-nodpi/ui_huge_rex.png differ
diff --git a/src/main/res/drawable-nodpi/ui_medium_rex.png b/src/main/res/drawable-nodpi/ui_medium_rex.png
index ea7f70a0..6c861927 100644
Binary files a/src/main/res/drawable-nodpi/ui_medium_rex.png and b/src/main/res/drawable-nodpi/ui_medium_rex.png differ
diff --git a/src/main/res/drawable-nodpi/ui_small_rex.png b/src/main/res/drawable-nodpi/ui_small_rex.png
index cd70d22c..0e6513cb 100644
Binary files a/src/main/res/drawable-nodpi/ui_small_rex.png and b/src/main/res/drawable-nodpi/ui_small_rex.png differ
