Project

General

Profile

Download (51.7 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / CubitFactory.java @ 659f1180

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.objects;
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.mesh.MeshTriangle;
31
import org.distorted.library.type.Static1D;
32
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class CubitFactory
38
  {
39
  private static final float SQ2 = (float)Math.sqrt(2);
40
  private static final float SQ3 = (float)Math.sqrt(3);
41
  private static final float SQ6 = (float)Math.sqrt(6);
42

    
43
  private static CubitFactory mThis;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
  private CubitFactory()
48
    {
49

    
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public static CubitFactory getInstance()
55
    {
56
    if( mThis==null ) mThis = new CubitFactory();
57

    
58
    return mThis;
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
// CUBE
63

    
64
  MeshBase createCubeMesh(int index)
65
    {
66
    float[] bands;
67
    float D = 0.027f;
68
    float E = 0.5f-D;
69
    float[] vertices = { -E,-E, +E,-E, +E,+E, -E,+E };
70
    int extraI, extraV;
71

    
72
    switch(index)
73
      {
74
      case 0 : bands = new float[] { 1.0f    ,-D,
75
                                     1.0f-D/2,-D*0.55f,
76
                                     1.0f-D  ,-D*0.25f,
77
                                     1.0f-2*D, 0.0f,
78
                                     0.50f, 0.040f,
79
                                     0.0f, 0.048f };
80
               extraI = 2;
81
               extraV = 2;
82
               break;
83
      case 1 : bands = new float[] { 1.0f    ,-D,
84
                                     1.0f-D*1.2f,-D*0.55f,
85
                                     1.0f-2*D, 0.0f,
86
                                     0.50f, 0.040f,
87
                                     0.0f, 0.048f };
88
               extraI = 2;
89
               extraV = 2;
90
               break;
91
      case 2 : bands = new float[] { 1.0f    ,-D,
92
                                     1.0f-D*1.2f,-D*0.55f,
93
                                     1.0f-2*D, 0.0f,
94
                                     0.50f, 0.040f,
95
                                     0.0f, 0.048f };
96
               extraI = 1;
97
               extraV = 2;
98
               break;
99
      default: bands = new float[] { 1.0f    ,-D,
100
                                     1.0f-2*D, 0.0f,
101
                                     0.50f, 0.025f,
102
                                     0.0f, 0.030f };
103
               extraI = 1;
104
               extraV = 1;
105
               break;
106
      }
107

    
108
    return createCubeMesh(vertices,bands,extraI,extraV);
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  private MeshBase createCubeMesh(float[] vertices, float[] bands, int extraI, int extraV)
114
    {
115
    final int MESHES=6;
116
    int association = 1;
117
    MeshBase[] meshes = new MeshPolygon[MESHES];
118
    meshes[0] = new MeshPolygon(vertices,bands,extraI,extraV);
119
    meshes[0].setEffectAssociation(0,association,0);
120

    
121
    for(int i=1; i<MESHES; i++)
122
      {
123
      association <<=1;
124
      meshes[i] = meshes[0].copy(true);
125
      meshes[i].setEffectAssociation(0,association,0);
126
      }
127

    
128
    MeshBase mesh = new MeshJoined(meshes);
129

    
130
    Static3D axisY   = new Static3D(0,1,0);
131
    Static3D axisX   = new Static3D(1,0,0);
132
    Static3D center  = new Static3D(0,0,0);
133
    Static1D angle90 = new Static1D(90);
134
    Static1D angle180= new Static1D(180);
135
    Static1D angle270= new Static1D(270);
136

    
137
    float d1 = 1.0f;
138
    float d2 =-0.05f;
139
    float d3 = 0.12f;
140

    
141
    Static3D dCen0 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(+0.5f) );
142
    Static3D dCen1 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(-0.5f) );
143
    Static3D dCen2 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(+0.5f) );
144
    Static3D dCen3 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(-0.5f) );
145
    Static3D dCen4 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(+0.5f) );
146
    Static3D dCen5 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(-0.5f) );
147
    Static3D dCen6 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(+0.5f) );
148
    Static3D dCen7 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(-0.5f) );
149

    
150
    Static3D dVec0 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(+0.5f) );
151
    Static3D dVec1 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(-0.5f) );
152
    Static3D dVec2 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(+0.5f) );
153
    Static3D dVec3 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(-0.5f) );
154
    Static3D dVec4 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(+0.5f) );
155
    Static3D dVec5 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(-0.5f) );
156
    Static3D dVec6 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(+0.5f) );
157
    Static3D dVec7 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(-0.5f) );
158

    
159
    Static4D dReg  = new Static4D(0,0,0,d3);
160
    Static1D dRad  = new Static1D(1);
161

    
162
    VertexEffectMove effect0 = new VertexEffectMove(new Static3D(0,0,+0.5f));
163
    VertexEffectRotate effect1 = new VertexEffectRotate( angle180, axisX, center );
164
    VertexEffectRotate effect2 = new VertexEffectRotate( angle90 , axisX, center );
165
    VertexEffectRotate effect3 = new VertexEffectRotate( angle270, axisX, center );
166
    VertexEffectRotate effect4 = new VertexEffectRotate( angle270, axisY, center );
167
    VertexEffectRotate effect5 = new VertexEffectRotate( angle90 , axisY, center );
168

    
169
    VertexEffectDeform effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
170
    VertexEffectDeform effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
171
    VertexEffectDeform effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
172
    VertexEffectDeform effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
173
    VertexEffectDeform effect10= new VertexEffectDeform(dVec4, dRad, dCen4, dReg);
174
    VertexEffectDeform effect11= new VertexEffectDeform(dVec5, dRad, dCen5, dReg);
175
    VertexEffectDeform effect12= new VertexEffectDeform(dVec6, dRad, dCen6, dReg);
176
    VertexEffectDeform effect13= new VertexEffectDeform(dVec7, dRad, dCen7, dReg);
177

    
178
    effect0.setMeshAssociation(63,-1);  // all 6 sides
179
    effect1.setMeshAssociation(32,-1);  // back
180
    effect2.setMeshAssociation( 8,-1);  // bottom
181
    effect3.setMeshAssociation( 4,-1);  // top
182
    effect4.setMeshAssociation( 2,-1);  // left
183
    effect5.setMeshAssociation( 1,-1);  // right
184

    
185
    mesh.apply(effect0);
186
    mesh.apply(effect1);
187
    mesh.apply(effect2);
188
    mesh.apply(effect3);
189
    mesh.apply(effect4);
190
    mesh.apply(effect5);
191
    mesh.apply(effect6);
192
    mesh.apply(effect7);
193
    mesh.apply(effect8);
194
    mesh.apply(effect9);
195
    mesh.apply(effect10);
196
    mesh.apply(effect11);
197
    mesh.apply(effect12);
198
    mesh.apply(effect13);
199

    
200
    mesh.mergeEffComponents();
201

    
202
    return mesh;
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206
// SKEWB
207

    
208
  MeshBase createSkewbCornerMesh()
