commit 59835a0a1ebdceec2f9c5dc77c0d54f165b81dea
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sat May 16 21:51:14 2020 +0100

    Beginnings of a new 'Predeform' app which tests pre-applying a queue of Vertex Effects to a (single?) Mesh.
    So far just a copy of Inflate app.

diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 21edd75..a44e0db 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -57,5 +57,7 @@
         <activity android:name=".earth.EarthActivity"/>
         <activity android:name=".rubik.RubikActivity"/>
         <activity android:name=".meshjoin.MeshJoinActivity"/>
+        <activity android:name=".predeform.PredeformActivity"/>
+        <activity android:name=".predeform.PredeformActivity2"/>
     </application>
 </manifest>
diff --git a/src/main/java/org/distorted/examples/TableOfContents.java b/src/main/java/org/distorted/examples/TableOfContents.java
index 1404ce7..3ab601a 100644
--- a/src/main/java/org/distorted/examples/TableOfContents.java
+++ b/src/main/java/org/distorted/examples/TableOfContents.java
@@ -71,6 +71,7 @@ import org.distorted.examples.movingglow.MovingGlowActivity;
 import org.distorted.examples.earth.EarthActivity;
 import org.distorted.examples.rubik.RubikActivity;
 import org.distorted.examples.meshjoin.MeshJoinActivity;
+import org.distorted.examples.predeform.PredeformActivity;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -119,6 +120,7 @@ public class TableOfContents extends ListActivity
     EARTH             (R.drawable.icon_example_earth           , R.string.example_earth           , R.string.example_earth_subtitle           ,            EarthActivity.class),
     RUBIK             (R.drawable.icon_example_rubik           , R.string.example_rubik           , R.string.example_rubik_subtitle           ,            RubikActivity.class),
     MESHJOIN          (R.drawable.icon_example_meshjoin        , R.string.example_meshjoin           , R.string.example_meshjoin_subtitle           ,            MeshJoinActivity.class),
+    PREDEFORM         (R.drawable.icon_example_wip             , R.string.example_predeform           , R.string.example_predeform_subtitle           ,            PredeformActivity.class),
     ;
 
     final int icon, title, subtitle;
