Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ 6983badf

1 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.examples.meshfile;
21
22 1af8e143 Leszek Koltunski
import android.content.Context;
23
import android.content.res.Resources;
24 42aa970f Leszek Koltunski
import android.graphics.Bitmap;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27
import android.opengl.GLSurfaceView;
28
29 8ac4c0bc Leszek Koltunski
import org.distorted.examples.R;
30 a65604a7 Leszek Koltunski
import org.distorted.library.effect.Effect;
31 6991ece5 Leszek Koltunski
import org.distorted.library.effect.EffectType;
32 42aa970f Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
33
import org.distorted.library.effect.MatrixEffectScale;
34 39b925d5 Leszek Koltunski
import org.distorted.library.effect.VertexEffectDisappear;
35 42aa970f Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.library.main.DistortedScreen;
38
import org.distorted.library.main.DistortedTexture;
39 6991ece5 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
40 1af8e143 Leszek Koltunski
import org.distorted.library.mesh.MeshFile;
41 42aa970f Leszek Koltunski
import org.distorted.library.type.DynamicQuat;
42
import org.distorted.library.type.Static3D;
43
import org.distorted.library.type.Static4D;
44
45 1af8e143 Leszek Koltunski
import java.io.DataInputStream;
46
import java.io.IOException;
47
import java.io.InputStream;
48
49 42aa970f Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
50
import javax.microedition.khronos.opengles.GL10;
51
52 6991ece5 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
53
54 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56 061449ed Leszek Koltunski
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
57 42aa970f Leszek Koltunski
{
58 7edab735 Leszek Koltunski
    private static final float SQ2 = (float)Math.sqrt(2);
59
    private static final float SQ3 = (float)Math.sqrt(3);
60 16b336db Leszek Koltunski
    private final float DEFAULT_SCALE = 0.3f;
61
62 140f2c4e Leszek Koltunski
    private final GLSurfaceView mView;
63 42aa970f Leszek Koltunski
    private DistortedTexture mTexture;
64 140f2c4e Leszek Koltunski
    private final DistortedScreen mScreen;
65
    private final DistortedEffects mEffects;
66
    private final Static3D mScale;
67 48c88f57 Leszek Koltunski
    private long mTime;
68 16b336db Leszek Koltunski
    private float mCurrentScale;
69 6991ece5 Leszek Koltunski
    private MeshBase mMesh;
70 42aa970f Leszek Koltunski
71
    Static4D mQuat1, mQuat2;
72
    int mScreenMin;
73
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76
    MeshFileRenderer(GLSurfaceView v)
77
      {
78
      mView = v;
79
      mScreen = new DistortedScreen();
80
      mScale= new Static3D(1,1,1);
81
      Static3D center=new Static3D(0,0,0);
82
83 16b336db Leszek Koltunski
      mCurrentScale = DEFAULT_SCALE;
84
85 42aa970f Leszek Koltunski
      mQuat1 = new Static4D(0,0,0,1);
86 fe032f52 Leszek Koltunski
      mQuat2 = new Static4D(0,0,0,1);
87 42aa970f Leszek Koltunski
88
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
89
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
90
91
      quatInt1.add(mQuat1);
92
      quatInt2.add(mQuat2);
93
94 39b925d5 Leszek Koltunski
      VertexEffectDisappear disappear = new VertexEffectDisappear();
95
      disappear.setMeshAssociation(1,-1);
96
97 42aa970f Leszek Koltunski
      mEffects = new DistortedEffects();
98
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
99
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
100
      mEffects.apply( new MatrixEffectScale(mScale));
101
102 39b925d5 Leszek Koltunski
      mEffects.apply( disappear );
103
104 42aa970f Leszek Koltunski
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
105 48c88f57 Leszek Koltunski
      mScreen.showFPS();
106 42aa970f Leszek Koltunski
      }
107
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109
   
110
    public void onDrawFrame(GL10 glUnused) 
111
      {
112
      mScreen.render( System.currentTimeMillis() );
113
      }
114
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
    
117
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
118
      {
119
      mScreenMin = Math.min(width, height);
120 16b336db Leszek Koltunski
      float factor = mCurrentScale*mScreenMin;
121 42aa970f Leszek Koltunski
      mScale.set(factor,factor,factor);
122
      mScreen.resize(width, height);
123
      }
124
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
    
127
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
128
      {
129
      if( mTexture==null ) mTexture = new DistortedTexture();
130
131 a65604a7 Leszek Koltunski
      Effect.enableEffects(EffectType.VERTEX);
132 04a21ed6 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX, 20);
133 ef02f5e0 Leszek Koltunski
      DistortedLibrary.needTransformFeedback();
134 7c72e798 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
135 061449ed Leszek Koltunski
      }
