Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ 0e93d1a3

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 302e40d1 leszek
import org.distorted.library.mesh.MeshBandedTriangle;
40 6991ece5 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
41 1af8e143 Leszek Koltunski
import org.distorted.library.mesh.MeshFile;
42 b2adcd57 Leszek Koltunski
import org.distorted.library.mesh.MeshMultigon;
43 1bb5d3b7 Leszek Koltunski
import org.distorted.library.mesh.MeshPolygon;
44 42aa970f Leszek Koltunski
import org.distorted.library.type.DynamicQuat;
45
import org.distorted.library.type.Static3D;
46
import org.distorted.library.type.Static4D;
47
48 1bb5d3b7 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
49 0dee575b Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
50
import org.distorted.objectlib.helpers.ObjectShape;
51 1bb5d3b7 Leszek Koltunski
52 1af8e143 Leszek Koltunski
import java.io.DataInputStream;
53
import java.io.IOException;
54
import java.io.InputStream;
55
56 42aa970f Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
57
import javax.microedition.khronos.opengles.GL10;
58
59 b2adcd57 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.MULTIGON;
60 1bb5d3b7 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.POLYGON;
61 6991ece5 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
62 302e40d1 leszek
import static org.distorted.examples.meshfile.MeshFileActivity.TRIANGLE;
63 baace8e9 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
64 6991ece5 Leszek Koltunski
65 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67 dc10a48d Leszek Koltunski
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
68 42aa970f Leszek Koltunski
{
69 7edab735 Leszek Koltunski
    private static final float SQ3 = (float)Math.sqrt(3);
70 16b336db Leszek Koltunski
    private final float DEFAULT_SCALE = 0.3f;
71
72 140f2c4e Leszek Koltunski
    private final GLSurfaceView mView;
73 dc10a48d Leszek Koltunski
    private final Resources mResources;
74 140f2c4e Leszek Koltunski
    private final DistortedScreen mScreen;
75
    private final DistortedEffects mEffects;
76
    private final Static3D mScale;
77 dc10a48d Leszek Koltunski
78
    private DistortedTexture mTexture;
79
    private MeshBase mMesh;
80 48c88f57 Leszek Koltunski
    private long mTime;
81 16b336db Leszek Koltunski
    private float mCurrentScale;
82 4d49605b Leszek Koltunski
    private boolean mNormals;
83 42aa970f Leszek Koltunski
84
    Static4D mQuat1, mQuat2;
85
    int mScreenMin;
86
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
89
    MeshFileRenderer(GLSurfaceView v)
90
      {
91
      mView = v;
92 dc10a48d Leszek Koltunski
      mResources = v.getResources();
93
94 42aa970f Leszek Koltunski
      mScreen = new DistortedScreen();
95
      mScale= new Static3D(1,1,1);
96
      Static3D center=new Static3D(0,0,0);
97
98 16b336db Leszek Koltunski
      mCurrentScale = DEFAULT_SCALE;
99 4d49605b Leszek Koltunski
      mNormals = false;
100 16b336db Leszek Koltunski
101 42aa970f Leszek Koltunski
      mQuat1 = new Static4D(0,0,0,1);
102 fe032f52 Leszek Koltunski
      mQuat2 = new Static4D(0,0,0,1);
103 42aa970f Leszek Koltunski
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 39b925d5 Leszek Koltunski
      VertexEffectDisappear disappear = new VertexEffectDisappear();
111
      disappear.setMeshAssociation(1,-1);
112
113 42aa970f Leszek Koltunski
      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 39b925d5 Leszek Koltunski
      mEffects.apply( disappear );
119
120 42aa970f Leszek Koltunski
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
121 48c88f57 Leszek Koltunski
      mScreen.showFPS();
122 42aa970f Leszek Koltunski
      }
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 16b336db Leszek Koltunski
      float factor = mCurrentScale*mScreenMin;
137 42aa970f Leszek Koltunski
      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 a65604a7 Leszek Koltunski
      Effect.enableEffects(EffectType.VERTEX);
148 04a21ed6 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX, 20);
149 ef02f5e0 Leszek Koltunski
      DistortedLibrary.needTransformFeedback();
150 dc10a48d Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(this);
151 42aa970f Leszek Koltunski
      }
152
153 16b336db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 4d49605b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175
    void flipNormals()
