Project

General

Profile

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

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

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.MeshBandedTriangle;
40
import org.distorted.library.mesh.MeshBase;
41
import org.distorted.library.mesh.MeshFile;
42
import org.distorted.library.mesh.MeshMultigon;
43
import org.distorted.library.mesh.MeshPolygon;
44
import org.distorted.library.type.DynamicQuat;
45
import org.distorted.library.type.Static3D;
46
import org.distorted.library.type.Static4D;
47

    
48
import org.distorted.objectlib.helpers.FactoryCubit;
49
import org.distorted.objectlib.helpers.ObjectFaceShape;
50
import org.distorted.objectlib.helpers.ObjectShape;
51

    
52
import java.io.DataInputStream;
53
import java.io.IOException;
54
import java.io.InputStream;
55

    
56
import javax.microedition.khronos.egl.EGLConfig;
57
import javax.microedition.khronos.opengles.GL10;
58

    
59
import static org.distorted.examples.meshfile.MeshFileActivity.MULTIGON;
60
import static org.distorted.examples.meshfile.MeshFileActivity.POLYGON;
61
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
62
import static org.distorted.examples.meshfile.MeshFileActivity.TRIANGLE;
63
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
68
{
69
    private static final float SQ3 = (float)Math.sqrt(3);
70
    private final float DEFAULT_SCALE = 0.3f;
71

    
72
    private final GLSurfaceView mView;
73
    private final Resources mResources;
74
    private final DistortedScreen mScreen;
75
    private final DistortedEffects mEffects;
76
    private final Static3D mScale;
77

    
78
    private DistortedTexture mTexture;
79
    private MeshBase mMesh;
80
    private long mTime;
81
    private float mCurrentScale;
82
    private boolean mNormals;
83

    
84
    Static4D mQuat1, mQuat2;
85
    int mScreenMin;
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
    MeshFileRenderer(GLSurfaceView v)
90
      {
91
      mView = v;
92
      mResources = v.getResources();
93

    
94
      mScreen = new DistortedScreen();
95
      mScale= new Static3D(1,1,1);
96
      Static3D center=new Static3D(0,0,0);
97

    
98
      mCurrentScale = DEFAULT_SCALE;
99
      mNormals = false;
100

    
101
      mQuat1 = new Static4D(0,0,0,1);
102
      mQuat2 = new Static4D(0,0,0,1);
103

    
104
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
105
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
106

    
107
      quatInt1.add(mQuat1);
108
      quatInt2.add(mQuat2);
109

    
110
      VertexEffectDisappear disappear = new VertexEffectDisappear();
111
      disappear.setMeshAssociation(1,-1);
112

    
113
      mEffects = new DistortedEffects();
114
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
115
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
116
      mEffects.apply( new MatrixEffectScale(mScale));
117

    
118
      mEffects.apply( disappear );
119

    
120
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
121
      mScreen.showFPS();
122
      }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
   
126
    public void onDrawFrame(GL10 glUnused) 
127
      {
128
      mScreen.render( System.currentTimeMillis() );
129
      }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132
    
133
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
134
      {
135
      mScreenMin = Math.min(width, height);
136
      float factor = mCurrentScale*mScreenMin;
137
      mScale.set(factor,factor,factor);
138
      mScreen.resize(width, height);
139
      }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142
    
143
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
144
      {
145
      if( mTexture==null ) mTexture = new DistortedTexture();
146

    
147
      Effect.enableEffects(EffectType.VERTEX);
148
      DistortedLibrary.setMax(EffectType.VERTEX, 20);
149
      DistortedLibrary.needTransformFeedback();
150
      DistortedLibrary.onSurfaceCreated(this);
151
      }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
//   0 ---> 0
155
//  50 ---> DEFAULT_SCALE
156
// 100 ---> 4*DEFAULT_SCALE
157

    
158
    void setScale(int scale)
159
      {
160
      if( scale<= 50 )
161
        {
162
        mCurrentScale = DEFAULT_SCALE * scale / 50.0f;
163
        }
164
      else
165
        {
166
        mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f);
167
        }
168

    
169
      float factor = mCurrentScale*mScreenMin;
170
      mScale.set(factor,factor,factor);
171
      }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
    void flipNormals()
