Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ 13884c8a

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 b2adcd57 Leszek Koltunski
import org.distorted.library.mesh.MeshMultigon;
42 1bb5d3b7 Leszek Koltunski
import org.distorted.library.mesh.MeshPolygon;
43 42aa970f Leszek Koltunski
import org.distorted.library.type.DynamicQuat;
44
import org.distorted.library.type.Static3D;
45
import org.distorted.library.type.Static4D;
46
47 1bb5d3b7 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
48 0dee575b Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
49
import org.distorted.objectlib.helpers.ObjectShape;
50 acb2aaae Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
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 baace8e9 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
63 6991ece5 Leszek Koltunski
64 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66 dc10a48d Leszek Koltunski
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
67 42aa970f Leszek Koltunski
{
68 7edab735 Leszek Koltunski
    private static final float SQ3 = (float)Math.sqrt(3);
69 16b336db Leszek Koltunski
    private final float DEFAULT_SCALE = 0.3f;
70
71 140f2c4e Leszek Koltunski
    private final GLSurfaceView mView;
72 dc10a48d Leszek Koltunski
    private final Resources mResources;
73 140f2c4e Leszek Koltunski
    private final DistortedScreen mScreen;
74
    private final DistortedEffects mEffects;
75
    private final Static3D mScale;
76 dc10a48d Leszek Koltunski
77
    private DistortedTexture mTexture;
78
    private MeshBase mMesh;
79 48c88f57 Leszek Koltunski
    private long mTime;
80 16b336db Leszek Koltunski
    private float mCurrentScale;
81 4d49605b Leszek Koltunski
    private boolean mNormals;
82 42aa970f Leszek Koltunski
83
    Static4D mQuat1, mQuat2;
84
    int mScreenMin;
85
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87
88
    MeshFileRenderer(GLSurfaceView v)
89
      {
90
      mView = v;
91 dc10a48d Leszek Koltunski
      mResources = v.getResources();
92
93 42aa970f Leszek Koltunski
      mScreen = new DistortedScreen();
94
      mScale= new Static3D(1,1,1);
95
      Static3D center=new Static3D(0,0,0);
96
97 16b336db Leszek Koltunski
      mCurrentScale = DEFAULT_SCALE;
98 4d49605b Leszek Koltunski
      mNormals = false;
99 16b336db Leszek Koltunski
100 42aa970f Leszek Koltunski
      mQuat1 = new Static4D(0,0,0,1);
101 fe032f52 Leszek Koltunski
      mQuat2 = new Static4D(0,0,0,1);
102 42aa970f Leszek Koltunski
103
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
104
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
105
106
      quatInt1.add(mQuat1);
107
      quatInt2.add(mQuat2);
108
109 39b925d5 Leszek Koltunski
      VertexEffectDisappear disappear = new VertexEffectDisappear();
110
      disappear.setMeshAssociation(1,-1);
111
112 42aa970f Leszek Koltunski
      mEffects = new DistortedEffects();
113
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
114
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
115
      mEffects.apply( new MatrixEffectScale(mScale));
116
117 39b925d5 Leszek Koltunski
      mEffects.apply( disappear );
118
119 42aa970f Leszek Koltunski
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
120 48c88f57 Leszek Koltunski
      mScreen.showFPS();
121 42aa970f Leszek Koltunski
      }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
   
125
    public void onDrawFrame(GL10 glUnused) 
126
      {
127
      mScreen.render( System.currentTimeMillis() );
128
      }
129
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
    
132
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
133
      {
134
      mScreenMin = Math.min(width, height);
135 16b336db Leszek Koltunski
      float factor = mCurrentScale*mScreenMin;
136 42aa970f Leszek Koltunski
      mScale.set(factor,factor,factor);
137
      mScreen.resize(width, height);
138
      }
139
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
    
142
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
143
      {
144
      if( mTexture==null ) mTexture = new DistortedTexture();
145
146 a65604a7 Leszek Koltunski
      Effect.enableEffects(EffectType.VERTEX);
147 04a21ed6 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX, 20);
148 ef02f5e0 Leszek Koltunski
      DistortedLibrary.needTransformFeedback();
149 dc10a48d Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(this);
150 42aa970f Leszek Koltunski
      }
151
152 16b336db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
153
//   0 ---> 0
154
//  50 ---> DEFAULT_SCALE
155
// 100 ---> 4*DEFAULT_SCALE
156
157
    void setScale(int scale)
