Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / FactoryCubit.java @ 55f20739

1 7edab735 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.examples.meshfile;
21
22
import org.distorted.library.effect.VertexEffect;
23
import org.distorted.library.effect.VertexEffectDeform;
24
import org.distorted.library.effect.VertexEffectMove;
25
import org.distorted.library.effect.VertexEffectRotate;
26
import org.distorted.library.effect.VertexEffectScale;
27
import org.distorted.library.mesh.MeshBase;
28
import org.distorted.library.mesh.MeshJoined;
29
import org.distorted.library.mesh.MeshPolygon;
30
import org.distorted.library.type.Static1D;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 55f20739 Leszek Koltunski
class FactoryCubit
37 7edab735 Leszek Koltunski
  {
38
  private static final float SQ2 = (float)Math.sqrt(2);
39
  private static final float SQ3 = (float)Math.sqrt(3);
40
  private static final float SQ6 = (float)Math.sqrt(6);
41
42 55f20739 Leszek Koltunski
  private static final float IVY_D = 0.10f;
43
  private static final int   IVY_N = 8;
44
45 7edab735 Leszek Koltunski
  private static final Static1D RADIUS = new Static1D(1);
46
47 55f20739 Leszek Koltunski
  private static FactoryCubit mThis;
48 7edab735 Leszek Koltunski
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
51 55f20739 Leszek Koltunski
  private FactoryCubit()
52 7edab735 Leszek Koltunski
    {
53
54
    }
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 55f20739 Leszek Koltunski
  public static FactoryCubit getInstance()
59 7edab735 Leszek Koltunski
    {
60 55f20739 Leszek Koltunski
    if( mThis==null ) mThis = new FactoryCubit();
61 7edab735 Leszek Koltunski
62
    return mThis;
63
    }
64
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
// H - height of the band in the middle
67
// alpha - angle of the edge  [0,90]
68
// dist - often in a polygon the distance from edge to center is not 1, but something else.
69
// This is the distance.
70
// K - where to begin the second, much more flat part of the band. [0,1]
71
// N - number of bands. N>=3
72
//
73
// theory: two distinct parts to the band:
74
// 1) (0,B) - steep
75
// 2) (B,1) - flat
76
//
77
// In first part, we have y = g(x) ; in second - y = g(f(x)) where
78
//
79
// g(x) = sqrt( R^2 - (x-D)^2 ) - R*cos(alpha)
80
// f(x) = ((D-B)/(1-B)*x + B*(1-D)/(1-B)
81
// h(x) = R*(sin(alpha) - sin(x))
82
// R = H/(1-cos(alpha))
83
// D = H*sin(alpha)
84
// B = h(K*alpha)
85
//
86
// The N points are taken at:
87
//
88
// 1) in the second part, there are K2 = (N-3)/3 such points
89
// 2) in the first - K1 = (N-3) - K2
90
// 3) also, the 3 points 0,B,1
91
//
92
// so we have the sequence A[i] of N points
93
//
94
// 0
95
// h((i+1)*(1-K)*alpha/(K1+1)) (i=0,1,...,K1-1)
96
// B
97
// (1-B)*(i+1)/(K2+1) + B   (i=0,i,...,K2-1)
98
// 1
99
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
102
  private float f(float D, float B, float x)
103
    {
104
    return ((D-B)*x + B*(1-D))/(1-B);
105
    }
106
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
109
  private float g(float R, float D, float x, float cosAlpha)
110
    {
111
    float d = x-D;
112
    return (float)(Math.sqrt(R*R-d*d)-R*cosAlpha);
113
    }
114
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117
  private float h(float R, float sinAlpha, float x)
118
    {
119
    return R*(sinAlpha-(float)Math.sin(x));
120
    }
121
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123
124 55f20739 Leszek Koltunski
  float[] computeBands(float H, int alpha, float dist, float K, int N)
125 7edab735 Leszek Koltunski
    {
126
    float[] bands = new float[2*N];
127
128
    bands[0] = 1.0f;
129
    bands[1] = 0.0f;
130
131
    float beta = (float)Math.atan(dist*Math.tan(Math.PI*alpha/180));
132
    float sinBeta = (float)Math.sin(beta);
133
    float cosBeta = (float)Math.cos(beta);
134
    float R = cosBeta<1.0f ? H/(1.0f-cosBeta) : 0.0f;
135
    float D = R*sinBeta;
136
    float B = h(R,sinBeta,K*beta);
137
138
    if( D>1.0f )
139
      {
140
      for(int i=1; i<N; i++)
141
        {
142
        bands[2*i  ] = (float)(N-1-i)/(N-1);
143
        bands[2*i+1] = H*(1-bands[2*i]);
144
        }
145
      }
146
    else
147
      {
148 55f20739 Leszek Koltunski
      int K2 = (int)((N-3)*K);
149 7edab735 Leszek Koltunski
      int K1 = (N-3)-K2;
150
151
      for(int i=0; i<=K1; i++)
152
        {
153
        float angle = K*beta + (1-K)*beta*(K1-i)/(K1+1);
154
        float x = h(R,sinBeta,angle);
155
        bands[2*i+2] = 1.0f - x;
156
        bands[2*i+3] = g(R,D,x,cosBeta);
157
        }
158
159
      for(int i=0; i<=K2; i++)
160
        {
161
        float x = (1-B)*(i+1)/(K2+1) + B;
162
        bands[2*K1+2 + 2*i+2] = 1.0f - x;
163
        bands[2*K1+2 + 2*i+3] = g(R,D,f(D,B,x),cosBeta);
164
        }
165
      }
166
167 55f20739 Leszek Koltunski
    bands[2*N-2] = 0.0f;
168
    bands[2*N-1] =    H;
169
170 7edab735 Leszek Koltunski
    return bands;
171
    }
172
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175
  private void roundCorners(MeshBase mesh, Static3D center, Static3D[] vertices, float strength, float regionRadius)
176
    {
177
    Static4D reg= new Static4D(0,0,0,regionRadius);
178
179
    float centX = center.get0();
180
    float centY = center.get1();
181
    float centZ = center.get2();
182
183
    for (Static3D vertex : vertices)
184
      {
185
      float x = strength*(centX - vertex.get0());
186
      float y = strength*(centY - vertex.get1());
187
      float z = strength*(centZ - vertex.get2());
188
189
      VertexEffect effect = new VertexEffectDeform(new Static3D(x,y,z), RADIUS, vertex, reg);
190
      mesh.apply(effect);
191
      }
192
    }
193
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
196 55f20739 Leszek Koltunski
  MeshBase createFacesCube(int sizeIndex)
197 7edab735 Leszek Koltunski
    {
198 55f20739 Leszek Koltunski
    MeshBase[] meshes = new MeshPolygon[6];
199 7edab735 Leszek Koltunski
200 55f20739 Leszek Koltunski
    float E = 0.5f;
201
    int extraI, extraV, num;
202 7edab735 Leszek Koltunski
203 55f20739 Leszek Koltunski
    switch(sizeIndex)
204 7edab735 Leszek Koltunski
      {
205 55f20739 Leszek Koltunski
      case 0 : num = 6; extraI = 2; extraV = 2; break;
206
      case 1 : num = 5; extraI = 2; extraV = 2; break;
207
      case 2 : num = 5; extraI = 1; extraV = 2; break;
208
      default: num = 4; extraI = 1; extraV = 1; break;
209 7edab735 Leszek Koltunski
      }
210
211 55f20739 Leszek Koltunski
    float[] vertices = { -E,-E, +E,-E, +E,+E, -E,+E };
212
    float[] bands = computeBands(0.048f,35,E,0.7f,num);
213 7edab735 Leszek Koltunski
214 55f20739 Leszek Koltunski
    meshes[0] = new MeshPolygon(vertices,bands,extraI,extraV);
215
    meshes[0].setEffectAssociation(0,1,0);
216
    meshes[1] = meshes[0].copy(true);
217
    meshes[1].setEffectAssociation(0,2,0);
218
    meshes[2] = meshes[0].copy(true);
219
    meshes[2].setEffectAssociation(0,4,0);
220
    meshes[3] = meshes[0].copy(true);
221
    meshes[3].setEffectAssociation(0,8,0);
222
    meshes[4] = meshes[0].copy(true);
223
    meshes[4].setEffectAssociation(0,16,0);
224
    meshes[5] = meshes[0].copy(true);
225
    meshes[5].setEffectAssociation(0,32,0);
226 7edab735 Leszek Koltunski
227
    return new MeshJoined(meshes);
228
    }
229
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231
232
  MeshBase createFacesSkewbCorner()
233
    {
234
    MeshBase[] meshes = new MeshBase[6];
235
236
    float E = 0.5f;
237
    float F = SQ2/2;
238 55f20739 Leszek Koltunski
    float G = SQ6/16;
239 7edab735 Leszek Koltunski
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
240 55f20739 Leszek Koltunski
    float[] bands0 = computeBands(0.028f,35,E/3,0.7f,7);
241 7edab735 Leszek Koltunski
242
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
243
    meshes[0].setEffectAssociation(0,1,0);
244
    meshes[1] = meshes[0].copy(true);
245
    meshes[1].setEffectAssociation(0,2,0);
246
    meshes[2] = meshes[0].copy(true);
247
    meshes[2].setEffectAssociation(0,4,0);
248
249 55f20739 Leszek Koltunski
    float[] vertices1 = { -F/2,-2*G, F/2,-2*G, 3*F/8,-G, 1*F/8,G, 0,2*G };
250 7edab735 Leszek Koltunski
    float[] bands1 = computeBands(0,0,1,0,3);
251
252
    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
253
    meshes[3].setEffectAssociation(0,8,0);
254
    meshes[4] = meshes[3].copy(true);
255
    meshes[4].setEffectAssociation(0,16,0);
256
    meshes[5] = meshes[3].copy(true);
257
    meshes[5].setEffectAssociation(0,32,0);
258
259
    return new MeshJoined(meshes);
260
    }
261
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263
264
  MeshBase createFacesSkewbFace()
265
    {
266
    MeshBase[] meshes = new MeshBase[5];
267
268
    float E = SQ2/4;
269
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
270 55f20739 Leszek Koltunski
    float[] bands0 = computeBands(0.051f,35,E/2,0.9f,7);
271 7edab735 Leszek Koltunski
272
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
273
    meshes[0].setEffectAssociation(0,1,0);
274
275 6af1e973 Leszek Koltunski
    float[] vertices1 = { -E,-SQ3*E, -E*0.7f,-SQ3*E, +E*0.7f,-SQ3*E, +E,-SQ3*E, 0,0 };
276 7edab735 Leszek Koltunski
    float[] bands1 = computeBands(0,0,1,0,3);
277
278
    meshes[1] = new MeshPolygon(vertices1,bands1,0,0);
279
    meshes[1].setEffectAssociation(0,2,0);
280
    meshes[2] = meshes[1].copy(true);
281
    meshes[2].setEffectAssociation(0,4,0);
282
    meshes[3] = meshes[1].copy(true);
283
    meshes[3].setEffectAssociation(0,8,0);
284
    meshes[4] = meshes[1].copy(true);
285
    meshes[4].setEffectAssociation(0,16,0);
286
287
    return new MeshJoined(meshes);
288
    }
289
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291
292
  MeshBase createFacesOcta()
293
    {
294 55f20739 Leszek Koltunski
    MeshBase[] meshes = new MeshPolygon[8];
295 7edab735 Leszek Koltunski
296 55f20739 Leszek Koltunski
    float E = 0.75f;
297 7edab735 Leszek Koltunski
    float F = 0.5f;
298
    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
299 55f20739 Leszek Koltunski
    float[] bands = computeBands(0.05f,35,F,0.8f,6);
300 7edab735 Leszek Koltunski
301
    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
302 55f20739 Leszek Koltunski
    meshes[0].setEffectAssociation(0,1,0);
303
    meshes[1] = meshes[0].copy(true);
304
    meshes[1].setEffectAssociation(0,2,0);
305
    meshes[2] = meshes[0].copy(true);
306
    meshes[2].setEffectAssociation(0,4,0);
307
    meshes[3] = meshes[0].copy(true);
308
    meshes[3].setEffectAssociation(0,8,0);
309
    meshes[4] = meshes[0].copy(true);
310
    meshes[4].setEffectAssociation(0,16,0);
311
    meshes[5] = meshes[0].copy(true);
312
    meshes[5].setEffectAssociation(0,32,0);
313
    meshes[6] = meshes[0].copy(true);
314
    meshes[6].setEffectAssociation(0,64,0);
315
    meshes[7] = meshes[0].copy(true);
316
    meshes[7].setEffectAssociation(0,128,0);
317 7edab735 Leszek Koltunski
318
    return new MeshJoined(meshes);
319
    }
320
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
323
  MeshBase createFacesTetra()
324
    {
325
    MeshBase[] meshes = new MeshBase[4];
326
327 55f20739 Leszek Koltunski
    float E = 0.75f;
328 7edab735 Leszek Koltunski
    float F = 0.5f;
329
    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
330 55f20739 Leszek Koltunski
    float[] bands = computeBands(0.05f,35,F,0.8f,6);
331 7edab735 Leszek Koltunski
332
    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
333 55f20739 Leszek Koltunski
    meshes[0].setEffectAssociation(0,1,0);
334
    meshes[1] = meshes[0].copy(true);
335
    meshes[1].setEffectAssociation(0,2,0);
336
    meshes[2] = meshes[0].copy(true);
337
    meshes[2].setEffectAssociation(0,4,0);
338
    meshes[3] = meshes[0].copy(true);
339
    meshes[3].setEffectAssociation(0,8,0);
340 7edab735 Leszek Koltunski
341
    return new MeshJoined(meshes);
342
    }
343
344
///////////////////////////////////////////////////////////////////////////////////////////////////
345
346
  MeshBase createFacesDino()
347
    {
348 55f20739 Leszek Koltunski
    MeshBase[] meshes = new MeshPolygon[4];
349 7edab735 Leszek Koltunski
350
    float E = 0.5f*SQ2;
351
    float F = 0.5f;
352
    float[] vertices0 = { -F,F/3, 0,-2*F/3, +F,F/3 };
353 55f20739 Leszek Koltunski
    float[] bands0 = computeBands(0.028f,30,F/3,0.8f,7);
354 7edab735 Leszek Koltunski
355
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 5);
356
    meshes[0].setEffectAssociation(0,1,0);
357
    meshes[1] = meshes[0].copy(true);
358
    meshes[1].setEffectAssociation(0,2,0);
359
360
    float[] vertices1 = { -E/2,-E*(SQ3/6), E/2,-E*(SQ3/6), 0,E*(SQ3/3) };
361
    float[] bands1 = computeBands(0.02f,45,F/3,0.2f,3);
362
363
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
364
    meshes[2].setEffectAssociation(0,4,0);
365
    meshes[3] = meshes[2].copy(true);
366
    meshes[3].setEffectAssociation(0,8,0);
367
368
    return new MeshJoined(meshes);
369
    }
