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