commit 808ef3aab0d457ab8eff8c3eada249778493a1e9
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Aug 28 01:36:17 2020 +0100

    First attempt at new mesh - Polygon. Unfinished (normal vector!), untested

diff --git a/src/main/java/org/distorted/library/mesh/MeshPolygon.java b/src/main/java/org/distorted/library/mesh/MeshPolygon.java
new file mode 100644
index 0000000..30da3d1
--- /dev/null
+++ b/src/main/java/org/distorted/library/mesh/MeshPolygon.java
@@ -0,0 +1,176 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2020 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.mesh;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Create a polygon of any shape and varying elevations from the edges towards the center.
+ * <p>
+ * Specify a list of vertices. Any two adjacent vertices + the center (0,0,0) form a triangle. The
+ * polygon is going to be split into such triangles, and each triange is split into adjustable number
+ * of 'bands' form the outer edge towards the center. Edges of each band can can at any elevation.
+ */
+public class MeshPolygon extends MeshBase
+  {
+  private float[] mPolygonVertices;
+  private int mNumPolygonVertices;
+  private float[] mPolygonBands;
+  private int mNumPolygonBands;
+
+  private int remainingVert;
+  private int numVertices;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// polygonVertices>=3 , polygonBands>=2
+
+  private void computeNumberOfVertices(int numPolygonVertices, int numPolygonBands)
+     {
+     numVertices = (numPolygonVertices*numPolygonBands+2)*(numPolygonBands-1) - 1;
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int addVertex(int vertex, int polyBand, int polyVertex, int index, float[] attribs1, float[] attribs2)
+    {
+    remainingVert--;
+
+    float band = mPolygonBands[2*polyBand  ];
+    float elev = mPolygonBands[2*polyBand+1];
+
+    float Xfirst  = mPolygonVertices[2*polyVertex  ]*band;
+    float Yfirst  = mPolygonVertices[2*polyVertex+1]*band;
+
+    int polyEndVer = polyVertex==mNumPolygonVertices-1 ? 0 : polyVertex+1;
+
+    float Xlast   = mPolygonVertices[2*polyEndVer  ]*band;
+    float Ylast   = mPolygonVertices[2*polyEndVer+1]*band;
+
+    float quot = (float)index / (polyBand-1);
+
+    float x = Xfirst + quot*(Xlast-Xfirst);
+    float y = Yfirst + quot*(Ylast-Yfirst);
+
+    attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB  ] =    x;
+    attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] =    y;
+    attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = elev;
+
+    attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB  ] = 0.0f;  //
+    attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;  // TODO
+    attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;  //
+
+    attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB  ] = x+0.5f;
+    attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = y+0.5f;
+
+    return vertex+1;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int createBandStrip(int vertex, int polyBand, int polyVertex, float[] attribs1, float[] attribs2)
+    {
+    if( polyVertex==0 )
+      {
+      vertex = addVertex(vertex,polyBand,polyVertex,0,attribs1,attribs2);
+
+      if( polyBand>0 )
+        {
+        vertex = addVertex(vertex,polyBand,polyVertex,0,attribs1,attribs2);
+        }
+      }
+
+    int numPairs = mNumPolygonBands-1-polyBand;
+
+    for(int pair=0; pair<numPairs; pair++)
+      {
+      vertex = addVertex(vertex,polyBand+1,polyVertex,pair  ,attribs1,attribs2);
+      vertex = addVertex(vertex,polyBand  ,polyVertex,pair+1,attribs1,attribs2);
+      }
+
+    return vertex;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void buildGrid(float[] attribs1, float[] attribs2)
+    {
+    int vertex=0;
+
+    for(int band=0; band<mNumPolygonBands-1; band++)
+      for(int polyVertex=0; polyVertex<mNumPolygonVertices; polyVertex++)
+        {
+        vertex = createBandStrip(vertex,band,polyVertex,attribs1,attribs2);
+        }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Create a polygon of any shape and varying elevations from the edges towards the center.
+ *
+ * @param verticesXY 2N floats - packed description of polygon vertices. N pairs (x,y).
+ * @param bands      2K floats; K pairs of two floats each describing a single band.
+ *                   From (1.0,Z[0]) (outer edge, its Z elevation) to (0.0,Z[K]) (the center,
+ *                   its elevation). The polygon is split into such concentric bands.
+ */
+  public MeshPolygon(float[] verticesXY, float[] bands)
+    {
+    super();
+
+    mPolygonVertices      = verticesXY;
+    mPolygonBands         = bands;
+    mNumPolygonVertices   = mPolygonVertices.length /2;
+    mNumPolygonBands      = mPolygonBands.length;
+
+    computeNumberOfVertices(mNumPolygonVertices,mNumPolygonBands);
+
+    float[] attribs1= new float[VERT1_ATTRIBS*numVertices];
+    float[] attribs2= new float[VERT2_ATTRIBS*numVertices];
+
+    buildGrid(attribs1,attribs2);
+
+    if( remainingVert!=0 )
+      android.util.Log.d("MeshPolygon", "remainingVert " +remainingVert );
+
+    setAttribs(attribs1,attribs2);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Copy constructor.
+ */
+  public MeshPolygon(MeshPolygon mesh, boolean deep)
+    {
+    super(mesh,deep);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Copy the Mesh.
+ *
+ * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
+ *             normals and inflates (the rest, in particular the mVertAttribs2 containing texture
+ *             coordinates and effect associations, is always deep copied)
+ */
+  public MeshPolygon copy(boolean deep)
+    {
+    return new MeshPolygon(this,deep);
+    }
+ }
\ No newline at end of file
