Project

General

Profile

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

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

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 = 14;
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

    
268
      ///// CUBE ////////////////////////////////////////////////////////////////////////////////
269

    
270
      if( mode==0 )
271
        {
272
        vertices = new double[][]
273
          {
274
              { 0.5, 0.5, 0.5 },
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
          };
283

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

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

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

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

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

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

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

    
315
        numComponents = 8;
316
        }
317

    
318
      ///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
319

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

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

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

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

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

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

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

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

    
359
        numComponents = 4;
360
        }
361

    
362
      ///// DINO ////////////////////////////////////////////////////////////////////////////////
363

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

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

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

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

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

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

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

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

    
405
        numComponents = 4;
406
        }
407

    
408
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
409

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

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

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

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

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

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

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

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

    
455
        numComponents = 8;
456
        }
457

    
458
      ///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
459

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

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

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

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

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

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

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

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

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

    
515
        numComponents = 6;
516
        }
517

    
518
      ///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
519

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
628
        numComponents = 6;
629
        }
630

    
631
      ///// IVY_FACE ////////////////////////////////////////////////////////////////////////
632

    
633
      else if( mode==6 )
634
        {
635
        int IVY_N = 6;
636
        final float IVY_D = 0.003f;
637
        final double angle = Math.PI/(2*IVY_N);
638
        final double CORR  = 1.0 - 2*IVY_D;
639

    
640
        vertices   = new double[2*IVY_N][3];
641
        vertIndexes= new int[2][2*IVY_N];
642

    
643
        for(int i=0; i<IVY_N; i++)
644
          {
645
          double cos = Math.cos(i*angle);
646
          double sin = Math.sin(i*angle);
647

    
648
          vertices[i      ][0] = CORR*(0.5-cos);
649
          vertices[i      ][1] = CORR*(0.5-sin);
650
          vertices[i      ][2] = 0.0;
651
          vertices[i+IVY_N][0] = CORR*(cos-0.5);
652
          vertices[i+IVY_N][1] = CORR*(sin-0.5);
653
          vertices[i+IVY_N][2] = 0.0;
654

    
655
          vertIndexes[0][i      ] = i;
656
          vertIndexes[0][i+IVY_N] = i+IVY_N;
657
          vertIndexes[1][i      ] = i;
658
          vertIndexes[1][i+IVY_N] = i+IVY_N;
659
          }
660

    
661
        bands = new float[][]
662
          {
663
             {+0.012f,20,0.2f,0.5f,7,1,2},
664
             {-0.100f,20,0.2f,0.0f,2,1,2},
665
          };
666

    
667
        bandIndexes = new int[] { 0,1 };
668

    
669
        corners = new float[][]
670
          {
671
             {0.03f,0.10f}
672
          };
673

    
674
        centers = new float[][]
675
          {
676
              {-0.0f,-0.0f,-0.5f}
677
          };
678

    
679
        cornerIndexes = new int[2*IVY_N];
680
        centerIndexes = new int[2*IVY_N];
681

    
682
        for(int i=0; i<2*IVY_N; i++)
683
          {
684
          cornerIndexes[i] = -1;
685
          centerIndexes[i] = -1;
686
          }
687

    
688
        cornerIndexes[0    ] = 0;
689
        cornerIndexes[IVY_N] = 0;
690
        centerIndexes[0    ] = 0;
691
        centerIndexes[IVY_N] = 0;
692

    
693
        numComponents = 2;
694
        }
695

    
696
      ///// SKEWB Ultimate SMALL  /////////////////////////////////////////////////////////////
697

    
698
      else if( mode==7 )
