Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ 4b2cad6d

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 final float DEFAULT_SCALE = 0.3f;
62

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

    
72
    Static4D mQuat1, mQuat2;
73
    int mScreenMin;
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

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

    
84
      mCurrentScale = DEFAULT_SCALE;
85

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

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

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

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

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

    
103
      mEffects.apply( disappear );
104

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

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

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

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

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

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

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

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

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

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

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

    
172
      long t1 = System.currentTimeMillis();
173

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

    
183
      long t2 = System.currentTimeMillis();
184

    
185
      mTime = t2-t1;
186

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

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

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

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

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

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

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

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

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

    
233
      return null;
234
      }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

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

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

    
249
      return bitmap;
250
      }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

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

    
267
      ///// CUBE ////////////////////////////////////////////////////////////////////////////////
268

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

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

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

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

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

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

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

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

    
314
        numComponents = 8;
315
        }
316

    
317
      ///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
318

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

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

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

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

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

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

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

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

    
358
        numComponents = 4;
359
        }
360

    
361
      ///// DINO ////////////////////////////////////////////////////////////////////////////////
362

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

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

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

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

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

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

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

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

    
404
        numComponents = 4;
405
        }
406

    
407
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
408

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

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

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

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

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

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

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

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

    
454
        numComponents = 8;
455
        }
456

    
457
      ///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
458

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

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

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

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

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

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

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

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

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

    
514
        numComponents = 6;
515
        }
516

    
517
      ///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
518

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
627
        numComponents = 6;
628
        }
629

    
630
      ///// IVY_FACE ////////////////////////////////////////////////////////////////////////
631

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

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

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

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

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

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

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

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

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

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

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

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

    
692
        numComponents = 2;
693
        }
694

    
695
      ///// SKEWB Ultimate SMALL  /////////////////////////////////////////////////////////////
696

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

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

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

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

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

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

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

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

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

    
745
        numComponents = 8;
746
        }
747

    
748
      ///// SKEWB Ultimate BIG ///////////////////////////////////////////////////////////////
749

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

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

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

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

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

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

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

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

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

    
804
        numComponents = 8;
805
        }
806

    
807
      ///// SQUARE-1 MIDDLE ///////////////////////////////////////////////////////////////
808

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

    
813
        vertices = new double[][]
814
          {
815
              { -1.5-X, 0.5, 1.5 },
816
              {    0.0, 0.5, 1.5 },
817
              {    0.0, 0.5,-1.5 },
818
              { -1.5+X, 0.5,-1.5 },
819
              { -1.5-X,-0.5, 1.5 },
820
              {    0.0,-0.5, 1.5 },
821
              {    0.0,-0.5,-1.5 },
822
              { -1.5+X,-0.5,-1.5 }
823
          };
824

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

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

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

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

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

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

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

    
858
        numComponents = 6;
859
        }
860

    
861
      ///// SQUARE-1 EDGE ///////////////////////////////////////////////////////////////
862

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

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

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

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

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

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

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

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

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

    
908
        numComponents = 6;
909
        }
910

    
911
      ///// SQUARE-1 CORNER ///////////////////////////////////////////////////////////////
912

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

    
917
        vertices = new double[][]
918
          {
919
              { X-1.5, 0.5,  0.0 },
920
              {   0.0, 0.5,  0.0 },
921
              {   0.0, 0.5,X-1.5 },
922
              {  -1.5, 0.5, -1.5 },
923
              { X-1.5,-0.5,  0.0 },
924
              {   0.0,-0.5,  0.0 },
925
              {   0.0,-0.5,X-1.5 },
926
              {  -1.5,-0.5, -1.5 }
927
          };
928

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

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

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

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

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

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

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

    
961
        numComponents = 6;
962
        }
963

    
964
      ///// SQUARE-2 CORNER ///////////////////////////////////////////////////////////////
965

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

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

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

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

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

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

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

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

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

    
1012
        numComponents = 5;
