Revision 5f2853be
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/MeshCubes.java | ||
---|---|---|
109 | 109 |
} |
110 | 110 |
} |
111 | 111 |
|
112 |
int frontVert = 2*( frontWalls + 2*frontSegments - 1) +2*triangleShifts + windingShifts; |
|
113 |
int sideVert = 2*( mSideWalls + mSideBends + mEdgeNum -1); |
|
114 |
int firstWinding= (mSlices>0 && (frontVert+1)%2==1 ) ? 1:0; |
|
115 |
int dataL = mSlices==0 ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert); |
|
112 |
int frontVert = 2*( frontWalls + 2*frontSegments - 1) +2*triangleShifts + windingShifts; |
|
113 |
int sideVertOneSlice= 2*( mSideWalls + mSideBends + mEdgeNum -1); |
|
114 |
int sideVert = 2*(mSlices-1) + mSlices*sideVertOneSlice; |
|
115 |
int firstWinding = (mSlices>0 && (frontVert+1)%2==1 ) ? 1:0; |
|
116 |
int dataL = mSlices==0 ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert); |
|
116 | 117 |
/* |
117 | 118 |
android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts+" winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert); |
118 | 119 |
android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+mSideWalls+" sSegments="+mEdgeNum+" sideBends="+mSideBends+" dataLen="+dataL ); |
... | ... | |
185 | 186 |
for(int i=0; i<mRows; i++) |
186 | 187 |
mCubes[i][j] = (desc.charAt(i*mCols+j) == '1' ? 1:0); |
187 | 188 |
|
188 |
//android.util.Log.d("cubes", "VERT STRING:"+debug(mBoundingVert,3)); |
|
189 |
|
|
190 | 189 |
markRegions(); |
191 | 190 |
numVertices = computeDataLength(); |
192 | 191 |
|
... | ... | |
498 | 497 |
|
499 | 498 |
private int buildIthSide(Edge curr, int vertex, float[] attribs) |
500 | 499 |
{ |
501 |
Edge prev; |
|
502 |
|
|
500 |
Edge prev, next; |
|
501 |
int col, row, side; |
|
502 |
|
|
503 | 503 |
if( curr.side==NORTH ) // water outside |
504 | 504 |
{ |
505 | 505 |
prev = new Edge(WEST,curr.row,curr.col); |
... | ... | |
509 | 509 |
prev = curr; |
510 | 510 |
curr = new Edge(EAST,curr.row+1,curr.col-1); |
511 | 511 |
} |
512 |
|
|
513 |
int col = curr.col; |
|
514 |
int row = curr.row; |
|
515 |
int side= curr.side; |
|
516 |
Edge next = getNextEdge(curr); |
|
517 |
|
|
518 |
addSideVertex(curr,BACK,LOWER,prev.side,vertex,attribs); |
|
519 |
vertex++; |
|
520 |
|
|
521 |
do |
|
512 |
|
|
513 |
for(int i=0; i<mSlices; i++) |
|
522 | 514 |
{ |
523 |
if( prev.side!=curr.side ) |
|
515 |
col = curr.col; |
|
516 |
row = curr.row; |
|
517 |
side= curr.side; |
|
518 |
next = getNextEdge(curr); |
|
519 |
|
|
520 |
addSideVertex(curr,BACK,i+1,prev.side,vertex++,attribs); |
|
521 |
|
|
522 |
do |
|
524 | 523 |
{ |
525 |
addSideVertex(curr,BACK,LOWER,prev.side,vertex,attribs);
|
|
526 |
vertex++;
|
|
527 |
addSideVertex(curr,BACK,UPPER,prev.side,vertex,attribs);
|
|
528 |
vertex++;
|
|
529 |
} |
|
524 |
if( prev.side!=curr.side )
|
|
525 |
{
|
|
526 |
addSideVertex(curr,BACK,i+1,prev.side,vertex++,attribs);
|
|
527 |
addSideVertex(curr,BACK,i ,prev.side,vertex++,attribs);
|
|
528 |
}
|
|
530 | 529 |
|
531 |
addSideVertex(curr,FRONT,LOWER,next.side,vertex,attribs); |
|
532 |
vertex++; |
|
533 |
addSideVertex(curr,FRONT,UPPER,next.side,vertex,attribs); |
|
534 |
vertex++; |
|
530 |
addSideVertex(curr,FRONT,i+1,next.side,vertex++,attribs); |
|
531 |
addSideVertex(curr,FRONT,i ,next.side,vertex++,attribs); |
|
535 | 532 |
|
536 |
prev = curr; |
|
537 |
curr = next; |
|
538 |
next = getNextEdge(curr); |
|
539 |
} |
|
540 |
while( curr.col!=col || curr.row!=row || curr.side!=side ); |
|
541 |
|
|
542 |
vertex = repeatLast(vertex,attribs); |
|
533 |
prev = curr; |
|
534 |
curr = next; |
|
535 |
next = getNextEdge(curr); |
|
536 |
} |
|
537 |
while( curr.col!=col || curr.row!=row || curr.side!=side ); |
|
543 | 538 |
|
539 |
vertex = repeatLast(vertex,attribs); |
|
540 |
} |
|
541 |
|
|
544 | 542 |
return vertex; |
545 | 543 |
} |
546 | 544 |
|
... | ... | |
616 | 614 |
|
617 | 615 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
618 | 616 |
|
619 |
private void addSideVertex(Edge curr, boolean back, boolean lower,int side, int vertex, float[] attribs)
|
|
617 |
private void addSideVertex(Edge curr, boolean back, int slice,int side, int vertex, float[] attribs)
|
|
620 | 618 |
{ |
621 | 619 |
//android.util.Log.e("CUBES", "adding Side vertex!"); |
622 | 620 |
|
... | ... | |
630 | 628 |
|
631 | 629 |
attribs[8*vertex ] = x - 0.5f; |
632 | 630 |
attribs[8*vertex+1] = 0.5f - (float)curr.row/mRows; |
633 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ;
|
|
631 |
attribs[8*vertex+2] = FRONTZ + ((BACKZ-FRONTZ)*slice)/mSlices;
|
|
634 | 632 |
attribs[8*vertex+3] = side==NORTH ? 0.0f : (side==WEST?-R:R); |
635 | 633 |
attribs[8*vertex+4] = 1.0f; |
636 |
attribs[8*vertex+5] = lower ? -R:R;
|
|
634 |
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
637 | 635 |
attribs[8*vertex+6] = x; |
638 |
attribs[8*vertex+7] = 1.0f-(float)(lower? (curr.row-1):(curr.row ))/mRows;
|
|
636 |
attribs[8*vertex+7] = 1.0f-(float)(curr.row-slice)/mRows;
|
|
639 | 637 |
break; |
640 | 638 |
case SOUTH: x = (float)(back ? (curr.col+1):(curr.col ))/mCols; |
641 | 639 |
|
642 | 640 |
attribs[8*vertex ] = x - 0.5f; |
643 | 641 |
attribs[8*vertex+1] = 0.5f - (float)(curr.row+1)/mRows; |
644 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ;
|
|
642 |
attribs[8*vertex+2] = FRONTZ + ((BACKZ-FRONTZ)*slice)/mSlices;
|
|
645 | 643 |
attribs[8*vertex+3] = side==SOUTH ? 0.0f: (side==EAST?-R:R); |
646 | 644 |
attribs[8*vertex+4] =-1.0f; |
647 |
attribs[8*vertex+5] = lower ? -R:R;
|
|
645 |
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
648 | 646 |
attribs[8*vertex+6] = x; |
649 |
attribs[8*vertex+7] = 1.0f-(float)(lower? (curr.row+2):(curr.row+1))/mRows;
|
|
647 |
attribs[8*vertex+7] = 1.0f - (float)(curr.row+1+slice)/mRows;
|
|
650 | 648 |
break; |
651 | 649 |
case WEST : y = (float)(back ? (curr.row+1):(curr.row))/mRows; |
652 | 650 |
|
653 | 651 |
attribs[8*vertex ] = (float)curr.col/mCols -0.5f; |
654 | 652 |
attribs[8*vertex+1] = 0.5f - y; |
655 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ;
|
|
653 |
attribs[8*vertex+2] = FRONTZ + ((BACKZ-FRONTZ)*slice)/mSlices;
|
|
656 | 654 |
attribs[8*vertex+3] =-1.0f; |
657 | 655 |
attribs[8*vertex+4] = side==WEST ? 0.0f : (side==NORTH?-R:R); |
658 |
attribs[8*vertex+5] = lower ? -R:R;
|
|
659 |
attribs[8*vertex+6] = (float)(lower ? (curr.col-1):(curr.col ))/mCols;
|
|
656 |
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
657 |
attribs[8*vertex+6] = (float)(curr.col-slice)/mCols;
|
|
660 | 658 |
attribs[8*vertex+7] = 1.0f - y; |
661 | 659 |
break; |
662 | 660 |
case EAST : y = (float)(back ? (curr.row):(curr.row+1))/mRows; |
663 | 661 |
|
664 | 662 |
attribs[8*vertex ] = (float)(curr.col+1)/mCols -0.5f; |
665 | 663 |
attribs[8*vertex+1] = 0.5f - y; |
666 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ;
|
|
664 |
attribs[8*vertex+2] = FRONTZ + ((BACKZ-FRONTZ)*slice)/mSlices;
|
|
667 | 665 |
attribs[8*vertex+3] = 1.0f; |
668 | 666 |
attribs[8*vertex+4] = side==EAST ? 0.0f : (side==SOUTH?-R:R); |
669 |
attribs[8*vertex+5] = lower ? -R:R;
|
|
670 |
attribs[8*vertex+6] = (float)(lower ? (curr.col+2):(curr.col+1))/mCols;
|
|
667 |
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
668 |
attribs[8*vertex+6] = (float)(curr.col+1+slice)/mCols;
|
|
671 | 669 |
attribs[8*vertex+7] = 1.0f - y; |
672 | 670 |
break; |
673 | 671 |
} |
Also available in: Unified diff
Full support for any-depth MeshCubes.