699
        {
700
        double S = (SQ5+1)/4;
701

    
702
        vertices = new double[][]
703
          {
704
              { 0.0       ,  0.0      , 0.0       },
705
              { -0.5*S    , 0.5*S+0.25, -0.25     },
706
              {-0.25      , -S/2      , (-2*S-1)/4},
707
              { 0.5*S+0.25, 0.25      , -S/2      },
708
              { 0.0       , 0.5       , -S-0.5    },
709
              { 0.0       , 0.5       , 0.0       },
710
              { -0.5*S    ,-0.5*S+0.25, -0.25     },
711
              {  0.5*S    ,-0.5*S+0.25, -0.25     }
712
          };
713

    
714
        vertIndexes = new int[][]
715
          {
716
              {6,0,5,1},   // counterclockwise!
717
              {0,7,3,5},
718
              {0,6,2,7},
719
              {4,3,5,1},
720
              {4,2,7,3},
721
              {4,1,6,2},
722
          };
723

    
724
        bands = new float[][]
725
          {
726
             {0.04f,17,0.5f,0.2f,5,  2,2},
727
             {0.01f, 1,0.5f,0.2f,5,  2,2}
728
          };
729

    
730
        bandIndexes = new int[] { 0,0,0,1,1,1 };
731

    
732
        corners = new float[][]
733
          {
734
              { 0.013f, 0.08f }
735
          };
736

    
737
        cornerIndexes = new int[] { 0, 0, 0, 0,-1,0,0,0 };
738

    
739
        centers = new float[][]
740
          {
741
              { 0.0f,-0.5f, (float)(-S-0.5) }
742
          };
743

    
744
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
745

    
746
        numComponents = 8;
747
        }
748

    
749
      ///// SKEWB Ultimate BIG ///////////////////////////////////////////////////////////////
750

    
751
      else if( mode==8 )
752
        {
753
        double S = (SQ5+1)/4;
754

    
755
        vertices = new double[][]
756
          {
757
              {-S/2     ,-S/2+0.25,     0.25},
758
              { S/2     , S/2-0.25,    -0.25},
759
              {-S       ,     0.00,     0.00},
760
              {     0.25, S/2     ,-S/2-0.25},
761
              {-S/2     ,-S/2-0.25,     0.25},
762
              { S/2+0.25,    -0.25,-S/2     },
763
              {-S       ,    -0.50,     0.00},
764
              {     0.50,     0.00,-S       },
765
              {-S  +0.25, S/2     ,-S/2-0.25},
766
              {     0.25,-S/2-0.50,-S/2+0.25},
767
              {-S/2     ,-S/2-0.25,-S  -0.25}
768
          };
769

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

    
782
        bands = new float[][]
783
          {
784
             {0.04f,17,0.5f,0.2f,5,  2,2},
785
             {0.04f,17,0.5f,0.2f,5,  2,2},
786
             {0.01f, 1,0.5f,0.2f,5,  2,2}
787
          };
788

    
789
        bandIndexes = new int[] { 0,0,1,1,2,2,2,2 };
790

    
791
        corners = new float[][]
792
          {
793
              { 0.013f, 0.08f }
794
          };
795

    
796
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
797

    
798
        centers = new float[][]
799
          {
800
              { (float)(-S/2), 0.25f, (float)(-S/2-0.5) }
801
          };
802

    
803
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
804

    
805
        numComponents = 8;
806
        }
807

    
808
      ///// SQUARE-1 MIDDLE ///////////////////////////////////////////////////////////////
809

    
810
      else if( mode==9 )
811
        {
812
        final float X = 3*(2-SQ3)/2;
813

    
814
        vertices = new double[][]
815
          {
816
              { -1.5-X, 0.5, 1.5 },
817
              {    0.0, 0.5, 1.5 },
818
              {    0.0, 0.5,-1.5 },
819
              { -1.5+X, 0.5,-1.5 },
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
          };
825

    
826
        vertIndexes = new int[][]
827
          {
828
              {0,1,2,3},   // counterclockwise!
829
              {4,5,6,7},
830
              {4,5,1,0},
831
              {5,6,2,1},
832
              {6,7,3,2},
833
              {7,4,0,3}
834
          };
835

    
836
        bands = new float[][]
837
          {
838
             {0.040f,35,0.8f,1.0f,5,2,1},
839
             {0.020f,35,0.8f,1.0f,5,2,1},
840
             {0.001f,35,0.8f,1.0f,5,2,1}
841
          };
842

    
843
        bandIndexes = new int[] { 2,2,1,1,0,2 };
844

    
845
        corners = new float[][]
846
          {
847
              {0.04f,0.05f}
848
          };
849

    
850
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
851

    
852
        centers = new float[][]
853
          {
854
              { -0.75f, 0.0f, 0.0f}
855
          };
856

    
857
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
858

    
859
        numComponents = 6;
860
        }
