Project

General

Profile

Download (37.7 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ 3f7a9aec

1 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.examples.meshfile;
21
22 1af8e143 Leszek Koltunski
import android.content.Context;
23
import android.content.res.Resources;
24 42aa970f Leszek Koltunski
import android.graphics.Bitmap;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27
import android.opengl.GLSurfaceView;
28
29 8ac4c0bc Leszek Koltunski
import org.distorted.examples.R;
30 a65604a7 Leszek Koltunski
import org.distorted.library.effect.Effect;
31 6991ece5 Leszek Koltunski
import org.distorted.library.effect.EffectType;
32 42aa970f Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
33
import org.distorted.library.effect.MatrixEffectScale;
34 39b925d5 Leszek Koltunski
import org.distorted.library.effect.VertexEffectDisappear;
35 42aa970f Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.library.main.DistortedScreen;
38
import org.distorted.library.main.DistortedTexture;
39 6991ece5 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
40 1af8e143 Leszek Koltunski
import org.distorted.library.mesh.MeshFile;
41 1bb5d3b7 Leszek Koltunski
import org.distorted.library.mesh.MeshPolygon;
42 42aa970f Leszek Koltunski
import org.distorted.library.type.DynamicQuat;
43
import org.distorted.library.type.Static3D;
44
import org.distorted.library.type.Static4D;
45
46 1bb5d3b7 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
47
48 1af8e143 Leszek Koltunski
import java.io.DataInputStream;
49
import java.io.IOException;
50
import java.io.InputStream;
51
52 42aa970f Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
53
import javax.microedition.khronos.opengles.GL10;
54
55 1bb5d3b7 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.POLYGON;
56 6991ece5 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
57
58 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
59
60 061449ed Leszek Koltunski
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
61 42aa970f Leszek Koltunski
{
62 7edab735 Leszek Koltunski
    private static final float SQ2 = (float)Math.sqrt(2);
63
    private static final float SQ3 = (float)Math.sqrt(3);
64 db9903e8 Leszek Koltunski
    private static final float SQ5 = (float)Math.sqrt(5);
65 9db7b0e5 Leszek Koltunski
    private static final float SQ6 = (float)Math.sqrt(6);
66 16b336db Leszek Koltunski
    private final float DEFAULT_SCALE = 0.3f;
67
68 140f2c4e Leszek Koltunski
    private final GLSurfaceView mView;
69 42aa970f Leszek Koltunski
    private DistortedTexture mTexture;
70 140f2c4e Leszek Koltunski
    private final DistortedScreen mScreen;
71
    private final DistortedEffects mEffects;
72
    private final Static3D mScale;
73 48c88f57 Leszek Koltunski
    private long mTime;
74 16b336db Leszek Koltunski
    private float mCurrentScale;
75 6991ece5 Leszek Koltunski
    private MeshBase mMesh;
76 42aa970f Leszek Koltunski
77
    Static4D mQuat1, mQuat2;
78
    int mScreenMin;
79
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
82
    MeshFileRenderer(GLSurfaceView v)
83
      {
84
      mView = v;
85
      mScreen = new DistortedScreen();
86
      mScale= new Static3D(1,1,1);
87
      Static3D center=new Static3D(0,0,0);
88
89 16b336db Leszek Koltunski
      mCurrentScale = DEFAULT_SCALE;
90
91 42aa970f Leszek Koltunski
      mQuat1 = new Static4D(0,0,0,1);
92 fe032f52 Leszek Koltunski
      mQuat2 = new Static4D(0,0,0,1);
93 42aa970f Leszek Koltunski
94
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
95
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
96
97
      quatInt1.add(mQuat1);
98
      quatInt2.add(mQuat2);
99
100 39b925d5 Leszek Koltunski
      VertexEffectDisappear disappear = new VertexEffectDisappear();
101
      disappear.setMeshAssociation(1,-1);
102
103 42aa970f Leszek Koltunski
      mEffects = new DistortedEffects();
104
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
105
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
106
      mEffects.apply( new MatrixEffectScale(mScale));
107
108 39b925d5 Leszek Koltunski
      mEffects.apply( disappear );
109
110 42aa970f Leszek Koltunski
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
111 48c88f57 Leszek Koltunski
      mScreen.showFPS();
112 42aa970f Leszek Koltunski
      }
113
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
   
116
    public void onDrawFrame(GL10 glUnused) 
117
      {
118
      mScreen.render( System.currentTimeMillis() );
119
      }
120
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
    
123
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
124
      {
125
      mScreenMin = Math.min(width, height);
126 16b336db Leszek Koltunski
      float factor = mCurrentScale*mScreenMin;
127 42aa970f Leszek Koltunski
      mScale.set(factor,factor,factor);
128
      mScreen.resize(width, height);
129
      }
130
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132
    
133
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
134
      {
135
      if( mTexture==null ) mTexture = new DistortedTexture();
136
137 a65604a7 Leszek Koltunski
      Effect.enableEffects(EffectType.VERTEX);
138 04a21ed6 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX, 20);
139 ef02f5e0 Leszek Koltunski
      DistortedLibrary.needTransformFeedback();
140 7c72e798 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
141 061449ed Leszek Koltunski
      }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145
    public void distortedException(Exception ex)
146
      {
147
      android.util.Log.e("MeshFile", ex.getMessage() );
148 42aa970f Leszek Koltunski
      }
149
150 16b336db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
151
//   0 ---> 0
152
//  50 ---> DEFAULT_SCALE
153
// 100 ---> 4*DEFAULT_SCALE
154
155
    void setScale(int scale)
156
      {
157
      if( scale<= 50 )
158
        {
159
        mCurrentScale = DEFAULT_SCALE * scale / 50.0f;
160
        }
161
      else
162
        {
163
        mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f);
164
        }
165
166
      float factor = mCurrentScale*mScreenMin;
167
      mScale.set(factor,factor,factor);
168
      }
169
170 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
171
172 1af8e143 Leszek Koltunski
    void open(int resourceID)
173 42aa970f Leszek Koltunski
      {
174 099d8f8b Leszek Koltunski
      if( mTexture==null ) mTexture = new DistortedTexture();
175 8ac4c0bc Leszek Koltunski
      mTexture.setTexture( createTexture(resourceID) );
176
177 acad428e Leszek Koltunski
      long t1 = System.currentTimeMillis();
178 6991ece5 Leszek Koltunski
179 1bb5d3b7 Leszek Koltunski
      if( resourceID==PROCEDURAL )
180 6991ece5 Leszek Koltunski
        {
181 1bb5d3b7 Leszek Koltunski
        createMesh();
182
        }
183
      else if( resourceID==POLYGON )
184
        {
185
        createPolygon();
186 6991ece5 Leszek Koltunski
        }
187
      else
188
        {
189 1bb5d3b7 Leszek Koltunski
        openMesh(resourceID);
190 6991ece5 Leszek Koltunski
        }
191
192 acad428e Leszek Koltunski
      long t2 = System.currentTimeMillis();
193
194 48c88f57 Leszek Koltunski
      mTime = t2-t1;
195 42aa970f Leszek Koltunski
196 71c7624f Leszek Koltunski
      mScreen.detachAll();
197 7198e5c9 Leszek Koltunski
      mScreen.attach(mTexture,mEffects,mMesh);
198 42aa970f Leszek Koltunski
      }