209
    {
210
    float D = 0.02f;
211
    float E = 0.5f;
212
    float F = SQ2/2;
213

    
214
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
215

    
216
    float[] bands0 = { 1.0f    , 0,
217
                       1.0f-2*D, D*0.25f,
218
                       1.0f-4*D, D*0.35f,
219
                       1.0f-8*D, D*0.6f,
220
                       0.60f   , D*1.0f,
221
                       0.30f   , D*1.375f,
222
                       0.0f    , D*1.4f };
223

    
224
    MeshBase[] meshes = new MeshBase[6];
225

    
226
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
227
    meshes[0].setEffectAssociation(0,1,0);
228
    meshes[1] = meshes[0].copy(true);
229
    meshes[1].setEffectAssociation(0,2,0);
230
    meshes[2] = meshes[0].copy(true);
231
    meshes[2].setEffectAssociation(0,4,0);
232

    
233
    float[] vertices1 = { 0,0, F,0, F/2,(SQ3/2)*F };
234
    float[] bands1 = { 1.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f };
235

    
236
    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
237
    meshes[3].setEffectAssociation(0,8,0);
238
    meshes[4] = meshes[3].copy(true);
239
    meshes[4].setEffectAssociation(0,16,0);
240
    meshes[5] = meshes[3].copy(true);
241
    meshes[5].setEffectAssociation(0,32,0);
242

    
243
    MeshBase mesh = new MeshJoined(meshes);
244

    
245
    Static3D axisX  = new Static3D(1,0,0);
246
    Static3D axisY  = new Static3D(0,1,0);
247
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
248
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
249
    Static1D angle1 = new Static1D(+90);
250
    Static1D angle2 = new Static1D(-90);
251
    Static1D angle3 = new Static1D(-15);
252
    Static1D angle4 = new Static1D((float)((180.0f/Math.PI)*Math.acos(SQ3/3)));
253
    Static1D angle5 = new Static1D(120);
254
    Static1D angle6 = new Static1D(240);
255
    Static3D center1= new Static3D(0,0,0);
256
    Static3D center2= new Static3D(-0.5f,-0.5f,-0.5f);
257
    Static3D move1  = new Static3D(-E/4,-E/4,0);
258
    Static3D move2  = new Static3D(-0.5f,-0.5f,-0.5f);
259

    
260
    float d0 =-0.04f;
261
    float d1 = 0.04f;
262
    float r0 = 0.15f;
263
    float r1 = 0.10f;
264

    
265
    Static3D vec0   = new Static3D(d0*(+SQ3/3),d0*(+SQ3/3),d0*(+SQ3/3));
266
    Static3D vec1   = new Static3D(d1*(+SQ3/3),d1*(-SQ3/3),d1*(-SQ3/3));
267
    Static3D vec2   = new Static3D(d1*(-SQ3/3),d1*(+SQ3/3),d1*(-SQ3/3));
268
    Static3D vec3   = new Static3D(d1*(-SQ3/3),d1*(-SQ3/3),d1*(+SQ3/3));
269

    
270
    Static1D radius = new Static1D(0.5f);
271

    
272
    Static3D cent0  = new Static3D( 0.0f, 0.0f, 0.0f);
273
    Static3D cent1  = new Static3D(-0.5f, 0.0f, 0.0f);
274
    Static3D cent2  = new Static3D( 0.0f,-0.5f, 0.0f);
275
    Static3D cent3  = new Static3D( 0.0f, 0.0f,-0.5f);
276

    
277
    Static4D reg0   = new Static4D(0,0,0,r0);
278
    Static4D reg1   = new Static4D(0,0,0,r1);
279

    
280
    VertexEffectMove   effect0 = new VertexEffectMove(move1);
281
    VertexEffectScale effect1 = new VertexEffectScale(new Static3D(1,1,-1));
282
    VertexEffectRotate effect2 = new VertexEffectRotate(angle1,axisX,center1);
283
    VertexEffectRotate effect3 = new VertexEffectRotate(angle2,axisY,center1);
284
    VertexEffectMove   effect4 = new VertexEffectMove(move2);
285
    VertexEffectRotate effect5 = new VertexEffectRotate(angle1,axisX,center2);
286
    VertexEffectRotate effect6 = new VertexEffectRotate(angle3,axisY,center2);
287
    VertexEffectRotate effect7 = new VertexEffectRotate(angle4,axis0,center2);
288
    VertexEffectRotate effect8 = new VertexEffectRotate(angle5,axis1,center2);
289
    VertexEffectRotate effect9 = new VertexEffectRotate(angle6,axis1,center2);
290

    
291
    VertexEffectDeform effect10= new VertexEffectDeform(vec0,radius,cent0,reg0);
292
    VertexEffectDeform effect11= new VertexEffectDeform(vec1,radius,cent1,reg1);
293
    VertexEffectDeform effect12= new VertexEffectDeform(vec2,radius,cent2,reg1);
294
    VertexEffectDeform effect13= new VertexEffectDeform(vec3,radius,cent3,reg1);
295

    
296
    effect0.setMeshAssociation( 7,-1);  // meshes 0,1,2
297
    effect1.setMeshAssociation( 6,-1);  // meshes 1,2
298
    effect2.setMeshAssociation( 2,-1);  // mesh 1
299
    effect3.setMeshAssociation( 4,-1);  // mesh 2
300
    effect4.setMeshAssociation(56,-1);  // meshes 3,4,5
301
    effect5.setMeshAssociation(56,-1);  // meshes 3,4,5
302
    effect6.setMeshAssociation(56,-1);  // meshes 3,4,5
303
    effect7.setMeshAssociation(56,-1);  // meshes 3,4,5
304
    effect8.setMeshAssociation(16,-1);  // mesh 4
305
    effect9.setMeshAssociation(32,-1);  // mesh 5
306

    
307
    effect10.setMeshAssociation(63,-1); // all meshes
308
    effect11.setMeshAssociation(63,-1); // all meshes
309
    effect12.setMeshAssociation(63,-1); // all meshes
310
    effect13.setMeshAssociation(63,-1); // all meshes
311

    
312
    mesh.apply(effect0);
313
    mesh.apply(effect1);
314
    mesh.apply(effect2);
315
    mesh.apply(effect3);
316
    mesh.apply(effect4);
317
    mesh.apply(effect5);
318
    mesh.apply(effect6);
319
    mesh.apply(effect7);
320
    mesh.apply(effect8);
321
    mesh.apply(effect9);
322

    
323
    mesh.apply(effect10);
324
    mesh.apply(effect11);
325
    mesh.apply(effect12);
326
    mesh.apply(effect13);
327

    
328
    mesh.mergeEffComponents();
329

    
330
    return mesh;
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  MeshBase createSkewbFaceMesh()
336
    {
337
    int association = 1;
338

    
339
    float D = 0.03f;
340
    float E = SQ2/4;
341
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
342

    
343
    float[] bands0 = { 1.0f    , 0,
344
                       1.0f-D/2, D*0.30f,
345
                       1.0f- D , D*0.50f,
346
                       1.0f-2*D, D*0.80f,
347
                       0.60f   , D*1.40f,
348
                       0.30f   , D*1.60f,
349
                       0.0f    , D*1.70f };
350

    
351
    MeshBase[] meshes = new MeshBase[6];
352
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
353
    meshes[0].setEffectAssociation(0,association,0);
354

    
355
    association <<= 1;
356

    
357
    float[] vertices1 = { -E,-SQ3*E, +E,-SQ3*E, 0,0 };
358
    float[] bands1 = { 1.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f };
359

    
360
    meshes[1] = new MeshPolygon(vertices1,bands1,0,0);
361
    meshes[1].setEffectAssociation(0,association,0);
362

    
363
    for(int i=2; i<5; i++)
364
      {
365
      association <<= 1;
366
      meshes[i] = meshes[1].copy(true);
367
      meshes[i].setEffectAssociation(0,association,0);
368
      }
369

    
370
    association <<= 1;
371
    meshes[5] = new MeshTriangle(1);                  // empty triangle so that
372
    meshes[5].setEffectAssociation(0,association,0);  // all cubits have 6 faces
373

    
374
    MeshBase mesh = new MeshJoined(meshes);
375

    
376
    Static3D center = new Static3D(0,0,0);
377
    Static3D axis1   = new Static3D(1,0,0);
378
    Static3D axis2   = new Static3D(0,0,1);
379
    float angle = -(float)((180.0f/Math.PI)*Math.acos(SQ3/3));
380

    
381
    float f = 0.05f;
382
    float r = 0.10f;
383
    float d = 0.5f;
384
    float e = +D*0.6f;
385
    Static3D vector0 = new Static3D(-f, 0, 0);
386
    Static3D vector1 = new Static3D( 0,+f, 0);
387
    Static3D vector2 = new Static3D(+f, 0, 0);
388
    Static3D vector3 = new Static3D( 0,-f, 0);
389
    Static1D radius  = new Static1D(1.0f);
390
    Static4D region  = new Static4D(0,0,0,r);
391
    Static3D center0 = new Static3D(+d, 0, e);
392
    Static3D center1 = new Static3D( 0,-d, e);
393
    Static3D center2 = new Static3D(-d, 0, e);
394
    Static3D center3 = new Static3D( 0,+d, e);
395

    
396
    VertexEffectRotate effect0 = new VertexEffectRotate( new Static1D(angle), axis1, center);
397
    VertexEffectRotate effect1 = new VertexEffectRotate( new Static1D(  135), axis2, center);
398
    VertexEffectRotate effect2 = new VertexEffectRotate( new Static1D(   45), axis2, center);
399
    VertexEffectRotate effect3 = new VertexEffectRotate( new Static1D(  -45), axis2, center);
400
    VertexEffectRotate effect4 = new VertexEffectRotate( new Static1D( -135), axis2, center);
401
    VertexEffectMove   effect5 = new VertexEffectMove( new Static3D(0,0,-0.5f) );
402
    VertexEffectDeform effect6 = new VertexEffectDeform(vector0,radius,center0,region);
403
    VertexEffectDeform effect7 = new VertexEffectDeform(vector1,radius,center1,region);
404
    VertexEffectDeform effect8 = new VertexEffectDeform(vector2,radius,center2,region);
405
    VertexEffectDeform effect9 = new VertexEffectDeform(vector3,radius,center3,region);
406
    VertexEffectScale  effect10= new VertexEffectScale(0.01f);
407

    
408
    effect0.setMeshAssociation(30,-1);  // meshes 1,2,3,4
409
    effect1.setMeshAssociation( 2,-1);  // mesh 1
410
    effect2.setMeshAssociation( 5,-1);  // meshes 0,2
411
    effect3.setMeshAssociation( 8,-1);  // mesh 3
412
    effect4.setMeshAssociation(16,-1);  // mesh 4
413
    effect5.setMeshAssociation(30,-1);  // meshes 1,2,3,4
414
    effect6.setMeshAssociation(31,-1);  // meshes 0,1,2,3,4
415
    effect7.setMeshAssociation(31,-1);  // meshes 0,1,2,3,4
416
    effect8.setMeshAssociation(31,-1);  // meshes 0,1,2,3,4
417
    effect9.setMeshAssociation(31,-1);  // meshes 0,1,2,3,4
418
    effect10.setMeshAssociation(32,-1); // mesh 5
419

    
420
    mesh.apply(effect0);
421
    mesh.apply(effect1);
422
    mesh.apply(effect2);
423
    mesh.apply(effect3);
424
    mesh.apply(effect4);
425
    mesh.apply(effect5);
426
    mesh.apply(effect6);
427
    mesh.apply(effect7);
428
    mesh.apply(effect8);
429
    mesh.apply(effect9);
430
    mesh.apply(effect10);
431

    
432
    mesh.mergeEffComponents();
433

    
434
    return mesh;
435
    }
436

    
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438
// SKEWB DIAMOND / PYRAMINX
439

    
440
  MeshBase createOctaMesh()
441
    {
442
    int association = 1;
443

    
444
    float C = 0.06f;
445
    float D = 0.031f;
446
    float E = SQ3/2;
447
    float F = 0.5f;
448

    
449
    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
450

    
451
    float[] bands = new float[] { 1.0f    , 0,
452
                                  1.0f  -C, D*0.55f,
453
                                  1.0f-2*C, D*0.85f,
454
                                  1.0f-4*C, D*1.20f,
455
                                  0.5f    , D*1.40f,
456
                                  0.0f    , D*1.50f };
457

    
458
    MeshBase[] meshes = new MeshPolygon[8];
459
    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
460
    meshes[0].setEffectAssociation(0,association,0);
461

    
462
    for(int i=1; i<8; i++)
463
      {
464
      association <<= 1;
465
      meshes[i] = meshes[0].copy(true);
466
      meshes[i].setEffectAssociation(0,association,0);
467
      }
468

    
469
    MeshBase mesh = new MeshJoined(meshes);
470

    
471
    float d1 = SQ2/2;
472
    float d2 =-0.06f;
473
    float d3 = 0.20f;
474

    
475
    Static3D a0 = new Static3D(     0, 1,     0 );
476
    Static3D a1 = new Static3D( SQ2/2, 0, SQ2/2 );
477
    Static3D a2 = new Static3D(-SQ2/2, 0, SQ2/2 );
478

    
479
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
480
    Static1D angle1= new Static1D( 90);
481
    Static1D angle2= new Static1D(180);
482
    Static1D angle3= new Static1D(270);
483

    
484
    Static3D move1 = new Static3D(0,SQ2/2-SQ3/3,0);
485

    
486
    Static3D axisX = new Static3D(1,0,0);
487
    Static3D axisY = new Static3D(0,1,0);
488

    
489
    Static3D cent0 = new Static3D(0,0,0);
490
    Static3D cent1 = new Static3D(0,SQ2/2,0);
491

    
492
    Static3D flipY = new Static3D( 1,-1, 1);
493

    
494
    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
495
    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
496
    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
497
    Static3D dCen3 = new Static3D(-d1*a0.get0(),-d1*a0.get1(),-d1*a0.get2() );
498
    Static3D dCen4 = new Static3D(-d1*a1.get0(),-d1*a2.get1(),-d1*a2.get2() );
499
    Static3D dCen5 = new Static3D(-d1*a2.get0(),-d1*a1.get1(),-d1*a1.get2() );
500

    
501
    Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
502
    Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
503
    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
504
    Static3D dVec3 = new Static3D(-d2*a0.get0(),-d2*a0.get1(),-d2*a0.get2() );
505
    Static3D dVec4 = new Static3D(-d2*a1.get0(),-d2*a1.get1(),-d2*a1.get2() );
506
    Static3D dVec5 = new Static3D(-d2*a2.get0(),-d2*a2.get1(),-d2*a2.get2() );
507

    
508
    Static4D dReg  = new Static4D(0,0,0,d3);
509
    Static1D dRad  = new Static1D(1);
510

    
511
    VertexEffectMove   effect0 = new VertexEffectMove(move1);
512
    VertexEffectRotate effect1 = new VertexEffectRotate(alpha , axisX, cent1);
513
    VertexEffectRotate effect2 = new VertexEffectRotate(angle1, axisY, cent0);
514
    VertexEffectRotate effect3 = new VertexEffectRotate(angle2, axisY, cent0);
515
    VertexEffectRotate effect4 = new VertexEffectRotate(angle3, axisY, cent0);
516
    VertexEffectScale  effect5 = new VertexEffectScale(flipY);
517

    
518
    VertexEffectDeform  effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
519
    VertexEffectDeform  effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
520
    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
521
    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
522
    VertexEffectDeform  effect10= new VertexEffectDeform(dVec4, dRad, dCen4, dReg);
523
    VertexEffectDeform  effect11= new VertexEffectDeform(dVec5, dRad, dCen5, dReg);
524

    
525
    effect0.setMeshAssociation (255,-1); // apply to all meshes
526
    effect1.setMeshAssociation (255,-1); // apply to all meshes
527
    effect2.setMeshAssociation ( 34,-1); // apply to meshes 1 & 5
528
    effect3.setMeshAssociation ( 68,-1); // apply to meshes 2 & 6
529
    effect4.setMeshAssociation (136,-1); // apply to meshes 3 & 7
530
    effect5.setMeshAssociation (240,-1); // apply to meshes 4,5,6,7
531
    effect6.setMeshAssociation (255,-1); // apply to all meshes
532
    effect7.setMeshAssociation (255,-1); // apply to all meshes
533
    effect8.setMeshAssociation (255,-1); // apply to all meshes
534
    effect9.setMeshAssociation (255,-1); // apply to all meshes
535
    effect10.setMeshAssociation(255,-1); // apply to all meshes
536
    effect11.setMeshAssociation(255,-1); // apply to all meshes
537

    
538
    mesh.apply(effect0);
539
    mesh.apply(effect1);
540
    mesh.apply(effect2);
541
    mesh.apply(effect3);
542
    mesh.apply(effect4);
543
    mesh.apply(effect5);
544
    mesh.apply(effect6);
545
    mesh.apply(effect7);
546
    mesh.apply(effect8);
547
    mesh.apply(effect9);
548
    mesh.apply(effect10);
549
    mesh.apply(effect11);
550

    
551
    mesh.mergeEffComponents();
552

    
553
    return mesh;
554
    }
555

    
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557

    
558
  MeshBase createTetraMesh()
559
    {
560
    int association = 1;
561

    
562
    float C = 0.06f;
563
    float D = 0.035f;
564
    float E = SQ3/2;
565
    float F = 0.5f;
566

    
567
    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
568

    
569
    float[] bands = new float[] { 1.0f    , 0,
570
                                  1.0f  -C, D*0.50f,
571
                                  1.0f-2*C, D*0.80f,
572
                                  1.0f-4*C, D*1.10f,
573
                                  0.5f    , D*1.30f,
574
                                  0.0f    , D*1.35f };
575

    
576
    MeshBase[] meshes = new MeshBase[8];
577
    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
578
    meshes[0].setEffectAssociation(0,association,0);
579

    
580
    for(int i=1; i<4; i++)
581
      {
582
      association <<= 1;
583
      meshes[i] = meshes[0].copy(true);
584
      meshes[i].setEffectAssociation(0,association,0);
585
      }
586

    
587
    for(int i=4; i<8; i++)
588
      {
589
      association <<= 1;
590
      meshes[i] = new MeshTriangle(1);
591
      meshes[i].setEffectAssociation(0,association,0);
592
      }
593

    
594
    MeshBase mesh = new MeshJoined(meshes);
595

    
596
    Static3D flipZ = new Static3D( 1, 1,-1);
597

    
598
    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
599
    Static1D angle1= new Static1D( 90);
600
    Static1D angle2= new Static1D(180);
601
    Static3D move1 = new Static3D(0,SQ2/4-SQ3/6,0);
602

    
603
    Static3D axisX = new Static3D(1,0,0);
604
    Static3D axisY = new Static3D(0,1,0);
605
    Static3D axisZ = new Static3D(0,0,1);
606

    
607
    Static3D cent0 = new Static3D(0,0,0);
608
    Static3D cent1 = new Static3D(0,SQ2/4,0);
609

    
610
    float d1 =-1.00f;
611
    float d2 = 0.10f;
612
    float d3 = 0.15f;
613

    
614
    float vx = 0.5f   ;
615
    float vy = (SQ2/4);
616

    
617
    Static3D a0 = new Static3D(+vx,-vy, 0 );
618
    Static3D a1 = new Static3D(-vx,-vy, 0 );
619
    Static3D a2 = new Static3D(  0, vy,-vx);
620
    Static3D a3 = new Static3D(  0, vy,+vx);
621

    
622
    Static4D dReg  = new Static4D(0,0,0,d3);
623
    Static1D dRad  = new Static1D(1);
624

    
625
    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
626
    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
627
    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
628
    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
629

    
630
    Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
631
    Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
632
    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
633
    Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
634

    
635
    VertexEffectRotate effect0 = new VertexEffectRotate(angle2, axisZ, cent0);
636
    VertexEffectMove   effect1 = new VertexEffectMove(move1);
637
    VertexEffectRotate effect2 = new VertexEffectRotate(alpha , axisX, cent1);
638
    VertexEffectScale  effect3 = new VertexEffectScale(flipZ);
639
    VertexEffectRotate effect4 = new VertexEffectRotate(angle1, axisY, cent0);
640
    VertexEffectRotate effect5 = new VertexEffectRotate(angle2, axisZ, cent0);
641

    
642
    VertexEffectDeform  effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
643
    VertexEffectDeform  effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
644
    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
645
    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
646

    
647
    VertexEffectScale  effect10 = new VertexEffectScale(0.1f);
648

    
649
    effect0.setMeshAssociation(15,-1); // meshes 0,1,2,3
650
    effect1.setMeshAssociation(15,-1); // meshes 0,1,2,3
651
    effect2.setMeshAssociation(15,-1); // meshes 0,1,2,3
652
    effect3.setMeshAssociation(10,-1); // meshes 1 & 3
653
    effect4.setMeshAssociation(12,-1); // meshes 2 & 3
654
    effect5.setMeshAssociation(12,-1); // meshes 2 & 3
655
    effect6.setMeshAssociation(15,-1); // meshes 0,1,2,3
656
    effect7.setMeshAssociation(15,-1); // meshes 0,1,2,3
657
    effect8.setMeshAssociation(15,-1); // meshes 0,1,2,3
658
    effect9.setMeshAssociation(15,-1); // meshes 0,1,2,3
659
    effect10.setMeshAssociation(240,-1); // meshes 4,5,6,7
660

    
661
    mesh.apply(effect0);
662
    mesh.apply(effect1);
663
    mesh.apply(effect2);
664
    mesh.apply(effect3);
665
    mesh.apply(effect4);
666
    mesh.apply(effect5);
667
    mesh.apply(effect6);
668
    mesh.apply(effect7);
669
    mesh.apply(effect8);
670
    mesh.apply(effect9);
671
    mesh.apply(effect10);
672

    
673
    mesh.mergeEffComponents();
674

    
675
    return mesh;
676
    }
677

    
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679
// DINO
680

    
681
  MeshBase createDinoMesh()
682
    {
683
    final float ANGLE = (float)((180/Math.PI)*(Math.atan(SQ2)));
684

    
685
    final int MESHES=4;
686

    
687
    float D = 0.02f;
688
    float E = 0.5f*SQ2;
689
    float F = 0.5f;
690

    
691
    float[] bands0 = { 1.0f    , 0,
692
                       1.0f-2*D, D*0.25f,
693
                       1.0f-4*D, D*0.35f,
694
                       1.0f-8*D, D*0.6f,
695
                       0.60f   , D*1.0f,
696
                       0.30f   , D*1.375f,
697
                       0.0f    , D*1.4f };
698

    
699
    float[] vertices0 = { -F,F/3, 0,-2*F/3, +F,F/3 };
700

    
701
    MeshBase[] meshes = new MeshPolygon[MESHES];
702
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 5);
703
    meshes[0].setEffectAssociation(0,1,0);
704
    meshes[1] = meshes[0].copy(true);
705
    meshes[1].setEffectAssociation(0,2,0);
706

    
707
    float[] bands1 = { 1.0f    , 0,
708
                       0.50f   , 0.10f,
709
                       0.0f    , 0.20f };
710

    
711
    float[] vertices1 = { -E/2,-E*(SQ3/6), E/2,-E*(SQ3/6), 0,E*(SQ3/3) };
712

    
713
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
714
    meshes[2].setEffectAssociation(0,4,0);
715
    meshes[3] = meshes[2].copy(true);
716
    meshes[3].setEffectAssociation(0,8,0);
717

    
718
    MeshBase mesh = new MeshJoined(meshes);
719

    
720
    Static3D a0 = new Static3D(     0,-3*F,    0 );
721
    Static3D a1 = new Static3D(     0,   0, -3*F );
722
    Static3D a2 = new Static3D(  -3*F,   0,    0 );
723
    Static3D a3 = new Static3D(  +3*F,   0,    0 );
724

    
725
    Static3D v0 = new Static3D(     0,-3*F/2, 3*F/2 );
726
    Static3D v1 = new Static3D(     0, 3*F/2,-3*F/2 );
727
    Static3D v2 = new Static3D(  -3*F, 3*F/2, 3*F/2 );
728
    Static3D v3 = new Static3D(  +3*F, 3*F/2, 3*F/2 );
729

    
730
    float d1 = 1.0f;
731
    float d2 =-0.10f;
732
    float d3 =-0.10f;
733
    float d4 = 0.40f;
734

    
735
    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
736
    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
737
    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
738
    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
739

    
740
    Static3D dVec0 = new Static3D( d3*v0.get0(), d3*v0.get1(), d3*v0.get2() );
741
    Static3D dVec1 = new Static3D( d3*v1.get0(), d3*v1.get1(), d3*v1.get2() );
742
    Static3D dVec2 = new Static3D( d2*v2.get0(), d2*v2.get1(), d2*v2.get2() );
743
    Static3D dVec3 = new Static3D( d2*v3.get0(), d2*v3.get1(), d2*v3.get2() );
744

    
745
    Static4D dReg  = new Static4D(0,0,0,d4);
746
    Static1D dRad  = new Static1D(1);
747

    
748
    Static1D angle1 = new Static1D(+ANGLE);
749
    Static1D angle2 = new Static1D(-ANGLE);
750

    
751
    Static3D axisX  = new Static3D(1,0,0);
752
    Static3D axisY  = new Static3D(0,1,0);
753
    Static3D axisZ  = new Static3D(0,-1,1);
754

    
755
    Static3D center0= new Static3D(0,0,0);
756
    Static3D center1= new Static3D(0,-3*F,0);
757

    
758
    VertexEffectScale   effect0 = new VertexEffectScale ( new Static3D(3,3,3) );
759
    VertexEffectMove    effect1 = new VertexEffectMove  ( new Static3D(0,-F,0) );
760
    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), axisX, center0 );