861

    
862
      ///// SQUARE-1 EDGE ///////////////////////////////////////////////////////////////
863

    
864
      else if( mode==10 )
865
        {
866
        final float X = 3*(2-SQ3)/2;
867

    
868
        vertices = new double[][]
869
          {
870
              { -X, 0.5, 0.0 },
871
              { +X, 0.5, 0.0 },
872
              {0.0, 0.5,-1.5 },
873
              { -X,-0.5, 0.0 },
874
              { +X,-0.5, 0.0 },
875
              {0.0,-0.5,-1.5 },
876
          };
877

    
878
        vertIndexes = new int[][]
879
          {
880
              {0,1,2},   // counterclockwise!
881
              {3,4,5},
882
              {3,4,1,0},
883
              {4,5,2,1},
884
              {5,3,0,2}
885
          };
886

    
887
        bands = new float[][]
888
          {
889
            {0.038f,35,0.5f,0.9f, 5,2,1},
890
            {0.001f,35,0.5f,0.9f, 5,2,1}
891
          };
892

    
893
        bandIndexes = new int[]  { 0,1,0,1,1 };
894

    
895
        corners = new float[][]
896
          {
897
             {0.06f,0.20f}
898
          };
899

    
900
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
901

    
902
        centers = new float[][]
903
          {
904
              { 0.0f, 0.0f,-0.5f}
905
          };
906

    
907
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
908

    
909
        numComponents = 6;
910
        }
911

    
912
      ///// SQUARE-1 CORNER ///////////////////////////////////////////////////////////////
913

    
914
      else if( mode==11 )
915
        {
916
        final float X = 3*(2-SQ3)/2;
917

    
918
        vertices = new double[][]
919
          {
920
              { X-1.5, 0.5,  0.0 },
921
              {   0.0, 0.5,  0.0 },
922
              {   0.0, 0.5,X-1.5 },
923
              {  -1.5, 0.5, -1.5 },
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
          };
929

    
930
        vertIndexes = new int[][]
931
          {
932
              {0,1,2,3},   // counterclockwise!
933
              {4,5,6,7},
934
              {4,5,1,0},
935
              {5,6,2,1},
936
              {7,4,0,3},
937
              {6,7,3,2}
938
          };
939

    
940
        bands = new float[][]
941
          {
942
            {0.038f,35,0.9f,1.0f, 5,2,1},
943
            {0.001f,35,0.9f,1.0f, 5,2,1}
944
          };
945

    
946
        bandIndexes = new int[]  { 0,1,0,0,1,1 };
947

    
948
        corners = new float[][]
949
          {
950
            {0.08f,0.20f}
951
          };
952

    
953
        cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
954

    
955
        centers = new float[][]
956
          {
957
             { -0.5f, 0.0f,-0.5f}
958
          };
959

    
960
        centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
961

    
962
        numComponents = 6;
963
        }
964

    
965
      ///// SQUARE-2 CORNER ///////////////////////////////////////////////////////////////
966

    
967
      else if( mode==12 )
