Revision 6983badf
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java | ||
---|---|---|
252 | 252 |
|
253 | 253 |
private void createMesh() |
254 | 254 |
{ |
255 |
int mode = 4; |
|
255 |
int mode = 6; |
|
256 |
int numComponents = 0; |
|
256 | 257 |
double[][] vertices = null; |
257 | 258 |
int[][] vertIndexes = null; |
258 | 259 |
float[][] bands = null; |
259 | 260 |
int[] bandIndexes = null; |
260 | 261 |
float[][] corners = null; |
261 | 262 |
int[] cornerIndexes = null; |
263 |
float[][] centers = null; |
|
264 |
int[] centerIndexes = null; |
|
262 | 265 |
|
263 | 266 |
///// CUBE //////////////////////////////////////////////////////////////////////////////// |
264 | 267 |
|
... | ... | |
299 | 302 |
}; |
300 | 303 |
|
301 | 304 |
cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 }; |
305 |
|
|
306 |
centers = new float[][] |
|
307 |
{ |
|
308 |
{ 0.0f, 0.0f, 0.0f } |
|
309 |
}; |
|
310 |
|
|
311 |
centerIndexes = new int[] { 0,0,0,0,0,0,0,0 }; |
|
312 |
|
|
313 |
numComponents = 8; |
|
302 | 314 |
} |
303 | 315 |
|
304 | 316 |
///// TETRAHEDRON ////////////////////////////////////////////////////////////////////////// |
... | ... | |
334 | 346 |
}; |
335 | 347 |
|
336 | 348 |
cornerIndexes = new int[] { 0,0,0,0 }; |
349 |
|
|
350 |
centers = new float[][] |
|
351 |
{ |
|
352 |
{ 0.0f, 0.0f, 0.0f } |
|
353 |
}; |
|
354 |
|
|
355 |
centerIndexes = new int[] { 0,0,0,0 }; |
|
356 |
|
|
357 |
numComponents = 4; |
|
337 | 358 |
} |
338 | 359 |
|
339 | 360 |
///// DINO //////////////////////////////////////////////////////////////////////////////// |
... | ... | |
366 | 387 |
|
367 | 388 |
corners = new float[][] |
368 | 389 |
{ |
369 |
{ 0.01f, 0.04f }
|
|
390 |
{ 0.02f, 0.04f }
|
|
370 | 391 |
}; |
371 | 392 |
|
372 | 393 |
cornerIndexes = new int[] { 0,0,0,0 }; |
394 |
|
|
395 |
centers = new float[][] |
|
396 |
{ |
|
397 |
{ 0.0f,-0.25f,-0.25f } |
|
398 |
}; |
|
399 |
|
|
400 |
centerIndexes = new int[] { 0,0,0,0 }; |
|
401 |
|
|
402 |
numComponents = 4; |
|
373 | 403 |
} |
374 | 404 |
|
375 | 405 |
///// OCTAHEDRON //////////////////////////////////////////////////////////////////////////// |
... | ... | |
411 | 441 |
}; |
412 | 442 |
|
413 | 443 |
cornerIndexes = new int[] { 0,0,0,0,0,0 }; |
444 |
|
|
445 |
centers = new float[][] |
|
446 |
{ |
|
447 |
{ 0.0f, 0.0f, 0.0f } |
|
448 |
}; |
|
449 |
|
|
450 |
centerIndexes = new int[] { 0,0,0,0,0,0 }; |
|
451 |
|
|
452 |
numComponents = 8; |
|
414 | 453 |
} |
415 | 454 |
|
416 | 455 |
///// KILOMINX EDGE //////////////////////////////////////////////////////////////////////// |
... | ... | |
458 | 497 |
|
459 | 498 |
corners = new float[][] |
460 | 499 |
{ |
461 |
{ 0.01f, 0.12f }, |
|
462 |
{ 0.00f, 0.00f } |
|
500 |
{ 0.04f, 0.12f } |
|
501 |
}; |
|
502 |
|
|
503 |
cornerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 }; |
|
504 |
|
|
505 |
centers = new float[][] |
|
506 |
{ |
|
507 |
{ 0.0f, 0.0f, 0.0f } |
|
508 |
}; |
|
509 |
|
|
510 |
centerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 }; |
|
511 |
|
|
512 |
numComponents = 6; |
|
513 |
} |
|
514 |
|
|
515 |
///// IVY_CORNER //////////////////////////////////////////////////////////////////////// |
|
516 |
|
|
517 |
else if( mode==5 ) |
|
518 |
{ |
|
519 |
int IVY_N = 3; |
|
520 |
final float IVY_D = 0.003f; |
|
521 |
final double angle = Math.PI/(2*IVY_N); |
|
522 |
final double CORR = 1.0 - 2*IVY_D; |
|
523 |
|
|
524 |
vertices = new double[3*IVY_N+7][3]; |
|
525 |
vertIndexes = new int[6][IVY_N+4]; |
|
526 |
|
|
527 |
vertices[0][0] = 0.0; |
|
528 |
vertices[0][1] = 0.0; |
|
529 |
vertices[0][2] = 0.0; |
|
530 |
vertices[1][0] =-1.0; |
|
531 |
vertices[1][1] = 0.0; |
|
532 |
vertices[1][2] = 0.0; |
|
533 |
vertices[2][0] = 0.0; |
|
534 |
vertices[2][1] =-1.0; |
|
535 |
vertices[2][2] = 0.0; |
|
536 |
vertices[3][0] = 0.0; |
|
537 |
vertices[3][1] = 0.0; |
|
538 |
vertices[3][2] =-1.0; |
|
539 |
|
|
540 |
vertIndexes[0][0] = 2; |
|
541 |
vertIndexes[0][1] = 0; |
|
542 |
vertIndexes[0][2] = 1; |
|
543 |
vertIndexes[3][0] = 2; |
|
544 |
vertIndexes[3][1] = 0; |
|
545 |
vertIndexes[3][2] = 1; |
|
546 |
|
|
547 |
vertIndexes[1][0] = 3; |
|
548 |
vertIndexes[1][1] = 0; |
|
549 |
vertIndexes[1][2] = 2; |
|
550 |
vertIndexes[4][0] = 3; |
|
551 |
vertIndexes[4][1] = 0; |
|
552 |
vertIndexes[4][2] = 2; |
|
553 |
|
|
554 |
vertIndexes[2][0] = 1; |
|
555 |
vertIndexes[2][1] = 0; |
|
556 |
vertIndexes[2][2] = 3; |
|
557 |
vertIndexes[5][0] = 1; |
|
558 |
vertIndexes[5][1] = 0; |
|
559 |
vertIndexes[5][2] = 3; |
|
560 |
|
|
561 |
int N1 = 4; |
|
562 |
int N2 = N1 + IVY_N + 1; |
|
563 |
int N3 = N2 + IVY_N + 1; |
|
564 |
|
|
565 |
for(int i=0; i<=IVY_N; i++) |
|
566 |
{ |
|
567 |
double cos1 = Math.cos((IVY_N-i)*angle); |
|
568 |
double sin1 = Math.sin((IVY_N-i)*angle); |
|
569 |
double cos2 = Math.cos(( i)*angle); |
|
570 |
double sin2 = Math.sin(( i)*angle); |
|
571 |
|
|
572 |
vertices[N1+i][0] = CORR*(cos1-0.5) - 0.5; |
|
573 |
vertices[N1+i][1] = CORR*(sin1-0.5) - 0.5; |
|
574 |
vertices[N1+i][2] = 0.0; |
|
575 |
|
|
576 |
vertices[N2+i][0] = 0.0; |
|
577 |
vertices[N2+i][1] = CORR*(sin2-0.5) - 0.5; |
|
578 |
vertices[N2+i][2] = CORR*(cos2-0.5) - 0.5; |
|
579 |
|
|
580 |
vertices[N3+i][0] = CORR*(cos2-0.5) - 0.5; |
|
581 |
vertices[N3+i][1] = 0.0; |
|
582 |
vertices[N3+i][2] = CORR*(sin2-0.5) - 0.5; |
|
583 |
|
|
584 |
vertIndexes[0][i+3] = N1 + i; |
|
585 |
vertIndexes[1][i+3] = N2 + i; |
|
586 |
vertIndexes[2][i+3] = N3 + i; |
|
587 |
vertIndexes[3][i+3] = N1 + i; |
|
588 |
vertIndexes[4][i+3] = N2 + i; |
|
589 |
vertIndexes[5][i+3] = N3 + i; |
|
590 |
} |
|
591 |
|
|
592 |
bands = new float[][] |
|
593 |
{ |
|
594 |
{+0.012f,20,0.2f,0.5f,7,1,2}, |
|
595 |
{-0.100f,20,0.2f,0.0f,2,1,2} |
|
596 |
}; |
|
597 |
|
|
598 |
bandIndexes = new int[] { 0,0,0,1,1,1 }; |
|
599 |
|
|
600 |
corners = new float[][] |
|
601 |
{ |
|
602 |
{ 0.04f, 0.12f } |
|
603 |
}; |
|
604 |
|
|
605 |
cornerIndexes = new int[3*IVY_N+7]; |
|
606 |
|
|
607 |
centers = new float[][] |
|
608 |
{ |
|
609 |
{-0.5f,-0.5f,-0.5f} |
|
463 | 610 |
}; |
464 | 611 |
|
465 |
cornerIndexes = new int[] { 0,1,1,1,0,1,1,1 }; |
|
612 |
centerIndexes = new int[3*IVY_N+7]; |
|
613 |
|
|
614 |
for(int i=0; i<4; i++) |
|
615 |
{ |
|
616 |
cornerIndexes[i] = 0; |
|
617 |
centerIndexes[i] = 0; |
|
618 |
} |
|
619 |
for(int i=4; i<3*IVY_N+7; i++) |
|
620 |
{ |
|
621 |
cornerIndexes[i] = -1; |
|
622 |
centerIndexes[i] = -1; |
|
623 |
} |
|
624 |
|
|
625 |
numComponents = 6; |
|
626 |
} |
|
627 |
|
|
628 |
///// IVY_FACE //////////////////////////////////////////////////////////////////////// |
|
629 |
|
|
630 |
else if( mode==6 ) |
|
631 |
{ |
|
632 |
int IVY_N = 6; |
|
633 |
final float IVY_D = 0.003f; |
|
634 |
final double angle = Math.PI/(2*IVY_N); |
|
635 |
final double CORR = 1.0 - 2*IVY_D; |
|
636 |
|
|
637 |
vertices = new double[2*IVY_N][3]; |
|
638 |
vertIndexes= new int[2][2*IVY_N]; |
|
639 |
|
|
640 |
for(int i=0; i<IVY_N; i++) |
|
641 |
{ |
|
642 |
double cos = Math.cos(i*angle); |
|
643 |
double sin = Math.sin(i*angle); |
|
644 |
|
|
645 |
vertices[i ][0] = CORR*(0.5-cos); |
|
646 |
vertices[i ][1] = CORR*(0.5-sin); |
|
647 |
vertices[i ][2] = 0.0; |
|
648 |
vertices[i+IVY_N][0] = CORR*(cos-0.5); |
|
649 |
vertices[i+IVY_N][1] = CORR*(sin-0.5); |
|
650 |
vertices[i+IVY_N][2] = 0.0; |
|
651 |
|
|
652 |
vertIndexes[0][i ] = i; |
|
653 |
vertIndexes[0][i+IVY_N] = i+IVY_N; |
|
654 |
vertIndexes[1][i ] = i; |
|
655 |
vertIndexes[1][i+IVY_N] = i+IVY_N; |
|
656 |
} |
|
657 |
|
|
658 |
bands = new float[][] |
|
659 |
{ |
|
660 |
{+0.012f,20,0.2f,0.5f,7,1,2}, |
|
661 |
{-0.100f,20,0.2f,0.0f,2,1,2}, |
|
662 |
}; |
|
663 |
|
|
664 |
bandIndexes = new int[] { 0,1 }; |
|
665 |
|
|
666 |
corners = new float[][] |
|
667 |
{ |
|
668 |
{0.03f,0.10f} |
|
669 |
}; |
|
670 |
|
|
671 |
centers = new float[][] |
|
672 |
{ |
|
673 |
{-0.0f,-0.0f,-0.5f} |
|
674 |
}; |
|
675 |
|
|
676 |
cornerIndexes = new int[2*IVY_N]; |
|
677 |
centerIndexes = new int[2*IVY_N]; |
|
678 |
|
|
679 |
for(int i=0; i<2*IVY_N; i++) |
|
680 |
{ |
|
681 |
cornerIndexes[i] = -1; |
|
682 |
centerIndexes[i] = -1; |
|
683 |
} |
|
684 |
|
|
685 |
cornerIndexes[0 ] = 0; |
|
686 |
cornerIndexes[IVY_N] = 0; |
|
687 |
centerIndexes[0 ] = 0; |
|
688 |
centerIndexes[IVY_N] = 0; |
|
689 |
|
|
690 |
numComponents = 2; |
|
466 | 691 |
} |
467 | 692 |
|
468 | 693 |
FactoryCubit factory = FactoryCubit.getInstance(); |
469 |
mMesh = factory.createRoundedSolid(vertices, vertIndexes, bands, bandIndexes, corners, cornerIndexes); |
|
470 | 694 |
|
471 |
int numEff = mMesh.numEffComponents(); |
|
695 |
factory.clear(); |
|
696 |
factory.createNewFaceTransform(vertices,vertIndexes); |
|
697 |
mMesh = factory.createRoundedSolid(vertices, vertIndexes, |
|
698 |
bands, bandIndexes, |
|
699 |
corners, cornerIndexes, |
|
700 |
centers, centerIndexes, |
|
701 |
numComponents ); |
|
702 |
|
|
703 |
int numEff = mMesh.getNumEffComponents(); |
|
472 | 704 |
|
473 | 705 |
for(int i=0; i<numEff; i++) |
474 | 706 |
{ |
... | ... | |
486 | 718 |
DataInputStream dos = new DataInputStream(is); |
487 | 719 |
mMesh = new MeshFile(dos); |
488 | 720 |
|
489 |
int numEff = mMesh.numEffComponents();
|
|
721 |
int numEff = mMesh.getNumEffComponents();
|
|
490 | 722 |
|
491 | 723 |
for(int i=0; i<numEff; i++) |
492 | 724 |
{ |
... | ... | |
554 | 786 |
|
555 | 787 |
int getEffComponentNum() |
556 | 788 |
{ |
557 |
return mMesh.numEffComponents();
|
|
789 |
return mMesh.getNumEffComponents();
|
|
558 | 790 |
} |
559 | 791 |
|
560 | 792 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
561 | 793 |
|
562 | 794 |
int getTexComponentNum() |
563 | 795 |
{ |
564 |
return mMesh.numTexComponents();
|
|
796 |
return mMesh.getNumTexComponents();
|
|
565 | 797 |
} |
566 | 798 |
} |
Also available in: Unified diff
Port bugfixes from DistortedCube; add Ivy Corner & Ivy Face meshes.