136
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139
    public void distortedException(Exception ex)
140
      {
141
      android.util.Log.e("MeshFile", ex.getMessage() );
142 42aa970f Leszek Koltunski
      }
143
144 16b336db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
145
//   0 ---> 0
146
//  50 ---> DEFAULT_SCALE
147
// 100 ---> 4*DEFAULT_SCALE
148
149
    void setScale(int scale)
150
      {
151
      if( scale<= 50 )
152
        {
153
        mCurrentScale = DEFAULT_SCALE * scale / 50.0f;
154
        }
155
      else
156
        {
157
        mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f);
158
        }
159
160
      float factor = mCurrentScale*mScreenMin;
161
      mScale.set(factor,factor,factor);
162
      }
163
164 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
165
166 1af8e143 Leszek Koltunski
    void open(int resourceID)
167 42aa970f Leszek Koltunski
      {
168 099d8f8b Leszek Koltunski
      if( mTexture==null ) mTexture = new DistortedTexture();
169 8ac4c0bc Leszek Koltunski
      mTexture.setTexture( createTexture(resourceID) );
170
171 acad428e Leszek Koltunski
      long t1 = System.currentTimeMillis();
172 6991ece5 Leszek Koltunski
173
      if( resourceID!=PROCEDURAL )
174
        {
175
        openMesh(resourceID);
176
        }
177
      else
178
        {
179
        createMesh();
180
        }
181
182 acad428e Leszek Koltunski
      long t2 = System.currentTimeMillis();
183
184 48c88f57 Leszek Koltunski
      mTime = t2-t1;
185 42aa970f Leszek Koltunski
186 71c7624f Leszek Koltunski
      mScreen.detachAll();
187 7198e5c9 Leszek Koltunski
      mScreen.attach(mTexture,mEffects,mMesh);
188 42aa970f Leszek Koltunski
      }
189
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
192 1af8e143 Leszek Koltunski
    private Bitmap createTexture(int resourceID)