968
        {
969
        final float X = 3*(2-SQ3)/2;
970
        final float Z = 0.75f - X/2;
971

    
972
        vertices = new double[][]
973
          {
974
              { X-1.5+Z, 0.5,  0.0 },
975
              {       Z, 0.5,  0.0 },
976
              {  -1.5+Z, 0.5, -1.5 },
977
              { X-1.5+Z,-0.5,  0.0 },
978
              {       Z,-0.5,  0.0 },
979
              {  -1.5+Z,-0.5, -1.5 }
980
          };
981

    
982
        vertIndexes = new int[][]
983
          {
984
              {0,1,2},   // counterclockwise!
985
              {5,4,3},
986
              {3,4,1,0},
987
              {4,5,2,1},
988
              {5,3,0,2}
989
          };
990

    
991
        bands = new float[][]
992
          {
993
            {0.040f,35,0.9f,1.0f, 5,2,1},
994
            {0.001f,35,0.9f,1.0f, 5,2,1}
995
          };
996

    
997
        bandIndexes = new int[] { 0,0,0,1,1 };
998

    
999
        corners = new float[][]
1000
          {
1001
            {0.05f,0.13f}
1002
          };
1003

    
1004
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
1005

    
1006
        centers = new float[][]
1007
          {
1008
             { 0.0f, 0.0f,-0.5f}
1009
          };
1010

    
1011
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
1012

    
1013
        numComponents = 5;
1014
        }
1015

    
1016
      ///// REDI CORNER ///////////////////////////////////////////////////////////////
1017

    
1018
      else if( mode==13 )
1019
        {
1020
        vertices = new double[][]
1021
          {
1022
             { 0.0f, 0.0f, 0.0f },
1023
             {-0.5f, 0.5f, 0.5f },
1024
             {-0.5f,-0.5f, 0.5f },
1025
             { 0.5f, 0.5f, 0.5f },
1026
             { 0.5f,-0.5f, 0.5f },
1027
             { 0.5f, 0.5f,-0.5f },
1028
             { 0.5f,-0.5f,-0.5f },
1029
             {-0.5f, 0.5f,-0.5f },
1030
          };
1031

    
1032
        vertIndexes = new int[][]
1033
          {
1034
             { 2,4,3,1 },
1035
             { 1,3,5,7 },
1036
             { 4,6,5,3 },
1037

    
1038
             { 2,4,0 },
1039
             { 5,7,0 },
1040
             { 4,6,0 },
1041
             { 7,1,0 },
1042
             { 1,2,0 },
1043
             { 6,5,0 }
1044
          };
1045

    
1046
        bands = new float[][]
1047
          {
1048
             {0.06f,35,0.5f,0.7f,5,2,2},
1049
             {0.01f,35,0.2f,0.4f,5,2,2}
1050
          };
1051

    
1052
        bandIndexes = new int[] { 0,0,0,1,1,1,1,1,1 };
1053

    
1054
        corners = new float[][]
1055
          {
1056
            {0.06f,0.12f}
1057
          };
1058

    
1059
        cornerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1060

    
1061
        centers = new float[][]
1062
          {
1063
             { 0.0f, 0.0f, 0.0f}
1064
          };
1065

    
1066
        centerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1067

    
1068
        numComponents = 9;
1069
        }
1070

    
1071
      ///// JING CORNER ///////////////////////////////////////////////////////////////
1072

    
1073
      else if( mode==14 )
