Project

General

Profile

« Previous | Next » 

Revision fa5dad15

Added by Leszek Koltunski over 1 year ago

Major progress with supporting cubit faces with holes.

View differences:

src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
329 329
      mMesh.setEffectAssociation(0,0,0);
330 330
      }
331 331

  
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

  
334
    private float[] gen(float x, float y)
335
      {
336
      return new float[] { x+0.1f, y-0.1f, x-0.1f, y-0.1f, x-0.1f, y+0.1f, x+0.1f, y+0.1f };
337
      }
338

  
332 339
///////////////////////////////////////////////////////////////////////////////////////////////////
333 340

  
334 341
    private void createMultigon()
......
337 344
      int extraIndex    = 0;
338 345
      int extraVertices = 0;
339 346

  
340
      float[] v1 = new float[] {  0,0,  0.5f, -SQ3/2, 1,0 };
341
      float[] v2 = new float[] { -1,0, -0.5f, -SQ3/2, 0,0 };
342
      float[] v3 = new float[] {  0,0, -0.5f, -SQ3/2, 0.5f, -SQ3/2 };
343

  
344
      float[][] vertices = new float[][] {v1,v2,v3};
345
/*
346
      float[] v1 = new float[] {  -A,-A,   A,-A,   A,  A,   -A,  A };
347
      float[] v2 = new float[] {   A,-A, 2*A,-A, 2*A,  A,    A,  A };
348
      float[] v3 = new float[] {-3*A,-A,  -A,-A,  -A,  A, -3*A,  A };
349
      float[] v4 = new float[] {  -A, A,   A, A,   A,3*A,   -A,3*A };
350
      float[] v5 = new float[] {-3*A, A,  -A, A,  -A,3*A, -3*A,3*A };
351

  
352
      float[][] vertices = new float[][] {v1,v2,v3,v4,v5};
353
 */
354
/*
355
      float[] c1 = new float[] { 0,0 };
356
      float[] c2 = new float[] { 1.5f*A,0 };
357
      float[] c3 = new float[] {-1.5f*A,0 };
358
      float[] c4 = new float[] { 0,1.5f*A };
359
      float[] c5 = new float[] { -1.5f*A,1.5f*A };
360

  
361
      float[][] centers = new float[][] { c1,c2,c3,c4,c5 };
362
*/
363
      float C = 2f;
347
      float[][] vertices = new float[19][];
348

  
349
      vertices[ 0] = gen( 0.4f,-0.4f);
350
      vertices[ 1] = gen( 0.2f,-0.4f);
351
      vertices[ 2] = gen( 0.0f,-0.4f);
352
      vertices[ 3] = gen(-0.2f,-0.4f);
353
      vertices[ 4] = gen(-0.4f,-0.4f);
354
      vertices[ 5] = gen(-0.4f,-0.2f);
355
      vertices[ 6] = gen(-0.4f, 0.0f);
356
      vertices[ 7] = gen(-0.4f, 0.2f);
357
      vertices[ 8] = gen(-0.4f, 0.4f);
358
      vertices[ 9] = gen(-0.2f, 0.4f);
359
      vertices[10] = gen( 0.0f, 0.4f);
360
      vertices[11] = gen( 0.2f, 0.4f);
361
      vertices[12] = gen( 0.4f, 0.4f);
362
      vertices[13] = gen( 0.4f, 0.2f);
363
      vertices[14] = gen( 0.4f, 0.0f);
364
      vertices[15] = gen( 0.4f,-0.2f);
365
      vertices[16] = gen( 0.0f,-0.2f);
366
      vertices[17] = gen( 0.0f, 0.0f);
367
      vertices[18] = gen( 0.0f, 0.2f);
368

  
369
      float C = 0.5f;
364 370
      float[] bands = new float[] { 1.0f, 0.00f*C, 0.9f, 0.04f*C,  0.8f, 0.07f*C, 0.5f, 0.09f*C, 0.0f, 0.10f*C};