761
    VertexEffectScale   effect3 = new VertexEffectScale ( new Static3D(1,-1,1) );
762
    VertexEffectMove    effect4 = new VertexEffectMove  ( new Static3D(3*E/2,E*(SQ3/2)-3*F,0) );
763
    VertexEffectRotate  effect5 = new VertexEffectRotate( new Static1D(+90), axisY, center1 );
764
    VertexEffectScale   effect6 = new VertexEffectScale ( new Static3D(-1,1,1) );
765
    VertexEffectRotate  effect7 = new VertexEffectRotate( new Static1D( 45), axisX, center1 );
766
    VertexEffectRotate  effect8 = new VertexEffectRotate( angle1           , axisZ, center1 );
767
    VertexEffectRotate  effect9 = new VertexEffectRotate( angle2           , axisZ, center1 );
768

    
769
    VertexEffectDeform  effect10= new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
770
    VertexEffectDeform  effect11= new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
771
    VertexEffectDeform  effect12= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
772
    VertexEffectDeform  effect13= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
773

    
774
    effect0.setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
775
    effect1.setMeshAssociation( 3,-1);  // apply to meshes 0,1
776
    effect2.setMeshAssociation( 2,-1);  // apply to mesh 1
777
    effect3.setMeshAssociation( 2,-1);  // apply to mesh 0