1074
        {
1075
        final float F = 0.24f;
1076
        final float X = F/2;
1077
        final float Y = F*SQ2/2;
1078
        final float Z =-F/2;
1079

    
1080
        vertices = new double[][]
1081
          {
1082
             { 0.0, 0.0, 0.0 },
1083
             {   X,   Y,   Z },
1084
             { 0.0, 2*Y, 2*Z },
1085
             {  -X,   Y,   Z },
1086
             { 0.0, 0.0,    -F },
1087
             {   X,   Y,   Z-F },
1088
             { 0.0, 2*Y, 2*Z-F },
1089
             {  -X,   Y,   Z-F },
1090
          };
1091

    
1092
        vertIndexes = new int[][]
1093
          {
1094
             {0,1,2,3},
1095
             {1,0,4,5},
1096
             {7,4,0,3},
1097
             {1,5,6,2},
1098
             {7,3,2,6},
1099
             {4,7,6,5}
1100
          };
1101

    
1102
        bands = new float[][]
1103
          {
1104
             {0.015f,35,0.5f*F,F,5,1,1},
1105
             {0.001f,35,0.5f*F,F,5,1,1}
1106
          };
1107

    
1108
        bandIndexes = new int[] { 0,0,0,1,1,1 };
1109

    
1110
        corners = new float[][]
1111
          {
1112
            {0.08f,0.20f*F},
1113
            {0.07f,0.20f*F}
1114
          };
1115

    
1116
        cornerIndexes = new int[] { 0,1,1,-1,1,-1,-1,-1 };
1117

    
1118
        centers = new float[][]
1119
          {
1120
             { 0.0f, Y, Z-F/2}
1121
          };
1122

    
1123
        centerIndexes = new int[] { 0,0,0,-1,0,-1,-1,-1 };
1124

    
1125
        numComponents = 6;
1126
        }
1127

    
1128
      ///// JING EDGE ///////////////////////////////////////////////////////////////
1129

    
1130
      else if( mode==15 )
1131
        {
1132
        final float F = 0.24f;
1133
        final float X = F/2;
1134
        final float Y = F*SQ2/2;
1135
        final float Z =-F/2;
1136

    
1137
        vertices = new double[][]
1138
          {
1139
             { 0.0, 0.0,     0.5-F },
1140
             {   X,   Y,   Z+0.5-F },
1141
             { 0.0, 2*Y, 2*Z+0.5-F },
1142
             {  -X,   Y,   Z+0.5-F },
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
          };
1148

    
1149
        vertIndexes = new int[][]
1150
          {
1151
             {0,4,5,1},
1152
             {3,7,4,0},
1153
             {0,1,2,3},
1154
             {4,7,6,5},
1155
             {1,5,6,2},
1156
             {2,6,7,3}
1157
          };
1158

    
1159
        bands = new float[][]
1160
          {
1161
             {0.015f,35,0.5f*F,F,5,1,1},
1162
             {0.001f,35,0.5f*F,F,5,1,1}
1163
          };
1164

    
1165
        bandIndexes = new int[] { 0,0,1,1,1,1 };
1166

    
1167
        corners = new float[][]
1168
          {
1169
            {0.07f,0.20f*F}
1170
          };
1171

    
1172
        cornerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1173

    
1174
        centers = new float[][]
1175
          {
1176
             { 0, F*SQ2/2, 0 }
1177
          };
1178

    
1179
        centerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1180

    
1181
        numComponents = 6;
1182
        }
1183

    
1184
      ///// JING FACE ///////////////////////////////////////////////////////////////
1185

    
1186
      else if( mode==16 )
1187
        {
1188
        final float F = 0.24f;
1189
        final float L = (1-3*F);
1190
        final float X = L/2;
1191
        final float Y = L*SQ2/2;
1192
        final float Z =-L/2;
1193
        final float D = F/L;
1194

    
1195
        vertices = new double[][]
1196
          {
1197
              {    0.0,     -2*Y/3,   -2*Z/3 },
1198
              {      X,        Y/3,      Z/3 },
1199
              {     -X,        Y/3,      Z/3 },
1200
              {    0.0,     -2*Y/3,   -2*Z/3+2*D*Z },
1201
              {  X-D*X,    Y/3-D*Y,  Z/3+D*Z },
1202
              { -X+D*X,    Y/3-D*Y,  Z/3+D*Z },
1203
          };
1204

    
1205
        vertIndexes = new int[][]
1206
          {
1207
             {0,1,2},
1208
             {3,5,4},
1209
             {0,3,4,1},
1210
             {5,3,0,2},
1211
             {4,5,2,1}
1212
          };
1213

    
1214
        bands = new float[][]
1215
          {
1216
             {0.025f,35,0.20f*(1-3*F),0.6f*(1-3*F),5,1,1},
1217
             {0.001f,35,0.05f*(1-3*F),0.1f*(1-3*F),5,1,1}
1218
          };
1219

    
1220
        bandIndexes = new int[] { 0,1,1,1,1,1 };
1221

    
1222
        corners = new float[][]
1223
          {
1224
            {0.04f,0.15f}
1225
          };
1226

    
1227
        cornerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1228

    
1229
        centers = new float[][]
1230
          {
1231
            { 0, -2*Y/3, 4*Z/3 }
1232
          };
1233

    
1234
        centerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1235

    
1236
        numComponents = 6;
1237
        }