370
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372
373
  MeshBase createFacesHelicopterCorner()
374
    {
375
    MeshBase[] meshes = new MeshBase[6];
376
377
    float E = 0.5f;
378
    float F = SQ2/4;
379
    float G = 1.0f/12;
380
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
381 55f20739 Leszek Koltunski
    float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7);
382 7edab735 Leszek Koltunski
383
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
384
    meshes[0].setEffectAssociation(0,1,0);
385
    meshes[1] = meshes[0].copy(true);
386
    meshes[1].setEffectAssociation(0,2,0);
387
    meshes[2] = meshes[0].copy(true);
388
    meshes[2].setEffectAssociation(0,4,0);
389
390
    float[] vertices1 = { -F,-G, 0,-G, +F,-G, 0,2*G };
391
    float[] bands1 = computeBands(0.00f,0,0,0.0f,3);
392
    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
393
    meshes[3].setEffectAssociation(0,8,0);
394
    meshes[4] = meshes[3].copy(true);
395
    meshes[4].setEffectAssociation(0,16,0);
396
    meshes[5] = meshes[3].copy(true);
397
    meshes[5].setEffectAssociation(0,32,0);
398
399
    return new MeshJoined(meshes);
400
    }
401
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403
404
  MeshBase createFacesHelicopterFace()
