Project

General

Profile

« Previous | Next » 

Revision b76da174

Added by Leszek Koltunski 11 months ago

First try converting FactoryBandagedCuboid to MeshMultigon (still doesn't work)

View differences:

src/main/java/org/distorted/objectlib/helpers/FactoryBandagedCuboid.java
44 44
      };
45 45

  
46 46
  private static FactoryBandagedCuboid mThis;
47
  private ArrayList<float[]> mVertexArray;
47
  private BandagedElementCuboid[] mElements;
48
  private ArrayList<float[][]> mVertexArray;
48 49
  private ArrayList<float[]> mTmpArray;
50

  
49 51
  private float[][][] mVertices;
50
  private int[][][] mIndices;
52
  private int[][][][] mIndices;
51 53
  private int[][] mBandIndices;
52 54
  private float[][] mMove;
53

  
54 55
  private int mX, mY, mZ, mMax;
55 56
  private float dX, dY, dZ;
56 57
  private int[][] mWall;
57
  private int[][] mPoints;
58 58
  private float[][] mCuts;
59 59
  private float[][] mNormal;
60
  private BandagedElementCuboid[] mElements;
61 60
  private int mNumElements;
61
  private int[][] mFaceBelongsBitmap;
62 62

  
63 63
///////////////////////////////////////////////////////////////////////////////////////////////////
64 64

  
......
109 109

  
110 110
///////////////////////////////////////////////////////////////////////////////////////////////////
111 111

  
112
  private float[][] getVertices(ArrayList<float[]> list, float[] move, int variant)
112
  private void computeMove(float[] pos, int variant)
113 113
    {
114
    int numMoves = move.length/3;
115
    mMove[variant][0]=0.0f;
116
    mMove[variant][1]=0.0f;
117
    mMove[variant][2]=0.0f;
114
    int numMoves = pos.length/3;
115
    float[] m = mMove[variant];
116
    m[0]=0.0f;
117
    m[1]=0.0f;
118
    m[2]=0.0f;
118 119

  
119
    for(int m=0; m<numMoves; m++)
120
    for(int i=0; i<numMoves; i++)
120 121
      {
121
      mMove[variant][0] += move[3*m  ];
122
      mMove[variant][1] += move[3*m+1];
123
      mMove[variant][2] += move[3*m+2];
122
      m[0] += pos[3*i  ];
123
      m[1] += pos[3*i+1];
124
      m[2] += pos[3*i+2];
124 125
      }
125 126

  
126
    mMove[variant][0]/=numMoves;
127
    mMove[variant][1]/=numMoves;
128
    mMove[variant][2]/=numMoves;
127
    m[0]/=numMoves;
128
    m[1]/=numMoves;
129
    m[2]/=numMoves;
130
    }
131

  
132
///////////////////////////////////////////////////////////////////////////////////////////////////
129 133

  
134
  private float[][] getVertices(ArrayList<float[][]> list, int variant)