778
    effect4.setMeshAssociation(12,-1);  // apply to meshes 2,3
779
    effect5.setMeshAssociation(12,-1);  // apply to meshes 2,3
780
    effect6.setMeshAssociation( 8,-1);  // apply to mesh 3
781
    effect7.setMeshAssociation(12,-1);  // apply to meshes 2,3
782
    effect8.setMeshAssociation( 4,-1);  // apply to mesh 2
783
    effect9.setMeshAssociation( 8,-1);  // apply to mesh 3
784
    effect10.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
785
    effect11.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
786
    effect12.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
787
    effect13.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
788

    
789
    mesh.apply(effect0);
790
    mesh.apply(effect1);
791
    mesh.apply(effect2);
792
    mesh.apply(effect3);
793
    mesh.apply(effect4);
794
    mesh.apply(effect5);
795
    mesh.apply(effect6);
796
    mesh.apply(effect7);
797
    mesh.apply(effect8);
798
    mesh.apply(effect9);
799
    mesh.apply(effect10);
800
    mesh.apply(effect11);
801
    mesh.apply(effect12);
802
    mesh.apply(effect13);
803

    
804
    mesh.mergeEffComponents();
805

    
806
    return mesh;
807
    }
808

    
809
///////////////////////////////////////////////////////////////////////////////////////////////////
810
// Helicopter
811

    
812
  MeshBase createHelicopterCornerMesh()