405
    {
406
    MeshBase[] meshes = new MeshBase[4];
407
408
    float E = 0.5f;
409
    float F = SQ2/4;
410
    float G = 1.0f/12;
411
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
412 55f20739 Leszek Koltunski
    float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7);
413 7edab735 Leszek Koltunski
414
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
415
    meshes[0].setEffectAssociation(0,1,0);
416
417
    float[] vertices1 = { -F,-G, +F,-G, 0,2*G};
418
    float[] bands1 = computeBands(0.01f,45,F,0.0f,3);
419
420
    meshes[1] = new MeshPolygon(vertices1, bands1, 1, 3);
421
    meshes[1].setEffectAssociation(0,2,0);
422
423
    float[] vertices2 = { -E/2,-F/3, +E/2,-F/3, 0,2*F/3};
424
425
    meshes[2] = new MeshPolygon(vertices2, bands1, 1, 3);
426
    meshes[2].setEffectAssociation(0,4,0);
427
    meshes[3] = meshes[2].copy(true);
428
    meshes[3].setEffectAssociation(0,8,0);
429
430
    return new MeshJoined(meshes);
431
    }
432
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434
435
  MeshBase createFacesRediEdge()
436
    {
437 55f20739 Leszek Koltunski
    MeshBase[] meshes = new MeshPolygon[6];
438 7edab735 Leszek Koltunski
439 55f20739 Leszek Koltunski
    float F = 0.25f;
440 7edab735 Leszek Koltunski
    float[] vertices0 = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F };
441 55f20739 Leszek Koltunski
    float[] bands0 = computeBands(0.038f,35,F,0.7f,7);
442 7edab735 Leszek Koltunski
443
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 2);
444
    meshes[0].setEffectAssociation(0,1,0);
445
    meshes[1] = meshes[0].copy(true);
446
    meshes[1].setEffectAssociation(0,2,0);
447
448 55f20739 Leszek Koltunski
    float[] bands1 = computeBands(0.02f,35,F/2,0.2f,3);
449 7edab735 Leszek Koltunski
    float[] vertices1 = { -F/2, +F/2, -F/2, -1.5f*F, 1.5f*F, +F/2 };
450
451
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
452
    meshes[2].setEffectAssociation(0,4,0);
453
    meshes[3] = meshes[2].copy(true);
454
    meshes[3].setEffectAssociation(0,8,0);
455
456
    float X = 0.25f*SQ2;
457
    float Y = SQ6/16;
458
    float[] vertices2 = { -X, Y, -1.5f*X, -Y, +1.5f*X, -Y, +X, Y };
459
460
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 1);
461
    meshes[4].setEffectAssociation(0,16,0);
462
    meshes[5] = meshes[4].copy(true);
463
    meshes[5].setEffectAssociation(0,32,0);
464
465
    return new MeshJoined(meshes);
466
    }
467
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
470
  MeshBase createFacesRediCorner()
471
    {
472 55f20739 Leszek Koltunski
    MeshBase[] meshes = new MeshBase[6];
473 7edab735 Leszek Koltunski
474
    float E = 0.5f;
475 55f20739 Leszek Koltunski
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
476
    float[] bands0 = computeBands(0.06f,35,E,0.7f,6);
477 7edab735 Leszek Koltunski
478 55f20739 Leszek Koltunski
    meshes[0] = new MeshPolygon(vertices0,bands0,2,2);
479 7edab735 Leszek Koltunski
    meshes[0].setEffectAssociation(0,1,0);
480
    meshes[1] = meshes[0].copy(true);
481
    meshes[1].setEffectAssociation(0,2,0);
482
    meshes[2] = meshes[0].copy(true);
483
    meshes[2].setEffectAssociation(0,4,0);
484
485 55f20739 Leszek Koltunski
    float F = 0.5f;
486 7edab735 Leszek Koltunski
    float X = 0.5f;
487
    float G = 0.72f;
488 55f20739 Leszek Koltunski
    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 };
489
    float[] bands1 = computeBands(0.0f,0,1.0f,0.0f,2);
490 7edab735 Leszek Koltunski
491 55f20739 Leszek Koltunski
    meshes[3] = new MeshPolygon(vertices1,bands1,0,0);
492 7edab735 Leszek Koltunski
    meshes[3].setEffectAssociation(0,8,0);
493
    meshes[4] = meshes[3].copy(true);
494
    meshes[4].setEffectAssociation(0,16,0);
495
    meshes[5] = meshes[3].copy(true);
496
    meshes[5].setEffectAssociation(0,32,0);
497
498
    return new MeshJoined(meshes);
499
    }
500
501 55f20739 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
502
503
  MeshBase createFacesIvyCorner()
504
    {
505
    MeshBase[] meshes = new MeshBase[6];
506
507
    final float angle = (float)Math.PI/(2*IVY_N);
508
    final float CORR  = 1.0f - IVY_D*SQ2;
509
    final float DIST  = 0.4f;
510
    final float CORR2 = 0.5f;
511
    float[] vertices = new float[2*(IVY_N+1)+6];
512
513
    vertices[0] = (-0.5f+IVY_D-DIST)*CORR2;
514
    vertices[1] = ( 0.5f      -DIST)*CORR2;
515
    vertices[2] = ( 0.5f      -DIST)*CORR2;
516
    vertices[3] = ( 0.5f      -DIST)*CORR2;
517
    vertices[4] = ( 0.5f      -DIST)*CORR2;
518
    vertices[5] = (-0.5f+IVY_D-DIST)*CORR2;
519
520
    for(int i=0; i<=IVY_N; i++)
521
      {
522
      float sin = (float)Math.sin(i*angle);
523
      float cos = (float)Math.cos(i*angle);
524
525
      vertices[2*i+6] = (CORR*(cos-0.5f)-DIST)*CORR2;
526
      vertices[2*i+7] = (CORR*(sin-0.5f)-DIST)*CORR2;
527
      }
528
529
    float[] bands0 = computeBands(+0.02f,18,0.2f,0.5f,5);
530
    float[] bands1 = computeBands(-0.10f,20,0.2f,0.0f,2);
531
532
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
533
    meshes[0].setEffectAssociation(0,1,0);
534
    meshes[1] = meshes[0].copy(true);
535
    meshes[1].setEffectAssociation(0,2,0);
536
    meshes[2] = meshes[0].copy(true);
537
    meshes[2].setEffectAssociation(0,4,0);
538
    meshes[3] = new MeshPolygon(vertices,bands1,0,0);
539
    meshes[3].setEffectAssociation(0,8,0);
540
    meshes[4] = meshes[3].copy(true);
541
    meshes[4].setEffectAssociation(0,16,0);
542
    meshes[5] = meshes[3].copy(true);
543
    meshes[5].setEffectAssociation(0,32,0);
544
545
    return new MeshJoined(meshes);
546
    }
