1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube 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
|
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.helpers;
|
21
|
|
22
|
import org.distorted.library.effect.MatrixEffectMove;
|
23
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
24
|
import org.distorted.library.effect.MatrixEffectScale;
|
25
|
import org.distorted.library.effect.VertexEffect;
|
26
|
import org.distorted.library.effect.VertexEffectDeform;
|
27
|
import org.distorted.library.effect.VertexEffectMove;
|
28
|
import org.distorted.library.effect.VertexEffectRotate;
|
29
|
import org.distorted.library.effect.VertexEffectScale;
|
30
|
import org.distorted.library.mesh.MeshBase;
|
31
|
import org.distorted.library.mesh.MeshJoined;
|
32
|
import org.distorted.library.mesh.MeshPolygon;
|
33
|
import org.distorted.library.type.Static1D;
|
34
|
import org.distorted.library.type.Static3D;
|
35
|
import org.distorted.library.type.Static4D;
|
36
|
|
37
|
import java.util.ArrayList;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public class FactoryCubit
|
42
|
{
|
43
|
private static final float SQ2 = (float)Math.sqrt(2);
|
44
|
private static final float SQ3 = (float)Math.sqrt(3);
|
45
|
private static final float SQ5 = (float)Math.sqrt(5);
|
46
|
private static final float SQ6 = (float)Math.sqrt(6);
|
47
|
|
48
|
private static final Static1D RADIUS = new Static1D(1);
|
49
|
private static FactoryCubit mThis;
|
50
|
|
51
|
// IVY
|
52
|
static final float IVY_D = 0.003f;
|
53
|
static final float IVY_C = 0.59f;
|
54
|
static final float IVY_M = 0.35f;
|
55
|
private static final int IVY_N = 8;
|
56
|
|
57
|
// REX
|
58
|
public static final float REX_D = 0.2f;
|
59
|
|
60
|
// KILO / MEGAMINX
|
61
|
public static final float SIN54 = (SQ5+1)/4;
|
62
|
public static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4);
|
63
|
public static final float SIN18 = (SQ5-1)/4;
|
64
|
public static final float COS18 = (float)(0.25f*Math.sqrt(10.0f+2.0f*SQ5));
|
65
|
public static final float COS_HALFD= (float)(Math.sqrt(0.5f-0.1f*SQ5)); // cos(half the dihedral angle)
|
66
|
public static final float SIN_HALFD= (float)(Math.sqrt(0.5f+0.1f*SQ5)); // sin(half the dihedral angle)
|
67
|
public static final float DIHEDRAL1= (float)(Math.acos(-SQ5/5)*180/Math.PI);
|
68
|
public static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90);
|
69
|
public static final float MINX_SC = 0.5f;
|
70
|
|
71
|
|
72
|
private static final double[] mBuffer = new double[3];
|
73
|
private static final double[] mQuat1 = new double[4];
|
74
|
private static final double[] mQuat2 = new double[4];
|
75
|
private static final double[] mQuat3 = new double[4];
|
76
|
private static final double[] mQuat4 = new double[4];
|
77
|
|
78
|
private static class StickerCoords
|
79
|
{
|
80
|
double[] vertices;
|
81
|
}
|
82
|
|
83
|
private static class FaceTransform
|
84
|
{
|
85
|
int sticker;
|
86
|
double vx,vy,vz;
|
87
|
double scale;
|
88
|
double qx,qy,qz,qw;
|
89
|
boolean flip;
|
90
|
}
|
91
|
|
92
|
private static final ArrayList<FaceTransform> mNewFaceTransf = new ArrayList<>();
|
93
|
private static final ArrayList<FaceTransform> mOldFaceTransf = new ArrayList<>();
|
94
|
private static final ArrayList<StickerCoords> mStickerCoords = new ArrayList<>();
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
|
98
|
private FactoryCubit()
|
99
|
{
|
100
|
|
101
|
}
|
102
|
|
103
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104
|
|
105
|
public static FactoryCubit getInstance()
|
106
|
{
|
107
|
if( mThis==null ) mThis = new FactoryCubit();
|
108
|
|
109
|
return mThis;
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
// H - height of the band in the middle
|
114
|
// alpha - angle of the edge [0,90]
|
115
|
// dist - often in a polygon the distance from edge to center is not 1, but something else.
|
116
|
// This is the distance.
|
117
|
// K - where to begin the second, much more flat part of the band. [0,1]
|
118
|
// N - number of bands. N>=3
|
119
|
//
|
120
|
// theory: two distinct parts to the band:
|
121
|
// 1) (0,B) - steep
|
122
|
// 2) (B,1) - flat
|
123
|
//
|
124
|
// In first part, we have y = g(x) ; in second - y = g(f(x)) where
|
125
|
//
|
126
|
// g(x) = sqrt( R^2 - (x-D)^2 ) - R*cos(alpha)
|
127
|
// f(x) = ((D-B)/(1-B)*x + B*(1-D)/(1-B)
|
128
|
// h(x) = R*(sin(alpha) - sin(x))
|
129
|
// R = H/(1-cos(alpha))
|
130
|
// D = H*sin(alpha)
|
131
|
// B = h(K*alpha)
|
132
|
//
|
133
|
// The N points are taken at:
|
134
|
//
|
135
|
// 1) in the second part, there are K2 = (N-3)/3 such points
|
136
|
// 2) in the first - K1 = (N-3) - K2
|
137
|
// 3) also, the 3 points 0,B,1
|
138
|
//
|
139
|
// so we have the sequence A[i] of N points
|
140
|
//
|
141
|
// 0
|
142
|
// h((i+1)*(1-K)*alpha/(K1+1)) (i=0,1,...,K1-1)
|
143
|
// B
|
144
|
// (1-B)*(i+1)/(K2+1) + B (i=0,i,...,K2-1)
|
145
|
// 1
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
private float f(float D, float B, float x)
|
150
|
{
|
151
|
return ((D-B)*x + B*(1-D))/(1-B);
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
|
156
|
private float g(float R, float D, float x, float cosAlpha)
|
157
|
{
|
158
|
float d = x-D;
|
159
|
return (float)(Math.sqrt(R*R-d*d)-R*cosAlpha);
|
160
|
}
|
161
|
|
162
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163
|
|
164
|
private float h(float R, float sinAlpha, float x)
|
165
|
{
|
166
|
return R*(sinAlpha-(float)Math.sin(x));
|
167
|
}
|
168
|
|
169
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170
|
|
171
|
private float[] computeBands(float H, int alpha, float dist, float K, int N)
|
172
|
{
|
173
|
float[] bands = new float[2*N];
|
174
|
|
175
|
bands[0] = 1.0f;
|
176
|
bands[1] = 0.0f;
|
177
|
|
178
|
float beta = (float)Math.atan(dist*Math.tan(Math.PI*alpha/180));
|
179
|
float sinBeta = (float)Math.sin(beta);
|
180
|
float cosBeta = (float)Math.cos(beta);
|
181
|
float R = cosBeta<1.0f ? H/(1.0f-cosBeta) : 0.0f;
|
182
|
float D = R*sinBeta;
|
183
|
float B = h(R,sinBeta,K*beta);
|
184
|
|
185
|
if( D>1.0f )
|
186
|
{
|
187
|
for(int i=1; i<N; i++)
|
188
|
{
|
189
|
bands[2*i ] = (float)(N-1-i)/(N-1);
|
190
|
bands[2*i+1] = H*(1-bands[2*i]);
|
191
|
}
|
192
|
}
|
193
|
else
|
194
|
{
|
195
|
int K2 = (int)((N-3)*K);
|
196
|
int K1 = (N-3)-K2;
|
197
|
|
198
|
for(int i=0; i<=K1; i++)
|
199
|
{
|
200
|
float angle = K*beta + (1-K)*beta*(K1-i)/(K1+1);
|
201
|
float x = h(R,sinBeta,angle);
|
202
|
bands[2*i+2] = 1.0f - x;
|
203
|
bands[2*i+3] = g(R,D,x,cosBeta);
|
204
|
}
|
205
|
|
206
|
for(int i=0; i<=K2; i++)
|
207
|
{
|
208
|
float x = (1-B)*(i+1)/(K2+1) + B;
|
209
|
bands[2*K1+2 + 2*i+2] = 1.0f - x;
|
210
|
bands[2*K1+2 + 2*i+3] = g(R,D,f(D,B,x),cosBeta);
|
211
|
}
|
212
|
}
|
213
|
|
214
|
bands[2*N-2] = 0.0f;
|
215
|
bands[2*N-1] = H;
|
216
|
|
217
|
return bands;
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
|
222
|
private void roundCorners(MeshBase mesh, Static3D center, Static3D[] vertices, float strength, float regionRadius)
|
223
|
{
|
224
|
Static4D reg= new Static4D(0,0,0,regionRadius);
|
225
|
|
226
|
float centX = center.get0();
|
227
|
float centY = center.get1();
|
228
|
float centZ = center.get2();
|
229
|
|
230
|
for (Static3D vertex : vertices)
|
231
|
{
|
232
|
float x = strength*(centX - vertex.get0());
|
233
|
float y = strength*(centY - vertex.get1());
|
234
|
float z = strength*(centZ - vertex.get2());
|
235
|
|
236
|
VertexEffect effect = new VertexEffectDeform(new Static3D(x,y,z), RADIUS, vertex, reg);
|
237
|
mesh.apply(effect);
|
238
|
}
|
239
|
}
|
240
|
|
241
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
242
|
|
243
|
MeshBase createFacesHelicopterCorner()
|
244
|
{
|
245
|
MeshBase[] meshes = new MeshBase[6];
|
246
|
|
247
|
float E = 0.5f;
|
248
|
float F = SQ2/4;
|
249
|
float G = 1.0f/12;
|
250
|
float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
|
251
|
float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7);
|
252
|
|
253
|
meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
|
254
|
meshes[0].setEffectAssociation(0,1,0);
|
255
|
meshes[1] = meshes[0].copy(true);
|
256
|
meshes[1].setEffectAssociation(0,2,0);
|
257
|
meshes[2] = meshes[0].copy(true);
|
258
|
meshes[2].setEffectAssociation(0,4,0);
|
259
|
|
260
|
float[] vertices1 = { -F,-G, 0,-G, +F,-G, 0,2*G };
|
261
|
float[] bands1 = computeBands(0.00f,0,0,0.0f,3);
|
262
|
meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
|
263
|
meshes[3].setEffectAssociation(0,8,0);
|
264
|
meshes[4] = meshes[3].copy(true);
|
265
|
meshes[4].setEffectAssociation(0,16,0);
|
266
|
meshes[5] = meshes[3].copy(true);
|
267
|
meshes[5].setEffectAssociation(0,32,0);
|
268
|
|
269
|
return new MeshJoined(meshes);
|
270
|
}
|
271
|
|
272
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
273
|
|
274
|
MeshBase createFacesHelicopterFace()
|
275
|
{
|
276
|
MeshBase[] meshes = new MeshBase[4];
|
277
|
|
278
|
float E = 0.5f;
|
279
|
float F = SQ2/4;
|
280
|
float G = 1.0f/12;
|
281
|
float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
|
282
|
float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7);
|
283
|
|
284
|
meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
|
285
|
meshes[0].setEffectAssociation(0,1,0);
|
286
|
|
287
|
float[] vertices1 = { -F,-G, +F,-G, 0,2*G};
|
288
|
float[] bands1 = computeBands(0.01f,45,F,0.0f,3);
|
289
|
|
290
|
meshes[1] = new MeshPolygon(vertices1, bands1, 1, 3);
|
291
|
meshes[1].setEffectAssociation(0,2,0);
|
292
|
|
293
|
float[] vertices2 = { -E/2,-F/3, +E/2,-F/3, 0,2*F/3};
|
294
|
|
295
|
meshes[2] = new MeshPolygon(vertices2, bands1, 1, 3);
|
296
|
meshes[2].setEffectAssociation(0,4,0);
|
297
|
meshes[3] = meshes[2].copy(true);
|
298
|
meshes[3].setEffectAssociation(0,8,0);
|
299
|
|
300
|
return new MeshJoined(meshes);
|
301
|
}
|
302
|
|
303
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
304
|
|
305
|
MeshBase createFacesRediEdge()
|
306
|
{
|
307
|
MeshBase[] meshes = new MeshPolygon[6];
|
308
|
|
309
|
float F = 0.25f;
|
310
|
float[] vertices0 = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F };
|
311
|
float[] bands0 = computeBands(0.038f,35,F,0.7f,7);
|
312
|
|
313
|
meshes[0] = new MeshPolygon(vertices0, bands0, 2, 2);
|
314
|
meshes[0].setEffectAssociation(0,1,0);
|
315
|
meshes[1] = meshes[0].copy(true);
|
316
|
meshes[1].setEffectAssociation(0,2,0);
|
317
|
|
318
|
float[] bands1 = computeBands(0.02f,35,F/2,0.2f,3);
|
319
|
float[] vertices1 = { -F/2, +F/2, -F/2, -1.5f*F, 1.5f*F, +F/2 };
|
320
|
|
321
|
meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
|
322
|
meshes[2].setEffectAssociation(0,4,0);
|
323
|
meshes[3] = meshes[2].copy(true);
|
324
|
meshes[3].setEffectAssociation(0,8,0);
|
325
|
|
326
|
float X = 0.25f*SQ2;
|
327
|
float Y = SQ6/16;
|
328
|
float[] vertices2 = { -X, Y, -1.5f*X, -Y, +1.5f*X, -Y, +X, Y };
|
329
|
|
330
|
meshes[4] = new MeshPolygon(vertices2, bands1, 1, 1);
|
331
|
meshes[4].setEffectAssociation(0,16,0);
|
332
|
meshes[5] = meshes[4].copy(true);
|
333
|
meshes[5].setEffectAssociation(0,32,0);
|
334
|
|
335
|
return new MeshJoined(meshes);
|
336
|
}
|
337
|
|
338
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
339
|
|
340
|
MeshBase createFacesRediCorner()
|
341
|
{
|
342
|
MeshBase[] meshes = new MeshBase[6];
|
343
|
|
344
|
float E = 0.5f;
|
345
|
float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
|
346
|
float[] bands0 = computeBands(0.06f,35,E,0.7f,6);
|
347
|
|
348
|
meshes[0] = new MeshPolygon(vertices0,bands0,2,2);
|
349
|
meshes[0].setEffectAssociation(0,1,0);
|
350
|
meshes[1] = meshes[0].copy(true);
|
351
|
meshes[1].setEffectAssociation(0,2,0);
|
352
|
meshes[2] = meshes[0].copy(true);
|
353
|
meshes[2].setEffectAssociation(0,4,0);
|
354
|
|
355
|
float F = 0.5f;
|
356
|
float X = 0.5f;
|
357
|
float G = 0.72f;
|
358
|
float[] vertices1 = { -E,+F, -E+X,0, -E,-F, -E*G,-F, +E*G,-F, +E,-F, +E-X,0, +E,+F, +E*G,+F, -E*G,+F };
|
359
|
float[] bands1 = computeBands(0.0f,0,1.0f,0.0f,2);
|
360
|
|
361
|
meshes[3] = new MeshPolygon(vertices1,bands1,0,0);
|
362
|
meshes[3].setEffectAssociation(0,8,0);
|
363
|
meshes[4] = meshes[3].copy(true);
|
364
|
meshes[4].setEffectAssociation(0,16,0);
|
365
|
meshes[5] = meshes[3].copy(true);
|
366
|
meshes[5].setEffectAssociation(0,32,0);
|
367
|
|
368
|
return new MeshJoined(meshes);
|
369
|
}
|
370
|
|
371
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
372
|
|
373
|
MeshBase createFacesIvyCorner()
|
374
|
{
|
375
|
MeshBase[] meshes = new MeshBase[6];
|
376
|
|
377
|
final float angle = (float)Math.PI/(2*IVY_N);
|
378
|
final float CORR = 1.0f - 2*IVY_D;
|
379
|
final float DIST = -0.5f*CORR + IVY_D;
|
380
|
float[] vertices = new float[2*(IVY_N+1)+6];
|
381
|
|
382
|
vertices[0] = (0.5f-IVY_M) * IVY_C;
|
383
|
vertices[1] = (DIST-IVY_M) * IVY_C;
|
384
|
vertices[2] = (0.5f-IVY_M) * IVY_C;
|
385
|
vertices[3] = (0.5f-IVY_M) * IVY_C;
|
386
|
vertices[4] = (DIST-IVY_M) * IVY_C;
|
387
|
vertices[5] = (0.5f-IVY_M) * IVY_C;
|
388
|
|
389
|
for(int i=0; i<=IVY_N; i++)
|
390
|
{
|
391
|
float ang = (IVY_N-i)*angle;
|
392
|
float sin = (float)Math.sin(ang);
|
393
|
float cos = (float)Math.cos(ang);
|
394
|
|
395
|
vertices[2*i+6] = (CORR*(cos-0.5f)-IVY_M)*IVY_C;
|
396
|
vertices[2*i+7] = (CORR*(sin-0.5f)-IVY_M)*IVY_C;
|
397
|
}
|
398
|
|
399
|
float[] bands0 = computeBands(+0.012f,20,0.2f,0.5f,7);
|
400
|
float[] bands1 = computeBands(-0.100f,20,0.2f,0.0f,2);
|
401
|
|
402
|
meshes[0] = new MeshPolygon(vertices,bands0,1,2);
|
403
|
meshes[0].setEffectAssociation(0,1,0);
|
404
|
meshes[1] = meshes[0].copy(true);
|
405
|
meshes[1].setEffectAssociation(0,2,0);
|
406
|
meshes[2] = meshes[0].copy(true);
|
407
|
meshes[2].setEffectAssociation(0,4,0);
|
408
|
meshes[3] = new MeshPolygon(vertices,bands1,1,2);
|
409
|
meshes[3].setEffectAssociation(0,8,0);
|
410
|
meshes[4] = meshes[3].copy(true);
|
411
|
meshes[4].setEffectAssociation(0,16,0);
|
412
|
meshes[5] = meshes[3].copy(true);
|
413
|
meshes[5].setEffectAssociation(0,32,0);
|
414
|
|
415
|
return new MeshJoined(meshes);
|
416
|
}
|
417
|
|
418
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
419
|
|
420
|
MeshBase createFacesIvyFace()
|
421
|
{
|
422
|
MeshBase[] meshes = new MeshBase[2];
|
423
|
|
424
|
final float angle = (float)Math.PI/(2*IVY_N);
|
425
|
final float CORR = 1.0f - 2*IVY_D;
|
426
|
float[] vertices = new float[4*IVY_N];
|
427
|
|
428
|
for(int i=0; i<IVY_N; i++)
|
429
|
{
|
430
|
float sin = (float)Math.sin(i*angle);
|
431
|
float cos = (float)Math.cos(i*angle);
|
432
|
|
433
|
vertices[2*i ] = CORR*(0.5f-cos);
|
434
|
vertices[2*i+1 ] = CORR*(0.5f-sin);
|
435
|
vertices[2*i +2*IVY_N] = CORR*(cos-0.5f);
|
436
|
vertices[2*i+1+2*IVY_N] = CORR*(sin-0.5f);
|
437
|
}
|
438
|
|
439
|
float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
|
440
|
float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
|
441
|
|
442
|
meshes[0] = new MeshPolygon(vertices,bands0,0,0);
|
443
|
meshes[0].setEffectAssociation(0,1,0);
|
444
|
meshes[1] = new MeshPolygon(vertices,bands1,0,0);
|
445
|
meshes[1].setEffectAssociation(0,2,0);
|
446
|
|
447
|
return new MeshJoined(meshes);
|
448
|
}
|
449
|
|
450
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
451
|
|
452
|
MeshBase createFacesRexCorner()
|
453
|
{
|
454
|
MeshBase[] meshes = new MeshBase[2];
|
455
|
|
456
|
float F = REX_D*SQ2;
|
457
|
float G = (1-REX_D)*SQ2/2;
|
458
|
float H = 0.1f;
|
459
|
float J = +2*G/3 - H*G;
|
460
|
|
461
|
float[] vertices = { -F/2, -G/3, +F/2, -G/3, H*F/2, J, -H*F/2, J};
|
462
|
|
463
|
float[] bands0 = computeBands(+0.016f,10,G/3,0.5f,5);
|
464
|
float[] bands1 = computeBands(-0.230f,45,G/3,0.0f,2);
|
465
|
|
466
|
meshes[0] = new MeshPolygon(vertices,bands0,1,1);
|
467
|
meshes[0].setEffectAssociation(0,1,0);
|
468
|
meshes[1] = new MeshPolygon(vertices,bands1,0,0);
|
469
|
meshes[1].setEffectAssociation(0,2,0);
|
470
|
|
471
|
return new MeshJoined(meshes);
|
472
|
}
|
473
|
|
474
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
475
|
|
476
|
MeshBase createFacesRexFace()
|
477
|
{
|
478
|
MeshBase[] meshes = new MeshBase[2];
|
479
|
|
480
|
float[] vertices = { -REX_D,0.0f, 0.0f, -REX_D, +REX_D, 0.0f, 0.0f, +REX_D};
|
481
|
|
482
|
float[] bands0 = computeBands(0.016f,10,REX_D/2,0.5f,5);
|
483
|
float[] bands1 = computeBands(0.000f,45,REX_D/2,0.0f,2);
|
484
|
|
485
|
meshes[0] = new MeshPolygon(vertices,bands0,0,0);
|
486
|
meshes[0].setEffectAssociation(0,1,0);
|
487
|
meshes[1] = new MeshPolygon(vertices,bands1,0,0);
|
488
|
meshes[1].setEffectAssociation(0,2,0);
|
489
|
|
490
|
return new MeshJoined(meshes);
|
491
|
}
|
492
|
|
493
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
494
|
|
495
|
MeshBase createFacesRexEdge()
|
496
|
{
|
497
|
MeshBase[] meshes = new MeshPolygon[6];
|
498
|
|
499
|
float E = 0.5f - REX_D;
|
500
|
float F = 0.5f;
|
501
|
float[] vertices0 = { -F,E/3, 0,-2*E/3, +F,E/3 };
|
502
|
float[] bands0 = computeBands(0.03f,27,F/3,0.8f,5);
|
503
|
|
504
|
meshes[0] = new MeshPolygon(vertices0, bands0, 2, 3);
|
505
|
meshes[0].setEffectAssociation(0,1,0);
|
506
|
meshes[1] = meshes[0].copy(true);
|
507
|
meshes[1].setEffectAssociation(0,2,0);
|
508
|
|
509
|
float G = (float)Math.sqrt(E*E+F*F);
|
510
|
float[] vertices1 = { -2*G/3, -E/3, G/3, -E/3, G/3, 2*E/3 };
|
511
|
float[] bands1 = computeBands(0.00f,45,G/3,0.2f,3);
|
512
|
|
513
|
meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
|
514
|
meshes[2].setEffectAssociation(0,4,0);
|
515
|
meshes[3] = meshes[2].copy(true);
|
516
|
meshes[3].setEffectAssociation(0,8,0);
|
517
|
meshes[4] = meshes[2].copy(true);
|
518
|
meshes[4].setEffectAssociation(0,16,0);
|
519
|
meshes[5] = meshes[2].copy(true);
|
520
|
meshes[5].setEffectAssociation(0,32,0);
|
521
|
|
522
|
return new MeshJoined(meshes);
|
523
|
}
|
524
|
|
525
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
526
|
|
527
|
MeshBase createFacesKilominxCenter()
|
528
|
{
|
529
|
MeshBase[] meshes = new MeshPolygon[6];
|
530
|
|
531
|
float X1= 0.5f*SIN54;
|
532
|
float Y1= 0.5f*SIN_HALFD;
|
533
|
float Y2= Y1 - 0.5f*COS54;
|
534
|
float H = 0.5f* SIN54 /COS54 ;
|
535
|
float X2= MINX_SC*H* SIN_HALFD;
|
536
|
float Y3= MINX_SC*H/(2*COS_HALFD);
|
537
|
float Y4= MINX_SC*H*(1/(2*COS_HALFD) - COS_HALFD);
|
538
|
|
539
|
float[] vertices0 = { -X1, Y2, 0, -Y1, X1, Y2, 0, Y1 };
|
540
|
float[] bands0 = computeBands(0.04f,17,0.3f,0.2f,5);
|
541
|
float[] vertices1 = { -X2, Y4, 0, -Y3, X2, Y4, 0, Y3 };
|
542
|
float[] bands1 = computeBands(0.00f, 0,0.25f,0.5f,2);
|
543
|
|
544
|
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
|
545
|
meshes[0].setEffectAssociation(0, 1,0);
|
546
|
meshes[1] = meshes[0].copy(true);
|
547
|
meshes[1].setEffectAssociation(0, 2,0);
|
548
|
meshes[2] = meshes[0].copy(true);
|
549
|
meshes[2].setEffectAssociation(0, 4,0);
|
550
|
meshes[3] = new MeshPolygon(vertices1, bands1, 0, 0);
|
551
|
meshes[3].setEffectAssociation(0, 8,0);
|
552
|
meshes[4] = meshes[3].copy(true);
|
553
|
meshes[4].setEffectAssociation(0,16,0);
|
554
|
meshes[5] = meshes[3].copy(true);
|
555
|
meshes[5].setEffectAssociation(0,32,0);
|
556
|
|
557
|
return new MeshJoined(meshes);
|
558
|
}
|
559
|
|
560
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
561
|
|
562
|
MeshBase createFacesMinxCorner(int numLayers)
|
563
|
{
|
564
|
MeshBase[] meshes = new MeshPolygon[6];
|
565
|
|
566
|
float Y = COS54/(2*SIN54);
|
567
|
|
568
|
float[] vertices0 = { -0.5f, 0.0f, 0.0f, -Y, 0.5f, 0.0f, 0.0f, Y };
|
569
|
|
570
|
int numBands0 = numLayers==3 ? 5 : 3;
|
571
|
int numBands1 = numLayers==3 ? 2 : 2;
|
572
|
float h = numLayers==3 ? 0.04f : 0.03f;
|
573
|
int e = numLayers==3 ? 4 : 1;
|
574
|
|
575
|
float[] bands0 = computeBands(h ,34,0.3f,0.2f, numBands0);
|
576
|
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f, numBands1);
|
577
|
|
578
|
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
|
579
|
meshes[0].setEffectAssociation(0, 1,0);
|
580
|
meshes[1] = meshes[0].copy(true);
|
581
|
meshes[1].setEffectAssociation(0, 2,0);
|
582
|
meshes[2] = meshes[0].copy(true);
|
583
|
meshes[2].setEffectAssociation(0, 4,0);
|
584
|
meshes[3] = new MeshPolygon(vertices0, bands1, 1, e);
|
585
|
meshes[3].setEffectAssociation(0, 8,0);
|
586
|
meshes[4] = meshes[3].copy(true);
|
587
|
meshes[4].setEffectAssociation(0,16,0);
|
588
|
meshes[5] = meshes[3].copy(true);
|
589
|
meshes[5].setEffectAssociation(0,32,0);
|
590
|
|
591
|
return new MeshJoined(meshes);
|
592
|
}
|
593
|
|
594
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
595
|
|
596
|
MeshBase createFacesKilominxEdge(int numLayers, float width, float height)
|
597
|
{
|
598
|
MeshBase[] meshes = new MeshPolygon[6];
|
599
|
|
600
|
float D = height/COS18;
|
601
|
float W = D*SIN18;
|
602
|
float X1 = height/2;
|
603
|
float Y1 = width/2;
|
604
|
float Y2 = (width+W)/2;
|
605
|
float X3 = D*SIN54;
|
606
|
float Y3 = D*COS54;
|
607
|
float X4 = height*SIN_HALFD;
|
608
|
float Y4 = height*COS_HALFD;
|
609
|
|
610
|
float[] vertices0 = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
|
611
|
float[] vertices1 = { -X1,-Y2, X1, -Y2, X1, Y2+W,-X1, Y2 };
|
612
|
float[] vertices2 = { -X3, 0.0f, 0.0f, -Y3, X3, 0.0f, 0.0f, Y3 };
|
613
|
float[] vertices3 = { -X4, 0.0f, 0.0f, -Y4, X4, 0.0f, 0.0f, Y4 };
|
614
|
|
615
|
int numBands0 = numLayers<=5 ? 5 : 3;
|
616
|
int numBands1 = numLayers<=5 ? 3 : 2;
|
617
|
float h = numLayers<=5 ? 0.03f : 0.03f;
|
618
|
|
619
|
float[] bands0 = computeBands(h ,34,0.2f,0.2f,numBands0);
|
620
|
float[] bands1 = computeBands(0.01f,34,0.3f,0.2f,numBands1);
|
621
|
|
622
|
meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
|
623
|
meshes[0].setEffectAssociation(0, 1,0);
|
624
|
meshes[1] = meshes[0].copy(true);
|
625
|
meshes[1].setEffectAssociation(0, 2,0);
|
626
|
meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
|
627
|
meshes[2].setEffectAssociation(0, 4,0);
|
628
|
meshes[3] = meshes[2].copy(true);
|
629
|
meshes[3].setEffectAssociation(0, 8,0);
|
630
|
meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0);
|
631
|
meshes[4].setEffectAssociation(0,16,0);
|
632
|
meshes[5] = new MeshPolygon(vertices3, bands1, 0, 0);
|
633
|
meshes[5].setEffectAssociation(0,32,0);
|
634
|
|
635
|
return new MeshJoined(meshes);
|
636
|
}
|
637
|
|
638
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
639
|
|
640
|
MeshBase createFacesMegaminxEdge(int numLayers, float width, float height)
|
641
|
{
|
642
|
MeshBase[] meshes = new MeshPolygon[6];
|
643
|
|
644
|
float D = height/COS18;
|
645
|
float W = D*SIN18;
|
646
|
|
647
|
float Y1 = 0.5f*width;
|
648
|
float Y2 = 0.5f*width + W;
|
649
|
float Y3 = 0.5f*width + 2*W;
|
650
|
float X2 = D*SIN54;
|
651
|
float X1 = 0.5f*height;
|
652
|
float Y4 = D*COS54;
|
653
|
|
654
|
float[] vertices0 = { -X1, Y1, -X1, -Y1, X1, -Y2, X1, Y2 };
|
655
|
float[] vertices1 = { -X1, Y3, -X1, -Y3, X1, -Y2, X1, Y2 };
|
656
|
float[] vertices2 = { -X2, 0.0f, 0.0f, -Y4, X2, 0.0f, 0.0f, Y4 };
|
657
|
|
658
|
int numBands0 = numLayers==3 ? 5 : 3;
|
659
|
int numBands1 = numLayers==3 ? 2 : 2;
|
660
|
float h = numLayers==3 ? 0.03f : 0.03f;
|
661
|
|
662
|
float[] bands0 = computeBands(h ,34,0.2f,0.2f,numBands0);
|
663
|
float[] bands1 = computeBands(0.00f,34,0.3f,0.2f,numBands1);
|
664
|
|
665
|
meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0);
|
666
|
meshes[0].setEffectAssociation(0, 1,0);
|
667
|
meshes[1] = meshes[0].copy(true);
|
668
|
meshes[1].setEffectAssociation(0, 2,0);
|
669
|
meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
|
670
|
meshes[2].setEffectAssociation(0, 4,0);
|
671
|
meshes[3] = meshes[2].copy(true);
|
672
|
meshes[3].setEffectAssociation(0, 8,0);
|
673
|
meshes[4] = new MeshPolygon(vertices2, bands1, 0, 0);
|
674
|
meshes[4].setEffectAssociation(0,16,0);
|
675
|
meshes[5] = meshes[4].copy(true);
|
676
|
meshes[5].setEffectAssociation(0,32,0);
|
677
|
|
678
|
return new MeshJoined(meshes);
|
679
|
}
|
680
|
|
681
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
682
|
|
683
|
MeshBase createFacesMegaminxCenter(int numLayers)
|
684
|
{
|
685
|
MeshBase[] meshes = new MeshPolygon[2];
|
686
|
|
687
|
float R = 0.5f;
|
688
|
float X1 = R*COS54;
|
689
|
float Y1 = R*SIN54;
|
690
|
float X2 = R*COS18;
|
691
|
float Y2 = R*SIN18;
|
692
|
|
693
|
float[] vertices0 = { -X1,+Y1, -X2,-Y2, 0.0f,-R, +X2,-Y2, +X1,+Y1 };
|
694
|
|
695
|
int numBands0 = numLayers==3 ? 4 : 3;
|
696
|
int numBands1 = numLayers==3 ? 2 : 2;
|
697
|
float h = numLayers==3 ? 0.04f : 0.04f;
|
698
|
|
699
|
float[] bands0 = computeBands( h ,45, R/3,0.2f, numBands0);
|
700
|
float[] bands1 = computeBands( 0.00f,34, R/3,0.2f, numBands1);
|
701
|
|
702
|
meshes[0] = new MeshPolygon(vertices0, bands0, 0, 0);
|
703
|
meshes[0].setEffectAssociation(0,1,0);
|
704
|
meshes[1] = new MeshPolygon(vertices0, bands1, 0, 0);
|
705
|
meshes[1].setEffectAssociation(0,2,0);
|
706
|
|
707
|
return new MeshJoined(meshes);
|
708
|
}
|
709
|
|
710
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
711
|
|
712
|
private float[] createVertices(int A, int B)
|
713
|
{
|
714
|
float E = 0.5f / Math.max(A,B);
|
715
|
return new float[] { -A*E,-B*E, +A*E,-B*E, +A*E,+B*E, -A*E,+B*E };
|
716
|
}
|
717
|
|
718
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
719
|
|
720
|
MeshBase createCuboid(int[] dimensions)
|
721
|
{
|
722
|
int X = dimensions[0];
|
723
|
int Y = dimensions[1];
|
724
|
int Z = dimensions[2];
|
725
|
|
726
|
float[] verticesXY = createVertices(X,Y);
|
727
|
float[] verticesXZ = createVertices(X,Z);
|
728
|
float[] verticesYZ = createVertices(Z,Y);
|
729
|
|
730
|
float defHeight = 0.048f;
|
731
|
|
732
|
float[] bandsX = computeBands( defHeight/X,65,0.25f,0.5f,5);
|
733
|
float[] bandsY = computeBands( defHeight/Y,65,0.25f,0.5f,5);
|
734
|
float[] bandsZ = computeBands( defHeight/Z,65,0.25f,0.5f,5);
|
735
|
|
736
|
MeshBase[] meshes = new MeshPolygon[6];
|
737
|
|
738
|
meshes[0] = new MeshPolygon(verticesYZ,bandsX,1,2);
|
739
|
meshes[0].setEffectAssociation(0,1,0);
|
740
|
meshes[1] = meshes[0].copy(true);
|
741
|
meshes[1].setEffectAssociation(0,2,0);
|
742
|
meshes[2] = new MeshPolygon(verticesXZ,bandsY,1,2);
|
743
|
meshes[2].setEffectAssociation(0,4,0);
|
744
|
meshes[3] = meshes[2].copy(true);
|
745
|
meshes[3].setEffectAssociation(0,8,0);
|
746
|
meshes[4] = new MeshPolygon(verticesXY,bandsZ,1,2);
|
747
|
meshes[4].setEffectAssociation(0,16,0);
|
748
|
meshes[5] = meshes[4].copy(true);
|
749
|
meshes[5].setEffectAssociation(0,32,0);
|
750
|
|
751
|
return new MeshJoined(meshes);
|
752
|
}
|
753
|
|
754
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
755
|
// EFFECTS
|
756
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
757
|
|
758
|
VertexEffect[] createVertexEffectsHelicopterCorner()
|
759
|
{
|
760
|
float E = 0.5f;
|
761
|
|
762
|
Static3D axisX = new Static3D(1,0,0);
|
763
|
Static3D axisY = new Static3D(0,1,0);
|
764
|
Static3D axis0 = new Static3D(-SQ2/2,0,SQ2/2);
|
765
|
Static3D axis1 = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
|
766
|
Static1D angle1 = new Static1D(+90);
|
767
|
Static1D angle2 = new Static1D(-90);
|
768
|
Static1D angle3 = new Static1D(-135);
|
769
|
Static1D angle4 = new Static1D(90);
|
770
|
Static1D angle5 = new Static1D(120);
|
771
|
Static1D angle6 = new Static1D(240);
|
772
|
Static3D center1= new Static3D(0,0,0);
|
773
|
Static3D center2= new Static3D(-0.25f,-0.25f,-0.25f);
|
774
|
Static3D move1 = new Static3D(-E/4,-E/4,0);
|
775
|
Static3D move2 = new Static3D(-0.25f,(-1.0f/6)-0.25f,-0.25f);
|
776
|
|
777
|
VertexEffect[] effect = new VertexEffect[10];
|
778
|
|
779
|
effect[0] = new VertexEffectMove(move1);
|
780
|
effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
|
781
|
effect[2] = new VertexEffectRotate(angle1,axisX,center1);
|
782
|
effect[3] = new VertexEffectRotate(angle2,axisY,center1);
|
783
|
effect[4] = new VertexEffectMove(move2);
|
784
|
effect[5] = new VertexEffectRotate(angle1,axisX,center2);
|
785
|
effect[6] = new VertexEffectRotate(angle3,axisY,center2);
|
786
|
effect[7] = new VertexEffectRotate(angle4,axis0,center2);
|
787
|
effect[8] = new VertexEffectRotate(angle5,axis1,center2);
|
788
|
effect[9] = new VertexEffectRotate(angle6,axis1,center2);
|
789
|
|
790
|
effect[0].setMeshAssociation( 7,-1); // meshes 0,1,2
|
791
|
effect[1].setMeshAssociation( 6,-1); // meshes 1,2
|
792
|
effect[2].setMeshAssociation( 2,-1); // mesh 1
|
793
|
effect[3].setMeshAssociation( 4,-1); // mesh 2
|
794
|
effect[4].setMeshAssociation(56,-1); // meshes 3,4,5
|
795
|
effect[5].setMeshAssociation(56,-1); // meshes 3,4,5
|
796
|
effect[6].setMeshAssociation(56,-1); // meshes 3,4,5
|
797
|
effect[7].setMeshAssociation(56,-1); // meshes 3,4,5
|
798
|
effect[8].setMeshAssociation(16,-1); // mesh 4
|
799
|
effect[9].setMeshAssociation(32,-1); // mesh 5
|
800
|
|
801
|
return effect;
|
802
|
}
|
803
|
|
804
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
805
|
|
806
|
VertexEffect[] createVertexEffectsHelicopterFace()
|
807
|
{
|
808
|
float E = 0.5f;
|
809
|
float F = SQ2/4;
|
810
|
|
811
|
Static3D move0 = new Static3D(-E/4, -E/4, 0);
|
812
|
Static3D move1 = new Static3D(-(SQ2/24)-E/2, -(SQ2/24)-E/2, 0);
|
813
|
Static3D move2 = new Static3D(-E/2, F/3, 0);
|
814
|
Static3D move3 = new Static3D(+E/2, F/3, 0);
|
815
|
Static3D move4 = new Static3D(+E/3,+E/3, 0);
|
816
|
Static1D angle1 = new Static1D(135);
|
817
|
Static1D angle2 = new Static1D(90);
|
818
|
Static1D angle3 = new Static1D(-90);
|
819
|
Static1D angle4 = new Static1D(-135);
|
820
|
Static3D axisX = new Static3D(1,0,0);
|
821
|
Static3D axisY = new Static3D(0,1,0);
|
822
|
Static3D axisZ = new Static3D(0,0,1);
|
823
|
Static3D axis1 = new Static3D(1,-1,0);
|
824
|
Static3D center = new Static3D(0,0,0);
|
825
|
Static3D center1= new Static3D(-E/2,-E/2,0);
|
826
|
|
827
|
VertexEffect[] effect = new VertexEffect[10];
|
828
|
|
829
|
effect[0] = new VertexEffectMove(move0);
|
830
|
effect[1] = new VertexEffectRotate(angle1, axisZ, center);
|
831
|
effect[2] = new VertexEffectMove(move1);
|
832
|
effect[3] = new VertexEffectRotate(angle2, axis1, center1);
|
833
|
effect[4] = new VertexEffectMove(move2);
|
834
|
effect[5] = new VertexEffectMove(move3);
|
835
|
effect[6] = new VertexEffectRotate(angle3, axisZ, center);
|
836
|
effect[7] = new VertexEffectRotate(angle4, axisX, center);
|
837
|
effect[8] = new VertexEffectRotate(angle1, axisY, center);
|
838
|
effect[9] = new VertexEffectMove(move4);
|
839
|
|
840
|
effect[0].setMeshAssociation( 1,-1); // mesh 0
|
841
|
effect[1].setMeshAssociation( 2,-1); // mesh 1
|
842
|
effect[2].setMeshAssociation( 2,-1); // mesh 1
|
843
|
effect[3].setMeshAssociation( 2,-1); // mesh 1
|
844
|
effect[4].setMeshAssociation( 4,-1); // mesh 2
|
845
|
effect[5].setMeshAssociation( 8,-1); // mesh 3
|
846
|
effect[6].setMeshAssociation( 8,-1); // mesh 3
|
847
|
effect[7].setMeshAssociation( 4,-1); // mesh 2
|
848
|
effect[8].setMeshAssociation( 8,-1); // mesh 3
|
849
|
effect[9].setMeshAssociation(15,-1); // meshes 0,1,2,3
|
850
|
|
851
|
return effect;
|
852
|
}
|
853
|
|
854
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
855
|
|
856
|
VertexEffect[] createVertexEffectsRediEdge()
|
857
|
{
|
858
|
Static3D move0 = new Static3D(0.0f, -0.5f, 0.0f);
|
859
|
Static3D move1 = new Static3D(0.25f, -0.25f, 0.0f);
|
860
|
Static3D move2 = new Static3D(0.5f, 0.0f, 0.0f);
|
861
|
Static3D move3 = new Static3D(0.0f, (SQ3-6)/8, (SQ3-6)/8);
|
862
|
Static3D flipZ = new Static3D(1,1,-1);
|
863
|
Static3D flipX = new Static3D(-1,1,1);
|
864
|
Static3D scale = new Static3D(2,2,2);
|
865
|
Static3D cent0 = new Static3D(0,0, 0);
|
866
|
Static3D cent1 = new Static3D(0,0, -1.5f);
|
867
|
Static3D axisX = new Static3D(1,0, 0);
|
868
|
Static3D axisY = new Static3D(0,1, 0);
|
869
|
Static3D axis = new Static3D(0,SQ2/2,-SQ2/2);
|
870
|
Static1D angle1= new Static1D(90);
|
871
|
Static1D angle2= new Static1D(45);
|
872
|
Static1D angle3= new Static1D( (float)(180/Math.PI*Math.acos(SQ3/3)) );
|
873
|
|
874
|
VertexEffect[] effect = new VertexEffect[12];
|
875
|
|
876
|
effect[0] = new VertexEffectScale(scale);
|
877
|
effect[1] = new VertexEffectMove(move0);
|
878
|
effect[2] = new VertexEffectScale(flipZ);
|
879
|
effect[3] = new VertexEffectRotate(angle1,axisX,cent0);
|
880
|
effect[4] = new VertexEffectMove(move1);
|
881
|
effect[5] = new VertexEffectRotate(angle1,axisY,cent0);
|
882
|
effect[6] = new VertexEffectMove(move2);
|
883
|
effect[7] = new VertexEffectScale(flipX);
|
884
|
effect[8] = new VertexEffectRotate(angle2,axisX,cent0);
|
885
|
effect[9] = new VertexEffectMove(move3);
|
886
|
effect[10]= new VertexEffectRotate(angle3,axis ,cent1);
|
887
|
effect[11]= new VertexEffectScale(flipX);
|
888
|
|
889
|
effect[0].setMeshAssociation(63,-1); // meshes 0,1,2,3,4,5
|
890
|
effect[1].setMeshAssociation( 3,-1); // meshes 0,1
|
891
|
effect[2].setMeshAssociation( 2,-1); // mesh 1
|
892
|
effect[3].setMeshAssociation( 2,-1); // mesh 1
|
893
|
effect[4].setMeshAssociation(12,-1); // meshes 2,3
|
894
|
effect[5].setMeshAssociation(60,-1); // meshes 2,3,4,5
|
895
|
effect[6].setMeshAssociation(12,-1); // meshes 2,3
|
896
|
effect[7].setMeshAssociation( 8,-1); // mesh 3
|
897
|
effect[8].setMeshAssociation(48,-1); // meshes 4,5
|
898
|
effect[9].setMeshAssociation(48,-1); // meshes 4,5
|
899
|
effect[10].setMeshAssociation(48,-1); // meshes 4,5
|
900
|
effect[11].setMeshAssociation(32,-1); // mesh 5
|
901
|
|
902
|
return effect;
|
903
|
}
|
904
|
|
905
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
906
|
|
907
|
VertexEffect[] createVertexEffectsRediCorner()
|
908
|
{
|
909
|
Static3D axisY = new Static3D(0,1,0);
|
910
|
Static3D axisX = new Static3D(1,0,0);
|
911
|
Static3D axisZ = new Static3D(0,0,1);
|
912
|
Static3D center = new Static3D(0,0,0);
|
913
|
Static1D angle90 = new Static1D(90);
|
914
|
Static1D angle270= new Static1D(270);
|
915
|
Static1D angle45 = new Static1D(-45);
|
916
|
Static3D scale = new Static3D(1.0f, SQ2, 1.0f);
|
917
|
|
918
|
VertexEffect[] effect = new VertexEffect[7];
|
919
|
|
920
|
effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
|
921
|
effect[1] = new VertexEffectRotate( angle270, axisX, center );
|
922
|
effect[2] = new VertexEffectRotate( angle90 , axisY, center );
|
923
|
effect[3] = new VertexEffectScale(scale);
|
924
|
effect[4] = new VertexEffectRotate( angle45 , axisX, center );
|
925
|
effect[5] = new VertexEffectRotate( angle90 , axisY, center );
|
926
|
effect[6] = new VertexEffectRotate( angle270, axisZ, center );
|
927
|
|
928
|
effect[0].setMeshAssociation( 7,-1); // 0,1,2
|
929
|
effect[1].setMeshAssociation( 2,-1); // 1
|
930
|
effect[2].setMeshAssociation( 4,-1); // 2
|
931
|
effect[3].setMeshAssociation(56,-1); // 3,4,5
|
932
|
effect[4].setMeshAssociation(56,-1); // 3,4,5
|
933
|
effect[5].setMeshAssociation(16,-1); // 4
|
934
|
effect[6].setMeshAssociation(32,-1); // 5
|
935
|
|
936
|
return effect;
|
937
|
}
|
938
|
|
939
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
940
|
|
941
|
VertexEffect[] createVertexEffectsIvyCorner()
|
942
|
{
|
943
|
Static3D axisX = new Static3D(1,0,0);
|
944
|
Static3D axisY = new Static3D(0,1,0);
|
945
|
Static1D angle1 = new Static1D(+90);
|
946
|
Static1D angle2 = new Static1D(-90);
|
947
|
Static3D center = new Static3D(0,0,0);
|
948
|
Static3D move1 = new Static3D(IVY_M-0.5f,IVY_M-0.5f,0);
|
949
|
|
950
|
VertexEffect[] effect = new VertexEffect[5];
|
951
|
|
952
|
effect[0] = new VertexEffectScale(1/IVY_C);
|
953
|
effect[1] = new VertexEffectMove(move1);
|
954
|
effect[2] = new VertexEffectScale(new Static3D(1,1,-1));
|
955
|
effect[3] = new VertexEffectRotate(angle1,axisX,center);
|
956
|
effect[4] = new VertexEffectRotate(angle2,axisY,center);
|
957
|
|
958
|
effect[2].setMeshAssociation(54,-1); // meshes 1,2,4,5
|
959
|
effect[3].setMeshAssociation(18,-1); // meshes 1,4
|
960
|
effect[4].setMeshAssociation(36,-1); // meshes 2,5
|
961
|
|
962
|
return effect;
|
963
|
}
|
964
|
|
965
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
966
|
|
967
|
VertexEffect[] createVertexEffectsRexEdge()
|
968
|
{
|
969
|
float E = 0.5f - REX_D;
|
970
|
float F = 0.5f;
|
971
|
float G = (float)Math.sqrt(E*E+F*F);
|
972
|
float A = (float)((180/Math.PI)*Math.asin(E/G));
|
973
|
|
974
|
Static3D move1 = new Static3D( 0.0f, -E/3, 0.0f);
|
975
|
Static3D move2 = new Static3D(2*G/3 -F, +E/3, 0.0f);
|
976
|
|
977
|
Static3D center0= new Static3D(0.0f, 0.0f, 0.0f);
|
978
|
Static3D center1= new Static3D( -F, 0.0f, 0.0f);
|
979
|
Static3D center2= new Static3D( +F, 0.0f, 0.0f);
|
980
|
Static3D axisX = new Static3D(1.0f, 0.0f, 0.0f);
|
981
|
Static3D axisY = new Static3D(0.0f, 1.0f, 0.0f);
|
982
|
Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
|
983
|
|
984
|
Static1D angle180 = new Static1D(180);
|
985
|
Static1D angle90 = new Static1D( 90);
|
986
|
Static1D angle270 = new Static1D(270);
|
987
|
Static1D angle1 = new Static1D(+A);
|
988
|
Static1D angle2 = new Static1D(-A);
|
989
|
|
990
|
VertexEffect[] effect = new VertexEffect[12];
|
991
|
|
992
|
effect[0] = new VertexEffectMove(move1);
|
993
|
effect[1] = new VertexEffectMove(move2);
|
994
|
effect[2] = new VertexEffectRotate( angle90, axisX, center0 );
|
995
|
effect[3] = new VertexEffectRotate( angle270, axisX, center0 );
|
996
|
effect[4] = new VertexEffectRotate( angle180, axisX, center0 );
|
997
|
effect[5] = new VertexEffectRotate( angle180, axisY, center0 );
|
998
|
effect[6] = new VertexEffectScale ( new Static3D(-1, 1, 1) );
|
999
|
effect[7] = new VertexEffectScale ( new Static3D( 1,-1, 1) );
|
1000
|
effect[8] = new VertexEffectRotate( angle1, axisY, center1);
|
1001
|
effect[9] = new VertexEffectRotate( angle2, axisY, center2);
|
1002
|
effect[10]= new VertexEffectRotate( angle2, axisZ, center1);
|
1003
|
effect[11]= new VertexEffectRotate( angle1, axisZ, center2);
|
1004
|
|
1005
|
effect[0].setMeshAssociation( 3,-1); // meshes 0 & 1
|
1006
|
effect[1].setMeshAssociation(60,-1); // meshes 2,3,4,5
|
1007
|
effect[2].setMeshAssociation( 2,-1); // meshes 1
|
1008
|
effect[3].setMeshAssociation(12,-1); // meshes 2,3
|
1009
|
effect[4].setMeshAssociation(48,-1); // meshes 4,5
|
1010
|
effect[5].setMeshAssociation(32,-1); // mesh 5
|
1011
|
effect[6].setMeshAssociation( 8,-1); // apply to mesh 3
|
1012
|
effect[7].setMeshAssociation( 2,-1); // apply to mesh 1
|
1013
|
effect[8].setMeshAssociation(16,-1); // apply to mesh 4
|
1014
|
effect[9].setMeshAssociation(32,-1); // apply to mesh 5
|
1015
|
effect[10].setMeshAssociation(4,-1); // apply to mesh 2
|
1016
|
effect[11].setMeshAssociation(8,-1); // apply to mesh 3
|
1017
|
|
1018
|
return effect;
|
1019
|
}
|
1020
|
|
1021
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1022
|
|
1023
|
VertexEffect[] createVertexEffectsRexCorner()
|
1024
|
{
|
1025
|
Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
|
1026
|
Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
|
1027
|
Static1D angle = new Static1D(225);
|
1028
|
|
1029
|
VertexEffect[] effect = new VertexEffect[1];
|
1030
|
effect[0] = new VertexEffectRotate(angle, axisZ, center);
|
1031
|
|
1032
|
return effect;
|
1033
|
}
|
1034
|
|
1035
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1036
|
|
1037
|
VertexEffect[] createVertexEffectsKilominxCenter(float width)
|
1038
|
{
|
1039
|
VertexEffect[] effect = new VertexEffect[11];
|
1040
|
|
1041
|
float H = 0.5f*(SIN54/COS54);
|
1042
|
float Y1= 0.5f*SIN_HALFD;
|
1043
|
float Y2= H/(2*COS_HALFD);
|
1044
|
float cos18 = (float)(Math.sqrt(1- SIN18 * SIN18));
|
1045
|
float LEN = (float)Math.sqrt(H*H/(COS_HALFD*COS_HALFD) + 0.25f);
|
1046
|
|
1047
|
Static3D axisZ = new Static3D(0.0f , 0.0f , 1.0f);
|
1048
|
Static3D axisY = new Static3D(0.0f , 1.0f , 0.0f);
|
1049
|
Static3D axisA = new Static3D(-SIN18, cos18, 0.0f);
|
1050
|
Static3D axisC = new Static3D( H/LEN, -0.5f/LEN,-H* SIN_HALFD /(COS_HALFD*LEN));
|
1051
|
|
1052
|
Static3D move1 = new Static3D(0,-Y1,0);
|
1053
|
Static3D move2 = new Static3D(0,-Y2,0);
|
1054
|
Static3D move3 = new Static3D(0.5f*cos18,0.5f*SIN18,0);
|
1055
|
Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
|
1056
|
|
1057
|
Static1D angle1 = new Static1D(54);
|
1058
|
Static1D angle2 = new Static1D(DIHEDRAL1/2+18);
|
1059
|
Static1D angle3 = new Static1D(90);
|
1060
|
Static1D angle4 = new Static1D(120);
|
1061
|
Static1D angle5 = new Static1D(240);
|
1062
|
Static1D angle6 = new Static1D(90-DIHEDRAL1/2);
|
1063
|
|
1064
|
effect[0] = new VertexEffectMove(move1);
|
1065
|
effect[1] = new VertexEffectScale(1/MINX_SC);
|
1066
|
effect[2] = new VertexEffectMove(move2);
|
1067
|
effect[3] = new VertexEffectRotate(angle1, axisZ, center);
|
1068
|
effect[4] = new VertexEffectRotate(angle2, axisZ, center);
|
1069
|
effect[5] = new VertexEffectRotate(angle3, axisA, center);
|
1070
|
effect[6] = new VertexEffectMove(move3);
|
1071
|
effect[7] = new VertexEffectRotate(angle4, axisC, center);
|
1072
|
effect[8] = new VertexEffectRotate(angle5, axisC, center);
|
1073
|
effect[9] = new VertexEffectRotate(angle6, axisY, center);
|
1074
|
effect[10]= new VertexEffectScale(width/0.5f);
|
1075
|
|
1076
|
effect[0].setMeshAssociation( 7,-1); // meshes 0,1,2
|
1077
|
effect[1].setMeshAssociation(56,-1); // meshes 3,4,5
|
1078
|
effect[2].setMeshAssociation(56,-1); // meshes 3,4,5
|
1079
|
effect[3].setMeshAssociation( 7,-1); // meshes 0,1,2
|
1080
|
effect[4].setMeshAssociation(56,-1); // meshes 3,4,5
|
1081
|
effect[5].setMeshAssociation(56,-1); // meshes 3,4,5
|
1082
|
effect[6].setMeshAssociation(56,-1); // meshes 3,4,5
|
1083
|
effect[7].setMeshAssociation(18,-1); // meshes 1,4
|
1084
|
effect[8].setMeshAssociation(36,-1); // meshes 2,5
|
1085
|
|
1086
|
return effect;
|
1087
|
}
|
1088
|
|
1089
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1090
|
|
1091
|
VertexEffect[] createVertexEffectsMinxCorner(float width)
|
1092
|
{
|
1093
|
VertexEffect[] effect = new VertexEffect[9];
|
1094
|
|
1095
|
float Y = COS54/(2*SIN54);
|
1096
|
|
1097
|
float sinA = (2*SIN54*SIN54-1)/COS54;
|
1098
|
float cosA = (float)Math.sqrt(1-sinA*sinA);
|
1099
|
float LEN = 0.5f/SIN54;
|
1100
|
float scale= width/LEN;
|
1101
|
|
1102
|
Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
|
1103
|
Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
|
1104
|
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
|
1105
|
|
1106
|
Static3D centerU = new Static3D( 0.0f, Y, 0.0f);
|
1107
|
Static3D centerD = new Static3D( 0.0f,-Y, 0.0f);
|
1108
|
|
1109
|
Static3D move1= new Static3D(0.0f, -sinA*LEN, -cosA*LEN );
|
1110
|
Static3D move2= new Static3D(0.0f, Y , 0.0f );
|
1111
|
|
1112
|
Static1D angleD = new Static1D(DIHEDRAL1);
|
1113
|
Static1D angleE = new Static1D(360-DIHEDRAL1);
|
1114
|
Static1D angleF = new Static1D(DIHEDRAL2);
|
1115
|
|
1116
|
effect[0] = new VertexEffectScale ( new Static3D( 1, 1,-1) );
|
1117
|
effect[1] = new VertexEffectRotate(angleE, axisA, centerU);
|
1118
|
effect[2] = new VertexEffectRotate(angleD, axisB, centerU);
|
1119
|
effect[3] = new VertexEffectMove(move1);
|
1120
|
effect[4] = new VertexEffectRotate(angleE, axisA, centerD);
|
1121
|
effect[5] = new VertexEffectRotate(angleD, axisB, centerD);
|
1122
|
effect[6] = new VertexEffectRotate(angleF, axisX, centerD);
|
1123
|
effect[7] = new VertexEffectMove(move2);
|
1124
|
effect[8] = new VertexEffectScale(scale);
|
1125
|
|
1126
|
effect[0].setMeshAssociation( 3,-1); // meshes 0,1
|
1127
|
effect[1].setMeshAssociation( 16,-1); // mesh 4
|
1128
|
effect[2].setMeshAssociation( 32,-1); // mesh 5
|
1129
|
effect[3].setMeshAssociation( 56,-1); // meshes 3,4,5
|
1130
|
effect[4].setMeshAssociation( 1,-1); // mesh 0
|
1131
|
effect[5].setMeshAssociation( 2,-1); // mesh 1
|
1132
|
|
1133
|
return effect;
|
1134
|
}
|
1135
|
|
1136
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1137
|
|
1138
|
VertexEffect[] createVertexEffectsKilominxEdge(float width, float height, boolean left)
|
1139
|
{
|
1140
|
VertexEffect[] effect = new VertexEffect[11 + (left ? 0:1)];
|
1141
|
|
1142
|
float D = height/COS18;
|
1143
|
float W = D*SIN18;
|
1144
|
float X1 = height/2;
|
1145
|
float Y1 = width/2;
|
1146
|
float Y2 = (width+W)/2;
|
1147
|
float Y3 = D*COS54;
|
1148
|
float Y4 = height*COS_HALFD;
|
1149
|
float Z = 2*height*COS_HALFD;
|
1150
|
float alpha = 90-DIHEDRAL1/2;
|
1151
|
|
1152
|
Static1D angle1 = new Static1D(alpha);
|
1153
|
Static1D angle2 = new Static1D(180-alpha);
|
1154
|
Static1D angle3 = new Static1D(DIHEDRAL2);
|
1155
|
Static1D angle4 = new Static1D(90);
|
1156
|
|
1157
|
Static3D move1 = new Static3D(+X1,-Y1,0);
|
1158
|
Static3D move2 = new Static3D(-X1,-Y2+W,-Z);
|
1159
|
Static3D move3 = new Static3D(0,+Y3,0);
|
1160
|
Static3D move4 = new Static3D(0,-Y4-width,0);
|
1161
|
Static3D scale = new Static3D(+1,+1,-1);
|
1162
|
|
1163
|
Static3D axisXplus = new Static3D(+1, 0, 0);
|
1164
|
Static3D axisYplus = new Static3D( 0,+1, 0);
|
1165
|
|
1166
|
Static3D center1= new Static3D( 0, 0, 0);
|
1167
|
Static3D center2= new Static3D( 0, 0,-Z);
|
1168
|
Static3D center3= new Static3D( 0,-width, 0);
|
1169
|
|
1170
|
effect[ 0] = new VertexEffectMove(move1);
|
1171
|
effect[ 1] = new VertexEffectMove(move2);
|
1172
|
effect[ 2] = new VertexEffectMove(move3);
|
1173
|
effect[ 3] = new VertexEffectMove(move4);
|
1174
|
effect[ 4] = new VertexEffectScale(scale);
|
1175
|
effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
|
1176
|
effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
|
1177
|
effect[ 7] = new VertexEffectRotate(angle1, axisYplus , center2);
|
1178
|
effect[ 8] = new VertexEffectRotate(angle2, axisYplus , center2);
|
1179
|
effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center1);
|
1180
|
effect[10] = new VertexEffectRotate(angle4, axisXplus , center3);
|
1181
|
|
1182
|
if( !left )
|
1183
|
{
|
1184
|
Static3D scale1 = new Static3D(+1,-1,+1);
|
1185
|
effect[11] = new VertexEffectScale(scale1);
|
1186
|
}
|
1187
|
|
1188
|
effect[ 0].setMeshAssociation( 3,-1); // meshes 0,1
|
1189
|
effect[ 1].setMeshAssociation(12,-1); // meshes 2,3
|
1190
|
effect[ 2].setMeshAssociation(16,-1); // mesh 4
|
1191
|
effect[ 3].setMeshAssociation(32,-1); // mesh 5
|
1192
|
effect[ 4].setMeshAssociation( 2,-1); // mesh 1
|
1193
|
effect[ 5].setMeshAssociation( 1,-1); // mesh 0
|
1194
|
effect[ 6].setMeshAssociation( 2,-1); // mesh 1
|
1195
|
effect[ 7].setMeshAssociation( 4,-1); // mesh 2
|
1196
|
effect[ 8].setMeshAssociation( 8,-1); // mesh 3
|
1197
|
effect[ 9].setMeshAssociation(16,-1); // mesh 4
|
1198
|
effect[10].setMeshAssociation(32,-1); // mesh 5
|
1199
|
|
1200
|
return effect;
|
1201
|
}
|
1202
|
|
1203
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1204
|
|
1205
|
VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
|
1206
|
{
|
1207
|
VertexEffect[] effect = new VertexEffect[11];
|
1208
|
|
1209
|
float X = 0.5f*height;
|
1210
|
float Y = height*(COS54/COS18) + width*0.5f;
|
1211
|
float Z = 2*height*COS_HALFD;
|
1212
|
|
1213
|
float alpha = 90-DIHEDRAL1/2;
|
1214
|
float beta = DIHEDRAL2;
|
1215
|
|
1216
|
Static1D angle1 = new Static1D(alpha);
|
1217
|
Static1D angle2 = new Static1D(180-alpha);
|
1218
|
Static1D angle3 = new Static1D(beta);
|
1219
|
|
1220
|
Static3D move1 = new Static3D(X,0,0);
|
1221
|
Static3D move2 = new Static3D(X,0,-Z);
|
1222
|
Static3D move3 = new Static3D(0,+Y,0);
|
1223
|
Static3D move4 = new Static3D(0,-Y,0);
|
1224
|
Static3D scale = new Static3D(+1,+1,-1);
|
1225
|
|
1226
|
Static3D axisXplus = new Static3D(+1, 0, 0);
|
1227
|
Static3D axisXminus= new Static3D(-1, 0, 0);
|
1228
|
Static3D axisYplus = new Static3D( 0,+1, 0);
|
1229
|
Static3D axisYminus= new Static3D( 0,-1, 0);
|
1230
|
|
1231
|
Static3D center1= new Static3D( 0, 0, 0);
|
1232
|
Static3D center2= new Static3D( 0, 0,-Z);
|
1233
|
Static3D center3= new Static3D( 0,+width*0.5f, 0);
|
1234
|
Static3D center4= new Static3D( 0,-width*0.5f, 0);
|
1235
|
|
1236
|
effect[ 0] = new VertexEffectMove(move1);
|
1237
|
effect[ 1] = new VertexEffectMove(move2);
|
1238
|
effect[ 2] = new VertexEffectMove(move3);
|
1239
|
effect[ 3] = new VertexEffectMove(move4);
|
1240
|
effect[ 4] = new VertexEffectScale(scale);
|
1241
|
effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
|
1242
|
effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
|
1243
|
effect[ 7] = new VertexEffectRotate(angle1, axisYminus, center2);
|
1244
|
effect[ 8] = new VertexEffectRotate(angle2, axisYminus, center2);
|
1245
|
effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center3);
|
1246
|
effect[10] = new VertexEffectRotate(angle3, axisXminus, center4);
|
1247
|
|
1248
|
effect[ 0].setMeshAssociation( 3,-1); // meshes 0,1
|
1249
|
effect[ 1].setMeshAssociation(12,-1); // meshes 2,3
|
1250
|
effect[ 2].setMeshAssociation(16,-1); // mesh 4
|
1251
|
effect[ 3].setMeshAssociation(32,-1); // mesh 5
|
1252
|
effect[ 4].setMeshAssociation( 2,-1); // mesh 1
|
1253
|
effect[ 5].setMeshAssociation( 1,-1); // mesh 0
|
1254
|
effect[ 6].setMeshAssociation( 2,-1); // mesh 1
|
1255
|
effect[ 7].setMeshAssociation( 4,-1); // mesh 2
|
1256
|
effect[ 8].setMeshAssociation( 8,-1); // mesh 3
|
1257
|
effect[ 9].setMeshAssociation(16,-1); // mesh 4
|
1258
|
effect[10].setMeshAssociation(32,-1); // mesh 5
|
1259
|
|
1260
|
return effect;
|
1261
|
}
|
1262
|
|
1263
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1264
|
|
1265
|
VertexEffect[] createVertexEffectsMegaminxCenter(float width)
|
1266
|
{
|
1267
|
VertexEffect[] effect = new VertexEffect[2];
|
1268
|
|
1269
|
Static1D angle = new Static1D(DIHEDRAL2);
|
1270
|
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
|
1271
|
Static3D center= new Static3D( 0, 0, 0);
|
1272
|
|
1273
|
effect[0] = new VertexEffectScale(width/COS54);
|
1274
|
effect[1] = new VertexEffectRotate(angle, axisX, center);
|
1275
|
|
1276
|
return effect;
|
1277
|
}
|
1278
|
|
1279
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1280
|
|
1281
|
VertexEffect[] createCuboidEffects(int[] dimensions)
|
1282
|
{
|
1283
|
float X = dimensions[0];
|
1284
|
float Y = dimensions[1];
|
1285
|
float Z = dimensions[2];
|
1286
|
|
1287
|
float MAX_XY = Math.max(X,Y);
|
1288
|
float MAX_XZ = Math.max(X,Z);
|
1289
|
float MAX_YZ = Math.max(Z,Y);
|
1290
|
|
1291
|
Static1D angle = new Static1D(90);
|
1292
|
Static3D move = new Static3D( 0.0f, 0.0f, 0.5f);
|
1293
|
Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
|
1294
|
Static3D axisY = new Static3D( 0.0f, 1.0f, 0.0f);
|
1295
|
Static3D center= new Static3D( 0.0f, 0.0f, 0.0f);
|
1296
|
|
1297
|
Static3D scale3 = new Static3D(MAX_XY,MAX_XY,+Z);
|
1298
|
Static3D scale4 = new Static3D(MAX_XY,MAX_XY,-Z);
|
1299
|
Static3D scale5 = new Static3D(MAX_XZ,+Y,MAX_XZ);
|
1300
|
Static3D scale6 = new Static3D(MAX_XZ,-Y,MAX_XZ);
|
1301
|
Static3D scale7 = new Static3D(+X,MAX_YZ,MAX_YZ);
|
1302
|
Static3D scale8 = new Static3D(-X,MAX_YZ,MAX_YZ);
|
1303
|
|
1304
|
VertexEffect[] effect = new VertexEffect[9];
|
1305
|
|
1306
|
effect[0] = new VertexEffectMove(move);
|
1307
|
effect[1] = new VertexEffectRotate(angle, axisX, center);
|
1308
|
effect[2] = new VertexEffectRotate(angle, axisY, center);
|
1309
|
effect[3] = new VertexEffectScale(scale3);
|
1310
|
effect[4] = new VertexEffectScale(scale4);
|
1311
|
effect[5] = new VertexEffectScale(scale5);
|
1312
|
effect[6] = new VertexEffectScale(scale6);
|
1313
|
effect[7] = new VertexEffectScale(scale7);
|
1314
|
effect[8] = new VertexEffectScale(scale8);
|
1315
|
|
1316
|
effect[1].setMeshAssociation(12,-1); // meshes 2,3
|
1317
|
effect[2].setMeshAssociation( 3,-1); // meshes 0,1
|
1318
|
effect[3].setMeshAssociation(16,-1); // mesh 4
|
1319
|
effect[4].setMeshAssociation(32,-1); // mesh 5
|
1320
|
effect[5].setMeshAssociation( 8,-1); // mesh 3
|
1321
|
effect[6].setMeshAssociation( 4,-1); // mesh 2
|
1322
|
effect[7].setMeshAssociation( 1,-1); // mesh 0
|
1323
|
effect[8].setMeshAssociation( 2,-1); // mesh 1
|
1324
|
|
1325
|
return effect;
|
1326
|
}
|
1327
|
|
1328
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1329
|
// OBJECTS
|
1330
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1331
|
|
1332
|
|
1333
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1334
|
// Helicopter
|
1335
|
|
1336
|
public MeshBase createHelicopterCornerMesh()
|
1337
|
{
|
1338
|
MeshBase mesh = createFacesHelicopterCorner();
|
1339
|
VertexEffect[] effects = createVertexEffectsHelicopterCorner();
|
1340
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1341
|
|
1342
|
float E = 0.5f;
|
1343
|
Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
|
1344
|
|
1345
|
Static3D[] verticesType1 = new Static3D[1];
|
1346
|
verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
|
1347
|
roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
|
1348
|
|
1349
|
Static3D[] verticesType2 = new Static3D[3];
|
1350
|
verticesType2[0] = new Static3D(-E, 0, 0);
|
1351
|
verticesType2[1] = new Static3D( 0,-E, 0);
|
1352
|
verticesType2[2] = new Static3D( 0, 0,-E);
|
1353
|
roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
|
1354
|
|
1355
|
mesh.mergeEffComponents();
|
1356
|
|
1357
|
return mesh;
|
1358
|
}
|
1359
|
|
1360
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1361
|
|
1362
|
public MeshBase createHelicopterFaceMesh()
|
1363
|
{
|
1364
|
MeshBase mesh = createFacesHelicopterFace();
|
1365
|
VertexEffect[] effects = createVertexEffectsHelicopterFace();
|
1366
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1367
|
|
1368
|
float E = 0.5f;
|
1369
|
Static3D roundingCenter = new Static3D(-E/2 + E/3,-E/2 + E/3,-E/2);
|
1370
|
|
1371
|
Static3D[] verticesType1 = new Static3D[1];
|
1372
|
verticesType1[0] = new Static3D(E/3,E/3,0.0f);
|
1373
|
roundCorners(mesh,roundingCenter,verticesType1,0.06f,0.15f);
|
1374
|
|
1375
|
Static3D[] verticesType2 = new Static3D[2];
|
1376
|
verticesType2[0] = new Static3D(-E+E/3, E/3 , 0);
|
1377
|
verticesType2[1] = new Static3D( E/3 ,-E+E/3, 0);
|
1378
|
roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
|
1379
|
|
1380
|
mesh.mergeEffComponents();
|
1381
|
mesh.addEmptyTexComponent();
|
1382
|
mesh.addEmptyTexComponent();
|
1383
|
|
1384
|
return mesh;
|
1385
|
}
|
1386
|
|
1387
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1388
|
// Redi cube
|
1389
|
|
1390
|
public MeshBase createRediEdgeMesh()
|
1391
|
{
|
1392
|
MeshBase mesh = createFacesRediEdge();
|
1393
|
VertexEffect[] effects = createVertexEffectsRediEdge();
|
1394
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1395
|
|
1396
|
Static3D center = new Static3D(0.0f,-0.75f,-0.75f);
|
1397
|
Static3D[] vertices = new Static3D[2];
|
1398
|
vertices[0] = new Static3D( 0.5f, 0.0f, 0.0f);
|
1399
|
vertices[1] = new Static3D(-0.5f, 0.0f, 0.0f);
|
1400
|
roundCorners(mesh,center,vertices,0.06f,0.20f);
|
1401
|
|
1402
|
mesh.mergeEffComponents();
|
1403
|
|
1404
|
return mesh;
|
1405
|
}
|
1406
|
|
1407
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1408
|
|
1409
|
public MeshBase createRediCornerMesh()
|
1410
|
{
|
1411
|
MeshBase mesh = createFacesRediCorner();
|
1412
|
VertexEffect[] effects = createVertexEffectsRediCorner();
|
1413
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1414
|
|
1415
|
Static3D center = new Static3D(0,0,0);
|
1416
|
Static3D[] vertices = new Static3D[8];
|
1417
|
vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f);
|
1418
|
vertices[1] = new Static3D(+0.5f,+0.5f,-0.5f);
|
1419
|
vertices[2] = new Static3D(+0.5f,-0.5f,+0.5f);
|
1420
|
vertices[3] = new Static3D(+0.5f,-0.5f,-0.5f);
|
1421
|
vertices[4] = new Static3D(-0.5f,+0.5f,+0.5f);
|
1422
|
vertices[5] = new Static3D(-0.5f,+0.5f,-0.5f);
|
1423
|
vertices[6] = new Static3D(-0.5f,-0.5f,+0.5f);
|
1424
|
vertices[7] = new Static3D(-0.5f,-0.5f,-0.5f);
|
1425
|
|
1426
|
roundCorners(mesh,center,vertices,0.06f,0.12f);
|
1427
|
|
1428
|
mesh.mergeEffComponents();
|
1429
|
|
1430
|
return mesh;
|
1431
|
}
|
1432
|
|
1433
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1434
|
|
1435
|
public MeshBase createIvyCornerMesh()
|
1436
|
{
|
1437
|
MeshBase mesh = createFacesIvyCorner();
|
1438
|
VertexEffect[] effects = createVertexEffectsIvyCorner();
|
1439
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1440
|
|
1441
|
Static3D center = new Static3D(-0.5f,-0.5f,-0.5f);
|
1442
|
Static3D[] vertices = new Static3D[4];
|
1443
|
vertices[0] = new Static3D(+0.0f,+0.0f,+0.0f);
|
1444
|
vertices[1] = new Static3D(-1.0f,+0.0f,+0.0f);
|
1445
|
vertices[2] = new Static3D(+0.0f,-1.0f,+0.0f);
|
1446
|
vertices[3] = new Static3D(+0.0f,+0.0f,-1.0f);
|
1447
|
|
1448
|
roundCorners(mesh,center,vertices,0.03f,0.10f);
|
1449
|
|
1450
|
mesh.mergeEffComponents();
|
1451
|
|
1452
|
return mesh;
|
1453
|
}
|
1454
|
|
1455
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1456
|
|
1457
|
public MeshBase createIvyFaceMesh()
|
1458
|
{
|
1459
|
MeshBase mesh = createFacesIvyFace();
|
1460
|
|
1461
|
Static3D center = new Static3D(-0.0f,-0.0f,-0.5f);
|
1462
|
Static3D[] vertices = new Static3D[2];
|
1463
|
vertices[0] = new Static3D(-0.5f,+0.5f,+0.0f);
|
1464
|
vertices[1] = new Static3D(+0.5f,-0.5f,+0.0f);
|
1465
|
|
1466
|
roundCorners(mesh,center,vertices,0.03f,0.10f);
|
1467
|
|
1468
|
mesh.mergeEffComponents();
|
1469
|
mesh.addEmptyTexComponent();
|
1470
|
mesh.addEmptyTexComponent();
|
1471
|
mesh.addEmptyTexComponent();
|
1472
|
mesh.addEmptyTexComponent();
|
1473
|
|
1474
|
return mesh;
|
1475
|
}
|
1476
|
|
1477
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1478
|
|
1479
|
public MeshBase createRexCornerMesh()
|
1480
|
{
|
1481
|
MeshBase mesh = createFacesRexCorner();
|
1482
|
VertexEffect[] effects = createVertexEffectsRexCorner();
|
1483
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1484
|
|
1485
|
final float G = (1-REX_D)/3;
|
1486
|
Static3D center = new Static3D(0.0f,0.0f,-G*SQ2/2);
|
1487
|
Static3D[] vertices = new Static3D[1];
|
1488
|
vertices[0] = new Static3D(+G,-G,+0.0f);
|
1489
|
roundCorners(mesh,center,vertices,0.10f,0.10f);
|
1490
|
|
1491
|
mesh.mergeEffComponents();
|
1492
|
mesh.addEmptyTexComponent();
|
1493
|
mesh.addEmptyTexComponent();
|
1494
|
mesh.addEmptyTexComponent();
|
1495
|
mesh.addEmptyTexComponent();
|
1496
|
|
1497
|
return mesh;
|
1498
|
}
|
1499
|
|
1500
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1501
|
|
1502
|
public MeshBase createRexFaceMesh()
|
1503
|
{
|
1504
|
MeshBase mesh = createFacesRexFace();
|
1505
|
|
1506
|
mesh.mergeEffComponents();
|
1507
|
mesh.addEmptyTexComponent();
|
1508
|
mesh.addEmptyTexComponent();
|
1509
|
mesh.addEmptyTexComponent();
|
1510
|
mesh.addEmptyTexComponent();
|
1511
|
|
1512
|
return mesh;
|
1513
|
}
|
1514
|
|
1515
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1516
|
|
1517
|
public MeshBase createRexEdgeMesh()
|
1518
|
{
|
1519
|
MeshBase mesh = createFacesRexEdge();
|
1520
|
VertexEffect[] effects = createVertexEffectsRexEdge();
|
1521
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1522
|
|
1523
|
Static3D center = new Static3D(0.0f,-0.5f,-0.5f);
|
1524
|
Static3D[] vertices = new Static3D[2];
|
1525
|
vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f);
|
1526
|
vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f);
|
1527
|
roundCorners(mesh,center,vertices,0.06f,0.10f);
|
1528
|
|
1529
|
mesh.mergeEffComponents();
|
1530
|
|
1531
|
return mesh;
|
1532
|
}
|
1533
|
|
1534
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1535
|
|
1536
|
public MeshBase createKilominxCenterMesh(float width)
|
1537
|
{
|
1538
|
MeshBase mesh = createFacesKilominxCenter();
|
1539
|
VertexEffect[] effects = createVertexEffectsKilominxCenter(width);
|
1540
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1541
|
|
1542
|
float A = (2*SQ3/3)* SIN54;
|
1543
|
float B = 0.4f;
|
1544
|
float X = SIN_HALFD * SIN54 *COS54 ;
|
1545
|
float Y = SIN54 * SIN54 - 0.5f;
|
1546
|
float Z = COS_HALFD* SIN54 *COS54 ;
|
1547
|
|
1548
|
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
|
1549
|
|
1550
|
Static3D[] vertices = new Static3D[4];
|
1551
|
vertices[0] = new Static3D( 0.0f, 0.0f, 0.0f);
|
1552
|
vertices[1] = new Static3D( 0.0f,-0.5f, 0.0f);
|
1553
|
vertices[2] = new Static3D(-X , Y ,-Z );
|
1554
|
vertices[3] = new Static3D(+X , Y ,-Z );
|
1555
|
|
1556
|
roundCorners(mesh,center,vertices,0.03f,0.10f);
|
1557
|
|
1558
|
mesh.mergeEffComponents();
|
1559
|
|
1560
|
return mesh;
|
1561
|
}
|
1562
|
|
1563
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1564
|
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
|
1565
|
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
|
1566
|
|
1567
|
public MeshBase createKilominxEdgeMesh(int numLayers, float width, float height, boolean left)
|
1568
|
{
|
1569
|
MeshBase mesh = createFacesKilominxEdge(numLayers,width,height);
|
1570
|
VertexEffect[] effects = createVertexEffectsKilominxEdge(width,height,left);
|
1571
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1572
|
|
1573
|
// round...
|
1574
|
|
1575
|
mesh.mergeEffComponents();
|
1576
|
|
1577
|
return mesh;
|
1578
|
}
|
1579
|
|
1580
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1581
|
|
1582
|
public MeshBase createMinxCornerMesh(int numLayers, float width)
|
1583
|
{
|
1584
|
MeshBase mesh = createFacesMinxCorner(numLayers);
|
1585
|
VertexEffect[] effects = createVertexEffectsMinxCorner(width);
|
1586
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1587
|
|
1588
|
float A = (2*SQ3/3)* SIN54;
|
1589
|
float B = 0.4f;
|
1590
|
/*
|
1591
|
float X = SIN_HALFD* SIN54 * COS54;
|
1592
|
float Y = SIN54 * SIN54 - 0.5f;
|
1593
|
float Z = COS_HALFD* SIN54 * COS54;
|
1594
|
float S = 2*width;
|
1595
|
*/
|
1596
|
Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
|
1597
|
Static3D[] vertices = new Static3D[1];
|
1598
|
vertices[0] = new Static3D( 0.0f, 0.0f , 0.0f);
|
1599
|
/*
|
1600
|
vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f);
|
1601
|
vertices[2] = new Static3D(-X*S , Y*S ,-Z*S );
|
1602
|
vertices[3] = new Static3D(+X*S , Y*S ,-Z*S );
|
1603
|
*/
|
1604
|
roundCorners(mesh,center,vertices,0.04f,0.10f);
|
1605
|
|
1606
|
mesh.mergeEffComponents();
|
1607
|
|
1608
|
return mesh;
|
1609
|
}
|
1610
|
|
1611
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1612
|
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
|
1613
|
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
|
1614
|
|
1615
|
public MeshBase createMegaminxEdgeMesh(int numLayers, float width, float height)
|
1616
|
{
|
1617
|
MeshBase mesh = createFacesMegaminxEdge(numLayers,width,height);
|
1618
|
VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height);
|
1619
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1620
|
|
1621
|
mesh.mergeEffComponents();
|
1622
|
|
1623
|
return mesh;
|
1624
|
}
|
1625
|
|
1626
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1627
|
|
1628
|
public MeshBase createMegaminxCenterMesh(int numLayers, float width)
|
1629
|
{
|
1630
|
MeshBase mesh = createFacesMegaminxCenter(numLayers);
|
1631
|
VertexEffect[] effects = createVertexEffectsMegaminxCenter(width);
|
1632
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1633
|
|
1634
|
mesh.mergeEffComponents();
|
1635
|
mesh.addEmptyTexComponent();
|
1636
|
mesh.addEmptyTexComponent();
|
1637
|
mesh.addEmptyTexComponent();
|
1638
|
mesh.addEmptyTexComponent();
|
1639
|
|
1640
|
return mesh;
|
1641
|
}
|
1642
|
|
1643
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1644
|
|
1645
|
public MeshBase createCuboidMesh(int[] dimensions)
|
1646
|
{
|
1647
|
MeshBase mesh = createCuboid(dimensions);
|
1648
|
VertexEffect[] effects = createCuboidEffects(dimensions);
|
1649
|
for( VertexEffect effect : effects ) mesh.apply(effect);
|
1650
|
|
1651
|
int X = dimensions[0];
|
1652
|
int Y = dimensions[1];
|
1653
|
int Z = dimensions[2];
|
1654
|
|
1655
|
float strength = 0.04f;
|
1656
|
float radius = 0.15f;
|
1657
|
|
1658
|
Static3D[] vertices = new Static3D[1];
|
1659
|
Static3D center;
|
1660
|
|
1661
|
vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,+0.5f*Z);
|
1662
|
center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
|
1663
|
roundCorners(mesh, center, vertices, strength, radius);
|
1664
|
|
1665
|
vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,-0.5f*Z);
|
1666
|
center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
|
1667
|
roundCorners(mesh, center, vertices, strength, radius);
|
1668
|
|
1669
|
vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,+0.5f*Z);
|
1670
|
center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
|
1671
|
roundCorners(mesh, center, vertices, strength, radius);
|
1672
|
|
1673
|
vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,-0.5f*Z);
|
1674
|
center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
|
1675
|
roundCorners(mesh, center, vertices, strength, radius);
|
1676
|
|
1677
|
vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,+0.5f*Z);
|
1678
|
center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
|
1679
|
roundCorners(mesh, center, vertices, strength, radius);
|
1680
|
|
1681
|
vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,-0.5f*Z);
|
1682
|
center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
|
1683
|
roundCorners(mesh, center, vertices, strength, radius);
|
1684
|
|
1685
|
vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,+0.5f*Z);
|
1686
|
center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
|
1687
|
roundCorners(mesh, center, vertices, strength, radius);
|
1688
|
|
1689
|
vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,-0.5f*Z);
|
1690
|
center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
|
1691
|
roundCorners(mesh, center, vertices, strength, radius);
|
1692
|
|
1693
|
mesh.mergeEffComponents();
|
1694
|
|
1695
|
return mesh;
|
1696
|
}
|
1697
|
|
1698
|
|
1699
|
|
1700
|
|
1701
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1702
|
|
1703
|
private boolean areColinear(double[][] vertices, int index1, int index2, int index3)
|
1704
|
{
|
1705
|
double x1 = vertices[index1][0];
|
1706
|
double y1 = vertices[index1][1];
|
1707
|
double z1 = vertices[index1][2];
|
1708
|
double x2 = vertices[index2][0];
|
1709
|
double y2 = vertices[index2][1];
|
1710
|
double z2 = vertices[index2][2];
|
1711
|
double x3 = vertices[index3][0];
|
1712
|
double y3 = vertices[index3][1];
|
1713
|
double z3 = vertices[index3][2];
|
1714
|
|
1715
|
double v1x = x2-x1;
|
1716
|
double v1y = y2-y1;
|
1717
|
double v1z = z2-z1;
|
1718
|
double v2x = x3-x1;
|
1719
|
double v2y = y3-y1;
|
1720
|
double v2z = z3-z1;
|
1721
|
|
1722
|
double A = Math.sqrt( (v1x*v1x+v1y*v1y+v1z*v1z) / (v2x*v2x+v2y*v2y+v2z*v2z) );
|
1723
|
|
1724
|
return (v1x==A*v2x && v1y==A*v2y && v1z==A*v2z);
|
1725
|
}
|
1726
|
|
1727
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1728
|
|
1729
|
private void computeNormalVector(double[][] vertices, int index1, int index2, int index3)
|
1730
|
{
|
1731
|
double x1 = vertices[index1][0];
|
1732
|
double y1 = vertices[index1][1];
|
1733
|
double z1 = vertices[index1][2];
|
1734
|
double x2 = vertices[index2][0];
|
1735
|
double y2 = vertices[index2][1];
|
1736
|
double z2 = vertices[index2][2];
|
1737
|
double x3 = vertices[index3][0];
|
1738
|
double y3 = vertices[index3][1];
|
1739
|
double z3 = vertices[index3][2];
|
1740
|
|
1741
|
double v1x = x2-x1;
|
1742
|
double v1y = y2-y1;
|
1743
|
double v1z = z2-z1;
|
1744
|
double v2x = x3-x1;
|
1745
|
double v2y = y3-y1;
|
1746
|
double v2z = z3-z1;
|
1747
|
|
1748
|
mBuffer[0] = v1y*v2z - v2y*v1z;
|
1749
|
mBuffer[1] = v1z*v2x - v2z*v1x;
|
1750
|
mBuffer[2] = v1x*v2y - v2x*v1y;
|
1751
|
|
1752
|
double len = mBuffer[0]*mBuffer[0] + mBuffer[1]*mBuffer[1] + mBuffer[2]*mBuffer[2];
|
1753
|
len = Math.sqrt(len);
|
1754
|
mBuffer[0] /= len;
|
1755
|
mBuffer[1] /= len;
|
1756
|
mBuffer[2] /= len;
|
1757
|
}
|
1758
|
|
1759
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1760
|
// return quat1*quat2
|
1761
|
|
1762
|
private static void quatMultiply( double[] quat1, double[] quat2, double[] result )
|
1763
|
{
|
1764
|
double qx = quat1[0];
|
1765
|
double qy = quat1[1];
|
1766
|
double qz = quat1[2];
|
1767
|
double qw = quat1[3];
|
1768
|
|
1769
|
double rx = quat2[0];
|
1770
|
double ry = quat2[1];
|
1771
|
double rz = quat2[2];
|
1772
|
double rw = quat2[3];
|
1773
|
|
1774
|
result[0] = rw*qx - rz*qy + ry*qz + rx*qw;
|
1775
|
result[1] = rw*qy + rz*qx + ry*qw - rx*qz;
|
1776
|
result[2] = rw*qz + rz*qw - ry*qx + rx*qy;
|
1777
|
result[3] = rw*qw - rz*qz - ry*qy - rx*qx;
|
1778
|
}
|
1779
|
|
1780
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1781
|
|
1782
|
private void fitInSquare(FaceTransform info, double[][] vert3D)
|
1783
|
{
|
1784
|
double minX = Double.MAX_VALUE;
|
1785
|
double maxX =-Double.MAX_VALUE;
|
1786
|
double minY = Double.MAX_VALUE;
|
1787
|
double maxY =-Double.MAX_VALUE;
|
1788
|
|
1789
|
for (double[] vert : vert3D)
|
1790
|
{
|
1791
|
double x = vert[0];
|
1792
|
double y = vert[1];
|
1793
|
|
1794
|
if (x > maxX) maxX = x;
|
1795
|
if (x < minX) minX = x;
|
1796
|
if (y > maxY) maxY = y;
|
1797
|
if (y < minY) minY = y;
|
1798
|
}
|
1799
|
|
1800
|
minX = minX<0 ? -minX:minX;
|
1801
|
maxX = maxX<0 ? -maxX:maxX;
|
1802
|
minY = minY<0 ? -minY:minY;
|
1803
|
maxY = maxY<0 ? -maxY:maxY;
|
1804
|
|
1805
|
double max1 = Math.max(minX,minY);
|
1806
|
double max2 = Math.max(maxX,maxY);
|
1807
|
double max3 = Math.max(max1,max2);
|
1808
|
|
1809
|
info.scale = max3/0.5;
|
1810
|
|
1811
|
int len = vert3D.length;
|
1812
|
StickerCoords sInfo = new StickerCoords();
|
1813
|
sInfo.vertices = new double[2*len];
|
1814
|
|
1815
|
for( int vertex=0; vertex<len; vertex++ )
|
1816
|
{
|
1817
|
sInfo.vertices[2*vertex ] = vert3D[vertex][0] / info.scale;
|
1818
|
sInfo.vertices[2*vertex+1] = vert3D[vertex][1] / info.scale;
|
1819
|
}
|
1820
|
|
1821
|
mStickerCoords.add(sInfo);
|
1822
|
|
1823
|
info.sticker = mStickerCoords.size() -1;
|
1824
|
info.flip = false;
|
1825
|
}
|
1826
|
|
1827
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1828
|
|
1829
|
private FaceTransform constructNewTransform(final double[][] vert3D)
|
1830
|
{
|
1831
|
FaceTransform ft = new FaceTransform();
|
1832
|
|
1833
|
// compute center of gravity
|
1834
|
ft.vx = 0.0f;
|
1835
|
ft.vy = 0.0f;
|
1836
|
ft.vz = 0.0f;
|
1837
|
int len = vert3D.length;
|
1838
|
|
1839
|
for (double[] vert : vert3D)
|
1840
|
{
|
1841
|
ft.vx += vert[0];
|
1842
|
ft.vy += vert[1];
|
1843
|
ft.vz += vert[2];
|
1844
|
}
|
1845
|
|
1846
|
ft.vx /= len;
|
1847
|
ft.vy /= len;
|
1848
|
ft.vz /= len;
|
1849
|
|
1850
|
// move all vertices so that their center of gravity is at (0,0,0)
|
1851
|
for (int i=0; i<len; i++)
|
1852
|
{
|
1853
|
vert3D[i][0] -= ft.vx;
|
1854
|
vert3D[i][1] -= ft.vy;
|
1855
|
vert3D[i][2] -= ft.vz;
|
1856
|
}
|
1857
|
|
1858
|
// find 3 non-colinear vertices
|
1859
|
int foundIndex = -1;
|
1860
|
|
1861
|
for(int vertex=2; vertex<len; vertex++)
|
1862
|
{
|
1863
|
if( !areColinear(vert3D,0,1,vertex) )
|
1864
|
{
|
1865
|
foundIndex = vertex;
|
1866
|
break;
|
1867
|
}
|
1868
|
}
|
1869
|
|
1870
|
// compute the normal vector
|
1871
|
if( foundIndex==-1 )
|
1872
|
{
|
1873
|
throw new RuntimeException("all vertices colinear");
|
1874
|
}
|
1875
|
|
1876
|
computeNormalVector(vert3D,0,1,foundIndex);
|
1877
|
|
1878
|
// rotate so that the normal vector becomes (0,0,1)
|
1879
|
double axisX, axisY, axisZ;
|
1880
|
|
1881
|
if( mBuffer[0]!=0.0f || mBuffer[1]!=0.0f )
|
1882
|
{
|
1883
|
axisX = -mBuffer[1];
|
1884
|
axisY = mBuffer[0];
|
1885
|
axisZ = 0.0f;
|
1886
|
|
1887
|
double axiLen = axisX*axisX + axisY*axisY;
|
1888
|
axiLen = Math.sqrt(axiLen);
|
1889
|
axisX /= axiLen;
|
1890
|
axisY /= axiLen;
|
1891
|
axisZ /= axiLen;
|
1892
|
}
|
1893
|
else
|
1894
|
{
|
1895
|
axisX = 0.0f;
|
1896
|
axisY = 1.0f;
|
1897
|
axisZ = 0.0f;
|
1898
|
}
|
1899
|
|
1900
|
double cosTheta = mBuffer[2];
|
1901
|
double sinTheta = Math.sqrt(1-cosTheta*cosTheta);
|
1902
|
double sinHalfTheta = computeSinHalf(cosTheta);
|
1903
|
double cosHalfTheta = computeCosHalf(sinTheta,cosTheta);
|
1904
|
|
1905
|
mQuat1[0] = axisX*sinHalfTheta;
|
1906
|
mQuat1[1] = axisY*sinHalfTheta;
|
1907
|
mQuat1[2] = axisZ*sinHalfTheta;
|
1908
|
mQuat1[3] = cosHalfTheta;
|
1909
|
mQuat2[0] =-axisX*sinHalfTheta;
|
1910
|
mQuat2[1] =-axisY*sinHalfTheta;
|
1911
|
mQuat2[2] =-axisZ*sinHalfTheta;
|
1912
|
mQuat2[3] = cosHalfTheta;
|
1913
|
|
1914
|
for (double[] vert : vert3D)
|
1915
|
{
|
1916
|
quatMultiply(mQuat1, vert , mQuat3);
|
1917
|
quatMultiply(mQuat3, mQuat2, vert );
|
1918
|
}
|
1919
|
|
1920
|
// fit the whole thing in a square and remember the scale & 2D vertices
|
1921
|
fitInSquare(ft, vert3D);
|
1922
|
|
1923
|
// remember the rotation
|
1924
|
ft.qx =-mQuat1[0];
|
1925
|
ft.qy =-mQuat1[1];
|
1926
|
ft.qz =-mQuat1[2];
|
1927
|
ft.qw = mQuat1[3];
|
1928
|
|
1929
|
return ft;
|
1930
|
}
|
1931
|
|
1932
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1933
|
|
1934
|
private double computeCos(double oldX, double oldY, double newX, double newY, double len1, double len2)
|
1935
|
{
|
1936
|
double ret= (oldX*newX+oldY*newY) / (len1*len2);
|
1937
|
if( ret<-1.0 ) return -1.0;
|
1938
|
if( ret> 1.0 ) return 1.0;
|
1939
|
|
1940
|
return ret;
|
1941
|
}
|
1942
|
|
1943
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1944
|
// sin of (signed!) angle between vectors 'old' and 'new', counterclockwise!
|
1945
|
|
1946
|
private double computeSin(double oldX, double oldY, double newX, double newY, double len1, double len2)
|
1947
|
{
|
1948
|
double ret= (newX*oldY-oldX*newY) / (len1*len2);
|
1949
|
if( ret<-1.0 ) return -1.0;
|
1950
|
if( ret> 1.0 ) return 1.0;
|
1951
|
|
1952
|
return ret;
|
1953
|
}
|
1954
|
|
1955
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1956
|
|
1957
|
private void rotateAllVertices(double[] result, int len, double[] vertices, double sin, double cos)
|
1958
|
{
|
1959
|
for(int i=0; i<len; i++)
|
1960
|
{
|
1961
|
result[2*i ] = vertices[2*i ]*cos - vertices[2*i+1]*sin;
|
1962
|
result[2*i+1] = vertices[2*i ]*sin + vertices[2*i+1]*cos;
|
1963
|
}
|
1964
|
}
|
1965
|
|
1966
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1967
|
|
1968
|
private double computeScale(double[] v1, double[] v2)
|
1969
|
{
|
1970
|
double lenSq1 = v1[0]*v1[0] + v1[1]*v1[1];
|
1971
|
double lenSq2 = v2[0]*v2[0] + v2[1]*v2[1];
|
1972
|
|
1973
|
return Math.sqrt(lenSq2/lenSq1);
|
1974
|
}
|
1975
|
|
1976
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1977
|
// valid for 0<angle<2*PI
|
1978
|
|
1979
|
private double computeSinHalf(double cos)
|
1980
|
{
|
1981
|
return Math.sqrt((1-cos)/2);
|
1982
|
}
|
1983
|
|
1984
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1985
|
// valid for 0<angle<2*PI
|
1986
|
|
1987
|
private double computeCosHalf(double sin, double cos)
|
1988
|
{
|
1989
|
double cosHalf = Math.sqrt((1+cos)/2);
|
1990
|
return sin<0 ? -cosHalf : cosHalf;
|
1991
|
}
|
1992
|
|
1993
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
1994
|
|
1995
|
private int computeRotatedIndex(int oldVertex, int len, int rotatedVertex, boolean inverted)
|
1996
|
{
|
1997
|
int v = (rotatedVertex + (inverted? -oldVertex : oldVertex));
|
1998
|
if( v>=len ) v-=len;
|
1999
|
if( v< 0 ) v+=len;
|
2000
|
|
2001
|
return v;
|
2002
|
}
|
2003
|
|
2004
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2005
|
|
2006
|
private boolean isScaledVersionOf(double[] newVert, double[] oldVert, int len, int vertex, boolean inverted)
|
2007
|
{
|
2008
|
double EPSILON = 0.001;
|
2009
|
double scale = computeScale(newVert,oldVert);
|
2010
|
|
2011
|
for(int i=1; i<len; i++)
|
2012
|
{
|
2013
|
int index = computeRotatedIndex(i,len,vertex,inverted);
|
2014
|
|
2015
|
double horz = oldVert[2*i ] - scale*newVert[2*index ];
|
2016
|
double vert = oldVert[2*i+1] - scale*newVert[2*index+1];
|
2017
|
|
2018
|
if( horz>EPSILON || horz<-EPSILON || vert>EPSILON || vert<-EPSILON ) return false;
|
2019
|
}
|
2020
|
|
2021
|
return true;
|
2022
|
}
|
2023
|
|
2024
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2025
|
|
2026
|
private void mirrorAllVertices(double[] output, int len, double[] input)
|
2027
|
{
|
2028
|
for(int vertex=0; vertex<len; vertex++)
|
2029
|
{
|
2030
|
output[2*vertex ] = input[2*vertex ];
|
2031
|
output[2*vertex+1] =-input[2*vertex+1];
|
2032
|
}
|
2033
|
}
|
2034
|
|
2035
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2036
|
|
2037
|
private void correctInfo(FaceTransform info, double scale, double sin, double cos, int oldSticker, boolean flip)
|
2038
|
{
|
2039
|
mStickerCoords.remove(info.sticker);
|
2040
|
|
2041
|
info.flip = flip;
|
2042
|
info.sticker = oldSticker;
|
2043
|
info.scale *= scale;
|
2044
|
|
2045
|
mQuat1[0] = info.qx;
|
2046
|
mQuat1[1] = info.qy;
|
2047
|
mQuat1[2] = info.qz;
|
2048
|
mQuat1[3] = info.qw;
|
2049
|
|
2050
|
double sinHalf = computeSinHalf(cos);
|
2051
|
double cosHalf = computeCosHalf(sin,cos);
|
2052
|
|
2053
|
if( flip )
|
2054
|
{
|
2055
|
mQuat3[0] = 0.0f;
|
2056
|
mQuat3[1] = 0.0f;
|
2057
|
mQuat3[2] = sinHalf;
|
2058
|
mQuat3[3] = cosHalf;
|
2059
|
|
2060
|
mQuat4[0] = 1.0;
|
2061
|
mQuat4[1] = 0.0;
|
2062
|
mQuat4[2] = 0.0;
|
2063
|
mQuat4[3] = 0.0;
|
2064
|
|
2065
|
quatMultiply( mQuat3, mQuat4, mQuat2 );
|
2066
|
}
|
2067
|
else
|
2068
|
{
|
2069
|
mQuat2[0] = 0.0f;
|
2070
|
mQuat2[1] = 0.0f;
|
2071
|
mQuat2[2] = sinHalf;
|
2072
|
mQuat2[3] = cosHalf;
|
2073
|
}
|
2074
|
|
2075
|
quatMultiply( mQuat1, mQuat2, mQuat3 );
|
2076
|
|
2077
|
info.qx = mQuat3[0];
|
2078
|
info.qy = mQuat3[1];
|
2079
|
info.qz = mQuat3[2];
|
2080
|
info.qw = mQuat3[3];
|
2081
|
}
|
2082
|
|
2083
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2084
|
|
2085
|
private void printVert(double[] buffer)
|
2086
|
{
|
2087
|
int len = buffer.length/2;
|
2088
|
String str = "";
|
2089
|
|
2090
|
for(int i=0; i<len; i++)
|
2091
|
{
|
2092
|
str += (" ("+buffer[2*i]+" , "+buffer[2*i+1]+" ) ");
|
2093
|
}
|
2094
|
|
2095
|
android.util.Log.d("D", str);
|
2096
|
}
|
2097
|
|
2098
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2099
|
|
2100
|
private boolean foundVertex(FaceTransform info, double[] buffer, int len, double[] newVert,
|
2101
|
double[] oldVert, double lenFirstOld, int oldSticker, boolean inverted)
|
2102
|
{
|
2103
|
for(int vertex=0; vertex<len; vertex++)
|
2104
|
{
|
2105
|
double newX = newVert[2*vertex ];
|
2106
|
double newY = newVert[2*vertex+1];
|
2107
|
double lenIthNew = Math.sqrt(newX*newX + newY*newY);
|
2108
|
double cos = computeCos( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
|
2109
|
double sin = computeSin( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld);
|
2110
|
|
2111
|
rotateAllVertices(buffer,len,newVert,sin,cos);
|
2112
|
|
2113
|
if( isScaledVersionOf(buffer,oldVert,len,vertex,inverted) )
|
2114
|
{
|
2115
|
double scale = computeScale(oldVert,newVert);
|
2116
|
correctInfo(info,scale,sin,cos,oldSticker,inverted);
|
2117
|
return true;
|
2118
|
}
|
2119
|
}
|
2120
|
|
2121
|
return false;
|
2122
|
}
|
2123
|
|
2124
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2125
|
|
2126
|
private boolean successfullyCollapsedStickers(final FaceTransform newInfo, final FaceTransform oldInfo)
|
2127
|
{
|
2128
|
StickerCoords sNewInfo = mStickerCoords.get(newInfo.sticker);
|
2129
|
StickerCoords sOldInfo = mStickerCoords.get(oldInfo.sticker);
|
2130
|
double[] newVert = sNewInfo.vertices;
|
2131
|
double[] oldVert = sOldInfo.vertices;
|
2132
|
int oldLen = oldVert.length;
|
2133
|
int newLen = newVert.length;
|
2134
|
|
2135
|
if( oldLen == newLen )
|
2136
|
{
|
2137
|
int oldSticker = oldInfo.sticker;
|
2138
|
double[] buffer1 = new double[oldLen];
|
2139
|
double lenFirstOld = Math.sqrt(oldVert[0]*oldVert[0] + oldVert[1]*oldVert[1]);
|
2140
|
if( foundVertex(newInfo, buffer1, oldLen/2, newVert, oldVert, lenFirstOld, oldSticker, false) ) return true;
|
2141
|
double[] buffer2 = new double[oldLen];
|
2142
|
mirrorAllVertices(buffer2, newLen/2, newVert);
|
2143
|
if( foundVertex(newInfo, buffer1, oldLen/2, buffer2, oldVert, lenFirstOld, oldSticker, true ) ) return true;
|
2144
|
}
|
2145
|
|
2146
|
return false;
|
2147
|
}
|
2148
|
|
2149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2150
|
|
2151
|
private double[][] constructVert(double[][] vertices, int[] index)
|
2152
|
{
|
2153
|
int len = index.length;
|
2154
|
double[][] ret = new double[len][4];
|
2155
|
|
2156
|
for(int i=0; i<len; i++)
|
2157
|
{
|
2158
|
ret[i][0] = vertices[index[i]][0];
|
2159
|
ret[i][1] = vertices[index[i]][1];
|
2160
|
ret[i][2] = vertices[index[i]][2];
|
2161
|
ret[i][3] = 1.0f;
|
2162
|
}
|
2163
|
|
2164
|
return ret;
|
2165
|
}
|
2166
|
|
2167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2168
|
|
2169
|
private void prepareAndRoundCorners(MeshBase mesh, double[][] vertices,
|
2170
|
float[][] corners, int[] cornerIndexes,
|
2171
|
float[][] centers, int[] centerIndexes )
|
2172
|
{
|
2173
|
int lenV = vertices.length;
|
2174
|
Static3D[] staticVert = new Static3D[1];
|
2175
|
Static3D center = new Static3D(0,0,0);
|
2176
|
|
2177
|
for(int v=0; v<lenV; v++)
|
2178
|
{
|
2179
|
staticVert[0] = new Static3D( (float)vertices[v][0], (float)vertices[v][1], (float)vertices[v][2]);
|
2180
|
|
2181
|
int cent = centerIndexes[v];
|
2182
|
|
2183
|
if( cent>=0 )
|
2184
|
{
|
2185
|
center.set( centers[cent][0], centers[cent][1], centers[cent][2]);
|
2186
|
|
2187
|
int corn = cornerIndexes[v];
|
2188
|
float strength = corners[corn][0];
|
2189
|
float radius = corners[corn][1];
|
2190
|
|
2191
|
roundCorners(mesh, center, staticVert, strength, radius);
|
2192
|
}
|
2193
|
}
|
2194
|
}
|
2195
|
|
2196
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2197
|
|
2198
|
private void correctComponents(MeshBase mesh, int numComponents)
|
2199
|
{
|
2200
|
int numTexToBeAdded = numComponents-mesh.getNumTexComponents();
|
2201
|
|
2202
|
mesh.mergeEffComponents();
|
2203
|
|
2204
|
for(int i=0; i<numTexToBeAdded; i++ ) mesh.addEmptyTexComponent();
|
2205
|
}
|
2206
|
|
2207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2208
|
|
2209
|
private void printTransform(FaceTransform f)
|
2210
|
{
|
2211
|
android.util.Log.e("D", "q=("+f.qx+", "+f.qy+", "+f.qz+", "+f.qw+") v=("
|
2212
|
+f.vx+", "+f.vy+", "+f.vz+") scale="+f.scale+" sticker="+f.sticker);
|
2213
|
}
|
2214
|
|
2215
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2216
|
// PUBLIC
|
2217
|
|
2218
|
public void printStickerCoords()
|
2219
|
{
|
2220
|
int stickers = mStickerCoords.size();
|
2221
|
|
2222
|
android.util.Log.d("D", "---- STICKER COORDS ----");
|
2223
|
|
2224
|
for(int s=0; s<stickers; s++)
|
2225
|
{
|
2226
|
String ver = "{ ";
|
2227
|
StickerCoords info = mStickerCoords.get(s);
|
2228
|
int len = info.vertices.length/2;
|
2229
|
|
2230
|
for(int i =0; i<len; i++)
|
2231
|
{
|
2232
|
if( i!=0 ) ver += ", ";
|
2233
|
ver += ( (float)info.vertices[2*i]+"f, "+(float)info.vertices[2*i+1]+"f");
|
2234
|
}
|
2235
|
|
2236
|
ver += " }";
|
2237
|
android.util.Log.d("D", ver);
|
2238
|
}
|
2239
|
|
2240
|
android.util.Log.d("D", "---- END STICKER COORDS ----");
|
2241
|
}
|
2242
|
|
2243
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2244
|
|
2245
|
public void printFaceTransform()
|
2246
|
{
|
2247
|
android.util.Log.d("D", "---- OLD FACE TRANSFORM ---");
|
2248
|
|
2249
|
int oldfaces = mOldFaceTransf.size();
|
2250
|
|
2251
|
for(int f=0; f<oldfaces; f++)
|
2252
|
{
|
2253
|
printTransform(mOldFaceTransf.get(f));
|
2254
|
}
|
2255
|
|
2256
|
android.util.Log.d("D", "---- NEW FACE TRANSFORM ---");
|
2257
|
|
2258
|
int newfaces = mNewFaceTransf.size();
|
2259
|
|
2260
|
for(int f=0; f<newfaces; f++)
|
2261
|
{
|
2262
|
printTransform(mNewFaceTransf.get(f));
|
2263
|
}
|
2264
|
}
|
2265
|
|
2266
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2267
|
|
2268
|
public void clear()
|
2269
|
{
|
2270
|
mStickerCoords.clear();
|
2271
|
mNewFaceTransf.clear();
|
2272
|
mOldFaceTransf.clear();
|
2273
|
}
|
2274
|
|
2275
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2276
|
|
2277
|
public void createNewFaceTransform( final double[][] vertices, final int[][] indexes)
|
2278
|
{
|
2279
|
FaceTransform ft;
|
2280
|
int numNew = mNewFaceTransf.size();
|
2281
|
|
2282
|
for(int i=0; i<numNew; i++)
|
2283
|
{
|
2284
|
ft = mNewFaceTransf.remove(0);
|
2285
|
mOldFaceTransf.add(ft);
|
2286
|
}
|
2287
|
|
2288
|
int numFaces = indexes.length;
|
2289
|
int numOld = mOldFaceTransf.size();
|
2290
|
|
2291
|
for (int face=0; face<numFaces; face++)
|
2292
|
{
|
2293
|
boolean collapsed = false;
|
2294
|
|
2295
|
double[][] vert = constructVert(vertices, indexes[face]);
|
2296
|
FaceTransform newT = constructNewTransform(vert);
|
2297
|
|
2298
|
for (int old=0; !collapsed && old<numOld; old++)
|
2299
|
{
|
2300
|
ft = mOldFaceTransf.get(old);
|
2301
|
if (successfullyCollapsedStickers(newT, ft)) collapsed = true;
|
2302
|
}
|
2303
|
|
2304
|
for (int pre=0; !collapsed && pre<face; pre++)
|
2305
|
{
|
2306
|
ft = mNewFaceTransf.get(pre);
|
2307
|
if (successfullyCollapsedStickers(newT, ft)) collapsed = true;
|
2308
|
}
|
2309
|
|
2310
|
mNewFaceTransf.add(newT);
|
2311
|
}
|
2312
|
}
|
2313
|
|
2314
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2315
|
|
2316
|
public MeshBase createRoundedSolid(final double[][] vertices, final int[][] vertIndexes,
|
2317
|
final float[][] bands , final int[] bandIndexes,
|
2318
|
final float[][] corners , final int[] cornerIndexes,
|
2319
|
final float[][] centers , final int[] centerIndexes,
|
2320
|
final int numComponents )
|
2321
|
{
|
2322
|
int numFaces = vertIndexes.length;
|
2323
|
float[] band, bandsComputed;
|
2324
|
MeshBase[] meshes = new MeshBase[numFaces];
|
2325
|
FaceTransform fInfo;
|
2326
|
StickerCoords sInfo;
|
2327
|
|
2328
|
for(int face=0; face<numFaces; face++)
|
2329
|
{
|
2330
|
fInfo = mNewFaceTransf.get(face);
|
2331
|
sInfo = mStickerCoords.get(fInfo.sticker);
|
2332
|
|
2333
|
double[] verts = sInfo.vertices;
|
2334
|
int lenVerts = verts.length;
|
2335
|
float[] vertsFloat = new float[lenVerts];
|
2336
|
for(int i=0; i<lenVerts; i++) vertsFloat[i] = (float)verts[i];
|
2337
|
|
2338
|
band = bands[bandIndexes[face]];
|
2339
|
bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]);
|
2340
|
meshes[face] = new MeshPolygon(vertsFloat,bandsComputed,(int)band[5],(int)band[6]);
|
2341
|
meshes[face].setEffectAssociation(0,(1<<face),0);
|
2342
|
}
|
2343
|
|
2344
|
MeshBase mesh = new MeshJoined(meshes);
|
2345
|
Static3D center = new Static3D(0,0,0);
|
2346
|
|
2347
|
for(int face=0; face<numFaces; face++)
|
2348
|
{
|
2349
|
int assoc = (1<<face);
|
2350
|
fInfo = mNewFaceTransf.get(face);
|
2351
|
|
2352
|
float vx = (float)fInfo.vx;
|
2353
|
float vy = (float)fInfo.vy;
|
2354
|
float vz = (float)fInfo.vz;
|
2355
|
float sc = (float)fInfo.scale;
|
2356
|
float qx = (float)fInfo.qx;
|
2357
|
float qy = (float)fInfo.qy;
|
2358
|
float qz = (float)fInfo.qz;
|
2359
|
float qw = (float)fInfo.qw;
|
2360
|
|
2361
|
Static3D scale = new Static3D(sc,sc, fInfo.flip ? -sc : sc);
|
2362
|
Static3D move3D= new Static3D(vx,vy,vz);
|
2363
|
Static4D quat = new Static4D(qx,qy,qz,qw);
|
2364
|
|
2365
|
mesh.apply(new MatrixEffectScale(scale) ,assoc,-1);
|
2366
|
mesh.apply(new MatrixEffectQuaternion(quat,center),assoc,-1);
|
2367
|
mesh.apply(new MatrixEffectMove(move3D) ,assoc,-1);
|
2368
|
}
|
2369
|
|
2370
|
prepareAndRoundCorners(mesh, vertices, corners, cornerIndexes, centers, centerIndexes);
|
2371
|
|
2372
|
correctComponents(mesh,numComponents);
|
2373
|
|
2374
|
return mesh;
|
2375
|
}
|
2376
|
}
|