813
    {
814
    float D = 0.02f;
815
    float E = 0.5f;
816
    float F = SQ2/4;
817

    
818
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
819

    
820
    float[] bands0 = { 1.0f    , 0,
821
                       1.0f-2*D, D*0.25f,
822
                       1.0f-4*D, D*0.35f,
823
                       1.0f-8*D, D*0.6f,
824
                       0.60f   , D*1.0f,
825
                       0.30f   , D*1.375f,
826
                       0.0f    , D*1.4f };
827

    
828
    MeshBase[] meshes = new MeshBase[6];
829

    
830
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
831
    meshes[0].setEffectAssociation(0,1,0);
832
    meshes[1] = meshes[0].copy(true);
833
    meshes[1].setEffectAssociation(0,2,0);
834
    meshes[2] = meshes[0].copy(true);
835
    meshes[2].setEffectAssociation(0,4,0);
836

    
837
    float[] vertices1 = { -F,-1.0f/12, +F,-1.0f/12, 0,1.0f/6 };
838
    float[] bands1 = { 1.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f };
839

    
840
    meshes[3] = new MeshPolygon(vertices1,bands1,1,5);
841
    meshes[3].setEffectAssociation(0,8,0);
842
    meshes[4] = meshes[3].copy(true);
843
    meshes[4].setEffectAssociation(0,16,0);
844
    meshes[5] = meshes[3].copy(true);
845
    meshes[5].setEffectAssociation(0,32,0);
846

    
847
    MeshBase mesh = new MeshJoined(meshes);
848

    
849
    Static3D axisX  = new Static3D(1,0,0);
850
    Static3D axisY  = new Static3D(0,1,0);
851
    Static3D axis0  = new Static3D(-SQ2/2,0,SQ2/2);
852
    Static3D axis1  = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3);
853
    Static1D angle1 = new Static1D(+90);
854
    Static1D angle2 = new Static1D(-90);
855
    Static1D angle3 = new Static1D(-135);
856
    Static1D angle4 = new Static1D(90);
857
    Static1D angle5 = new Static1D(120);
858
    Static1D angle6 = new Static1D(240);
859
    Static3D center1= new Static3D(0,0,0);
860
    Static3D center2= new Static3D(-0.25f,-0.25f,-0.25f);
861
    Static3D move1  = new Static3D(-E/4,-E/4,0);
862
    Static3D move2  = new Static3D(-0.25f,(-1.0f/6)-0.25f,-0.25f);
863

    
864
    float d0 =-0.04f;
865
    float d1 = 0.04f;
866
    float r0 = 0.15f;
867
    float r1 = 0.10f;
868

    
869
    Static3D vec0   = new Static3D(d0*(+SQ3/3),d0*(+SQ3/3),d0*(+SQ3/3));
870
    Static3D vec1   = new Static3D(d1*(+SQ3/3),d1*(-SQ3/3),d1*(-SQ3/3));
871
    Static3D vec2   = new Static3D(d1*(-SQ3/3),d1*(+SQ3/3),d1*(-SQ3/3));
872
    Static3D vec3   = new Static3D(d1*(-SQ3/3),d1*(-SQ3/3),d1*(+SQ3/3));
873

    
874
    Static1D radius = new Static1D(0.5f);
875

    
876
    Static3D cent0  = new Static3D( 0.0f, 0.0f, 0.0f);
877
    Static3D cent1  = new Static3D(-0.5f, 0.0f, 0.0f);
878
    Static3D cent2  = new Static3D( 0.0f,-0.5f, 0.0f);
879
    Static3D cent3  = new Static3D( 0.0f, 0.0f,-0.5f);
880

    
881
    Static4D reg0   = new Static4D(0,0,0,r0);
882
    Static4D reg1   = new Static4D(0,0,0,r1);
883

    
884
    VertexEffectMove   effect0 = new VertexEffectMove(move1);
885
    VertexEffectScale  effect1 = new VertexEffectScale(new Static3D(1,1,-1));
886
    VertexEffectRotate effect2 = new VertexEffectRotate(angle1,axisX,center1);
887
    VertexEffectRotate effect3 = new VertexEffectRotate(angle2,axisY,center1);
888
    VertexEffectMove   effect4 = new VertexEffectMove(move2);
889
    VertexEffectRotate effect5 = new VertexEffectRotate(angle1,axisX,center2);
890
    VertexEffectRotate effect6 = new VertexEffectRotate(angle3,axisY,center2);