365

  
366 371
/*
367 372
      float B = 0.1f;
368 373
      int numBands = 7;
......
384 389
        }
385 390
      }
386 391

  
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

  
394
    private float[][] createV()
395
      {
396
      return new float[][]
397
              {
398
                      {-0.5f ,  1.5f , -0.5f },  //0
399
                      {-0.5f ,  0.5f , -0.5f },
400
                      {-0.5f ,  0.5f ,  0.5f },
401
                      {-0.5f ,  1.5f ,  0.5f },
402
                      {-0.5f , -0.5f , -0.5f },
403
                      {-0.5f , -0.5f ,  0.5f },  //5
404
                      {-0.5f , -1.5f , -0.5f },
405
                      {-0.5f , -1.5f ,  0.5f },
406
                      { 1.5f , -0.5f , -0.5f },
407
                      { 1.5f , -1.5f , -0.5f },
408
                      { 1.5f , -1.5f ,  0.5f },  //10
409
                      { 1.5f , -0.5f ,  0.5f },
410
                      { 1.5f ,  0.5f , -0.5f },
411
                      { 1.5f ,  0.5f ,  0.5f },
412
                      { 1.5f ,  1.5f , -0.5f },
413
                      { 1.5f ,  1.5f ,  0.5f },  //15
414
                      {-2.5f ,  2.5f , -0.5f },
415
                      {-2.5f ,  1.5f , -0.5f },
416
                      {-2.5f ,  1.5f ,  0.5f },
417
                      {-2.5f ,  2.5f ,  0.5f },
418
                      {-2.5f ,  0.5f , -0.5f },  //20
419
                      {-2.5f ,  0.5f ,  0.5f },
420
                      {-2.5f , -0.5f , -0.5f },
421
                      {-2.5f , -0.5f ,  0.5f },
422
                      {-2.5f , -1.5f , -0.5f },
423
                      {-2.5f , -1.5f ,  0.5f },  //25
424
                      {-2.5f , -2.5f , -0.5f },
425
                      {-2.5f , -2.5f ,  0.5f },
426
                      { 0.5f ,  1.5f ,  0.5f },
427
                      { 0.5f ,  0.5f ,  0.5f },
428
                      { 0.5f ,  0.5f , -0.5f },  //30
429
                      { 0.5f ,  1.5f , -0.5f },
430
                      { 0.5f , -0.5f ,  0.5f },
431
                      { 0.5f , -0.5f , -0.5f },
432
                      { 0.5f , -1.5f ,  0.5f },
433
                      { 0.5f , -1.5f , -0.5f },  //35
434
                      { 2.5f , -0.5f ,  0.5f },
435
                      { 2.5f , -1.5f ,  0.5f },
436
                      { 2.5f , -1.5f , -0.5f },
437
                      { 2.5f , -0.5f , -0.5f },
438
                      { 2.5f ,  0.5f ,  0.5f },  //40
439
                      { 2.5f ,  0.5f , -0.5f },
440
                      { 2.5f ,  1.5f ,  0.5f },
441
                      { 2.5f ,  1.5f , -0.5f },
442
                      { 2.5f ,  2.5f ,  0.5f },
443
                      { 2.5f ,  2.5f , -0.5f },  //45
444
                      { 2.5f , -2.5f ,  0.5f },
445
                      { 2.5f , -2.5f , -0.5f },
446
                      {-1.5f ,  1.5f ,  0.5f },
447
                      {-1.5f ,  0.5f ,  0.5f },
448
                      {-1.5f ,  0.5f , -0.5f },  //50
449
                      {-1.5f ,  1.5f , -0.5f },
450
                      {-1.5f , -0.5f ,  0.5f },
451
                      {-1.5f , -0.5f , -0.5f },
452
                      {-1.5f , -1.5f ,  0.5f },
453
                      {-1.5f , -1.5f , -0.5f },  //55
454
                      {-1.5f , -2.5f , -0.5f },
455
                      {-1.5f , -2.5f ,  0.5f },
456
                      {-0.5f , -2.5f , -0.5f },
457
                      {-0.5f , -2.5f ,  0.5f },
458
                      { 0.5f , -2.5f , -0.5f },  //60
459
                      { 0.5f , -2.5f ,  0.5f },
460
                      { 1.5f , -2.5f , -0.5f },
461
                      { 1.5f , -2.5f ,  0.5f },
462
                      { 1.5f ,  2.5f , -0.5f },
463
                      { 1.5f ,  2.5f ,  0.5f },  //65
464
                      { 0.5f ,  2.5f , -0.5f },
465
                      { 0.5f ,  2.5f ,  0.5f },
466
                      {-0.5f ,  2.5f , -0.5f },
467
                      {-0.5f ,  2.5f ,  0.5f },
468
                      {-1.5f ,  2.5f , -0.5f },  //70
469
                      {-1.5f ,  2.5f ,  0.5f },
470
              };
471
      }
472

  
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

  
475
    private int[][][] createVI()
476
      {
477
      return new int[][][]
478
              {
479
                    //  { {  0, 1, 2, 3 } , {  1, 4, 5, 2 } , {  4, 6, 7, 5 } },
480
                    //  { {  8, 9,10,11 } , { 12, 8,11,13 } , { 14,12,13,15 } },
481
                    //  { { 16,17,18,19 } , { 17,20,21,18 } , { 20,22,23,21 } , { 22,24,25,23 } , { 24,26,27,25 } },
482
                    //  { { 28,29,30,31 } , { 29,32,33,30 } , { 32,34,35,33 } },
483
                    //  { { 36,37,38,39 } , { 40,36,39,41 } , { 42,40,41,43 } , { 44,42,43,45 } , { 37,46,47,38 } },
484
                    //  { { 48,49,50,51 } , { 49,52,53,50 } , { 52,54,55,53 } },
485
                    //  { { 28,31,14,15 } },
486
                    //  { { 48,51, 0, 3 } },
487
                    //  { { 27,26,56,57 } , { 57,56,58,59 } , { 59,58,60,61 } , { 61,60,62,63 } , { 63,62,47,46 } },
488
                    //  { { 64,65,44,45 } , { 66,67,65,64 } , { 68,69,67,66 } , { 70,71,69,68 } , { 16,19,71,70 } },
489
                    //  { { 55,54, 7, 6 } },
490
                    //  { { 35,34,10, 9 } },
491
                      { { 31,30, 1, 0 } , { 30,33, 4, 1 } , { 33,35, 6, 4 } , { 35,60,58, 6 } , {  6,58,56,55 } , { 55,56,26,24 } , { 53,55,24,22 } , { 50,53,22,20 } , { 51,50,20,17 } , { 70,51,17,16 } , { 68, 0,51,70 } , { 66,31, 0,68 } , { 64,14,31,66 } , { 45,43,14,64 } , { 43,41,12,14 } , { 41,39, 8,12 } , { 39,38, 9, 8 } , { 38,47,62, 9 } , {  9,62,60,35 } },
492
                      { {  3, 2,29,28 } , {  2, 5,32,29 } , {  5, 7,34,32 } , {  7,59,61,34 } , { 54,57,59, 7 } , { 25,27,57,54 } , { 23,25,54,52 } , { 21,23,52,49 } , { 18,21,49,48 } , { 19,18,48,71 } , { 71,48, 3,69 } , { 69, 3,28,67 } , { 67,28,15,65 } , { 65,15,42,44 } , { 15,13,40,42 } , { 13,11,36,40 } , { 11,10,37,36 } , { 10,63,46,37 } , { 34,61,63,10 } },
493
              };
494
      }
495

  
387 496
///////////////////////////////////////////////////////////////////////////////////////////////////
388 497

  
389 498
    private void createMesh()
390 499
      {
391
      /*
392
      float A = 2.0f;
393

  
394
      float[][] vertices =
395
          {
396
              { 0.5f, 0.5f, 0.5f },
397
              { 0.5f, 0.5f,-0.5f },
398
              { 0.5f,-0.5f, 0.5f },
399
              { 0.5f,-0.5f,-0.5f },
400
              {-0.5f, 0.5f, 0.5f },
401
              {-0.5f, 0.5f,-0.5f },
402
              {-0.5f,-0.5f, 0.5f },
403
              {-0.5f,-0.5f,-0.5f },
404

  
405
              { 0.5f,   -A, 0.5f },
406
              { 0.5f,   -A,-0.5f },
407
              {-0.5f,   -A, 0.5f },
408
              {-0.5f,   -A,-0.5f },
409

  
410
              {   -A, 0.5f, 0.5f },
411
              {   -A, 0.5f,-0.5f },
412
              {   -A,-0.5f, 0.5f },
413
              {   -A,-0.5f,-0.5f },
414
          };
415

  
416
      int[][][] vertIndices =
417
          {
418
              { { 8, 9, 1, 0} },
419
              { {15,14,12,13} },
420
              { {11,10, 6, 7} },
421
              { {12, 0, 1,13} },
422
              { {11, 9, 8,10} },
423
              { {15, 7, 6,14} },
424
              { {14, 6, 4,12}, { 6, 2, 0, 4}, {10, 8, 2, 6} },
425
              { { 3, 7, 5, 1}, { 9,11, 7, 3}, { 7,15,13, 5} }
426
          };
427

  
428
      float height = 0.02f;
429
      int num = 5;
430
      int extraI = 1;
431
      int extraV = 1;
432

  
433
      float[][] bands= { {height,25,0.3f,0.5f,num,extraI,extraV} };
434

  
435
      int[] bandIndices = {0,0,0,0,0,0,0,0};
436
      float[] convex = null;
437

  
438
      float[][] corners= { {0.036f,0.12f} };
439
      float[][] centers= { {0.0f, 0.0f, 0.0f} };
440
      int[] ind    = { 0,0,-1,-1,-1,-1,-1,-1, 0,0,0,0,0,0,0,0 };
441
      */