135
    {
130 136
    int total  = 0;
131 137
    int length = list.size();
132
    float[][] vertices = new float[length][];
138
    float[][][] vertices = new float[length][][];
133 139

  
134 140
    for( int i=0; i<length; i++ )
135 141
      {
136 142
      vertices[i] = list.get(i);
137
      total += vertices[i].length/3;
143
      int len = vertices[i].length;
144
      for(int j=0; j<len; j++) total += vertices[i][j].length/3;
138 145
      }
139 146

  
140 147
    float[][] verts = new float[total][3];
......
142 149

  
143 150
    for(int i=0; i<length; i++)
144 151
      {
145
      int len = vertices[i].length/3;
152
      int len = vertices[i].length;
146 153

  
147 154
      for(int j=0; j<len; j++)
148 155
        {
149
        verts[pointer][0] = vertices[i][3*j  ] - mMove[variant][0];
150
        verts[pointer][1] = vertices[i][3*j+1] - mMove[variant][1];
151
        verts[pointer][2] = vertices[i][3*j+2] - mMove[variant][2];
152
        pointer++;
156
        float[] v = vertices[i][j];
157
        int l = v.length/3;
158

  
159
        for(int k=0; k<l; k++)
160
          {
161
          verts[pointer][0] = v[3*k  ] - mMove[variant][0];
162
          verts[pointer][1] = v[3*k+1] - mMove[variant][1];
163
          verts[pointer][2] = v[3*k+2] - mMove[variant][2];
164
          pointer++;
165
          }
153 166
        }
154 167
      }
155 168

  
......
158 171

  
159 172
///////////////////////////////////////////////////////////////////////////////////////////////////
160 173

  
161
  private int[][] getIndices(ArrayList<float[]> list)
174
  private int[][][] getIndices(ArrayList<float[][]> list)
162 175
    {
163 176
    int indicesSoFar=0;
164 177
    int length = list.size();
165
    int[][] indices = new int[length][];
178
    int[][][] indices = new int[length][][];
166 179

  
167 180
    for( int i=0; i<length; i++ )
168 181
      {
169
      float[] f = list.get(i);
170
      int len = f.length/3;
171
      int[] ind = new int[len];
172
      for(int j=0; j<len; j++) ind[j] = (indicesSoFar++);
182
      float[][] face = list.get(i);
183
      int len = face.length;
184
      int[][] ind = new int[len][];
185

  
186
      for(int j=0; j<len; j++)
187
        {
188
        int l = face[j].length/3;
189
        ind[j] = new int[l];
190
        for(int k=0; k<l; k++) ind[j][k] = (indicesSoFar++);
191
        }
192

  
173 193
      indices[i] = ind;
174 194
      }
175 195

  
......
178 198

  
179 199
///////////////////////////////////////////////////////////////////////////////////////////////////
180 200

  
181
  private void markAllVertices(float[] vertex, float[][] vertices, int[][] indices, int pointer, int variant)
201
  private void markAllVertices(float[] vertex, float[][] vertices, int[][][] indices, int pointer, int variant)
182 202
    {
183
    int lenI = indices.length;
203
    int numFaces = indices.length;
184 204

  
185
    for(int index=0; index<lenI; index++)
205
    for(int face=0; face<numFaces; face++)
186 206
      {
187
      int len = indices[index].length;
207
      int len = indices[face].length;
188 208

  
189
      for(int i=0; i<len; i++)
209
      for(int comp=0; comp<len; comp++)
190 210
        {
191
        if( mIndices[variant][index][i] == -1 )
192
          {
193
          int ind = indices[index][i];
194
          float[] ver = vertices[ind];
211
        int l = indices[face][comp].length;
195 212

  
196
          if( vertex[0]==ver[0] && vertex[1]==ver[1] && vertex[2]==ver[2] )
213
        for(int v=0; v<l; v++)
214
          {
215
          if( mIndices[variant][face][comp][v]==-1 )
197 216
            {
198
            mIndices[variant][index][i] = pointer;
217
            int ind=indices[face][comp][v];
218
            float[] ver=vertices[ind];
219

  
220
            if(vertex[0]==ver[0] && vertex[1]==ver[1] && vertex[2]==ver[2])
221
              {
222
              mIndices[variant][face][comp][v]=pointer;
223
              }
199 224
            }
200 225
          }
201 226
        }
......
212 237
//   1.0f, -1.0f, +0.0f,
213 238
//   0.0f, -1.0f, -1.0f },
214 239

  
215
  private void compressVerticesAndIndices(int variant, float[][] vertices, int[][] indices)
240
  private void compressVerticesAndIndices(int variant, float[][] vertices, int[][][] indices)
216 241
    {
217 242
    if( mTmpArray==null ) mTmpArray = new ArrayList<>();
218 243

  
219
    int lenI = indices.length;
244
    int numFaces = indices.length;
220 245
    int pointer=0;
221 246

  
222
    mIndices[variant] = new int[lenI][];
247
    mIndices[variant] = new int[numFaces][][];
223 248

  
224
    for(int index=0; index<lenI; index++)
249
    for(int face=0; face<numFaces;face++)
225 250
      {
226
      int len = indices[index].length;
227
      mIndices[variant][index] = new int[len];
228
      for(int i=0; i<len; i++) mIndices[variant][index][i] = -1;
251
      int len = indices[face].length;
252
      mIndices[variant][face] = new int[len][];
253

  
254
      for(int comp=0; comp<len; comp++)
255
        {
256
        int l = indices[face][comp].length;
257
        for(int v=0; v<l; v++)
258
          {
259
          mIndices[variant][face][comp] = new int[l];
260
          mIndices[variant][face][comp][v] = -1;
261
          }
262
        }
229 263
      }
230 264

  
231
    for(int index=0; index<lenI; index++)
265
    for(int face=0; face<numFaces; face++)
232 266
      {
233
      int len = indices[index].length;
267
      int len = indices[face].length;
234 268

  
235
      for(int i=0; i<len; i++)
269
      for(int comp=0; comp<len; comp++)
236 270
        {
237
        if( mIndices[variant][index][i] == -1 )
271
        int l = indices[face][comp].length;
272

  
273
        for(int v=0; v<l; v++)
238 274
          {
239
          int ind = indices[index][i];
240
          float[] ver = vertices[ind];
241
          mTmpArray.add(ver);
242
          markAllVertices(ver,vertices,indices,pointer,variant);
243
          pointer++;
275
          if( mIndices[variant][face][comp][v]==-1 )
276
            {
277
            int ind=indices[face][comp][v];
278
            float[] ver=vertices[ind];
279
            mTmpArray.add(ver);
280
            markAllVertices(ver, vertices, indices, pointer, variant);
281
            pointer++;
282
            }
244 283
          }
245 284
        }
246 285
      }
......
269 308

  
270 309
///////////////////////////////////////////////////////////////////////////////////////////////////
271 310

  
272
  private void displayWall(String tmp)
273
    {
274
    StringBuilder sb = new StringBuilder();
275

  
276
    for(int i=0; i<mMax; i++)
277
      {
278
      for(int j=0; j<mMax; j++)
279
        {
280
        sb.append(mWall[i][j]);
281
        sb.append(' ');
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)
311
  private void createRight(int x, ArrayList<float[][]> list)
292 312
    {
293 313
    for(int i=0; i<mMax; i++)
294 314
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
......
306 326

  
307 327
///////////////////////////////////////////////////////////////////////////////////////////////////
308 328

  
309
  private void createLeft(int x, ArrayList<float[]> list)
329
  private void createLeft(int x, ArrayList<float[][]> list)
310 330
    {
311 331
    for(int i=0; i<mMax; i++)
312 332
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
......
324 344

  
325 345
///////////////////////////////////////////////////////////////////////////////////////////////////
326 346

  
327
  private void createTop(int y, ArrayList<float[]> list)
347
  private void createTop(int y, ArrayList<float[][]> list)
328 348
    {
329 349
    for(int i=0; i<mMax; i++)
330 350
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
......
342 362

  
343 363
///////////////////////////////////////////////////////////////////////////////////////////////////
344 364

  
345
  private void createBottom(int y, ArrayList<float[]> list)
365
  private void createBottom(int y, ArrayList<float[][]> list)
346 366
    {
347 367
    for(int i=0; i<mMax; i++)
348 368
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
......
360 380

  
361 381
///////////////////////////////////////////////////////////////////////////////////////////////////
362 382

  
363
  private void createFront(int z, ArrayList<float[]> list)
383
  private void createFront(int z, ArrayList<float[][]> list)
364 384
    {
365 385
    for(int i=0; i<mMax; i++)
366 386
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
......
378 398

  
379 399
///////////////////////////////////////////////////////////////////////////////////////////////////
380 400

  
381
  private void createBack(int z, ArrayList<float[]> list)
401
  private void createBack(int z, ArrayList<float[][]> list)
382 402
    {
383 403
    for(int i=0; i<mMax; i++)
384 404
      for(int j=0; j<mMax; j++) mWall[i][j] = WALL_EMPTY;
......
423 443
    return sections;
424 444
    }
425 445

  
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
// return true iff exactly three or exactly one of the four values (x1,x2,x3,x4) are equal to 'value'.
428

  
429
  private boolean threeOrOne(int x1, int x2, int x3, int x4, int value)
430
    {
431
    if( x1==value ) return x2==value ? (x3==value)^(x4==value) : (x3==value)^(x4!=value);
432
    else            return x2==value ? (x3==value)^(x4!=value) : (x3==value)^(x4==value);
433
    }
434

  
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

  
437
  private boolean isOddVertical(int x, int y)
438
    {
439
    int number = 0;
440

  
441
    for(int i=0; i<y; i++)
442
      if( mPoints[x][i]==0 ) number++;
443

  
444
    return (number%2)==0;
445
    }
446

  
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448

  
449
  private boolean isOddHorizontal(int x, int y)
450
    {
451
    int number = 0;
452

  
453
    for(int i=0; i<x; i++)
454
      if( mPoints[i][y]==0 ) number++;
455

  
456
    return (number%2)==0;
457
    }
458

  
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

  
461
  private int moveUp(int x, int y)
462
    {
463
    for(int i=y-1; i>=0; i--)
464
      if( mPoints[x][i]==0 ) return i;
465

  
466
    android.util.Log.e("D", "moveUp error!");
467
    return 0;
468
    }
469

  
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

  
472
  private int moveDown(int x, int y)
473
    {
474
    for(int i=y+1; i<=mMax; i++)
475
      if( mPoints[x][i]==0 ) return i;
476

  
477
    android.util.Log.e("D", "moveDown error!");
478
    return 0;
479
    }
480

  
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

  
483
  private int moveLeft(int x, int y)
484
    {
485
    for(int i=x-1; i>=0; i--)
486
      if( mPoints[i][y]==0 ) return i;
487

  
488
    android.util.Log.e("D", "moveLeft error!");
489
    return 0;
490
    }
491

  
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

  
494
  private int moveRight(int x, int y)
495
    {
496
    for(int i=x+1; i<=mMax; i++)
497
      if( mPoints[i][y]==0 ) return i;
498

  
499
    android.util.Log.e("D", "moveRight error!");
500
    return 0;
501
    }
502

  
503 446
///////////////////////////////////////////////////////////////////////////////////////////////////
504 447

  
505
  private float[] buildVertices(int[][] wall, int section, float dx, float dy)
448
  private float[][] buildVertices(int[][] wall, int section, float dx, float dy)
506 449
    {
507
    int numPoints = buildPoints(wall,section);
508
    int numSections = numPoints/2;
509
    float[] vertices = new float[3*numPoints];
510
    int x=0,y=0,pointer=0;
450
    int numMarked = howManyMarked(wall,section);
451
    float[][] vertices = new float[numMarked][];
452
    int curr=0;
511 453

  
512
    for(int i=0; i<=mMax; i++)
513
      for(int j=0; j<=mMax; j++)
514
        if( mPoints[i][j]==0 )
454
    for(int x=0; x<mMax; x++)
455
      for(int y=0; y<mMax; y++)
456
        if( wall[x][y]==section )
515 457
          {
516
          x = i;
517
          y = j;
518
          i = j = mMax+1;
519
          }
458
          vertices[curr] = new float[12];
520 459

  
521
    for(int s=0; s<numSections; s++)
522
      {
523
      vertices[6*pointer  ] = x-dx;
524
      vertices[6*pointer+1] = dy-y;
525
      vertices[6*pointer+2] = 0.0f;
460
          vertices[curr][ 0] = x-dx;
461
          vertices[curr][ 1] = dy-y;
462
          vertices[curr][ 2] = 0.0f;
526 463

  
527
      y = isOddVertical(x,y) ? moveDown(x,y) : moveUp(x,y);
464
          vertices[curr][ 3] = x-dx;
465
          vertices[curr][ 4] = dy-y-1;
466
          vertices[curr][ 5] = 0.0f;
528 467

  
529
      vertices[6*pointer+3] = x-dx;
530
      vertices[6*pointer+4] = dy-y;
531
      vertices[6*pointer+5] = 0.0f;
468
          vertices[curr][ 6] = x-dx+1;
469
          vertices[curr][ 7] = dy-y-1;
470
          vertices[curr][ 8] = 0.0f;
532 471

  
533
      x = isOddHorizontal(x,y) ? moveRight(x,y) : moveLeft(x,y);
472
          vertices[curr][ 9] = x-dx+1;
473
          vertices[curr][10] = dy-y;
474
          vertices[curr][11] = 0.0f;
534 475

  
535
      pointer++;
536
      }
476
          curr++;
477
          }
537 478

  
538 479
    return vertices;
539 480
    }
540 481

  
541 482
///////////////////////////////////////////////////////////////////////////////////////////////////
542 483

  
543
  private int buildPoints(int[][] wall, int section)
484
  private int howManyMarked(int[][] wall, int section)
544 485
    {
545
    int numPoints=0;
546
    boolean thereIsCorner;
486
    int numMarked=0;
547 487

  
548
    for(int x=0; x<=mMax; x++)
549
      for(int y=0; y<=mMax; y++)
550
        {
551
        if( y==0 )
552
          {
553
               if( x==   0 ) thereIsCorner = (wall[     0][0]==section);
554
          else if( x==mMax ) thereIsCorner = (wall[mMax-1][0]==section);
555
          else               thereIsCorner = (wall[x-1][0]==section)^(wall[x][0]==section);
556
          }
557
        else if( y==mMax )
558
          {
559
               if( x==   0 ) thereIsCorner = (wall[     0][mMax-1]==section);
560
          else if( x==mMax ) thereIsCorner = (wall[mMax-1][mMax-1]==section);
561
          else               thereIsCorner = (wall[x-1][mMax-1]==section)^(wall[x][mMax-1]==section);
562
          }
563
        else if( x==0 )
564
          {
565
          thereIsCorner = (wall[0][y-1]==section)^(wall[0][y]==section);
566
          }
567
        else if( x==mMax )
568
          {
569
          thereIsCorner = (wall[mMax-1][y-1]==section)^(wall[mMax-1][y]==section);
570
          }
571
        else
572
          {
573
          thereIsCorner = threeOrOne(wall[x-1][y-1],wall[x-1][y],wall[x][y-1],wall[x][y],section);
574
          }
575

  
576
        if( thereIsCorner )
577
          {
578
          mPoints[x][y] = 0;
579
          numPoints++;
580
          }
581
        else
582
          {
583
          mPoints[x][y] =-1;
584
          }
585
        }
488
    for(int x=0; x<mMax; x++)
489
      for(int y=0; y<mMax; y++)
490
        if( wall[x][y]==section ) numMarked++;
586 491

  
587
    return numPoints;
492
    return numMarked;
588 493
    }
589 494

  
590 495
///////////////////////////////////////////////////////////////////////////////////////////////////
591 496

  
592
  private void rotateAndMoveVertices(float[] vertices, int axis, int layer)
497
  private void rotateAndMoveVertices(float[][] vertices, int axis, int layer)
593 498
    {
594
    int i,len = vertices.length/3;
499
    int i,len = vertices.length;
595 500

  
596 501
    switch(axis)
597 502
      {
598 503
      case AXIS_XP: for(i=0; i<len; i++)
599 504
                      {
600
                      vertices[3*i+2] =-vertices[3*i  ];
601
                      vertices[3*i  ] = layer-(dX-1.0f);
505
                      int l = vertices[i].length/3;
506

  
507
                      for(int j=0; j<l; j++)
508
                        {
509
                        vertices[i][3*j+2] = -vertices[i][3*j];
510
                        vertices[i][3*j]   = layer-(dX-1.0f);
511
                        }
602 512
                      }
603 513
                    break;
604 514
      case AXIS_XM: for(i=0; i<len; i++)
605 515
                      {
606
                      vertices[3*i+2] = vertices[3*i  ];
607
                      vertices[3*i  ] = layer-dX;
516
                      int l = vertices[i].length/3;
517

  
518
                      for(int j=0; j<l; j++)
519
                        {
520
                        vertices[i][3*j+2] = vertices[i][3*j];
521
                        vertices[i][3*j]   = layer-dX;
522
                        }
608 523
                      }
609 524
                    break;
610 525
      case AXIS_YP: for(i=0; i<len; i++)
611 526
                      {
612
                      vertices[3*i+2] =-vertices[3*i+1];
613
                      vertices[3*i+1] = layer-(dY-1.0f);
527
                      int l = vertices[i].length/3;
528

  
529
                      for(int j=0; j<l; j++)
530
                        {
531
                        vertices[i][3*j+2] = -vertices[i][3*j+1];
532
                        vertices[i][3*j+1] = layer-(dY-1.0f);
533
                        }
614 534
                      }
615 535
                    break;
616 536
      case AXIS_YM: for(i=0; i<len; i++)
617 537
                      {
618
                      vertices[3*i+2] = vertices[3*i+1];
619
                      vertices[3*i+1] = layer-dY;
538
                      int l = vertices[i].length/3;
539

  
540
                      for(int j=0; j<l; j++)
541
                        {
542
                        vertices[i][3*j+2] = vertices[i][3*j+1];
543
                        vertices[i][3*j+1] = layer-dY;
544
                        }
620 545
                      }
621 546
                    break;
622 547
      case AXIS_ZP: for(i=0; i<len; i++)
623 548
                      {
624
                      vertices[3*i+2] = layer-(dZ-1.0f);
549
                      int l = vertices[i].length/3;
550

  
551
                      for(int j=0; j<l; j++)
552
                        {
553
                        vertices[i][3*j+2] = layer-(dZ-1.0f);
554
                        }
625 555
                      }
626 556
                    break;
627 557
      case AXIS_ZM: for(i=0; i<len; i++)
628 558
                      {
629
                      vertices[3*i+2] = layer-dZ;
630
                      vertices[3*i  ] =-vertices[3*i  ];
559
                      int l = vertices[i].length/3;
560

  
561
                      for(int j=0; j<l; j++)
562
                        {
563
                        vertices[i][3*j+2] = layer-dZ;
564
                        vertices[i][3*j]   = -vertices[i][3*j];
565
                        }
631 566
                      }
632 567
                    break;
633 568
      }
......
641 576
//   c. take layer into consideration and move the vertices.
642 577
//   d. add the resulting vertices to the list.
643 578

  
644
  private void createVertices(ArrayList<float[]> list, int[][] wall, int axis, int layer)
579
  private void createVertices(ArrayList<float[][]> list, int[][] wall, int axis, int layer)
645 580
    {
646 581
    int sections = markSections(wall);
647 582

  
......
650 585

  
651 586
    for(int i=0; i<sections; i++)
652 587
      {
653
      float[] vertices = buildVertices(wall,i+1,dx,dy);
588
      float[][] vertices = buildVertices(wall,i+1,dx,dy);
589
/*
590
if(axis==AXIS_XP || axis==AXIS_XM)
591
  {
592
  StringBuilder s = new StringBuilder();
593
  int n = vertices.length;
594
  s.append("createVertices: numComp: ");
595
  s.append(n);
596

  
597
  for(float[] floats : vertices)
598
    {
599
    int l=floats.length/3;
654 600

  
601
    for(int k=0; k<l; k++)
602
      {
603
      s.append(" (");
604
      s.append(floats[3*k  ]);
605
      s.append(" ");
606
      s.append(floats[3*k+1]);
607
      s.append(" ");
608
      s.append(floats[3*k+2]);
609
      s.append(") ");
610
      }
611
    s.append("\n");
612
    }
613

  
614
  android.util.Log.e("D", "1 --> "+s);
615
  }
616
*/
655 617
      rotateAndMoveVertices(vertices,axis,layer);
656
      list.add(vertices);
657 618
/*
658
      int len = vertices.length/3;
659
      String w="";
660

  
661
      for(int j=0; j<len; j++)
619
      if(axis==AXIS_XP || axis==AXIS_XM)
662 620
        {
663
        w += ( "["+vertices[3*j]+" "+vertices[3*j+1]+" "+vertices[3*j+2]+"] ");
621
        StringBuilder s = new StringBuilder();
622
        int n = vertices.length;
623
        s.append("createVertices: numComp: ");
624
        s.append(n);
625

  
626
        for(float[] floats : vertices)
627
          {
628
          int l=floats.length/3;
629

  
630
          for(int k=0; k<l; k++)
631
            {
632
            s.append(" (");
633
            s.append(floats[3*k  ]);
634
            s.append(" ");
635
            s.append(floats[3*k+1]);
636
            s.append(" ");
637
            s.append(floats[3*k+2]);
638
            s.append(") ");
639
            }
640
          s.append("\n");
641
          }
642

  
643
        android.util.Log.e("D", "2 --> "+s);
664 644
        }
665
      android.util.Log.e("D", "1 section: "+i+" axis: "+axis+" layer: "+layer+" vertices after: "+w);
666 645
*/
646
      list.add(vertices);
667 647
      }
668 648
    }
669 649

  
......
687 667
// (vertices,indices) define a cubit face, i.e. a connected subset of the NxN grid.
688 668
// Return its 'diameter', i.e. max(width,height)
689 669

  
690
  private int faceDiameter(float[][] vertices, int[] indices)
670
  private int faceDiameter(float[][] vertices, int[][] indices)
691 671
    {
692 672
    float maxX = -dX;
693 673
    float minX =  dX;
......
696 676
    float maxZ = -dZ;
697 677
    float minZ =  dZ;
698 678

  
699
    for (int index : indices)
700
      {
701
      float[] v = vertices[index];
702

  
703
      if (v[0] > maxX) maxX = v[0];
704
      if (v[0] < minX) minX = v[0];
705
      if (v[1] > maxY) maxY = v[1];
706
      if (v[1] < minY) minY = v[1];
707
      if (v[2] > maxZ) maxZ = v[2];
708
      if (v[2] < minZ) minZ = v[2];
709
      }
679
    for (int[] ind : indices)
680
      for(int index : ind)
681
        {
682
        float[] v = vertices[index];
683

  
684
        if (v[0] > maxX) maxX = v[0];
685
        if (v[0] < minX) minX = v[0];
686
        if (v[1] > maxY) maxY = v[1];
687
        if (v[1] < minY) minY = v[1];
688
        if (v[2] > maxZ) maxZ = v[2];
689
        if (v[2] < minZ) minZ = v[2];
690
        }
710 691

  
711 692
    float diffX = maxX-minX;
712 693
    float diffY = maxY-minY;
......
717 698
    return (int)max;
718 699
    }
719 700

  
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

  
703
  private int[] computeFaceBelongsBitmap(float[][] vertices, int[][][] indices, float[] move)
704
    {
705
    int numVerts = vertices.length;
706
    int[] ret = new int[numVerts];
707

  
708
    for(int[][] ints : indices)
709
      for(int[] ind : ints)
710
        for(int index : ind)
711
          {
712
          int vertBelongsBitmap=0x00000000;
713
          float[] vert=vertices[index];
714

  
715
          if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[0], dX) ) vertBelongsBitmap |= (1   );
716
          if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[1], dX) ) vertBelongsBitmap |= (1<<1);
717
          if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[2], dY) ) vertBelongsBitmap |= (1<<2);
718
          if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[3], dY) ) vertBelongsBitmap |= (1<<3);
719
          if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[4], dZ) ) vertBelongsBitmap |= (1<<4);
720
          if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[5], dZ) ) vertBelongsBitmap |= (1<<5);
721

  
722
          ret[index]=vertBelongsBitmap;
723
          }
724

  
725
    return ret;
726
    }
727

  
720 728
///////////////////////////////////////////////////////////////////////////////////////////////////
721 729
// return array of:
722 730
// 0 if this is an inner face, 1 if its diameter is 1, 2 if diameter is 2, 3 if 3, etc
723 731
// but only up to 5 (because the number of bands is 6 - see createIrregularFaceShape() )
724 732

  
725
  private int[] generateBandIndices(float[][] vertices, int[][] indices, float[] move)
733
  private int[] generateBandIndices(float[][] vertices, int[][][] indices, int[] belongs)
726 734
    {
727 735
    int numCubitFaces = indices.length;
728 736
    int[] bandIndices = new int[numCubitFaces];
729 737

  
730
    for(int cubitFace=0; cubitFace<numCubitFaces; cubitFace++)
738
    for(int f=0; f<numCubitFaces; f++)
731 739
      {
732
      bandIndices[cubitFace] = 0xffffffff;
733
      int numVertices = indices[cubitFace].length;
740
      bandIndices[f] = 0xffffffff;
741
      for( int index : indices[f][0] ) bandIndices[f] &= belongs[index];
734 742

  
735
      for(int vertex=0; vertex<numVertices; vertex++)
743
      if( bandIndices[f]!=0 ) // outer face
736 744
        {
737
        int vertBelongsBitmap = 0x00000000;
738
        float[] vert = vertices[ indices[cubitFace][vertex] ];
739

  
740
        if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[0], dX) ) vertBelongsBitmap |= (1   );
741
        if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[1], dX) ) vertBelongsBitmap |= (1<<1);