891
    VertexEffectRotate effect7 = new VertexEffectRotate(angle4,axis0,center2);
892
    VertexEffectRotate effect8 = new VertexEffectRotate(angle5,axis1,center2);
893
    VertexEffectRotate effect9 = new VertexEffectRotate(angle6,axis1,center2);
894

    
895
    VertexEffectDeform effect10= new VertexEffectDeform(vec0,radius,cent0,reg0);
896
    VertexEffectDeform effect11= new VertexEffectDeform(vec1,radius,cent1,reg1);
897
    VertexEffectDeform effect12= new VertexEffectDeform(vec2,radius,cent2,reg1);
898
    VertexEffectDeform effect13= new VertexEffectDeform(vec3,radius,cent3,reg1);
899

    
900
    effect0.setMeshAssociation( 7,-1);  // meshes 0,1,2
901
    effect1.setMeshAssociation( 6,-1);  // meshes 1,2
902
    effect2.setMeshAssociation( 2,-1);  // mesh 1
903
    effect3.setMeshAssociation( 4,-1);  // mesh 2
904
    effect4.setMeshAssociation(56,-1);  // meshes 3,4,5
905
    effect5.setMeshAssociation(56,-1);  // meshes 3,4,5
906
    effect6.setMeshAssociation(56,-1);  // meshes 3,4,5
907
    effect7.setMeshAssociation(56,-1);  // meshes 3,4,5
908
    effect8.setMeshAssociation(16,-1);  // mesh 4
909
    effect9.setMeshAssociation(32,-1);  // mesh 5
910

    
911
    effect10.setMeshAssociation(63,-1); // all meshes
912
    effect11.setMeshAssociation(63,-1); // all meshes
913
    effect12.setMeshAssociation(63,-1); // all meshes
914
    effect13.setMeshAssociation(63,-1); // all meshes
915

    
916
    mesh.apply(effect0);
917
    mesh.apply(effect1);
918
    mesh.apply(effect2);
919
    mesh.apply(effect3);
920
    mesh.apply(effect4);
921
    mesh.apply(effect5);
922
    mesh.apply(effect6);
923
    mesh.apply(effect7);
924
    mesh.apply(effect8);
925
    mesh.apply(effect9);
926

    
927
    mesh.apply(effect10);
928
    mesh.apply(effect11);
929
    mesh.apply(effect12);
930
    mesh.apply(effect13);
931

    
932
    mesh.mergeEffComponents();
933

    
934
    return mesh;
935
    }
936

    
937
///////////////////////////////////////////////////////////////////////////////////////////////////
938

    
939
  MeshBase createHelicopterFaceMesh()
940
    {
941
    MeshBase[] meshes = new MeshBase[6];
942

    
943
    float D = 0.02f;
944
    float E = 0.5f;
945
    float F = SQ2/4;
946
    float G = 1.0f/12;
947

    
948
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
949

    
950
    float[] bands0 = { 1.0f    , 0,
951
                       1.0f-2*D, D*0.25f,
952
                       1.0f-4*D, D*0.35f,
953
                       1.0f-8*D, D*0.6f,
954
                       0.60f   , D*1.0f,
955
                       0.30f   , D*1.375f,
956
                       0.0f    , D*1.4f };
957

    
958
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
959
    meshes[0].setEffectAssociation(0,1,0);
960

    
961
    float[] vertices1 = { -F,-G, +F,-G, 0,2*G};
962

    
963
    float[] bands1 = { 1.0f   , 0.0f,
964
                       0.5f   , 0.01f,
965
                       0.0f   , 0.01f };
966

    
967
    meshes[1] = new MeshPolygon(vertices1, bands1, 1, 3);
968
    meshes[1].setEffectAssociation(0,2,0);
969

    
970
    float[] vertices2 = { -E/2,-F/3, +E/2,-F/3, 0,2*F/3};
971

    
972
    float[] bands2 = { 1.0f   , 0.0f,
973
                       0.5f   , 0.01f,
974
                       0.0f   , 0.01f };
975

    
976
    meshes[2] = new MeshPolygon(vertices2, bands2, 1, 3);
977
    meshes[2].setEffectAssociation(0,4,0);
978
    meshes[3] = meshes[2].copy(true);
979
    meshes[3].setEffectAssociation(0,8,0);
980
    meshes[4] = new MeshTriangle(1);
981
    meshes[4].setEffectAssociation(0,16,0);
982
    meshes[5] = new MeshTriangle(1);
983
    meshes[5].setEffectAssociation(0,32,0);
984

    
985
    MeshBase mesh = new MeshJoined(meshes);
986

    
987
    Static3D move0  = new Static3D(-1.0f/8, -1.0f/8, 0);
988
    Static3D move1  = new Static3D(-(SQ2/24)-1.0f/4, -(SQ2/24)-1.0f/4, 0);
989
    Static3D move2  = new Static3D(-E/2, F/3, 0);
990
    Static3D move3  = new Static3D(+E/2, F/3, 0);
991
    Static3D move4  = new Static3D(+E/3,+E/3, 0);
992
    Static1D angle1 = new Static1D(135);
993
    Static1D angle2 = new Static1D(90);
994
    Static1D angle3 = new Static1D(-90);
995
    Static1D angle4 = new Static1D(-135);
996
    Static3D axisX  = new Static3D(1,0,0);
997
    Static3D axisY  = new Static3D(0,1,0);
998
    Static3D axisZ  = new Static3D(0,0,1);
999
    Static3D axis1  = new Static3D(1,-1,0);
1000
    Static3D center = new Static3D(0,0,0);
1001
    Static3D center1= new Static3D(-0.25f,-0.25f,0);
1002

    
1003
    float d0 =-0.03f;
1004
    float d1 =-0.04f;
1005
    float r0 = 0.15f;
1006
    float r1 = 0.10f;
1007

    
1008
    Static3D vec0   = new Static3D(d0*(+SQ3/3),d0*(+SQ3/3),d0*(+SQ3/3));
1009
    Static3D vec1   = new Static3D(d1*(-SQ3/3),d1*(+SQ3/3),d1*(+SQ3/3));
1010
    Static3D vec2   = new Static3D(d1*(+SQ3/3),d1*(-SQ3/3),d1*(+SQ3/3));
1011

    
1012
    Static1D radius = new Static1D(0.5f);
1013

    
1014
    Static3D cent0  = new Static3D( 0.0f, 0.0f, 0.0f);
1015
    Static3D cent1  = new Static3D(-0.5f, 0.0f, 0.0f);
1016
    Static3D cent2  = new Static3D( 0.0f,-0.5f, 0.0f);
1017

    
1018
    Static4D reg0   = new Static4D(0,0,0,r0);
1019
    Static4D reg1   = new Static4D(0,0,0,r1);
1020

    
1021
    VertexEffectMove   effect0 = new VertexEffectMove(move0);
1022
    VertexEffectRotate effect1 = new VertexEffectRotate(angle1, axisZ, center);
1023
    VertexEffectMove   effect2 = new VertexEffectMove(move1);
1024
    VertexEffectRotate effect3 = new VertexEffectRotate(angle2, axis1, center1);
1025
    VertexEffectMove   effect4 = new VertexEffectMove(move2);
1026
    VertexEffectMove   effect5 = new VertexEffectMove(move3);
1027
    VertexEffectRotate effect6 = new VertexEffectRotate(angle3, axisZ, center);
1028
    VertexEffectRotate effect7 = new VertexEffectRotate(angle4, axisX, center);
1029
    VertexEffectRotate effect8 = new VertexEffectRotate(angle1, axisY, center);
1030
    VertexEffectScale  effect9 = new VertexEffectScale(0);
1031
    VertexEffectDeform effect10= new VertexEffectDeform(vec0,radius,cent0,reg0);
1032
    VertexEffectDeform effect11= new VertexEffectDeform(vec1,radius,cent1,reg1);
1033
    VertexEffectDeform effect12= new VertexEffectDeform(vec2,radius,cent2,reg1);
1034
    VertexEffectMove   effect13= new VertexEffectMove(move4);
1035

    
1036
    effect0.setMeshAssociation( 1,-1);  // mesh 0
1037
    effect1.setMeshAssociation( 2,-1);  // mesh 1
1038
    effect2.setMeshAssociation( 2,-1);  // mesh 1
1039
    effect3.setMeshAssociation( 2,-1);  // mesh 1
1040
    effect4.setMeshAssociation( 4,-1);  // mesh 2
1041
    effect5.setMeshAssociation( 8,-1);  // mesh 3
1042
    effect6.setMeshAssociation( 8,-1);  // mesh 3
1043
    effect7.setMeshAssociation( 4,-1);  // mesh 2
1044
    effect8.setMeshAssociation( 8,-1);  // mesh 3
1045
    effect9.setMeshAssociation(48,-1);  // meshes 4,5
1046
    effect10.setMeshAssociation(15,-1); // meshes 0,1,2,3
1047
    effect11.setMeshAssociation(15,-1); // meshes 0,1,2,3
1048
    effect12.setMeshAssociation(15,-1); // meshes 0,1,2,3
1049
    effect13.setMeshAssociation(15,-1); // meshes 0,1,2,3
1050

    
1051
    mesh.apply(effect0);
1052
    mesh.apply(effect1);
1053
    mesh.apply(effect2);
1054
    mesh.apply(effect3);
1055
    mesh.apply(effect4);
1056
    mesh.apply(effect5);
1057
    mesh.apply(effect6);
1058
    mesh.apply(effect7);
1059
    mesh.apply(effect8);
1060
    mesh.apply(effect9);
1061
    mesh.apply(effect10);
1062
    mesh.apply(effect11);
1063
    mesh.apply(effect12);
1064
    mesh.apply(effect13);
1065

    
1066
    mesh.mergeEffComponents();
1067

    
1068
    return mesh;
1069
    }
