Revision c90aca24
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/library/mesh/MeshCubes.java | ||
---|---|---|
31 | 31 |
*/ |
32 | 32 |
public class MeshCubes extends MeshBase |
33 | 33 |
{ |
34 |
private static final float R = 0.0f;//0.2f;
|
|
34 |
private static final float R = 0.0f; |
|
35 | 35 |
|
36 | 36 |
private static final int FRONT = 0; |
37 | 37 |
private static final int BACK = 1; |
... | ... | |
165 | 165 |
int sideVert = 2*(mSlices-1) + mSlices*sideVertOneSlice; |
166 | 166 |
int firstWinding = (mSlices>0 && (frontVert+1)%2==1 ) ? 1:0; |
167 | 167 |
int dataL = mSlices==0 ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert); |
168 |
/* |
|
169 |
android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts+" winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert); |
|
170 |
android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+mSideWalls+" sSegments="+mEdgeNum+" sideBends="+mSideBends+" dataLen="+dataL ); |
|
171 |
*/ |
|
168 |
|
|
172 | 169 |
return dataL<0 ? 0:dataL; |
173 | 170 |
} |
174 | 171 |
|
175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
176 |
/* |
|
177 |
private static String debug(short[] val) |
|
178 |
{ |
|
179 |
String ret="";j |
|
180 |
|
|
181 |
for(int i=0; i<val.length; i++) ret+=(" "+val[i]); |
|
182 |
|
|
183 |
return ret; |
|
184 |
} |
|
185 |
*/ |
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
/* |
|
188 |
private static String debug(float[] val, int stop) |
|
189 |
{ |
|
190 |
String ret=""; |
|
191 |
float v; |
|
192 |
boolean neg; |
|
193 |
int mod; |
|
194 |
|
|
195 |
for(int i=0; i<val.length; i++) |
|
196 |
{ |
|
197 |
if( i%stop==0 ) ret+="\n"; |
|
198 |
|
|
199 |
mod = i%stop; |
|
200 |
|
|
201 |
if( mod==0 || mod==3 || mod==6 ) ret+=" ("; |
|
202 |
|
|
203 |
v = val[i]; |
|
204 |
if( v==-0.0f ) v=0.0f; |
|
205 |
|
|
206 |
|
|
207 |
neg = v<0; |
|
208 |
v = (v<0 ? -v:v); |
|
209 |
|
|
210 |
ret+=((neg? " -":" +")+v); |
|
211 |
|
|
212 |
if( mod==2 || mod==5 || mod==7 ) ret+=")"; |
|
213 |
} |
|
214 |
|
|
215 |
return ret; |
|
216 |
} |
|
217 |
*/ |
|
218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
219 |
/* |
|
220 |
private static String debug(Edge e) |
|
221 |
{ |
|
222 |
String d = ""; |
|
223 |
|
|
224 |
switch(e.side) |
|
225 |
{ |
|
226 |
case NORTH: d+="NORTH "; break; |
|
227 |
case SOUTH: d+="SOUTH "; break; |
|
228 |
case WEST : d+="WEST "; break; |
|
229 |
case EAST : d+="EAST "; break; |
|
230 |
} |
|
231 |
|
|
232 |
d+=("("+e.row+","+e.col+")"); |
|
233 |
|
|
234 |
return d; |
|
235 |
} |
|
236 |
*/ |
|
237 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
238 | 173 |
|
239 | 174 |
private void prepareDataStructures(int cols, String desc, int slices) |
... | ... | |
347 | 282 |
|
348 | 283 |
do |
349 | 284 |
{ |
350 |
//android.util.Log.d("CUBES", "checking edge "+debug(e1)); |
|
351 |
|
|
352 | 285 |
mSideWalls++; |
353 | 286 |
|
354 | 287 |
if( e1.side==NORTH || e1.side==SOUTH ) |
... | ... | |
362 | 295 |
mEdges.remove(j); |
363 | 296 |
mEdgeNum--; |
364 | 297 |
j--; |
365 |
|
|
366 |
//android.util.Log.e("CUBES", "removing edge "+debug(e2)); |
|
367 | 298 |
} |
368 | 299 |
} |
369 | 300 |
} |
... | ... | |
456 | 387 |
if( lr>0 ) lr= 1; |
457 | 388 |
mNormalX[3] = lr*R; |
458 | 389 |
mNormalY[3] = td*R; |
459 |
/* |
|
460 |
android.util.Log.d("CUBES", "row="+row+" col="+col); |
|
461 |
android.util.Log.d("CUBES", mNormalX[0]+" "+mNormalY[0]); |
|
462 |
android.util.Log.d("CUBES", mNormalX[1]+" "+mNormalY[1]); |
|
463 |
android.util.Log.d("CUBES", mNormalX[2]+" "+mNormalY[2]); |
|
464 |
android.util.Log.d("CUBES", mNormalX[3]+" "+mNormalY[3]); |
|
465 |
*/ |
|
466 | 390 |
} |
467 | 391 |
|
468 | 392 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
475 | 399 |
boolean currentBlockIsNE; |
476 | 400 |
float vectZ = (front ? 0.5f : -0.5f); |
477 | 401 |
|
478 |
//android.util.Log.d("CUBES", "buildFrontBack"); |
|
479 |
|
|
480 | 402 |
for(int row=0; row<mRows; row++) |
481 | 403 |
{ |
482 | 404 |
last =0; |
... | ... | |
491 | 413 |
|
492 | 414 |
if( !seenLand && !front && ((currVert%2==1)^currentBlockIsNE) ) |
493 | 415 |
{ |
494 |
//android.util.Log.d("CUBES","repeating winding2 vertex"); |
|
495 |
|
|
496 | 416 |
repeatLast(attribs); |
497 | 417 |
} |
498 | 418 |
|
... | ... | |
538 | 458 |
|
539 | 459 |
private void buildSideGrid(float[] attribs) |
540 | 460 |
{ |
541 |
//android.util.Log.d("CUBES", "buildSide"); |
|
542 |
|
|
543 | 461 |
for(int i=0; i<mEdgeNum; i++) |
544 | 462 |
{ |
545 | 463 |
buildIthSide(mEdges.get(i), attribs); |
... | ... | |
599 | 517 |
{ |
600 | 518 |
int col = curr.col; |
601 | 519 |
int row = curr.row; |
602 |
|
|
603 |
//android.util.Log.e("CUBES", "row="+row+" col="+col+" mRows="+mRows+" mCols="+mCols); |
|
604 |
|
|
520 |
|
|
605 | 521 |
switch(curr.side) |
606 | 522 |
{ |
607 | 523 |
case NORTH: if( col==mCols-1 ) |
... | ... | |
695 | 611 |
|
696 | 612 |
mInflateY[row][col] = (byte)diff; |
697 | 613 |
} |
698 |
|
|
699 |
//android.util.Log.e("mesh","col="+col+" row="+row+" inflateX="+mInflateX[col][row]+" InflateY="+mInflateY[col][row]); |
|
700 | 614 |
} |
701 | 615 |
|
702 | 616 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
736 | 650 |
|
737 | 651 |
private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs) |
738 | 652 |
{ |
739 |
//android.util.Log.e("CUBES", "adding Side vertex!"); |
|
740 | 653 |
float x, y, z; |
741 | 654 |
int row, col; |
742 | 655 |
|
... | ... | |
839 | 752 |
|
840 | 753 |
private void repeatLast(float[] attribs) |
841 | 754 |
{ |
842 |
//android.util.Log.e("CUBES", "repeating last vertex!"); |
|
843 |
|
|
844 | 755 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB ]; |
845 | 756 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+1]; |
846 | 757 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+2]; |
... | ... | |
916 | 827 |
*/ |
917 | 828 |
public MeshCubes(int cols, String desc, int slices) |
918 | 829 |
{ |
919 |
super( (float)slices/cols); |
|
920 |
|
|
921 | 830 |
Static4D map = new Static4D(0.0f,0.0f,1.0f,1.0f); |
922 | 831 |
fillTexMappings(map,map,map,map,map,map); |
923 | 832 |
prepareDataStructures(cols,desc,slices); |
... | ... | |
963 | 872 |
*/ |
964 | 873 |
public MeshCubes(int cols, String desc, int slices, Static4D front, Static4D back, Static4D left, Static4D right, Static4D top, Static4D bottom) |
965 | 874 |
{ |
966 |
super( (float)slices/cols); |
|
967 | 875 |
fillTexMappings(front,back,left,right,top,bottom); |
968 | 876 |
prepareDataStructures(cols,desc,slices); |
969 | 877 |
build(); |
... | ... | |
979 | 887 |
*/ |
980 | 888 |
public MeshCubes(int cols, int rows, int slices) |
981 | 889 |
{ |
982 |
super( (float)slices/cols); |
|
983 |
|
|
984 | 890 |
Static4D map = new Static4D(0.0f,0.0f,1.0f,1.0f); |
985 | 891 |
fillTexMappings(map,map,map,map,map,map); |
986 | 892 |
prepareDataStructures(cols,rows,slices); |
... | ... | |
1010 | 916 |
*/ |
1011 | 917 |
public MeshCubes(int cols, int rows, int slices, Static4D front, Static4D back, Static4D left, Static4D right, Static4D top, Static4D bottom) |
1012 | 918 |
{ |
1013 |
super( (float)slices/cols); |
|
1014 | 919 |
fillTexMappings(front,back,left,right,top,bottom); |
1015 | 920 |
prepareDataStructures(cols,rows,slices); |
1016 | 921 |
build(); |
Also available in: Unified diff
Move the 'pre-multiply mesh before applying any effects' thing from [(Xsize of texture, Ysize of texture) x Mesh's zFactor] to Effects.setStretch(sx,sy,sz)