442
      float[][] vertices = { {-1.5f, 0.0f, 0.0f},{ 1.5f, 0.0f, 0.0f},{ 0.0f,-1.5f, 0.0f},{ 0.0f, 0.0f,-1.5f},{0,0,0} };
443
      int[][][] vertIndices = { {{2,1,4},{4,0,2}},{{3,0,4},{4,1,3}},{{2,3,1}},{{3,2,0}} };
444
      float h1 = 0.035f;
445
      float h2 = 0.010f;
500
      float[][] vertices = createV();
501
      int[][][] vertIndices = createVI();
502

  
503
      int numFaces = vertIndices.length;
504

  
505
      float h = 0.001f;
446 506
      int angle = 30;
447 507
      float R = 0.1f;
448 508
      float S = 0.5f;
449 509
      int N   = 6;
450 510
      int exI = 0;
451 511
      int exV = 0;
452
      float[][] bands  = { {h1,angle,R,S,N,exI,exV}, {h2,angle,R,S,N,exI,exV} };
453
      int[] bandIndices= { 0,0,1,1 };
454
      float[] convex = null;
455
      float[][] corners   = { {0.07f,0.40f}, {0.05f,0.30f} };
456
      int[] cornerIndices = { 0,0,1,1,-1 };
457
      float[][] centers   = { {0.0f, -0.75f, -0.75f} };