742
        if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[2], dY) ) vertBelongsBitmap |= (1<<2);
743
        if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[3], dY) ) vertBelongsBitmap |= (1<<3);
744
        if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[4], dZ) ) vertBelongsBitmap |= (1<<4);
745
        if( vertInFace(vert, move, TouchControlHexahedron.FACE_AXIS[5], dZ) ) vertBelongsBitmap |= (1<<5);
746

  
747
        bandIndices[cubitFace] &= vertBelongsBitmap;
745
        int diameter = faceDiameter(vertices, indices[f]);
746
        bandIndices[f] = (diameter>=6 ? 5:diameter);
748 747
        }
749

  
750
      if( bandIndices[cubitFace]!=0 ) // outer face
751
        {
752
        int diameter = faceDiameter(vertices, indices[cubitFace]);
753
        bandIndices[cubitFace] = (diameter>=6 ? 5:diameter);
754
        }
755

  
756
      //android.util.Log.e("D", "cubit face "+cubitFace+" : "+bandIndices[cubitFace]);
757 748
      }
758 749

  
759 750
    return bandIndices;
......
791 782

  
792 783
///////////////////////////////////////////////////////////////////////////////////////////////////
793 784

  
794
  private float[] computeVector(int index, float[][] vertices, int[][] indices, int[] bandIndices)