diff --git a/src/main/java/org/distorted/examples/predeform/PredeformActivity.java b/src/main/java/org/distorted/examples/predeform/PredeformActivity.java
new file mode 100644
index 0000000..1dc9f0c
--- /dev/null
+++ b/src/main/java/org/distorted/examples/predeform/PredeformActivity.java
@@ -0,0 +1,288 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 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.examples.predeform;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.NumberPicker;
+import android.widget.Spinner;
+import android.widget.TableRow;
+
+import org.distorted.examples.R;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class PredeformActivity extends Activity
+                               implements View.OnClickListener, AdapterView.OnItemSelectedListener
+  {
+  private static final int COLOR_OFF = 0xffffe81f;
+  private static final int COLOR_ON  = 0xff0000ff;
+  private static final int COLOR_INAC= 0xff999999;
+
+  private int mNumCols = 1;
+  private int mNumRows = 1;
+  private int mNumSlic = 1;
+  private boolean mGridInitialized;
+  private NumberPicker mColsPicker, mRowsPicker, mSlicPicker;
+  private boolean[] mShape;
+  private int mObjectType;
+  private int mBitmapID;
+  private LinearLayout mLay;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  @Override
+  protected void onCreate(Bundle savedState)
+    {
+    super.onCreate(savedState);
+
+    setContentView(R.layout.objectpickerlayout);
+
+    mLay = findViewById(R.id.objectpicker_buttongrid);
+
+    mColsPicker = findViewById(R.id.objectpicker_cols);
+    mRowsPicker = findViewById(R.id.objectpicker_rows);
+    mSlicPicker = findViewById(R.id.objectpicker_slices);
+
+    mColsPicker.setMaxValue(40);
+    mColsPicker.setMinValue( 1);
+    mRowsPicker.setMaxValue(40);
+    mRowsPicker.setMinValue( 1);
+    mSlicPicker.setMaxValue(40);
+    mSlicPicker.setMinValue( 0);
+
+    mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
+         {
+         @Override
+         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
+           {
+           setGrid();
+           }
+         });
+
+    mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
+         {
+         @Override
+         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
+           {
+           setGrid();
+           }
+         });
+
+    mSlicPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
+         {
+         @Override
+         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
+           {
+           mNumSlic = mSlicPicker.getValue();
+           }
+         });
+
+    mObjectType = 0;
+    mGridInitialized = false;
+
+    Spinner typeSpinner  = findViewById(R.id.objectpicker_spinnerType);
+    typeSpinner.setOnItemSelectedListener(this);
+
+    String[] objectType = new String[PredeformMeshList.LENGTH];
+
+    for(int mesh = 0; mesh< PredeformMeshList.LENGTH; mesh++)
+      {
+      objectType[mesh] = "Mesh: "+ PredeformMeshList.getName(mesh);
+      }
+
+    ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
+    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+    typeSpinner.setAdapter(adapterType);
+
+    Spinner bitmapSpinner  = findViewById(R.id.objectpicker_spinnerBitmap);
+    bitmapSpinner.setOnItemSelectedListener(this);
+
+    String[] objectBitmap = new String[] { "Texture: Grid", "Texture: Girl", "Texture: Dog", "Texture: Cat",
+                                           "Texture: Squares", "Texture: Bean", "Texture: Lisa", "Texture: World" };
+
+    ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
+    adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+    bitmapSpinner.setAdapter(adapterBitmap);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setGrid()
+    {
+    mGridInitialized = true;
+
+    mNumCols = mColsPicker.getValue();
+    mNumRows = mRowsPicker.getValue();
+
+    int width = mLay.getWidth();
+    int height= mLay.getHeight();
+    int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0;
+    int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0;
+    int size= Math.min(w, h);
+    int pad = size<20 ? 1 : size/20;
+
+    mLay.removeAllViews();
+
+    mShape = new boolean[mNumRows*mNumCols];
+
+    TableRow.LayoutParams p = new TableRow.LayoutParams();
+
+    p.rightMargin  = pad;
+    p.leftMargin   = pad;
+    p.topMargin    = pad;
+    p.bottomMargin = pad;
+    p.height       = size;
+    p.width        = size;
+
+    for (int rows=0; rows<mNumRows; rows++)
+      {
+      TableRow tr = new TableRow(this);
+      tr.setGravity(Gravity.CENTER);
+
+      for(int cols=0; cols<mNumCols; cols++)
+        {
+        Button b = new Button(this);
+        b.setOnClickListener(this);
+        b.setId(rows*mNumCols+cols);
+        b.setLayoutParams(p);
+        b.setBackgroundColor(mObjectType==0 ? COLOR_ON:COLOR_INAC);
+        tr.addView(b, p);
+        mShape[rows*mNumCols+cols] = true;
+        }
+
+      mLay.addView(tr);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void onClick(View view)
+    {
+    if( mObjectType==0 )  // cubes
+      {
+      Button tmp = (Button)view;
+      int id = tmp.getId();
+      mShape[id] = !mShape[id];
+      tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void uncheckAll()
+    {
+    TableRow tr;
+    Button butt;
+
+    for (int row=0; row<mNumRows; row++)
+      {
+      tr = (TableRow)mLay.getChildAt(row);
+
+      for(int col=0; col<mNumCols; col++)
+        {
+        butt = (Button)tr.getVirtualChildAt(col);
+        butt.setBackgroundColor(mObjectType==0 ? COLOR_ON : COLOR_INAC);
+        mShape[row*mNumCols+col] = true;
+        }
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void Create(View v)
+    {
+    Intent mainInt = new Intent( getApplicationContext(), PredeformActivity2.class);
+    Bundle b = new Bundle();
+
+    b.putInt("type"  , mObjectType);
+    b.putInt("cols"  , PredeformMeshList.getCols(mObjectType, mNumCols, mNumRows, mNumSlic) );
+    b.putInt("rows"  , PredeformMeshList.getRows(mObjectType, mNumCols, mNumRows, mNumSlic) );
+    b.putInt("slices", PredeformMeshList.getSlic(mObjectType, mNumCols, mNumRows, mNumSlic) );
+    b.putInt("bitmap", mBitmapID);
+
+    b.putString("string", PredeformMeshList.getString(mObjectType, mNumCols, mNumRows, mShape));
+
+    mainInt.putExtras(b);
+    startActivity(mainInt);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
+    {
+    switch(parent.getId())
+      {
+      case R.id.objectpicker_spinnerType  : if( mObjectType!=pos )
+                                              {
+                                              mObjectType = pos;
+                                              uncheckAll();
+
+                                              int dim = PredeformMeshList.getDimension(mObjectType);
+
+                                              mRowsPicker.setEnabled(dim>=1);
+                                              mColsPicker.setEnabled(dim>=2);
+                                              mSlicPicker.setEnabled(dim>=3);
+                                              }
+                                            break;
+      case R.id.objectpicker_spinnerBitmap: switch(pos)
+                                              {
+                                              case 0: mBitmapID = -1            ; break;
+                                              case 1: mBitmapID = R.raw.face    ; break;
+                                              case 2: mBitmapID = R.raw.dog     ; break;
+                                              case 3: mBitmapID = R.raw.cat     ; break;
+                                              case 4: mBitmapID = R.raw.grid    ; break;
+                                              case 5: mBitmapID = R.raw.bean    ; break;
+                                              case 6: mBitmapID = R.raw.monalisa; break;
+                                              case 7: mBitmapID = R.raw.world   ; break;
+                                              }
+                                            break;
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void onNothingSelected(AdapterView<?> parent)
+    {
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Overrides
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  @Override
+  public void onWindowFocusChanged(boolean hasFocus)
+    {
+    super.onWindowFocusChanged(hasFocus);
+
+    mColsPicker.setValue(mNumCols);
+    mRowsPicker.setValue(mNumRows);
+    mSlicPicker.setValue(mNumSlic);
+
+    if( !mGridInitialized ) setGrid();
+    }
+  }
diff --git a/src/main/java/org/distorted/examples/predeform/PredeformActivity2.java b/src/main/java/org/distorted/examples/predeform/PredeformActivity2.java
new file mode 100644
index 0000000..fadfd76
--- /dev/null
+++ b/src/main/java/org/distorted/examples/predeform/PredeformActivity2.java
@@ -0,0 +1,250 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 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.examples.predeform;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.opengl.GLSurfaceView;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.SeekBar;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import org.distorted.examples.R;
+import org.distorted.library.main.DistortedLibrary;
+import org.distorted.library.main.DistortedTexture;
+import org.distorted.library.mesh.MeshBase;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class PredeformActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
+{
+    private Bitmap mBitmap;
+    private TextView mTextLevel;
+    private DistortedTexture mTexture;
+    private MeshBase mMesh;
+    private int mNumRows, mNumCols, mNumSlic;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onPause() 
+      {
+      GLSurfaceView mView = this.findViewById(R.id.predeformSurfaceView);
+      if( mView!=null ) mView.onPause();
+
+      DistortedLibrary.onPause();
+      super.onPause();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onResume() 
+      {
+      super.onResume();
+      
+      GLSurfaceView mView = this.findViewById(R.id.predeformSurfaceView);
+      if( mView!=null ) mView.onResume();  
+      }
+    
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onDestroy() 
+      {
+      DistortedLibrary.onDestroy();
+      super.onDestroy();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onCreate(Bundle savedState)
+      {
+      super.onCreate(savedState);
+
+      Bundle b = getIntent().getExtras();
+
+      String str     = b.getString("string");
+      int objectType = b.getInt("type");
+      int bitmapID   = b.getInt("bitmap");
+      mNumCols       = b.getInt("cols");
+      mNumRows       = b.getInt("rows");
+      mNumSlic       = b.getInt("slices");
+
+      int maxsize = mNumCols > mNumRows ? (Math.max(mNumCols, mNumSlic)) : (Math.max(mNumRows, mNumSlic));
+      createBitmap(maxsize,bitmapID);
+      mMesh =  PredeformMeshList.createMesh(objectType, mNumCols, mNumRows, mNumSlic, bitmapID, str);
+
+      mTexture = new DistortedTexture();
+
+      setContentView(R.layout.predeformlayout);
+
+      Spinner renderSpinner = findViewById(R.id.predeformSpinnerMode);
+      renderSpinner.setOnItemSelectedListener(this);
+
+      String[] objectBitmap = new String[] { "Render: Normal", "Render: OIT" };
+
+      ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
+      adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+      renderSpinner.setAdapter(adapterBitmap);
+
+      mTextLevel = findViewById(R.id.predeformInflateText);
+
+      SeekBar transparencyBar = findViewById(R.id.predeformTransparency);
+      transparencyBar.setOnSeekBarChangeListener(this);
+      transparencyBar.setProgress(50);
+
+      SeekBar inflateBar = findViewById(R.id.predeformInflateLevel);
+      inflateBar.setOnSeekBarChangeListener(this);
+      inflateBar.setProgress(50);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void createBitmap(int size, int bitmapID)
+      {
+      if( bitmapID!=-1)
+        {
+        try (InputStream is = getResources().openRawResource(bitmapID))
+          {
+          mBitmap = BitmapFactory.decodeStream(is);
+          }
+        catch( IOException ex ) { android.util.Log.e("act", "failed to open resource "+bitmapID); }
+        }
+      else
+        {
+        final int T = 64;
+        final int S = T*size;
+
+        Paint paint = new Paint();
+        mBitmap = Bitmap.createBitmap(S,S, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(mBitmap);
+
+        paint.setAntiAlias(true);
+        paint.setTextAlign(Paint.Align.CENTER);
+        paint.setColor(0xff008800);
+        paint.setStyle(Paint.Style.FILL);
+        canvas.drawRect(0, 0, S, S, paint);
+        paint.setColor(0xffffffff);
+
+        for(int i=0; i<=size ; i++ )
+          {
+          canvas.drawRect( T*i-1, 0, T*i+1, S, paint);
+          canvas.drawRect( 0, T*i-1, S, T*i+1, paint);
+          }
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    int getRows()
+      {
+      return mNumRows;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    int getCols()
+      {
+      return mNumCols;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    int getSlic()
+      {
+      return mNumSlic;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public Bitmap getBitmap()
+      {
+      return mBitmap;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
+      {
+      PredeformSurfaceView v = this.findViewById(R.id.predeformSurfaceView);
+      PredeformRenderer renderer = v.getRenderer();
+
+      if( parent.getId()==R.id.predeformSpinnerMode)
+        {
+        renderer.setRenderModeToOIT(pos==1);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onNothingSelected(AdapterView<?> parent)
+      {
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
+      {
+      switch (bar.getId())
+        {
+        case R.id.predeformTransparency: PredeformSurfaceView v1 = this.findViewById(R.id.predeformSurfaceView);
+                                         v1.getRenderer().setTransparency(progress);
+                                         break;
+        case R.id.predeformInflateLevel: PredeformSurfaceView v2 = this.findViewById(R.id.predeformSurfaceView);
+                                         float level = v2.getRenderer().setLevel(progress);
+                                         mTextLevel.setText(getString(R.string.inflate_placeholder, level));
+                                         break;
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onStartTrackingTouch(SeekBar bar) { }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onStopTrackingTouch(SeekBar bar)  { }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public DistortedTexture getTexture()
+      {
+      return mTexture;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public MeshBase getMesh()
+      {
+      return mMesh;
+      }
+}
diff --git a/src/main/java/org/distorted/examples/predeform/PredeformMeshList.java b/src/main/java/org/distorted/examples/predeform/PredeformMeshList.java
new file mode 100644
index 0000000..393e66b
--- /dev/null
+++ b/src/main/java/org/distorted/examples/predeform/PredeformMeshList.java
@@ -0,0 +1,179 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.examples.predeform;
+
+import org.distorted.library.mesh.MeshBase;
+import org.distorted.library.mesh.MeshCubes;
+import org.distorted.library.mesh.MeshQuad;
+import org.distorted.library.mesh.MeshRectangles;
+import org.distorted.library.mesh.MeshSphere;
+import org.distorted.library.mesh.MeshTriangles;
+import org.distorted.library.type.Static4D;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public enum PredeformMeshList
+  {
+  Cubes      ( 3 ),
+  Rectangles ( 2 ),
+  Sphere     ( 1 ),
+  Quad       ( 0 ),
+  Triangles  ( 1 ),
+  ;
+
+  static final int LENGTH = values().length;
+  private static final PredeformMeshList[] meshes;
+  private int mDimension;
+
+  static
+    {
+    int i=0;
+    meshes = new PredeformMeshList[LENGTH];
+
+    for(PredeformMeshList mesh: PredeformMeshList.values())
+      {
+      meshes[i++] = mesh;
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  PredeformMeshList(int dim )
+    {
+    mDimension =  dim;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static String getName(int ordinal)
+    {
+    return meshes[ordinal].name();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static int getDimension(int ordinal)
+    {
+    return  meshes[ordinal].mDimension;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static int getRows(int ordinal, int cols, int rows, int slic)
+    {
+    switch(ordinal)
+      {
+      case 0: return rows;  // cubes
+      case 1: return rows;  // rectangles
+      case 2: return rows;  // sphere
+      case 3: return 1;     // quad
+      case 4: return rows;  // triangles
+      }
+
+    return 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static int getCols(int ordinal, int cols, int rows, int slic)
+    {
+    switch(ordinal)
+      {
+      case 0: return cols;  // cubes
+      case 1: return cols;  // rectangles
+      case 2: return rows;  // sphere
+      case 3: return 1;     // quad
+      case 4: return rows;  // triangles
+      }
+
+    return 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static int getSlic(int ordinal, int cols, int rows, int slic)
+    {
+    switch(ordinal)
+      {
+      case 0: return slic;  // cubes
+      case 1: return 0;     // rectangles
+      case 2: return rows;  // sphere
+      case 3: return 0;     // quad
+      case 4: return 0;     // triangles
+      }
+
+    return 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static String getString(int ordinal, int cols, int rows, boolean[] shape)
+    {
+    if( ordinal==0 )
+      {
+      String str = "";
+
+      for(int i=0; i<rows*cols; i++)
+        str += shape[i] ? "1" : "0";
+
+      return str;
+      }
+
+    return "";
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  static MeshBase createMesh(int ordinal, int cols, int rows, int slic, int bitmapID, String str)
+    {
+    MeshBase mesh;
+
+    int maxsize = cols > rows ? (Math.max(cols, slic)) : (Math.max(rows, slic)) ;
+
+    switch( meshes[ordinal] )
+      {
+      case Cubes     : if( bitmapID!=-1 )
+                         {
+                         mesh = new MeshCubes(cols, str, slic);
+                         }
+                       else
+                         {
+                         Static4D mapFB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)rows/maxsize);
+                         Static4D mapLR = new Static4D(0.0f,0.0f, (float)slic/maxsize, (float)rows/maxsize);
+                         Static4D mapTB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)slic/maxsize);
+
+                         mesh = new MeshCubes(cols, str, slic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB);
+                         }
+                       break;
+      case Rectangles: mesh = new MeshRectangles(cols,rows);
+                       break;
+      case Sphere    : mesh = new MeshSphere(rows);
+                       break;
+      case Quad      : mesh = new MeshQuad();
+                       break;
+      case Triangles : mesh = new MeshTriangles(rows);
+                       break;
+      default:         mesh = null;
+                       android.util.Log.e("Meshes", "Error: unimplemented Mesh!");
+      }
+
+    return mesh;
+    }
+  }
diff --git a/src/main/java/org/distorted/examples/predeform/PredeformRenderer.java b/src/main/java/org/distorted/examples/predeform/PredeformRenderer.java
new file mode 100644
index 0000000..0fa0bac
--- /dev/null
+++ b/src/main/java/org/distorted/examples/predeform/PredeformRenderer.java
@@ -0,0 +1,166 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 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.examples.predeform;
+
+import android.opengl.GLSurfaceView;
+
+import org.distorted.library.effect.FragmentEffectAlpha;
+import org.distorted.library.effect.MatrixEffectQuaternion;
+import org.distorted.library.effect.MatrixEffectScale;
+import org.distorted.library.effect.VertexEffectScale;
+import org.distorted.library.main.DistortedEffects;
+import org.distorted.library.main.DistortedLibrary;
+import org.distorted.library.main.DistortedScreen;
+import org.distorted.library.main.DistortedTexture;
+import org.distorted.library.mesh.MeshBase;
+import org.distorted.library.type.DynamicQuat;
+import org.distorted.library.type.Static1D;
+import org.distorted.library.type.Static3D;
+import org.distorted.library.type.Static4D;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class PredeformRenderer implements GLSurfaceView.Renderer
+{
+    private static final float FOV = 30.0f;
+    private static final float NEAR = 0.1f;
+
+    private GLSurfaceView mView;
+    private DistortedTexture mTexture;
+    private DistortedEffects mEffects;
+    private MeshBase mMesh;
+    private DistortedScreen mScreen;
+    private float mObjWidth, mObjHeight, mObjDepth;
+    private Static3D mScale;
+    private Static1D mAlpha;
+
+    Static4D mQuat1, mQuat2;
+    int mScreenMin;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    PredeformRenderer(GLSurfaceView v)
+      {
+      mView = v;
+
+      mAlpha = new Static1D(1.0f);
+      mScale= new Static3D(1,1,1);
+
+      Static3D center=new Static3D(0,0,0);
+
+      PredeformActivity2 act = (PredeformActivity2)v.getContext();
+
+      mTexture = act.getTexture();
+      mMesh    = act.getMesh();
+
+      mObjWidth = act.getCols();
+      mObjHeight= act.getRows();
+      mObjDepth = act.getSlic();
+
+      mQuat1 = new Static4D(0,0,0,1);  // unity
+      mQuat2 = new Static4D(0,0,0,1);  // quaternions
+      
+      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
+      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
+
+      quatInt1.add(mQuat1);
+      quatInt2.add(mQuat2);
+
+      mEffects = new DistortedEffects();
+      mEffects.apply( new VertexEffectScale(new Static3D(mObjWidth,mObjHeight,mObjDepth) ) );
+      mEffects.apply( new MatrixEffectScale(mScale));
+      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
+      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
+      mEffects.apply( new FragmentEffectAlpha(mAlpha));
+
+      mScreen = new DistortedScreen();
+      mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f);
+      mScreen.setProjection(FOV, NEAR);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+   
+    public void onDrawFrame(GL10 glUnused) 
+      {
+      mScreen.render( System.currentTimeMillis() );
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
+      {
+      final float SCALE = 0.75f;
+
+      mScreenMin = Math.min(width, height);
+      float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight :  (SCALE*width)/mObjWidth;
+      mScale.set(factor,factor,factor);
+      mScreen.resize(width, height);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    void setRenderModeToOIT(boolean oit)
+      {
+      mScreen.setOrderIndependentTransparency(oit);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    void setTransparency(int level)
+      {
+      mAlpha.set((float)level/100.0f);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    float setLevel(int level)
+      {
+      float inflateLevel = (level-50)/50.0f;
+      mMesh.setInflate(inflateLevel);
+
+      return inflateLevel;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
+      {
+      PredeformActivity2 act = (PredeformActivity2)mView.getContext();
+
+      mTexture.setTexture( act.getBitmap() );
+      mScreen.detachAll();
+      mScreen.attach(mTexture,mEffects,mMesh);
+
+      VertexEffectScale.enable();
+      FragmentEffectAlpha.enable();
+
+      try
+        {
+        DistortedLibrary.onCreate(act);
+        }
+      catch(Exception ex)
+        {
+        android.util.Log.e("Inflate", ex.getMessage() );
+        }
+      }
+}
diff --git a/src/main/java/org/distorted/examples/predeform/PredeformSurfaceView.java b/src/main/java/org/distorted/examples/predeform/PredeformSurfaceView.java
new file mode 100644
index 0000000..ad17dd8
--- /dev/null
+++ b/src/main/java/org/distorted/examples/predeform/PredeformSurfaceView.java
@@ -0,0 +1,141 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 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.examples.predeform;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
+import android.opengl.GLSurfaceView;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.widget.Toast;
+
+import org.distorted.examples.R;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class PredeformSurfaceView extends GLSurfaceView
+{
+    private final static int DIRECTION_SENSITIVITY=  12;
+    private int mX, mY;
+    private PredeformRenderer mRenderer;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public PredeformSurfaceView(Context context, AttributeSet attrs)
+      {
+      super(context,attrs);
+
+      mX = -1;
+      mY = -1;
+
+      if(!isInEditMode())
+        {
+        mRenderer = new PredeformRenderer(this);
+        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
+        setRenderer(mRenderer);
+        Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show();
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public PredeformRenderer getRenderer()
+      {
+      return mRenderer;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void resetQuats()
+      {
+      float qx = mRenderer.mQuat1.get0();
+      float qy = mRenderer.mQuat1.get1();
+      float qz = mRenderer.mQuat1.get2();
+      float qw = mRenderer.mQuat1.get3();
+
+      float rx = mRenderer.mQuat2.get0();
+      float ry = mRenderer.mQuat2.get1();
+      float rz = mRenderer.mQuat2.get2();
+      float rw = mRenderer.mQuat2.get3();
+
+      float tx = rw*qx - rz*qy + ry*qz + rx*qw;
+      float ty = rw*qy + rz*qx + ry*qw - rx*qz;
+      float tz = rw*qz + rz*qw - ry*qx + rx*qy;
+      float tw = rw*qw - rz*qz - ry*qy - rx*qx;
+
+      mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
+      mRenderer.mQuat2.set(tx, ty, tz, tw);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override public boolean onTouchEvent(MotionEvent event) 
+      {
+      int action = event.getAction();
+      int x = (int)event.getX();
+      int y = (int)event.getY();
+           
+      switch(action)
+         {
+         case MotionEvent.ACTION_DOWN: mX = x;
+                                       mY = y;
+                                       break;
+                                       
+         case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 )
+                                         {
+                                         float px = mY-y;
+                                         float py = mX-x;
+                                         float pz = 0;
+                                         float plen = (float)Math.sqrt(px*px + py*py + pz*pz);
+                                         
+                                         if( plen>0 )
+                                           {
+                                           px /= plen;
+                                           py /= plen;
+                                           pz /= plen;
+
+                                           float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
+                                           float sinA = (float)Math.sqrt(1-cosA*cosA);
+                                         
+                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
+                                           }
+                                         }
+                                       if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
+                                         {
+                                         mX = x;
+                                         mY = y;
+                                         resetQuats();
+                                         }
+                                       break;
+                                       
+         case MotionEvent.ACTION_UP  : mX = -1;
+                                       mY = -1;
+        	                             resetQuats();
+                                       break;
+         }
+             
+      return true;
+      }
+         
+}
+
diff --git a/src/main/res/layout/predeformlayout.xml b/src/main/res/layout/predeformlayout.xml
new file mode 100644
index 0000000..1fefd01
--- /dev/null
+++ b/src/main/res/layout/predeformlayout.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:gravity="center_horizontal"
+    android:orientation="vertical" >
+
+    <org.distorted.examples.predeform.PredeformSurfaceView
+        android:id="@+id/predeformSurfaceView"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1.00" />
+
+    <LinearLayout
+        android:id="@+id/linearLayout"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center|fill_horizontal"
+        android:orientation="horizontal"
+        android:background="@color/blue">
+
+        <TextView
+            android:id="@+id/predeformInflateText"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="0.3"
+            android:paddingLeft="10dp"
+            android:text="@string/inflate" />
+
+        <SeekBar
+            android:id="@+id/predeformInflateLevel"
+            android:layout_weight="0.7"
+            android:layout_width="0dp"
+            android:layout_height="50dp"
+            android:paddingLeft="10dp"
+            android:paddingRight="5dp" />
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:id="@+id/linearLayout3"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center|fill_horizontal"
+        android:orientation="horizontal"
+        android:background="@color/blue">
+
+        <SeekBar
+            android:id="@+id/predeformTransparency"
+            android:layout_weight="0.50"
+            android:layout_width="0dp"
+            android:layout_height="50dp"
+            android:paddingLeft="10dp"
+            android:paddingRight="10dp" />
+
+        <Spinner
+            android:layout_width="0dp"
+            android:layout_height="50dp"
+            android:layout_weight="0.5"
+            android:id="@+id/predeformSpinnerMode"
+            />
+    </LinearLayout>
+
+</LinearLayout>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index bac2276..e3f69d7 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -195,6 +195,8 @@
     <string name="example_rubik_subtitle">Keep an eye on memory consumption while allocating and deallocating Nodes.</string>
     <string name="example_meshjoin">Joining Meshes</string>
     <string name="example_meshjoin_subtitle">See how one can join several simple meshes to form a single, more advanced one.</string>
+    <string name="example_predeform">PreApply Vertex Effects to a Mesh</string>
+    <string name="example_predeform_subtitle">Create a more advanced Mesh by taking one of the simple ones and pre-applying a queue of Vertex Effects to it.</string>
 
     <string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string>
     <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>
