Revision c65d5889
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/objectlib/helpers/FactoryBandagedCuboid.java | ||
---|---|---|
55 | 55 |
private float dX, dY, dZ; |
56 | 56 |
private int[][] mWall; |
57 | 57 |
private int[][] mPoints; |
58 |
private boolean[][][] mTmp; |
|
58 |
private float[][] mCuts; |
|
59 |
private float[][] mNormal; |
|
60 |
private BandagedElementCuboid[] mElements; |
|
61 |
private int mNumElements; |
|
59 | 62 |
|
60 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 64 |
|
... | ... | |
64 | 67 |
|
65 | 68 |
} |
66 | 69 |
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
public float[][] getCuts(int[] numLayers) |
|
73 |
{ |
|
74 |
int numFaces = 6; |
|
75 |
float[][] cuts = new float[numFaces][]; |
|
76 |
|
|
77 |
for(int axis=0; axis<numFaces; axis++) |
|
78 |
{ |
|
79 |
int len = numLayers[axis/2]; |
|
80 |
float start = 1-len*0.5f; |
|
81 |
|
|
82 |
if( len>=2 ) |
|
83 |
{ |
|
84 |
cuts[axis] = new float[len-1]; |
|
85 |
for(int i=0; i<len-1; i++) cuts[axis][i] = start+i; |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
return cuts; |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
private void createNormal() |
|
95 |
{ |
|
96 |
if( mNormal==null ) |
|
97 |
{ |
|
98 |
mNormal = new float[][] |
|
99 |
{ |
|
100 |
{ 1, 0, 0 }, |
|
101 |
{-1, 0, 0 }, |
|
102 |
{ 0, 1, 0 }, |
|
103 |
{ 0,-1, 0 }, |
|
104 |
{ 0, 0, 1 }, |
|
105 |
{ 0, 0,-1 } |
|
106 |
}; |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
67 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 111 |
|
69 | 112 |
private float[][] getVertices(ArrayList<float[]> list, float[] move, int variant) |
... | ... | |
213 | 256 |
|
214 | 257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
215 | 258 |
|
216 |
private boolean cubitExists(float[] pos, float x, float y, float z)
|
|
259 |
private boolean elementExists(int x, int y, int z)
|
|
217 | 260 |
{ |
218 |
int len = pos.length/3; |
|
219 |
|
|
220 |
for(int i=0; i<len; i++) |
|
221 |
if( pos[3*i]==x && pos[3*i+1]==y && pos[3*i+2]==z ) return true; |
|
261 |
for(int i=0; i<mNumElements; i++) |
|
262 |
{ |
|
263 |
int[] row = mElements[i].getRotRow(); |
|
264 |
if( row[0]==x && row[2]==y && row[4]==z ) return true; |
|
265 |
} |
|
222 | 266 |
|
223 | 267 |
return false; |
224 | 268 |
} |
225 | 269 |
|
226 | 270 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
227 | 271 |
|
228 |
private void createRight(int x, ArrayList<float[]> list)
|
|
272 |
private void displayWall(String tmp)
|
|
229 | 273 |
{ |
230 |
for(int y=0; y<mMax; y++) |
|
231 |
for(int z=0; z<mMax; z++) |
|
274 |
StringBuilder sb = new StringBuilder(); |
|
275 |
|
|
276 |
for(int i=0; i<mMax; i++) |
|
277 |
{ |
|
278 |
for(int j=0; j<mMax; j++) |
|
232 | 279 |
{ |
233 |
boolean b = (y<mY && z<mZ) && ( mTmp[x][mY-1-y][mZ-1-z] && (x+1>=mX || !mTmp[x+1][mY-1-y][mZ-1-z]) );
|
|
234 |
mWall[z][y] = b ? WALL_MARKED : WALL_EMPTY;
|
|
280 |
sb.append(mWall[i][j]);
|
|
281 |
sb.append(' ');
|
|
235 | 282 |
} |
283 |
sb.append(" - "); |
|
284 |
} |
|
285 |
|
|
286 |
android.util.Log.e("D", tmp+" : "+sb); |
|
287 |
} |
|
288 |
|
|
289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
290 |
|
|
291 |
private void createRight(int x, ArrayList<float[]> list) |
|
292 |
{ |
|
293 |
for(int i=0; i<mMax; i++) |
|
294 |
for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY; |
|
295 |
|
|
296 |
for(int i=0; i<mNumElements; i++) |
|
297 |
{ |
|
298 |
int[] row = mElements[i].getRotRow(); |
|
299 |
int y = mY-1-row[2]; |
|
300 |
int z = mZ-1-row[4]; |
|
301 |
if( row[0]==x ) mWall[z][y] = elementExists(x+1,y,z) ? WALL_EMPTY : WALL_MARKED; |
|
302 |
} |
|
236 | 303 |
|
237 | 304 |
createVertices(list,mWall,AXIS_XP,x); |
238 | 305 |
} |
... | ... | |
241 | 308 |
|
242 | 309 |
private void createLeft(int x, ArrayList<float[]> list) |
243 | 310 |
{ |
244 |
for(int y=0; y<mMax; y++) |
|
245 |
for(int z=0; z<mMax; z++) |
|
246 |
{ |
|
247 |
boolean b = (y<mY && z<mZ) && ( mTmp[x][mY-1-y][z] && (x<1 || !mTmp[x-1][mY-1-y][z]) ); |
|
248 |
mWall[z][y] = b ? WALL_MARKED : WALL_EMPTY; |
|
249 |
} |
|
311 |
for(int i=0; i<mMax; i++) |
|
312 |
for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY; |
|
313 |
|
|
314 |
for(int i=0; i<mNumElements; i++) |
|
315 |
{ |
|
316 |
int[] row = mElements[i].getRotRow(); |
|
317 |
int y = mY-1-row[2]; |
|
318 |
int z = row[4]; |
|
319 |
if( row[0]==x ) mWall[z][y] = elementExists(x-1,y,z) ? WALL_EMPTY : WALL_MARKED; |
|
320 |
} |
|
250 | 321 |
|
251 | 322 |
createVertices(list,mWall,AXIS_XM,x); |
252 | 323 |
} |
... | ... | |
255 | 326 |
|
256 | 327 |
private void createTop(int y, ArrayList<float[]> list) |
257 | 328 |
{ |
258 |
for(int z=0; z<mMax; z++) |
|
259 |
for(int x=0; x<mMax; x++) |
|
260 |
{ |
|
261 |
boolean b = (x<mX && z<mZ) && ( mTmp[x][y][z] && (y+1>=mY || !mTmp[x][y+1][z]) ); |
|
262 |
mWall[x][z] = b ? WALL_MARKED : WALL_EMPTY; |
|
263 |
} |
|
329 |
for(int i=0; i<mMax; i++) |
|
330 |
for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY; |
|
331 |
|
|
332 |
for(int i=0; i< mNumElements; i++) |
|
333 |
{ |
|
334 |
int[] row = mElements[i].getRotRow(); |
|
335 |
int x = row[0]; |
|
336 |
int z = row[4]; |
|
337 |
if( row[2]==y ) mWall[x][z] = elementExists(x,y+1,z) ? WALL_EMPTY : WALL_MARKED; |
|
338 |
} |
|
264 | 339 |
|
265 | 340 |
createVertices(list,mWall,AXIS_YP,y); |
266 | 341 |
} |
... | ... | |
269 | 344 |
|
270 | 345 |
private void createBottom(int y, ArrayList<float[]> list) |
271 | 346 |
{ |
272 |
for(int z=0; z<mMax; z++) |
|
273 |
for(int x=0; x<mMax; x++) |
|
274 |
{ |
|
275 |
boolean b = (x<mX && z<mZ) && ( mTmp[x][y][mZ-1-z] && (y<1 || !mTmp[x][y-1][mZ-1-z]) ); |
|
276 |
mWall[x][z] = b ? WALL_MARKED : WALL_EMPTY; |
|
277 |
} |
|
347 |
for(int i=0; i<mMax; i++) |
|
348 |
for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY; |
|
349 |
|
|
350 |
for(int i=0; i<mNumElements; i++) |
|
351 |
{ |
|
352 |
int[] row = mElements[i].getRotRow(); |
|
353 |
int x = row[0]; |
|
354 |
int z = mZ-1-row[4]; |
|
355 |
if( row[2]==y ) mWall[x][z] = elementExists(x,y-1,z) ? WALL_EMPTY : WALL_MARKED; |
|
356 |
} |
|
278 | 357 |
|
279 | 358 |
createVertices(list,mWall,AXIS_YM,y); |
280 | 359 |
} |
... | ... | |
283 | 362 |
|
284 | 363 |
private void createFront(int z, ArrayList<float[]> list) |
285 | 364 |
{ |
286 |
for(int y=0; y<mMax; y++) |
|
287 |
for(int x=0; x<mMax; x++) |
|
288 |
{ |
|
289 |
boolean b = (x<mX && y<mY) && ( mTmp[x][mY-1-y][z] && (z+1>=mZ || !mTmp[x][mY-1-y][z+1]) ); |
|
290 |
mWall[x][y] = b ? WALL_MARKED : WALL_EMPTY; |
|
291 |
} |
|
365 |
for(int i=0; i<mMax; i++) |
|
366 |
for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY; |
|
367 |
|
|
368 |
for(int i=0; i<mNumElements; i++) |
|
369 |
{ |
|
370 |
int[] row = mElements[i].getRotRow(); |
|
371 |
int x = row[0]; |
|
372 |
int y = mY-1-row[2]; |
|
373 |
if( row[4]==z ) mWall[x][y] = elementExists(x,y,z+1) ? WALL_EMPTY : WALL_MARKED; |
|
374 |
} |
|
292 | 375 |
|
293 | 376 |
createVertices(list,mWall,AXIS_ZP,z); |
294 | 377 |
} |
... | ... | |
297 | 380 |
|
298 | 381 |
private void createBack(int z, ArrayList<float[]> list) |
299 | 382 |
{ |
300 |
for(int y=0; y<mMax; y++) |
|
301 |
for(int x=0; x<mMax; x++) |
|
302 |
{ |
|
303 |
boolean b = (x<mX && y<mY) && ( mTmp[mX-1-x][mY-1-y][z] && (z<1 || !mTmp[mX-1-x][mY-1-y][z-1]) ); |
|
304 |
mWall[x][y] = b ? WALL_MARKED : WALL_EMPTY; |
|
305 |
} |
|
383 |
for(int i=0; i<mMax; i++) |
|
384 |
for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY; |
|
385 |
|
|
386 |
for(int i=0; i<mNumElements; i++) |
|
387 |
{ |
|
388 |
int[] row = mElements[i].getRotRow(); |
|
389 |
int x = mX-1-row[0]; |
|
390 |
int y = mY-1-row[2]; |
|
391 |
if( row[4]==z ) mWall[x][y] = elementExists(x,y,z-1) ? WALL_EMPTY : WALL_MARKED; |
|
392 |
} |
|
306 | 393 |
|
307 | 394 |
createVertices(list,mWall,AXIS_ZM,z); |
308 | 395 |
} |
... | ... | |
798 | 885 |
|
799 | 886 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
800 | 887 |
|
801 |
public void prepare(int numVariants, int x, int y, int z)
|
|
888 |
public void prepare(int numVariants, int[] numLayers)
|
|
802 | 889 |
{ |
803 | 890 |
if( mVertexArray==null ) mVertexArray = new ArrayList<>(); |
804 | 891 |
mVertices= new float[numVariants][][]; |
... | ... | |
806 | 893 |
mMove = new float[numVariants][3]; |
807 | 894 |
mBandIndices = new int[numVariants][]; |
808 | 895 |
|
809 |
mX = x;
|
|
810 |
mY = y;
|
|
811 |
mZ = z;
|
|
896 |
mX = numLayers[0];
|
|
897 |
mY = numLayers[1];
|
|
898 |
mZ = numLayers[2];
|
|
812 | 899 |
|
813 | 900 |
dX = mX/2.0f; |
814 | 901 |
dY = mY/2.0f; |
... | ... | |
818 | 905 |
|
819 | 906 |
mWall = new int[mMax][mMax]; |
820 | 907 |
mPoints = new int[mMax+1][mMax+1]; |
821 |
mTmp = new boolean[mX][mY][mZ]; |
|
908 |
mCuts = getCuts(numLayers); |
|
909 |
|
|
910 |
createNormal(); |
|
822 | 911 |
} |
823 | 912 |
|
824 | 913 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
827 | 916 |
{ |
828 | 917 |
mVertexArray.clear(); |
829 | 918 |
|
830 |
float begX = 0.5f*(1-mX); |
|
831 |
float begY = 0.5f*(1-mY); |
|
832 |
float begZ = 0.5f*(1-mZ); |
|
833 |
|
|
834 |
for(int x=0; x<mX; x++) |
|
835 |
for(int y=0; y<mY; y++) |
|
836 |
for(int z=0; z<mZ; z++) mTmp[x][y][z] = cubitExists(pos,begX+x,begY+y,begZ+z); |
|
919 |
mNumElements = pos.length/3; |
|
920 |
mElements = new BandagedElementCuboid[mNumElements]; |
|
921 |
for(int i=0; i<mNumElements; i++) mElements[i] = new BandagedElementCuboid(pos, 3*i, mNormal, mCuts); |
|
837 | 922 |
|
838 | 923 |
for(int x=0; x<mX; x++) createRight (x,mVertexArray); |
839 | 924 |
for(int x=0; x<mX; x++) createLeft (x,mVertexArray); |
... | ... | |
888 | 973 |
int angle = 60; |
889 | 974 |
float R = 0.2f; |
890 | 975 |
float S = 0.5f; |
891 |
int numVerts= 5; |
|
976 |
int numVerts= (mX+mY+mZ)>= 16 ? 4:5;
|
|
892 | 977 |
int extraI = 0; |
893 | 978 |
int extraV = 0; |
894 | 979 |
|
... | ... | |
904 | 989 |
|
905 | 990 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
906 | 991 |
|
907 |
public MeshBase createMesh(float[] pos, int x, int y, int z, boolean iconMode, boolean roundCorners)
|
|
992 |
public MeshBase createMesh(float[] pos, int[] numLayers, boolean iconMode, boolean roundCorners)
|
|
908 | 993 |
{ |
909 |
prepare(1,x,y,z);
|
|
994 |
prepare(1,numLayers);
|
|
910 | 995 |
ObjectShape shape = createIrregularShape(0,pos); |
911 | 996 |
ObjectFaceShape face = createIrregularFaceShape(0,iconMode); |
912 | 997 |
ObjectVertexEffects effects = createVertexEffects(0,roundCorners); |
Also available in: Unified diff
generalize FactoryBandagedCuboid: start removing 'cuboidal' assumptions from it.