2017年11月9日 星期四

JavaFX 3D - Truncated Icosahedron

以下是以JavaFX 8的TriangleMesh類別建構之Truncated Icosahedron (截角二十面體),屬於Archimedean Solid (阿基米德立體)。

float C0 = length * (float) (1.0 + Math.sqrt(5.0)) / 4.0f;
float C1 = length * (float) (1.0 + Math.sqrt(5.0)) / 2.0f;
float C2 = length * (float) (5.0 + Math.sqrt(5.0)) / 4.0f;
float C3 = length * (float) (2.0 + Math.sqrt(5.0)) / 2.0f;
float C4 = length * (float) (1.0 + Math.sqrt(5.0)) / 4.0f * 3.0f;
float C5 = length * 0.5f;
float C6 = length * 1.0f;

// 建立TriangleMesh
TriangleMesh trianglemesh = new TriangleMesh();

// 設定頂點座標
trianglemesh.getPoints().addAll(
    C5, 0.0f,   C4,
    C5, 0.0f,  -C4,
   -C5, 0.0f,   C4,
   -C5, 0.0f,  -C4,
    C4,   C5, 0.0f,
    C4,  -C5, 0.0f,
   -C4,   C5, 0.0f,
   -C4,  -C5, 0.0f,
  0.0f,   C4,   C5,
  0.0f,   C4,  -C5,
  0.0f,  -C4,   C5,
  0.0f,  -C4,  -C5,
    C6,   C0,   C3,
    C6,   C0,  -C3,
    C6,  -C0,   C3,
    C6,  -C0,  -C3,
   -C6,   C0,   C3,
   -C6,   C0,  -C3,
   -C6,  -C0,   C3,
   -C6,  -C0,  -C3,
    C3,   C6,   C0,
    C3,   C6,  -C0,
    C3,  -C6,   C0,
    C3,  -C6,  -C0,
   -C3,   C6,   C0,
   -C3,   C6,  -C0,
   -C3,  -C6,   C0,
   -C3,  -C6,  -C0,
    C0,   C3,   C6,
    C0,   C3,  -C6,
    C0,  -C3,   C6,
    C0,  -C3,  -C6,
   -C0,   C3,   C6,
   -C0,   C3,  -C6,
   -C0,  -C3,   C6,
   -C0,  -C3,  -C6,
    C5,   C1,   C2,
    C5,   C1,  -C2,
    C5,  -C1,   C2,
    C5,  -C1,  -C2,
   -C5,   C1,   C2,
   -C5,   C1,  -C2,
   -C5,  -C1,   C2,
   -C5,  -C1,  -C2,
    C2,   C5,   C1,
    C2,   C5,  -C1,
    C2,  -C5,   C1,
    C2,  -C5,  -C1,
   -C2,   C5,   C1,
   -C2,   C5,  -C1,
   -C2,  -C5,   C1,
   -C2,  -C5,  -C1,
    C1,   C2,   C5,
    C1,   C2,  -C5,
    C1,  -C2,   C5,
    C1,  -C2,  -C5,
   -C1,   C2,   C5,
   -C1,   C2,  -C5,
   -C1,  -C2,   C5,
   -C1,  -C2,  -C5
);

// 設定貼圖座標
trianglemesh.getTexCoords().addAll(
  0.0f, 0.0f, // 0                         
  0.5f, 0.0f, // 1                          
  1.0f, 0.0f, // 2                               
  0.0f, 0.5f, // 3                               
  0.5f, 0.5f, // 4                               
  1.0f, 0.5f, // 5                              
  0.0f, 1.0f, // 6                               
  0.5f, 1.0f, // 7                               
  1.0f, 1.0f  // 8                          
);

