Project

General

Profile

« Previous | Next » 

Revision 9d0df4c6

Added by Leszek Koltunski almost 6 years ago

Progress with the Inflate vector in MeshCubes.

Pretty much works now - what remains is calibration.

View differences:

src/main/java/org/distorted/library/mesh/MeshCubes.java
56 56
   
57 57
   private int mCols, mRows, mSlices;
58 58
   private int[][] mCubes;
59
   private byte[][] mInflateX, mInflateY;
59 60
   private ArrayList<Edge> mEdges = new ArrayList<>();
60 61

  
61 62
   private int currVert;
......
189 190
       mCols = cols;
190 191
       mRows = desc.length()/cols;
191 192

  
192
       mCubes = new int[mRows][mCols];
193
       
193
       mCubes    = new int[mRows][mCols];
194
       mInflateX = new byte[mRows+1][mCols+1];
195
       mInflateY = new byte[mRows+1][mCols+1];
196

  
194 197
       for(int j=0; j<mCols; j++)
195 198
         for(int i=0; i<mRows; i++)
196
           mCubes[i][j] = (desc.charAt(i*mCols+j) == '1' ? 1:0);
199
           mCubes[i][j] = (desc.charAt(i * mCols + j) == '1' ? 1 : 0);
200

  
201
       for(int j=0; j<mCols+1; j++)
202
         for(int i=0; i<mRows+1; i++)
203
           {
204
           fillInflate(j,i);
205
           }
197 206

  
198 207
       markRegions();
199 208
       numVertices = computeDataLength();
......
213 222

  
214 223
     if( cols>0 && rows>0 )
215 224
       {
216
       mCubes = new int[mRows][mCols];
225
       mCubes    = new int[mRows][mCols];
226
       mInflateX = new byte[mRows+1][mCols+1];
227
       mInflateY = new byte[mRows+1][mCols+1];
217 228

  
218 229
       for(int j=0; j<mCols; j++)
219 230
         for(int i=0; i<mRows; i++)
220 231
           mCubes[i][j] = 1;
221 232

  
233
       for(int j=0; j<mCols+1; j++)
234
         for(int i=0; i<mRows+1; i++)
235
           {
236
           fillInflate(j,i);
237
           }
238

  
222 239
       markRegions();
223 240
       numVertices = computeDataLength();
224 241
       currVert = 0;
......
488 505
       curr = new Edge(EAST,curr.row+1,curr.col-1);
489 506
       }
490 507

  
491
     for(int i=0; i<mSlices; i++)
508
     for(int slice=0; slice<mSlices; slice++)
492 509
       {
493 510
       col = curr.col;
494 511
       row = curr.row;
495 512
       side= curr.side;
496 513
       next = getNextEdge(curr);
497 514
     
498
       addSideVertex(curr,true,i+1,prev.side,attribs);
515
       addSideVertex(curr,true,slice+1,prev.side,attribs);
499 516

  
500 517
       do
501 518
         {
502 519
         if( prev.side!=curr.side )
503 520
           {
504
           addSideVertex(curr,true,i+1,prev.side,attribs);
505
           addSideVertex(curr,true,i  ,prev.side,attribs);
521
           addSideVertex(curr,true,slice+1,prev.side,attribs);
522
           addSideVertex(curr,true,slice  ,prev.side,attribs);
506 523
           }
507 524
       
508
         addSideVertex(curr,false,i+1,next.side,attribs);
509
         addSideVertex(curr,false,i  ,next.side,attribs);
525
         addSideVertex(curr,false,slice+1,next.side,attribs);
526
         addSideVertex(curr,false,slice  ,next.side,attribs);
510 527
       
511 528
         prev = curr;
512 529
         curr = next;
......
567 584
       }
568 585
     }
569 586

  
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588

  
589
  private void fillInflate(int col, int row)
590
    {
591
    int diff;
592

  
593
         if( col==0     ) mInflateX[col][row] = -1;
594
    else if( col==mCols ) mInflateX[col][row] = +1;
595
    else
596
      {
597
      if( row==0 )
598
        {
599
        diff = mCubes[0][col-1]-mCubes[0][col];
600
        }
601
      else if( row==mRows )
602
        {
603
        diff = mCubes[mRows-1][col-1]-mCubes[mRows-1][col];
604
        }
605
      else
606
        {
607
        diff = (mCubes[row  ][col-1]-mCubes[row  ][col]) +
608
               (mCubes[row-1][col-1]-mCubes[row-1][col]) ;
609

  
610
        if( diff==-2 ) diff=-1;
611
        if( diff== 2 ) diff= 1;
612
        }
613

  
614
      mInflateX[col][row] = (byte)diff;
615
      }
616

  
617
         if( row==0    ) mInflateY[col][row] = +1;
618
    else if(row==mRows ) mInflateY[col][row] = -1;
619
    else
620
      {
621
      if( col==0 )
622
        {
623
        diff = mCubes[row][0]-mCubes[row-1][0];
624
        }
625
      else if( col==mCols )
626
        {
627
        diff = mCubes[row][mCols-1]-mCubes[row-1][mCols-1];
628
        }
629
      else
630
        {
631
        diff = (mCubes[row  ][col-1]+mCubes[row  ][col]) -
632
               (mCubes[row-1][col-1]+mCubes[row-1][col]) ;
633

  
634
        if( diff==-2 ) diff=-1;
635
        if( diff== 2 ) diff= 1;
636
        }
637

  
638
      mInflateY[col][row] = (byte)diff;
639
      }
640

  
641
    //android.util.Log.e("mesh","col="+col+" row="+row+" inflateX="+mInflateX[col][row]+" InflateY="+mInflateY[col][row]);
642
    }
