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
|
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
52
|
|
53
|
import java.io.DataInputStream;
|
54
|
import java.io.IOException;
|
55
|
import java.io.InputStream;
|
56
|
|
57
|
import javax.microedition.khronos.egl.EGLConfig;
|
58
|
import javax.microedition.khronos.opengles.GL10;
|
59
|
|
60
|
import static org.distorted.examples.meshfile.MeshFileActivity.MULTIGON;
|
61
|
import static org.distorted.examples.meshfile.MeshFileActivity.POLYGON;
|
62
|
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
|
63
|
import static org.distorted.examples.meshfile.MeshFileActivity.TRIANGLE;
|
64
|
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
69
|
{
|
70
|
private static final float SQ3 = (float)Math.sqrt(3);
|
71
|
private final float DEFAULT_SCALE = 0.3f;
|
72
|
|
73
|
private final GLSurfaceView mView;
|
74
|
private final Resources mResources;
|
75
|
private final DistortedScreen mScreen;
|
76
|
private final DistortedEffects mEffects;
|
77
|
private final Static3D mScale;
|
78
|
|
79
|
private DistortedTexture mTexture;
|
80
|
private MeshBase mMesh;
|
81
|
private long mTime;
|
82
|
private float mCurrentScale;
|
83
|
private boolean mNormals;
|
84
|
|
85
|
Static4D mQuat1, mQuat2;
|
86
|
int mScreenMin;
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
MeshFileRenderer(GLSurfaceView v)
|
91
|
{
|
92
|
mView = v;
|
93
|
mResources = v.getResources();
|
94
|
|
95
|
mScreen = new DistortedScreen();
|
96
|
mScale= new Static3D(1,1,1);
|
97
|
Static3D center=new Static3D(0,0,0);
|
98
|
|
99
|
mCurrentScale = DEFAULT_SCALE;
|
100
|
mNormals = false;
|
101
|
|
102
|
mQuat1 = new Static4D(0,0,0,1);
|
103
|
mQuat2 = new Static4D(0,0,0,1);
|
104
|
|
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
|
VertexEffectDisappear disappear = new VertexEffectDisappear();
|
112
|
disappear.setMeshAssociation(1,-1);
|
113
|
|
114
|
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
|
mEffects.apply( disappear );
|
120
|
|
121
|
mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
122
|
mScreen.showFPS();
|
123
|
}
|
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
|
float factor = mCurrentScale*mScreenMin;
|
138
|
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
|
Effect.enableEffects(EffectType.VERTEX);
|
149
|
DistortedLibrary.setMax(EffectType.VERTEX, 20);
|
150
|
DistortedLibrary.needTransformFeedback();
|
151
|
DistortedLibrary.onSurfaceCreated(this);
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
void flipNormals()
|
177
|
{
|
178
|
mNormals = !mNormals;
|
179
|
if( mMesh!=null ) mMesh.setShowNormals(mNormals);
|
180
|
}
|
181
|
|
182
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
183
|
|
184
|
void open(int resourceID)
|
185
|
{
|
186
|
if( mTexture==null ) mTexture = new DistortedTexture();
|
187
|
mTexture.setTexture( createTexture(resourceID) );
|
188
|
|
189
|
long t1 = System.currentTimeMillis();
|
190
|
|
191
|
if( resourceID==PROCEDURAL )
|
192
|
{
|
193
|
createMesh();
|
194
|
}
|
195
|
else if( resourceID==POLYGON )
|
196
|
{
|
197
|
createPolygon();
|
198
|
}
|
199
|
else if( resourceID==MULTIGON )
|
200
|
{
|
201
|
createMultigon();
|
202
|
}
|
203
|
else if( resourceID==TRIANGLE )
|
204
|
{
|
205
|
createTriangle();
|
206
|
}
|
207
|
else
|
208
|
{
|
209
|
openMesh(resourceID);
|
210
|
}
|
211
|
|
212
|
long t2 = System.currentTimeMillis();
|
213
|
|
214
|
mTime = t2-t1;
|
215
|
|
216
|
mScreen.detachAll();
|
217
|
mScreen.attach(mTexture,mEffects,mMesh);
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
|
222
|
private Bitmap createTexture(int resourceID)
|
223
|
{
|
224
|
TextureFactory factory = TextureFactory.getInstance();
|
225
|
|
226
|
float[] vertices;
|
227
|
int[] colors;
|
228
|
float F = 0.5f;
|
229
|
float E = SQ3/2;
|
230
|
|
231
|
if( resourceID == R.raw.deferredjob || resourceID == R.raw.meshjoin ||
|
232
|
resourceID == PROCEDURAL || resourceID == POLYGON ||
|
233
|
resourceID == MULTIGON || resourceID == TRIANGLE ||
|
234
|
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
|
|
266
|
return null;
|
267
|
}
|
268
|
|
269
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
270
|
|
271
|
private Bitmap createWhiteTexture()
|
272
|
{
|
273
|
int SIZE = 1;
|
274
|
Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
|
275
|
Canvas canvas = new Canvas(bitmap);
|
276
|
|
277
|
Paint paint = new Paint();
|
278
|
paint.setColor(0xffffff55);
|
279
|
paint.setStyle(Paint.Style.FILL);
|
280
|
canvas.drawRect(0, 0, SIZE, SIZE, paint);
|
281
|
|
282
|
return bitmap;
|
283
|
}
|
284
|
|
285
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
305
|
|
306
|
private void createPolygon()
|
307
|
{
|
308
|
float A = 0.5f;
|
309
|
float B = 0.04f;
|
310
|
|
311
|
int extraIndex = 0;
|
312
|
int extraVertices = 0;
|
313
|
float[] vertices = { -A,-A, A,-A, A,A, -A,A };
|
314
|
|
315
|
float C = 2f;
|
316
|
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
|
|
318
|
/*
|
319
|
int numBands = 5;
|
320
|
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
|
*/
|
328
|
mMesh = new MeshPolygon(vertices,bands,extraIndex,extraVertices,0.0f,0.0f);
|
329
|
mMesh.setEffectAssociation(0,0,0);
|
330
|
}
|
331
|
|
332
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
333
|
|
334
|
private float[] gen(float x, float y)
|
335
|
{
|
336
|
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 };
|
337
|
}
|
338
|
|
339
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
340
|
|
341
|
private void createMultigon()
|
342
|
{
|
343
|
float A = 0.5f;
|
344
|
int extraIndex = 0;
|
345
|
int extraVertices = 0;
|
346
|
|
347
|
float[][] vertices = new float[19][];
|
348
|
|
349
|
vertices[ 0] = gen( 0.4f,-0.4f);
|
350
|
vertices[ 1] = gen( 0.2f,-0.4f);
|
351
|
vertices[ 2] = gen( 0.0f,-0.4f);
|
352
|
vertices[ 3] = gen(-0.2f,-0.4f);
|
353
|
vertices[ 4] = gen(-0.4f,-0.4f);
|
354
|
vertices[ 5] = gen(-0.4f,-0.2f);
|
355
|
vertices[ 6] = gen(-0.4f, 0.0f);
|
356
|
vertices[ 7] = gen(-0.4f, 0.2f);
|
357
|
vertices[ 8] = gen(-0.4f, 0.4f);
|
358
|
vertices[ 9] = gen(-0.2f, 0.4f);
|
359
|
vertices[10] = gen( 0.0f, 0.4f);
|
360
|
vertices[11] = gen( 0.2f, 0.4f);
|
361
|
vertices[12] = gen( 0.4f, 0.4f);
|
362
|
vertices[13] = gen( 0.4f, 0.2f);
|
363
|
vertices[14] = gen( 0.4f, 0.0f);
|
364
|
vertices[15] = gen( 0.4f,-0.2f);
|
365
|
vertices[16] = gen( 0.0f,-0.2f);
|
366
|
vertices[17] = gen( 0.0f, 0.0f);
|
367
|
vertices[18] = gen( 0.0f, 0.2f);
|
368
|
|
369
|
float C = 0.5f;
|
370
|
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};
|
371
|
/*
|
372
|
float B = 0.1f;
|
373
|
int numBands = 7;
|
374
|
float[] bands = new float[2*numBands];
|
375
|
|
376
|
for(int i=0; i<numBands; i++)
|
377
|
{
|
378
|
bands[2*i ] = 1 + i/(1.0f-numBands);
|
379
|
bands[2*i+1] = B/(numBands-1)*i;
|
380
|
}
|
381
|
*/
|
382
|
mMesh = new MeshMultigon(vertices,bands,extraIndex,extraVertices);
|
383
|
|
384
|
int numEff = mMesh.getNumEffComponents();
|
385
|
|
386
|
for(int i=0; i<numEff; i++)
|
387
|
{
|
388
|
mMesh.setEffectAssociation(i, 0, i);
|
389
|
}
|
390
|
}
|
391
|
|
392
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
393
|
|
394
|
private float[][] createV()
|
395
|
{
|
396
|
return new float[][]
|
397
|
{
|
398
|
{-0.5f , 1.5f , -0.5f }, //0
|
399
|
{-0.5f , 0.5f , -0.5f },
|
400
|
{-0.5f , 0.5f , 0.5f },
|
401
|
{-0.5f , 1.5f , 0.5f },
|
402
|
{-0.5f , -0.5f , -0.5f },
|
403
|
{-0.5f , -0.5f , 0.5f }, //5
|
404
|
{-0.5f , -1.5f , -0.5f },
|
405
|
{-0.5f , -1.5f , 0.5f },
|
406
|
{ 1.5f , -0.5f , -0.5f },
|
407
|
{ 1.5f , -1.5f , -0.5f },
|
408
|
{ 1.5f , -1.5f , 0.5f }, //10
|
409
|
{ 1.5f , -0.5f , 0.5f },
|
410
|
{ 1.5f , 0.5f , -0.5f },
|
411
|
{ 1.5f , 0.5f , 0.5f },
|
412
|
{ 1.5f , 1.5f , -0.5f },
|
413
|
{ 1.5f , 1.5f , 0.5f }, //15
|
414
|
{-2.5f , 2.5f , -0.5f },
|
415
|
{-2.5f , 1.5f , -0.5f },
|
416
|
{-2.5f , 1.5f , 0.5f },
|
417
|
{-2.5f , 2.5f , 0.5f },
|
418
|
{-2.5f , 0.5f , -0.5f }, //20
|
419
|
{-2.5f , 0.5f , 0.5f },
|
420
|
{-2.5f , -0.5f , -0.5f },
|
421
|
{-2.5f , -0.5f , 0.5f },
|
422
|
{-2.5f , -1.5f , -0.5f },
|
423
|
{-2.5f , -1.5f , 0.5f }, //25
|
424
|
{-2.5f , -2.5f , -0.5f },
|
425
|
{-2.5f , -2.5f , 0.5f },
|
426
|
{ 0.5f , 1.5f , 0.5f },
|
427
|
{ 0.5f , 0.5f , 0.5f },
|
428
|
{ 0.5f , 0.5f , -0.5f }, //30
|
429
|
{ 0.5f , 1.5f , -0.5f },
|
430
|
{ 0.5f , -0.5f , 0.5f },
|
431
|
{ 0.5f , -0.5f , -0.5f },
|
432
|
{ 0.5f , -1.5f , 0.5f },
|
433
|
{ 0.5f , -1.5f , -0.5f }, //35
|
434
|
{ 2.5f , -0.5f , 0.5f },
|
435
|
{ 2.5f , -1.5f , 0.5f },
|
436
|
{ 2.5f , -1.5f , -0.5f },
|
437
|
{ 2.5f , -0.5f , -0.5f },
|
438
|
{ 2.5f , 0.5f , 0.5f }, //40
|
439
|
{ 2.5f , 0.5f , -0.5f },
|
440
|
{ 2.5f , 1.5f , 0.5f },
|
441
|
{ 2.5f , 1.5f , -0.5f },
|
442
|
{ 2.5f , 2.5f , 0.5f },
|
443
|
{ 2.5f , 2.5f , -0.5f }, //45
|
444
|
{ 2.5f , -2.5f , 0.5f },
|
445
|
{ 2.5f , -2.5f , -0.5f },
|
446
|
{-1.5f , 1.5f , 0.5f },
|
447
|
{-1.5f , 0.5f , 0.5f },
|
448
|
{-1.5f , 0.5f , -0.5f }, //50
|
449
|
{-1.5f , 1.5f , -0.5f },
|
450
|
{-1.5f , -0.5f , 0.5f },
|
451
|
{-1.5f , -0.5f , -0.5f },
|
452
|
{-1.5f , -1.5f , 0.5f },
|
453
|
{-1.5f , -1.5f , -0.5f }, //55
|
454
|
{-1.5f , -2.5f , -0.5f },
|
455
|
{-1.5f , -2.5f , 0.5f },
|
456
|
{-0.5f , -2.5f , -0.5f },
|
457
|
{-0.5f , -2.5f , 0.5f },
|
458
|
{ 0.5f , -2.5f , -0.5f }, //60
|
459
|
{ 0.5f , -2.5f , 0.5f },
|
460
|
{ 1.5f , -2.5f , -0.5f },
|
461
|
{ 1.5f , -2.5f , 0.5f },
|
462
|
{ 1.5f , 2.5f , -0.5f },
|
463
|
{ 1.5f , 2.5f , 0.5f }, //65
|
464
|
{ 0.5f , 2.5f , -0.5f },
|
465
|
{ 0.5f , 2.5f , 0.5f },
|
466
|
{-0.5f , 2.5f , -0.5f },
|
467
|
{-0.5f , 2.5f , 0.5f },
|
468
|
{-1.5f , 2.5f , -0.5f }, //70
|
469
|
{-1.5f , 2.5f , 0.5f },
|
470
|
};
|
471
|
}
|
472
|
|
473
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
474
|
|
475
|
private int[][][] createVI()
|
476
|
{
|
477
|
return new int[][][]
|
478
|
{
|
479
|
// { { 0, 1, 2, 3 } , { 1, 4, 5, 2 } , { 4, 6, 7, 5 } },
|
480
|
// { { 8, 9,10,11 } , { 12, 8,11,13 } , { 14,12,13,15 } },
|
481
|
// { { 16,17,18,19 } , { 17,20,21,18 } , { 20,22,23,21 } , { 22,24,25,23 } , { 24,26,27,25 } },
|
482
|
// { { 28,29,30,31 } , { 29,32,33,30 } , { 32,34,35,33 } },
|
483
|
// { { 36,37,38,39 } , { 40,36,39,41 } , { 42,40,41,43 } , { 44,42,43,45 } , { 37,46,47,38 } },
|
484
|
// { { 48,49,50,51 } , { 49,52,53,50 } , { 52,54,55,53 } },
|
485
|
// { { 28,31,14,15 } },
|
486
|
// { { 48,51, 0, 3 } },
|
487
|
// { { 27,26,56,57 } , { 57,56,58,59 } , { 59,58,60,61 } , { 61,60,62,63 } , { 63,62,47,46 } },
|
488
|
// { { 64,65,44,45 } , { 66,67,65,64 } , { 68,69,67,66 } , { 70,71,69,68 } , { 16,19,71,70 } },
|
489
|
// { { 55,54, 7, 6 } },
|
490
|
// { { 35,34,10, 9 } },
|
491
|
{ { 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 } },
|
492
|
{ { 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 } },
|
493
|
};
|
494
|
}
|
495
|
|
496
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
497
|
|
498
|
private void createMesh()
|
499
|
{
|
500
|
float[][] vertices = createV();
|
501
|
int[][][] vertIndices = createVI();
|
502
|
|
503
|
int numFaces = vertIndices.length;
|
504
|
|
505
|
float h = 0.001f;
|
506
|
int angle = 30;
|
507
|
float R = 0.1f;
|
508
|
float S = 0.5f;
|
509
|
int N = 6;
|
510
|
int exI = 0;
|
511
|
int exV = 0;
|
512
|
float[][] bands = { {h,angle,R,S,N,exI,exV} };
|
513
|
|
514
|
int[] bandIndices= new int[numFaces];
|
515
|
|
516
|
ObjectShape shape = new ObjectShape(vertices, vertIndices);
|
517
|
ObjectFaceShape face = new ObjectFaceShape(bands, bandIndices, null);
|
518
|
|
519
|
int[] outer = new int[numFaces];
|
520
|
|
521
|
FactoryCubit factory = FactoryCubit.getInstance();
|
522
|
factory.clear();
|
523
|
factory.createNewFaceTransform(shape,outer);
|
524
|
mMesh = factory.createRoundedSolid(shape,face,null,MESH_NICE,numFaces);
|
525
|
|
526
|
int numEff = mMesh.getNumEffComponents();
|
527
|
for(int i=0; i<numEff; i++) mMesh.setEffectAssociation(i, 0, i);
|
528
|
}
|
529
|
|
530
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
531
|
|
532
|
private void openMesh(int resourceID)
|
533
|
{
|
534
|
Context con = mView.getContext();
|
535
|
Resources res = con.getResources();
|
536
|
InputStream is = res.openRawResource(resourceID);
|
537
|
DataInputStream dos = new DataInputStream(is);
|
538
|
mMesh = new MeshFile(dos);
|
539
|
|
540
|
int numEff = mMesh.getNumEffComponents();
|
541
|
|
542
|
for(int i=0; i<numEff; i++)
|
543
|
{
|
544
|
mMesh.setEffectAssociation(i, 0, i);
|
545
|
}
|
546
|
|
547
|
try
|
548
|
{
|
549
|
is.close();
|
550
|
}
|
551
|
catch(IOException e)
|
552
|
{
|
553
|
android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
|
554
|
}
|
555
|
}
|
556
|
|
557
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
558
|
|
559
|
MeshBase getMesh()
|
560
|
{
|
561
|
return mMesh;
|
562
|
}
|
563
|
|
564
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
565
|
|
566
|
long getTime()
|
567
|
{
|
568
|
return mTime;
|
569
|
}
|
570
|
|
571
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
572
|
|
573
|
int getBytes()
|
574
|
{
|
575
|
if( mMesh instanceof MeshFile )
|
576
|
{
|
577
|
return ((MeshFile)mMesh).getNumBytes();
|
578
|
}
|
579
|
|
580
|
return 0;
|
581
|
}
|
582
|
|
583
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
584
|
|
585
|
int getVertices()
|
586
|
{
|
587
|
return mMesh.getNumVertices();
|
588
|
}
|
589
|
|
590
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
591
|
|
592
|
int getEndEffIndex(int component)
|
593
|
{
|
594
|
return mMesh.getLastVertexEff(component);
|
595
|
}
|
596
|
|
597
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
598
|
|
599
|
int getEndTexIndex(int component)
|
600
|
{
|
601
|
return mMesh.getLastVertexTex(component);
|
602
|
}
|
603
|
|
604
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
605
|
|
606
|
int getEffComponentNum()
|
607
|
{
|
608
|
return mMesh.getNumEffComponents();
|
609
|
}
|
610
|
|
611
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
612
|
|
613
|
int getTexComponentNum()
|
614
|
{
|
615
|
return mMesh.getNumTexComponents();
|
616
|
}
|
617
|
|
618
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
619
|
|
620
|
public void distortedException(Exception ex)
|
621
|
{
|
622
|
android.util.Log.e("MeshFile", ex.getMessage() );
|
623
|
}
|
624
|
|
625
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
626
|
|
627
|
public InputStream localFile(int fileID)
|
628
|
{
|
629
|
return mResources.openRawResource(fileID);
|
630
|
}
|
631
|
|
632
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
633
|
|
634
|
public void logMessage(String message)
|
635
|
{
|
636
|
android.util.Log.e("MeshFile", message );
|
637
|
}
|
638
|
}
|