commit 9e8eb9e44d3cdbdc71c13d2ecdf88d5ff4066fed
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Oct 27 17:20:25 2021 +0200

    Correect JSON reading and writing: shape corners and centers are optional!

diff --git a/build.gradle b/build.gradle
index 40291065..a1c8b493 100644
--- a/build.gradle
+++ b/build.gradle
@@ -26,4 +26,6 @@ dependencies {
     api project(':distorted-library')
     implementation 'com.google.firebase:firebase-crashlytics:18.2.3'
     implementation 'androidx.appcompat:appcompat:1.3.1'
+    implementation project(path: ':distorted-puzzle-dmesh')
+    implementation project(path: ':distorted-puzzle-jsons')
 }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/objectlib/json/JsonReader.java b/src/main/java/org/distorted/objectlib/json/JsonReader.java
index 915e1182..6675ae3d 100644
--- a/src/main/java/org/distorted/objectlib/json/JsonReader.java
+++ b/src/main/java/org/distorted/objectlib/json/JsonReader.java
@@ -233,43 +233,48 @@ public class JsonReader
         }
 
       ////// cornerPush ///////////////////////////////////////////////
-      JSONArray jsonCornerPush= jsonShape.getJSONArray("cornerPush");
-      int numCornerP = jsonCornerPush.length();
-      corners[i] = new float[numCornerP][2];
+      JSONArray jsonCornerPush= jsonShape.optJSONArray("cornerPush");
 
-      for(int j=0; j<numCornerP; j++)
+      if( jsonCornerPush!=null )
         {
-        JSONObject jsonC = jsonCornerPush.getJSONObject(j);
-        corners[i][j][0] = (float)jsonC.getDouble("strength");
-        corners[i][j][1] = (float)jsonC.getDouble("radius");
+        int numCornerP = jsonCornerPush.length();
+        corners[i] = new float[numCornerP][2];
+
+        for(int j=0; j<numCornerP; j++)
+          {
+          JSONObject jsonC = jsonCornerPush.getJSONObject(j);
+          corners[i][j][0] = (float)jsonC.getDouble("strength");
+          corners[i][j][1] = (float)jsonC.getDouble("radius");
+          }
         }
 
       ////// centerPush ///////////////////////////////////////////////
-      JSONArray jsonCenterPush= jsonShape.getJSONArray("centerPush");
-      int numCenterP = jsonCenterPush.length();
-      centers[i] = new float[numCenterP][3];
+      JSONArray jsonCenterPush= jsonShape.optJSONArray("centerPush");
 
-      for(int j=0; j<numCenterP; j++)
+      if( jsonCenterPush!=null )
         {
-        JSONObject jsonC = jsonCenterPush.getJSONObject(j);
-        centers[i][j][0] = (float)jsonC.getDouble("x");
-        centers[i][j][1] = (float)jsonC.getDouble("y");
-        centers[i][j][2] = (float)jsonC.getDouble("z");
+        int numCenterP = jsonCenterPush.length();
+        centers[i] = new float[numCenterP][3];
+
+        for(int j=0; j<numCenterP; j++)
+          {
+          JSONObject jsonC = jsonCenterPush.getJSONObject(j);
+          centers[i][j][0] = (float)jsonC.getDouble("x");
+          centers[i][j][1] = (float)jsonC.getDouble("y");
+          centers[i][j][2] = (float)jsonC.getDouble("z");
+          }
         }
 
       ////// convexity ///////////////////////////////////////////////
-      try
+      JSONObject jsonConvexity = jsonShape.optJSONObject("convexity");
+
+      if( jsonConvexity!=null )
         {
-        JSONObject jsonConvexity = jsonShape.getJSONObject("convexity");
         convexity[i] = new float[3];
         convexity[i][0] = (float)jsonConvexity.getDouble("x");
         convexity[i][1] = (float)jsonConvexity.getDouble("y");
         convexity[i][2] = (float)jsonConvexity.getDouble("z");
         }
-      catch(JSONException ex)
-        {
-        // ignore
-        }
       }
 
     for(int i=0; i<mNumCubitVariants; i++)
