Revision a51fe521
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/MeshCubes.java | ||
---|---|---|
185 | 185 |
|
186 | 186 |
private void prepareDataStructures(int cols, String desc, boolean frontOnly) |
187 | 187 |
{ |
188 |
mRows =0; |
|
189 |
mCols =0; |
|
190 |
dataLength=0;
|
|
188 |
mRows =0;
|
|
189 |
mCols =0;
|
|
190 |
numVertices=0;
|
|
191 | 191 |
|
192 | 192 |
if( cols>0 && desc.contains("1") ) |
193 | 193 |
{ |
... | ... | |
205 | 205 |
//android.util.Log.d("cubes", "VERT STRING:"+debug(mBoundingVert,3)); |
206 | 206 |
|
207 | 207 |
markRegions(); |
208 |
dataLength = computeDataLength(frontOnly);
|
|
208 |
numVertices = computeDataLength(frontOnly);
|
|
209 | 209 |
|
210 |
remainingVert = dataLength;
|
|
210 |
remainingVert = numVertices;
|
|
211 | 211 |
} |
212 | 212 |
} |
213 | 213 |
|
... | ... | |
216 | 216 |
|
217 | 217 |
private void prepareDataStructures(int cols, int rows, boolean frontOnly) |
218 | 218 |
{ |
219 |
mRows =rows; |
|
220 |
mCols =cols; |
|
221 |
dataLength= 0;
|
|
219 |
mRows =rows;
|
|
220 |
mCols =cols;
|
|
221 |
numVertices = 0;
|
|
222 | 222 |
|
223 | 223 |
if( cols>0 && rows>0 ) |
224 | 224 |
{ |
... | ... | |
233 | 233 |
//android.util.Log.d("cubes", "VERT FULL:"+debug(mBoundingVert,3)); |
234 | 234 |
|
235 | 235 |
markRegions(); |
236 |
dataLength = computeDataLength(frontOnly);
|
|
236 |
numVertices = computeDataLength(frontOnly);
|
|
237 | 237 |
|
238 |
remainingVert = dataLength;
|
|
238 |
remainingVert = numVertices;
|
|
239 | 239 |
} |
240 | 240 |
} |
241 | 241 |
|
... | ... | |
267 | 267 |
|
268 | 268 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
269 | 269 |
|
270 |
private float retLeftmost(int row) |
|
270 |
private float retLeftmost(int row)
|
|
271 | 271 |
{ |
272 | 272 |
if( row==0 ) |
273 | 273 |
{ |
... | ... | |
439 | 439 |
// inside). Each Edge needs to point from Land to Water (thus the '(SOUTH,i-1,j)' below) - otherwise |
440 | 440 |
// later on setting up normal vectors wouldn't work. |
441 | 441 |
|
442 |
private void markRegions()
|
|
442 |
private void markRegions() |
|
443 | 443 |
{ |
444 | 444 |
int i, j, numWater=1, numLand=0; |
445 | 445 |
|
... | ... | |
506 | 506 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
507 | 507 |
// when calling, make sure that newVal != val |
508 | 508 |
|
509 |
private void markRegion(short newVal, int row, int col)
|
|
509 |
private void markRegion(short newVal, int row, int col) |
|
510 | 510 |
{ |
511 | 511 |
int val = mCubes[row][col]; |
512 | 512 |
mCubes[row][col] = newVal; |
... | ... | |
519 | 519 |
|
520 | 520 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
521 | 521 |
|
522 |
private void createNormals(boolean front, int row, int col)
|
|
522 |
private void createNormals(boolean front, int row, int col) |
|
523 | 523 |
{ |
524 | 524 |
int td,lr; |
525 | 525 |
|
... | ... | |
591 | 591 |
android.util.Log.d("CUBES", mNormalX[3]+" "+mNormalY[3]); |
592 | 592 |
*/ |
593 | 593 |
} |
594 |
|
|
595 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
596 |
|
|
597 |
private int addFrontVertex(int vertex, int index, float vectZ, int col, int row, float[] position, float[] normal, float[] texture) |
|
598 |
{ |
|
599 |
remainingVert--; |
|
600 |
|
|
601 |
float x = (float)col/mCols; |
|
602 |
float y = (float)row/mRows; |
|
603 |
|
|
604 |
position[3*vertex ] = x-0.5f; |
|
605 |
position[3*vertex+1] = 0.5f-y; |
|
606 |
position[3*vertex+2] = vectZ; |
|
607 |
normal[3*vertex ] = mNormalX[index]; |
|
608 |
normal[3*vertex+1] = mNormalY[index]; |
|
609 |
normal[3*vertex+2] = mNormalZ[index]; |
|
610 |
texture[2*vertex ] = x; |
|
611 |
texture[2*vertex+1] = 1.0f-y; |
|
612 |
|
|
613 |
return vertex+1; |
|
614 |
} |
|
615 | 594 |
|
616 | 595 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
617 | 596 |
|
618 |
private int buildFrontBackGrid(boolean front, int vertex, float[] position, float[] normal, float[] texture)
|
|
597 |
private int buildFrontBackGrid(boolean front, int vertex, float[] attribs)
|
|
619 | 598 |
{ |
620 | 599 |
int last, current; |
621 | 600 |
boolean seenLand=false; |
... | ... | |
641 | 620 |
{ |
642 | 621 |
//android.util.Log.d("CUBES","repeating winding2 vertex"); |
643 | 622 |
|
644 |
vertex = repeatLast(vertex,position,normal,texture);
|
|
623 |
vertex = repeatLast(vertex,attribs);
|
|
645 | 624 |
} |
646 | 625 |
|
647 | 626 |
createNormals(front,row,col); |
... | ... | |
650 | 629 |
{ |
651 | 630 |
if( (last!=current) || !lastBlockIsNE ) |
652 | 631 |
{ |
653 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
|
|
654 |
vertex= addFrontVertex( vertex, 0, vectZ, col, row, position, normal, texture);
|
|
655 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
|
|
656 |
if( !lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,position,normal,texture);
|
|
657 |
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, position, normal, texture);
|
|
632 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
|
633 |
vertex= addFrontVertex( vertex, 0, vectZ, col, row, attribs);
|
|
634 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
|
635 |
if( !lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,attribs);
|
|
636 |
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, attribs);
|
|
658 | 637 |
} |
659 |
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row, position, normal, texture);
|
|
660 |
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, position, normal, texture);
|
|
638 |
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row, attribs);
|
|
639 |
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, attribs);
|
|
661 | 640 |
} |
662 | 641 |
else |
663 | 642 |
{ |
664 | 643 |
if( (last!=current) || lastBlockIsNE ) |
665 | 644 |
{ |
666 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
|
|
667 |
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, position, normal, texture);
|
|
668 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,position,normal,texture);
|
|
669 |
if( lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,position,normal,texture);
|
|
670 |
vertex= addFrontVertex( vertex, 0, vectZ, col, row, position, normal, texture);
|
|
645 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
|
646 |
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, attribs);
|
|
647 |
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
|
648 |
if( lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,attribs);
|
|
649 |
vertex= addFrontVertex( vertex, 0, vectZ, col, row, attribs);
|
|
671 | 650 |
} |
672 |
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, position, normal, texture);
|
|
673 |
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row , position, normal, texture);
|
|
651 |
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, attribs);
|
|
652 |
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row , attribs);
|
|
674 | 653 |
} |
675 | 654 |
|
676 | 655 |
seenLand = true; |
... | ... | |
686 | 665 |
|
687 | 666 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
688 | 667 |
|
689 |
private int repeatLast(int vertex, float[] position, float[] normal, float[] texture)
|
|
668 |
private int repeatLast(int vertex, float[] attribs)
|
|
690 | 669 |
{ |
691 | 670 |
//android.util.Log.e("CUBES", "repeating last vertex!"); |
692 | 671 |
|
... | ... | |
694 | 673 |
{ |
695 | 674 |
remainingVert--; |
696 | 675 |
|
697 |
position[3*vertex ] = position[3*vertex-3]; |
|
698 |
position[3*vertex+1] = position[3*vertex-2]; |
|
699 |
position[3*vertex+2] = position[3*vertex-1]; |
|
700 |
|
|
701 |
normal[3*vertex ] = normal[3*vertex-3]; |
|
702 |
normal[3*vertex+1] = normal[3*vertex-2]; |
|
703 |
normal[3*vertex+2] = normal[3*vertex-1]; |
|
704 |
|
|
705 |
texture[2*vertex ] = texture[2*vertex-2]; |
|
706 |
texture[2*vertex+1] = texture[2*vertex-1]; |
|
676 |
attribs[8*vertex ] = attribs[8*vertex-8]; |
|
677 |
attribs[8*vertex+1] = attribs[8*vertex-7]; |
|
678 |
attribs[8*vertex+2] = attribs[8*vertex-6]; |
|
679 |
attribs[8*vertex+3] = attribs[8*vertex-5]; |
|
680 |
attribs[8*vertex+4] = attribs[8*vertex-4]; |
|
681 |
attribs[8*vertex+5] = attribs[8*vertex-3]; |
|
682 |
attribs[8*vertex+6] = attribs[8*vertex-2]; |
|
683 |
attribs[8*vertex+7] = attribs[8*vertex-1]; |
|
707 | 684 |
|
708 | 685 |
vertex++; |
709 | 686 |
} |
... | ... | |
713 | 690 |
|
714 | 691 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
715 | 692 |
|
716 |
private int buildSideGrid(int vertex, float[] position, float[] normal, float[] texture)
|
|
693 |
private int buildSideGrid(int vertex, float[] attribs)
|
|
717 | 694 |
{ |
718 | 695 |
//android.util.Log.d("CUBES", "buildSide"); |
719 | 696 |
|
720 | 697 |
for(int i=0; i<mEdgeNum; i++) |
721 | 698 |
{ |
722 |
vertex = buildIthSide(mEdges.get(i), vertex, position, normal, texture);
|
|
699 |
vertex = buildIthSide(mEdges.get(i), vertex, attribs);
|
|
723 | 700 |
} |
724 | 701 |
|
725 | 702 |
return vertex; |
... | ... | |
727 | 704 |
|
728 | 705 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
729 | 706 |
|
730 |
private int buildIthSide(Edge curr, int vertex, float[] position, float[] normal, float[] texture)
|
|
707 |
private int buildIthSide(Edge curr, int vertex, float[] attribs)
|
|
731 | 708 |
{ |
732 | 709 |
Edge prev; |
733 | 710 |
|
... | ... | |
746 | 723 |
int side= curr.side; |
747 | 724 |
Edge next = getNextEdge(curr); |
748 | 725 |
|
749 |
addSideVertex(curr,BACK,LOWER,prev.side,vertex,position,normal,texture);
|
|
726 |
addSideVertex(curr,BACK,LOWER,prev.side,vertex,attribs);
|
|
750 | 727 |
vertex++; |
751 | 728 |
|
752 | 729 |
do |
753 | 730 |
{ |
754 | 731 |
if( prev.side!=curr.side ) |
755 | 732 |
{ |
756 |
addSideVertex(curr,BACK,LOWER,prev.side,vertex,position,normal,texture);
|
|
733 |
addSideVertex(curr,BACK,LOWER,prev.side,vertex,attribs);
|
|
757 | 734 |
vertex++; |
758 |
addSideVertex(curr,BACK,UPPER,prev.side,vertex,position,normal,texture);
|
|
735 |
addSideVertex(curr,BACK,UPPER,prev.side,vertex,attribs);
|
|
759 | 736 |
vertex++; |
760 | 737 |
} |
761 | 738 |
|
762 |
addSideVertex(curr,FRONT,LOWER,next.side,vertex,position,normal,texture);
|
|
739 |
addSideVertex(curr,FRONT,LOWER,next.side,vertex,attribs);
|
|
763 | 740 |
vertex++; |
764 |
addSideVertex(curr,FRONT,UPPER,next.side,vertex,position,normal,texture);
|
|
741 |
addSideVertex(curr,FRONT,UPPER,next.side,vertex,attribs);
|
|
765 | 742 |
vertex++; |
766 | 743 |
|
767 | 744 |
prev = curr; |
... | ... | |
770 | 747 |
} |
771 | 748 |
while( curr.col!=col || curr.row!=row || curr.side!=side ); |
772 | 749 |
|
773 |
vertex = repeatLast(vertex,position,normal,texture);
|
|
750 |
vertex = repeatLast(vertex,attribs);
|
|
774 | 751 |
|
775 | 752 |
return vertex; |
776 | 753 |
} |
777 | 754 |
|
778 | 755 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
779 | 756 |
|
780 |
private Edge getNextEdge(Edge curr)
|
|
757 |
private Edge getNextEdge(Edge curr) |
|
781 | 758 |
{ |
782 | 759 |
int col = curr.col; |
783 | 760 |
int row = curr.row; |
... | ... | |
824 | 801 |
} |
825 | 802 |
} |
826 | 803 |
|
804 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
805 |
|
|
806 |
private int addFrontVertex(int vertex, int index, float vectZ, int col, int row, float[] attribs) |
|
807 |
{ |
|
808 |
remainingVert--; |
|
809 |
|
|
810 |
float x = (float)col/mCols; |
|
811 |
float y = (float)row/mRows; |
|
812 |
|
|
813 |
attribs[8*vertex ] = x-0.5f; |
|
814 |
attribs[8*vertex+1] = 0.5f-y; |
|
815 |
attribs[8*vertex+2] = vectZ; |
|
816 |
attribs[8*vertex+3] = mNormalX[index]; |
|
817 |
attribs[8*vertex+4] = mNormalY[index]; |
|
818 |
attribs[8*vertex+5] = mNormalZ[index]; |
|
819 |
attribs[8*vertex+6] = x; |
|
820 |
attribs[8*vertex+7] = 1.0f-y; |
|
821 |
|
|
822 |
return vertex+1; |
|
823 |
} |
|
824 |
|
|
827 | 825 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
828 | 826 |
|
829 |
private void addSideVertex(Edge curr, boolean back, boolean lower,int side, int vertex, float[] position, float[] normal, float[] texture)
|
|
827 |
private void addSideVertex(Edge curr, boolean back, boolean lower,int side, int vertex, float[] attribs)
|
|
830 | 828 |
{ |
831 | 829 |
//android.util.Log.e("CUBES", "adding Side vertex!"); |
832 | 830 |
|
... | ... | |
838 | 836 |
{ |
839 | 837 |
case NORTH: x = (float)(back ? (curr.col ):(curr.col+1))/mCols; |
840 | 838 |
|
841 |
position[3*vertex ] = x - 0.5f; |
|
842 |
position[3*vertex+1] = 0.5f - (float)curr.row/mRows; |
|
843 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
|
844 |
|
|
845 |
normal[3*vertex ] = side==NORTH ? 0.0f : (side==WEST?-R:R); |
|
846 |
normal[3*vertex+1] = 1.0f; |
|
847 |
normal[3*vertex+2] = lower ? -R:R; |
|
848 |
|
|
849 |
texture[2*vertex ] = x; |
|
850 |
texture[2*vertex+1] = 1.0f-(float)(lower? (curr.row-1):(curr.row ))/mRows; |
|
839 |
attribs[8*vertex ] = x - 0.5f; |
|
840 |
attribs[8*vertex+1] = 0.5f - (float)curr.row/mRows; |
|
841 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ; |
|
842 |
attribs[8*vertex+3] = side==NORTH ? 0.0f : (side==WEST?-R:R); |
|
843 |
attribs[8*vertex+4] = 1.0f; |
|
844 |
attribs[8*vertex+5] = lower ? -R:R; |
|
845 |
attribs[8*vertex+6] = x; |
|
846 |
attribs[8*vertex+7] = 1.0f-(float)(lower? (curr.row-1):(curr.row ))/mRows; |
|
851 | 847 |
break; |
852 | 848 |
case SOUTH: x = (float)(back ? (curr.col+1):(curr.col ))/mCols; |
853 | 849 |
|
854 |
position[3*vertex ] = x - 0.5f; |
|
855 |
position[3*vertex+1] = 0.5f - (float)(curr.row+1)/mRows; |
|
856 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
|
857 |
|
|
858 |
normal[3*vertex ] = side==SOUTH ? 0.0f: (side==EAST?-R:R); |
|
859 |
normal[3*vertex+1] =-1.0f; |
|
860 |
normal[3*vertex+2] = lower ? -R:R; |
|
861 |
|
|
862 |
texture[2*vertex ] = x; |
|
863 |
texture[2*vertex+1] = 1.0f-(float)(lower? (curr.row+2):(curr.row+1))/mRows; |
|
850 |
attribs[8*vertex ] = x - 0.5f; |
|
851 |
attribs[8*vertex+1] = 0.5f - (float)(curr.row+1)/mRows; |
|
852 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ; |
|
853 |
attribs[8*vertex+3] = side==SOUTH ? 0.0f: (side==EAST?-R:R); |
|
854 |
attribs[8*vertex+4] =-1.0f; |
|
855 |
attribs[8*vertex+5] = lower ? -R:R; |
|
856 |
attribs[8*vertex+6] = x; |
|
857 |
attribs[8*vertex+7] = 1.0f-(float)(lower? (curr.row+2):(curr.row+1))/mRows; |
|
864 | 858 |
break; |
865 | 859 |
case WEST : y = (float)(back ? (curr.row+1):(curr.row))/mRows; |
866 | 860 |
|
867 |
position[3*vertex ] = (float)curr.col/mCols -0.5f; |
|
868 |
position[3*vertex+1] = 0.5f - y; |
|
869 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
|
870 |
|
|
871 |
normal[3*vertex ] =-1.0f; |
|
872 |
normal[3*vertex+1] = side==WEST ? 0.0f : (side==NORTH?-R:R); |
|
873 |
normal[3*vertex+2] = lower ? -R:R; |
|
874 |
|
|
875 |
texture[2*vertex ] = (float)(lower ? (curr.col-1):(curr.col ))/mCols; |
|
876 |
texture[2*vertex+1] = 1.0f - y; |
|
861 |
attribs[8*vertex ] = (float)curr.col/mCols -0.5f; |
|
862 |
attribs[8*vertex+1] = 0.5f - y; |
|
863 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ; |
|
864 |
attribs[8*vertex+3] =-1.0f; |
|
865 |
attribs[8*vertex+4] = side==WEST ? 0.0f : (side==NORTH?-R:R); |
|
866 |
attribs[8*vertex+5] = lower ? -R:R; |
|
867 |
attribs[8*vertex+6] = (float)(lower ? (curr.col-1):(curr.col ))/mCols; |
|
868 |
attribs[8*vertex+7] = 1.0f - y; |
|
877 | 869 |
break; |
878 | 870 |
case EAST : y = (float)(back ? (curr.row):(curr.row+1))/mRows; |
879 | 871 |
|
880 |
position[3*vertex ] = (float)(curr.col+1)/mCols -0.5f; |
|
881 |
position[3*vertex+1] = 0.5f - y; |
|
882 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
|
883 |
|
|
884 |
normal[3*vertex ] = 1.0f; |
|
885 |
normal[3*vertex+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R); |
|
886 |
normal[3*vertex+2] = lower ? -R:R; |
|
887 |
|
|
888 |
texture[2*vertex ] = (float)(lower ? (curr.col+2):(curr.col+1))/mCols; |
|
889 |
texture[2*vertex+1] = 1.0f - y; |
|
872 |
attribs[8*vertex ] = (float)(curr.col+1)/mCols -0.5f; |
|
873 |
attribs[8*vertex+1] = 0.5f - y; |
|
874 |
attribs[8*vertex+2] = lower ? BACKZ : FRONTZ; |
|
875 |
attribs[8*vertex+3] = 1.0f; |
|
876 |
attribs[8*vertex+4] = side==EAST ? 0.0f : (side==SOUTH?-R:R); |
|
877 |
attribs[8*vertex+5] = lower ? -R:R; |
|
878 |
attribs[8*vertex+6] = (float)(lower ? (curr.col+2):(curr.col+1))/mCols; |
|
879 |
attribs[8*vertex+7] = 1.0f - y; |
|
890 | 880 |
break; |
891 | 881 |
} |
892 | 882 |
|
893 |
if(texture[2*vertex ]>1.0f) texture[2*vertex ] =2.0f-texture[2*vertex ];
|
|
894 |
if(texture[2*vertex ]<0.0f) texture[2*vertex ] = -texture[2*vertex ];
|
|
895 |
if(texture[2*vertex+1]>1.0f) texture[2*vertex+1] =2.0f-texture[2*vertex+1];
|
|
896 |
if(texture[2*vertex+1]<0.0f) texture[2*vertex+1] = -texture[2*vertex+1];
|
|
883 |
if(attribs[8*vertex+6]>1.0f) attribs[8*vertex+6] = 2.0f-attribs[8*vertex+6];
|
|
884 |
if(attribs[8*vertex+6]<0.0f) attribs[8*vertex+6] = -attribs[8*vertex+6];
|
|
885 |
if(attribs[8*vertex+7]>1.0f) attribs[8*vertex+7] = 2.0f-attribs[8*vertex+7];
|
|
886 |
if(attribs[8*vertex+7]<0.0f) attribs[8*vertex+7] = -attribs[8*vertex+7];
|
|
897 | 887 |
} |
898 | 888 |
|
899 | 889 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
900 | 890 |
|
901 |
private void build(boolean frontOnly)
|
|
891 |
private void build(boolean frontOnly) |
|
902 | 892 |
{ |
903 |
int numVertices=0; |
|
904 |
float[] positionData= new float[POSITION_DATA_SIZE*dataLength]; |
|
905 |
float[] normalData = new float[NORMAL_DATA_SIZE *dataLength]; |
|
906 |
float[] textureData = new float[TEX_DATA_SIZE *dataLength]; |
|
893 |
int vertSoFar=0; |
|
894 |
float[] attribs= new float[(POSITION_DATA_SIZE+NORMAL_DATA_SIZE+TEX_DATA_SIZE)*numVertices]; |
|
907 | 895 |
|
908 |
//android.util.Log.d("CUBES","building front grid...");
|
|
896 |
//android.util.Log.d("MeshCubes","building front grid...");
|
|
909 | 897 |
|
910 |
numVertices = buildFrontBackGrid(true, numVertices,positionData,normalData,textureData);
|
|
898 |
vertSoFar = buildFrontBackGrid(true, vertSoFar,attribs);
|
|
911 | 899 |
|
912 | 900 |
if( !frontOnly ) |
913 | 901 |
{ |
914 |
numVertices = repeatLast(numVertices,positionData,normalData,textureData);
|
|
915 |
if( numVertices%2==1 )
|
|
902 |
vertSoFar = repeatLast(vertSoFar,attribs);
|
|
903 |
if( vertSoFar%2==1 )
|
|
916 | 904 |
{ |
917 |
//android.util.Log.d("CUBES","repeating winding1 vertex");
|
|
905 |
//android.util.Log.d("MeshCubes","repeating winding1 vertex");
|
|
918 | 906 |
|
919 |
numVertices = repeatLast(numVertices,positionData,normalData,textureData);
|
|
907 |
vertSoFar = repeatLast(vertSoFar,attribs);
|
|
920 | 908 |
} |
921 | 909 |
|
922 |
//android.util.Log.d("CUBES","building side grid...");
|
|
910 |
//android.util.Log.d("MeshCubes","building side grid...");
|
|
923 | 911 |
|
924 |
numVertices = buildSideGrid (numVertices,positionData,normalData,textureData);
|
|
912 |
vertSoFar = buildSideGrid (vertSoFar,attribs);
|
|
925 | 913 |
|
926 |
//android.util.Log.d("CUBES","building back grid...");
|
|
914 |
//android.util.Log.d("MeshCubes","building back grid...");
|
|
927 | 915 |
|
928 |
numVertices = buildFrontBackGrid (false,numVertices,positionData,normalData,textureData);
|
|
916 |
buildFrontBackGrid (false,vertSoFar,attribs);
|
|
929 | 917 |
} |
930 | 918 |
|
931 |
/* |
|
932 |
android.util.Log.e("CUBES","dataLen="+dataLength+" vertex="+numVertices); |
|
933 |
android.util.Log.d("CUBES", "position: "+debug(positionData,3) ); |
|
934 |
android.util.Log.d("CUBES", "normal: " +debug( normalData,3) ); |
|
935 |
android.util.Log.d("CUBES", "texture: " +debug( textureData,2) ); |
|
936 |
*/ |
|
919 |
//android.util.Log.e("MeshCubes", "dataLen="+numVertices); |
|
920 |
//android.util.Log.d("MeshCubes", "attribs: "+debug(attribs,8) ); |
|
937 | 921 |
|
938 | 922 |
mEdges.clear(); |
939 | 923 |
mEdges = null; |
940 | 924 |
mCubes = null; |
941 | 925 |
|
942 | 926 |
if( remainingVert!=0 ) |
943 |
android.util.Log.d("CUBES", "remainingVert " +remainingVert );
|
|
927 |
android.util.Log.e("MeshCubes", "remainingVert " +remainingVert );
|
|
944 | 928 |
|
945 |
mMeshPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
946 |
mMeshPositions.put(positionData).position(0); |
|
947 |
|
|
948 |
mMeshNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
949 |
mMeshNormals.put(normalData).position(0); |
|
950 |
|
|
951 |
mMeshTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
952 |
mMeshTexture.put(textureData).position(0); |
|
929 |
mVertAttribs = ByteBuffer.allocateDirect(numVertices*VERTSIZE).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
930 |
mVertAttribs.put(attribs).position(0); |
|
953 | 931 |
} |
954 | 932 |
|
955 | 933 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
956 | 934 |
|
957 |
float[] getBoundingVertices()
|
|
935 |
float[] getBoundingVertices() |
|
958 | 936 |
{ |
959 | 937 |
return mBoundingVert; |
960 | 938 |
} |
... | ... | |
986 | 964 |
* </p> |
987 | 965 |
* @param frontOnly Only create the front wall or side and back as well? |
988 | 966 |
*/ |
989 |
public MeshCubes(int cols, String desc, boolean frontOnly)
|
|
990 |
{
|
|
991 |
super(frontOnly ? 0.0f:1.0f/cols);
|
|
992 |
prepareDataStructures(cols,desc,frontOnly);
|
|
993 |
build(frontOnly);
|
|
994 |
}
|
|
967 |
public MeshCubes(int cols, String desc, boolean frontOnly) |
|
968 |
{ |
|
969 |
super(frontOnly ? 0.0f:1.0f/cols); |
|
970 |
prepareDataStructures(cols,desc,frontOnly); |
|
971 |
build(frontOnly); |
|
972 |
} |
|
995 | 973 |
|
996 | 974 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
997 | 975 |
/** |
... | ... | |
1001 | 979 |
* @param rows Number of rows. |
1002 | 980 |
* @param frontOnly Only create the front wall or side and back as well? |
1003 | 981 |
*/ |
1004 |
public MeshCubes(int cols, int rows, boolean frontOnly) |
|
1005 |
{ |
|
1006 |
super(frontOnly ? 0.0f:1.0f/cols); |
|
1007 |
prepareDataStructures(cols,rows,frontOnly); |
|
1008 |
build(frontOnly); |
|
1009 |
} |
|
982 |
public MeshCubes(int cols, int rows, boolean frontOnly) |
|
983 |
{ |
|
984 |
super(frontOnly ? 0.0f:1.0f/cols); |
|
985 |
prepareDataStructures(cols,rows,frontOnly); |
|
986 |
build(frontOnly); |
|
1010 | 987 |
} |
1011 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1012 |
|
|
988 |
} |
Also available in: Unified diff
Move from unpacked to packad server-side Vertex attribute buffer.