1013
        }
1014

    
1015
      ///// REDI CORNER ///////////////////////////////////////////////////////////////
1016

    
1017
      else if( mode==13 )
1018
        {
1019
        vertices = new double[][]
1020
          {
1021
             { 0.0f, 0.0f, 0.0f },
1022
             {-0.5f, 0.5f, 0.5f },
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
          };
1030

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

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

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

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

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

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

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

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

    
1067
        numComponents = 9;
1068
        }
1069

    
1070
      ///// END DEFINITIONS /////////////////////////////////////////////////////////////////
1071

    
1072
      FactoryCubit factory = FactoryCubit.getInstance();
1073

    
1074
      factory.clear();
1075
      factory.createNewFaceTransform(vertices,vertIndexes);
1076
      mMesh = factory.createRoundedSolid(vertices, vertIndexes,
1077
                                         bands, bandIndexes,
1078
                                         corners, cornerIndexes,
1079
                                         centers, centerIndexes,
1080
                                         numComponents );
1081

    
1082
      int numEff = mMesh.getNumEffComponents();
1083

    
1084
      for(int i=0; i<numEff; i++)
1085
        {
1086
        mMesh.setEffectAssociation(i, 0, i);
1087
        }
1088
      }
1089

    
1090
///////////////////////////////////////////////////////////////////////////////////////////////////
1091

    
1092
    private void openMesh(int resourceID)
1093
      {
1094
      Context con = mView.getContext();
1095
      Resources res = con.getResources();
1096
      InputStream is = res.openRawResource(resourceID);
1097
      DataInputStream dos = new DataInputStream(is);
1098
      mMesh = new MeshFile(dos);
1099

    
1100
      int numEff = mMesh.getNumEffComponents();
1101

    
1102
      for(int i=0; i<numEff; i++)
1103
        {
1104
        mMesh.setEffectAssociation(i, 0, i);
1105
        }
1106

    
1107
      try
1108
        {
1109
        is.close();
1110
        }
1111
      catch(IOException e)
1112
        {
1113
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
1114
        }
1115
      }
1116

    
1117
///////////////////////////////////////////////////////////////////////////////////////////////////
1118

    
1119
    MeshBase getMesh()
1120
      {
1121
      return mMesh;
1122
      }
1123

    
1124
///////////////////////////////////////////////////////////////////////////////////////////////////
1125

    
1126
    long getTime()
1127
      {
1128
      return mTime;
1129
      }
1130

    
1131
///////////////////////////////////////////////////////////////////////////////////////////////////
1132

    
1133
    int getBytes()
1134
      {
1135
      if( mMesh instanceof MeshFile )
1136
        {
1137
        return ((MeshFile)mMesh).getNumBytes();
1138
        }
1139

    
1140
      return 0;
1141
      }
1142

    
1143
///////////////////////////////////////////////////////////////////////////////////////////////////
1144

    
1145
    int getVertices()
1146
      {
1147
      return mMesh.getNumVertices();
1148
      }
1149

    
1150
///////////////////////////////////////////////////////////////////////////////////////////////////
1151

    
1152
    int getEndEffIndex(int component)
1153
      {
1154
      return mMesh.getLastVertexEff(component);
1155
      }
1156

    
1157
///////////////////////////////////////////////////////////////////////////////////////////////////
1158

    
1159
    int getEndTexIndex(int component)
1160
      {
1161
      return mMesh.getLastVertexTex(component);
1162
      }
1163

    
1164
///////////////////////////////////////////////////////////////////////////////////////////////////
1165

    
1166
    int getEffComponentNum()
1167
      {
1168
      return mMesh.getNumEffComponents();
1169
      }
1170

    
1171
///////////////////////////////////////////////////////////////////////////////////////////////////
1172

    
1173
    int getTexComponentNum()
1174
      {
1175
      return mMesh.getNumTexComponents();
1176
      }
1177
}
(3-3/5)