diff --git a/src/main/java/org/distorted/objectlib/json/JsonWriter.java b/src/main/java/org/distorted/objectlib/json/JsonWriter.java
index 36112731..1feb662e 100644
--- a/src/main/java/org/distorted/objectlib/json/JsonWriter.java
+++ b/src/main/java/org/distorted/objectlib/json/JsonWriter.java
@@ -273,10 +273,18 @@ public class JsonWriter
       shapeObj.put("faces", facesArr);
       JSONArray bandsArr = generateBands(bands);
       shapeObj.put("bands", bandsArr);
-      JSONArray cornerArr = generateCorners(corners);
-      shapeObj.put("cornerPush", cornerArr);
-      JSONArray centerArr = generateCenters(centers);
-      shapeObj.put("centerPush", centerArr);
+
+      if( corners!=null )
+        {
+        JSONArray cornerArr = generateCorners(corners);
+        shapeObj.put("cornerPush", cornerArr);
+        }
+
+      if( centers!=null )
+        {
+        JSONArray centerArr = generateCenters(centers);
+        shapeObj.put("centerPush", centerArr);
+        }
 
       shapes.put(shapeObj);
       }
diff --git a/src/main/res/raw/ban1_3.dmesh b/src/main/res/raw/ban1_3.dmesh
deleted file mode 100644
index b9d7abdf..00000000
Binary files a/src/main/res/raw/ban1_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/ban2_3.dmesh b/src/main/res/raw/ban2_3.dmesh
deleted file mode 100644
index 7b914a4c..00000000
Binary files a/src/main/res/raw/ban2_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/ban3_3.dmesh b/src/main/res/raw/ban3_3.dmesh
deleted file mode 100644
index c8d5d2b7..00000000
Binary files a/src/main/res/raw/ban3_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/ban4_3.dmesh b/src/main/res/raw/ban4_3.dmesh
deleted file mode 100644
index e3f207ad..00000000
Binary files a/src/main/res/raw/ban4_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/cu_232.dmesh b/src/main/res/raw/cu_232.dmesh
deleted file mode 100644
index 5cf3b284..00000000
Binary files a/src/main/res/raw/cu_232.dmesh and /dev/null differ
diff --git a/src/main/res/raw/cu_323.dmesh b/src/main/res/raw/cu_323.dmesh
deleted file mode 100644
index 24a3122b..00000000
Binary files a/src/main/res/raw/cu_323.dmesh and /dev/null differ
diff --git a/src/main/res/raw/cu_343.dmesh b/src/main/res/raw/cu_343.dmesh
deleted file mode 100644
index 6716a7b2..00000000
Binary files a/src/main/res/raw/cu_343.dmesh and /dev/null differ
diff --git a/src/main/res/raw/cube_2.dmesh b/src/main/res/raw/cube_2.dmesh
deleted file mode 100644
index fbebccf0..00000000
Binary files a/src/main/res/raw/cube_2.dmesh and /dev/null differ
diff --git a/src/main/res/raw/cube_3.dmesh b/src/main/res/raw/cube_3.dmesh
deleted file mode 100644
index ce97963d..00000000
Binary files a/src/main/res/raw/cube_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/cube_4.dmesh b/src/main/res/raw/cube_4.dmesh
deleted file mode 100644
index 895f9634..00000000
Binary files a/src/main/res/raw/cube_4.dmesh and /dev/null differ
diff --git a/src/main/res/raw/cube_5.dmesh b/src/main/res/raw/cube_5.dmesh
deleted file mode 100644
index 7e2cd422..00000000
Binary files a/src/main/res/raw/cube_5.dmesh and /dev/null differ
diff --git a/src/main/res/raw/diam_2.dmesh b/src/main/res/raw/diam_2.dmesh
deleted file mode 100644
index 2ffc96ec..00000000
Binary files a/src/main/res/raw/diam_2.dmesh and /dev/null differ
diff --git a/src/main/res/raw/diam_3.dmesh b/src/main/res/raw/diam_3.dmesh
deleted file mode 100644
index 64a9247d..00000000
Binary files a/src/main/res/raw/diam_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/diam_4.dmesh b/src/main/res/raw/diam_4.dmesh
deleted file mode 100644
index ab6de2ee..00000000
Binary files a/src/main/res/raw/diam_4.dmesh and /dev/null differ
diff --git a/src/main/res/raw/dino_3.dmesh b/src/main/res/raw/dino_3.dmesh
deleted file mode 100644
index 6a86ae85..00000000
Binary files a/src/main/res/raw/dino_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/heli_3.dmesh b/src/main/res/raw/heli_3.dmesh
deleted file mode 100644
index f50e871f..00000000
Binary files a/src/main/res/raw/heli_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/ivy_2.dmesh b/src/main/res/raw/ivy_2.dmesh
deleted file mode 100644
index 831b7d3c..00000000
Binary files a/src/main/res/raw/ivy_2.dmesh and /dev/null differ
diff --git a/src/main/res/raw/jing_2.dmesh b/src/main/res/raw/jing_2.dmesh
deleted file mode 100644
index 3d79603c..00000000
Binary files a/src/main/res/raw/jing_2.dmesh and /dev/null differ
diff --git a/src/main/res/raw/kilo_3.dmesh b/src/main/res/raw/kilo_3.dmesh
deleted file mode 100644
index 89c96732..00000000
Binary files a/src/main/res/raw/kilo_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/kilo_5.dmesh b/src/main/res/raw/kilo_5.dmesh
deleted file mode 100644
index 91a82ab8..00000000
Binary files a/src/main/res/raw/kilo_5.dmesh and /dev/null differ
diff --git a/src/main/res/raw/mega_3.dmesh b/src/main/res/raw/mega_3.dmesh
deleted file mode 100644
index faf0be11..00000000
Binary files a/src/main/res/raw/mega_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/mega_5.dmesh b/src/main/res/raw/mega_5.dmesh
deleted file mode 100644
index 85c39c6e..00000000
Binary files a/src/main/res/raw/mega_5.dmesh and /dev/null differ
diff --git a/src/main/res/raw/mirr_2.dmesh b/src/main/res/raw/mirr_2.dmesh
deleted file mode 100644
index 152caec7..00000000
Binary files a/src/main/res/raw/mirr_2.dmesh and /dev/null differ
diff --git a/src/main/res/raw/mirr_3.dmesh b/src/main/res/raw/mirr_3.dmesh
deleted file mode 100644
index a1c12104..00000000
Binary files a/src/main/res/raw/mirr_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/pyra_3.dmesh b/src/main/res/raw/pyra_3.dmesh
deleted file mode 100644
index e536f7d2..00000000
Binary files a/src/main/res/raw/pyra_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/pyra_4.dmesh b/src/main/res/raw/pyra_4.dmesh
deleted file mode 100644
index d2179266..00000000
Binary files a/src/main/res/raw/pyra_4.dmesh and /dev/null differ
diff --git a/src/main/res/raw/pyra_5.dmesh b/src/main/res/raw/pyra_5.dmesh
deleted file mode 100644
index b1b43016..00000000
Binary files a/src/main/res/raw/pyra_5.dmesh and /dev/null differ
diff --git a/src/main/res/raw/redi_3.dmesh b/src/main/res/raw/redi_3.dmesh
deleted file mode 100644
index 4d30d35e..00000000
Binary files a/src/main/res/raw/redi_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/rex_3.dmesh b/src/main/res/raw/rex_3.dmesh
deleted file mode 100644
index ac0dfe9e..00000000
Binary files a/src/main/res/raw/rex_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/skew_2.dmesh b/src/main/res/raw/skew_2.dmesh
deleted file mode 100644
index 637dbc83..00000000
Binary files a/src/main/res/raw/skew_2.dmesh and /dev/null differ
diff --git a/src/main/res/raw/skew_3.dmesh b/src/main/res/raw/skew_3.dmesh
deleted file mode 100644
index deae07bf..00000000
Binary files a/src/main/res/raw/skew_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/squ1_3.dmesh b/src/main/res/raw/squ1_3.dmesh
deleted file mode 100644
index 239497d6..00000000
Binary files a/src/main/res/raw/squ1_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/squ2_3.dmesh b/src/main/res/raw/squ2_3.dmesh
deleted file mode 100644
index 56ff0c85..00000000
Binary files a/src/main/res/raw/squ2_3.dmesh and /dev/null differ
diff --git a/src/main/res/raw/ulti_2.dmesh b/src/main/res/raw/ulti_2.dmesh
deleted file mode 100644
index 27bfde0c..00000000
Binary files a/src/main/res/raw/ulti_2.dmesh and /dev/null differ