// 設定各三角形的面
trianglemesh.getFaces().addAll(
   0, 0, 14, 4, 46, 1,
   0, 0, 46, 4, 44, 1,
   0, 0, 44, 4, 12, 1,
   1, 0, 13, 4, 45, 1,
   1, 0, 45, 4, 47, 1,
   1, 0, 47, 4, 15, 1,
   2, 0, 16, 4, 48, 1,
   2, 0, 48, 4, 50, 1,
   2, 0, 50, 4, 18, 1,
   3, 0, 19, 4, 51, 1,
   3, 0, 51, 4, 49, 1,
   3, 0, 49, 4, 17, 1,
   4, 0, 21, 4, 53, 1,
   4, 0, 53, 4, 52, 1,
   4, 0, 52, 4, 20, 1,
   5, 0, 22, 4, 54, 1,
   5, 0, 54, 4, 55, 1,
   5, 0, 55, 4, 23, 1,
   6, 0, 24, 4, 56, 1,
   6, 0, 56, 4, 57, 1,
   6, 0, 57, 4, 25, 1,
   7, 0, 27, 4, 59, 1,
   7, 0, 59, 4, 58, 1,
   7, 0, 58, 4, 26, 1,
   8, 0, 32, 4, 40, 1,
   8, 0, 40, 4, 36, 1,
   8, 0, 36, 4, 28, 1,
   9, 0, 29, 4, 37, 1,
   9, 0, 37, 4, 41, 1,
   9, 0, 41, 4, 33, 1,
  10, 0, 30, 4, 38, 1,
  10, 0, 38, 4, 42, 1,
  10, 0, 42, 4, 34, 1,
  11, 0, 35, 4, 43, 1,
  11, 0, 43, 4, 39, 1,
  11, 0, 39, 4, 31, 1,
   0, 1,  2, 5, 18, 2,
   0, 1, 18, 5, 42, 2,
   0, 1, 42, 5, 38, 2,
   0, 1, 38, 5, 14, 2,
   0, 1, 12, 5, 36, 2,
   0, 1, 36, 5, 40, 2,
   0, 1, 40, 5, 16, 2,
   0, 1, 16, 5,  2, 2,
   1, 1,  3, 5, 17, 2,
   1, 1, 17, 5, 41, 2,
   1, 1, 41, 5, 37, 2,
   1, 1, 37, 5, 13, 2,
   1, 1, 15, 5, 39, 2,
   1, 1, 39, 5, 43, 2,
   1, 1, 43, 5, 19, 2,
   1, 1, 19, 5,  3, 2,
  20, 1, 44, 5, 46, 2,
  20, 1, 46, 5, 22, 2,
  20, 1, 22, 5,  5, 2,
  20, 1,  5, 5,  4, 2,
  20, 1, 52, 5, 28, 2,
  20, 1, 28, 5, 36, 2,
  20, 1, 36, 5, 12, 2,
  20, 1, 12, 5, 44, 2,
  23, 1, 47, 5, 45, 2,
  23, 1, 45, 5, 21, 2,
  23, 1, 21, 5,  4, 2,
  23, 1,  4, 5,  5, 2,
  23, 1, 55, 5, 31, 2,
  23, 1, 31, 5, 39, 2,
  23, 1, 39, 5, 15, 2,
  23, 1, 15, 5, 47, 2,
  24, 1, 48, 5, 16, 2,
  24, 1, 16, 5, 40, 2,
  24, 1, 40, 5, 32, 2,
  24, 1, 32, 5, 56, 2,
  24, 1,  6, 5,  7, 2,
  24, 1,  7, 5, 26, 2,
  24, 1, 26, 5, 50, 2,
  24, 1, 50, 5, 48, 2,
  27, 1, 51, 5, 19, 2,
  27, 1, 19, 5, 43, 2,
  27, 1, 43, 5, 35, 2,
  27, 1, 35, 5, 59, 2,
  27, 1,  7, 5,  6, 2,
  27, 1,  6, 5, 25, 2,
  27, 1, 25, 5, 49, 2,
  27, 1, 49, 5, 51, 2,
  29, 1, 53, 5, 21, 2,
  29, 1, 21, 5, 45, 2,
  29, 1, 45, 5, 13, 2,
  29, 1, 13, 5, 37, 2,
  29, 1,  9, 5,  8, 2,
  29, 1,  8, 5, 28, 2,
  29, 1, 28, 5, 52, 2,
  29, 1, 52, 5, 53, 2,
  30, 1, 54, 5, 22, 2,
  30, 1, 22, 5, 46, 2,
  30, 1, 46, 5, 14, 2,
  30, 1, 14, 5, 38, 2,
  30, 1, 10, 5, 11, 2,
  30, 1, 11, 5, 31, 2,
  30, 1, 31, 5, 55, 2,
  30, 1, 55, 5, 54, 2,
  33, 1, 57, 5, 56, 2,
  33, 1, 56, 5, 32, 2,
  33, 1, 32, 5,  8, 2,
  33, 1,  8, 5,  9, 2,
  33, 1, 41, 5, 17, 2,
  33, 1, 17, 5, 49, 2,
  33, 1, 49, 5, 25, 2,
  33, 1, 25, 5, 57, 2,
  34, 1, 58, 5, 59, 2,
  34, 1, 59, 5, 35, 2,
  34, 1, 35, 5, 11, 2,
  34, 1, 11, 5, 10, 2,
  34, 1, 42, 5, 18, 2,
  34, 1, 18, 5, 50, 2,
  34, 1, 50, 5, 26, 2,
  34, 1, 26, 5, 58, 2
);

// 設定各面的平滑參數
trianglemesh.getFaceSmoothingGroups().addAll(
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,      
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,      
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,     
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0,
  0, 0, 0, 0
);

// 建立MeshView
MeshView meshview;

meshview = new MeshView(createMesh(70));
...
【參考資料】

[1] Java Official Web Site:http://www.oracle.com/technetwork/java/index.html
[2] JavaFX:http://www.oracle.com/technetwork/java/javafx
[3] JavaFX 8.0 API Specification.
[4] Java Platform, Standard Edition 8 API Specification.
[5] JDK 8 Certified System Configurations.
[6] H. M. Cundy, A. P. Rollett, Mathematical Models, Tarquin Publications, 1981.
[7] G. Sellers, R. S. Wright, N. Haemel, OpenGL SuperBible: Comprehensive Tutorial and Reference (6th Edition), Addison-Wesley Professional, 2013.
[8] 黃嘉輝, JavaFX 8技術手冊, ISBN: 9789863474050, 碁峰資訊, 2014.

© Chia-Hui Huang

沒有留言:

張貼留言