547
548
///////////////////////////////////////////////////////////////////////////////////////////////////
549
550
  MeshBase createFacesIvyFace()
551
    {
552
    MeshBase[] meshes = new MeshBase[2];
553
554
    final float angle = (float)Math.PI/(2*IVY_N);
555
    final float CORR  = 1.0f - IVY_D*SQ2;
556
    float[] vertices = new float[4*IVY_N];
557
558
    for(int i=0; i<IVY_N; i++)
559
      {
560
      float sin = (float)Math.sin(i*angle);
561
      float cos = (float)Math.cos(i*angle);
562
563
      vertices[2*i          ] = CORR*(0.5f-cos);
564
      vertices[2*i+1        ] = CORR*(0.5f-sin);
565
      vertices[2*i  +2*IVY_N] = CORR*(cos-0.5f);
566
      vertices[2*i+1+2*IVY_N] = CORR*(sin-0.5f);
567
      }
568
569
    float[] bands0 = computeBands(+0.05f,35,0.5f,0.5f,5);
570
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
571
572
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
573
    meshes[0].setEffectAssociation(0,1,0);
574
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
575
    meshes[1].setEffectAssociation(0,2,0);
576
577
    return new MeshJoined(meshes);
578
    }
579
580
///////////////////////////////////////////////////////////////////////////////////////////////////
581
// EFFECTS
582 7edab735 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
583
584
  VertexEffect[] createVertexEffectsCube()
585
    {
586
    Static3D axisY   = new Static3D(0,1,0);
587
    Static3D axisX   = new Static3D(1,0,0);
588
    Static3D center  = new Static3D(0,0,0);
589
    Static1D angle90 = new Static1D(90);
590
    Static1D angle180= new Static1D(180);
591
    Static1D angle270= new Static1D(270);
592
593
    VertexEffect[] effect = new VertexEffect[6];
594
595
    effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
596
    effect[1] = new VertexEffectRotate( angle180, axisX, center );
597
    effect[2] = new VertexEffectRotate( angle90 , axisX, center );
598
    effect[3] = new VertexEffectRotate( angle270, axisX, center );
599
    effect[4] = new VertexEffectRotate( angle270, axisY, center );
600
    effect[5] = new VertexEffectRotate( angle90 , axisY, center );
601
602
    effect[0].setMeshAssociation(63,-1);  // all 6 sides
603
    effect[1].setMeshAssociation(32,-1);  // back
604
    effect[2].setMeshAssociation( 8,-1);  // bottom
605
    effect[3].setMeshAssociation( 4,-1);  // top
606
    effect[4].setMeshAssociation( 2,-1);  // left
607
    effect[5].setMeshAssociation( 1,-1);  // right
608
609
    return effect;
610
    }
611
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613
614
  VertexEffect[] createVertexEffectsSkewbCorner()
615
    {
616
    float E = 0.5f;
617
618
    Static3D axisX  = new Static3D(1,0,0);
619
    Static3D axisY  = new Static3D(0,1,0);
620
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
621
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
622
    Static1D angle1 = new Static1D(+90);
623
    Static1D angle2 = new Static1D(-90);
624
    Static1D angle3 = new Static1D(-15);
625
    Static1D angle4 = new Static1D((float)((180.0f/Math.PI)*Math.acos(SQ3/3)));
626
    Static1D angle5 = new Static1D(120);
627
    Static1D angle6 = new Static1D(240);
628
    Static3D center1= new Static3D(0,0,0);
629
    Static3D center2= new Static3D(-0.5f,-0.5f,-0.5f);
630
    Static3D move1  = new Static3D(-E/4,-E/4,0);
631 55f20739 Leszek Koltunski
    Static3D move2  = new Static3D(-0.5f+SQ2/4,-0.5f+SQ6/8,-0.5f);
632 7edab735 Leszek Koltunski
633
    VertexEffect[] effect = new VertexEffect[10];
634
635
    effect[0] = new VertexEffectMove(move1);
636
    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
637
    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
638
    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
639
    effect[4] = new VertexEffectMove(move2);
640
    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
641
    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
642
    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
643
    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
644
    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
645
646
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
647
    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
648
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
649
    effect[3].setMeshAssociation( 4,-1);  // mesh 2
650
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
651
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
652
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
653
    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
654
    effect[8].setMeshAssociation(16,-1);  // mesh 4
655
    effect[9].setMeshAssociation(32,-1);  // mesh 5
656
657
    return effect;
658
    }
659
660
///////////////////////////////////////////////////////////////////////////////////////////////////
661
662
  VertexEffect[] createVertexEffectsSkewbFace()
663
    {
664
    Static3D center = new Static3D(0,0,0);
665
    Static3D axisX  = new Static3D(1,0,0);
666
    Static3D axisZ  = new Static3D(0,0,1);
667
    float angle = -(float)((180.0f/Math.PI)*Math.acos(SQ3/3));
668
669
    VertexEffect[] effect = new VertexEffect[6];
670
671
    effect[0] = new VertexEffectRotate( new Static1D(angle), axisX, center);
672
    effect[1] = new VertexEffectRotate( new Static1D(  135), axisZ, center);
673
    effect[2] = new VertexEffectRotate( new Static1D(   45), axisZ, center);
674
    effect[3] = new VertexEffectRotate( new Static1D(  -45), axisZ, center);
675
    effect[4] = new VertexEffectRotate( new Static1D( -135), axisZ, center);
676
    effect[5] = new VertexEffectMove( new Static3D(0,0,-0.5f) );
677
678
    effect[0].setMeshAssociation(30,-1);  // meshes 1,2,3,4
679
    effect[1].setMeshAssociation( 2,-1);  // mesh 1
680
    effect[2].setMeshAssociation( 5,-1);  // meshes 0,2
681
    effect[3].setMeshAssociation( 8,-1);  // mesh 3
682
    effect[4].setMeshAssociation(16,-1);  // mesh 4
683
    effect[5].setMeshAssociation(30,-1);  // meshes 1,2,3,4
684
685
    return effect;
686
    }
687
688
///////////////////////////////////////////////////////////////////////////////////////////////////
689
690
  VertexEffect[] createVertexEffectsOcta()
691
    {
692
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
693
    Static1D angle1= new Static1D( 90);
694
    Static1D angle2= new Static1D(180);
695
    Static1D angle3= new Static1D(270);
696
    Static3D move1 = new Static3D(0,SQ2/2-SQ3/3,0);
697
    Static3D axisX = new Static3D(1,0,0);
698
    Static3D axisY = new Static3D(0,1,0);
699
    Static3D cent0 = new Static3D(0,0,0);
700
    Static3D cent1 = new Static3D(0,SQ2/2,0);
701
    Static3D flipY = new Static3D( 1,-1, 1);
702 55f20739 Leszek Koltunski
    Static3D scale = new Static3D( 1, 2*SQ3/3, 1);
703 7edab735 Leszek Koltunski
704 55f20739 Leszek Koltunski
    VertexEffect[] effect = new VertexEffect[7];
705 7edab735 Leszek Koltunski
706 55f20739 Leszek Koltunski
    effect[0] = new VertexEffectScale(scale);
707
    effect[1] = new VertexEffectMove(move1);
708
    effect[2] = new VertexEffectRotate(alpha , axisX, cent1);
709
    effect[3] = new VertexEffectRotate(angle1, axisY, cent0);
710
    effect[4] = new VertexEffectRotate(angle2, axisY, cent0);
711
    effect[5] = new VertexEffectRotate(angle3, axisY, cent0);
712
    effect[6] = new VertexEffectScale(flipY);
713 7edab735 Leszek Koltunski
714 55f20739 Leszek Koltunski
    effect[3].setMeshAssociation ( 34,-1); // apply to meshes 1 & 5
715
    effect[4].setMeshAssociation ( 68,-1); // apply to meshes 2 & 6
716
    effect[5].setMeshAssociation (136,-1); // apply to meshes 3 & 7
717
    effect[6].setMeshAssociation (240,-1); // apply to meshes 4,5,6,7
718 7edab735 Leszek Koltunski
719
    return effect;
720
    }
