Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ a40adec7

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import android.content.Context;
23
import android.content.res.Resources;
24
import android.graphics.Bitmap;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27
import android.opengl.GLSurfaceView;
28

    
29
import org.distorted.examples.R;
30
import org.distorted.library.effect.Effect;
31
import org.distorted.library.effect.EffectType;
32
import org.distorted.library.effect.MatrixEffectQuaternion;
33
import org.distorted.library.effect.MatrixEffectScale;
34
import org.distorted.library.effect.VertexEffectDisappear;
35
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
import org.distorted.library.mesh.MeshBase;
40
import org.distorted.library.mesh.MeshFile;
41
import org.distorted.library.type.DynamicQuat;
42
import org.distorted.library.type.Static3D;
43
import org.distorted.library.type.Static4D;
44

    
45
import java.io.DataInputStream;
46
import java.io.IOException;
47
import java.io.InputStream;
48

    
49
import javax.microedition.khronos.egl.EGLConfig;
50
import javax.microedition.khronos.opengles.GL10;
51

    
52
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
57
{
58
    private static final float SQ2 = (float)Math.sqrt(2);
59
    private static final float SQ3 = (float)Math.sqrt(3);
60
    private static final float SQ5 = (float)Math.sqrt(5);
61
    private static final float SQ6 = (float)Math.sqrt(6);
62
    private final float DEFAULT_SCALE = 0.3f;
63

    
64
    private final GLSurfaceView mView;
65
    private DistortedTexture mTexture;
66
    private final DistortedScreen mScreen;
67
    private final DistortedEffects mEffects;
68
    private final Static3D mScale;
69
    private long mTime;
70
    private float mCurrentScale;
71
    private MeshBase mMesh;
72

    
73
    Static4D mQuat1, mQuat2;
74
    int mScreenMin;
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
    MeshFileRenderer(GLSurfaceView v)
79
      {
80
      mView = v;
81
      mScreen = new DistortedScreen();
82
      mScale= new Static3D(1,1,1);
83
      Static3D center=new Static3D(0,0,0);
84

    
85
      mCurrentScale = DEFAULT_SCALE;
86

    
87
      mQuat1 = new Static4D(0,0,0,1);
88
      mQuat2 = new Static4D(0,0,0,1);
89

    
90
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
91
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
92

    
93
      quatInt1.add(mQuat1);
94
      quatInt2.add(mQuat2);
95

    
96
      VertexEffectDisappear disappear = new VertexEffectDisappear();
97
      disappear.setMeshAssociation(1,-1);
98

    
99
      mEffects = new DistortedEffects();
100
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
101
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
102
      mEffects.apply( new MatrixEffectScale(mScale));
103

    
104
      mEffects.apply( disappear );
105

    
106
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
107
      mScreen.showFPS();
108
      }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111
   
112
    public void onDrawFrame(GL10 glUnused) 
113
      {
114
      mScreen.render( System.currentTimeMillis() );
115
      }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
    
119
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
120
      {
121
      mScreenMin = Math.min(width, height);
122
      float factor = mCurrentScale*mScreenMin;
123
      mScale.set(factor,factor,factor);
124
      mScreen.resize(width, height);
125
      }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
    
129
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
130
      {
131
      if( mTexture==null ) mTexture = new DistortedTexture();
132

    
133
      Effect.enableEffects(EffectType.VERTEX);
134
      DistortedLibrary.setMax(EffectType.VERTEX, 20);
135
      DistortedLibrary.needTransformFeedback();
136
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
137
      }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
    public void distortedException(Exception ex)
142
      {
143
      android.util.Log.e("MeshFile", ex.getMessage() );
144
      }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
//   0 ---> 0
148
//  50 ---> DEFAULT_SCALE
149
// 100 ---> 4*DEFAULT_SCALE
150

    
151
    void setScale(int scale)
152
      {
153
      if( scale<= 50 )
154
        {
155
        mCurrentScale = DEFAULT_SCALE * scale / 50.0f;
156
        }
157
      else
158
        {
159
        mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f);
160
        }
161

    
162
      float factor = mCurrentScale*mScreenMin;
163
      mScale.set(factor,factor,factor);
164
      }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
    void open(int resourceID)
169
      {
170
      if( mTexture==null ) mTexture = new DistortedTexture();
171
      mTexture.setTexture( createTexture(resourceID) );
172

    
173
      long t1 = System.currentTimeMillis();
174

    
175
      if( resourceID!=PROCEDURAL )
176
        {
177
        openMesh(resourceID);
178
        }
179
      else
180
        {
181
        createMesh();
182
        }
183

    
184
      long t2 = System.currentTimeMillis();
185

    
186
      mTime = t2-t1;
187

    
188
      mScreen.detachAll();
189
      mScreen.attach(mTexture,mEffects,mMesh);
190
      }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
    private Bitmap createTexture(int resourceID)