1070

    
1071
///////////////////////////////////////////////////////////////////////////////////////////////////
1072
// Redi cube
1073

    
1074
  private void roundCorners(MeshBase mesh)
1075
    {
1076
    float cX = 0.0f;
1077
    float cY = -0.75f;
1078
    float cZ = -0.75f;
1079

    
1080
    float d1=-0.05f;
1081
    float d2=-0.05f;
1082
    float r0= 0.20f;
1083
    float r1= 0.20f;
1084

    
1085
    Static3D vert0 = new Static3D( 0.5f, 0.0f, 0.0f);
1086
    Static3D vert1 = new Static3D(-0.5f, 0.0f, 0.0f);
1087
    Static3D vert2 = new Static3D( 0.0f, 0.0f,-1.5f);
1088
    Static3D vert3 = new Static3D( 0.0f,-1.5f, 0.0f);
1089

    
1090
    Static3D vec0 = new Static3D( d1*(+0.5f-cX), d1*(+0.0f-cY), d1*(+0.0f-cZ));
1091
    Static3D vec1 = new Static3D( d1*(-0.5f-cX), d1*(+0.0f-cY), d1*(+0.0f-cZ));
1092
    Static3D vec2 = new Static3D( d2*(+0.0f-cX), d2*(+0.0f-cY), d2*(-1.5f-cZ));
1093
    Static3D vec3 = new Static3D( d2*(+0.0f-cX), d2*(-1.5f-cY), d2*(+0.0f-cZ));
1094

    
1095
    Static1D radius = new Static1D(0.5f);
1096
    Static4D reg0   = new Static4D(0,0,0,r0);
1097
    Static4D reg1   = new Static4D(0,0,0,r1);
1098

    
1099
    VertexEffect effect0= new VertexEffectDeform(vec0,radius,vert0,reg0);
1100
    VertexEffect effect1= new VertexEffectDeform(vec1,radius,vert1,reg0);
1101
    VertexEffect effect2= new VertexEffectDeform(vec2,radius,vert2,reg1);
1102
    VertexEffect effect3= new VertexEffectDeform(vec3,radius,vert3,reg1);
1103

    
1104
    mesh.apply(effect0);
1105
    mesh.apply(effect1);
1106
    mesh.apply(effect2);
1107
    mesh.apply(effect3);
1108
    }
1109

    
1110
///////////////////////////////////////////////////////////////////////////////////////////////////
1111

    
1112
  MeshBase createRediEdgeMesh()
1113
    {
1114
    final int MESHES=6;
1115

    
1116
    float C = 0.02f;
1117
    float D = 0.02f;
1118
    float F = 0.25f;
1119

    
1120
    float[] bands0 = { 1.0f    , 0,
1121
                       1.0f-2*C, D*0.25f,
1122
                       1.0f-4*C, D*0.35f,
1123
                       1.0f-8*C, D*0.6f,
1124
                       0.60f   , D*1.0f,
1125
                       0.30f   , D*1.375f,
1126
                       0.0f    , D*1.4f };
1127

    
1128
    float[] vertices0 = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F };
1129

    
1130
    MeshBase[] meshes = new MeshPolygon[MESHES];
1131
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 2);
1132
    meshes[0].setEffectAssociation(0,1,0);
1133
    meshes[1] = meshes[0].copy(true);
1134
    meshes[1].setEffectAssociation(0,2,0);
1135

    
1136
    float[] bands1 = { 1.0f    , 0,
1137
                       0.90f   , D,
1138
                       0.0f    , D };
1139

    
1140
    float[] vertices1 = { -F/2, +F/2, -F/2, -1.5f*F, 1.5f*F, +F/2 };
1141

    
1142
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
1143
    meshes[2].setEffectAssociation(0,4,0);
1144
    meshes[3] = meshes[2].copy(true);
1145
    meshes[3].setEffectAssociation(0,8,0);
1146

    
1147
    float[] bands2 = { 1.0f    , 0,
1148
                       0.90f   , D,
1149
                       0.0f    , D };
1150

    
1151
    float X = 0.25f*SQ2;
1152
    float Y = SQ6/16;
1153

    
1154
    float[] vertices2 = { -X, Y, -1.5f*X, -Y, +1.5f*X, -Y, +X, Y };
1155

    
1156
    meshes[4] = new MeshPolygon(vertices2, bands2, 1, 1);
1157
    meshes[4].setEffectAssociation(0,16,0);
1158
    meshes[5] = meshes[4].copy(true);
1159
    meshes[5].setEffectAssociation(0,32,0);
1160

    
1161
    MeshBase mesh = new MeshJoined(meshes);
1162

    
1163
    Static3D move0 = new Static3D(0.0f, -0.5f, 0.0f);
1164
    Static3D move1 = new Static3D(0.25f, -0.25f, 0.0f);
1165
    Static3D move2 = new Static3D(0.5f, 0.0f, 0.0f);
1166
    Static3D move3 = new Static3D(0.0f, (SQ3-6)/8, (SQ3-6)/8);
1167
    Static3D flipZ = new Static3D(1,1,-1);
1168
    Static3D flipX = new Static3D(-1,1,1);
1169
    Static3D scale = new Static3D(2,2,2);
1170
    Static3D cent0 = new Static3D(0,0, 0);
1171
    Static3D cent1 = new Static3D(0,0, -1.5f);
1172
    Static3D axisX = new Static3D(1,0, 0);
1173
    Static3D axisY = new Static3D(0,1, 0);
1174
    Static3D axis  = new Static3D(0,SQ2/2,-SQ2/2);
1175
    Static1D angle1= new Static1D(90);
1176
    Static1D angle2= new Static1D(45);
1177
    Static1D angle3= new Static1D( (float)(180/Math.PI*Math.acos(SQ3/3)) );
1178

    
1179
    VertexEffect effect0 = new VertexEffectScale(scale);
1180
    VertexEffect effect1 = new VertexEffectMove(move0);
1181
    VertexEffect effect2 = new VertexEffectScale(flipZ);
1182
    VertexEffect effect3 = new VertexEffectRotate(angle1,axisX,cent0);
1183
    VertexEffect effect4 = new VertexEffectMove(move1);
1184
    VertexEffect effect5 = new VertexEffectRotate(angle1,axisY,cent0);
1185
    VertexEffect effect6 = new VertexEffectMove(move2);
