Project

General

Profile

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

magiccube / src / main / java / org / distorted / helpers / FactoryCubit.java @ 7dc57f89

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