643

  
570 644
///////////////////////////////////////////////////////////////////////////////////////////////////
571 645

  
572 646
  private void addFrontVertex(int index, float vectZ, int col, int row, float[] attribs)
......
582 656
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
583 657
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
584 658

  
585
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = 0.0f;  // TODO
586
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f;  // TODO
659
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[col][row]/2.0f;
660
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[col][row]/2.0f;
587 661
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ;
588 662

  
589 663
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
......
597 671
  private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs)
598 672
     {
599 673
     //android.util.Log.e("CUBES", "adding Side vertex!");
600
     float x, y;
674
     float x, y, z;
675
     int row, col;
601 676

  
602 677
     switch(curr.side)
603 678
       {
604
       case NORTH: x = (float)(back ? (curr.col  ):(curr.col+1))/mCols;
679
       case NORTH: row = curr.row;
680
                   col = (back ? (curr.col  ):(curr.col+1));
681
                   x = (float)col/mCols;
682
                   y = 0.5f - (float)row/mRows;
683
                   z = 0.5f - (float)slice/mSlices;
605 684

  
606 685
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x - 0.5f;
607
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - (float)curr.row/mRows;
608
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
686
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
687
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
609 688

  
610 689
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = side==NORTH ? 0.0f : (side==WEST?-R:R);
611 690
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
612 691
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
613 692

  
614
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = 0.0f;  //
615
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f;  // TODO
616
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
693
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[col][row]/2.0f;
694
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[col][row]/2.0f;
695
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
617 696

  
618 697
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
619
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-(float)(curr.row-slice)/mRows;
698
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-(float)(row-slice)/mRows;
620 699
                   break;
621
       case SOUTH: x = (float)(back ? (curr.col+1):(curr.col  ))/mCols;
700
       case SOUTH: row = curr.row+1;
701
                   col = (back ? (curr.col+1):(curr.col));
702
                   x = (float)col/mCols;
703
                   y = 0.5f - (float)row/mRows;
704
                   z = 0.5f - (float)slice/mSlices;
622 705

  
623 706
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x - 0.5f;
624
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - (float)(curr.row+1)/mRows;
625
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
707
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
708
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
626 709

  
627 710
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
628 711
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
629 712
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
630 713

  
631
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = 0.0f;  //
632
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f;  // TODO
633
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
714
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[col][row]/2.0f;
715
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[col][row]/2.0f;
716
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
634 717

  
635 718
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
636
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - (float)(curr.row+1+slice)/mRows;
719
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - (float)(row+slice)/mRows;
637 720
                   break;
638
       case WEST : y = (float)(back  ? (curr.row+1):(curr.row))/mRows;
721
       case WEST : row = (back  ? (curr.row+1):(curr.row));
722
                   col = curr.col;
723
                   x = (float)col/mCols -0.5f;
724
                   y = (float)row/mRows;
725
                   z = 0.5f - (float)slice/mSlices;
639 726

  
640
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = (float)curr.col/mCols -0.5f;
727
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x;
641 728
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
642
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
729
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
643 730

  
644 731
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] =-1.0f;
645 732
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
646 733
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
647 734

  
648
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = 0.0f;  //
649
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f;  // TODO
650
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
735
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[col][row]/2.0f;
736
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[col][row]/2.0f;
737
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
651 738

  
652
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(curr.col-slice)/mCols;
739
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(col-slice)/mCols;
653 740
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
654 741
                   break;
655
       case EAST : y = (float)(back  ? (curr.row):(curr.row+1))/mRows;
742
       case EAST : row = (back  ? (curr.row):(curr.row+1));
743
                   col = (curr.col+1);
744
                   x = (float)col/mCols -0.5f;
745
                   y = (float)row/mRows;
746
                   z = 0.5f - (float)slice/mSlices;
656 747

  
657
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = (float)(curr.col+1)/mCols -0.5f;
748
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x;
658 749
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
659
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
750
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
660 751

  
661 752
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = 1.0f;
662 753
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
663 754
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
664 755

  
665
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = 0.0f;  //
666
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f;  // TODO
667
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
756
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[col][row]/2.0f;
757
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[col][row]/2.0f;
758
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
668 759

  
669
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(curr.col+1+slice)/mCols;
760
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(col+slice)/mCols;
670 761
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
671 762
                   break;
672 763
       }
......
725 816
     mEdges.clear();
726 817
     mEdges = null;
727 818
     mCubes = null;
819
     mInflateX = null;
820
     mInflateY = null;
728 821

  
729 822
     if( currVert!=numVertices )
730 823
       android.util.Log.e("MeshCubes", "currVert " +currVert+" numVertices="+numVertices );

Also available in: Unified diff