195
      {
196
      TextureFactory factory = TextureFactory.getInstance();
197

    
198
      float[] vertices;
199
      int[] colors;
200
      float F = 0.5f;
201
      float E = SQ3/2;
202
      float G = SQ2/4;
203

    
204
      switch(resourceID)
205
          {
206
          case  R.raw.deferredjob:
207
          case  R.raw.meshjoin   :
208
          case  PROCEDURAL       :
209
          case  R.raw.predeform  : return createWhiteTexture();
210

    
211
          case  R.raw.cube2      :
212
          case  R.raw.cube3      :
213
          case  R.raw.cube4      :
214
          case  R.raw.cube5      : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
215
                                   vertices = new float[] { -F,-F, +F,-F, +F,+F, -F,+F};
216
                                   return factory.createTexture(vertices,colors,0.10f, 0.10f, true);
217
          case  R.raw.pyra3      :
218
          case  R.raw.pyra4      :
219
          case  R.raw.pyra5      : colors = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
220
                                   vertices = new float[] { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
221
                                   return factory.createTexture(vertices,colors,0.05f, 0.05f, true);
222

    
223
          case  R.raw.dino       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
224
                                   vertices = new float[] { -F,F/3, 0,-2*F/3, +F,F/3 };
225
                                   return factory.createTexture(vertices,colors,0.05f, 0.03f, true);
226

    
227
          case R.raw.skewb       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
228
                                   //vertices = new float[] { -G,-G, +G,-G, +G,+G, -G,+G };
229

    
230
                                   vertices = new float[] { -F+F/4,F/4, F/4,-F+F/4, F/4,F/4};
231
                                   return factory.createTexture(vertices,colors,0.05f, 0.08f, true);
232
          }
233

    
234
      return null;
235
      }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

    
239
    private Bitmap createWhiteTexture()
240
      {
241
      int SIZE = 1;
242
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
243
      Canvas canvas = new Canvas(bitmap);
244

    
245
      Paint paint = new Paint();
246
      paint.setColor(0xffffff55);
247
      paint.setStyle(Paint.Style.FILL);
248
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
249

    
250
      return bitmap;
251
      }
252

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
    private void createMesh()
256
      {
257
      int mode            = 5;
258
      int numComponents   = 0;
259
      double[][] vertices = null;
260
      int[][] vertIndexes = null;
261
      float[][] bands     = null;
262
      int[] bandIndexes   = null;
263
      float[][] corners   = null;
264
      int[] cornerIndexes = null;
265
      float[][] centers   = null;
266
      int[] centerIndexes = null;
267
      float[] convexCenter= null;
268

    
269
      ///// CUBE ////////////////////////////////////////////////////////////////////////////////
270

    
271
      if( mode==0 )
272
        {
273
        vertices = new double[][]
274
          {
275
              { 0.5, 0.5, 0.5 },
276
              { 0.5, 0.5,-0.5 },
277
              { 0.5,-0.5, 0.5 },
278
              { 0.5,-0.5,-0.5 },
279
              {-0.5, 0.5, 0.5 },
280
              {-0.5, 0.5,-0.5 },
281
              {-0.5,-0.5, 0.5 },
282
              {-0.5,-0.5,-0.5 },
283
          };
284

    
285
        vertIndexes = new int[][]
286
          {
287
              {2,3,1,0},   // counterclockwise!
288
              {7,6,4,5},
289
              {4,0,1,5},
290
              {7,3,2,6},
291
              {6,2,0,4},
292
              {3,7,5,1}
293
          };
294

    
295
        bands = new float[][]
296
          {
297
              {0.05f,40,0.5f,0.2f,5,  2,2}
298
          };
299

    
300
        bandIndexes = new int[] { 0,0,0,0,0,0 };
301

    
302
        corners = new float[][]
303
          {
304
              { 0.01f, 0.10f }
305
          };
306

    
307
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
308

    
309
        centers = new float[][]
310
          {
311
              { 0.0f, 0.0f, 0.0f }
312
          };
313

    
314
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
315

    
316
        numComponents = 8;
317
        }
318

    
319
      ///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
320

    
321
      else if( mode==1 )
322
        {
323
        vertices = new double[][]
324
          {
325
              {-0.5, SQ2/4, 0.0},
326
              { 0.5, SQ2/4, 0.0},
327
              { 0.0,-SQ2/4, 0.5},
328
              { 0.0,-SQ2/4,-0.5}
329
          };
330

    
331
        vertIndexes = new int[][]
332
          {
333
              {2,1,0},   // counterclockwise!
334
              {2,3,1},
335
              {3,2,0},
336
              {3,0,1}
337
          };
338

    
339
        bands = new float[][]
340
          {
341
              {0.05f,30,0.6f,0.5f,5,  2,2}
342
          };
343

    
344
        bandIndexes = new int[] { 0,0,0,0 };
345

    
346
        corners = new float[][]
347
          {
348
              { 0.02f, 0.10f }
349
          };
350

    
351
        cornerIndexes = new int[] { 0,0,0,0 };
352

    
353
        centers = new float[][]
354
          {
355
              { 0.0f, 0.0f, 0.0f }
356
          };
357

    
358
        centerIndexes = new int[] { 0,0,0,0 };
359

    
360
        numComponents = 4;
361
        }
362

    
363
      ///// DINO ////////////////////////////////////////////////////////////////////////////////
364

    
365
      else if( mode==2 )
366
        {
367
        vertices = new double[][]
368
          {
369
             {-1.5, 0.0, 0.0},
370
             { 1.5, 0.0, 0.0},
371
             { 0.0,-1.5, 0.0},
372
             { 0.0, 0.0,-1.5}
373
          };
374

    
375
        vertIndexes = new int[][]
376
          {
377
             {2,1,0},   // counterclockwise!
378
             {3,0,1},
379
             {2,3,1},
380
             {3,2,0},
381
          };
382

    
383
        bands = new float[][]
384
          {
385
              {0.035f,30,0.16f,0.8f,6,2,2},
386
              {0.010f,45,0.16f,0.2f,6,2,2}
387
          };
388

    
389
        bandIndexes = new int[] { 0,0,1,1 };
390

    
391
        corners = new float[][]
392
          {
393
               {0.07f,0.40f},
394
               {0.05f,0.30f}
395
          };
396

    
397
        cornerIndexes = new int[] { 0,0,1,1 };
398

    
399
        centers = new float[][]
400
          {
401
              { 0.0f,-0.75f,-0.75f }
402
          };
403

    
404
        centerIndexes = new int[] { 0,0,0,0 };
405

    
406
        numComponents = 4;
407
        }
408

    
409
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
410

    
411
      else if( mode==3 )
412
        {
413
        vertices = new double[][]
414
          {
415
              { 0.5,   0.0, 0.5},
416
              { 0.5,   0.0,-0.5},
417
              {-0.5,   0.0,-0.5},
418
              {-0.5,   0.0, 0.5},
419
              { 0.0, SQ2/2, 0.0},
420
              { 0.0,-SQ2/2, 0.0},
421
          };
422

    
423
        vertIndexes = new int[][]
424
          {
425
              {3,0,4},   // counterclockwise!
426
              {0,1,4},
427
              {1,2,4},
428
              {2,3,4},
429
              {5,0,3},
430
              {5,1,0},
431
              {5,2,1},
432
              {5,3,2}
433
          };
434

    
435
        bands = new float[][]
436
          {
437
             {0.05f,17,0.5f,0.2f,5,  2,2}
438
          };
439

    
440
        bandIndexes = new int[] { 0,0,0,0,0,0,0,0 };
441

    
442
        corners = new float[][]
443
          {
444
              { 0.03f, 0.12f }
445
          };
446

    
447
        cornerIndexes = new int[] { 0,0,0,0,0,0 };
448

    
449
        centers = new float[][]
450
          {
451
              { 0.0f, 0.0f, 0.0f }
452
          };
453

    
454
        centerIndexes = new int[] { 0,0,0,0,0,0 };
455

    
456
        numComponents = 8;
457
        }
458

    
459
      ///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
460

    
461
      else if( mode==4 )
462
        {
463
        double SQ5  = Math.sqrt(5);
464
        double SIN18= (SQ5-1)/4;
465
        double COS18= 0.25*Math.sqrt(10.0+2.0*SQ5);
466
        double H = 1.0;
467
        double L = 2.0;
468
        double X = H*Math.sqrt((5+SQ5)/10);
469
        double Y = H*Math.sqrt((5-SQ5)/10);
470
        double D = H*SIN18/COS18;
471

    
472
        vertices = new double[][]
473
          {
474
              { 0.0,   Y, L/2},
475
              {   X, 0.0, L/2},
476
              { 0.0,  -Y, L/2},
477
              {  -X, 0.0, L/2},
478
              { 0.0,  Y, -L/2 +D},
479
              {   X, 0.0,-L/2   },
480
              { 0.0, -Y, -L/2-D },
481
              {  -X, 0.0,-L/2   }
482
          };
483

    
484
        vertIndexes = new int[][]
485
          {
486
              {3,2,1,0},   // counterclockwise!
487
              {0,1,5,4},
488
              {3,0,4,7},
489
              {2,1,5,6},
490
              {3,2,6,7},
491
              {4,5,6,7}
492
          };
493

    
494
        bands = new float[][]
495
          {
496
             {0.04f,13,(float)(L/3),(float)L/8, 5,2,3},
497
             {0.00f, 0,(float)(L/2),(float)L/4, 5,2,3}
498
          };
499

    
500
        bandIndexes = new int[] { 1,0,0,1,1,1 };
501

    
502
        corners = new float[][]
503
          {
504
              { 0.04f, 0.12f }
505
          };
506

    
507
        cornerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
508

    
509
        centers = new float[][]
510
          {
511
              { 0.0f, 0.0f, 0.0f }
512
          };
513

    
514
        centerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
515

    
516
        numComponents = 6;
517
        }
518

    
519
      ///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
520

    
521
      else if( mode==5 )
522
        {
523
        int IVY_N = 8;
524
        final float IVY_D = 0.003f;
525
        final double angle = Math.PI/(2*IVY_N);
526
        final double CORR  = 1.0 - 2*IVY_D;
527

    
528
        vertices = new double[3*IVY_N+7][3];
529
        vertIndexes = new int[6][IVY_N+4];
530

    
531
        vertices[0][0] = 0.0;
532
        vertices[0][1] = 0.0;
533
        vertices[0][2] = 0.0;
534
        vertices[1][0] =-1.0;
535
        vertices[1][1] = 0.0;
536
        vertices[1][2] = 0.0;
537
        vertices[2][0] = 0.0;
538
        vertices[2][1] =-1.0;
539
        vertices[2][2] = 0.0;
540
        vertices[3][0] = 0.0;
541
        vertices[3][1] = 0.0;
542
        vertices[3][2] =-1.0;
543

    
544
        vertIndexes[0][0] = 2;
545
        vertIndexes[0][1] = 0;
546
        vertIndexes[0][2] = 1;
547
        vertIndexes[3][0] = 2;
548
        vertIndexes[3][1] = 0;
549
        vertIndexes[3][2] = 1;
550

    
551
        vertIndexes[1][0] = 3;
552
        vertIndexes[1][1] = 0;
553
        vertIndexes[1][2] = 2;
554
        vertIndexes[4][0] = 3;
555
        vertIndexes[4][1] = 0;
556
        vertIndexes[4][2] = 2;
557

    
558
        vertIndexes[2][0] = 1;
559
        vertIndexes[2][1] = 0;
560
        vertIndexes[2][2] = 3;
561
        vertIndexes[5][0] = 1;
562
        vertIndexes[5][1] = 0;
563
        vertIndexes[5][2] = 3;
564

    
565
        int N1 = 4;
566
        int N2 = N1 + IVY_N + 1;
567
        int N3 = N2 + IVY_N + 1;
568

    
569
        for(int i=0; i<=IVY_N; i++)
570
          {
571
          double cos1 = Math.cos((IVY_N-i)*angle);
572
          double sin1 = Math.sin((IVY_N-i)*angle);
573
          double cos2 = Math.cos((      i)*angle);
574
          double sin2 = Math.sin((      i)*angle);
575

    
576
          vertices[N1+i][0] = CORR*(cos1-0.5) - 0.5;
577
          vertices[N1+i][1] = CORR*(sin1-0.5) - 0.5;
578
          vertices[N1+i][2] = 0.0;
579

    
580
          vertices[N2+i][0] = 0.0;
581
          vertices[N2+i][1] = CORR*(sin2-0.5) - 0.5;
582
          vertices[N2+i][2] = CORR*(cos2-0.5) - 0.5;
583

    
584
          vertices[N3+i][0] = CORR*(cos2-0.5) - 0.5;
585
          vertices[N3+i][1] = 0.0;
586
          vertices[N3+i][2] = CORR*(sin2-0.5) - 0.5;
587

    
588
          vertIndexes[0][i+3] = N1 + i;
589
          vertIndexes[1][i+3] = N2 + i;
590
          vertIndexes[2][i+3] = N3 + i;
591
          vertIndexes[3][i+3] = N1 + i;
592
          vertIndexes[4][i+3] = N2 + i;
593
          vertIndexes[5][i+3] = N3 + i;
594
          }
595

    
596
        bands = new float[][]
597
          {
598
             {+0.012f,20,0.2f,0.5f,7,1,2},
599
             {-0.100f,20,0.2f,0.0f,2,1,2}
600
          };
601

    
602
        bandIndexes = new int[] { 0,0,0,1,1,1 };
603

    
604
        corners = new float[][]
605
          {
606
              { 0.04f, 0.12f }
607
          };
608

    
609
        cornerIndexes = new int[3*IVY_N+7];
610

    
611
        centers = new float[][]
612
          {
613
              {-0.5f,-0.5f,-0.5f}
614
          };
615

    
616
        centerIndexes = new int[3*IVY_N+7];
617

    
618
        for(int i=0; i<4; i++)
619
          {
620
          cornerIndexes[i] = 0;
621
          centerIndexes[i] = 0;
622
          }
623
        for(int i=4; i<3*IVY_N+7; i++)
624
          {
625
          cornerIndexes[i] = -1;
626
          centerIndexes[i] = -1;
627
          }
628

    
629
        float C = 0.5f - SQ2/4;
630
        convexCenter = new float[] {-C,-C,-C};
631

    
632
        numComponents = 6;
633
        }
634

    
635
      ///// IVY_FACE ////////////////////////////////////////////////////////////////////////
636

    
637
      else if( mode==6 )
638
        {
639
        int IVY_N = 6;
640
        final float IVY_D = 0.003f;
641
        final double angle = Math.PI/(2*IVY_N);
642
        final double CORR  = 1.0 - 2*IVY_D;
643

    
644
        vertices   = new double[2*IVY_N][3];
645
        vertIndexes= new int[2][2*IVY_N];
646

    
647
        for(int i=0; i<IVY_N; i++)
648
          {
649
          double cos = Math.cos(i*angle);
650
          double sin = Math.sin(i*angle);
651

    
652
          vertices[i      ][0] = CORR*(0.5-cos);
653
          vertices[i      ][1] = CORR*(0.5-sin);
654
          vertices[i      ][2] = 0.0;
655
          vertices[i+IVY_N][0] = CORR*(cos-0.5);
656
          vertices[i+IVY_N][1] = CORR*(sin-0.5);
657
          vertices[i+IVY_N][2] = 0.0;
658

    
659
          vertIndexes[0][i      ] = i;
660
          vertIndexes[0][i+IVY_N] = i+IVY_N;
661
          vertIndexes[1][i      ] = i;
662
          vertIndexes[1][i+IVY_N] = i+IVY_N;
663
          }
664

    
665
        bands = new float[][]
666
          {
667
             {+0.012f,20,0.2f,0.5f,7,1,2},
668
             {-0.100f,20,0.2f,0.0f,2,1,2},
669
          };
670

    
671
        bandIndexes = new int[] { 0,1 };
672

    
673
        corners = new float[][]
674
          {
675
             {0.03f,0.10f}
676
          };
677

    
678
        centers = new float[][]
679
          {
680
              {-0.0f,-0.0f,-0.5f}
681
          };
682

    
683
        cornerIndexes = new int[2*IVY_N];
684
        centerIndexes = new int[2*IVY_N];
685

    
686
        for(int i=0; i<2*IVY_N; i++)
687
          {
688
          cornerIndexes[i] = -1;
689
          centerIndexes[i] = -1;
690
          }
691

    
692
        cornerIndexes[0    ] = 0;
693
        cornerIndexes[IVY_N] = 0;
694
        centerIndexes[0    ] = 0;
695
        centerIndexes[IVY_N] = 0;
696

    
697
        numComponents = 2;
698
        }
699

    
700
      ///// SKEWB Ultimate SMALL  /////////////////////////////////////////////////////////////
701

    
702
      else if( mode==7 )
703
        {
704
        double S = (SQ5+1)/4;
705

    
706
        vertices = new double[][]
707
          {
708
              { 0.0       ,  0.0      , 0.0       },
709
              { -0.5*S    , 0.5*S+0.25, -0.25     },
710
              {-0.25      , -S/2      , (-2*S-1)/4},
711
              { 0.5*S+0.25, 0.25      , -S/2      },
712
              { 0.0       , 0.5       , -S-0.5    },
713
              { 0.0       , 0.5       , 0.0       },
714
              { -0.5*S    ,-0.5*S+0.25, -0.25     },
715
              {  0.5*S    ,-0.5*S+0.25, -0.25     }
716
          };
717

    
718
        vertIndexes = new int[][]
719
          {
720
              {6,0,5,1},   // counterclockwise!
721
              {0,7,3,5},
722
              {0,6,2,7},
723
              {4,3,5,1},
724
              {4,2,7,3},
725
              {4,1,6,2},
726
          };
727

    
728
        bands = new float[][]
729
          {
730
             {0.04f,17,0.5f,0.2f,5,  2,2},
731
             {0.01f, 1,0.5f,0.2f,5,  2,2}
732
          };
733

    
734
        bandIndexes = new int[] { 0,0,0,1,1,1 };
735

    
736
        corners = new float[][]
737
          {
738
              { 0.013f, 0.08f }
739
          };
740

    
741
        cornerIndexes = new int[] { 0, 0, 0, 0,-1,0,0,0 };
742

    
743
        centers = new float[][]
744
          {
745
              { 0.0f,-0.5f, (float)(-S-0.5) }
746
          };
747

    
748
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
749

    
750
        numComponents = 8;
751
        }
752

    
753
      ///// SKEWB Ultimate BIG ///////////////////////////////////////////////////////////////
754

    
755
      else if( mode==8 )
756
        {
757
        double S = (SQ5+1)/4;
758

    
759
        vertices = new double[][]
760
          {
761
              {-S/2     ,-S/2+0.25,     0.25},
762
              { S/2     , S/2-0.25,    -0.25},
763
              {-S       ,     0.00,     0.00},
764
              {     0.25, S/2     ,-S/2-0.25},
765
              {-S/2     ,-S/2-0.25,     0.25},
766
              { S/2+0.25,    -0.25,-S/2     },
767
              {-S       ,    -0.50,     0.00},
768
              {     0.50,     0.00,-S       },
769
              {-S  +0.25, S/2     ,-S/2-0.25},
770
              {     0.25,-S/2-0.50,-S/2+0.25},
771
              {-S/2     ,-S/2-0.25,-S  -0.25}
772
          };
773

    
774
        vertIndexes = new int[][]
775
          {
776
              {0,1,3,8,2},   // counterclockwise!
777
              {0,4,9,5,1},
778
              { 0,2,6,4},
779
              { 1,5,7,3},
780
              {10,9,4,6},
781
              {10,9,5,7},
782
              {10,8,3,7},
783
              {10,8,2,6}
784
          };
785

    
786
        bands = new float[][]
787
          {
788
             {0.04f,17,0.5f,0.2f,5,  2,2},
789
             {0.04f,17,0.5f,0.2f,5,  2,2},
790
             {0.01f, 1,0.5f,0.2f,5,  2,2}
791
          };
792

    
793
        bandIndexes = new int[] { 0,0,1,1,2,2,2,2 };
794

    
795
        corners = new float[][]
796
          {
797
              { 0.013f, 0.08f }
798
          };
799

    
800
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
801

    
802
        centers = new float[][]
803
          {
804
              { (float)(-S/2), 0.25f, (float)(-S/2-0.5) }
805
          };
806

    
807
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
808

    
809
        numComponents = 8;
810
        }
811

    
812
      ///// SQUARE-1 MIDDLE ///////////////////////////////////////////////////////////////
813

    
814
      else if( mode==9 )
815
        {
816
        final float X = 3*(2-SQ3)/2;
817

    
818
        vertices = new double[][]
819
          {
820
              { -1.5-X, 0.5, 1.5 },
821
              {    0.0, 0.5, 1.5 },
822
              {    0.0, 0.5,-1.5 },
823
              { -1.5+X, 0.5,-1.5 },
824
              { -1.5-X,-0.5, 1.5 },
825
              {    0.0,-0.5, 1.5 },
826
              {    0.0,-0.5,-1.5 },
827
              { -1.5+X,-0.5,-1.5 }
828
          };
829

    
830
        vertIndexes = new int[][]
831
          {
832
              {0,1,2,3},   // counterclockwise!
833
              {4,5,6,7},
834
              {4,5,1,0},
835
              {5,6,2,1},
836
              {6,7,3,2},
837
              {7,4,0,3}
838
          };
839

    
840
        bands = new float[][]
841
          {
842
             {0.040f,35,0.8f,1.0f,5,2,1},
843
             {0.020f,35,0.8f,1.0f,5,2,1},
844
             {0.001f,35,0.8f,1.0f,5,2,1}
845
          };
846

    
847
        bandIndexes = new int[] { 2,2,1,1,0,2 };
848

    
849
        corners = new float[][]
850
          {
851
              {0.04f,0.05f}
852
          };
853

    
854
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
855

    
856
        centers = new float[][]
857
          {
858
              { -0.75f, 0.0f, 0.0f}
859
          };
860

    
861
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
862

    
863
        numComponents = 6;
864
        }
865

    
866
      ///// SQUARE-1 EDGE ///////////////////////////////////////////////////////////////
867

    
868
      else if( mode==10 )
869
        {
870
        final float X = 3*(2-SQ3)/2;
871

    
872
        vertices = new double[][]
873
          {
874
              { -X, 0.5, 0.0 },
875
              { +X, 0.5, 0.0 },
876
              {0.0, 0.5,-1.5 },
877
              { -X,-0.5, 0.0 },
878
              { +X,-0.5, 0.0 },
879
              {0.0,-0.5,-1.5 },
880
          };
881

    
882
        vertIndexes = new int[][]
883
          {
884
              {0,1,2},   // counterclockwise!
885
              {3,4,5},
886
              {3,4,1,0},
887
              {4,5,2,1},
888
              {5,3,0,2}
889
          };
890

    
891
        bands = new float[][]
892
          {
893
            {0.038f,35,0.5f,0.9f, 5,2,1},
894
            {0.001f,35,0.5f,0.9f, 5,2,1}
895
          };
896

    
897
        bandIndexes = new int[]  { 0,1,0,1,1 };
898

    
899
        corners = new float[][]
900
          {
901
             {0.06f,0.20f}
902
          };
903

    
904
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
905

    
906
        centers = new float[][]
907
          {
908
              { 0.0f, 0.0f,-0.5f}
909
          };
910

    
911
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
912

    
913
        numComponents = 6;
914
        }
915

    
916
      ///// SQUARE-1 CORNER ///////////////////////////////////////////////////////////////
917

    
918
      else if( mode==11 )
919
        {
920
        final float X = 3*(2-SQ3)/2;
921

    
922
        vertices = new double[][]
923
          {
924
              { X-1.5, 0.5,  0.0 },
925
              {   0.0, 0.5,  0.0 },
926
              {   0.0, 0.5,X-1.5 },
927
              {  -1.5, 0.5, -1.5 },
928
              { X-1.5,-0.5,  0.0 },
929
              {   0.0,-0.5,  0.0 },
930
              {   0.0,-0.5,X-1.5 },
931
              {  -1.5,-0.5, -1.5 }
932
          };
933

    
934
        vertIndexes = new int[][]
935
          {
936
              {0,1,2,3},   // counterclockwise!
937
              {4,5,6,7},
938
              {4,5,1,0},
939
              {5,6,2,1},
940
              {7,4,0,3},
941
              {6,7,3,2}
942
          };
943

    
944
        bands = new float[][]
945
          {
946
            {0.038f,35,0.9f,1.0f, 5,2,1},
947
            {0.001f,35,0.9f,1.0f, 5,2,1}
948
          };
949

    
950
        bandIndexes = new int[]  { 0,1,0,0,1,1 };
951

    
952
        corners = new float[][]
953
          {
954
            {0.08f,0.20f}
955
          };
956

    
957
        cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
958

    
959
        centers = new float[][]
960
          {
961
             { -0.5f, 0.0f,-0.5f}
962
          };
963

    
964
        centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
965

    
966
        numComponents = 6;
967
        }
968

    
969
      ///// SQUARE-2 CORNER ///////////////////////////////////////////////////////////////
970

    
971
      else if( mode==12 )
972
        {
973
        final float X = 3*(2-SQ3)/2;
974
        final float Z = 0.75f - X/2;
975

    
976
        vertices = new double[][]
977
          {
978
              { X-1.5+Z, 0.5,  0.0 },
979
              {       Z, 0.5,  0.0 },
980
              {  -1.5+Z, 0.5, -1.5 },
981
              { X-1.5+Z,-0.5,  0.0 },
982
              {       Z,-0.5,  0.0 },
983
              {  -1.5+Z,-0.5, -1.5 }
984
          };
985

    
986
        vertIndexes = new int[][]
987
          {
988
              {0,1,2},   // counterclockwise!
989
              {5,4,3},
990
              {3,4,1,0},
991
              {4,5,2,1},
992
              {5,3,0,2}
993
          };
994

    
995
        bands = new float[][]
996
          {
997
            {0.040f,35,0.9f,1.0f, 5,2,1},
998
            {0.001f,35,0.9f,1.0f, 5,2,1}
999
          };
1000

    
1001
        bandIndexes = new int[] { 0,0,0,1,1 };
1002

    
1003
        corners = new float[][]
1004
          {
1005
            {0.05f,0.13f}
1006
          };
1007

    
1008
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
1009

    
1010
        centers = new float[][]
1011
          {
1012
             { 0.0f, 0.0f,-0.5f}
1013
          };
1014

    
1015
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
1016

    
1017
        numComponents = 5;
1018
        }
1019

    
1020
      ///// REDI CORNER ///////////////////////////////////////////////////////////////
1021

    
1022
      else if( mode==13 )
1023
        {
1024
        vertices = new double[][]
1025
          {
1026
             { 0.0f, 0.0f, 0.0f },
1027
             {-0.5f, 0.5f, 0.5f },
1028
             {-0.5f,-0.5f, 0.5f },
1029
             { 0.5f, 0.5f, 0.5f },
1030
             { 0.5f,-0.5f, 0.5f },
1031
             { 0.5f, 0.5f,-0.5f },
1032
             { 0.5f,-0.5f,-0.5f },
1033
             {-0.5f, 0.5f,-0.5f },
1034
          };
1035

    
1036
        vertIndexes = new int[][]
1037
          {
1038
             { 2,4,3,1 },
1039
             { 1,3,5,7 },
1040
             { 4,6,5,3 },
1041

    
1042
             { 2,4,0 },
1043
             { 5,7,0 },
1044
             { 4,6,0 },
1045
             { 7,1,0 },
1046
             { 1,2,0 },
1047
             { 6,5,0 }
1048
          };
1049

    
1050
        bands = new float[][]
1051
          {
1052
             {0.06f,35,0.5f,0.7f,5,2,2},
1053
             {0.01f,35,0.2f,0.4f,5,2,2}
1054
          };
1055

    
1056
        bandIndexes = new int[] { 0,0,0,1,1,1,1,1,1 };
1057

    
1058
        corners = new float[][]
1059
          {
1060
            {0.06f,0.12f}
1061
          };
1062

    
1063
        cornerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1064

    
1065
        centers = new float[][]
1066
          {
1067
             { 0.0f, 0.0f, 0.0f}
1068
          };
1069

    
1070
        centerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1071

    
1072
        numComponents = 9;
1073
        }
1074

    
1075
      ///// JING CORNER ///////////////////////////////////////////////////////////////
1076

    
1077
      else if( mode==14 )
1078
        {
1079
        final float F = 0.24f;
1080
        final float X = F/2;
1081
        final float Y = F*SQ2/2;
1082
        final float Z =-F/2;
1083

    
1084
        vertices = new double[][]
1085
          {
1086
             { 0.0, 0.0, 0.0 },
1087
             {   X,   Y,   Z },
1088
             { 0.0, 2*Y, 2*Z },
1089
             {  -X,   Y,   Z },
1090
             { 0.0, 0.0,    -F },
1091
             {   X,   Y,   Z-F },
1092
             { 0.0, 2*Y, 2*Z-F },
1093
             {  -X,   Y,   Z-F },
1094
          };
1095

    
1096
        vertIndexes = new int[][]
1097
          {
1098
             {0,1,2,3},
1099
             {1,0,4,5},
1100
             {7,4,0,3},
1101
             {1,5,6,2},
1102
             {7,3,2,6},
1103
             {4,7,6,5}
1104
          };
1105

    
1106
        bands = new float[][]
1107
          {
1108
             {0.015f,35,0.5f*F,F,5,1,1},
1109
             {0.001f,35,0.5f*F,F,5,1,1}
1110
          };
1111

    
1112
        bandIndexes = new int[] { 0,0,0,1,1,1 };
1113

    
1114
        corners = new float[][]
1115
          {
1116
            {0.08f,0.20f*F},
1117
            {0.07f,0.20f*F}
1118
          };
1119

    
1120
        cornerIndexes = new int[] { 0,1,1,-1,1,-1,-1,-1 };
1121

    
1122
        centers = new float[][]
1123
          {
1124
             { 0.0f, Y, Z-F/2}
1125
          };
1126

    
1127
        centerIndexes = new int[] { 0,0,0,-1,0,-1,-1,-1 };
1128

    
1129
        numComponents = 6;
1130
        }
1131

    
1132
      ///// JING EDGE ///////////////////////////////////////////////////////////////
1133

    
1134
      else if( mode==15 )
1135
        {
1136
        final float F = 0.24f;
1137
        final float X = F/2;
1138
        final float Y = F*SQ2/2;
1139
        final float Z =-F/2;
1140

    
1141
        vertices = new double[][]
1142
          {
1143
             { 0.0, 0.0,     0.5-F },
1144
             {   X,   Y,   Z+0.5-F },
1145
             { 0.0, 2*Y, 2*Z+0.5-F },
1146
             {  -X,   Y,   Z+0.5-F },
1147
             { 0.0, 0.0,    -0.5+F },
1148
             {   X,   Y,  -Z-0.5+F },
1149
             { 0.0, 2*Y,-2*Z-0.5+F },
1150
             {  -X,   Y,  -Z-0.5+F },
1151
          };
1152

    
1153
        vertIndexes = new int[][]
1154
          {
1155
             {0,4,5,1},
1156
             {3,7,4,0},
1157
             {0,1,2,3},
1158
             {4,7,6,5},
1159
             {1,5,6,2},
1160
             {2,6,7,3}
1161
          };
1162

    
1163
        bands = new float[][]
1164
          {
1165
             {0.015f,35,0.5f*F,F,5,1,1},
1166
             {0.001f,35,0.5f*F,F,5,1,1}
1167
          };
1168

    
1169
        bandIndexes = new int[] { 0,0,1,1,1,1 };
1170

    
1171
        corners = new float[][]
1172
          {
1173
            {0.07f,0.20f*F}
1174
          };
1175

    
1176
        cornerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1177

    
1178
        centers = new float[][]
1179
          {
1180
             { 0, F*SQ2/2, 0 }
1181
          };
1182

    
1183
        centerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1184

    
1185
        numComponents = 6;
1186
        }
1187

    
1188
      ///// JING FACE ///////////////////////////////////////////////////////////////
1189

    
1190
      else if( mode==16 )
1191
        {
1192
        final float F = 0.24f;
1193
        final float L = (1-3*F);
1194
        final float X = L/2;
1195
        final float Y = L*SQ2/2;
1196
        final float Z =-L/2;
1197
        final float D = F/L;
1198

    
1199
        vertices = new double[][]
1200
          {
1201
              {    0.0,     -2*Y/3,   -2*Z/3 },
1202
              {      X,        Y/3,      Z/3 },
1203
              {     -X,        Y/3,      Z/3 },
1204
              {    0.0,     -2*Y/3,   -2*Z/3+2*D*Z },
1205
              {  X-D*X,    Y/3-D*Y,  Z/3+D*Z },
1206
              { -X+D*X,    Y/3-D*Y,  Z/3+D*Z },
1207
          };
1208

    
1209
        vertIndexes = new int[][]
1210
          {
1211
             {0,1,2},
1212
             {3,5,4},
1213
             {0,3,4,1},
1214
             {5,3,0,2},
1215
             {4,5,2,1}
1216
          };
1217

    
1218
        bands = new float[][]
1219
          {
1220
             {0.025f,35,0.20f*(1-3*F),0.6f*(1-3*F),5,1,1},
1221
             {0.001f,35,0.05f*(1-3*F),0.1f*(1-3*F),5,1,1}
1222
          };
1223

    
1224
        bandIndexes = new int[] { 0,1,1,1,1,1 };
1225

    
1226
        corners = new float[][]
1227
          {
1228
            {0.04f,0.15f}
1229
          };
1230

    
1231
        cornerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1232

    
1233
        centers = new float[][]
1234
          {
1235
            { 0, -2*Y/3, 4*Z/3 }
1236
          };
1237

    
1238
        centerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1239

    
1240
        numComponents = 6;
1241
        }
1242

    
1243
      ///// END DEFINITIONS /////////////////////////////////////////////////////////////////
1244

    
1245
      FactoryCubit factory = FactoryCubit.getInstance();
1246

    
1247
      factory.clear();
1248
      factory.createNewFaceTransform(vertices,vertIndexes);
1249
      mMesh = factory.createRoundedSolid(vertices, vertIndexes,
1250
                                         bands, bandIndexes,
1251
                                         corners, cornerIndexes,
1252
                                         centers, centerIndexes,
1253
                                         numComponents, convexCenter );
1254

    
1255
      int numEff = mMesh.getNumEffComponents();
1256

    
1257
      for(int i=0; i<numEff; i++)
1258
        {
1259
        mMesh.setEffectAssociation(i, 0, i);
1260
        }
1261
      }
1262

    
1263
///////////////////////////////////////////////////////////////////////////////////////////////////
1264

    
1265
    private void openMesh(int resourceID)
1266
      {
1267
      Context con = mView.getContext();
1268
      Resources res = con.getResources();
1269
      InputStream is = res.openRawResource(resourceID);
1270
      DataInputStream dos = new DataInputStream(is);
1271
      mMesh = new MeshFile(dos);
1272

    
1273
      int numEff = mMesh.getNumEffComponents();
1274

    
1275
      for(int i=0; i<numEff; i++)
1276
        {
1277
        mMesh.setEffectAssociation(i, 0, i);
1278
        }
1279

    
1280
      try
1281
        {
1282
        is.close();
1283
        }
1284
      catch(IOException e)
1285
        {
1286
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
1287
        }
1288
      }
1289

    
1290
///////////////////////////////////////////////////////////////////////////////////////////////////
1291

    
1292
    MeshBase getMesh()
1293
      {
1294
      return mMesh;
1295
      }
1296

    
1297
///////////////////////////////////////////////////////////////////////////////////////////////////
1298

    
1299
    long getTime()
1300
      {
1301
      return mTime;
1302
      }
1303

    
1304
///////////////////////////////////////////////////////////////////////////////////////////////////
1305

    
1306
    int getBytes()
1307
      {
1308
      if( mMesh instanceof MeshFile )
1309
        {
1310
        return ((MeshFile)mMesh).getNumBytes();
1311
        }
1312

    
1313
      return 0;
1314
      }
1315

    
1316
///////////////////////////////////////////////////////////////////////////////////////////////////
1317

    
1318
    int getVertices()
1319
      {
1320
      return mMesh.getNumVertices();
1321
      }
1322

    
1323
///////////////////////////////////////////////////////////////////////////////////////////////////
1324

    
1325
    int getEndEffIndex(int component)
1326
      {
1327
      return mMesh.getLastVertexEff(component);
1328
      }
1329

    
1330
///////////////////////////////////////////////////////////////////////////////////////////////////
1331

    
1332
    int getEndTexIndex(int component)
1333
      {
1334
      return mMesh.getLastVertexTex(component);
1335
      }
1336

    
1337
///////////////////////////////////////////////////////////////////////////////////////////////////
1338

    
1339
    int getEffComponentNum()
1340
      {
1341
      return mMesh.getNumEffComponents();
1342
      }
1343

    
1344
///////////////////////////////////////////////////////////////////////////////////////////////////
1345

    
1346
    int getTexComponentNum()
1347
      {
1348
      return mMesh.getNumTexComponents();
1349
      }
1350
}
(3-3/5)