721
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723
724
  VertexEffect[] createVertexEffectsTetra()
725
    {
726
    Static3D flipZ = new Static3D( 1, 1,-1);
727
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
728
    Static1D angle1= new Static1D( 90);
729
    Static1D angle2= new Static1D(180);
730
    Static3D move1 = new Static3D(0,SQ2/4-SQ3/6,0);
731
    Static3D axisX = new Static3D(1,0,0);
732
    Static3D axisY = new Static3D(0,1,0);
733
    Static3D axisZ = new Static3D(0,0,1);
734
    Static3D cent0 = new Static3D(0,0,0);
735
    Static3D cent1 = new Static3D(0,SQ2/4,0);
736 55f20739 Leszek Koltunski
    Static3D scale = new Static3D( 1, 2*SQ3/3, 1);
737 7edab735 Leszek Koltunski
738 55f20739 Leszek Koltunski
    VertexEffect[] effect = new VertexEffect[7];
739 7edab735 Leszek Koltunski
740 55f20739 Leszek Koltunski
    effect[0] = new VertexEffectScale(scale);
741
    effect[1] = new VertexEffectRotate(angle2, axisZ, cent0);
742
    effect[2] = new VertexEffectMove(move1);
743
    effect[3] = new VertexEffectRotate(alpha , axisX, cent1);
744
    effect[4] = new VertexEffectScale(flipZ);
745
    effect[5] = new VertexEffectRotate(angle1, axisY, cent0);
746
    effect[6] = new VertexEffectRotate(angle2, axisZ, cent0);
747
748
    effect[4].setMeshAssociation(10,-1); // meshes 1 & 3
749 7edab735 Leszek Koltunski
    effect[5].setMeshAssociation(12,-1); // meshes 2 & 3
750 55f20739 Leszek Koltunski
    effect[6].setMeshAssociation(12,-1); // meshes 2 & 3
751 7edab735 Leszek Koltunski
752
    return effect;
753
    }
754
755
///////////////////////////////////////////////////////////////////////////////////////////////////
756
757
  VertexEffect[] createVertexEffectsDino()
758
    {
759
    float E = 0.5f*SQ2;
760
    float F = 0.5f;
761
    final float ANGLE = (float)((180/Math.PI)*(Math.atan(SQ2)));
762
763
    Static1D angle1 = new Static1D(-ANGLE);
764
    Static1D angle2 = new Static1D(+ANGLE);
765
    Static3D axisX  = new Static3D(1,0,0);
766
    Static3D axisY  = new Static3D(0,1,0);
767
    Static3D axisZ  = new Static3D(0,-1,1);
768
    Static3D center0= new Static3D(0,0,0);
769
    Static3D center1= new Static3D(0,-3*F,0);
770
771
    VertexEffect[] effect = new VertexEffect[10];
772
773
    effect[0] = new VertexEffectScale ( new Static3D(3,3,3) );
774
    effect[1] = new VertexEffectMove  ( new Static3D(0,-F,0) );
775
    effect[2] = new VertexEffectRotate( new Static1D(90), axisX, center0 );
776
    effect[3] = new VertexEffectScale ( new Static3D(1,-1,1) );
777
    effect[4] = new VertexEffectMove  ( new Static3D(3*E/2,E*(SQ3/2)-3*F,0) );
778
    effect[5] = new VertexEffectRotate( new Static1D(+90), axisY, center1 );
779
    effect[6] = new VertexEffectScale ( new Static3D(-1,1,1) );
780
    effect[7] = new VertexEffectRotate( new Static1D( 45), axisX, center1 );
781
    effect[8] = new VertexEffectRotate( angle1           , axisZ, center1 );
782
    effect[9] = new VertexEffectRotate( angle2           , axisZ, center1 );
783
784
    effect[0].setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
785
    effect[1].setMeshAssociation( 3,-1);  // apply to meshes 0,1
786
    effect[2].setMeshAssociation( 2,-1);  // apply to mesh 1
787
    effect[3].setMeshAssociation( 2,-1);  // apply to mesh 0
788
    effect[4].setMeshAssociation(12,-1);  // apply to meshes 2,3
789
    effect[5].setMeshAssociation(12,-1);  // apply to meshes 2,3
790
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
791
    effect[7].setMeshAssociation(12,-1);  // apply to meshes 2,3
792
    effect[8].setMeshAssociation( 4,-1);  // apply to mesh 2
793
    effect[9].setMeshAssociation( 8,-1);  // apply to mesh 3
794
795
    return effect;
796
    }
797
798
///////////////////////////////////////////////////////////////////////////////////////////////////
799
800
  VertexEffect[] createVertexEffectsHelicopterCorner()
801
    {
802
    float E = 0.5f;
803
804
    Static3D axisX  = new Static3D(1,0,0);
805
    Static3D axisY  = new Static3D(0,1,0);
806
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
807
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
808
    Static1D angle1 = new Static1D(+90);
809
    Static1D angle2 = new Static1D(-90);
810
    Static1D angle3 = new Static1D(-135);
811
    Static1D angle4 = new Static1D(90);
812
    Static1D angle5 = new Static1D(120);
813
    Static1D angle6 = new Static1D(240);
814
    Static3D center1= new Static3D(0,0,0);
815
    Static3D center2= new Static3D(-0.25f,-0.25f,-0.25f);
816
    Static3D move1  = new Static3D(-E/4,-E/4,0);
817
    Static3D move2  = new Static3D(-0.25f,(-1.0f/6)-0.25f,-0.25f);
818
819
    VertexEffect[] effect = new VertexEffect[10];
820
821
    effect[0] = new VertexEffectMove(move1);
822
    effect[1] = new VertexEffectScale(new Static3D(1,1,-1));
823
    effect[2] = new VertexEffectRotate(angle1,axisX,center1);
824
    effect[3] = new VertexEffectRotate(angle2,axisY,center1);
825
    effect[4] = new VertexEffectMove(move2);
826
    effect[5] = new VertexEffectRotate(angle1,axisX,center2);
827
    effect[6] = new VertexEffectRotate(angle3,axisY,center2);
828
    effect[7] = new VertexEffectRotate(angle4,axis0,center2);
829
    effect[8] = new VertexEffectRotate(angle5,axis1,center2);
830
    effect[9] = new VertexEffectRotate(angle6,axis1,center2);
831
832
    effect[0].setMeshAssociation( 7,-1);  // meshes 0,1,2
833
    effect[1].setMeshAssociation( 6,-1);  // meshes 1,2
834
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
835
    effect[3].setMeshAssociation( 4,-1);  // mesh 2
836
    effect[4].setMeshAssociation(56,-1);  // meshes 3,4,5
837
    effect[5].setMeshAssociation(56,-1);  // meshes 3,4,5
838
    effect[6].setMeshAssociation(56,-1);  // meshes 3,4,5
839
    effect[7].setMeshAssociation(56,-1);  // meshes 3,4,5
840
    effect[8].setMeshAssociation(16,-1);  // mesh 4
841
    effect[9].setMeshAssociation(32,-1);  // mesh 5
842
843
    return effect;
844
    }
845
846
///////////////////////////////////////////////////////////////////////////////////////////////////
847
848
  VertexEffect[] createVertexEffectsHelicopterFace()