158
      {
159
      if( scale<= 50 )
160
        {
161
        mCurrentScale = DEFAULT_SCALE * scale / 50.0f;
162
        }
163
      else
164
        {
165
        mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f);
166
        }
167
168
      float factor = mCurrentScale*mScreenMin;
169
      mScale.set(factor,factor,factor);
170
      }
171
172 4d49605b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174
    void flipNormals()
175
      {
176
      mNormals = !mNormals;
177
      if( mMesh!=null ) mMesh.setShowNormals(mNormals);
178
      }
179
180 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182 1af8e143 Leszek Koltunski
    void open(int resourceID)
183 42aa970f Leszek Koltunski
      {
184 099d8f8b Leszek Koltunski
      if( mTexture==null ) mTexture = new DistortedTexture();
185 8ac4c0bc Leszek Koltunski
      mTexture.setTexture( createTexture(resourceID) );
186
187 acad428e Leszek Koltunski
      long t1 = System.currentTimeMillis();
188 6991ece5 Leszek Koltunski
189 1bb5d3b7 Leszek Koltunski
      if( resourceID==PROCEDURAL )
190 6991ece5 Leszek Koltunski
        {
191 1bb5d3b7 Leszek Koltunski
        createMesh();
192
        }
193
      else if( resourceID==POLYGON )
194
        {
195
        createPolygon();
196 6991ece5 Leszek Koltunski
        }
197 b2adcd57 Leszek Koltunski
      else if( resourceID==MULTIGON )
198
        {
199
        createMultigon();
200
        }
201 6991ece5 Leszek Koltunski
      else
202
        {
203 1bb5d3b7 Leszek Koltunski
        openMesh(resourceID);
204 6991ece5 Leszek Koltunski
        }
205
206 acad428e Leszek Koltunski
      long t2 = System.currentTimeMillis();
207
208 48c88f57 Leszek Koltunski
      mTime = t2-t1;
209 42aa970f Leszek Koltunski
210 71c7624f Leszek Koltunski
      mScreen.detachAll();
211 7198e5c9 Leszek Koltunski
      mScreen.attach(mTexture,mEffects,mMesh);
212 42aa970f Leszek Koltunski
      }
213
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
216 1af8e143 Leszek Koltunski
    private Bitmap createTexture(int resourceID)
