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.MeshBase;
|
40
|
import org.distorted.library.mesh.MeshFile;
|
41
|
import org.distorted.library.type.DynamicQuat;
|
42
|
import org.distorted.library.type.Static3D;
|
43
|
import org.distorted.library.type.Static4D;
|
44
|
|
45
|
import java.io.DataInputStream;
|
46
|
import java.io.IOException;
|
47
|
import java.io.InputStream;
|
48
|
|
49
|
import javax.microedition.khronos.egl.EGLConfig;
|
50
|
import javax.microedition.khronos.opengles.GL10;
|
51
|
|
52
|
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
|
53
|
|
54
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
57
|
{
|
58
|
private static final float SQ2 = (float)Math.sqrt(2);
|
59
|
private static final float SQ3 = (float)Math.sqrt(3);
|
60
|
private final float DEFAULT_SCALE = 0.3f;
|
61
|
|
62
|
private final GLSurfaceView mView;
|
63
|
private DistortedTexture mTexture;
|
64
|
private final DistortedScreen mScreen;
|
65
|
private final DistortedEffects mEffects;
|
66
|
private final Static3D mScale;
|
67
|
private long mTime;
|
68
|
private float mCurrentScale;
|
69
|
private MeshBase mMesh;
|
70
|
|
71
|
Static4D mQuat1, mQuat2;
|
72
|
int mScreenMin;
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
MeshFileRenderer(GLSurfaceView v)
|
77
|
{
|
78
|
mView = v;
|
79
|
mScreen = new DistortedScreen();
|
80
|
mScale= new Static3D(1,1,1);
|
81
|
Static3D center=new Static3D(0,0,0);
|
82
|
|
83
|
mCurrentScale = DEFAULT_SCALE;
|
84
|
|
85
|
mQuat1 = new Static4D(0,0,0,1);
|
86
|
mQuat2 = new Static4D(0,0,0,1);
|
87
|
|
88
|
DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
|
89
|
DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
|
90
|
|
91
|
quatInt1.add(mQuat1);
|
92
|
quatInt2.add(mQuat2);
|
93
|
|
94
|
VertexEffectDisappear disappear = new VertexEffectDisappear();
|
95
|
disappear.setMeshAssociation(1,-1);
|
96
|
|
97
|
mEffects = new DistortedEffects();
|
98
|
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
|
99
|
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
|
100
|
mEffects.apply( new MatrixEffectScale(mScale));
|
101
|
|
102
|
mEffects.apply( disappear );
|
103
|
|
104
|
mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
105
|
mScreen.showFPS();
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
|
110
|
public void onDrawFrame(GL10 glUnused)
|
111
|
{
|
112
|
mScreen.render( System.currentTimeMillis() );
|
113
|
}
|
114
|
|
115
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116
|
|
117
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
118
|
{
|
119
|
mScreenMin = Math.min(width, height);
|
120
|
float factor = mCurrentScale*mScreenMin;
|
121
|
mScale.set(factor,factor,factor);
|
122
|
mScreen.resize(width, height);
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
|
127
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
128
|
{
|
129
|
if( mTexture==null ) mTexture = new DistortedTexture();
|
130
|
|
131
|
Effect.enableEffects(EffectType.VERTEX);
|
132
|
DistortedLibrary.setMax(EffectType.VERTEX, 20);
|
133
|
DistortedLibrary.needTransformFeedback();
|
134
|
DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
|
139
|
public void distortedException(Exception ex)
|
140
|
{
|
141
|
android.util.Log.e("MeshFile", ex.getMessage() );
|
142
|
}
|
143
|
|
144
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
145
|
// 0 ---> 0
|
146
|
// 50 ---> DEFAULT_SCALE
|
147
|
// 100 ---> 4*DEFAULT_SCALE
|
148
|
|
149
|
void setScale(int scale)
|
150
|
{
|
151
|
if( scale<= 50 )
|
152
|
{
|
153
|
mCurrentScale = DEFAULT_SCALE * scale / 50.0f;
|
154
|
}
|
155
|
else
|
156
|
{
|
157
|
mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f);
|
158
|
}
|
159
|
|
160
|
float factor = mCurrentScale*mScreenMin;
|
161
|
mScale.set(factor,factor,factor);
|
162
|
}
|
163
|
|
164
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165
|
|
166
|
void open(int resourceID)
|
167
|
{
|
168
|
if( mTexture==null ) mTexture = new DistortedTexture();
|
169
|
mTexture.setTexture( createTexture(resourceID) );
|
170
|
|
171
|
long t1 = System.currentTimeMillis();
|
172
|
|
173
|
if( resourceID!=PROCEDURAL )
|
174
|
{
|
175
|
openMesh(resourceID);
|
176
|
}
|
177
|
else
|
178
|
{
|
179
|
createMesh();
|
180
|
}
|
181
|
|
182
|
long t2 = System.currentTimeMillis();
|
183
|
|
184
|
mTime = t2-t1;
|
185
|
|
186
|
mScreen.detachAll();
|
187
|
mScreen.attach(mTexture,mEffects,mMesh);
|
188
|
}
|
189
|
|
190
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
191
|
|
192
|
private Bitmap createTexture(int resourceID)
|
193
|
{
|
194
|
TextureFactory factory = TextureFactory.getInstance();
|
195
|
|
196
|
float[] vertices;
|
197
|
int[] colors;
|
198
|
float F = 0.5f;
|
199
|
float E = SQ3/2;
|
200
|
float G = SQ2/4;
|
201
|
|
202
|
switch(resourceID)
|
203
|
{
|
204
|
case R.raw.deferredjob:
|
205
|
case R.raw.meshjoin :
|
206
|
case PROCEDURAL :
|
207
|
case R.raw.predeform : return createWhiteTexture();
|
208
|
|
209
|
case R.raw.cube2 :
|
210
|
case R.raw.cube3 :
|
211
|
case R.raw.cube4 :
|
212
|
case R.raw.cube5 : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
|
213
|
vertices = new float[] { -F,-F, +F,-F, +F,+F, -F,+F};
|
214
|
return factory.createTexture(vertices,colors,0.10f, 0.10f, true);
|
215
|
case R.raw.pyra3 :
|
216
|
case R.raw.pyra4 :
|
217
|
case R.raw.pyra5 : colors = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
|
218
|
vertices = new float[] { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
|
219
|
return factory.createTexture(vertices,colors,0.05f, 0.05f, true);
|
220
|
|
221
|
case R.raw.dino : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
|
222
|
vertices = new float[] { -F,F/3, 0,-2*F/3, +F,F/3 };
|
223
|
return factory.createTexture(vertices,colors,0.05f, 0.03f, true);
|
224
|
|
225
|
case R.raw.skewb : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
|
226
|
//vertices = new float[] { -G,-G, +G,-G, +G,+G, -G,+G };
|
227
|
|
228
|
vertices = new float[] { -F+F/4,F/4, F/4,-F+F/4, F/4,F/4};
|
229
|
return factory.createTexture(vertices,colors,0.05f, 0.08f, true);
|
230
|
}
|
231
|
|
232
|
return null;
|
233
|
}
|
234
|
|
235
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236
|
|
237
|
private Bitmap createWhiteTexture()
|
238
|
{
|
239
|
int SIZE = 1;
|
240
|
Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
|
241
|
Canvas canvas = new Canvas(bitmap);
|
242
|
|
243
|
Paint paint = new Paint();
|
244
|
paint.setColor(0xffffff55);
|
245
|
paint.setStyle(Paint.Style.FILL);
|
246
|
canvas.drawRect(0, 0, SIZE, SIZE, paint);
|
247
|
|
248
|
return bitmap;
|
249
|
}
|
250
|
|
251
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
252
|
|
253
|
private void createMesh()
|
254
|
{
|
255
|
int mode = 6;
|
256
|
int numComponents = 0;
|
257
|
double[][] vertices = null;
|
258
|
int[][] vertIndexes = null;
|
259
|
float[][] bands = null;
|
260
|
int[] bandIndexes = null;
|
261
|
float[][] corners = null;
|
262
|
int[] cornerIndexes = null;
|
263
|
float[][] centers = null;
|
264
|
int[] centerIndexes = null;
|
265
|
|
266
|
///// CUBE ////////////////////////////////////////////////////////////////////////////////
|
267
|
|
268
|
if( mode==0 )
|
269
|
{
|
270
|
vertices = new double[][]
|
271
|
{
|
272
|
{ 0.5, 0.5, 0.5 },
|
273
|
{ 0.5, 0.5,-0.5 },
|
274
|
{ 0.5,-0.5, 0.5 },
|
275
|
{ 0.5,-0.5,-0.5 },
|
276
|
{-0.5, 0.5, 0.5 },
|
277
|
{-0.5, 0.5,-0.5 },
|
278
|
{-0.5,-0.5, 0.5 },
|
279
|
{-0.5,-0.5,-0.5 },
|
280
|
};
|
281
|
|
282
|
vertIndexes = new int[][]
|
283
|
{
|
284
|
{2,3,1,0}, // counterclockwise!
|
285
|
{7,6,4,5},
|
286
|
{4,0,1,5},
|
287
|
{7,3,2,6},
|
288
|
{6,2,0,4},
|
289
|
{3,7,5,1}
|
290
|
};
|
291
|
|
292
|
bands = new float[][]
|
293
|
{
|
294
|
{0.05f,40,0.5f,0.2f,5, 2,2}
|
295
|
};
|
296
|
|
297
|
bandIndexes = new int[] { 0,0,0,0,0,0 };
|
298
|
|
299
|
corners = new float[][]
|
300
|
{
|
301
|
{ 0.01f, 0.10f }
|
302
|
};
|
303
|
|
304
|
cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
305
|
|
306
|
centers = new float[][]
|
307
|
{
|
308
|
{ 0.0f, 0.0f, 0.0f }
|
309
|
};
|
310
|
|
311
|
centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
312
|
|
313
|
numComponents = 8;
|
314
|
}
|
315
|
|
316
|
///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
|
317
|
|
318
|
else if( mode==1 )
|
319
|
{
|
320
|
vertices = new double[][]
|
321
|
{
|
322
|
{-0.5, SQ2/4, 0.0},
|
323
|
{ 0.5, SQ2/4, 0.0},
|
324
|
{ 0.0,-SQ2/4, 0.5},
|
325
|
{ 0.0,-SQ2/4,-0.5}
|
326
|
};
|
327
|
|
328
|
vertIndexes = new int[][]
|
329
|
{
|
330
|
{2,1,0}, // counterclockwise!
|
331
|
{2,3,1},
|
332
|
{3,2,0},
|
333
|
{3,0,1}
|
334
|
};
|
335
|
|
336
|
bands = new float[][]
|
337
|
{
|
338
|
{0.05f,30,0.6f,0.5f,5, 2,2}
|
339
|
};
|
340
|
|
341
|
bandIndexes = new int[] { 0,0,0,0 };
|
342
|
|
343
|
corners = new float[][]
|
344
|
{
|
345
|
{ 0.02f, 0.10f }
|
346
|
};
|
347
|
|
348
|
cornerIndexes = new int[] { 0,0,0,0 };
|
349
|
|
350
|
centers = new float[][]
|
351
|
{
|
352
|
{ 0.0f, 0.0f, 0.0f }
|
353
|
};
|
354
|
|
355
|
centerIndexes = new int[] { 0,0,0,0 };
|
356
|
|
357
|
numComponents = 4;
|
358
|
}
|
359
|
|
360
|
///// DINO ////////////////////////////////////////////////////////////////////////////////
|
361
|
|
362
|
else if( mode==2 )
|
363
|
{
|
364
|
vertices = new double[][]
|
365
|
{
|
366
|
{-0.5, 0.0, 0.0},
|
367
|
{ 0.5, 0.0, 0.0},
|
368
|
{ 0.0,-0.5, 0.0},
|
369
|
{ 0.0, 0.0,-0.5}
|
370
|
};
|
371
|
|
372
|
vertIndexes = new int[][]
|
373
|
{
|
374
|
{2,1,0}, // counterclockwise!
|
375
|
{2,3,1},
|
376
|
{3,2,0},
|
377
|
{3,0,1}
|
378
|
};
|
379
|
|
380
|
bands = new float[][]
|
381
|
{
|
382
|
{0.028f,30,0.25f,0.1f,7, 2,5},
|
383
|
{0.001f,30,0.25f,0.1f,7, 1,2}
|
384
|
};
|
385
|
|
386
|
bandIndexes = new int[] { 0,1,1,0 };
|
387
|
|
388
|
corners = new float[][]
|
389
|
{
|
390
|
{ 0.02f, 0.04f }
|
391
|
};
|
392
|
|
393
|
cornerIndexes = new int[] { 0,0,0,0 };
|
394
|
|
395
|
centers = new float[][]
|
396
|
{
|
397
|
{ 0.0f,-0.25f,-0.25f }
|
398
|
};
|
399
|
|
400
|
centerIndexes = new int[] { 0,0,0,0 };
|
401
|
|
402
|
numComponents = 4;
|
403
|
}
|
404
|
|
405
|
///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
|
406
|
|
407
|
else if( mode==3 )
|
408
|
{
|
409
|
vertices = new double[][]
|
410
|
{
|
411
|
{ 0.5, 0.0, 0.5},
|
412
|
{ 0.5, 0.0,-0.5},
|
413
|
{-0.5, 0.0,-0.5},
|
414
|
{-0.5, 0.0, 0.5},
|
415
|
{ 0.0, SQ2/2, 0.0},
|
416
|
{ 0.0,-SQ2/2, 0.0},
|
417
|
};
|
418
|
|
419
|
vertIndexes = new int[][]
|
420
|
{
|
421
|
{3,0,4}, // counterclockwise!
|
422
|
{0,1,4},
|
423
|
{1,2,4},
|
424
|
{2,3,4},
|
425
|
{5,0,3},
|
426
|
{5,1,0},
|
427
|
{5,2,1},
|
428
|
{5,3,2}
|
429
|
};
|
430
|
|
431
|
bands = new float[][]
|
432
|
{
|
433
|
{0.05f,17,0.5f,0.2f,5, 2,2}
|
434
|
};
|
435
|
|
436
|
bandIndexes = new int[] { 0,0,0,0,0,0,0,0 };
|
437
|
|
438
|
corners = new float[][]
|
439
|
{
|
440
|
{ 0.03f, 0.12f }
|
441
|
};
|
442
|
|
443
|
cornerIndexes = new int[] { 0,0,0,0,0,0 };
|
444
|
|
445
|
centers = new float[][]
|
446
|
{
|
447
|
{ 0.0f, 0.0f, 0.0f }
|
448
|
};
|
449
|
|
450
|
centerIndexes = new int[] { 0,0,0,0,0,0 };
|
451
|
|
452
|
numComponents = 8;
|
453
|
}
|
454
|
|
455
|
///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
|
456
|
|
457
|
else if( mode==4 )
|
458
|
{
|
459
|
double SQ5 = Math.sqrt(5);
|
460
|
double SIN18= (SQ5-1)/4;
|
461
|
double COS18= 0.25*Math.sqrt(10.0+2.0*SQ5);
|
462
|
double H = 1.0;
|
463
|
double L = 2.0;
|
464
|
double X = H*Math.sqrt((5+SQ5)/10);
|
465
|
double Y = H*Math.sqrt((5-SQ5)/10);
|
466
|
double D = H*SIN18/COS18;
|
467
|
|
468
|
vertices = new double[][]
|
469
|
{
|
470
|
{ 0.0, Y, L/2},
|
471
|
{ X, 0.0, L/2},
|
472
|
{ 0.0, -Y, L/2},
|
473
|
{ -X, 0.0, L/2},
|
474
|
{ 0.0, Y, -L/2 +D},
|
475
|
{ X, 0.0,-L/2 },
|
476
|
{ 0.0, -Y, -L/2-D },
|
477
|
{ -X, 0.0,-L/2 }
|
478
|
};
|
479
|
|
480
|
vertIndexes = new int[][]
|
481
|
{
|
482
|
{3,2,1,0}, // counterclockwise!
|
483
|
{0,1,5,4},
|
484
|
{3,0,4,7},
|
485
|
{2,1,5,6},
|
486
|
{3,2,6,7},
|
487
|
{4,5,6,7}
|
488
|
};
|
489
|
|
490
|
bands = new float[][]
|
491
|
{
|
492
|
{0.04f,13,(float)(L/3),(float)L/8, 5,2,3},
|
493
|
{0.00f, 0,(float)(L/2),(float)L/4, 5,2,3}
|
494
|
};
|
495
|
|
496
|
bandIndexes = new int[] { 1,0,0,1,1,1 };
|
497
|
|
498
|
corners = new float[][]
|
499
|
{
|
500
|
{ 0.04f, 0.12f }
|
501
|
};
|
502
|
|
503
|
cornerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
|
504
|
|
505
|
centers = new float[][]
|
506
|
{
|
507
|
{ 0.0f, 0.0f, 0.0f }
|
508
|
};
|
509
|
|
510
|
centerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
|
511
|
|
512
|
numComponents = 6;
|
513
|
}
|
514
|
|
515
|
///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
|
516
|
|
517
|
else if( mode==5 )
|
518
|
{
|
519
|
int IVY_N = 3;
|
520
|
final float IVY_D = 0.003f;
|
521
|
final double angle = Math.PI/(2*IVY_N);
|
522
|
final double CORR = 1.0 - 2*IVY_D;
|
523
|
|
524
|
vertices = new double[3*IVY_N+7][3];
|
525
|
vertIndexes = new int[6][IVY_N+4];
|
526
|
|
527
|
vertices[0][0] = 0.0;
|
528
|
vertices[0][1] = 0.0;
|
529
|
vertices[0][2] = 0.0;
|
530
|
vertices[1][0] =-1.0;
|
531
|
vertices[1][1] = 0.0;
|
532
|
vertices[1][2] = 0.0;
|
533
|
vertices[2][0] = 0.0;
|
534
|
vertices[2][1] =-1.0;
|
535
|
vertices[2][2] = 0.0;
|
536
|
vertices[3][0] = 0.0;
|
537
|
vertices[3][1] = 0.0;
|
538
|
vertices[3][2] =-1.0;
|
539
|
|
540
|
vertIndexes[0][0] = 2;
|
541
|
vertIndexes[0][1] = 0;
|
542
|
vertIndexes[0][2] = 1;
|
543
|
vertIndexes[3][0] = 2;
|
544
|
vertIndexes[3][1] = 0;
|
545
|
vertIndexes[3][2] = 1;
|
546
|
|
547
|
vertIndexes[1][0] = 3;
|
548
|
vertIndexes[1][1] = 0;
|
549
|
vertIndexes[1][2] = 2;
|
550
|
vertIndexes[4][0] = 3;
|
551
|
vertIndexes[4][1] = 0;
|
552
|
vertIndexes[4][2] = 2;
|
553
|
|
554
|
vertIndexes[2][0] = 1;
|
555
|
vertIndexes[2][1] = 0;
|
556
|
vertIndexes[2][2] = 3;
|
557
|
vertIndexes[5][0] = 1;
|
558
|
vertIndexes[5][1] = 0;
|
559
|
vertIndexes[5][2] = 3;
|
560
|
|
561
|
int N1 = 4;
|
562
|
int N2 = N1 + IVY_N + 1;
|
563
|
int N3 = N2 + IVY_N + 1;
|
564
|
|
565
|
for(int i=0; i<=IVY_N; i++)
|
566
|
{
|
567
|
double cos1 = Math.cos((IVY_N-i)*angle);
|
568
|
double sin1 = Math.sin((IVY_N-i)*angle);
|
569
|
double cos2 = Math.cos(( i)*angle);
|
570
|
double sin2 = Math.sin(( i)*angle);
|
571
|
|
572
|
vertices[N1+i][0] = CORR*(cos1-0.5) - 0.5;
|
573
|
vertices[N1+i][1] = CORR*(sin1-0.5) - 0.5;
|
574
|
vertices[N1+i][2] = 0.0;
|
575
|
|
576
|
vertices[N2+i][0] = 0.0;
|
577
|
vertices[N2+i][1] = CORR*(sin2-0.5) - 0.5;
|
578
|
vertices[N2+i][2] = CORR*(cos2-0.5) - 0.5;
|
579
|
|
580
|
vertices[N3+i][0] = CORR*(cos2-0.5) - 0.5;
|
581
|
vertices[N3+i][1] = 0.0;
|
582
|
vertices[N3+i][2] = CORR*(sin2-0.5) - 0.5;
|
583
|
|
584
|
vertIndexes[0][i+3] = N1 + i;
|
585
|
vertIndexes[1][i+3] = N2 + i;
|
586
|
vertIndexes[2][i+3] = N3 + i;
|
587
|
vertIndexes[3][i+3] = N1 + i;
|
588
|
vertIndexes[4][i+3] = N2 + i;
|
589
|
vertIndexes[5][i+3] = N3 + i;
|
590
|
}
|
591
|
|
592
|
bands = new float[][]
|
593
|
{
|
594
|
{+0.012f,20,0.2f,0.5f,7,1,2},
|
595
|
{-0.100f,20,0.2f,0.0f,2,1,2}
|
596
|
};
|
597
|
|
598
|
bandIndexes = new int[] { 0,0,0,1,1,1 };
|
599
|
|
600
|
corners = new float[][]
|
601
|
{
|
602
|
{ 0.04f, 0.12f }
|
603
|
};
|
604
|
|
605
|
cornerIndexes = new int[3*IVY_N+7];
|
606
|
|
607
|
centers = new float[][]
|
608
|
{
|
609
|
{-0.5f,-0.5f,-0.5f}
|
610
|
};
|
611
|
|
612
|
centerIndexes = new int[3*IVY_N+7];
|
613
|
|
614
|
for(int i=0; i<4; i++)
|
615
|
{
|
616
|
cornerIndexes[i] = 0;
|
617
|
centerIndexes[i] = 0;
|
618
|
}
|
619
|
for(int i=4; i<3*IVY_N+7; i++)
|
620
|
{
|
621
|
cornerIndexes[i] = -1;
|
622
|
centerIndexes[i] = -1;
|
623
|
}
|
624
|
|
625
|
numComponents = 6;
|
626
|
}
|
627
|
|
628
|
///// IVY_FACE ////////////////////////////////////////////////////////////////////////
|
629
|
|
630
|
else if( mode==6 )
|
631
|
{
|
632
|
int IVY_N = 6;
|
633
|
final float IVY_D = 0.003f;
|
634
|
final double angle = Math.PI/(2*IVY_N);
|
635
|
final double CORR = 1.0 - 2*IVY_D;
|
636
|
|
637
|
vertices = new double[2*IVY_N][3];
|
638
|
vertIndexes= new int[2][2*IVY_N];
|
639
|
|
640
|
for(int i=0; i<IVY_N; i++)
|
641
|
{
|
642
|
double cos = Math.cos(i*angle);
|
643
|
double sin = Math.sin(i*angle);
|
644
|
|
645
|
vertices[i ][0] = CORR*(0.5-cos);
|
646
|
vertices[i ][1] = CORR*(0.5-sin);
|
647
|
vertices[i ][2] = 0.0;
|
648
|
vertices[i+IVY_N][0] = CORR*(cos-0.5);
|
649
|
vertices[i+IVY_N][1] = CORR*(sin-0.5);
|
650
|
vertices[i+IVY_N][2] = 0.0;
|
651
|
|
652
|
vertIndexes[0][i ] = i;
|
653
|
vertIndexes[0][i+IVY_N] = i+IVY_N;
|
654
|
vertIndexes[1][i ] = i;
|
655
|
vertIndexes[1][i+IVY_N] = i+IVY_N;
|
656
|
}
|
657
|
|
658
|
bands = new float[][]
|
659
|
{
|
660
|
{+0.012f,20,0.2f,0.5f,7,1,2},
|
661
|
{-0.100f,20,0.2f,0.0f,2,1,2},
|
662
|
};
|
663
|
|
664
|
bandIndexes = new int[] { 0,1 };
|
665
|
|
666
|
corners = new float[][]
|
667
|
{
|
668
|
{0.03f,0.10f}
|
669
|
};
|
670
|
|
671
|
centers = new float[][]
|
672
|
{
|
673
|
{-0.0f,-0.0f,-0.5f}
|
674
|
};
|
675
|
|
676
|
cornerIndexes = new int[2*IVY_N];
|
677
|
centerIndexes = new int[2*IVY_N];
|
678
|
|
679
|
for(int i=0; i<2*IVY_N; i++)
|
680
|
{
|
681
|
cornerIndexes[i] = -1;
|
682
|
centerIndexes[i] = -1;
|
683
|
}
|
684
|
|
685
|
cornerIndexes[0 ] = 0;
|
686
|
cornerIndexes[IVY_N] = 0;
|
687
|
centerIndexes[0 ] = 0;
|
688
|
centerIndexes[IVY_N] = 0;
|
689
|
|
690
|
numComponents = 2;
|
691
|
}
|
692
|
|
693
|
FactoryCubit factory = FactoryCubit.getInstance();
|
694
|
|
695
|
factory.clear();
|
696
|
factory.createNewFaceTransform(vertices,vertIndexes);
|
697
|
mMesh = factory.createRoundedSolid(vertices, vertIndexes,
|
698
|
bands, bandIndexes,
|
699
|
corners, cornerIndexes,
|
700
|
centers, centerIndexes,
|
701
|
numComponents );
|
702
|
|
703
|
int numEff = mMesh.getNumEffComponents();
|
704
|
|
705
|
for(int i=0; i<numEff; i++)
|
706
|
{
|
707
|
mMesh.setEffectAssociation(i, 0, i);
|
708
|
}
|
709
|
}
|
710
|
|
711
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
712
|
|
713
|
private void openMesh(int resourceID)
|
714
|
{
|
715
|
Context con = mView.getContext();
|
716
|
Resources res = con.getResources();
|
717
|
InputStream is = res.openRawResource(resourceID);
|
718
|
DataInputStream dos = new DataInputStream(is);
|
719
|
mMesh = new MeshFile(dos);
|
720
|
|
721
|
int numEff = mMesh.getNumEffComponents();
|
722
|
|
723
|
for(int i=0; i<numEff; i++)
|
724
|
{
|
725
|
mMesh.setEffectAssociation(i, 0, i);
|
726
|
}
|
727
|
|
728
|
try
|
729
|
{
|
730
|
is.close();
|
731
|
}
|
732
|
catch(IOException e)
|
733
|
{
|
734
|
android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
|
735
|
}
|
736
|
}
|
737
|
|
738
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
739
|
|
740
|
MeshBase getMesh()
|
741
|
{
|
742
|
return mMesh;
|
743
|
}
|
744
|
|
745
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
746
|
|
747
|
long getTime()
|
748
|
{
|
749
|
return mTime;
|
750
|
}
|
751
|
|
752
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
753
|
|
754
|
int getBytes()
|
755
|
{
|
756
|
if( mMesh instanceof MeshFile )
|
757
|
{
|
758
|
return ((MeshFile)mMesh).getNumBytes();
|
759
|
}
|
760
|
|
761
|
return 0;
|
762
|
}
|
763
|
|
764
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
765
|
|
766
|
int getVertices()
|
767
|
{
|
768
|
return mMesh.getNumVertices();
|
769
|
}
|
770
|
|
771
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
772
|
|
773
|
int getEndEffIndex(int component)
|
774
|
{
|
775
|
return mMesh.getLastVertexEff(component);
|
776
|
}
|
777
|
|
778
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
779
|
|
780
|
int getEndTexIndex(int component)
|
781
|
{
|
782
|
return mMesh.getLastVertexTex(component);
|
783
|
}
|
784
|
|
785
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
786
|
|
787
|
int getEffComponentNum()
|
788
|
{
|
789
|
return mMesh.getNumEffComponents();
|
790
|
}
|
791
|
|
792
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
793
|
|
794
|
int getTexComponentNum()
|
795
|
{
|
796
|
return mMesh.getNumTexComponents();
|
797
|
}
|
798
|
}
|