Project

General

Profile

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

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

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