commit 9099e5670780624b98e2af37460ebc1b639b0b3f
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Feb 27 21:47:41 2020 +0000

    New Mesh 'Triangles' and updated Inflate & Generic apps to test it.

diff --git a/src/main/java/org/distorted/library/mesh/MeshBase.java b/src/main/java/org/distorted/library/mesh/MeshBase.java
index 295bd38..14f5d66 100644
--- a/src/main/java/org/distorted/library/mesh/MeshBase.java
+++ b/src/main/java/org/distorted/library/mesh/MeshBase.java
@@ -79,14 +79,14 @@ public abstract class MeshBase
        {
        mTextureMap = new float[8];
 
-       mTextureMap[ 0] = 0.0f;  // LLX
-       mTextureMap[ 1] = 0.0f;  // LLY
-       mTextureMap[ 2] = 0.0f;  // ULX
-       mTextureMap[ 3] = 1.0f;  // ULY
-       mTextureMap[ 4] = 1.0f;  // URX
-       mTextureMap[ 5] = 1.0f;  // URY
-       mTextureMap[ 6] = 1.0f;  // LRX
-       mTextureMap[ 7] = 0.0f;  // LRY
+       mTextureMap[ 0] = 0.0f;  // LD_X
+       mTextureMap[ 1] = 0.0f;  // LD_Y
+       mTextureMap[ 2] = 0.0f;  // LU_X
+       mTextureMap[ 3] = 1.0f;  // LU_Y
+       mTextureMap[ 4] = 1.0f;  // RU_X
+       mTextureMap[ 5] = 1.0f;  // RU_Y
+       mTextureMap[ 6] = 1.0f;  // RD_X
+       mTextureMap[ 7] = 0.0f;  // RD_Y
        }
      Component(Component original)
        {
@@ -101,11 +101,11 @@ public abstract class MeshBase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-   MeshBase(float width, float height, float depth)
+   MeshBase(float sx, float sy, float sz)
      {
-     mStretchX = width;
-     mStretchY = height;
-     mStretchZ = depth;
+     mStretchX = sx;
+     mStretchY = sy;
+     mStretchZ = sz;
 
      mShowNormals = false;
      mInflate     = 0.0f;
@@ -390,6 +390,24 @@ public abstract class MeshBase
      {
 
      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Sets texture maps for all components of this mesh.
+ * <p>
+ * Please note that calling this once with the complete list of Maps will be much faster than
+ * calling it repeatedly with one Maps at a time, as we have to reallocate the array of vertices
+ * each time.
+ */
+   public void setTextureMap(float[][] maps)
+     {
+     int components = mComponent.size();
+
+     for(int comp=0; comp<components; comp++)
+       {
+
+       }
+     }
    }
 
 
diff --git a/src/main/java/org/distorted/library/mesh/MeshTriangles.java b/src/main/java/org/distorted/library/mesh/MeshTriangles.java
new file mode 100644
index 0000000..5390064
--- /dev/null
+++ b/src/main/java/org/distorted/library/mesh/MeshTriangles.java
@@ -0,0 +1,121 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class MeshTriangles extends MeshBase
+  {
+  private static final float HEIGHT = (float)Math.sqrt(3)*0.5f;
+  private int numVertices;
+  private int remainingVert;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int addVertex(int vertex, float x, float y, float[] attribs)
+     {
+     remainingVert--;
+
+     attribs[VERT_ATTRIBS*vertex + POS_ATTRIB  ] = x-0.5f;
+     attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = y-HEIGHT/3;
+     attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f;
+
+     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB  ] = 0.0f;
+     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
+     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
+
+     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB  ] = (x-0.5f);
+     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = (y-HEIGHT/3);
+     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f   ;  // Inflated surface needs to be slightly in front
+
+     attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB  ] = x;
+     attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = y;
+
+     return vertex+1;
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void computeNumberOfVertices(int level)
+     {
+     numVertices = level*(level+2);
+     remainingVert = numVertices;
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int buildRow(int vertex,float sx, float sy, int length, float dx, float dy, float[] attribs)
+    {
+    for(int i=0; i<length; i++)
+      {
+      vertex = addVertex(vertex, sx   , sy   , attribs);
+      vertex = addVertex(vertex, sx+dx, sy+dy, attribs);
+      sx += 2*dx;
+      }
+
+    vertex = addVertex(vertex, sx, sy, attribs);
+
+    return vertex;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void buildGrid(float[] attribs, int level)
+     {
+     float sx = 0.0f;
+     float sy = 0.0f;
+     float dx = 0.5f/level;
+     float dy = HEIGHT/level;
+     int vertex = 0;
+
+     for(int row=level; row>=1; row--)
+       {
+       vertex = buildRow(vertex,sx,sy,row,dx,dy,attribs);
+
+       sx += 2*dx*(row-0.5f);
+       sy += dy;
+       dx *= -1;
+       }
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+///////////////////////////////////////////////////////////////////////////////////////////////////
+  /**
+   * Creates the underlying grid of vertices with the usual attribs which approximates an equilateral
+   * triangle.
+   *
+   * @param level Specifies the level of slicing. Valid values: level &ge; 1
+   */
+  public MeshTriangles(int level)
+     {
+     super(1,HEIGHT,0);
+
+     computeNumberOfVertices(level);
+
+     float[] attribs= new float[VERT_ATTRIBS*numVertices];
+     buildGrid(attribs,level);
+
+     if( remainingVert!=0 )
+       android.util.Log.d("MeshTriangles", "remainingVert " +remainingVert );
+
+     setAttribs(attribs);
+     }
+  }