849
    {
850
    float E = 0.5f;
851
    float F = SQ2/4;
852
853
    Static3D move0  = new Static3D(-E/4, -E/4, 0);
854
    Static3D move1  = new Static3D(-(SQ2/24)-E/2, -(SQ2/24)-E/2, 0);
855
    Static3D move2  = new Static3D(-E/2, F/3, 0);
856
    Static3D move3  = new Static3D(+E/2, F/3, 0);
857
    Static3D move4  = new Static3D(+E/3,+E/3, 0);
858
    Static1D angle1 = new Static1D(135);
859
    Static1D angle2 = new Static1D(90);
860
    Static1D angle3 = new Static1D(-90);
861
    Static1D angle4 = new Static1D(-135);
862
    Static3D axisX  = new Static3D(1,0,0);
863
    Static3D axisY  = new Static3D(0,1,0);
864
    Static3D axisZ  = new Static3D(0,0,1);
865
    Static3D axis1  = new Static3D(1,-1,0);
866
    Static3D center = new Static3D(0,0,0);
867
    Static3D center1= new Static3D(-E/2,-E/2,0);
868
869
    VertexEffect[] effect = new VertexEffect[10];
870
871
    effect[0] = new VertexEffectMove(move0);
872
    effect[1] = new VertexEffectRotate(angle1, axisZ, center);
873
    effect[2] = new VertexEffectMove(move1);
874
    effect[3] = new VertexEffectRotate(angle2, axis1, center1);
875
    effect[4] = new VertexEffectMove(move2);
876
    effect[5] = new VertexEffectMove(move3);
877
    effect[6] = new VertexEffectRotate(angle3, axisZ, center);
878
    effect[7] = new VertexEffectRotate(angle4, axisX, center);
879
    effect[8] = new VertexEffectRotate(angle1, axisY, center);
880
    effect[9] = new VertexEffectMove(move4);
881
882
    effect[0].setMeshAssociation( 1,-1);  // mesh 0
883
    effect[1].setMeshAssociation( 2,-1);  // mesh 1
884
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
885
    effect[3].setMeshAssociation( 2,-1);  // mesh 1
886
    effect[4].setMeshAssociation( 4,-1);  // mesh 2
887
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
888
    effect[6].setMeshAssociation( 8,-1);  // mesh 3
889
    effect[7].setMeshAssociation( 4,-1);  // mesh 2
890
    effect[8].setMeshAssociation( 8,-1);  // mesh 3
891
    effect[9].setMeshAssociation(15,-1);  // meshes 0,1,2,3
892
893
    return effect;
894
    }
895
896
///////////////////////////////////////////////////////////////////////////////////////////////////
897
898
  VertexEffect[] createVertexEffectsRediEdge()
899
    {
900
    Static3D move0 = new Static3D(0.0f, -0.5f, 0.0f);
901
    Static3D move1 = new Static3D(0.25f, -0.25f, 0.0f);
902
    Static3D move2 = new Static3D(0.5f, 0.0f, 0.0f);
903
    Static3D move3 = new Static3D(0.0f, (SQ3-6)/8, (SQ3-6)/8);
904
    Static3D flipZ = new Static3D(1,1,-1);
905
    Static3D flipX = new Static3D(-1,1,1);
906
    Static3D scale = new Static3D(2,2,2);
907
    Static3D cent0 = new Static3D(0,0, 0);
908
    Static3D cent1 = new Static3D(0,0, -1.5f);
909
    Static3D axisX = new Static3D(1,0, 0);
910
    Static3D axisY = new Static3D(0,1, 0);
911
    Static3D axis  = new Static3D(0,SQ2/2,-SQ2/2);
912
    Static1D angle1= new Static1D(90);
913
    Static1D angle2= new Static1D(45);
914
    Static1D angle3= new Static1D( (float)(180/Math.PI*Math.acos(SQ3/3)) );
915
916
    VertexEffect[] effect = new VertexEffect[12];
917
918
    effect[0] = new VertexEffectScale(scale);
919
    effect[1] = new VertexEffectMove(move0);
920
    effect[2] = new VertexEffectScale(flipZ);
921
    effect[3] = new VertexEffectRotate(angle1,axisX,cent0);
922
    effect[4] = new VertexEffectMove(move1);
923
    effect[5] = new VertexEffectRotate(angle1,axisY,cent0);
924
    effect[6] = new VertexEffectMove(move2);
925
    effect[7] = new VertexEffectScale(flipX);
926
    effect[8] = new VertexEffectRotate(angle2,axisX,cent0);
927
    effect[9] = new VertexEffectMove(move3);
928
    effect[10]= new VertexEffectRotate(angle3,axis ,cent1);
929
    effect[11]= new VertexEffectScale(flipX);
930
931
    effect[0].setMeshAssociation(63,-1);  // meshes 0,1,2,3,4,5
932
    effect[1].setMeshAssociation( 3,-1);  // meshes 0,1
933
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
934
    effect[3].setMeshAssociation( 2,-1);  // mesh 1
935
    effect[4].setMeshAssociation(12,-1);  // meshes 2,3
936
    effect[5].setMeshAssociation(60,-1);  // meshes 2,3,4,5
937
    effect[6].setMeshAssociation(12,-1);  // meshes 2,3
938
    effect[7].setMeshAssociation( 8,-1);  // mesh 3
939
    effect[8].setMeshAssociation(48,-1);  // meshes 4,5
940
    effect[9].setMeshAssociation(48,-1);  // meshes 4,5
941
    effect[10].setMeshAssociation(48,-1); // meshes 4,5
942
    effect[11].setMeshAssociation(32,-1); // mesh 5
943
944
    return effect;
945
    }
946
947
///////////////////////////////////////////////////////////////////////////////////////////////////
948
949
  VertexEffect[] createVertexEffectsRediCorner()
950
    {
951
    Static3D axisY   = new Static3D(0,1,0);
952
    Static3D axisX   = new Static3D(1,0,0);
953
    Static3D axisZ   = new Static3D(0,0,1);
954
    Static3D center  = new Static3D(0,0,0);
955
    Static1D angle90 = new Static1D(90);
956
    Static1D angle270= new Static1D(270);
957
    Static1D angle45 = new Static1D(-45);
958 55f20739 Leszek Koltunski
    Static3D scale   = new Static3D(1.0f, SQ2, 1.0f);
959 7edab735 Leszek Koltunski
960 55f20739 Leszek Koltunski
    VertexEffect[] effect = new VertexEffect[7];
961 7edab735 Leszek Koltunski
962
    effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
963
    effect[1] = new VertexEffectRotate( angle270, axisX, center );
964
    effect[2] = new VertexEffectRotate( angle90 , axisY, center );
965 55f20739 Leszek Koltunski
    effect[3] = new VertexEffectScale(scale);
966
    effect[4] = new VertexEffectRotate( angle45 , axisX, center );
967
    effect[5] = new VertexEffectRotate( angle90 , axisY, center );
968
    effect[6] = new VertexEffectRotate( angle270, axisZ, center );
969 7edab735 Leszek Koltunski
970
    effect[0].setMeshAssociation( 7,-1);  // 0,1,2
971
    effect[1].setMeshAssociation( 2,-1);  // 1
972
    effect[2].setMeshAssociation( 4,-1);  // 2
973 55f20739 Leszek Koltunski
    effect[3].setMeshAssociation(56,-1);  // 3,4,5
974
    effect[4].setMeshAssociation(56,-1);  // 3,4,5
975
    effect[5].setMeshAssociation(16,-1);  // 4
976
    effect[6].setMeshAssociation(32,-1);  // 5
977
978
    return effect;
979
    }
980
981
///////////////////////////////////////////////////////////////////////////////////////////////////
982
983
  VertexEffect[] createVertexEffectsIvyCorner()
