Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ 31d42722

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 = 12;
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
              {-0.5, 0.0, 0.0},
368
              { 0.5, 0.0, 0.0},
369
              { 0.0,-0.5, 0.0},
370
              { 0.0, 0.0,-0.5}
371
          };
372

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

    
381
        bands = new float[][]
382
          {
383
              {0.028f,30,0.25f,0.1f,7,  2,5},
384
              {0.001f,30,0.25f,0.1f,7,  1,2}
385
          };
386

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

    
389
        corners = new float[][]
390
          {
391
              { 0.02f, 0.04f }
392
          };
393

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

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

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

    
403
        numComponents = 4;
404
        }
405

    
406
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
407

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

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

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

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

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

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

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

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

    
453
        numComponents = 8;
454
        }
455

    
456
      ///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
457

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

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

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

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

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

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

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

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

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

    
513
        numComponents = 6;
514
        }
515

    
516
      ///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
517

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
626
        numComponents = 6;
627
        }
628

    
629
      ///// IVY_FACE ////////////////////////////////////////////////////////////////////////
630

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

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

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

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

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

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

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

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

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

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

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

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

    
691
        numComponents = 2;
692
        }
693

    
694
      ///// SKEWB Ultimate SMALL  /////////////////////////////////////////////////////////////
695

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

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

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

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

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

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

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

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

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

    
744
        numComponents = 8;
745
        }
746

    
747
      ///// SKEWB Ultimate BIG ///////////////////////////////////////////////////////////////
748

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

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

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

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

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

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

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

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

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

    
803
        numComponents = 8;
804
        }
805

    
806
      ///// SQUARE-1 MIDDLE ///////////////////////////////////////////////////////////////
807

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

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

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

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

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

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

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

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

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

    
857
        numComponents = 6;
858
        }
859

    
860
      ///// SQUARE-1 EDGE ///////////////////////////////////////////////////////////////
861

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

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

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

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

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

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

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

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

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

    
907
        numComponents = 6;
908
        }
909

    
910
      ///// SQUARE-1 CORNER ///////////////////////////////////////////////////////////////
911

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

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

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

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

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

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

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

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

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

    
960
        numComponents = 6;
961
        }
962

    
963
      ///// SQUARE-2 CORNER ///////////////////////////////////////////////////////////////
964

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

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

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

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

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

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

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

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

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

    
1011
        numComponents = 5;
1012
        }
1013

    
1014
      ///// END DEFINITIONS /////////////////////////////////////////////////////////////////
1015

    
1016
      FactoryCubit factory = FactoryCubit.getInstance();
1017

    
1018
      factory.clear();
1019
      factory.createNewFaceTransform(vertices,vertIndexes);
1020
      mMesh = factory.createRoundedSolid(vertices, vertIndexes,
1021
                                         bands, bandIndexes,
1022
                                         corners, cornerIndexes,
1023
                                         centers, centerIndexes,
1024
                                         numComponents );
1025

    
1026
      int numEff = mMesh.getNumEffComponents();
1027

    
1028
      for(int i=0; i<numEff; i++)
1029
        {
1030
        mMesh.setEffectAssociation(i, 0, i);
1031
        }
1032
      }
1033

    
1034
///////////////////////////////////////////////////////////////////////////////////////////////////
1035

    
1036
    private void openMesh(int resourceID)
1037
      {
1038
      Context con = mView.getContext();
1039
      Resources res = con.getResources();
1040
      InputStream is = res.openRawResource(resourceID);
1041
      DataInputStream dos = new DataInputStream(is);
1042
      mMesh = new MeshFile(dos);
1043

    
1044
      int numEff = mMesh.getNumEffComponents();
1045

    
1046
      for(int i=0; i<numEff; i++)
1047
        {
1048
        mMesh.setEffectAssociation(i, 0, i);
1049
        }
1050

    
1051
      try
1052
        {
1053
        is.close();
1054
        }
1055
      catch(IOException e)
1056
        {
1057
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
1058
        }
1059
      }
1060

    
1061
///////////////////////////////////////////////////////////////////////////////////////////////////
1062

    
1063
    MeshBase getMesh()
1064
      {
1065
      return mMesh;
1066
      }
1067

    
1068
///////////////////////////////////////////////////////////////////////////////////////////////////
1069

    
1070
    long getTime()
1071
      {
1072
      return mTime;
1073
      }
1074

    
1075
///////////////////////////////////////////////////////////////////////////////////////////////////
1076

    
1077
    int getBytes()
1078
      {
1079
      if( mMesh instanceof MeshFile )
1080
        {
1081
        return ((MeshFile)mMesh).getNumBytes();
1082
        }
1083

    
1084
      return 0;
1085
      }
1086

    
1087
///////////////////////////////////////////////////////////////////////////////////////////////////
1088

    
1089
    int getVertices()
1090
      {
1091
      return mMesh.getNumVertices();
1092
      }
1093

    
1094
///////////////////////////////////////////////////////////////////////////////////////////////////
1095

    
1096
    int getEndEffIndex(int component)
1097
      {
1098
      return mMesh.getLastVertexEff(component);
1099
      }
1100

    
1101
///////////////////////////////////////////////////////////////////////////////////////////////////
1102

    
1103
    int getEndTexIndex(int component)
1104
      {
1105
      return mMesh.getLastVertexTex(component);
1106
      }
1107

    
1108
///////////////////////////////////////////////////////////////////////////////////////////////////
1109

    
1110
    int getEffComponentNum()
1111
      {
1112
      return mMesh.getNumEffComponents();
1113
      }
1114

    
1115
///////////////////////////////////////////////////////////////////////////////////////////////////
1116

    
1117
    int getTexComponentNum()
1118
      {
1119
      return mMesh.getNumTexComponents();
1120
      }
1121
}
(3-3/5)