199
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201
202 1af8e143 Leszek Koltunski
    private Bitmap createTexture(int resourceID)
203 42aa970f Leszek Koltunski
      {
204 7edab735 Leszek Koltunski
      TextureFactory factory = TextureFactory.getInstance();
205
206
      float[] vertices;
207
      int[] colors;
208
      float F = 0.5f;
209
      float E = SQ3/2;
210
211 8ac4c0bc Leszek Koltunski
      switch(resourceID)
212
          {
213
          case  R.raw.deferredjob:
214 7edab735 Leszek Koltunski
          case  R.raw.meshjoin   :
215 1beffb69 Leszek Koltunski
          case  PROCEDURAL       :
216 1bb5d3b7 Leszek Koltunski
          case  POLYGON          :
217 7edab735 Leszek Koltunski
          case  R.raw.predeform  : return createWhiteTexture();
218
219 8ac4c0bc Leszek Koltunski
          case  R.raw.cube2      :
220
          case  R.raw.cube3      :
221
          case  R.raw.cube4      :
222 7edab735 Leszek Koltunski
          case  R.raw.cube5      : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
223
                                   vertices = new float[] { -F,-F, +F,-F, +F,+F, -F,+F};
224
                                   return factory.createTexture(vertices,colors,0.10f, 0.10f, true);
225 8ac4c0bc Leszek Koltunski
          case  R.raw.pyra3      :
226
          case  R.raw.pyra4      :
227 7edab735 Leszek Koltunski
          case  R.raw.pyra5      : colors = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
228
                                   vertices = new float[] { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
229
                                   return factory.createTexture(vertices,colors,0.05f, 0.05f, true);
230 8ac4c0bc Leszek Koltunski
231 7edab735 Leszek Koltunski
          case  R.raw.dino       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
232
                                   vertices = new float[] { -F,F/3, 0,-2*F/3, +F,F/3 };
233
                                   return factory.createTexture(vertices,colors,0.05f, 0.03f, true);
234 8ac4c0bc Leszek Koltunski
235 7edab735 Leszek Koltunski
          case R.raw.skewb       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
236
                                   //vertices = new float[] { -G,-G, +G,-G, +G,+G, -G,+G };
237 8ac4c0bc Leszek Koltunski
238 7edab735 Leszek Koltunski
                                   vertices = new float[] { -F+F/4,F/4, F/4,-F+F/4, F/4,F/4};
239
                                   return factory.createTexture(vertices,colors,0.05f, 0.08f, true);
240
          }
241 8ac4c0bc Leszek Koltunski
242 7edab735 Leszek Koltunski
      return null;
243 8ac4c0bc Leszek Koltunski
      }
244
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246
247 7edab735 Leszek Koltunski
    private Bitmap createWhiteTexture()
248 8ac4c0bc Leszek Koltunski
      {
249 7edab735 Leszek Koltunski
      int SIZE = 1;
250 8ac4c0bc Leszek Koltunski
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
251
      Canvas canvas = new Canvas(bitmap);
252
253
      Paint paint = new Paint();
254 36793c52 Leszek Koltunski
      paint.setColor(0xffffff55);
255 1beffb69 Leszek Koltunski
      paint.setStyle(Paint.Style.FILL);
256 7edab735 Leszek Koltunski
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
257 6991ece5 Leszek Koltunski
258 72059460 Leszek Koltunski
      return bitmap;
259 6991ece5 Leszek Koltunski
      }
260
261 1bb5d3b7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
262
263
    private void createPolygon()
264
      {
265
      float A = 0.5f;
266
      float B = 0.1f;
267
268 65dd40aa Leszek Koltunski
      int extraIndex    = 2;
269 1bb5d3b7 Leszek Koltunski
      int extraVertices = 2;
270 65dd40aa Leszek Koltunski
      int numBands      = 2;
271 1bb5d3b7 Leszek Koltunski
272
      float[] vertices = new float[] { -A,-A, A,-A, A,A, -A,A };
273
      float[] bands = new float[2*numBands];
274
275
      for(int i=0; i<numBands; i++)
276
        {
277
        bands[2*i  ] = 1 + i/(1.0f-numBands);
278
        bands[2*i+1] = B/(numBands-1)*i;
279
        }
280
281
      mMesh = new MeshPolygon(vertices,bands,extraIndex,extraVertices);
282
      mMesh.setEffectAssociation(0,0,0);
283
      mMesh.setShowNormals(true);
284
      }
285
286 6991ece5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
287
288
    private void createMesh()
289
      {
290 a40adec7 Leszek Koltunski
      int mode            = 5;
291
      int numComponents   = 0;
292 3f7a9aec Leszek Koltunski
      float[][] vertices  = null;
293 28f4aba0 Leszek Koltunski
      int[][] vertIndexes = null;
294
      float[][] bands     = null;
295
      int[] bandIndexes   = null;
296
      float[][] corners   = null;
297
      int[] cornerIndexes = null;
298 6983badf Leszek Koltunski
      float[][] centers   = null;
299
      int[] centerIndexes = null;
300 a40adec7 Leszek Koltunski
      float[] convexCenter= null;
301 28f4aba0 Leszek Koltunski
302 4d883a92 Leszek Koltunski
      ///// CUBE ////////////////////////////////////////////////////////////////////////////////
303
304
      if( mode==0 )
305 28f4aba0 Leszek Koltunski
        {
306 3f7a9aec Leszek Koltunski
        vertices = new float[][]
307 33647db9 Leszek Koltunski
          {
308 3f7a9aec Leszek Koltunski
              { 0.5f, 0.5f, 0.5f },
309
              { 0.5f, 0.5f,-0.5f },
310
              { 0.5f,-0.5f, 0.5f },
311
              { 0.5f,-0.5f,-0.5f },
312
              {-0.5f, 0.5f, 0.5f },
313
              {-0.5f, 0.5f,-0.5f },
314
              {-0.5f,-0.5f, 0.5f },
315
              {-0.5f,-0.5f,-0.5f },
316 33647db9 Leszek Koltunski
          };
317
318 28f4aba0 Leszek Koltunski
        vertIndexes = new int[][]
319 33647db9 Leszek Koltunski
          {
320 140f2c4e Leszek Koltunski
              {2,3,1,0},   // counterclockwise!
321
              {7,6,4,5},
322
              {4,0,1,5},
323
              {7,3,2,6},
324
              {6,2,0,4},
325
              {3,7,5,1}
326 33647db9 Leszek Koltunski
          };
327
328 28f4aba0 Leszek Koltunski
        bands = new float[][]
329 33647db9 Leszek Koltunski
          {
330 6a96e571 Leszek Koltunski
              {0.05f,40,0.5f,0.2f,5,  2,2}
331 33647db9 Leszek Koltunski
          };
332 a65604a7 Leszek Koltunski
333 28f4aba0 Leszek Koltunski
        bandIndexes = new int[] { 0,0,0,0,0,0 };
334 1c41c4c9 Leszek Koltunski
335 28f4aba0 Leszek Koltunski
        corners = new float[][]
336 1b85f172 Leszek Koltunski
          {
337
              { 0.01f, 0.10f }
338
          };
339
340 28f4aba0 Leszek Koltunski
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
341 6983badf Leszek Koltunski
342
        centers = new float[][]
343
          {
344
              { 0.0f, 0.0f, 0.0f }
345
          };
346
347
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
348
349
        numComponents = 8;
350 28f4aba0 Leszek Koltunski
        }
351 4d883a92 Leszek Koltunski
352
      ///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
353
354
      else if( mode==1 )
355 28f4aba0 Leszek Koltunski
        {
356 3f7a9aec Leszek Koltunski
        vertices = new float[][]
357 28f4aba0 Leszek Koltunski
          {
358 3f7a9aec Leszek Koltunski
              {-0.5f, SQ2/4, 0.0f},
359
              { 0.5f, SQ2/4, 0.0f},
360
              { 0.0f,-SQ2/4, 0.5f},
361
              { 0.0f,-SQ2/4,-0.5f}
362 28f4aba0 Leszek Koltunski
          };
363
364
        vertIndexes = new int[][]
365
          {
366
              {2,1,0},   // counterclockwise!
367
              {2,3,1},
368
              {3,2,0},
369
              {3,0,1}
370
          };
371
372
        bands = new float[][]
373
          {
374
              {0.05f,30,0.6f,0.5f,5,  2,2}
375
          };
376
377
        bandIndexes = new int[] { 0,0,0,0 };
378
379
        corners = new float[][]
380
          {
381
              { 0.02f, 0.10f }
382
          };
383
384
        cornerIndexes = new int[] { 0,0,0,0 };
385 6983badf Leszek Koltunski
386
        centers = new float[][]
387
          {
388
              { 0.0f, 0.0f, 0.0f }
389
          };
390
391
        centerIndexes = new int[] { 0,0,0,0 };
392
393
        numComponents = 4;
394 28f4aba0 Leszek Koltunski
        }
395 4d883a92 Leszek Koltunski
396
      ///// DINO ////////////////////////////////////////////////////////////////////////////////
397
398
      else if( mode==2 )
399 28f4aba0 Leszek Koltunski
        {
400 3f7a9aec Leszek Koltunski
        vertices = new float[][]
401 28f4aba0 Leszek Koltunski
          {
402 3f7a9aec Leszek Koltunski
             {-1.5f, 0.0f, 0.0f},
403
             { 1.5f, 0.0f, 0.0f},
404
             { 0.0f,-1.5f, 0.0f},
405
             { 0.0f, 0.0f,-1.5f}
406 28f4aba0 Leszek Koltunski
          };
407
408
        vertIndexes = new int[][]
409
          {
410 4b2cad6d Leszek Koltunski
             {2,1,0},   // counterclockwise!
411
             {3,0,1},
412
             {2,3,1},
413
             {3,2,0},
414 28f4aba0 Leszek Koltunski
          };
415
416
        bands = new float[][]
417
          {
418 4b2cad6d Leszek Koltunski
              {0.035f,30,0.16f,0.8f,6,2,2},
419
              {0.010f,45,0.16f,0.2f,6,2,2}
420 28f4aba0 Leszek Koltunski
          };
421
422 4b2cad6d Leszek Koltunski
        bandIndexes = new int[] { 0,0,1,1 };
423 28f4aba0 Leszek Koltunski
424
        corners = new float[][]
425
          {
426 4b2cad6d Leszek Koltunski
               {0.07f,0.40f},
427
               {0.05f,0.30f}
428 28f4aba0 Leszek Koltunski
          };
429
430 4b2cad6d Leszek Koltunski
        cornerIndexes = new int[] { 0,0,1,1 };
431 6983badf Leszek Koltunski
432
        centers = new float[][]
433
          {
434 4b2cad6d Leszek Koltunski
              { 0.0f,-0.75f,-0.75f }
435 6983badf Leszek Koltunski
          };
436
437
        centerIndexes = new int[] { 0,0,0,0 };
438
439
        numComponents = 4;
440 28f4aba0 Leszek Koltunski
        }
441 1b85f172 Leszek Koltunski
442 6a96e571 Leszek Koltunski
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
443
444
      else if( mode==3 )
445
        {
446 3f7a9aec Leszek Koltunski
        vertices = new float[][]
447 6a96e571 Leszek Koltunski
          {
448 3f7a9aec Leszek Koltunski
              { 0.5f,   0.0f, 0.5f},
449
              { 0.5f,   0.0f,-0.5f},
450
              {-0.5f,   0.0f,-0.5f},
451
              {-0.5f,   0.0f, 0.5f},
452
              { 0.0f,  SQ2/2, 0.0f},
453
              { 0.0f, -SQ2/2, 0.0f},
454 6a96e571 Leszek Koltunski
          };
455
456
        vertIndexes = new int[][]
457
          {
458
              {3,0,4},   // counterclockwise!
459
              {0,1,4},
460
              {1,2,4},
461
              {2,3,4},
462
              {5,0,3},
463
              {5,1,0},
464
              {5,2,1},
465
              {5,3,2}
466
          };
467
468
        bands = new float[][]
469
          {
470
             {0.05f,17,0.5f,0.2f,5,  2,2}
471
          };
472
473
        bandIndexes = new int[] { 0,0,0,0,0,0,0,0 };
474
475
        corners = new float[][]
476
          {
477
              { 0.03f, 0.12f }
478
          };
479
480
        cornerIndexes = new int[] { 0,0,0,0,0,0 };
481 6983badf Leszek Koltunski
482
        centers = new float[][]
483
          {
484
              { 0.0f, 0.0f, 0.0f }
485
          };
486
487
        centerIndexes = new int[] { 0,0,0,0,0,0 };
488
489
        numComponents = 8;
490 6a96e571 Leszek Koltunski
        }
491
492 3083fab8 Leszek Koltunski
      ///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
493
494
      else if( mode==4 )
495
        {
496 3f7a9aec Leszek Koltunski
        float SQ5  = (float)Math.sqrt(5);
497
        float SIN18= (SQ5-1)/4;
498
        float COS18= 0.25f*(float)Math.sqrt(10.0+2.0*SQ5);
499
        float H = 1.0f;
500
        float L = 2.0f;
501
        float X = H*(float)Math.sqrt((5+SQ5)/10);
502
        float Y = H*(float)Math.sqrt((5-SQ5)/10);
503
        float D = H*SIN18/COS18;
504
505
        vertices = new float[][]
506
          {
507
              { 0.0f,    Y, L/2},
508
              {    X, 0.0f, L/2},
509
              { 0.0f,   -Y, L/2},
510
              {   -X, 0.0f, L/2},
511
              { 0.0f,    Y, -L/2 +D},
512
              {    X, 0.0f,-L/2   },
513
              { 0.0f,   -Y, -L/2-D },
514
              {   -X, 0.0f,-L/2   }
515 3083fab8 Leszek Koltunski
          };
516
517
        vertIndexes = new int[][]
518
          {
519
              {3,2,1,0},   // counterclockwise!
520
              {0,1,5,4},
521
              {3,0,4,7},
522
              {2,1,5,6},
523
              {3,2,6,7},
524
              {4,5,6,7}
525
          };
526
527
        bands = new float[][]
528
          {
529
             {0.04f,13,(float)(L/3),(float)L/8, 5,2,3},
530
             {0.00f, 0,(float)(L/2),(float)L/4, 5,2,3}
531
          };
532
533
        bandIndexes = new int[] { 1,0,0,1,1,1 };
534
535
        corners = new float[][]
536
          {
537 6983badf Leszek Koltunski
              { 0.04f, 0.12f }
538
          };
539
540
        cornerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
541
542
        centers = new float[][]
543
          {
544
              { 0.0f, 0.0f, 0.0f }
545
          };
546
547
        centerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
548
549
        numComponents = 6;
550
        }
551
552
      ///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
553
554
      else if( mode==5 )
555
        {
556 a40adec7 Leszek Koltunski
        int IVY_N = 8;
557 6983badf Leszek Koltunski
        final float IVY_D = 0.003f;
558 3f7a9aec Leszek Koltunski
        final float angle = (float)Math.PI/(2*IVY_N);
559
        final float CORR  = 1.0f - 2*IVY_D;
560 6983badf Leszek Koltunski
561 3f7a9aec Leszek Koltunski
        vertices = new float[3*IVY_N+7][3];
562 6983badf Leszek Koltunski
        vertIndexes = new int[6][IVY_N+4];
563
564 3f7a9aec Leszek Koltunski
        vertices[0][0] = 0.0f;
565
        vertices[0][1] = 0.0f;
566
        vertices[0][2] = 0.0f;
567
        vertices[1][0] =-1.0f;
568
        vertices[1][1] = 0.0f;
569
        vertices[1][2] = 0.0f;
570
        vertices[2][0] = 0.0f;
571
        vertices[2][1] =-1.0f;
572
        vertices[2][2] = 0.0f;
573
        vertices[3][0] = 0.0f;
574
        vertices[3][1] = 0.0f;
575
        vertices[3][2] =-1.0f;
576 6983badf Leszek Koltunski
577
        vertIndexes[0][0] = 2;
578
        vertIndexes[0][1] = 0;
579
        vertIndexes[0][2] = 1;
580
        vertIndexes[3][0] = 2;
581
        vertIndexes[3][1] = 0;
582
        vertIndexes[3][2] = 1;
583
584
        vertIndexes[1][0] = 3;
585
        vertIndexes[1][1] = 0;
586
        vertIndexes[1][2] = 2;
587
        vertIndexes[4][0] = 3;
588
        vertIndexes[4][1] = 0;
589
        vertIndexes[4][2] = 2;
590
591
        vertIndexes[2][0] = 1;
592
        vertIndexes[2][1] = 0;
593
        vertIndexes[2][2] = 3;
594
        vertIndexes[5][0] = 1;
595
        vertIndexes[5][1] = 0;
596
        vertIndexes[5][2] = 3;
597
598
        int N1 = 4;
599
        int N2 = N1 + IVY_N + 1;
600
        int N3 = N2 + IVY_N + 1;
601
602
        for(int i=0; i<=IVY_N; i++)
603
          {
604 3f7a9aec Leszek Koltunski
          float cos1 = (float)Math.cos((IVY_N-i)*angle);
605
          float sin1 = (float)Math.sin((IVY_N-i)*angle);
606
          float cos2 = (float)Math.cos((      i)*angle);
607
          float sin2 = (float)Math.sin((      i)*angle);
608 6983badf Leszek Koltunski
609 3f7a9aec Leszek Koltunski
          vertices[N1+i][0] = CORR*(cos1-0.5f) - 0.5f;
610
          vertices[N1+i][1] = CORR*(sin1-0.5f) - 0.5f;
611
          vertices[N1+i][2] = 0.0f;
612 6983badf Leszek Koltunski
613 3f7a9aec Leszek Koltunski
          vertices[N2+i][0] = 0.0f;
614
          vertices[N2+i][1] = CORR*(sin2-0.5f) - 0.5f;
615
          vertices[N2+i][2] = CORR*(cos2-0.5f) - 0.5f;
616 6983badf Leszek Koltunski
617 3f7a9aec Leszek Koltunski
          vertices[N3+i][0] = CORR*(cos2-0.5f) - 0.5f;
618
          vertices[N3+i][1] = 0.0f;
619
          vertices[N3+i][2] = CORR*(sin2-0.5f) - 0.5f;
620 6983badf Leszek Koltunski
621
          vertIndexes[0][i+3] = N1 + i;
622
          vertIndexes[1][i+3] = N2 + i;
623
          vertIndexes[2][i+3] = N3 + i;
624
          vertIndexes[3][i+3] = N1 + i;
625
          vertIndexes[4][i+3] = N2 + i;
626
          vertIndexes[5][i+3] = N3 + i;
627
          }
628
629
        bands = new float[][]
630
          {
631
             {+0.012f,20,0.2f,0.5f,7,1,2},
632
             {-0.100f,20,0.2f,0.0f,2,1,2}
633
          };
634
635
        bandIndexes = new int[] { 0,0,0,1,1,1 };
636
637
        corners = new float[][]
638
          {
639
              { 0.04f, 0.12f }
640
          };
641
642
        cornerIndexes = new int[3*IVY_N+7];
643
644
        centers = new float[][]
645
          {
646
              {-0.5f,-0.5f,-0.5f}
647 3083fab8 Leszek Koltunski
          };
648
649 6983badf Leszek Koltunski
        centerIndexes = new int[3*IVY_N+7];
650
651
        for(int i=0; i<4; i++)
652
          {
653
          cornerIndexes[i] = 0;
654
          centerIndexes[i] = 0;
655
          }
656
        for(int i=4; i<3*IVY_N+7; i++)
657
          {
658
          cornerIndexes[i] = -1;
659
          centerIndexes[i] = -1;
660
          }
661
662 a40adec7 Leszek Koltunski
        float C = 0.5f - SQ2/4;
663
        convexCenter = new float[] {-C,-C,-C};
664
665 6983badf Leszek Koltunski
        numComponents = 6;
666
        }
667
668
      ///// IVY_FACE ////////////////////////////////////////////////////////////////////////
669
670
      else if( mode==6 )
671
        {
672
        int IVY_N = 6;
673
        final float IVY_D = 0.003f;
674 3f7a9aec Leszek Koltunski
        final float angle = (float)Math.PI/(2*IVY_N);
675
        final float CORR  = 1.0f - 2*IVY_D;
676 6983badf Leszek Koltunski
677 3f7a9aec Leszek Koltunski
        vertices   = new float[2*IVY_N][3];
678 6983badf Leszek Koltunski
        vertIndexes= new int[2][2*IVY_N];
679
680
        for(int i=0; i<IVY_N; i++)
681
          {
682 3f7a9aec Leszek Koltunski
          float cos = (float)Math.cos(i*angle);
683
          float sin = (float)Math.sin(i*angle);
684 6983badf Leszek Koltunski
685 3f7a9aec Leszek Koltunski
          vertices[i      ][0] = CORR*(0.5f-cos);
686
          vertices[i      ][1] = CORR*(0.5f-sin);
687
          vertices[i      ][2] = 0.0f;
688
          vertices[i+IVY_N][0] = CORR*(cos-0.5f);
689
          vertices[i+IVY_N][1] = CORR*(sin-0.5f);
690
          vertices[i+IVY_N][2] = 0.0f;
691 6983badf Leszek Koltunski
692
          vertIndexes[0][i      ] = i;
693
          vertIndexes[0][i+IVY_N] = i+IVY_N;
694
          vertIndexes[1][i      ] = i;
695
          vertIndexes[1][i+IVY_N] = i+IVY_N;
696
          }
697
698
        bands = new float[][]
699
          {
700
             {+0.012f,20,0.2f,0.5f,7,1,2},
701
             {-0.100f,20,0.2f,0.0f,2,1,2},
702
          };
703
704
        bandIndexes = new int[] { 0,1 };
705
706
        corners = new float[][]
707
          {
708
             {0.03f,0.10f}
709
          };
710
711
        centers = new float[][]
712
          {
713
              {-0.0f,-0.0f,-0.5f}
714
          };
715
716
        cornerIndexes = new int[2*IVY_N];
717
        centerIndexes = new int[2*IVY_N];
718
719
        for(int i=0; i<2*IVY_N; i++)
720
          {
721
          cornerIndexes[i] = -1;
722
          centerIndexes[i] = -1;
723
          }
724
725
        cornerIndexes[0    ] = 0;
726
        cornerIndexes[IVY_N] = 0;
727
        centerIndexes[0    ] = 0;
728
        centerIndexes[IVY_N] = 0;
729
730
        numComponents = 2;
731 3083fab8 Leszek Koltunski
        }
732
733 db9903e8 Leszek Koltunski
      ///// SKEWB Ultimate SMALL  /////////////////////////////////////////////////////////////
734
735
      else if( mode==7 )
736
        {
737 3f7a9aec Leszek Koltunski
        float S = (SQ5+1)/4;
738 db9903e8 Leszek Koltunski
739 3f7a9aec Leszek Koltunski
        vertices = new float[][]
740 db9903e8 Leszek Koltunski
          {
741 3f7a9aec Leszek Koltunski
              { 0.0f        ,  0.0f       , 0.0f       },
742
              { -0.5f*S     , 0.5f*S+0.25f, -0.25f     },
743
              {-0.25f       , -S/2        , (-2*S-1)/4 },
744
              { 0.5f*S+0.25f, 0.25f       , -S/2       },
745
              { 0.0f        , 0.5f        , -S-0.5f    },
746
              { 0.0f        , 0.5f        , 0.0f       },
747
              { -0.5f*S     ,-0.5f*S+0.25f, -0.25f     },
748
              {  0.5f*S     ,-0.5f*S+0.25f, -0.25f     }
749 db9903e8 Leszek Koltunski
          };
750
751
        vertIndexes = new int[][]
752
          {
753
              {6,0,5,1},   // counterclockwise!
754
              {0,7,3,5},
755
              {0,6,2,7},
756
              {4,3,5,1},
757
              {4,2,7,3},
758
              {4,1,6,2},
759
          };
760
761
        bands = new float[][]
762
          {
763
             {0.04f,17,0.5f,0.2f,5,  2,2},
764
             {0.01f, 1,0.5f,0.2f,5,  2,2}
765
          };
766
767
        bandIndexes = new int[] { 0,0,0,1,1,1 };
768
769
        corners = new float[][]
770
          {
771
              { 0.013f, 0.08f }
772
          };
773
774
        cornerIndexes = new int[] { 0, 0, 0, 0,-1,0,0,0 };
775
776
        centers = new float[][]
777
          {
778
              { 0.0f,-0.5f, (float)(-S-0.5) }
779
          };
780
781
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
782
783
        numComponents = 8;
784
        }
785
786
      ///// SKEWB Ultimate BIG ///////////////////////////////////////////////////////////////
787
788
      else if( mode==8 )
789
        {
790 3f7a9aec Leszek Koltunski
        float S = (SQ5+1)/4;
791 db9903e8 Leszek Koltunski
792 3f7a9aec Leszek Koltunski
        vertices = new float[][]
793 db9903e8 Leszek Koltunski
          {
794 3f7a9aec Leszek Koltunski
              {-S/2      ,-S/2+0.25f,     0.25f},
795
              { S/2      , S/2-0.25f,    -0.25f},
796
              {-S        ,     0.00f,     0.00f},
797
              {     0.25f, S/2      ,-S/2-0.25f},
798
              {-S/2      ,-S/2-0.25f,     0.25f},
799
              { S/2+0.25f,    -0.25f,-S/2      },
800
              {-S        ,    -0.50f,     0.00f},
801
              {     0.50f,     0.00f,-S        },
802
              {-S  +0.25f, S/2      ,-S/2-0.25f},
803
              {     0.25f,-S/2-0.50f,-S/2+0.25f},
804
              {-S/2      ,-S/2-0.25f,-S  -0.25f}
805 db9903e8 Leszek Koltunski
          };
806
807
        vertIndexes = new int[][]
808
          {
809
              {0,1,3,8,2},   // counterclockwise!
810
              {0,4,9,5,1},
811
              { 0,2,6,4},
812
              { 1,5,7,3},
813
              {10,9,4,6},
814
              {10,9,5,7},
815
              {10,8,3,7},
816
              {10,8,2,6}
817
          };
818
819
        bands = new float[][]
820
          {
821
             {0.04f,17,0.5f,0.2f,5,  2,2},
822
             {0.04f,17,0.5f,0.2f,5,  2,2},
823
             {0.01f, 1,0.5f,0.2f,5,  2,2}
824
          };
825
826
        bandIndexes = new int[] { 0,0,1,1,2,2,2,2 };
827
828
        corners = new float[][]
829
          {
830
              { 0.013f, 0.08f }
831
          };
832
833
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
834
835
        centers = new float[][]
836
          {
837
              { (float)(-S/2), 0.25f, (float)(-S/2-0.5) }
838
          };
839
840
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
841
842
        numComponents = 8;
843
        }
844
845 96a6db6c Leszek Koltunski
      ///// SQUARE-1 MIDDLE ///////////////////////////////////////////////////////////////
846
847
      else if( mode==9 )
848
        {
849
        final float X = 3*(2-SQ3)/2;
850
851 3f7a9aec Leszek Koltunski
        vertices = new float[][]
852 96a6db6c Leszek Koltunski
          {
853 3f7a9aec Leszek Koltunski
              { -1.5f-X, 0.5f, 1.5f },
854
              {    0.0f, 0.5f, 1.5f },
855
              {    0.0f, 0.5f,-1.5f },
856
              { -1.5f+X, 0.5f,-1.5f },
857
              { -1.5f-X,-0.5f, 1.5f },
858
              {    0.0f,-0.5f, 1.5f },
859
              {    0.0f,-0.5f,-1.5f },
860
              { -1.5f+X,-0.5f,-1.5f }
861 96a6db6c Leszek Koltunski
          };
862
863
        vertIndexes = new int[][]
864
          {
865
              {0,1,2,3},   // counterclockwise!
866
              {4,5,6,7},
867
              {4,5,1,0},
868
              {5,6,2,1},
869
              {6,7,3,2},
870
              {7,4,0,3}
871
          };
872
873
        bands = new float[][]
874
          {
875
             {0.040f,35,0.8f,1.0f,5,2,1},
876
             {0.020f,35,0.8f,1.0f,5,2,1},
877
             {0.001f,35,0.8f,1.0f,5,2,1}
878
          };
879
880
        bandIndexes = new int[] { 2,2,1,1,0,2 };
881
882
        corners = new float[][]
883
          {
884
              {0.04f,0.05f}
885
          };
886
887
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
888
889
        centers = new float[][]
890
          {
891
              { -0.75f, 0.0f, 0.0f}
892
          };
893
894
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
895
896
        numComponents = 6;
897
        }
898
899
      ///// SQUARE-1 EDGE ///////////////////////////////////////////////////////////////
900
901
      else if( mode==10 )
902
        {
903
        final float X = 3*(2-SQ3)/2;
904
905 3f7a9aec Leszek Koltunski
        vertices = new float[][]
906 96a6db6c Leszek Koltunski
          {
907 3f7a9aec Leszek Koltunski
              {  -X, 0.5f, 0.0f },
908
              {  +X, 0.5f, 0.0f },
909
              {0.0f, 0.5f,-1.5f },
910
              {  -X,-0.5f, 0.0f },
911
              {  +X,-0.5f, 0.0f },
912
              {0.0f,-0.5f,-1.5f },
913 96a6db6c Leszek Koltunski
          };
914
915
        vertIndexes = new int[][]
916
          {
917
              {0,1,2},   // counterclockwise!
918
              {3,4,5},
919
              {3,4,1,0},
920
              {4,5,2,1},
921
              {5,3,0,2}
922
          };
923
924
        bands = new float[][]
925
          {
926
            {0.038f,35,0.5f,0.9f, 5,2,1},
927
            {0.001f,35,0.5f,0.9f, 5,2,1}
928
          };
929
930
        bandIndexes = new int[]  { 0,1,0,1,1 };
931
932
        corners = new float[][]
933
          {
934
             {0.06f,0.20f}
935
          };
936
937
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
938
939
        centers = new float[][]
940
          {
941
              { 0.0f, 0.0f,-0.5f}
942
          };
943
944
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
945
946
        numComponents = 6;
947
        }
948
949
      ///// SQUARE-1 CORNER ///////////////////////////////////////////////////////////////
950
951
      else if( mode==11 )
952
        {
953
        final float X = 3*(2-SQ3)/2;
954
955 3f7a9aec Leszek Koltunski
        vertices = new float[][]
956 96a6db6c Leszek Koltunski
          {
957 3f7a9aec Leszek Koltunski
              { X-1.5f, 0.5f,  0.0f },
958
              {   0.0f, 0.5f,  0.0f },
959
              {   0.0f, 0.5f,X-1.5f },
960
              {  -1.5f, 0.5f, -1.5f },
961
              { X-1.5f,-0.5f,  0.0f },
962
              {   0.0f,-0.5f,  0.0f },
963
              {   0.0f,-0.5f,X-1.5f },
964
              {  -1.5f,-0.5f, -1.5f }
965 96a6db6c Leszek Koltunski
          };
966
967
        vertIndexes = new int[][]
968
          {
969
              {0,1,2,3},   // counterclockwise!
970
              {4,5,6,7},
971
              {4,5,1,0},
972
              {5,6,2,1},
973
              {7,4,0,3},
974
              {6,7,3,2}
975
          };
976
977
        bands = new float[][]
978
          {
979
            {0.038f,35,0.9f,1.0f, 5,2,1},
980
            {0.001f,35,0.9f,1.0f, 5,2,1}
981
          };
982
983
        bandIndexes = new int[]  { 0,1,0,0,1,1 };
984
985
        corners = new float[][]
986
          {
987
            {0.08f,0.20f}
988
          };
989
990
        cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
991
992
        centers = new float[][]
993
          {
994
             { -0.5f, 0.0f,-0.5f}
995
          };
996
997
        centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
998
999
        numComponents = 6;
1000
        }
1001
1002 31d42722 Leszek Koltunski
      ///// SQUARE-2 CORNER ///////////////////////////////////////////////////////////////
1003
1004
      else if( mode==12 )
1005
        {
1006
        final float X = 3*(2-SQ3)/2;
1007
        final float Z = 0.75f - X/2;
1008
1009 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1010 31d42722 Leszek Koltunski
          {
1011 3f7a9aec Leszek Koltunski
              { X-1.5f+Z, 0.5f,  0.0f },
1012
              {        Z, 0.5f,  0.0f },
1013
              {  -1.5f+Z, 0.5f, -1.5f },
1014
              { X-1.5f+Z,-0.5f,  0.0f },
1015
              {        Z,-0.5f,  0.0f },
1016
              {  -1.5f+Z,-0.5f, -1.5f }
1017 31d42722 Leszek Koltunski
          };
1018
1019
        vertIndexes = new int[][]
1020
          {
1021
              {0,1,2},   // counterclockwise!
1022
              {5,4,3},
1023
              {3,4,1,0},
1024
              {4,5,2,1},
1025
              {5,3,0,2}
1026
          };
1027
1028
        bands = new float[][]
1029
          {
1030
            {0.040f,35,0.9f,1.0f, 5,2,1},
1031
            {0.001f,35,0.9f,1.0f, 5,2,1}
1032
          };
1033
1034
        bandIndexes = new int[] { 0,0,0,1,1 };
1035
1036
        corners = new float[][]
1037
          {
1038
            {0.05f,0.13f}
1039
          };
1040
1041
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
1042
1043
        centers = new float[][]
1044
          {
1045
             { 0.0f, 0.0f,-0.5f}
1046
          };
1047
1048
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
1049
1050
        numComponents = 5;
1051
        }
1052
1053 4b2cad6d Leszek Koltunski
      ///// REDI CORNER ///////////////////////////////////////////////////////////////
1054
1055
      else if( mode==13 )
1056
        {
1057 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1058 4b2cad6d Leszek Koltunski
          {
1059
             { 0.0f, 0.0f, 0.0f },
1060
             {-0.5f, 0.5f, 0.5f },
1061
             {-0.5f,-0.5f, 0.5f },
1062
             { 0.5f, 0.5f, 0.5f },
1063
             { 0.5f,-0.5f, 0.5f },
1064
             { 0.5f, 0.5f,-0.5f },
1065
             { 0.5f,-0.5f,-0.5f },
1066
             {-0.5f, 0.5f,-0.5f },
1067
          };
1068
1069
        vertIndexes = new int[][]
1070
          {
1071
             { 2,4,3,1 },
1072
             { 1,3,5,7 },
1073
             { 4,6,5,3 },
1074
1075
             { 2,4,0 },
1076
             { 5,7,0 },
1077
             { 4,6,0 },
1078
             { 7,1,0 },
1079
             { 1,2,0 },
1080
             { 6,5,0 }
1081
          };
1082
1083
        bands = new float[][]
1084
          {
1085
             {0.06f,35,0.5f,0.7f,5,2,2},
1086
             {0.01f,35,0.2f,0.4f,5,2,2}
1087
          };
1088
1089
        bandIndexes = new int[] { 0,0,0,1,1,1,1,1,1 };
1090
1091
        corners = new float[][]
1092
          {
1093
            {0.06f,0.12f}
1094
          };
1095
1096
        cornerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1097
1098
        centers = new float[][]
1099
          {
1100
             { 0.0f, 0.0f, 0.0f}
1101
          };
1102
1103
        centerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1104
1105
        numComponents = 9;
1106
        }
1107
1108 9db7b0e5 Leszek Koltunski
      ///// JING CORNER ///////////////////////////////////////////////////////////////
1109
1110
      else if( mode==14 )
1111
        {
1112 cf7ec8fa Leszek Koltunski
        final float F = 0.24f;
1113 99571baa Leszek Koltunski
        final float X = F/2;
1114
        final float Y = F*SQ2/2;
1115
        final float Z =-F/2;
1116 9db7b0e5 Leszek Koltunski
1117 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1118 9db7b0e5 Leszek Koltunski
          {
1119 3f7a9aec Leszek Koltunski
             { 0.0f, 0.0f,  0.0f },
1120
             {    X,    Y,     Z },
1121
             { 0.0f,  2*Y,   2*Z },
1122
             {   -X,    Y,     Z },
1123
             { 0.0f, 0.0f,    -F },
1124
             {    X,    Y,   Z-F },
1125
             { 0.0f,  2*Y, 2*Z-F },
1126
             {   -X,    Y,   Z-F },
1127 9db7b0e5 Leszek Koltunski
          };
1128
1129
        vertIndexes = new int[][]
1130
          {
1131 99571baa Leszek Koltunski
             {0,1,2,3},
1132 9db7b0e5 Leszek Koltunski
             {1,0,4,5},
1133 99571baa Leszek Koltunski
             {7,4,0,3},
1134
             {1,5,6,2},
1135
             {7,3,2,6},
1136
             {4,7,6,5}
1137 9db7b0e5 Leszek Koltunski
          };
1138
1139
        bands = new float[][]
1140
          {
1141
             {0.015f,35,0.5f*F,F,5,1,1},
1142
             {0.001f,35,0.5f*F,F,5,1,1}
1143
          };
1144
1145
        bandIndexes = new int[] { 0,0,0,1,1,1 };
1146
1147
        corners = new float[][]
1148
          {
1149 cf7ec8fa Leszek Koltunski
            {0.08f,0.20f*F},
1150 9db7b0e5 Leszek Koltunski
            {0.07f,0.20f*F}
1151
          };
1152
1153
        cornerIndexes = new int[] { 0,1,1,-1,1,-1,-1,-1 };
1154
1155
        centers = new float[][]
1156
          {
1157 99571baa Leszek Koltunski
             { 0.0f, Y, Z-F/2}
1158 9db7b0e5 Leszek Koltunski
          };
1159
1160
        centerIndexes = new int[] { 0,0,0,-1,0,-1,-1,-1 };
1161
1162
        numComponents = 6;
1163
        }
1164
1165
      ///// JING EDGE ///////////////////////////////////////////////////////////////
1166
1167
      else if( mode==15 )
1168
        {
1169 cf7ec8fa Leszek Koltunski
        final float F = 0.24f;
1170 99571baa Leszek Koltunski
        final float X = F/2;
1171
        final float Y = F*SQ2/2;
1172
        final float Z =-F/2;
1173 9db7b0e5 Leszek Koltunski
1174 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1175 9db7b0e5 Leszek Koltunski
          {
1176 3f7a9aec Leszek Koltunski
             { 0.0f, 0.0f,     0.5f-F },
1177
             {    X,    Y,   Z+0.5f-F },
1178
             { 0.0f,  2*Y, 2*Z+0.5f-F },
1179
             {   -X,    Y,   Z+0.5f-F },
1180
             { 0.0f, 0.0f,    -0.5f+F },
1181
             {    X,    Y,  -Z-0.5f+F },
1182
             { 0.0f,  2*Y,-2*Z-0.5f+F },
1183
             {   -X,    Y,  -Z-0.5f+F },
1184 9db7b0e5 Leszek Koltunski
          };
1185
1186
        vertIndexes = new int[][]
1187
          {
1188 99571baa Leszek Koltunski
             {0,4,5,1},
1189
             {3,7,4,0},
1190
             {0,1,2,3},
1191
             {4,7,6,5},
1192
             {1,5,6,2},
1193
             {2,6,7,3}
1194 9db7b0e5 Leszek Koltunski
          };
1195
1196
        bands = new float[][]
1197
          {
1198
             {0.015f,35,0.5f*F,F,5,1,1},
1199
             {0.001f,35,0.5f*F,F,5,1,1}
1200
          };
1201
1202
        bandIndexes = new int[] { 0,0,1,1,1,1 };
1203
1204
        corners = new float[][]
1205
          {
1206
            {0.07f,0.20f*F}
1207
          };
1208
1209 99571baa Leszek Koltunski
        cornerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1210 9db7b0e5 Leszek Koltunski
1211
        centers = new float[][]
1212
          {
1213 99571baa Leszek Koltunski
             { 0, F*SQ2/2, 0 }
1214 9db7b0e5 Leszek Koltunski
          };
1215
1216 99571baa Leszek Koltunski
        centerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1217 9db7b0e5 Leszek Koltunski
1218
        numComponents = 6;
1219
        }
1220
1221
      ///// JING FACE ///////////////////////////////////////////////////////////////
1222
1223
      else if( mode==16 )
1224
        {
1225 cf7ec8fa Leszek Koltunski
        final float F = 0.24f;
1226 99571baa Leszek Koltunski
        final float L = (1-3*F);
1227
        final float X = L/2;
1228
        final float Y = L*SQ2/2;
1229
        final float Z =-L/2;
1230
        final float D = F/L;
1231 9db7b0e5 Leszek Koltunski
1232 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1233 9db7b0e5 Leszek Koltunski
          {
1234 3f7a9aec Leszek Koltunski
              {    0.0f,     -2*Y/3,   -2*Z/3 },
1235
              {       X,        Y/3,      Z/3 },
1236
              {      -X,        Y/3,      Z/3 },
1237
              {    0.0f,     -2*Y/3,   -2*Z/3+2*D*Z },
1238
              {   X-D*X,    Y/3-D*Y,  Z/3+D*Z },
1239
              {  -X+D*X,    Y/3-D*Y,  Z/3+D*Z },
1240 9db7b0e5 Leszek Koltunski
          };
1241
1242
        vertIndexes = new int[][]
1243
          {
1244 99571baa Leszek Koltunski
             {0,1,2},
1245
             {3,5,4},
1246
             {0,3,4,1},
1247
             {5,3,0,2},
1248
             {4,5,2,1}
1249 9db7b0e5 Leszek Koltunski
          };
1250
1251
        bands = new float[][]
1252
          {
1253 99571baa Leszek Koltunski
             {0.025f,35,0.20f*(1-3*F),0.6f*(1-3*F),5,1,1},
1254
             {0.001f,35,0.05f*(1-3*F),0.1f*(1-3*F),5,1,1}
1255 9db7b0e5 Leszek Koltunski
          };
1256
1257
        bandIndexes = new int[] { 0,1,1,1,1,1 };
1258
1259
        corners = new float[][]
1260
          {
1261 99571baa Leszek Koltunski
            {0.04f,0.15f}
1262 9db7b0e5 Leszek Koltunski
          };
1263
1264
        cornerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1265
1266
        centers = new float[][]
1267
          {
1268 99571baa Leszek Koltunski
            { 0, -2*Y/3, 4*Z/3 }
1269 9db7b0e5 Leszek Koltunski
          };
1270
1271
        centerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1272
1273
        numComponents = 6;
1274
        }
1275
1276 db9903e8 Leszek Koltunski
      ///// END DEFINITIONS /////////////////////////////////////////////////////////////////
1277
1278 33647db9 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
1279 6991ece5 Leszek Koltunski
1280 6983badf Leszek Koltunski
      factory.clear();
1281
      factory.createNewFaceTransform(vertices,vertIndexes);
1282
      mMesh = factory.createRoundedSolid(vertices, vertIndexes,
1283
                                         bands, bandIndexes,
1284
                                         corners, cornerIndexes,
1285
                                         centers, centerIndexes,
1286 a40adec7 Leszek Koltunski
                                         numComponents, convexCenter );
1287 6983badf Leszek Koltunski
1288
      int numEff = mMesh.getNumEffComponents();
1289 6991ece5 Leszek Koltunski
1290
      for(int i=0; i<numEff; i++)
1291
        {
1292
        mMesh.setEffectAssociation(i, 0, i);
1293
        }
1294
      }
1295 42aa970f Leszek Koltunski
1296
///////////////////////////////////////////////////////////////////////////////////////////////////
1297
1298 6991ece5 Leszek Koltunski
    private void openMesh(int resourceID)
1299 42aa970f Leszek Koltunski
      {
1300 1af8e143 Leszek Koltunski
      Context con = mView.getContext();
1301
      Resources res = con.getResources();
1302
      InputStream is = res.openRawResource(resourceID);
1303
      DataInputStream dos = new DataInputStream(is);
1304 7198e5c9 Leszek Koltunski
      mMesh = new MeshFile(dos);
1305 1af8e143 Leszek Koltunski
1306 6983badf Leszek Koltunski
      int numEff = mMesh.getNumEffComponents();
1307 39b925d5 Leszek Koltunski
1308
      for(int i=0; i<numEff; i++)
1309
        {
1310
        mMesh.setEffectAssociation(i, 0, i);
1311
        }
1312
1313 1af8e143 Leszek Koltunski
      try
1314
        {
1315
        is.close();
1316
        }
1317
      catch(IOException e)
1318
        {
1319 48c88f57 Leszek Koltunski
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
1320 1af8e143 Leszek Koltunski
        }
1321 42aa970f Leszek Koltunski
      }
1322 48c88f57 Leszek Koltunski
1323 39b925d5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1324
1325 6991ece5 Leszek Koltunski
    MeshBase getMesh()
1326 39b925d5 Leszek Koltunski
      {
1327
      return mMesh;
1328
      }
1329
1330 48c88f57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1331
1332
    long getTime()
1333
      {
1334
      return mTime;
1335
      }
1336
1337
///////////////////////////////////////////////////////////////////////////////////////////////////
1338
1339
    int getBytes()
1340
      {
1341 6991ece5 Leszek Koltunski
      if( mMesh instanceof MeshFile )
1342
        {
1343
        return ((MeshFile)mMesh).getNumBytes();
1344
        }
1345
1346
      return 0;
1347 48c88f57 Leszek Koltunski
      }
1348
1349
///////////////////////////////////////////////////////////////////////////////////////////////////
1350
1351
    int getVertices()
1352
      {
1353 7198e5c9 Leszek Koltunski
      return mMesh.getNumVertices();
1354
      }
1355
1356
///////////////////////////////////////////////////////////////////////////////////////////////////
1357
1358
    int getEndEffIndex(int component)
1359
      {
1360
      return mMesh.getLastVertexEff(component);
1361
      }
1362
1363
///////////////////////////////////////////////////////////////////////////////////////////////////
1364
1365
    int getEndTexIndex(int component)
1366
      {
1367
      return mMesh.getLastVertexTex(component);
1368
      }
1369
1370
///////////////////////////////////////////////////////////////////////////////////////////////////
1371
1372
    int getEffComponentNum()
1373
      {
1374 6983badf Leszek Koltunski
      return mMesh.getNumEffComponents();
1375 7198e5c9 Leszek Koltunski
      }
1376
1377
///////////////////////////////////////////////////////////////////////////////////////////////////
1378
1379
    int getTexComponentNum()
1380
      {
1381 6983badf Leszek Koltunski
      return mMesh.getNumTexComponents();
1382 48c88f57 Leszek Koltunski
      }
1383 42aa970f Leszek Koltunski
}