176
      {
177
      mNormals = !mNormals;
178
      if( mMesh!=null ) mMesh.setShowNormals(mNormals);
179
      }
180
181 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
182
183 1af8e143 Leszek Koltunski
    void open(int resourceID)
184 42aa970f Leszek Koltunski
      {
185 099d8f8b Leszek Koltunski
      if( mTexture==null ) mTexture = new DistortedTexture();
186 8ac4c0bc Leszek Koltunski
      mTexture.setTexture( createTexture(resourceID) );
187
188 acad428e Leszek Koltunski
      long t1 = System.currentTimeMillis();
189 6991ece5 Leszek Koltunski
190 1bb5d3b7 Leszek Koltunski
      if( resourceID==PROCEDURAL )
191 6991ece5 Leszek Koltunski
        {
192 1bb5d3b7 Leszek Koltunski
        createMesh();
193
        }
194
      else if( resourceID==POLYGON )
195
        {
196
        createPolygon();
197 6991ece5 Leszek Koltunski
        }
198 b2adcd57 Leszek Koltunski
      else if( resourceID==MULTIGON )
199
        {
200
        createMultigon();
201
        }
202 302e40d1 leszek
      else if( resourceID==TRIANGLE )
203
        {
204
        createTriangle();
205
        }
206 6991ece5 Leszek Koltunski
      else
207
        {
208 1bb5d3b7 Leszek Koltunski
        openMesh(resourceID);
209 6991ece5 Leszek Koltunski
        }
210
211 acad428e Leszek Koltunski
      long t2 = System.currentTimeMillis();
212
213 48c88f57 Leszek Koltunski
      mTime = t2-t1;
214 42aa970f Leszek Koltunski
215 71c7624f Leszek Koltunski
      mScreen.detachAll();
216 7198e5c9 Leszek Koltunski
      mScreen.attach(mTexture,mEffects,mMesh);
217 42aa970f Leszek Koltunski
      }
218
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220
221 1af8e143 Leszek Koltunski
    private Bitmap createTexture(int resourceID)