176
      {
177
      mNormals = !mNormals;
178
      if( mMesh!=null ) mMesh.setShowNormals(mNormals);
179
      }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
    void open(int resourceID)
184
      {
185
      if( mTexture==null ) mTexture = new DistortedTexture();
186
      mTexture.setTexture( createTexture(resourceID) );
187

    
188
      long t1 = System.currentTimeMillis();
189

    
190
      if( resourceID==PROCEDURAL )
191
        {
192
        createMesh();
193
        }
194
      else if( resourceID==POLYGON )
195
        {
196
        createPolygon();
197
        }
198
      else if( resourceID==MULTIGON )
199
        {
200
        createMultigon();
201
        }
202
      else if( resourceID==TRIANGLE )
203
        {
204
        createTriangle();
205
        }
206
      else
207
        {
208
        openMesh(resourceID);
209
        }
210

    
211
      long t2 = System.currentTimeMillis();
212

    
213
      mTime = t2-t1;
214

    
215
      mScreen.detachAll();
216
      mScreen.attach(mTexture,mEffects,mMesh);
217
      }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
    private Bitmap createTexture(int resourceID)
222
      {
223
      TextureFactory factory = TextureFactory.getInstance();
224

    
225
      float[] vertices;
226
      int[] colors;
227
      float F = 0.5f;
228
      float E = SQ3/2;
229

    
230
      if( resourceID == R.raw.deferredjob || resourceID == R.raw.meshjoin    ||
231
          resourceID == PROCEDURAL        || resourceID == POLYGON           ||
232
          resourceID == MULTIGON          || resourceID == TRIANGLE          ||
233
          resourceID == R.raw.predeform    ) return createWhiteTexture();
234

    
235
      if( resourceID == R.raw.cube2       ||
236
          resourceID == R.raw.cube3       ||
237
          resourceID == R.raw.cube4       ||
238
          resourceID == R.raw.cube5        )
239
        {
240
        colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
241
        vertices = new float[] { -F,-F, +F,-F, +F,+F, -F,+F};
242
        return factory.createTexture(vertices,colors,0.10f, 0.10f, true);
243
        }
244
      if( resourceID == R.raw.pyra3       ||
245
          resourceID == R.raw.pyra4       ||
246
          resourceID == R.raw.pyra5        )
247
        {
248
        colors = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
249
        vertices = new float[] { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
250
        return factory.createTexture(vertices,colors,0.05f, 0.05f, true);
251
        }
252
      if( resourceID == R.raw.dino )
253
        {
254
        colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
255
        vertices = new float[] { -F,F/3, 0,-2*F/3, +F,F/3 };
256
        return factory.createTexture(vertices,colors,0.05f, 0.03f, true);
257
        }
258
      if( resourceID == R.raw.skewb )
259
        {
260
        colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
261
        vertices = new float[] { -F+F/4,F/4, F/4,-F+F/4, F/4,F/4};
262
        return factory.createTexture(vertices,colors,0.05f, 0.08f, true);
263
        }
264

    
265
      return null;
266
      }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

    
270
    private Bitmap createWhiteTexture()
271
      {
272
      int SIZE = 1;
273
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
274
      Canvas canvas = new Canvas(bitmap);
275

    
276
      Paint paint = new Paint();
277
      paint.setColor(0xffffff55);
278
      paint.setStyle(Paint.Style.FILL);
279
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
280

    
281
      return bitmap;
282
      }
283

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

    
286
    private void createTriangle()
287
      {
288
      float[] vL = {-1.0f, -0.5f};
289
      float[] vR = { 1.0f, -0.5f};
290
      float[] vT = { 0.0f,  1.0f};
291
      float C = 2f;
292
      float[] bands = { 1.0f, 0.00f*C, /*0.9f, 0.05f*C,*/ 0.8f, 0.06f*C, 0.5f, 0.09f*C, 0.0f, 0.10f*C};
293
      float[] normL = { vL[0]-vT[0], vL[1]-vT[1] };
294
      float[] normR = { vR[0]-vT[0], vR[1]-vT[1] };
295
      int mode = MeshBandedTriangle.MODE_NORMAL;
296
      int extraBands    = 2;
297
      int extraVertices = 1;
298

    
299
      mMesh = new MeshBandedTriangle(vL,vR,vT,bands,normL,normR,mode,extraBands,extraVertices);
300
      mMesh.setEffectAssociation(0,0,0);
301
      }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

    
305
    private void createPolygon()
306
      {
307
      float A = 0.5f;
308
      float B = 0.04f;
309

    
310
      int extraIndex    = 0;
311
      int extraVertices = 0;
312
      float[][] vertices = { {-A,-A}, {A,-A}, {A,A}, {-A,A} };
313

    
314
      float C = 2f;
315
      float[] bands = { 1.0f, 0.00f*C, 0.9f, 0.04f*C,  0.8f, 0.07f*C, 0.5f, 0.09f*C, 0.0f, 0.10f*C};
316
/*
317
      int numBands      = 5;
318
      float[] bands = new float[2*numBands];
319

    
320
      for(int i=0; i<numBands; i++)
321
        {
322
        bands[2*i  ] = 1 + i/(1.0f-numBands);
323
        bands[2*i+1] = B/(numBands-1)*i;
324
        }
325
*/
326
      mMesh = new MeshPolygon(vertices,bands,extraIndex,extraVertices,0.0f,0.0f);
327
      mMesh.setEffectAssociation(0,0,0);
328
      }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

    
332
    private float[][] gen(float x, float y)
333
      {
334
      return new float[][] { {x+0.1f,y-0.1f} , {x-0.1f,y-0.1f} , {x-0.1f,y+0.1f} , {x+0.1f,y+0.1f} };
335
      }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
    private void createMultigon()
340
      {
341
      float A = 0.5f;
342
      int extraIndex    = 0;
343
      int extraVertices = 0;
344

    
345
      float[][][] vertices = new float[19][][];
346

    
347
      vertices[ 0] = gen( 0.4f,-0.4f);
348
      vertices[ 1] = gen( 0.2f,-0.4f);
349
      vertices[ 2] = gen( 0.0f,-0.4f);
350
      vertices[ 3] = gen(-0.2f,-0.4f);
351
      vertices[ 4] = gen(-0.4f,-0.4f);
352
      vertices[ 5] = gen(-0.4f,-0.2f);
353
      vertices[ 6] = gen(-0.4f, 0.0f);
354
      vertices[ 7] = gen(-0.4f, 0.2f);
355
      vertices[ 8] = gen(-0.4f, 0.4f);
356
      vertices[ 9] = gen(-0.2f, 0.4f);
357
      vertices[10] = gen( 0.0f, 0.4f);
358
      vertices[11] = gen( 0.2f, 0.4f);
359
      vertices[12] = gen( 0.4f, 0.4f);
360
      vertices[13] = gen( 0.4f, 0.2f);
361
      vertices[14] = gen( 0.4f, 0.0f);
362
      vertices[15] = gen( 0.4f,-0.2f);
363
      vertices[16] = gen( 0.0f,-0.2f);
364
      vertices[17] = gen( 0.0f, 0.0f);
365
      vertices[18] = gen( 0.0f, 0.2f);
366

    
367
      float C = 0.5f;
368
      float[] bands = new float[] { 1.0f, 0.00f*C, 0.9f, 0.04f*C,  0.8f, 0.07f*C, 0.5f, 0.09f*C, 0.0f, 0.10f*C};
369
/*
370
      float B = 0.1f;
371
      int numBands = 7;
372
      float[] bands = new float[2*numBands];
373

    
374
      for(int i=0; i<numBands; i++)
375
        {
376
        bands[2*i  ] = 1 + i/(1.0f-numBands);
377
        bands[2*i+1] = B/(numBands-1)*i;
378
        }
379
*/
380
      mMesh = new MeshMultigon(vertices,bands,extraIndex,extraVertices);
381

    
382
      int numEff = mMesh.getNumEffComponents();
383

    
384
      for(int i=0; i<numEff; i++)
385
        {
386
        mMesh.setEffectAssociation(i, 0, i);
387
        }
388
      }
389

    
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

    
392
    private float[][] createV()
393
      {
394
      return new float[][]
395
              {
396
                      {-0.5f ,  1.5f , -0.5f },  //0
397
                      {-0.5f ,  0.5f , -0.5f },
398
                      {-0.5f ,  0.5f ,  0.5f },
399
                      {-0.5f ,  1.5f ,  0.5f },
400
                      {-0.5f , -0.5f , -0.5f },
401
                      {-0.5f , -0.5f ,  0.5f },  //5
402
                      {-0.5f , -1.5f , -0.5f },
403
                      {-0.5f , -1.5f ,  0.5f },
404
                      { 1.5f , -0.5f , -0.5f },
405
                      { 1.5f , -1.5f , -0.5f },
406
                      { 1.5f , -1.5f ,  0.5f },  //10
407
                      { 1.5f , -0.5f ,  0.5f },
408
                      { 1.5f ,  0.5f , -0.5f },
409
                      { 1.5f ,  0.5f ,  0.5f },
410
                      { 1.5f ,  1.5f , -0.5f },
411
                      { 1.5f ,  1.5f ,  0.5f },  //15
412
                      {-2.5f ,  2.5f , -0.5f },
413
                      {-2.5f ,  1.5f , -0.5f },
414
                      {-2.5f ,  1.5f ,  0.5f },
415
                      {-2.5f ,  2.5f ,  0.5f },
416
                      {-2.5f ,  0.5f , -0.5f },  //20
417
                      {-2.5f ,  0.5f ,  0.5f },
418
                      {-2.5f , -0.5f , -0.5f },
419
                      {-2.5f , -0.5f ,  0.5f },
420
                      {-2.5f , -1.5f , -0.5f },
421
                      {-2.5f , -1.5f ,  0.5f },  //25
422
                      {-2.5f , -2.5f , -0.5f },
423
                      {-2.5f , -2.5f ,  0.5f },
424
                      { 0.5f ,  1.5f ,  0.5f },
425
                      { 0.5f ,  0.5f ,  0.5f },
426
                      { 0.5f ,  0.5f , -0.5f },  //30
427
                      { 0.5f ,  1.5f , -0.5f },
428
                      { 0.5f , -0.5f ,  0.5f },
429
                      { 0.5f , -0.5f , -0.5f },
430
                      { 0.5f , -1.5f ,  0.5f },
431
                      { 0.5f , -1.5f , -0.5f },  //35
432
                      { 2.5f , -0.5f ,  0.5f },
433
                      { 2.5f , -1.5f ,  0.5f },
434
                      { 2.5f , -1.5f , -0.5f },
435
                      { 2.5f , -0.5f , -0.5f },
436
                      { 2.5f ,  0.5f ,  0.5f },  //40
437
                      { 2.5f ,  0.5f , -0.5f },
438
                      { 2.5f ,  1.5f ,  0.5f },
439
                      { 2.5f ,  1.5f , -0.5f },
440
                      { 2.5f ,  2.5f ,  0.5f },
441
                      { 2.5f ,  2.5f , -0.5f },  //45
442
                      { 2.5f , -2.5f ,  0.5f },
443
                      { 2.5f , -2.5f , -0.5f },
444
                      {-1.5f ,  1.5f ,  0.5f },
445
                      {-1.5f ,  0.5f ,  0.5f },
446
                      {-1.5f ,  0.5f , -0.5f },  //50
447
                      {-1.5f ,  1.5f , -0.5f },
448
                      {-1.5f , -0.5f ,  0.5f },
449
                      {-1.5f , -0.5f , -0.5f },
450
                      {-1.5f , -1.5f ,  0.5f },
451
                      {-1.5f , -1.5f , -0.5f },  //55
452
                      {-1.5f , -2.5f , -0.5f },
453
                      {-1.5f , -2.5f ,  0.5f },
454
                      {-0.5f , -2.5f , -0.5f },
455
                      {-0.5f , -2.5f ,  0.5f },
456
                      { 0.5f , -2.5f , -0.5f },  //60
457
                      { 0.5f , -2.5f ,  0.5f },
458
                      { 1.5f , -2.5f , -0.5f },
459
                      { 1.5f , -2.5f ,  0.5f },
460
                      { 1.5f ,  2.5f , -0.5f },
461
                      { 1.5f ,  2.5f ,  0.5f },  //65
462
                      { 0.5f ,  2.5f , -0.5f },
463
                      { 0.5f ,  2.5f ,  0.5f },
464
                      {-0.5f ,  2.5f , -0.5f },
465
                      {-0.5f ,  2.5f ,  0.5f },
466
                      {-1.5f ,  2.5f , -0.5f },  //70
467
                      {-1.5f ,  2.5f ,  0.5f },
468
              };
469
      }
470

    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472

    
473
    private int[][][] createVI()
474
      {
475
      return new int[][][]
476
              {
477
                    //  { {  0, 1, 2, 3 } , {  1, 4, 5, 2 } , {  4, 6, 7, 5 } },
478
                    //  { {  8, 9,10,11 } , { 12, 8,11,13 } , { 14,12,13,15 } },
479
                    //  { { 16,17,18,19 } , { 17,20,21,18 } , { 20,22,23,21 } , { 22,24,25,23 } , { 24,26,27,25 } },
480
                    //  { { 28,29,30,31 } , { 29,32,33,30 } , { 32,34,35,33 } },
481
                    //  { { 36,37,38,39 } , { 40,36,39,41 } , { 42,40,41,43 } , { 44,42,43,45 } , { 37,46,47,38 } },
482
                    //  { { 48,49,50,51 } , { 49,52,53,50 } , { 52,54,55,53 } },
483
                    //  { { 28,31,14,15 } },
484
                    //  { { 48,51, 0, 3 } },
485
                    //  { { 27,26,56,57 } , { 57,56,58,59 } , { 59,58,60,61 } , { 61,60,62,63 } , { 63,62,47,46 } },
486
                    //  { { 64,65,44,45 } , { 66,67,65,64 } , { 68,69,67,66 } , { 70,71,69,68 } , { 16,19,71,70 } },
487
                    //  { { 55,54, 7, 6 } },
488
                    //  { { 35,34,10, 9 } },
489
                      { { 31,30, 1, 0 } , { 30,33, 4, 1 } , { 33,35, 6, 4 } , { 35,60,58, 6 } , {  6,58,56,55 } , { 55,56,26,24 } , { 53,55,24,22 } , { 50,53,22,20 } , { 51,50,20,17 } , { 70,51,17,16 } , { 68, 0,51,70 } , { 66,31, 0,68 } , { 64,14,31,66 } , { 45,43,14,64 } , { 43,41,12,14 } , { 41,39, 8,12 } , { 39,38, 9, 8 } , { 38,47,62, 9 } , {  9,62,60,35 } },
490
                      { {  3, 2,29,28 } , {  2, 5,32,29 } , {  5, 7,34,32 } , {  7,59,61,34 } , { 54,57,59, 7 } , { 25,27,57,54 } , { 23,25,54,52 } , { 21,23,52,49 } , { 18,21,49,48 } , { 19,18,48,71 } , { 71,48, 3,69 } , { 69, 3,28,67 } , { 67,28,15,65 } , { 65,15,42,44 } , { 15,13,40,42 } , { 13,11,36,40 } , { 11,10,37,36 } , { 10,63,46,37 } , { 34,61,63,10 } },
491
              };
492
      }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
    private void createMesh()
497
      {
498
      float[][] vertices = createV();
499
      int[][][] vertIndices = createVI();
500

    
501
      int numFaces = vertIndices.length;
502

    
503
      float h = 0.001f;
504
      int angle = 30;
505
      float R = 0.1f;
506
      float S = 0.5f;
507
      int N   = 6;
508
      int exI = 0;
509
      int exV = 0;
510
      float[][] bands  = { {h,angle,R,S,N,exI,exV} };
511

    
512
      int[] bandIndices= new int[numFaces];
513

    
514
      ObjectShape shape = new ObjectShape(vertices, vertIndices);
515
      ObjectFaceShape face = new ObjectFaceShape(bands, bandIndices, null);
516

    
517
      int[] outer = new int[numFaces];
518

    
519
      FactoryCubit factory = FactoryCubit.getInstance();
520
      factory.clear();
521
      factory.createNewFaceTransform(shape,outer);
522
      mMesh = factory.createRoundedSolid(shape,face,null,MESH_NICE,numFaces);
523

    
524
      int numEff = mMesh.getNumEffComponents();
525
      for(int i=0; i<numEff; i++) mMesh.setEffectAssociation(i, 0, i);
526
      }
527

    
528
///////////////////////////////////////////////////////////////////////////////////////////////////
529

    
530
    private void openMesh(int resourceID)
531
      {
532
      Context con = mView.getContext();
533
      Resources res = con.getResources();
534
      InputStream is = res.openRawResource(resourceID);
535
      DataInputStream dos = new DataInputStream(is);
536
      mMesh = new MeshFile(dos);
537

    
538
      int numEff = mMesh.getNumEffComponents();
539

    
540
      for(int i=0; i<numEff; i++)
541
        {
542
        mMesh.setEffectAssociation(i, 0, i);
543
        }
544

    
545
      try
546
        {
547
        is.close();
548
        }
549
      catch(IOException e)
550
        {
551
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
552
        }
553
      }
554

    
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556

    
557
    MeshBase getMesh()
558
      {
559
      return mMesh;
560
      }
561

    
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563

    
564
    long getTime()
565
      {
566
      return mTime;
567
      }
568

    
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570

    
571
    int getBytes()
572
      {
573
      if( mMesh instanceof MeshFile )
574
        {
575
        return ((MeshFile)mMesh).getNumBytes();
576
        }
577

    
578
      return 0;
579
      }
580

    
581
///////////////////////////////////////////////////////////////////////////////////////////////////
582

    
583
    int getVertices()
584
      {
585
      return mMesh.getNumVertices();
586
      }
587

    
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589

    
590
    int getEndEffIndex(int component)
591
      {
592
      return mMesh.getLastVertexEff(component);
593
      }
594

    
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596

    
597
    int getEndTexIndex(int component)
598
      {
599
      return mMesh.getLastVertexTex(component);
600
      }
601

    
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603

    
604
    int getEffComponentNum()
605
      {
606
      return mMesh.getNumEffComponents();
607
      }
608

    
609
///////////////////////////////////////////////////////////////////////////////////////////////////
610

    
611
    int getTexComponentNum()
612
      {
613
      return mMesh.getNumTexComponents();
614
      }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617

    
618
    public void distortedException(Exception ex)
619
      {
620
      android.util.Log.e("MeshFile", ex.getMessage() );
621
      }
622

    
623
///////////////////////////////////////////////////////////////////////////////////////////////////
624

    
625
    public InputStream localFile(int fileID)
626
      {
627
      return mResources.openRawResource(fileID);
628
      }
629

    
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631

    
632
    public void logMessage(String message)
633
      {
634
      android.util.Log.e("MeshFile", message );
635
      }
636
}
(2-2/4)