984
    {
985
    float DIST=0.1f;
986
987
    Static3D axisX  = new Static3D(1,0,0);
988
    Static3D axisY  = new Static3D(0,1,0);
989
    Static1D angle1 = new Static1D(+90);
990
    Static1D angle2 = new Static1D(-90);
991
    Static3D center = new Static3D(0,0,0);
992
    Static3D move1  = new Static3D(-DIST,-DIST,0);
993
994
    VertexEffect[] effect = new VertexEffect[5];
995
996
    effect[0] = new VertexEffectScale(2.0f);
997
    effect[1] = new VertexEffectMove(move1);
998
    effect[2] = new VertexEffectScale(new Static3D(1,1,-1));
999
    effect[3] = new VertexEffectRotate(angle1,axisX,center);
1000
    effect[4] = new VertexEffectRotate(angle2,axisY,center);
1001
1002
    effect[2].setMeshAssociation(54,-1);  // meshes 1,2,4,5
1003
    effect[3].setMeshAssociation(18,-1);  // meshes 1,4
1004
    effect[4].setMeshAssociation(36,-1);  // meshes 2,5
1005 7edab735 Leszek Koltunski
1006
    return effect;
1007
    }
1008
1009
///////////////////////////////////////////////////////////////////////////////////////////////////
1010
// OBJECTS
1011
///////////////////////////////////////////////////////////////////////////////////////////////////
1012
// CUBE
1013
1014
  MeshBase createCubeMesh(int index)
1015
    {
1016
    MeshBase mesh = createFacesCube(index);
1017
    VertexEffect[] effects = createVertexEffectsCube();
1018
    for( VertexEffect effect : effects ) mesh.apply(effect);
1019
1020
    Static3D roundingCenter  = new Static3D(0,0,0);
1021
    Static3D[] vertices = new Static3D[8];
1022
    vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f);
1023
    vertices[1] = new Static3D(+0.5f,+0.5f,-0.5f);
1024
    vertices[2] = new Static3D(+0.5f,-0.5f,+0.5f);
1025
    vertices[3] = new Static3D(+0.5f,-0.5f,-0.5f);
1026
    vertices[4] = new Static3D(-0.5f,+0.5f,+0.5f);
1027
    vertices[5] = new Static3D(-0.5f,+0.5f,-0.5f);
1028
    vertices[6] = new Static3D(-0.5f,-0.5f,+0.5f);
1029
    vertices[7] = new Static3D(-0.5f,-0.5f,-0.5f);
1030 55f20739 Leszek Koltunski
1031 7edab735 Leszek Koltunski
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.12f);
1032
1033 55f20739 Leszek Koltunski
    mesh.mergeEffComponents();
1034
1035 7edab735 Leszek Koltunski
    return mesh;
1036
    }
1037
1038
///////////////////////////////////////////////////////////////////////////////////////////////////
1039
// SKEWB
1040
1041
  MeshBase createSkewbCornerMesh()
1042
    {
1043
    MeshBase mesh = createFacesSkewbCorner();
1044
    VertexEffect[] effects = createVertexEffectsSkewbCorner();
1045
    for( VertexEffect effect : effects ) mesh.apply(effect);
1046
1047
    float E = 0.5f;
1048
    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
1049
1050
    Static3D[] verticesType1 = new Static3D[1];
1051
    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
1052
    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
1053
1054
    Static3D[] verticesType2 = new Static3D[3];
1055
    verticesType2[0] = new Static3D(-E, 0, 0);
1056
    verticesType2[1] = new Static3D( 0,-E, 0);
1057
    verticesType2[2] = new Static3D( 0, 0,-E);
1058
    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
1059
1060 55f20739 Leszek Koltunski
    mesh.mergeEffComponents();
1061
1062 7edab735 Leszek Koltunski
    return mesh;
1063
    }
1064
1065
///////////////////////////////////////////////////////////////////////////////////////////////////
1066
1067
  MeshBase createSkewbFaceMesh()
1068
    {
1069
    MeshBase mesh = createFacesSkewbFace();
1070
    VertexEffect[] effects = createVertexEffectsSkewbFace();
1071
    for( VertexEffect effect : effects ) mesh.apply(effect);
1072
1073
    Static3D roundingCenter = new Static3D(0,0,-0.2f);
1074
    float E = SQ2/4;
1075
    Static3D[] vertices = new Static3D[4];
1076
    vertices[0] = new Static3D(-E*SQ2,      0, 0);
1077
    vertices[1] = new Static3D(+E*SQ2,      0, 0);
1078
    vertices[2] = new Static3D(     0, -E*SQ2, 0);
1079
    vertices[3] = new Static3D(     0, +E*SQ2, 0);
1080 55f20739 Leszek Koltunski
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.10f);
1081
1082
    mesh.mergeEffComponents();
1083
    mesh.addEmptyTexComponent();
1084 7edab735 Leszek Koltunski
1085
    return mesh;
1086
    }
1087
1088
///////////////////////////////////////////////////////////////////////////////////////////////////
1089
// SKEWB DIAMOND / PYRAMINX
1090
1091
  MeshBase createOctaMesh()
1092
    {
1093
    MeshBase mesh = createFacesOcta();
1094
    VertexEffect[] effects = createVertexEffectsOcta();
1095
    for( VertexEffect effect : effects ) mesh.apply(effect);
1096
1097
    Static3D roundingCenter = new Static3D(0,0,0);
1098
    Static3D[] vertices = new Static3D[6];
1099
    vertices[0] = new Static3D(    0, SQ2/2,    0 );
1100
    vertices[1] = new Static3D( 0.5f,     0, 0.5f );
1101
    vertices[2] = new Static3D(-0.5f,     0, 0.5f );
1102
    vertices[3] = new Static3D(    0,-SQ2/2,    0 );
1103
    vertices[4] = new Static3D(-0.5f,     0,-0.5f );
1104
    vertices[5] = new Static3D( 0.5f,     0,-0.5f );
1105 55f20739 Leszek Koltunski
1106 7edab735 Leszek Koltunski
    roundCorners(mesh,roundingCenter,vertices,0.06f,0.20f);
1107
1108 55f20739 Leszek Koltunski
    mesh.mergeEffComponents();
1109
1110 7edab735 Leszek Koltunski
    return mesh;
1111
    }
1112
1113
///////////////////////////////////////////////////////////////////////////////////////////////////
1114
1115
  MeshBase createTetraMesh()
1116
    {
1117
    MeshBase mesh = createFacesTetra();
1118
    VertexEffect[] effects = createVertexEffectsTetra();
1119
    for( VertexEffect effect : effects ) mesh.apply(effect);
1120
1121
    Static3D roundingCenter = new Static3D(0,0,0);
1122
    Static3D[] verticesRound = new Static3D[4];
1123
    verticesRound[0] = new Static3D(-0.5f,+SQ2/4,   0 );
1124
    verticesRound[1] = new Static3D(+0.5f,+SQ2/4,   0 );
1125
    verticesRound[2] = new Static3D(    0,-SQ2/4,+0.5f);
1126
    verticesRound[3] = new Static3D(    0,-SQ2/4,-0.5f);
1127
    roundCorners(mesh,roundingCenter,verticesRound,0.08f,0.15f);
1128
1129 55f20739 Leszek Koltunski
    mesh.mergeEffComponents();
1130
    mesh.addEmptyTexComponent();
1131
    mesh.addEmptyTexComponent();
1132
    mesh.addEmptyTexComponent();
1133
    mesh.addEmptyTexComponent();
1134
1135 7edab735 Leszek Koltunski
    return mesh;
1136
    }
1137
1138
///////////////////////////////////////////////////////////////////////////////////////////////////
1139
// DINO
1140
1141
  MeshBase createDinoMesh()