785
  private float[] computeVector(int index, float[][] vertices, int[][][] indices, int[] bandIndices)
795 786
    {
796 787
    int band=0;
797
    int len = indices.length;
788
    int numFaces = indices.length;
798 789
    int vector=-1;
799 790

  
800
    for(int i=0; i<len; i++)
791
    for(int f=0; f<numFaces; f++)
801 792
      {
802
      int len2 = indices[i].length;
793
      int numComponentsInFace = indices[f].length;
803 794

  
804
      for(int j=0; j<len2; j++)
795
      for(int c=0; c<numComponentsInFace; c++)
805 796
        {
806
        if( indices[i][j]==index )
797
        int[] ind = indices[f][c];
798
        int numVertsInComponent = ind.length;
799

  
800
        for(int v=0; v<numVertsInComponent; v++)
807 801
          {
808
          int prev = j>0 ? j-1 : len2-1;
809
          int next = j<len2-1 ? j+1 : 0;
802
          if(ind[v]==index)
803
            {
804
            int prev=v>0 ? v-1 : numComponentsInFace-1;
805
            int next=v<numComponentsInFace-1 ? v+1 : 0;
810 806

  
811
          int prevIndex = indices[i][prev];
812
          int currIndex = indices[i][j];
813
          int nextIndex = indices[i][next];
807
            int prevIndex=ind[prev];
808
            int currIndex=ind[v];
809
            int nextIndex=ind[next];
814 810

  
815
          int newVector = computeVectorFace(vertices[prevIndex],vertices[currIndex],vertices[nextIndex]);
816
          if( vector!=-1 && vector!=newVector ) return null;
811
            int newVector=computeVectorFace(vertices[prevIndex], vertices[currIndex], vertices[nextIndex]);
812
            if(vector!=-1 && vector!=newVector) return null;
817 813

  
818
          vector = newVector;
819
          band |= bandIndices[i];
814
            vector=newVector;
815
            band|=bandIndices[f];
816
            v = numVertsInComponent;
817
            }
820 818
          }
821 819
        }
822 820
      }
......
826 824

  
827 825
///////////////////////////////////////////////////////////////////////////////////////////////////
828 826

  
829
  private float[][] generateVectors(float[][] vertices, int[][] indices, int[] bandIndices)
827
  private float[][] generateVectors(float[][] vertices, int[][][] indices, int[] bandIndices)
830 828
    {
831 829
    int len = vertices.length;
832 830
    float[][] vectors = new float[len][];
......
839 837
    return vectors;
840 838
    }
841 839

  
840
///////////////////////////////////////////////////////////////////////////////////////////////////
841

  
842
  private void displayWall(String tmp)
843
    {
844
    StringBuilder sb = new StringBuilder();
845

  
846
    for(int i=0; i<mMax; i++)
847
      {
848
      for(int j=0; j<mMax; j++)
849
        {
850
        sb.append(mWall[i][j]);
851
        sb.append(' ');
852
        }
853
      sb.append("  -  ");
854
      }
855

  
856
    android.util.Log.e("D", tmp+" : "+sb);
857
    }
858

  
842 859
///////////////////////////////////////////////////////////////////////////////////////////////////
843 860

  
844 861
  private void debug(float[][] vert, int[][] ind)
......
864 881
    for (int[] ints : ind)
865 882
      {
866 883
      ii += "\n";
867
      int lenI2 = ints.length;
868

  
869
      for (int i2 = 0; i2 < lenI2; i2++)
870
        {
871
        ii += (ints[i2] + " ");
872
        }
884
      for(int anInt : ints) ii+=(anInt+" ");
873 885
      }
874 886
    android.util.Log.e("D", ii);
875 887
    }