458
      int[] centerIndices = { 0,0,0,0,-1 };
512
      float[][] bands  = { {h,angle,R,S,N,exI,exV} };
513

  
514
      int[] bandIndices= new int[numFaces];
459 515

  
460 516
      ObjectShape shape = new ObjectShape(vertices, vertIndices);
461
      ObjectFaceShape face = new ObjectFaceShape(bands, bandIndices, convex);
462
      ObjectVertexEffects effects = FactoryCubit.generateVertexEffect(vertices,corners,cornerIndices,centers,centerIndices);
517
      ObjectFaceShape face = new ObjectFaceShape(bands, bandIndices, null);
463 518

  
464
      int numFaces = shape.getNumFaces();
465 519
      int[] outer = new int[numFaces];
466 520

  
467 521
      FactoryCubit factory = FactoryCubit.getInstance();
468 522
      factory.clear();
469 523
      factory.createNewFaceTransform(shape,outer);
470
      mMesh = factory.createRoundedSolid(shape,face,effects,MESH_NICE,numFaces);
524
      mMesh = factory.createRoundedSolid(shape,face,null,MESH_NICE,numFaces);
471 525

  
472 526
      int numEff = mMesh.getNumEffComponents();
473 527
      for(int i=0; i<numEff; i++) mMesh.setEffectAssociation(i, 0, i);

Also available in: Unified diff