193 42aa970f Leszek Koltunski
      {
194 7edab735 Leszek Koltunski
      TextureFactory factory = TextureFactory.getInstance();
195
196
      float[] vertices;
197
      int[] colors;
198
      float F = 0.5f;
199
      float E = SQ3/2;
200
      float G = SQ2/4;
201
202 8ac4c0bc Leszek Koltunski
      switch(resourceID)
203
          {
204
          case  R.raw.deferredjob:
205 7edab735 Leszek Koltunski
          case  R.raw.meshjoin   :
206 1beffb69 Leszek Koltunski
          case  PROCEDURAL       :
207 7edab735 Leszek Koltunski
          case  R.raw.predeform  : return createWhiteTexture();
208
209 8ac4c0bc Leszek Koltunski
          case  R.raw.cube2      :
210
          case  R.raw.cube3      :
211
          case  R.raw.cube4      :
212 7edab735 Leszek Koltunski
          case  R.raw.cube5      : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
213
                                   vertices = new float[] { -F,-F, +F,-F, +F,+F, -F,+F};
214
                                   return factory.createTexture(vertices,colors,0.10f, 0.10f, true);
215 8ac4c0bc Leszek Koltunski
          case  R.raw.pyra3      :
216
          case  R.raw.pyra4      :
217 7edab735 Leszek Koltunski
          case  R.raw.pyra5      : colors = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
218
                                   vertices = new float[] { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
219
                                   return factory.createTexture(vertices,colors,0.05f, 0.05f, true);
220 8ac4c0bc Leszek Koltunski
221 7edab735 Leszek Koltunski
          case  R.raw.dino       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
222
                                   vertices = new float[] { -F,F/3, 0,-2*F/3, +F,F/3 };
223
                                   return factory.createTexture(vertices,colors,0.05f, 0.03f, true);
224 8ac4c0bc Leszek Koltunski
225 7edab735 Leszek Koltunski
          case R.raw.skewb       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
226
                                   //vertices = new float[] { -G,-G, +G,-G, +G,+G, -G,+G };
227 8ac4c0bc Leszek Koltunski
228 7edab735 Leszek Koltunski
                                   vertices = new float[] { -F+F/4,F/4, F/4,-F+F/4, F/4,F/4};
229
                                   return factory.createTexture(vertices,colors,0.05f, 0.08f, true);
230
          }
231 8ac4c0bc Leszek Koltunski
232 7edab735 Leszek Koltunski
      return null;
233 8ac4c0bc Leszek Koltunski
      }
234
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237 7edab735 Leszek Koltunski
    private Bitmap createWhiteTexture()
238 8ac4c0bc Leszek Koltunski
      {
239 7edab735 Leszek Koltunski
      int SIZE = 1;
240 8ac4c0bc Leszek Koltunski
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
241
      Canvas canvas = new Canvas(bitmap);
242
243
      Paint paint = new Paint();
244 36793c52 Leszek Koltunski
      paint.setColor(0xffffff55);
245 1beffb69 Leszek Koltunski
      paint.setStyle(Paint.Style.FILL);
246 7edab735 Leszek Koltunski
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
247 6991ece5 Leszek Koltunski
248 72059460 Leszek Koltunski
      return bitmap;
249 6991ece5 Leszek Koltunski
      }
250
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252
253
    private void createMesh()
254
      {
255 6983badf Leszek Koltunski
      int mode = 6;
256
      int numComponents = 0;
257 4d883a92 Leszek Koltunski
      double[][] vertices = null;
258 28f4aba0 Leszek Koltunski
      int[][] vertIndexes = null;
259
      float[][] bands     = null;
260
      int[] bandIndexes   = null;
261
      float[][] corners   = null;
262
      int[] cornerIndexes = null;
263 6983badf Leszek Koltunski
      float[][] centers   = null;
264
      int[] centerIndexes = null;
265 28f4aba0 Leszek Koltunski
266 4d883a92 Leszek Koltunski
      ///// CUBE ////////////////////////////////////////////////////////////////////////////////
267
268
      if( mode==0 )
269 28f4aba0 Leszek Koltunski
        {
270 4d883a92 Leszek Koltunski
        vertices = new double[][]
271 33647db9 Leszek Koltunski
          {
272 4d883a92 Leszek Koltunski
              { 0.5, 0.5, 0.5 },
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 33647db9 Leszek Koltunski
          };
281
282 28f4aba0 Leszek Koltunski
        vertIndexes = new int[][]
283 33647db9 Leszek Koltunski
          {
284 140f2c4e Leszek Koltunski
              {2,3,1,0},   // counterclockwise!
285
              {7,6,4,5},
286
              {4,0,1,5},
287
              {7,3,2,6},
288
              {6,2,0,4},
289
              {3,7,5,1}
290 33647db9 Leszek Koltunski
          };
291
292 28f4aba0 Leszek Koltunski
        bands = new float[][]
293 33647db9 Leszek Koltunski
          {
294 6a96e571 Leszek Koltunski
              {0.05f,40,0.5f,0.2f,5,  2,2}
295 33647db9 Leszek Koltunski
          };
296 a65604a7 Leszek Koltunski
297 28f4aba0 Leszek Koltunski
        bandIndexes = new int[] { 0,0,0,0,0,0 };
298 1c41c4c9 Leszek Koltunski
299 28f4aba0 Leszek Koltunski
        corners = new float[][]
300 1b85f172 Leszek Koltunski
          {
301
              { 0.01f, 0.10f }
302
          };
303
304 28f4aba0 Leszek Koltunski
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
305 6983badf Leszek Koltunski
306
        centers = new float[][]
307
          {
308
              { 0.0f, 0.0f, 0.0f }
309
          };
310
311
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
312
313
        numComponents = 8;
314 28f4aba0 Leszek Koltunski
        }
315 4d883a92 Leszek Koltunski
316
      ///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
317
318
      else if( mode==1 )
319 28f4aba0 Leszek Koltunski
        {
320 4d883a92 Leszek Koltunski
        vertices = new double[][]
321 28f4aba0 Leszek Koltunski
          {
322 4d883a92 Leszek Koltunski
              {-0.5, SQ2/4, 0.0},
323
              { 0.5, SQ2/4, 0.0},
324
              { 0.0,-SQ2/4, 0.5},
325
              { 0.0,-SQ2/4,-0.5}
326 28f4aba0 Leszek Koltunski
          };
327
328
        vertIndexes = new int[][]
329
          {
330
              {2,1,0},   // counterclockwise!
331
              {2,3,1},
332
              {3,2,0},
333
              {3,0,1}
334
          };
335
336
        bands = new float[][]
337
          {
338
              {0.05f,30,0.6f,0.5f,5,  2,2}
339
          };
340
341
        bandIndexes = new int[] { 0,0,0,0 };
342
343
        corners = new float[][]
344
          {
345
              { 0.02f, 0.10f }
346
          };
347
348
        cornerIndexes = new int[] { 0,0,0,0 };
349 6983badf Leszek Koltunski
350
        centers = new float[][]
351
          {
352
              { 0.0f, 0.0f, 0.0f }
353
          };
354
355
        centerIndexes = new int[] { 0,0,0,0 };
356
357
        numComponents = 4;
358 28f4aba0 Leszek Koltunski
        }
359 4d883a92 Leszek Koltunski
360
      ///// DINO ////////////////////////////////////////////////////////////////////////////////
361
362
      else if( mode==2 )
363 28f4aba0 Leszek Koltunski
        {
364 4d883a92 Leszek Koltunski
        vertices = new double[][]
365 28f4aba0 Leszek Koltunski
          {
366 4d883a92 Leszek Koltunski
              {-0.5, 0.0, 0.0},
367
              { 0.5, 0.0, 0.0},
368
              { 0.0,-0.5, 0.0},
369
              { 0.0, 0.0,-0.5}
370 28f4aba0 Leszek Koltunski
          };
371
372
        vertIndexes = new int[][]
373
          {
374
              {2,1,0},   // counterclockwise!
375
              {2,3,1},
376
              {3,2,0},
377
              {3,0,1}
378
          };
379
380
        bands = new float[][]
381
          {
382 6a96e571 Leszek Koltunski
              {0.028f,30,0.25f,0.1f,7,  2,5},
383
              {0.001f,30,0.25f,0.1f,7,  1,2}
384 28f4aba0 Leszek Koltunski
          };
385
386
        bandIndexes = new int[] { 0,1,1,0 };
387
388
        corners = new float[][]
389
          {
390 6983badf Leszek Koltunski
              { 0.02f, 0.04f }
391 28f4aba0 Leszek Koltunski
          };
392
393
        cornerIndexes = new int[] { 0,0,0,0 };
394 6983badf Leszek Koltunski
395
        centers = new float[][]
396
          {
397
              { 0.0f,-0.25f,-0.25f }
398
          };
399
400
        centerIndexes = new int[] { 0,0,0,0 };
401
402
        numComponents = 4;
403 28f4aba0 Leszek Koltunski
        }
404 1b85f172 Leszek Koltunski
405 6a96e571 Leszek Koltunski
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
406
407
      else if( mode==3 )
408
        {
409
        vertices = new double[][]
410
          {
411
              { 0.5,   0.0, 0.5},
412
              { 0.5,   0.0,-0.5},
413
              {-0.5,   0.0,-0.5},
414
              {-0.5,   0.0, 0.5},
415
              { 0.0, SQ2/2, 0.0},
416
              { 0.0,-SQ2/2, 0.0},
417
          };
418
419
        vertIndexes = new int[][]
420
          {
421
              {3,0,4},   // counterclockwise!
422
              {0,1,4},
423
              {1,2,4},
424
              {2,3,4},
425
              {5,0,3},
426
              {5,1,0},
427
              {5,2,1},
428
              {5,3,2}
429
          };
430
431
        bands = new float[][]
432
          {
433
             {0.05f,17,0.5f,0.2f,5,  2,2}
434
          };
435
436
        bandIndexes = new int[] { 0,0,0,0,0,0,0,0 };
437
438
        corners = new float[][]
439
          {
440
              { 0.03f, 0.12f }
441
          };
442
443
        cornerIndexes = new int[] { 0,0,0,0,0,0 };
444 6983badf Leszek Koltunski
445
        centers = new float[][]
446
          {
447
              { 0.0f, 0.0f, 0.0f }
448
          };
449
450
        centerIndexes = new int[] { 0,0,0,0,0,0 };
451
452
        numComponents = 8;
453 6a96e571 Leszek Koltunski
        }
454
455 3083fab8 Leszek Koltunski
      ///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
456
457
      else if( mode==4 )
458
        {
459
        double SQ5  = Math.sqrt(5);
460
        double SIN18= (SQ5-1)/4;
461
        double COS18= 0.25*Math.sqrt(10.0+2.0*SQ5);
462
        double H = 1.0;
463
        double L = 2.0;
464
        double X = H*Math.sqrt((5+SQ5)/10);
465
        double Y = H*Math.sqrt((5-SQ5)/10);
466
        double D = H*SIN18/COS18;
467
468
        vertices = new double[][]
469
          {
470
              { 0.0,   Y, L/2},
471
              {   X, 0.0, L/2},
472
              { 0.0,  -Y, L/2},
473
              {  -X, 0.0, L/2},
474
              { 0.0,  Y, -L/2 +D},
475
              {   X, 0.0,-L/2   },
476
              { 0.0, -Y, -L/2-D },
477
              {  -X, 0.0,-L/2   }
478
          };
479
480
        vertIndexes = new int[][]
481
          {
482
              {3,2,1,0},   // counterclockwise!
483
              {0,1,5,4},
484
              {3,0,4,7},
485
              {2,1,5,6},
486
              {3,2,6,7},
487
              {4,5,6,7}
488
          };
489
490
        bands = new float[][]
491
          {
492
             {0.04f,13,(float)(L/3),(float)L/8, 5,2,3},
493
             {0.00f, 0,(float)(L/2),(float)L/4, 5,2,3}
494
          };
495
496
        bandIndexes = new int[] { 1,0,0,1,1,1 };
497
498
        corners = new float[][]
499
          {
500 6983badf Leszek Koltunski
              { 0.04f, 0.12f }
501
          };
502
503
        cornerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
504
505
        centers = new float[][]
506
          {
507
              { 0.0f, 0.0f, 0.0f }
508
          };
509
510
        centerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
511
512
        numComponents = 6;
513
        }
514
515
      ///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
516
517
      else if( mode==5 )
518
        {
519
        int IVY_N = 3;
520
        final float IVY_D = 0.003f;
521
        final double angle = Math.PI/(2*IVY_N);
522
        final double CORR  = 1.0 - 2*IVY_D;
523
524
        vertices = new double[3*IVY_N+7][3];
525
        vertIndexes = new int[6][IVY_N+4];
526
527
        vertices[0][0] = 0.0;
528
        vertices[0][1] = 0.0;
529
        vertices[0][2] = 0.0;
530
        vertices[1][0] =-1.0;
531
        vertices[1][1] = 0.0;
532
        vertices[1][2] = 0.0;
533
        vertices[2][0] = 0.0;
534
        vertices[2][1] =-1.0;
535
        vertices[2][2] = 0.0;
536
        vertices[3][0] = 0.0;
537
        vertices[3][1] = 0.0;
538
        vertices[3][2] =-1.0;
539
540
        vertIndexes[0][0] = 2;
541
        vertIndexes[0][1] = 0;
542
        vertIndexes[0][2] = 1;
543
        vertIndexes[3][0] = 2;
544
        vertIndexes[3][1] = 0;
545
        vertIndexes[3][2] = 1;
546
547
        vertIndexes[1][0] = 3;
548
        vertIndexes[1][1] = 0;
549
        vertIndexes[1][2] = 2;
550
        vertIndexes[4][0] = 3;
551
        vertIndexes[4][1] = 0;
552
        vertIndexes[4][2] = 2;
553
554
        vertIndexes[2][0] = 1;
555
        vertIndexes[2][1] = 0;
556
        vertIndexes[2][2] = 3;
557
        vertIndexes[5][0] = 1;
558
        vertIndexes[5][1] = 0;
559
        vertIndexes[5][2] = 3;
560
561
        int N1 = 4;
562
        int N2 = N1 + IVY_N + 1;
563
        int N3 = N2 + IVY_N + 1;
564
565
        for(int i=0; i<=IVY_N; i++)
566
          {
567
          double cos1 = Math.cos((IVY_N-i)*angle);
568
          double sin1 = Math.sin((IVY_N-i)*angle);
569
          double cos2 = Math.cos((      i)*angle);
570
          double sin2 = Math.sin((      i)*angle);
571
572
          vertices[N1+i][0] = CORR*(cos1-0.5) - 0.5;
573
          vertices[N1+i][1] = CORR*(sin1-0.5) - 0.5;
574
          vertices[N1+i][2] = 0.0;
575
576
          vertices[N2+i][0] = 0.0;
577
          vertices[N2+i][1] = CORR*(sin2-0.5) - 0.5;
578
          vertices[N2+i][2] = CORR*(cos2-0.5) - 0.5;
579
580
          vertices[N3+i][0] = CORR*(cos2-0.5) - 0.5;
581
          vertices[N3+i][1] = 0.0;
582
          vertices[N3+i][2] = CORR*(sin2-0.5) - 0.5;
583
584
          vertIndexes[0][i+3] = N1 + i;
585
          vertIndexes[1][i+3] = N2 + i;
586
          vertIndexes[2][i+3] = N3 + i;
587
          vertIndexes[3][i+3] = N1 + i;
588
          vertIndexes[4][i+3] = N2 + i;
589
          vertIndexes[5][i+3] = N3 + i;
590
          }
591
592
        bands = new float[][]
593
          {
594
             {+0.012f,20,0.2f,0.5f,7,1,2},
595
             {-0.100f,20,0.2f,0.0f,2,1,2}
596
          };
597
598
        bandIndexes = new int[] { 0,0,0,1,1,1 };
599
600
        corners = new float[][]
601
          {
602
              { 0.04f, 0.12f }
603
          };
604
605
        cornerIndexes = new int[3*IVY_N+7];
606
607
        centers = new float[][]
608
          {
609
              {-0.5f,-0.5f,-0.5f}
610 3083fab8 Leszek Koltunski
          };
611
612 6983badf Leszek Koltunski
        centerIndexes = new int[3*IVY_N+7];
613
614
        for(int i=0; i<4; i++)
615
          {
616
          cornerIndexes[i] = 0;
617
          centerIndexes[i] = 0;
618
          }
619
        for(int i=4; i<3*IVY_N+7; i++)
620
          {
621
          cornerIndexes[i] = -1;
622
          centerIndexes[i] = -1;
623
          }
624
625
        numComponents = 6;
626
        }
627
628
      ///// IVY_FACE ////////////////////////////////////////////////////////////////////////
629
630
      else if( mode==6 )
631
        {
632
        int IVY_N = 6;
633
        final float IVY_D = 0.003f;
634
        final double angle = Math.PI/(2*IVY_N);
635
        final double CORR  = 1.0 - 2*IVY_D;
636
637
        vertices   = new double[2*IVY_N][3];
638
        vertIndexes= new int[2][2*IVY_N];
639
640
        for(int i=0; i<IVY_N; i++)
641
          {
642
          double cos = Math.cos(i*angle);
643
          double sin = Math.sin(i*angle);
644
645
          vertices[i      ][0] = CORR*(0.5-cos);
646
          vertices[i      ][1] = CORR*(0.5-sin);
647
          vertices[i      ][2] = 0.0;
648
          vertices[i+IVY_N][0] = CORR*(cos-0.5);
649
          vertices[i+IVY_N][1] = CORR*(sin-0.5);
650
          vertices[i+IVY_N][2] = 0.0;
651
652
          vertIndexes[0][i      ] = i;
653
          vertIndexes[0][i+IVY_N] = i+IVY_N;
654
          vertIndexes[1][i      ] = i;
655
          vertIndexes[1][i+IVY_N] = i+IVY_N;
656
          }
657
658
        bands = new float[][]
659
          {
660
             {+0.012f,20,0.2f,0.5f,7,1,2},
661
             {-0.100f,20,0.2f,0.0f,2,1,2},
662
          };
663
664
        bandIndexes = new int[] { 0,1 };
665
666
        corners = new float[][]
667
          {
668
             {0.03f,0.10f}
669
          };
670
671
        centers = new float[][]
672
          {
673
              {-0.0f,-0.0f,-0.5f}
674
          };
675
676
        cornerIndexes = new int[2*IVY_N];
677
        centerIndexes = new int[2*IVY_N];
678
679
        for(int i=0; i<2*IVY_N; i++)
680
          {
681
          cornerIndexes[i] = -1;
682
          centerIndexes[i] = -1;
683
          }
684
685
        cornerIndexes[0    ] = 0;
686
        cornerIndexes[IVY_N] = 0;
687
        centerIndexes[0    ] = 0;
688
        centerIndexes[IVY_N] = 0;
689
690
        numComponents = 2;
691 3083fab8 Leszek Koltunski
        }
692
693 33647db9 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
694 6991ece5 Leszek Koltunski
695 6983badf Leszek Koltunski
      factory.clear();
696
      factory.createNewFaceTransform(vertices,vertIndexes);
697
      mMesh = factory.createRoundedSolid(vertices, vertIndexes,
698
                                         bands, bandIndexes,
699
                                         corners, cornerIndexes,
700
                                         centers, centerIndexes,
701
                                         numComponents );
702
703
      int numEff = mMesh.getNumEffComponents();
704 6991ece5 Leszek Koltunski
705
      for(int i=0; i<numEff; i++)
706
        {
707
        mMesh.setEffectAssociation(i, 0, i);
708
        }
709
      }
710 42aa970f Leszek Koltunski
711
///////////////////////////////////////////////////////////////////////////////////////////////////
712
713 6991ece5 Leszek Koltunski
    private void openMesh(int resourceID)
714 42aa970f Leszek Koltunski
      {
715 1af8e143 Leszek Koltunski
      Context con = mView.getContext();
716
      Resources res = con.getResources();
717
      InputStream is = res.openRawResource(resourceID);
718
      DataInputStream dos = new DataInputStream(is);
719 7198e5c9 Leszek Koltunski
      mMesh = new MeshFile(dos);
720 1af8e143 Leszek Koltunski
721 6983badf Leszek Koltunski
      int numEff = mMesh.getNumEffComponents();
722 39b925d5 Leszek Koltunski
723
      for(int i=0; i<numEff; i++)
724
        {
725
        mMesh.setEffectAssociation(i, 0, i);
726
        }
727
728 1af8e143 Leszek Koltunski
      try
729
        {
730
        is.close();
731
        }
732
      catch(IOException e)
733
        {
734 48c88f57 Leszek Koltunski
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
735 1af8e143 Leszek Koltunski
        }
736 42aa970f Leszek Koltunski
      }
737 48c88f57 Leszek Koltunski
738 39b925d5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
739
740 6991ece5 Leszek Koltunski
    MeshBase getMesh()
741 39b925d5 Leszek Koltunski
      {
742
      return mMesh;
743
      }
744
745 48c88f57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
746
747
    long getTime()
748
      {
749
      return mTime;
750
      }
751
752
///////////////////////////////////////////////////////////////////////////////////////////////////
753
754
    int getBytes()
755
      {
756 6991ece5 Leszek Koltunski
      if( mMesh instanceof MeshFile )
757
        {
758
        return ((MeshFile)mMesh).getNumBytes();
759
        }
760
761
      return 0;
762 48c88f57 Leszek Koltunski
      }
763
764
///////////////////////////////////////////////////////////////////////////////////////////////////
765
766
    int getVertices()
767
      {
768 7198e5c9 Leszek Koltunski
      return mMesh.getNumVertices();
769
      }
770
771
///////////////////////////////////////////////////////////////////////////////////////////////////
772
773
    int getEndEffIndex(int component)
774
      {
775
      return mMesh.getLastVertexEff(component);
776
      }
777
778
///////////////////////////////////////////////////////////////////////////////////////////////////
779
780
    int getEndTexIndex(int component)
781
      {
782
      return mMesh.getLastVertexTex(component);
783
      }
784
785
///////////////////////////////////////////////////////////////////////////////////////////////////
786
787
    int getEffComponentNum()
788
      {
789 6983badf Leszek Koltunski
      return mMesh.getNumEffComponents();
790 7198e5c9 Leszek Koltunski
      }
791
792
///////////////////////////////////////////////////////////////////////////////////////////////////
793
794
    int getTexComponentNum()
795
      {
796 6983badf Leszek Koltunski
      return mMesh.getNumTexComponents();
797 48c88f57 Leszek Koltunski
      }
798 42aa970f Leszek Koltunski
}