......
889 901
    {
890 902
    if( mVertexArray==null ) mVertexArray = new ArrayList<>();
891 903
    mVertices= new float[numVariants][][];
892
    mIndices = new int[numVariants][][];
904
    mIndices = new int[numVariants][][][];
893 905
    mMove = new float[numVariants][3];
894 906
    mBandIndices = new int[numVariants][];
907
    mFaceBelongsBitmap= new int[numVariants][];
895 908

  
896 909
    mX = numLayers[0];
897 910
    mY = numLayers[1];
......
903 916

  
904 917
    mMax = mX>mY ? Math.max(mX,mZ) : Math.max(mY,mZ);
905 918

  
906
    mWall   = new int[mMax][mMax];
907
    mPoints = new int[mMax+1][mMax+1];
908
    mCuts   = getCuts(numLayers);
919
    mWall = new int[mMax][mMax];
920
    mCuts = getCuts(numLayers);
909 921

  
910 922
    createNormal();
911 923
    }
912 924

  
925
///////////////////////////////////////////////////////////////////////////////////////////////////
926

  
927
  private int debugArray(int start, String str)
928
    {
929
    StringBuilder s = new StringBuilder();
930
    int n = mVertexArray.size();
931
    for(int i=start; i<n; i++)
932
      {
933
      float[][] v = mVertexArray.get(i);
934
      int numC = v.length;
935
      s.append("numComp: ");
936
      s.append(numC);
937

  
938
      for(float[] floats : v)
939
        {
940
        int l=floats.length/3;
941

  
942
        for(int k=0; k<l; k++)
943
          {
944
          s.append(" (");
945
          s.append(floats[3*k  ]);
946
          s.append(" ");
947
          s.append(floats[3*k+1]);
948
          s.append(" ");
949
          s.append(floats[3*k+2]);
950
          s.append(") ");
951
          }
952
        }
953
      }
954

  
955
    android.util.Log.e("D", str+" : "+s);
956

  
957
    return n;
958
    }