217 42aa970f Leszek Koltunski
      {
218 7edab735 Leszek Koltunski
      TextureFactory factory = TextureFactory.getInstance();
219
220
      float[] vertices;
221
      int[] colors;
222
      float F = 0.5f;
223
      float E = SQ3/2;
224
225 77e66c58 Leszek Koltunski
      if( resourceID == R.raw.deferredjob ||
226
          resourceID == R.raw.meshjoin    ||
227
          resourceID == PROCEDURAL        ||
228
          resourceID == POLYGON           ||
229 b2adcd57 Leszek Koltunski
          resourceID == MULTIGON          ||
230 77e66c58 Leszek Koltunski
          resourceID == R.raw.predeform    ) return createWhiteTexture();
231
232
      if( resourceID == R.raw.cube2       ||
233
          resourceID == R.raw.cube3       ||
234
          resourceID == R.raw.cube4       ||
235
          resourceID == R.raw.cube5        )
236
        {
237
        colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
238
        vertices = new float[] { -F,-F, +F,-F, +F,+F, -F,+F};
239
        return factory.createTexture(vertices,colors,0.10f, 0.10f, true);
240
        }
241
      if( resourceID == R.raw.pyra3       ||
242
          resourceID == R.raw.pyra4       ||
243
          resourceID == R.raw.pyra5        )
244
        {
245
        colors = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
246
        vertices = new float[] { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
247
        return factory.createTexture(vertices,colors,0.05f, 0.05f, true);
248
        }
249
      if( resourceID == R.raw.dino )
250
        {
251
        colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
252
        vertices = new float[] { -F,F/3, 0,-2*F/3, +F,F/3 };
253
        return factory.createTexture(vertices,colors,0.05f, 0.03f, true);
254
        }
255
      if( resourceID == R.raw.skewb )
256
        {
257
        colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
258
        vertices = new float[] { -F+F/4,F/4, F/4,-F+F/4, F/4,F/4};
259
        return factory.createTexture(vertices,colors,0.05f, 0.08f, true);
260
        }
261 8ac4c0bc Leszek Koltunski
262 7edab735 Leszek Koltunski
      return null;
263 8ac4c0bc Leszek Koltunski
      }
264
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266
267 7edab735 Leszek Koltunski
    private Bitmap createWhiteTexture()
268 8ac4c0bc Leszek Koltunski
      {
269 7edab735 Leszek Koltunski
      int SIZE = 1;
270 8ac4c0bc Leszek Koltunski
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
271
      Canvas canvas = new Canvas(bitmap);
272
273
      Paint paint = new Paint();
274 36793c52 Leszek Koltunski
      paint.setColor(0xffffff55);
275 1beffb69 Leszek Koltunski
      paint.setStyle(Paint.Style.FILL);
276 7edab735 Leszek Koltunski
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
277 6991ece5 Leszek Koltunski
278 72059460 Leszek Koltunski
      return bitmap;
279 6991ece5 Leszek Koltunski
      }
280
281 1bb5d3b7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
282
283
    private void createPolygon()
284
      {
285
      float A = 0.5f;
286 46a0999e Leszek Koltunski
      float B = 0.04f;
287 1bb5d3b7 Leszek Koltunski
288 f804fce3 Leszek Koltunski
      int extraIndex    = 0;
289
      int extraVertices = 0;
290 1bb5d3b7 Leszek Koltunski
      float[] vertices = new float[] { -A,-A, A,-A, A,A, -A,A };
291 46a0999e Leszek Koltunski
292 bb6efcda Leszek Koltunski
      float C = 2f;
293 46a0999e Leszek Koltunski
      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};
294
295
/*
296
      int numBands      = 5;
297 1bb5d3b7 Leszek Koltunski
      float[] bands = new float[2*numBands];
298
299
      for(int i=0; i<numBands; i++)
300
        {
301
        bands[2*i  ] = 1 + i/(1.0f-numBands);
302
        bands[2*i+1] = B/(numBands-1)*i;
303
        }
304 46a0999e Leszek Koltunski
*/
305 bb6efcda Leszek Koltunski
      boolean[] edgesUp = new boolean[] {true,true,false,false};
306 f804fce3 Leszek Koltunski
      boolean[] vertsUp = new boolean[] {false,false,false,false};
307 1bb5d3b7 Leszek Koltunski
308 bb6efcda Leszek Koltunski
      mMesh = new MeshPolygon(vertices,bands,edgesUp,vertsUp,extraIndex,extraVertices,0.0f,0.0f);
309 1bb5d3b7 Leszek Koltunski
      mMesh.setEffectAssociation(0,0,0);
310 b2adcd57 Leszek Koltunski
      }
311
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313
314
    private void createMultigon()
315
      {
316
      float A = 0.5f;
317 45b6b6b5 Leszek Koltunski
      int extraIndex    = 0;
318
      int extraVertices = 0;
319 b2adcd57 Leszek Koltunski
320 bb6efcda Leszek Koltunski
      float[] v1 = new float[] {  -A,-A,   A,-A,   A,  A,   -A,  A };
321
      float[] v2 = new float[] {   A,-A, 2*A,-A, 2*A,  A,    A,  A };
322
      float[] v3 = new float[] {-3*A,-A,  -A,-A,  -A,  A, -3*A,  A };
323
      float[] v4 = new float[] {  -A, A,   A, A,   A,3*A,   -A,3*A };
324
      float[] v5 = new float[] {-3*A, A,  -A, A,  -A,3*A, -3*A,3*A };
325 b2adcd57 Leszek Koltunski
326 bb6efcda Leszek Koltunski
      float[][] vertices = new float[][] {v1,v2,v3,v4,v5};
327
/*
328 b2adcd57 Leszek Koltunski
      float[] c1 = new float[] { 0,0 };
329
      float[] c2 = new float[] { 1.5f*A,0 };
330 bb6efcda Leszek Koltunski
      float[] c3 = new float[] {-1.5f*A,0 };
331
      float[] c4 = new float[] { 0,1.5f*A };
332
      float[] c5 = new float[] { -1.5f*A,1.5f*A };
333
334
      float[][] centers = new float[][] { c1,c2,c3,c4,c5 };
335
*/
336 f804fce3 Leszek Koltunski
      float C = 1f;
337 b2adcd57 Leszek Koltunski
      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};
338
339 bb6efcda Leszek Koltunski
/*
340
      float B = 0.1f;
341
      int numBands = 7;
342 b2adcd57 Leszek Koltunski
      float[] bands = new float[2*numBands];
343
344
      for(int i=0; i<numBands; i++)
345
        {
346
        bands[2*i  ] = 1 + i/(1.0f-numBands);
347
        bands[2*i+1] = B/(numBands-1)*i;
348
        }
349 bb6efcda Leszek Koltunski
*/
350
      mMesh = new MeshMultigon(vertices,bands,extraIndex,extraVertices);