1238

    
1239
      ///// END DEFINITIONS /////////////////////////////////////////////////////////////////
1240

    
1241
      FactoryCubit factory = FactoryCubit.getInstance();
1242

    
1243
      factory.clear();
1244
      factory.createNewFaceTransform(vertices,vertIndexes);
1245
      mMesh = factory.createRoundedSolid(vertices, vertIndexes,
1246
                                         bands, bandIndexes,
1247
                                         corners, cornerIndexes,
1248
                                         centers, centerIndexes,
1249
                                         numComponents );
1250

    
1251
      int numEff = mMesh.getNumEffComponents();
1252

    
1253
      for(int i=0; i<numEff; i++)
1254
        {
1255
        mMesh.setEffectAssociation(i, 0, i);
1256
        }
1257
      }
1258

    
1259
///////////////////////////////////////////////////////////////////////////////////////////////////
1260

    
1261
    private void openMesh(int resourceID)
1262
      {
1263
      Context con = mView.getContext();
1264
      Resources res = con.getResources();
1265
      InputStream is = res.openRawResource(resourceID);
1266
      DataInputStream dos = new DataInputStream(is);
1267
      mMesh = new MeshFile(dos);
1268

    
1269
      int numEff = mMesh.getNumEffComponents();
1270

    
1271
      for(int i=0; i<numEff; i++)
1272
        {
1273
        mMesh.setEffectAssociation(i, 0, i);
1274
        }
1275

    
1276
      try
1277
        {
1278
        is.close();
1279
        }
1280
      catch(IOException e)
1281
        {
1282
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
1283
        }
1284
      }
1285

    
1286
///////////////////////////////////////////////////////////////////////////////////////////////////
1287

    
1288
    MeshBase getMesh()
1289
      {
1290
      return mMesh;
1291
      }
1292

    
1293
///////////////////////////////////////////////////////////////////////////////////////////////////
1294

    
1295
    long getTime()
1296
      {
1297
      return mTime;
1298
      }
1299

    
1300
///////////////////////////////////////////////////////////////////////////////////////////////////
1301

    
1302
    int getBytes()
1303
      {
1304
      if( mMesh instanceof MeshFile )
1305
        {
1306
        return ((MeshFile)mMesh).getNumBytes();
1307
        }
1308

    
1309
      return 0;
1310
      }
1311

    
1312
///////////////////////////////////////////////////////////////////////////////////////////////////
1313

    
1314
    int getVertices()
1315
      {
1316
      return mMesh.getNumVertices();
1317
      }
1318

    
1319
///////////////////////////////////////////////////////////////////////////////////////////////////
1320

    
1321
    int getEndEffIndex(int component)
1322
      {
1323
      return mMesh.getLastVertexEff(component);
1324
      }
1325

    
1326
///////////////////////////////////////////////////////////////////////////////////////////////////
1327

    
1328
    int getEndTexIndex(int component)
1329
      {
1330
      return mMesh.getLastVertexTex(component);
1331
      }
1332

    
1333
///////////////////////////////////////////////////////////////////////////////////////////////////
1334

    
1335
    int getEffComponentNum()
1336
      {
1337
      return mMesh.getNumEffComponents();
1338
      }
1339

    
1340
///////////////////////////////////////////////////////////////////////////////////////////////////
1341

    
1342
    int getTexComponentNum()
1343
      {
1344
      return mMesh.getNumTexComponents();
1345
      }
1346
}
(3-3/5)