959

  
913 960
///////////////////////////////////////////////////////////////////////////////////////////////////
914 961

  
915 962
  public ObjectShape createIrregularShape(int variant, float[] pos)
......
921 968
    for(int i=0; i<mNumElements; i++) mElements[i] = new BandagedElementCuboid(pos, 3*i, mNormal, mCuts);
922 969

  
923 970
    for(int x=0; x<mX; x++) createRight (x,mVertexArray);
971
  //  int n = debugArray(0,"RIGHT");
924 972
    for(int x=0; x<mX; x++) createLeft  (x,mVertexArray);
973
  //  n = debugArray(n,"LEFT");
925 974
    for(int y=0; y<mY; y++) createTop   (y,mVertexArray);
975
  //  n = debugArray(n,"TOP");
926 976
    for(int y=0; y<mY; y++) createBottom(y,mVertexArray);
977
  //  n = debugArray(n,"BOTTOM");
927 978
    for(int z=0; z<mZ; z++) createFront (z,mVertexArray);
979
  //  n = debugArray(n,"FRONT");
928 980
    for(int z=0; z<mZ; z++) createBack  (z,mVertexArray);
981
 //   n = debugArray(n,"BACK");
982

  
983
    computeMove(pos,variant);
984
    float[][] verts = getVertices(mVertexArray,variant);