351 45b6b6b5 Leszek Koltunski
352
      int numEff = mMesh.getNumEffComponents();
353
354
      for(int i=0; i<numEff; i++)
355
        {
356
        mMesh.setEffectAssociation(i, 0, i);
357
        }
358 1bb5d3b7 Leszek Koltunski
      }
359
360 6991ece5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
361
362
    private void createMesh()
363
      {
364 4d49605b Leszek Koltunski
      /*
365 d2f57a83 Leszek Koltunski
      float A = 2.0f;
366
367 d1d5d7e2 Leszek Koltunski
      float[][] vertices =
368
          {
369
              { 0.5f, 0.5f, 0.5f },
370
              { 0.5f, 0.5f,-0.5f },
371
              { 0.5f,-0.5f, 0.5f },
372
              { 0.5f,-0.5f,-0.5f },
373
              {-0.5f, 0.5f, 0.5f },
374
              {-0.5f, 0.5f,-0.5f },
375
              {-0.5f,-0.5f, 0.5f },
376
              {-0.5f,-0.5f,-0.5f },
377
378 d2f57a83 Leszek Koltunski
              { 0.5f,   -A, 0.5f },
379
              { 0.5f,   -A,-0.5f },
380
              {-0.5f,   -A, 0.5f },
381
              {-0.5f,   -A,-0.5f },
382
383
              {   -A, 0.5f, 0.5f },
384
              {   -A, 0.5f,-0.5f },
385
              {   -A,-0.5f, 0.5f },
386
              {   -A,-0.5f,-0.5f },
387 d1d5d7e2 Leszek Koltunski
          };
388
389
      int[][][] vertIndices =
390
          {
391 d2f57a83 Leszek Koltunski
              { { 8, 9, 1, 0} },
392
              { {15,14,12,13} },
393
              { {11,10, 6, 7} },
394
              { {12, 0, 1,13} },
395
              { {11, 9, 8,10} },
396
              { {15, 7, 6,14} },
397
              { {14, 6, 4,12}, { 6, 2, 0, 4}, {10, 8, 2, 6} },
398
              { { 3, 7, 5, 1}, { 9,11, 7, 3}, { 7,15,13, 5} }
399 d1d5d7e2 Leszek Koltunski
          };
400
401 d2f57a83 Leszek Koltunski
      float height = 0.02f;
402 d1d5d7e2 Leszek Koltunski
      int num = 5;
403
      int extraI = 1;
404
      int extraV = 1;
405
406 d2f57a83 Leszek Koltunski
      float[][] bands= { {height,25,0.3f,0.5f,num,extraI,extraV} };
407 d1d5d7e2 Leszek Koltunski
408 d2f57a83 Leszek Koltunski
      int[] bandIndices = {0,0,0,0,0,0,0,0};
409 d1d5d7e2 Leszek Koltunski
      float[] convex = null;
410
411
      float[][] corners= { {0.036f,0.12f} };
412
      float[][] centers= { {0.0f, 0.0f, 0.0f} };
413 d2f57a83 Leszek Koltunski
      int[] ind    = { 0,0,-1,-1,-1,-1,-1,-1, 0,0,0,0,0,0,0,0 };
414 4d49605b Leszek Koltunski
      */
415
      float[][] vertices = { {-1.5f, 0.0f, 0.0f},{ 1.5f, 0.0f, 0.0f},{ 0.0f,-1.5f, 0.0f},{ 0.0f, 0.0f,-1.5f},{0,0,0} };
416
      int[][][] vertIndices = { {{2,1,4},{4,0,2}},{{3,0,4},{4,1,3}},{{2,3,1}},{{3,2,0}} };
417
      float h1 = 0.035f;
418
      float h2 = 0.010f;
419
      int angle = 30;
420 13884c8a Leszek Koltunski
      float R = 0.1f;
421 4d49605b Leszek Koltunski
      float S = 0.5f;
422
      int N   = 6;
423 13884c8a Leszek Koltunski
      int exI = 0;
424
      int exV = 0;
425 4d49605b Leszek Koltunski
      float[][] bands  = { {h1,angle,R,S,N,exI,exV}, {h2,angle,R,S,N,exI,exV} };
426
      int[] bandIndices= { 0,0,1,1 };
427
      float[] convex = null;
428
      float[][] corners   = { {0.07f,0.40f}, {0.05f,0.30f} };
429
      int[] cornerIndices = { 0,0,1,1,-1 };
430
      float[][] centers   = { {0.0f, -0.75f, -0.75f} };
431
      int[] centerIndices = { 0,0,0,0,-1 };
432 d1d5d7e2 Leszek Koltunski
433
      ObjectShape shape = new ObjectShape(vertices, vertIndices);
434
      ObjectFaceShape face = new ObjectFaceShape(bands, bandIndices, convex);
435 4d49605b Leszek Koltunski
      ObjectVertexEffects effects = FactoryCubit.generateVertexEffect(vertices,corners,cornerIndices,centers,centerIndices);
436 d1d5d7e2 Leszek Koltunski
437
      int numFaces = shape.getNumFaces();
438
      int[] outer = new int[numFaces];
439 db9903e8 Leszek Koltunski
440 33647db9 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
441 6983badf Leszek Koltunski
      factory.clear();
442 fa96775c Leszek Koltunski
      factory.createNewFaceTransform(shape,outer);
443 d1d5d7e2 Leszek Koltunski
      mMesh = factory.createRoundedSolid(shape,face,effects,MESH_NICE,numFaces);
444 6983badf Leszek Koltunski
445
      int numEff = mMesh.getNumEffComponents();
446 d32fe3d9 Leszek Koltunski
      for(int i=0; i<numEff; i++) mMesh.setEffectAssociation(i, 0, i);
447 6991ece5 Leszek Koltunski
      }