222 42aa970f Leszek Koltunski
      {
223 7edab735 Leszek Koltunski
      TextureFactory factory = TextureFactory.getInstance();
224
225
      float[] vertices;
226
      int[] colors;
227
      float F = 0.5f;
228
      float E = SQ3/2;
229
230 302e40d1 leszek
      if( resourceID == R.raw.deferredjob || resourceID == R.raw.meshjoin    ||
231
          resourceID == PROCEDURAL        || resourceID == POLYGON           ||
232
          resourceID == MULTIGON          || resourceID == TRIANGLE          ||
233 77e66c58 Leszek Koltunski
          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 8ac4c0bc Leszek Koltunski
265 7edab735 Leszek Koltunski
      return null;
266 8ac4c0bc Leszek Koltunski
      }
267
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269
270 7edab735 Leszek Koltunski
    private Bitmap createWhiteTexture()
271 8ac4c0bc Leszek Koltunski
      {
272 7edab735 Leszek Koltunski
      int SIZE = 1;
273 8ac4c0bc Leszek Koltunski
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
274
      Canvas canvas = new Canvas(bitmap);
275
276
      Paint paint = new Paint();
277 36793c52 Leszek Koltunski
      paint.setColor(0xffffff55);
278 1beffb69 Leszek Koltunski
      paint.setStyle(Paint.Style.FILL);
279 7edab735 Leszek Koltunski
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
280 6991ece5 Leszek Koltunski
281 72059460 Leszek Koltunski
      return bitmap;
282 6991ece5 Leszek Koltunski
      }
283
284 302e40d1 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
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 1bb5d3b7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
304
305
    private void createPolygon()
306
      {
307
      float A = 0.5f;
308 46a0999e Leszek Koltunski
      float B = 0.04f;
309 1bb5d3b7 Leszek Koltunski
310 f804fce3 Leszek Koltunski
      int extraIndex    = 0;
311
      int extraVertices = 0;
312 612d4511 leszek
      float[][] vertices = { {-A,-A}, {A,-A}, {A,A}, {-A,A} };
313 46a0999e Leszek Koltunski
314 bb6efcda Leszek Koltunski
      float C = 2f;
315 302e40d1 leszek
      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 46a0999e Leszek Koltunski
/*
317
      int numBands      = 5;
318 1bb5d3b7 Leszek Koltunski
      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 46a0999e Leszek Koltunski
*/
326 662b5afa leszek
      mMesh = new MeshPolygon(vertices,bands,extraIndex,extraVertices,0.0f,0.0f);
327 1bb5d3b7 Leszek Koltunski
      mMesh.setEffectAssociation(0,0,0);
328 b2adcd57 Leszek Koltunski
      }
329
330 fa5dad15 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
331
332 bebaab7b leszek
    private float[][] gen(float x, float y)
333 fa5dad15 leszek
      {
334 bebaab7b leszek
      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 fa5dad15 leszek
      }
336
337 b2adcd57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
338
339
    private void createMultigon()
340
      {
341
      float A = 0.5f;
342 45b6b6b5 Leszek Koltunski
      int extraIndex    = 0;
343
      int extraVertices = 0;
344 b2adcd57 Leszek Koltunski
345 bebaab7b leszek
      float[][][] vertices = new float[19][][];
346 fa5dad15 leszek
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 a39e8df4 leszek
      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 bb6efcda Leszek Koltunski
/*
370
      float B = 0.1f;
371
      int numBands = 7;
372 b2adcd57 Leszek Koltunski
      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 bb6efcda Leszek Koltunski
*/
380
      mMesh = new MeshMultigon(vertices,bands,extraIndex,extraVertices);
381 45b6b6b5 Leszek Koltunski
382
      int numEff = mMesh.getNumEffComponents();
383
384
      for(int i=0; i<numEff; i++)
385
        {
386
        mMesh.setEffectAssociation(i, 0, i);
387
        }
388 1bb5d3b7 Leszek Koltunski
      }
389
390 fa5dad15 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
391
392
    private float[][] createV()
393
      {
394
      return new float[][]
395
              {
396 0e93d1a3 leszek
              {-1.6281155f, -0.2072947f, -3.1770508f },
397
              { 1.2135257f, -1.9635254f, -3.1770515f },
398
              {-0.5427052f, -1.9635254f, -0.33541024f},
399
              {-1.9635254f, -0.7499998f, -1.2135254f },
400
              {-0.75000024f, 1.2135258f, -1.9635254f },
401
              { 1.2135253f,  0.87811553f,-1.4208202f },
402
              {-1.2135255f,  0.4635256f, -0.7499998f },
403
              { 1.2135255f, -1.9635254f, -3.1770515f },
404
              { 2.9697561f, -1.9635254f, -0.33541024f},
405
              { 1.2135255f, -1.9635254f, 0.75f },
406
              { 8.940697E-8f, 1.7881393E-7f, 0.0f },
407
              { 1.2135255f, -0.4635254f, 0.75f },
408
              { 0.0f, 0.0f, 0.0f },
409
              { 1.2135255f, 0.87811553f, -1.4208202f },
410
              { 2.427051f, 0.0f, 0.0f }
411
412 fa5dad15 leszek
              };
413
      }
414
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416
417
    private int[][][] createVI()
418
      {
419
      return new int[][][]
420
              {
421 0e93d1a3 leszek
                {{ 0, 1, 2, 3 }},
422
                {{ 4, 5, 1, 0 }},
423
                {{ 0, 3, 6, 4 }},
424
                {{ 2, 7, 8, 9 }},
425
                {{ 3, 2, 10,6 }, { 2, 9, 11, 12 }},
426
                {{13, 14, 8, 7}},
427
                {{ 6, 10, 5, 4}, { 11, 14, 13, 12}},
428
                {{ 9, 8, 14, 11}}
429 fa5dad15 leszek
              };
430
      }
431
432 6991ece5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
433
434
    private void createMesh()
435
      {
436 fa5dad15 leszek
      float[][] vertices = createV();
437
      int[][][] vertIndices = createVI();
438
439
      int numFaces = vertIndices.length;
440
441
      float h = 0.001f;
442 4d49605b Leszek Koltunski
      int angle = 30;
443 13884c8a Leszek Koltunski
      float R = 0.1f;
444 4d49605b Leszek Koltunski
      float S = 0.5f;
445
      int N   = 6;
446 13884c8a Leszek Koltunski
      int exI = 0;
447
      int exV = 0;
448 fa5dad15 leszek
      float[][] bands  = { {h,angle,R,S,N,exI,exV} };
449
450
      int[] bandIndices= new int[numFaces];
451 d1d5d7e2 Leszek Koltunski
452
      ObjectShape shape = new ObjectShape(vertices, vertIndices);
453 fa5dad15 leszek
      ObjectFaceShape face = new ObjectFaceShape(bands, bandIndices, null);
454 d1d5d7e2 Leszek Koltunski
455
      int[] outer = new int[numFaces];
456 db9903e8 Leszek Koltunski
457 33647db9 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
458 6983badf Leszek Koltunski
      factory.clear();
459 fa96775c Leszek Koltunski
      factory.createNewFaceTransform(shape,outer);
460 fa5dad15 leszek
      mMesh = factory.createRoundedSolid(shape,face,null,MESH_NICE,numFaces);
461 6983badf Leszek Koltunski
462
      int numEff = mMesh.getNumEffComponents();
463 d32fe3d9 Leszek Koltunski
      for(int i=0; i<numEff; i++) mMesh.setEffectAssociation(i, 0, i);
464 6991ece5 Leszek Koltunski
      }
465 42aa970f Leszek Koltunski
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467
468 6991ece5 Leszek Koltunski
    private void openMesh(int resourceID)
469 42aa970f Leszek Koltunski
      {
470 1af8e143 Leszek Koltunski
      Context con = mView.getContext();
471
      Resources res = con.getResources();
472
      InputStream is = res.openRawResource(resourceID);
473
      DataInputStream dos = new DataInputStream(is);
474 7198e5c9 Leszek Koltunski
      mMesh = new MeshFile(dos);
475 1af8e143 Leszek Koltunski
476 6983badf Leszek Koltunski
      int numEff = mMesh.getNumEffComponents();
477 39b925d5 Leszek Koltunski
478
      for(int i=0; i<numEff; i++)
479
        {
480
        mMesh.setEffectAssociation(i, 0, i);
481
        }
482
483 1af8e143 Leszek Koltunski
      try
484
        {
485
        is.close();
486
        }
487
      catch(IOException e)
488
        {
489 48c88f57 Leszek Koltunski
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
490 1af8e143 Leszek Koltunski
        }
491 42aa970f Leszek Koltunski
      }
492 48c88f57 Leszek Koltunski
493 39b925d5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
494
495 6991ece5 Leszek Koltunski
    MeshBase getMesh()
496 39b925d5 Leszek Koltunski
      {
497
      return mMesh;
498
      }
499
500 48c88f57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
501
502
    long getTime()
503
      {
504
      return mTime;
505
      }
506
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508
509
    int getBytes()
510
      {
511 6991ece5 Leszek Koltunski
      if( mMesh instanceof MeshFile )
512
        {
513
        return ((MeshFile)mMesh).getNumBytes();
514
        }
515
516
      return 0;
517 48c88f57 Leszek Koltunski
      }
518
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520
521
    int getVertices()
522
      {
523 7198e5c9 Leszek Koltunski
      return mMesh.getNumVertices();
524
      }
525
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527
528
    int getEndEffIndex(int component)
529
      {
530
      return mMesh.getLastVertexEff(component);
531
      }
532
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534
535
    int getEndTexIndex(int component)
536
      {
537
      return mMesh.getLastVertexTex(component);
538
      }
539
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541
542
    int getEffComponentNum()
543
      {
544 6983badf Leszek Koltunski
      return mMesh.getNumEffComponents();
545 7198e5c9 Leszek Koltunski
      }
546
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548
549
    int getTexComponentNum()
550
      {
551 6983badf Leszek Koltunski
      return mMesh.getNumTexComponents();
552 48c88f57 Leszek Koltunski
      }
553 dc10a48d Leszek Koltunski
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555
556
    public void distortedException(Exception ex)
557
      {
558
      android.util.Log.e("MeshFile", ex.getMessage() );
559
      }
560
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562
563
    public InputStream localFile(int fileID)
564
      {
565
      return mResources.openRawResource(fileID);
566
      }
567
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569
570
    public void logMessage(String message)
571
      {
572
      android.util.Log.e("MeshFile", message );
573
      }
574 42aa970f Leszek Koltunski
}