985
    int[][][] inds  = getIndices(mVertexArray);
929 986

  
930
    float[][] verts = getVertices(mVertexArray,pos,variant);
931
    int[][] inds    = getIndices(mVertexArray);
987
    StringBuilder str = new StringBuilder();
988

  
989
    for(float[] v : verts)
990
      {
991
      str.append(" (");
992
      str.append(v[0]);
993
      str.append(" ");
994
      str.append(v[1]);
995
      str.append(" ");
996
      str.append(v[2]);
997
      str.append(")");
998
      }
999
    android.util.Log.e("D", "createIrregularShape: "+str);
932 1000

  
933 1001
    compressVerticesAndIndices(variant,verts,inds);
934
    mBandIndices[variant] = generateBandIndices(mVertices[variant], mIndices[variant], mMove[variant]);
1002

  
1003
    mFaceBelongsBitmap[variant] = computeFaceBelongsBitmap(mVertices[variant], mIndices[variant], mMove[variant]);
1004
    mBandIndices[variant] = generateBandIndices(mVertices[variant], mIndices[variant], mFaceBelongsBitmap[variant]);
935 1005

  
936 1006
    return new ObjectShape(mVertices[variant], mIndices[variant]);
937 1007
    }
......
978 1048
    int extraV  = 0;