448 42aa970f Leszek Koltunski
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450
451 6991ece5 Leszek Koltunski
    private void openMesh(int resourceID)
452 42aa970f Leszek Koltunski
      {
453 1af8e143 Leszek Koltunski
      Context con = mView.getContext();
454
      Resources res = con.getResources();
455
      InputStream is = res.openRawResource(resourceID);
456
      DataInputStream dos = new DataInputStream(is);
457 7198e5c9 Leszek Koltunski
      mMesh = new MeshFile(dos);
458 1af8e143 Leszek Koltunski
459 6983badf Leszek Koltunski
      int numEff = mMesh.getNumEffComponents();
460 39b925d5 Leszek Koltunski
461
      for(int i=0; i<numEff; i++)
462
        {
463
        mMesh.setEffectAssociation(i, 0, i);
464
        }
465
466 1af8e143 Leszek Koltunski
      try
467
        {
468
        is.close();
469
        }
470
      catch(IOException e)
471
        {
472 48c88f57 Leszek Koltunski
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
473 1af8e143 Leszek Koltunski
        }
474 42aa970f Leszek Koltunski
      }
475 48c88f57 Leszek Koltunski
476 39b925d5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
477
478 6991ece5 Leszek Koltunski
    MeshBase getMesh()
479 39b925d5 Leszek Koltunski
      {
480
      return mMesh;
481
      }
482
483 48c88f57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
484
485
    long getTime()
486
      {
487
      return mTime;
488
      }
489
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491
492
    int getBytes()
493
      {
494 6991ece5 Leszek Koltunski
      if( mMesh instanceof MeshFile )
495
        {
496
        return ((MeshFile)mMesh).getNumBytes();
497
        }
498
499
      return 0;
500 48c88f57 Leszek Koltunski
      }
501
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503
504
    int getVertices()
505
      {
506 7198e5c9 Leszek Koltunski
      return mMesh.getNumVertices();
507
      }
508
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510
511
    int getEndEffIndex(int component)
512
      {
513
      return mMesh.getLastVertexEff(component);
514
      }
515
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
518
    int getEndTexIndex(int component)
519
      {
520
      return mMesh.getLastVertexTex(component);
521
      }
522
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524
525
    int getEffComponentNum()
526
      {
527 6983badf Leszek Koltunski
      return mMesh.getNumEffComponents();
528 7198e5c9 Leszek Koltunski
      }
529
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531
532
    int getTexComponentNum()
533
      {
534 6983badf Leszek Koltunski
      return mMesh.getNumTexComponents();
535 48c88f57 Leszek Koltunski
      }
536 dc10a48d Leszek Koltunski
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538
539
    public void distortedException(Exception ex)
540
      {
541
      android.util.Log.e("MeshFile", ex.getMessage() );
542
      }
543
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545
546
    public InputStream localFile(int fileID)
547
      {
548
      return mResources.openRawResource(fileID);
549
      }
550
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552
553
    public void logMessage(String message)
554
      {
555
      android.util.Log.e("MeshFile", message );
556
      }
557 42aa970f Leszek Koltunski
}