1 |
4a9f01f9
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2023 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
db0d3a90
|
leszek
|
package org.distorted.objectlib.bandaged;
|
11 |
4a9f01f9
|
leszek
|
|
12 |
45aedaa7
|
leszek
|
import static org.distorted.objectlib.main.TwistyObject.SQ2;
|
13 |
|
|
import static org.distorted.objectlib.main.TwistyObject.SQ5;
|
14 |
4a9f01f9
|
leszek
|
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.REGION_SIZE;
|
15 |
|
|
import static org.distorted.objectlib.objects.TwistyBandagedCuboid.STRENGTH;
|
16 |
|
|
|
17 |
6155e738
|
leszek
|
import org.distorted.library.helpers.QuatHelper;
|
18 |
4a9f01f9
|
leszek
|
import org.distorted.library.mesh.MeshBase;
|
19 |
|
|
import org.distorted.library.type.Static3D;
|
20 |
6155e738
|
leszek
|
import org.distorted.library.type.Static4D;
|
21 |
db0d3a90
|
leszek
|
import org.distorted.objectlib.helpers.FactoryCubit;
|
22 |
|
|
import org.distorted.objectlib.helpers.ObjectFaceShape;
|
23 |
|
|
import org.distorted.objectlib.helpers.ObjectShape;
|
24 |
|
|
import org.distorted.objectlib.helpers.ObjectVertexEffects;
|
25 |
4a9f01f9
|
leszek
|
|
26 |
|
|
import java.util.ArrayList;
|
27 |
45aedaa7
|
leszek
|
import java.util.Collections;
|
28 |
|
|
import java.util.Comparator;
|
29 |
4a9f01f9
|
leszek
|
|
30 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31 |
|
|
|
32 |
|
|
abstract public class FactoryBandaged
|
33 |
|
|
{
|
34 |
45aedaa7
|
leszek
|
private static class BandagedCubitFace
|
35 |
|
|
{
|
36 |
|
|
private static final float[] sortVect = new float[] { 1/(2*SQ2), SQ2/(2*SQ2), SQ5/(2*SQ2) };
|
37 |
|
|
|
38 |
|
|
float[] vertices;
|
39 |
|
|
float[] center;
|
40 |
|
|
float[] normal;
|
41 |
|
|
float centerCast;
|
42 |
|
|
|
43 |
|
|
BandagedCubitFace(float[] verts)
|
44 |
|
|
{
|
45 |
|
|
vertices = verts;
|
46 |
|
|
computeCenter();
|
47 |
|
|
computeNormal();
|
48 |
|
|
computeCenterCast();
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
private void computeCenter()
|
52 |
|
|
{
|
53 |
|
|
int num = vertices.length/3;
|
54 |
|
|
center = new float[3];
|
55 |
|
|
|
56 |
|
|
for(int v=0; v<num; v++)
|
57 |
|
|
{
|
58 |
|
|
center[0] += vertices[3*v ];
|
59 |
|
|
center[1] += vertices[3*v+1];
|
60 |
|
|
center[2] += vertices[3*v+2];
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
center[0] /= num;
|
64 |
|
|
center[1] /= num;
|
65 |
|
|
center[2] /= num;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
private void computeNormal()
|
69 |
|
|
{
|
70 |
|
|
normal = new float[3];
|
71 |
|
|
|
72 |
|
|
float x1 = vertices[0];
|
73 |
|
|
float y1 = vertices[1];
|
74 |
|
|
float z1 = vertices[2];
|
75 |
|
|
float x2 = vertices[3];
|
76 |
|
|
float y2 = vertices[4];
|
77 |
|
|
float z2 = vertices[5];
|
78 |
|
|
float x3 = vertices[6];
|
79 |
|
|
float y3 = vertices[7];
|
80 |
|
|
float z3 = vertices[8];
|
81 |
|
|
|
82 |
|
|
float v1x = x2-x1;
|
83 |
|
|
float v1y = y2-y1;
|
84 |
|
|
float v1z = z2-z1;
|
85 |
|
|
float v2x = x3-x1;
|
86 |
|
|
float v2y = y3-y1;
|
87 |
|
|
float v2z = z3-z1;
|
88 |
|
|
|
89 |
|
|
normal[0] = v1y*v2z - v2y*v1z;
|
90 |
|
|
normal[1] = v1z*v2x - v2z*v1x;
|
91 |
|
|
normal[2] = v1x*v2y - v2x*v1y;
|
92 |
|
|
|
93 |
|
|
double len = normal[0]*normal[0] + normal[1]*normal[1] + normal[2]*normal[2];
|
94 |
|
|
len = Math.sqrt(len);
|
95 |
|
|
normal[0] /= len;
|
96 |
|
|
normal[1] /= len;
|
97 |
|
|
normal[2] /= len;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
private void computeCenterCast()
|
101 |
|
|
{
|
102 |
|
|
centerCast = center[0]*sortVect[0] + center[1]*sortVect[1] + center[2]*sortVect[2];
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
static class SortByCenterCast implements Comparator<BandagedCubitFace>
|
107 |
|
|
{
|
108 |
|
|
public int compare(BandagedCubitFace a, BandagedCubitFace b)
|
109 |
|
|
{
|
110 |
|
|
float diff = a.centerCast - b.centerCast;
|
111 |
|
|
return diff>0 ? 1: diff==0 ? 0: -1;
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
|
115 |
2fda293d
|
leszek
|
public static final Static4D QUAT = new Static4D(0,0,0,1);
|
116 |
6155e738
|
leszek
|
|
117 |
4a9f01f9
|
leszek
|
private ArrayList<float[]> mTmpArray;
|
118 |
6155e738
|
leszek
|
private ArrayList<float[][]> mVertexArray;
|
119 |
|
|
private BandagedElement[] mElements;
|
120 |
c8f3a765
|
leszek
|
private Static3D[] mPuzzleNormals;
|
121 |
4a9f01f9
|
leszek
|
private float[] mDist3D;
|
122 |
|
|
private int[][] mFaceBelongsBitmap;
|
123 |
ccb61aff
|
leszek
|
private float[][] mDiaAxis;
|
124 |
|
|
private float[][] mMinMax;
|
125 |
6155e738
|
leszek
|
private int mNumFaces;
|
126 |
|
|
private int mNumElements;
|
127 |
|
|
private float[][] mMove;
|
128 |
|
|
private int[][][][] mIndices;
|
129 |
|
|
private float[][][] mVertices;
|
130 |
|
|
private int[][] mBandIndices;
|
131 |
|
|
private int[] mNumLayers;
|
132 |
|
|
private float[] mTmp;
|
133 |
a662c27e
|
leszek
|
private float[][][] mAllPositions;
|
134 |
c8f3a765
|
leszek
|
private boolean mCalledFromBandagedObject; // true if this class is being called from the
|
135 |
|
|
// one of the 'BandagedObject*' classes; false if
|
136 |
|
|
// called from one of the 'TwistyBandaged*' classes.
|
137 |
4a9f01f9
|
leszek
|
|
138 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139 |
|
|
|
140 |
|
|
FactoryBandaged()
|
141 |
|
|
{
|
142 |
|
|
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
|
|
|
147 |
|
|
abstract Static3D[] getNormals();
|
148 |
5c825988
|
leszek
|
abstract float[][][] getPositions(int[] numLayers);
|
149 |
c85a4378
|
leszek
|
abstract Static4D getElementQuat(int[] numLayers, int cubitIndex);
|
150 |
ccb61aff
|
leszek
|
abstract float[][] getDiameterAxis();
|
151 |
6155e738
|
leszek
|
abstract float[] getDist3D(int[] numLayers);
|
152 |
|
|
abstract float[][] getBands(boolean iconMode, int[] numLayers);
|
153 |
|
|
abstract int getElementVariant(int[] numLayers, float x, float y, float z);
|
154 |
74dafadd
|
leszek
|
abstract int diameterMap(float diameter);
|
155 |
6155e738
|
leszek
|
abstract float[][] getVertices(int[] numLayers, int variant);
|
156 |
|
|
abstract int[][] getIndices(int[] numLayers, int variant);
|
157 |
a662c27e
|
leszek
|
abstract int getNumVariants(int[] numLayers);
|
158 |
c8f3a765
|
leszek
|
abstract float sizeCorrection(int[] numLayers); // again workaround for the Megaminx
|
159 |
|
|
// '2-3-4-5' vs. '3-3-5-5' problem.
|
160 |
4a9f01f9
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161 |
|
|
|
162 |
c8f3a765
|
leszek
|
private int[] computeFaceBelongsBitmap(float[][] vertices, float[] move, float corr)
|
163 |
4a9f01f9
|
leszek
|
{
|
164 |
|
|
int numVerts = vertices.length;
|
165 |
|
|
int[] ret = new int[numVerts];
|
166 |
|
|
|
167 |
c8f3a765
|
leszek
|
for(int v=0; v<numVerts; v++)
|
168 |
4a9f01f9
|
leszek
|
{
|
169 |
|
|
int vertBelongsBitmap=0x00000000;
|
170 |
c8f3a765
|
leszek
|
float[] vert=vertices[v];
|
171 |
4a9f01f9
|
leszek
|
|
172 |
c8f3a765
|
leszek
|
for(int f=0; f<mNumFaces; f++)
|
173 |
|
|
if( vertInFace(vert, move, mPuzzleNormals[f], mDist3D[f], corr) )
|
174 |
|
|
{
|
175 |
|
|
vertBelongsBitmap |= (1<<f);
|
176 |
|
|
}
|
177 |
4a9f01f9
|
leszek
|
|
178 |
c8f3a765
|
leszek
|
ret[v]=vertBelongsBitmap;
|
179 |
4a9f01f9
|
leszek
|
}
|
180 |
|
|
|
181 |
|
|
return ret;
|
182 |
|
|
}
|
183 |
|
|
|
184 |
5c825988
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185 |
|
|
|
186 |
|
|
private int getCubitIndex(float[][][] allPositions, int variant, float x, float y, float z)
|
187 |
|
|
{
|
188 |
|
|
int total = 0;
|
189 |
|
|
for(int v=0; v<variant; v++) total += allPositions[v].length;
|
190 |
|
|
|
191 |
|
|
float[][] pos = allPositions[variant];
|
192 |
|
|
float minerror = Float.MAX_VALUE;
|
193 |
|
|
int addition = -1;
|
194 |
|
|
int num = pos.length;
|
195 |
|
|
|
196 |
|
|
for(int n=0; n<num; n++)
|
197 |
|
|
{
|
198 |
|
|
float[] point = pos[n];
|
199 |
|
|
float dx = point[0]-x;
|
200 |
|
|
float dy = point[1]-y;
|
201 |
|
|
float dz = point[2]-z;
|
202 |
|
|
|
203 |
|
|
float diff = dx*dx + dy*dy + dz*dz;
|
204 |
|
|
|
205 |
|
|
if( diff<minerror )
|
206 |
|
|
{
|
207 |
|
|
addition = n;
|
208 |
|
|
minerror = diff;
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
return total + addition;
|
213 |
|
|
}
|
214 |
|
|
|
215 |
ccb61aff
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216 |
|
|
// (vertices,indices) define a single face of a set of connected elements.
|
217 |
|
|
// Return its 'diameter', i.e. the max distance (along any of its 'diameterAxis') between any two
|
218 |
|
|
// vertices of the face.
|
219 |
|
|
|
220 |
|
|
private float faceDiameter(float[][] vertices, int[][] indices)
|
221 |
|
|
{
|
222 |
|
|
int num = mDiaAxis.length;
|
223 |
|
|
|
224 |
|
|
for(int i=0; i<num; i++)
|
225 |
|
|
{
|
226 |
|
|
mMinMax[i][0] = Float.MAX_VALUE;
|
227 |
|
|
mMinMax[i][1] =-Float.MAX_VALUE;
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
for (int[] ind : indices)
|
231 |
|
|
for(int index : ind)
|
232 |
|
|
{
|
233 |
|
|
float[] v = vertices[index];
|
234 |
|
|
|
235 |
|
|
for(int i=0; i<num; i++)
|
236 |
|
|
{
|
237 |
|
|
float[] mm = mMinMax[i];
|
238 |
|
|
float[] ax = mDiaAxis[i];
|
239 |
|
|
float dist = v[0]*ax[0] + v[1]*ax[1] + v[2]*ax[2];
|
240 |
|
|
|
241 |
|
|
if ( dist > mm[1] ) mm[1] = dist;
|
242 |
|
|
if ( dist < mm[0] ) mm[0] = dist;
|
243 |
|
|
}
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
float maxDiff = 0;
|
247 |
|
|
|
248 |
|
|
for(int i=0; i<num; i++)
|
249 |
|
|
{
|
250 |
|
|
float[] mm = mMinMax[i];
|
251 |
|
|
float diff = mm[1]-mm[0];
|
252 |
|
|
if( diff>maxDiff ) maxDiff = diff;
|
253 |
|
|
}
|
254 |
|
|
|
255 |
f351be7d
|
leszek
|
return maxDiff+0.01f; // this will be rounded down to nearest int; we don't want 1.9999 here
|
256 |
ccb61aff
|
leszek
|
}
|
257 |
|
|
|
258 |
4a9f01f9
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
259 |
|
|
// return array of:
|
260 |
|
|
// 0 if this is an inner face, 1 if its diameter is 1, 2 if diameter is 2, 3 if 3, etc
|
261 |
|
|
// but only up to 5 (because the number of bands is 6 - see createIrregularFaceShape() )
|
262 |
|
|
|
263 |
60cc43cc
|
leszek
|
private int[] generateBandIndices(float[][] vertices, int[][][] indices, int[] belongs)
|
264 |
4a9f01f9
|
leszek
|
{
|
265 |
|
|
int numCubitFaces = indices.length;
|
266 |
|
|
int[] bandIndices = new int[numCubitFaces];
|
267 |
|
|
|
268 |
|
|
for(int f=0; f<numCubitFaces; f++)
|
269 |
|
|
{
|
270 |
|
|
bandIndices[f] = 0xffffffff;
|
271 |
|
|
for( int index : indices[f][0] ) bandIndices[f] &= belongs[index];
|
272 |
|
|
|
273 |
|
|
if( bandIndices[f]!=0 ) // outer face
|
274 |
|
|
{
|
275 |
|
|
float diameter = faceDiameter(vertices, indices[f]);
|
276 |
74dafadd
|
leszek
|
bandIndices[f] = diameterMap(diameter);
|
277 |
4a9f01f9
|
leszek
|
}
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
return bandIndices;
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
284 |
|
|
|
285 |
60cc43cc
|
leszek
|
private void computeMove(float[] pos, int variant)
|
286 |
4a9f01f9
|
leszek
|
{
|
287 |
|
|
int numMoves = pos.length/3;
|
288 |
|
|
float[] m = mMove[variant];
|
289 |
|
|
m[0]=0.0f;
|
290 |
|
|
m[1]=0.0f;
|
291 |
|
|
m[2]=0.0f;
|
292 |
|
|
|
293 |
|
|
for(int i=0; i<numMoves; i++)
|
294 |
|
|
{
|
295 |
|
|
m[0] += pos[3*i ];
|
296 |
|
|
m[1] += pos[3*i+1];
|
297 |
|
|
m[2] += pos[3*i+2];
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
m[0]/=numMoves;
|
301 |
|
|
m[1]/=numMoves;
|
302 |
|
|
m[2]/=numMoves;
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
306 |
|
|
|
307 |
60cc43cc
|
leszek
|
private float[][] getVertices(ArrayList<float[][]> list, int variant)
|
308 |
4a9f01f9
|
leszek
|
{
|
309 |
|
|
int total = 0;
|
310 |
|
|
int length = list.size();
|
311 |
|
|
float[][][] vertices = new float[length][][];
|
312 |
6725e537
|
leszek
|
float[] mo = mMove[variant];
|
313 |
4a9f01f9
|
leszek
|
|
314 |
|
|
for( int i=0; i<length; i++ )
|
315 |
|
|
{
|
316 |
|
|
vertices[i] = list.get(i);
|
317 |
|
|
int len = vertices[i].length;
|
318 |
|
|
for(int j=0; j<len; j++) total += vertices[i][j].length/3;
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
float[][] verts = new float[total][3];
|
322 |
|
|
int pointer = 0;
|
323 |
|
|
|
324 |
|
|
for(int i=0; i<length; i++)
|
325 |
|
|
{
|
326 |
|
|
int len = vertices[i].length;
|
327 |
|
|
|
328 |
|
|
for(int j=0; j<len; j++)
|
329 |
|
|
{
|
330 |
|
|
float[] v = vertices[i][j];
|
331 |
|
|
int l = v.length/3;
|
332 |
|
|
|
333 |
|
|
for(int k=0; k<l; k++)
|
334 |
|
|
{
|
335 |
6725e537
|
leszek
|
float[] ve = verts[pointer];
|
336 |
|
|
ve[0] = v[3*k ] - mo[0];
|
337 |
|
|
ve[1] = v[3*k+1] - mo[1];
|
338 |
|
|
ve[2] = v[3*k+2] - mo[2];
|
339 |
4a9f01f9
|
leszek
|
pointer++;
|
340 |
|
|
}
|
341 |
|
|
}
|
342 |
|
|
}
|
343 |
|
|
|
344 |
|
|
return verts;
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
348 |
|
|
|
349 |
60cc43cc
|
leszek
|
private int[][][] getIndices(ArrayList<float[][]> list)
|
350 |
4a9f01f9
|
leszek
|
{
|
351 |
|
|
int indicesSoFar=0;
|
352 |
|
|
int length = list.size();
|
353 |
|
|
int[][][] indices = new int[length][][];
|
354 |
|
|
|
355 |
|
|
for( int i=0; i<length; i++ )
|
356 |
|
|
{
|
357 |
|
|
float[][] face = list.get(i);
|
358 |
|
|
int len = face.length;
|
359 |
|
|
int[][] ind = new int[len][];
|
360 |
|
|
|
361 |
|
|
for(int j=0; j<len; j++)
|
362 |
|
|
{
|
363 |
|
|
int l = face[j].length/3;
|
364 |
|
|
ind[j] = new int[l];
|
365 |
|
|
for(int k=0; k<l; k++) ind[j][k] = (indicesSoFar++);
|
366 |
|
|
}
|
367 |
|
|
|
368 |
|
|
indices[i] = ind;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
return indices;
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
375 |
|
|
|
376 |
|
|
private void markAllVertices(float[] vertex, float[][] vertices, int[][][] indices, int pointer, int variant)
|
377 |
|
|
{
|
378 |
|
|
int numFaces = indices.length;
|
379 |
|
|
|
380 |
|
|
for(int face=0; face<numFaces; face++)
|
381 |
|
|
{
|
382 |
|
|
int len = indices[face].length;
|
383 |
|
|
|
384 |
|
|
for(int comp=0; comp<len; comp++)
|
385 |
|
|
{
|
386 |
|
|
int l = indices[face][comp].length;
|
387 |
ccb61aff
|
leszek
|
int[] in = mIndices[variant][face][comp];
|
388 |
4a9f01f9
|
leszek
|
|
389 |
|
|
for(int v=0; v<l; v++)
|
390 |
ccb61aff
|
leszek
|
if( in[v]==-1 )
|
391 |
4a9f01f9
|
leszek
|
{
|
392 |
|
|
int ind=indices[face][comp][v];
|
393 |
|
|
float[] ver=vertices[ind];
|
394 |
ccb61aff
|
leszek
|
if(vertex[0]==ver[0] && vertex[1]==ver[1] && vertex[2]==ver[2]) in[v]=pointer;
|
395 |
4a9f01f9
|
leszek
|
}
|
396 |
|
|
}
|
397 |
|
|
}
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
401 |
|
|
// So far the 'vertices/indices' are stored inefficiently, with each vertex stored three times
|
402 |
|
|
// (each one normally is a corner of three faces) or even six times. Compress!
|
403 |
|
|
// Example of six times: the central vertex here:
|
404 |
|
|
//
|
405 |
|
|
// { 1.0f, 0.0f, -1.0f,
|
406 |
|
|
// 1.0f, -1.0f, -1.0f,
|
407 |
|
|
// 1.0f, -1.0f, +0.0f,
|
408 |
|
|
// 0.0f, -1.0f, -1.0f },
|
409 |
|
|
|
410 |
60cc43cc
|
leszek
|
private void compressVerticesAndIndices(int variant, float[][] vertices, int[][][] indices)
|
411 |
4a9f01f9
|
leszek
|
{
|
412 |
|
|
if( mTmpArray==null ) mTmpArray = new ArrayList<>();
|
413 |
|
|
|
414 |
|
|
int numFaces = indices.length;
|
415 |
|
|
int pointer=0;
|
416 |
|
|
|
417 |
|
|
mIndices[variant] = new int[numFaces][][];
|
418 |
|
|
|
419 |
|
|
for(int face=0; face<numFaces;face++)
|
420 |
|
|
{
|
421 |
|
|
int len = indices[face].length;
|
422 |
|
|
mIndices[variant][face] = new int[len][];
|
423 |
|
|
|
424 |
|
|
for(int comp=0; comp<len; comp++)
|
425 |
|
|
{
|
426 |
|
|
int l = indices[face][comp].length;
|
427 |
|
|
mIndices[variant][face][comp] = new int[l];
|
428 |
|
|
for(int v=0; v<l; v++) mIndices[variant][face][comp][v] = -1;
|
429 |
|
|
}
|
430 |
|
|
}
|
431 |
|
|
|
432 |
|
|
for(int face=0; face<numFaces; face++)
|
433 |
|
|
{
|
434 |
|
|
int len = indices[face].length;
|
435 |
|
|
|
436 |
|
|
for(int comp=0; comp<len; comp++)
|
437 |
|
|
{
|
438 |
|
|
int l = indices[face][comp].length;
|
439 |
|
|
|
440 |
|
|
for(int v=0; v<l; v++)
|
441 |
|
|
{
|
442 |
|
|
if( mIndices[variant][face][comp][v]==-1 )
|
443 |
|
|
{
|
444 |
|
|
int ind=indices[face][comp][v];
|
445 |
|
|
float[] ver=vertices[ind];
|
446 |
|
|
mTmpArray.add(ver);
|
447 |
|
|
markAllVertices(ver, vertices, indices, pointer, variant);
|
448 |
|
|
pointer++;
|
449 |
|
|
}
|
450 |
|
|
}
|
451 |
|
|
}
|
452 |
|
|
}
|
453 |
|
|
|
454 |
|
|
int len = mTmpArray.size();
|
455 |
|
|
mVertices[variant] = new float[len][];
|
456 |
|
|
|
457 |
|
|
for(int i=0; i<len; i++)
|
458 |
|
|
{
|
459 |
|
|
mVertices[variant][i] = mTmpArray.remove(0);
|
460 |
|
|
}
|
461 |
|
|
}
|
462 |
|
|
|
463 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
464 |
|
|
|
465 |
c8f3a765
|
leszek
|
static boolean vertInFace(float[] vertex, float[] move, Static3D faceAxis, float dist, float corr)
|
466 |
4a9f01f9
|
leszek
|
{
|
467 |
|
|
final float MAX_ERROR = 0.01f;
|
468 |
|
|
|
469 |
|
|
float x= faceAxis.get0();
|
470 |
|
|
float y= faceAxis.get1();
|
471 |
|
|
float z= faceAxis.get2();
|
472 |
|
|
|
473 |
c8f3a765
|
leszek
|
float vx = vertex[0]*corr;
|
474 |
|
|
float vy = vertex[1]*corr;
|
475 |
|
|
float vz = vertex[2]*corr;
|
476 |
|
|
|
477 |
|
|
float a = (vx+move[0])*x + (vy+move[1])*y + (vz+move[2])*z;
|
478 |
4a9f01f9
|
leszek
|
float diff = a - dist;
|
479 |
|
|
|
480 |
|
|
return diff>-MAX_ERROR && diff<MAX_ERROR;
|
481 |
|
|
}
|
482 |
|
|
|
483 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
484 |
|
|
|
485 |
c8f3a765
|
leszek
|
private float[] computeVector(int index, float[][] vertices, int[][][] indices, int[] bandIndices, float[][] normals)
|
486 |
4a9f01f9
|
leszek
|
{
|
487 |
c8f3a765
|
leszek
|
int numFaces = indices.length;
|
488 |
|
|
int numBordering=0, numExternal=0;
|
489 |
|
|
float x=0, y=0, z=0;
|
490 |
4a9f01f9
|
leszek
|
|
491 |
c8f3a765
|
leszek
|
for(int f=0; f<numFaces; f++)
|
492 |
|
|
{
|
493 |
|
|
int numComponentsInFace = indices[f].length;
|
494 |
4a9f01f9
|
leszek
|
|
495 |
c8f3a765
|
leszek
|
for(int c=0; c<numComponentsInFace; c++)
|
496 |
|
|
{
|
497 |
|
|
int[] ind = indices[f][c];
|
498 |
|
|
int numVertsInComponent = ind.length;
|
499 |
4a9f01f9
|
leszek
|
|
500 |
c8f3a765
|
leszek
|
for(int v=0; v<numVertsInComponent; v++)
|
501 |
|
|
{
|
502 |
|
|
if( ind[v]==index )
|
503 |
|
|
{
|
504 |
|
|
float[] nor = normals[f];
|
505 |
4a9f01f9
|
leszek
|
|
506 |
c8f3a765
|
leszek
|
x += nor[0];
|
507 |
|
|
y += nor[1];
|
508 |
|
|
z += nor[2];
|
509 |
4a9f01f9
|
leszek
|
|
510 |
c8f3a765
|
leszek
|
numBordering++;
|
511 |
|
|
if( bandIndices[f]>0 ) numExternal++;
|
512 |
17a55777
|
leszek
|
|
513 |
c8f3a765
|
leszek
|
v = numVertsInComponent;
|
514 |
|
|
c = numComponentsInFace;
|
515 |
|
|
}
|
516 |
|
|
}
|
517 |
|
|
}
|
518 |
|
|
}
|
519 |
17a55777
|
leszek
|
|
520 |
c8f3a765
|
leszek
|
return ( numExternal<2 || numBordering<3 ) ? null : new float[] { x/numBordering, y/numBordering, z/numBordering};
|
521 |
17a55777
|
leszek
|
}
|
522 |
|
|
|
523 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
524 |
|
|
|
525 |
c8f3a765
|
leszek
|
private void createCubitFaceNormal(float[] output, float[] v0, float[] v1, float[] v2)
|
526 |
17a55777
|
leszek
|
{
|
527 |
c8f3a765
|
leszek
|
float ax = v0[0]-v1[0];
|
528 |
|
|
float ay = v0[1]-v1[1];
|
529 |
|
|
float az = v0[2]-v1[2];
|
530 |
17a55777
|
leszek
|
|
531 |
c8f3a765
|
leszek
|
float bx = v2[0]-v1[0];
|
532 |
|
|
float by = v2[1]-v1[1];
|
533 |
|
|
float bz = v2[2]-v1[2];
|
534 |
17a55777
|
leszek
|
|
535 |
c8f3a765
|
leszek
|
output[0] = ay*bz - az*by;
|
536 |
|
|
output[1] = az*bx - ax*bz;
|
537 |
|
|
output[2] = ax*by - ay*bx;
|
538 |
17a55777
|
leszek
|
|
539 |
c8f3a765
|
leszek
|
float len = (float)Math.sqrt(output[0]*output[0] + output[1]*output[1] + output[2]*output[2]);
|
540 |
17a55777
|
leszek
|
|
541 |
c8f3a765
|
leszek
|
if( len!=0 )
|
542 |
|
|
{
|
543 |
|
|
output[0] /= len;
|
544 |
|
|
output[1] /= len;
|
545 |
|
|
output[2] /= len;
|
546 |
|
|
}
|
547 |
|
|
else
|
548 |
|
|
{
|
549 |
|
|
android.util.Log.e("D", "ERROR in createCubitFaceNormal!");
|
550 |
17a55777
|
leszek
|
}
|
551 |
4a9f01f9
|
leszek
|
}
|
552 |
|
|
|
553 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
554 |
|
|
|
555 |
c8f3a765
|
leszek
|
private float[][] generateCubitFaceNormals(float[][] vertices, int[][][] indices)
|
556 |
4a9f01f9
|
leszek
|
{
|
557 |
|
|
int numFaces = indices.length;
|
558 |
c8f3a765
|
leszek
|
float[][] ret = new float[numFaces][3];
|
559 |
17a55777
|
leszek
|
|
560 |
4a9f01f9
|
leszek
|
for(int f=0; f<numFaces; f++)
|
561 |
|
|
{
|
562 |
c8f3a765
|
leszek
|
int[] verts = indices[f][0];
|
563 |
|
|
int numVerts = verts.length;
|
564 |
4a9f01f9
|
leszek
|
|
565 |
c8f3a765
|
leszek
|
for(int v=0; v<numVerts; v++)
|
566 |
4a9f01f9
|
leszek
|
{
|
567 |
c8f3a765
|
leszek
|
int i0 = verts[0];
|
568 |
|
|
int i1 = verts[1];
|
569 |
|
|
int i2 = verts[2];
|
570 |
4a9f01f9
|
leszek
|
|
571 |
c8f3a765
|
leszek
|
float[] v0 = vertices[i0];
|
572 |
|
|
float[] v1 = vertices[i1];
|
573 |
|
|
float[] v2 = vertices[i2];
|
574 |
4a9f01f9
|
leszek
|
|
575 |
c8f3a765
|
leszek
|
createCubitFaceNormal(ret[f], v0,v1,v2);
|
576 |
4a9f01f9
|
leszek
|
}
|
577 |
|
|
}
|
578 |
|
|
|
579 |
c8f3a765
|
leszek
|
return ret;
|
580 |
4a9f01f9
|
leszek
|
}
|
581 |
|
|
|
582 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
583 |
|
|
|
584 |
|
|
private float[][] generateVectors(float[][] vertices, int[][][] indices, int[] bandIndices)
|
585 |
|
|
{
|
586 |
|
|
int len = vertices.length;
|
587 |
|
|
float[][] vectors = new float[len][];
|
588 |
c8f3a765
|
leszek
|
float[][] normals = generateCubitFaceNormals(vertices,indices);
|
589 |
4a9f01f9
|
leszek
|
|
590 |
|
|
for(int i=0; i<len; i++)
|
591 |
|
|
{
|
592 |
c8f3a765
|
leszek
|
vectors[i] = computeVector(i,vertices,indices,bandIndices,normals);
|
593 |
4a9f01f9
|
leszek
|
}
|
594 |
|
|
|
595 |
|
|
return vectors;
|
596 |
|
|
}
|
597 |
|
|
|
598 |
c7c72305
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
599 |
|
|
|
600 |
6155e738
|
leszek
|
private float[] buildFaceVertices(float[][] vertices, int[] indices, float[] pos, Static4D quat)
|
601 |
c7c72305
|
leszek
|
{
|
602 |
45aedaa7
|
leszek
|
int num = indices.length;
|
603 |
|
|
float[] ret = new float[3*num];
|
604 |
c7c72305
|
leszek
|
|
605 |
45aedaa7
|
leszek
|
for(int i=0; i<num; i++)
|
606 |
c7c72305
|
leszek
|
{
|
607 |
45aedaa7
|
leszek
|
float[] v = vertices[indices[i]];
|
608 |
6155e738
|
leszek
|
QuatHelper.rotateVectorByQuat(mTmp,v[0],v[1],v[2],1,quat);
|
609 |
|
|
|
610 |
|
|
ret[3*i ] = mTmp[0] + pos[0];
|
611 |
|
|
ret[3*i+1] = mTmp[1] + pos[1];
|
612 |
|
|
ret[3*i+2] = mTmp[2] + pos[2];
|
613 |
45aedaa7
|
leszek
|
}
|
614 |
|
|
|
615 |
|
|
return ret;
|
616 |
|
|
}
|
617 |
|
|
|
618 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
619 |
c7c72305
|
leszek
|
|
620 |
45aedaa7
|
leszek
|
private void removeInternalWalls(ArrayList<BandagedCubitFace> list)
|
621 |
|
|
{
|
622 |
|
|
Collections.sort(list,new SortByCenterCast());
|
623 |
|
|
|
624 |
|
|
int numElements = list.size();
|
625 |
|
|
final float MAXDIFF = 0.01f;
|
626 |
|
|
|
627 |
|
|
for(int e=0; e<numElements; e++)
|
628 |
|
|
{
|
629 |
|
|
int ne = e+1;
|
630 |
|
|
BandagedCubitFace f1 = list.get(e);
|
631 |
|
|
float[] center = f1.center;
|
632 |
|
|
|
633 |
|
|
while( ne<numElements )
|
634 |
c7c72305
|
leszek
|
{
|
635 |
45aedaa7
|
leszek
|
BandagedCubitFace f2 = list.get(ne);
|
636 |
|
|
float diff = f2.centerCast-f1.centerCast;
|
637 |
c7c72305
|
leszek
|
|
638 |
45aedaa7
|
leszek
|
if( diff>-MAXDIFF && diff<MAXDIFF )
|
639 |
|
|
{
|
640 |
|
|
float[] c = f2.center;
|
641 |
|
|
float dx = c[0]-center[0];
|
642 |
|
|
float dy = c[1]-center[1];
|
643 |
|
|
float dz = c[2]-center[2];
|
644 |
|
|
|
645 |
|
|
float d = dx*dx + dy*dy + dz*dz;
|
646 |
|
|
|
647 |
|
|
if( d>-MAXDIFF && d<MAXDIFF )
|
648 |
|
|
{
|
649 |
|
|
list.remove(ne);
|
650 |
|
|
list.remove(e);
|
651 |
|
|
numElements -= 2;
|
652 |
|
|
e--;
|
653 |
|
|
break;
|
654 |
|
|
}
|
655 |
|
|
}
|
656 |
|
|
else break;
|
657 |
|
|
|
658 |
|
|
ne++;
|
659 |
|
|
}
|
660 |
c7c72305
|
leszek
|
}
|
661 |
|
|
}
|
662 |
|
|
|
663 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
664 |
|
|
|
665 |
45aedaa7
|
leszek
|
private float[][] getNextSection(ArrayList<BandagedCubitFace> list)
|
666 |
c7c72305
|
leszek
|
{
|
667 |
45aedaa7
|
leszek
|
int numElements = list.size();
|
668 |
|
|
if( numElements==0 ) return null;
|
669 |
c7c72305
|
leszek
|
|
670 |
45aedaa7
|
leszek
|
final float MAXDIFF = 0.01f;
|
671 |
|
|
float[][] ret = new float[numElements][];
|
672 |
|
|
BandagedCubitFace bcf = list.remove(0);
|
673 |
|
|
float[] normal = bcf.normal;
|
674 |
|
|
int removed = 1;
|
675 |
|
|
|
676 |
|
|
ret[0] = bcf.vertices;
|
677 |
|
|
|
678 |
|
|
for(int e=0; e<numElements-1; e++)
|
679 |
|
|
{
|
680 |
|
|
BandagedCubitFace f = list.get(e);
|
681 |
|
|
float[] n = f.normal;
|
682 |
|
|
|
683 |
|
|
float dx = n[0]-normal[0];
|
684 |
|
|
float dy = n[1]-normal[1];
|
685 |
|
|
float dz = n[2]-normal[2];
|
686 |
|
|
|
687 |
|
|
float diff = dx*dx + dy*dy + dz*dz;
|
688 |
|
|
|
689 |
|
|
if( diff>-MAXDIFF && diff<MAXDIFF )
|
690 |
c7c72305
|
leszek
|
{
|
691 |
45aedaa7
|
leszek
|
list.remove(e);
|
692 |
|
|
e--;
|
693 |
|
|
numElements--;
|
694 |
|
|
ret[removed++] = f.vertices;
|
695 |
c7c72305
|
leszek
|
}
|
696 |
45aedaa7
|
leszek
|
}
|
697 |
|
|
|
698 |
|
|
float[][] ret2 = new float[removed][];
|
699 |
|
|
for(int i=0; i<removed; i++) ret2[i] = ret[i];
|
700 |
c7c72305
|
leszek
|
|
701 |
45aedaa7
|
leszek
|
return ret2;
|
702 |
c7c72305
|
leszek
|
}
|
703 |
|
|
|
704 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
705 |
|
|
|
706 |
6725e537
|
leszek
|
private boolean isConnected(final float[] face1, final float[] face2)
|
707 |
c7c72305
|
leszek
|
{
|
708 |
45aedaa7
|
leszek
|
float MAXDIFF = 0.01f;
|
709 |
|
|
int l1 = face1.length/3;
|
710 |
|
|
int l2 = face2.length/3;
|
711 |
c7c72305
|
leszek
|
|
712 |
45aedaa7
|
leszek
|
for(int i=0; i<l1; i++)
|
713 |
c7c72305
|
leszek
|
{
|
714 |
45aedaa7
|
leszek
|
float x = face1[3*i ];
|
715 |
|
|
float y = face1[3*i+1];
|
716 |
|
|
float z = face1[3*i+2];
|
717 |
c7c72305
|
leszek
|
|
718 |
45aedaa7
|
leszek
|
for(int j=0; j<l2; j++)
|
719 |
|
|
{
|
720 |
|
|
float dx = x-face2[3*j ];
|
721 |
|
|
float dy = y-face2[3*j+1];
|
722 |
|
|
float dz = z-face2[3*j+2];
|
723 |
|
|
|
724 |
|
|
if( dx*dx + dy*dy + dz*dz < MAXDIFF )
|
725 |
c7c72305
|
leszek
|
{
|
726 |
45aedaa7
|
leszek
|
int inext = i==l1-1 ? 0 : i+1;
|
727 |
|
|
int jprev = j==0 ? l2-1 : j-1;
|
728 |
|
|
|
729 |
|
|
dx = face1[3*inext ] - face2[3*jprev ];
|
730 |
|
|
dy = face1[3*inext+1] - face2[3*jprev+1];
|
731 |
|
|
dz = face1[3*inext+2] - face2[3*jprev+2];
|
732 |
|
|
|
733 |
|
|
if( dx*dx + dy*dy + dz*dz < MAXDIFF ) return true;
|
734 |
|
|
|
735 |
|
|
int iprev = i==0 ? l1-1 : i-1;
|
736 |
|
|
int jnext = j==l2-1 ? 0 : j+1;
|
737 |
|
|
|
738 |
|
|
dx = face1[3*iprev ] - face2[3*jnext ];
|
739 |
|
|
dy = face1[3*iprev+1] - face2[3*jnext+1];
|
740 |
|
|
dz = face1[3*iprev+2] - face2[3*jnext+2];
|
741 |
|
|
|
742 |
|
|
return dx*dx + dy*dy + dz*dz < MAXDIFF;
|
743 |
c7c72305
|
leszek
|
}
|
744 |
45aedaa7
|
leszek
|
}
|
745 |
|
|
}
|
746 |
c7c72305
|
leszek
|
|
747 |
45aedaa7
|
leszek
|
return false;
|
748 |
|
|
}
|
749 |
c7c72305
|
leszek
|
|
750 |
45aedaa7
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
751 |
c7c72305
|
leszek
|
|
752 |
45aedaa7
|
leszek
|
private float[][] getNextConnected(float[][] section, int nonNull)
|
753 |
|
|
{
|
754 |
|
|
float[][] ret = new float[nonNull][];
|
755 |
|
|
int start,len = section.length;
|
756 |
|
|
|
757 |
|
|
for(start=0; start<len; start++)
|
758 |
|
|
if( section[start]!=null )
|
759 |
|
|
{
|
760 |
|
|
ret[0] = section[start];
|
761 |
|
|
section[start] = null;
|
762 |
|
|
break;
|
763 |
|
|
}
|
764 |
|
|
|
765 |
eeb0898c
|
leszek
|
int firstUnverified = 0;
|
766 |
|
|
int lastUnverified = 0;
|
767 |
|
|
start++;
|
768 |
45aedaa7
|
leszek
|
|
769 |
eeb0898c
|
leszek
|
while( firstUnverified<=lastUnverified )
|
770 |
45aedaa7
|
leszek
|
{
|
771 |
|
|
for(int i=start; i<len; i++)
|
772 |
eeb0898c
|
leszek
|
{
|
773 |
|
|
if( section[i]!=null && isConnected(ret[firstUnverified],section[i]) )
|
774 |
45aedaa7
|
leszek
|
{
|
775 |
eeb0898c
|
leszek
|
lastUnverified++;
|
776 |
|
|
ret[lastUnverified] = section[i];
|
777 |
45aedaa7
|
leszek
|
section[i] = null;
|
778 |
|
|
}
|
779 |
eeb0898c
|
leszek
|
}
|
780 |
|
|
firstUnverified++;
|
781 |
c7c72305
|
leszek
|
}
|
782 |
45aedaa7
|
leszek
|
|
783 |
eeb0898c
|
leszek
|
float[][] ret2 = new float[lastUnverified+1][];
|
784 |
|
|
for(int i=0; i<=lastUnverified; i++) ret2[i] = ret[i];
|
785 |
45aedaa7
|
leszek
|
|
786 |
|
|
return ret2;
|
787 |
c7c72305
|
leszek
|
}
|
788 |
|
|
|
789 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
790 |
|
|
|
791 |
ffc7ccd5
|
leszek
|
private void fillUpVertexArray()
|
792 |
c7c72305
|
leszek
|
{
|
793 |
45aedaa7
|
leszek
|
ArrayList<BandagedCubitFace> list = new ArrayList<>();
|
794 |
6155e738
|
leszek
|
mTmp = new float[4];
|
795 |
c7c72305
|
leszek
|
|
796 |
a662c27e
|
leszek
|
int numVariants = getNumVariants(mNumLayers);
|
797 |
|
|
|
798 |
|
|
float[][][] verts = new float[numVariants][][];
|
799 |
|
|
int[][][] inds = new int[numVariants][][];
|
800 |
|
|
|
801 |
|
|
for(int v=0; v<numVariants; v++)
|
802 |
|
|
{
|
803 |
|
|
verts[v] = getVertices(mNumLayers,v);
|
804 |
|
|
inds[v] = getIndices(mNumLayers,v);
|
805 |
|
|
}
|
806 |
|
|
|
807 |
c7c72305
|
leszek
|
for(int e=0; e<mNumElements; e++)
|
808 |
|
|
{
|
809 |
6155e738
|
leszek
|
BandagedElement element = mElements[e];
|
810 |
|
|
int variant = element.getVariant();
|
811 |
|
|
float[] pos = element.getPos();
|
812 |
|
|
Static4D quat = element.getQuat();
|
813 |
|
|
|
814 |
a662c27e
|
leszek
|
for( int[] ind : inds[variant])
|
815 |
c7c72305
|
leszek
|
{
|
816 |
a662c27e
|
leszek
|
float[] vertices = buildFaceVertices(verts[variant],ind,pos,quat);
|
817 |
45aedaa7
|
leszek
|
BandagedCubitFace face = new BandagedCubitFace(vertices);
|
818 |
|
|
list.add(face);
|
819 |
c7c72305
|
leszek
|
}
|
820 |
|
|
}
|
821 |
|
|
|
822 |
45aedaa7
|
leszek
|
removeInternalWalls(list);
|
823 |
|
|
|
824 |
|
|
while(true)
|
825 |
c7c72305
|
leszek
|
{
|
826 |
45aedaa7
|
leszek
|
float[][] section = getNextSection(list);
|
827 |
|
|
|
828 |
|
|
if( section!=null )
|
829 |
|
|
{
|
830 |
|
|
int nonNull = section.length;
|
831 |
|
|
|
832 |
|
|
while(nonNull>0)
|
833 |
|
|
{
|
834 |
|
|
float[][] connected = getNextConnected(section,nonNull);
|
835 |
|
|
nonNull -= connected.length;
|
836 |
|
|
mVertexArray.add(connected);
|
837 |
|
|
}
|
838 |
|
|
}
|
839 |
|
|
else break;
|
840 |
c7c72305
|
leszek
|
}
|
841 |
|
|
}
|
842 |
|
|
|
843 |
a662c27e
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
844 |
|
|
|
845 |
|
|
private boolean layersHaveChanged(int[] numLayers)
|
846 |
|
|
{
|
847 |
|
|
if( mNumLayers==null ) return true;
|
848 |
|
|
|
849 |
|
|
int len = mNumLayers.length;
|
850 |
|
|
|
851 |
|
|
for(int i=0; i<len; i++)
|
852 |
|
|
if(mNumLayers[i]!=numLayers[i]) return true;
|
853 |
|
|
|
854 |
|
|
return false;
|
855 |
|
|
}
|
856 |
|
|
|
857 |
4a9f01f9
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
858 |
|
|
// PUBLIC API
|
859 |
|
|
|
860 |
|
|
public void prepare(int numVariants, int[] numLayers)
|
861 |
|
|
{
|
862 |
|
|
if( mVertexArray==null ) mVertexArray = new ArrayList<>();
|
863 |
c8f3a765
|
leszek
|
mCalledFromBandagedObject = false;
|
864 |
4a9f01f9
|
leszek
|
mVertices= new float[numVariants][][];
|
865 |
|
|
mIndices = new int[numVariants][][][];
|
866 |
|
|
mMove = new float[numVariants][3];
|
867 |
|
|
mBandIndices = new int[numVariants][];
|
868 |
|
|
mFaceBelongsBitmap= new int[numVariants][];
|
869 |
|
|
|
870 |
a662c27e
|
leszek
|
if( layersHaveChanged(numLayers) )
|
871 |
|
|
{
|
872 |
|
|
mAllPositions = getPositions(numLayers);
|
873 |
|
|
}
|
874 |
|
|
|
875 |
|
|
int num = numLayers.length;
|
876 |
|
|
mNumLayers = new int[num];
|
877 |
|
|
for(int l=0; l<num; l++) mNumLayers[l] = numLayers[l];
|
878 |
|
|
|
879 |
c8f3a765
|
leszek
|
mPuzzleNormals= getNormals();
|
880 |
|
|
mNumFaces = mPuzzleNormals.length;
|
881 |
|
|
mDist3D = getDist3D(mNumLayers);
|
882 |
|
|
mDiaAxis = getDiameterAxis();
|
883 |
|
|
mMinMax = new float[mDiaAxis.length][2];
|
884 |
4a9f01f9
|
leszek
|
}
|
885 |
|
|
|
886 |
60cc43cc
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
887 |
|
|
|
888 |
|
|
public Static4D getCubitQuat(float x, float y, float z)
|
889 |
|
|
{
|
890 |
|
|
int elementVariant = getElementVariant(mNumLayers, x,y,z);
|
891 |
|
|
int cubitIndex = getCubitIndex(mAllPositions,elementVariant, x,y,z);
|
892 |
|
|
return getElementQuat(mNumLayers, cubitIndex);
|
893 |
|
|
}
|
894 |
|
|
|
895 |
4a9f01f9
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
896 |
|
|
|
897 |
|
|
public ObjectShape createIrregularShape(int variant, float[] pos)
|
898 |
|
|
{
|
899 |
|
|
mVertexArray.clear();
|
900 |
|
|
|
901 |
|
|
mNumElements = pos.length/3;
|
902 |
|
|
mElements = new BandagedElement[mNumElements];
|
903 |
5c825988
|
leszek
|
|
904 |
|
|
for(int e=0; e<mNumElements; e++)
|
905 |
8e878e7c
|
leszek
|
{
|
906 |
5c825988
|
leszek
|
float x= pos[3*e ];
|
907 |
|
|
float y= pos[3*e+1];
|
908 |
|
|
float z= pos[3*e+2];
|
909 |
|
|
int elementVariant = getElementVariant(mNumLayers, x,y,z);
|
910 |
a662c27e
|
leszek
|
int cubitIndex = getCubitIndex(mAllPositions,elementVariant, x,y,z);
|
911 |
5c825988
|
leszek
|
Static4D quat = getElementQuat(mNumLayers, cubitIndex);
|
912 |
|
|
mElements[e] = new BandagedElement(pos, 3*e, elementVariant, quat);
|
913 |
8e878e7c
|
leszek
|
}
|
914 |
4a9f01f9
|
leszek
|
|
915 |
ffc7ccd5
|
leszek
|
fillUpVertexArray();
|
916 |
4a9f01f9
|
leszek
|
|
917 |
|
|
computeMove(pos,variant);
|
918 |
|
|
float[][] verts = getVertices(mVertexArray,variant);
|
919 |
|
|
int[][][] inds = getIndices(mVertexArray);
|
920 |
|
|
|
921 |
|
|
compressVerticesAndIndices(variant,verts,inds);
|
922 |
|
|
|
923 |
|
|
return new ObjectShape(mVertices[variant], mIndices[variant]);
|
924 |
|
|
}
|
925 |
|
|
|
926 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
927 |
|
|
|
928 |
|
|
public ObjectFaceShape createIrregularFaceShape(int variant, boolean iconMode)
|
929 |
|
|
{
|
930 |
6155e738
|
leszek
|
float[][] bands = getBands(iconMode, mNumLayers);
|
931 |
c8f3a765
|
leszek
|
float corr = mCalledFromBandagedObject ? 1.0f : sizeCorrection(mNumLayers);
|
932 |
4a9f01f9
|
leszek
|
|
933 |
|
|
if( mBandIndices[variant]==null )
|
934 |
|
|
{
|
935 |
c8f3a765
|
leszek
|
mFaceBelongsBitmap[variant] = computeFaceBelongsBitmap(mVertices[variant], mMove[variant],corr);
|
936 |
4a9f01f9
|
leszek
|
mBandIndices[variant] = generateBandIndices(mVertices[variant], mIndices[variant], mFaceBelongsBitmap[variant]);
|
937 |
|
|
}
|
938 |
|
|
|
939 |
|
|
return new ObjectFaceShape(bands,mBandIndices[variant],null);
|
940 |
|
|
}
|
941 |
|
|
|
942 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
943 |
|
|
|
944 |
|
|
public ObjectVertexEffects createVertexEffects(int variant, boolean roundCorners)
|
945 |
|
|
{
|
946 |
|
|
float[][] vertVec= generateVectors(mVertices[variant], mIndices[variant], mBandIndices[variant]);
|
947 |
|
|
int numEffects = mVertices[variant].length;
|
948 |
|
|
float S = STRENGTH;
|
949 |
|
|
float[] region = {0,0,0,REGION_SIZE};
|
950 |
|
|
String[] names = new String[numEffects];
|
951 |
|
|
float[][] regions= new float[numEffects][];
|
952 |
|
|
boolean[] uses = new boolean[numEffects];
|
953 |
|
|
float[][] vars = new float[numEffects][];
|
954 |
|
|
|
955 |
|
|
for(int i=0; i<numEffects; i++)
|
956 |
|
|
{
|
957 |
|
|
float[] v = vertVec[i];
|
958 |
|
|
|
959 |
|
|
if( v!=null )
|
960 |
|
|
{
|
961 |
|
|
names[i] = FactoryCubit.NAME;
|
962 |
|
|
regions[i]= region;
|
963 |
|
|
uses[i] = roundCorners;
|
964 |
|
|
vars[i] = new float[] { 0, S*v[0], S*v[1], S*v[2], 1 };
|
965 |
|
|
}
|
966 |
|
|
}
|
967 |
|
|
|
968 |
|
|
return new ObjectVertexEffects(names,vars,mVertices[variant],regions,uses);
|
969 |
|
|
}
|
970 |
|
|
|
971 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
972 |
|
|
|
973 |
|
|
public MeshBase createMesh(float[] pos, int[] numLayers, boolean iconMode, boolean roundCorners)
|
974 |
|
|
{
|
975 |
|
|
prepare(1,numLayers);
|
976 |
c8f3a765
|
leszek
|
|
977 |
|
|
mCalledFromBandagedObject = true;
|
978 |
|
|
|
979 |
4a9f01f9
|
leszek
|
ObjectShape shape = createIrregularShape(0,pos);
|
980 |
|
|
ObjectFaceShape face = createIrregularFaceShape(0,iconMode);
|
981 |
|
|
ObjectVertexEffects effects = createVertexEffects(0,roundCorners);
|
982 |
|
|
int numFaces = shape.getNumFaces();
|
983 |
|
|
|
984 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
985 |
|
|
factory.clear();
|
986 |
|
|
factory.createNewFaceTransform(shape,null);
|
987 |
1fda81c4
|
leszek
|
return factory.createRoundedSolid(shape,face,effects,numFaces);
|
988 |
4a9f01f9
|
leszek
|
}
|
989 |
|
|
}
|