1186
    VertexEffect effect7 = new VertexEffectScale(flipX);
1187
    VertexEffect effect8 = new VertexEffectRotate(angle2,axisX,cent0);
1188
    VertexEffect effect9 = new VertexEffectMove(move3);
1189
    VertexEffect effect10= new VertexEffectRotate(angle3,axis ,cent1);
1190
    VertexEffect effect11= new VertexEffectScale(flipX);
1191

    
1192
    effect0.setMeshAssociation(63,-1);  // meshes 0,1,2,3,4,5
1193
    effect1.setMeshAssociation( 3,-1);  // meshes 0,1
1194
    effect2.setMeshAssociation( 2,-1);  // mesh 1
1195
    effect3.setMeshAssociation( 2,-1);  // mesh 1
1196
    effect4.setMeshAssociation(12,-1);  // meshes 2,3
1197
    effect5.setMeshAssociation(60,-1);  // meshes 2,3,4,5
1198
    effect6.setMeshAssociation(12,-1);  // meshes 2,3
1199
    effect7.setMeshAssociation( 8,-1);  // mesh 3
1200
    effect8.setMeshAssociation(48,-1);  // meshes 4,5
1201
    effect9.setMeshAssociation(48,-1);  // meshes 4,5
1202
    effect10.setMeshAssociation(48,-1); // meshes 4,5
1203
    effect11.setMeshAssociation(32,-1); // mesh 5
1204

    
1205
    mesh.apply(effect0);
1206
    mesh.apply(effect1);
1207
    mesh.apply(effect2);
1208
    mesh.apply(effect3);
1209
    mesh.apply(effect4);
1210
    mesh.apply(effect5);
1211
    mesh.apply(effect6);
1212
    mesh.apply(effect7);
1213
    mesh.apply(effect8);
1214
    mesh.apply(effect9);
1215
    mesh.apply(effect10);
1216
    mesh.apply(effect11);
1217

    
1218
    roundCorners(mesh);
1219

    
1220
    mesh.mergeEffComponents();
1221

    
1222
    return mesh;
1223
    }
1224

    
1225
///////////////////////////////////////////////////////////////////////////////////////////////////
1226

    
1227
  MeshBase createRediCornerMesh()
1228
    {
1229
    final int MESHES=6;
1230

    
1231
    float C = 0.027f;
1232
    float D = 0.027f;
1233
    float E = 0.5f;
1234
    float[] vertices1 = { -E,-E, +E,-E, +E,+E, -E,+E };
1235

    
1236
    float[] bands1 = new float[] { 1.0f   ,-D,
1237
                                  1.0f-C/2,-D*0.55f,
1238
                                  1.0f-C  ,-D*0.25f,
1239
                                  1.0f-2*C, 0.0f,
1240
                                  0.50f   , D*1.5f,
1241
                                  0.0f    , D*1.75f };
1242

    
1243
    MeshBase[] meshes = new MeshBase[MESHES];
1244
    meshes[0] = new MeshPolygon(vertices1,bands1,2,2);
1245
    meshes[0].setEffectAssociation(0,1,0);
1246
    meshes[1] = meshes[0].copy(true);
1247
    meshes[1].setEffectAssociation(0,2,0);
1248
    meshes[2] = meshes[0].copy(true);
1249
    meshes[2].setEffectAssociation(0,4,0);
1250

    
1251
    float F = SQ2/2;
1252
    float X = 0.5f;
1253

    
1254
    float[] vertices2 = { -E,+F, -E+X,0, -E,-F, +E,-F, +E-X,0, +E,+F };
1255

    
1256
    float[] bands2 = new float[] { 1.0f,0.0f,
1257
                                   0.0f,0.0f };
1258

    
1259
    meshes[3] = new MeshPolygon(vertices2,bands2,0,0);
1260
    meshes[3].setEffectAssociation(0,8,0);
1261
    meshes[4] = meshes[3].copy(true);
1262
    meshes[4].setEffectAssociation(0,16,0);
1263
    meshes[5] = meshes[3].copy(true);
1264
    meshes[5].setEffectAssociation(0,32,0);
1265

    
1266
    MeshBase mesh = new MeshJoined(meshes);
1267

    
1268
    Static3D axisY   = new Static3D(0,1,0);
1269
    Static3D axisX   = new Static3D(1,0,0);
1270
    Static3D axisZ   = new Static3D(0,0,1);
1271
    Static3D center  = new Static3D(0,0,0);
1272
    Static1D angle90 = new Static1D(90);
1273
    Static1D angle270= new Static1D(270);
1274
    Static1D angle45 = new Static1D(-45);
1275

    
1276
    float d1 = 1.0f;
1277
    float d2 =-0.05f;
1278
    float d3 = 0.12f;
1279

    
1280
    Static3D dCen0 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(+0.5f) );
1281
    Static3D dCen1 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(-0.5f) );
1282
    Static3D dCen2 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(+0.5f) );
1283
    Static3D dCen3 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(-0.5f) );
1284
    Static3D dCen4 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(+0.5f) );
1285
    Static3D dCen5 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(-0.5f) );
1286
    Static3D dCen6 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(+0.5f) );
1287
    Static3D dCen7 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(-0.5f) );
1288

    
1289
    Static3D dVec0 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(+0.5f) );
1290
    Static3D dVec1 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(-0.5f) );
1291
    Static3D dVec2 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(+0.5f) );
1292
    Static3D dVec3 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(-0.5f) );
1293
    Static3D dVec4 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(+0.5f) );
1294
    Static3D dVec5 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(-0.5f) );
1295
    Static3D dVec6 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(+0.5f) );
1296
    Static3D dVec7 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(-0.5f) );
1297

    
1298
    Static4D dReg  = new Static4D(0,0,0,d3);
1299
    Static1D dRad  = new Static1D(1);
1300

    
1301
    VertexEffect effect0 = new VertexEffectMove(new Static3D(0,0,+0.5f));
1302
    VertexEffect effect1 = new VertexEffectRotate( angle270, axisX, center );
1303
    VertexEffect effect2 = new VertexEffectRotate( angle90 , axisY, center );
1304
    VertexEffect effect3 = new VertexEffectRotate( angle45 , axisX, center );
1305
    VertexEffect effect4 = new VertexEffectRotate( angle90 , axisY, center );
1306
    VertexEffect effect5 = new VertexEffectRotate( angle270, axisZ, center );
1307

    
1308
    VertexEffect effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
1309
    VertexEffect effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
1310
    VertexEffect effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
1311
    VertexEffect effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
1312
    VertexEffect effect10= new VertexEffectDeform(dVec4, dRad, dCen4, dReg);
1313
    VertexEffect effect11= new VertexEffectDeform(dVec5, dRad, dCen5, dReg);
1314
    VertexEffect effect12= new VertexEffectDeform(dVec6, dRad, dCen6, dReg);
1315
    VertexEffect effect13= new VertexEffectDeform(dVec7, dRad, dCen7, dReg);
1316

    
1317
    effect0.setMeshAssociation( 7,-1);  // 0,1,2
1318
    effect1.setMeshAssociation( 2,-1);  // 1
1319
    effect2.setMeshAssociation( 4,-1);  // 2
1320
    effect3.setMeshAssociation(56,-1);  // 3
1321
    effect4.setMeshAssociation(16,-1);  // 4
1322
    effect5.setMeshAssociation(32,-1);  // 5
1323

    
1324
    mesh.apply(effect0);
1325
    mesh.apply(effect1);
1326
    mesh.apply(effect2);
1327
    mesh.apply(effect3);
1328
    mesh.apply(effect4);
1329
    mesh.apply(effect5);
1330

    
1331
    mesh.apply(effect6);
1332
    mesh.apply(effect7);
1333
    mesh.apply(effect8);
1334
    mesh.apply(effect9);
1335
    mesh.apply(effect10);
1336
    mesh.apply(effect11);
1337
    mesh.apply(effect12);
1338
    mesh.apply(effect13);
1339

    
1340
    mesh.mergeEffComponents();
1341

    
1342
    return mesh;
1343
    }
1344
  }
(2-2/21)