1142
    {
1143
    MeshBase mesh = createFacesDino();
1144
    VertexEffect[] effects = createVertexEffectsDino();
1145
    for( VertexEffect effect : effects ) mesh.apply(effect);
1146
1147
    float F = 0.5f;
1148
    Static3D roundingCenter = new Static3D(0.0f, -1.5f*F, -1.5f*F);
1149
    Static3D[] verticesRound = new Static3D[4];
1150
    verticesRound[0] = new Static3D(     0,-3*F,    0 );
1151
    verticesRound[1] = new Static3D(     0,   0, -3*F );
1152
    verticesRound[2] = new Static3D(  -3*F,   0,    0 );
1153
    verticesRound[3] = new Static3D(  +3*F,   0,    0 );
1154
    roundCorners(mesh,roundingCenter,verticesRound,0.10f,0.40f);
1155
1156 55f20739 Leszek Koltunski
    mesh.mergeEffComponents();
1157
1158 7edab735 Leszek Koltunski
    return mesh;
1159
    }
1160
1161
///////////////////////////////////////////////////////////////////////////////////////////////////
1162
// Helicopter
1163
1164
  MeshBase createHelicopterCornerMesh()
1165
    {
1166
    MeshBase mesh = createFacesHelicopterCorner();
1167
    VertexEffect[] effects = createVertexEffectsHelicopterCorner();
1168
    for( VertexEffect effect : effects ) mesh.apply(effect);
1169
1170
    float E = 0.5f;
1171
    Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2);
1172
1173
    Static3D[] verticesType1 = new Static3D[1];
1174
    verticesType1[0] = new Static3D(0.0f,0.0f,0.0f);
1175
    roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f);
1176
1177
    Static3D[] verticesType2 = new Static3D[3];
1178
    verticesType2[0] = new Static3D(-E, 0, 0);
1179
    verticesType2[1] = new Static3D( 0,-E, 0);
1180
    verticesType2[2] = new Static3D( 0, 0,-E);
1181 55f20739 Leszek Koltunski
    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
1182
1183
    mesh.mergeEffComponents();
1184 7edab735 Leszek Koltunski
1185
    return mesh;
1186
    }
1187
1188
///////////////////////////////////////////////////////////////////////////////////////////////////
1189
1190
  MeshBase createHelicopterFaceMesh()
1191
    {
1192
    MeshBase mesh = createFacesHelicopterFace();
1193
    VertexEffect[] effects = createVertexEffectsHelicopterFace();
1194
    for( VertexEffect effect : effects ) mesh.apply(effect);
1195
1196
    float E = 0.5f;
1197
    Static3D roundingCenter = new Static3D(-E/2 + E/3,-E/2 + E/3,-E/2);
1198
1199
    Static3D[] verticesType1 = new Static3D[1];
1200
    verticesType1[0] = new Static3D(E/3,E/3,0.0f);
1201
    roundCorners(mesh,roundingCenter,verticesType1,0.06f,0.15f);
1202
1203
    Static3D[] verticesType2 = new Static3D[2];
1204
    verticesType2[0] = new Static3D(-E+E/3, E/3  , 0);
1205
    verticesType2[1] = new Static3D( E/3  ,-E+E/3, 0);
1206 55f20739 Leszek Koltunski
    roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f);
1207
1208
    mesh.mergeEffComponents();
1209
    mesh.addEmptyTexComponent();
1210
    mesh.addEmptyTexComponent();
1211 7edab735 Leszek Koltunski
1212
    return mesh;
1213
    }
1214
1215
///////////////////////////////////////////////////////////////////////////////////////////////////
1216
// Redi cube
1217
1218
  MeshBase createRediEdgeMesh()
1219
    {
1220
    MeshBase mesh = createFacesRediEdge();
1221
    VertexEffect[] effects = createVertexEffectsRediEdge();
1222
    for( VertexEffect effect : effects ) mesh.apply(effect);
1223
1224
    Static3D center = new Static3D(0.0f,-0.75f,-0.75f);
1225 55f20739 Leszek Koltunski
    Static3D[] vertices = new Static3D[2];
1226 7edab735 Leszek Koltunski
    vertices[0] = new Static3D( 0.5f, 0.0f, 0.0f);
1227
    vertices[1] = new Static3D(-0.5f, 0.0f, 0.0f);
1228
    roundCorners(mesh,center,vertices,0.06f,0.20f);
1229
1230 55f20739 Leszek Koltunski
    mesh.mergeEffComponents();
1231
1232 7edab735 Leszek Koltunski
    return mesh;
1233
    }
1234
1235
///////////////////////////////////////////////////////////////////////////////////////////////////
1236
1237
  MeshBase createRediCornerMesh()
1238
    {
1239
    MeshBase mesh = createFacesRediCorner();
1240
    VertexEffect[] effects = createVertexEffectsRediCorner();
1241
    for( VertexEffect effect : effects ) mesh.apply(effect);
1242
1243
    Static3D center = new Static3D(0,0,0);
1244
    Static3D[] vertices = new Static3D[8];
1245
    vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f);
1246
    vertices[1] = new Static3D(+0.5f,+0.5f,-0.5f);
1247
    vertices[2] = new Static3D(+0.5f,-0.5f,+0.5f);
1248
    vertices[3] = new Static3D(+0.5f,-0.5f,-0.5f);
1249
    vertices[4] = new Static3D(-0.5f,+0.5f,+0.5f);
1250
    vertices[5] = new Static3D(-0.5f,+0.5f,-0.5f);
1251
    vertices[6] = new Static3D(-0.5f,-0.5f,+0.5f);
1252
    vertices[7] = new Static3D(-0.5f,-0.5f,-0.5f);
1253
1254
    roundCorners(mesh,center,vertices,0.06f,0.12f);
1255
1256 55f20739 Leszek Koltunski
    mesh.mergeEffComponents();
1257
1258
    return mesh;
1259
    }
1260
1261
///////////////////////////////////////////////////////////////////////////////////////////////////
1262
1263
  MeshBase createIvyCornerMesh()
1264
    {
1265
    MeshBase mesh = createFacesIvyCorner();
1266
    VertexEffect[] effects = createVertexEffectsIvyCorner();
1267
    for( VertexEffect effect : effects ) mesh.apply(effect);
1268
1269
    Static3D center = new Static3D(-0.5f,-0.5f,-0.5f);
1270
    Static3D[] vertices = new Static3D[4];
1271
    float DIST = IVY_D-0.5f;
1272
    vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f);
1273
    vertices[1] = new Static3D( DIST,+0.5f,+0.5f);
1274
    vertices[2] = new Static3D(+0.5f, DIST,+0.5f);
1275
    vertices[3] = new Static3D(+0.5f,+0.5f, DIST);
1276
1277
    roundCorners(mesh,center,vertices,0.06f,0.12f);
1278
1279
    mesh.mergeEffComponents();
1280
1281
    return mesh;
1282
    }
1283
1284
///////////////////////////////////////////////////////////////////////////////////////////////////
1285
1286
  MeshBase createIvyFaceMesh()
1287
    {
1288
    MeshBase mesh = createFacesIvyFace();
1289
1290
    float DIST = SQ2*(0.5f-IVY_D);
1291
    Static3D center = new Static3D(0.0f,0.0f,-0.0f);
1292
    Static3D[] vertices = new Static3D[2];
1293
    vertices[0] = new Static3D(+DIST,-DIST,+0.0f);
1294
    vertices[1] = new Static3D(-DIST,+DIST,+0.0f);
1295
1296
    roundCorners(mesh,center,vertices,0.10f,0.30f);
1297
1298
    mesh.mergeEffComponents();
1299
    mesh.addEmptyTexComponent();
1300
    mesh.addEmptyTexComponent();
1301
    mesh.addEmptyTexComponent();
1302
    mesh.addEmptyTexComponent();
1303
1304 7edab735 Leszek Koltunski
    return mesh;
1305
    }
1306
  }