979 1049

  
980 1050
    float[][] bands  = { {  0.001f,angle,R,S,numVerts,extraV,extraI},
981
                         {height/1,angle,R,S,numVerts,extraV,extraI},
1051
                         {height  ,angle,R,S,numVerts,extraV,extraI},
982 1052
                         {height/2,angle,R,S,numVerts,extraV,extraI},
983 1053
                         {height/3,angle,R,S,numVerts,extraV,extraI},
984 1054
                         {height/4,angle,R,S,numVerts,extraV,extraI},
......
993 1063
    {
994 1064
    prepare(1,numLayers);
995 1065
    ObjectShape shape           = createIrregularShape(0,pos);
1066
    /*
1067
    int numP = pos.length;
1068
    StringBuilder str = new StringBuilder();
1069
    str.append("numPos: ");
1070
    str.append(numP);
1071
    str.append("  ");
1072

  
1073
    for(float po : pos)
1074
      {
1075
      str.append(po);
1076
      str.append(" ");
1077
      }
1078

  
1079
    android.util.Log.e("D", "POS: "+str);
1080
    */
1081
    shape.debug();
1082

  
1083
    throw new RuntimeException("EX");
1084
    /*
996 1085
    ObjectFaceShape face        = createIrregularFaceShape(0,iconMode);
997 1086
    ObjectVertexEffects effects = createVertexEffects(0,roundCorners);
998 1087
    int numFaces                = shape.getNumFaces();
......
1001 1090
    factory.clear();
1002 1091
    factory.createNewFaceTransform(shape,null);
1003 1092
    return factory.createRoundedSolid(shape,face,effects,MESH_NICE,numFaces);
1093

  
1094
     */
1004 1095
    }
1005 1096
  }
src/main/java/org/distorted/objectlib/helpers/ObjectShape.java
50 50
    mNumFaces       = vertIndices.length;
51 51
    }
52 52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
  public void debug()
56
    {
57
    StringBuilder str = new StringBuilder();
58
    str.append("isMultigon: ");
59
    str.append(mFacesMultigon);
60
    str.append("\n");
61
    str.append("numVertices: ");
62
    int numV =mVertices.length;
63
    str.append(numV);
64

  
65
    for(float[] v : mVertices)
66
      {
67
      str.append(" (");
68
      str.append(v[0]);
69
      str.append(" ");
70
      str.append(v[1]);
71
      str.append(" ");
72
      str.append(v[2]);
73
      str.append(")");
74
      }
75

  
76
    if( mFacesMultigon )
77
      {
78
      int numFaces =mMultigonIndices.length;
79
      str.append("\nnumFaces: ");
80
      str.append(numFaces);
81
      str.append("\n");
82

  
83
      for(int[][] mMultigonIndex : mMultigonIndices)
84
        {
85
        int numC=mMultigonIndex.length;
86
        str.append("\nnumComponents: ");
87
        str.append(numC);
88
        str.append("\n   ");
89

  
90
        for(int[] multigonIndex : mMultigonIndex)
91
          {
92
          for(int index : multigonIndex)
93
            {
94
            str.append(" ");
95
            str.append(index);
96
            }
97
          str.append("\n   ");
98
          }
99
        }
100
      }
101
    else
102
      {
103
      int numFaces =mVertIndices.length;
104
      str.append("\nnumFaces: ");
105
      str.append(numFaces);
106
      str.append("\n   ");
107

  
108
      for(int[] vertIndex : mVertIndices)
109
        {
110
        for(int index : vertIndex)
111
          {
112
          str.append(" ");
113
          str.append(index);
114
          }
115
        str.append("\n   ");
116
        }
117
      }
118

  
119
    android.util.Log.e("D", "ObjectShape: \n"+str);
120
    }
121

  
53 122
///////////////////////////////////////////////////////////////////////////////////////////////////
54 123

  
55 124
  public int getNumFaces()

Also available in: Unified diff