2017年11月10日 星期五

JavaFX 3D - Borromean Rings

以下是以JavaFX 8的TriangleMesh類別建構之Borromean Rings,屬於Regular Tetragonal Toroidal Solid之一。

A toroid is said to be regular if every face has p vertices, and every vertex joins q faces. The Regular Tetragonal Toroidal Solids are regular genus-1 toroids in the class {4,4} (p=4, q=4) where 4 tetragonal (quadrilateral) faces meet at every vertex.
float C0  = length * 0.0f;
float C1  = length * 1.0f;
float C2  = length * 2.0f;
float C3  = length * 3.0f;
float C4  = length * 4.0f;
float C5  = length * 5.0f;

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

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

// 設定貼圖座標
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, 1,  2, 5,  6, 2,  // Yellow
   0, 1,  6, 5,  4, 2,  // Yellow
   0, 1,  4, 5,  5, 2,  // Yellow
   0, 1,  5, 5,  1, 2,  // Yellow
   0, 1,  1, 5,  9, 2,  // Yellow
   0, 1,  9, 5,  8, 2,  // Yellow
   0, 1,  8, 5, 10, 2,  // Yellow
   0, 1, 10, 5,  2, 2,  // Yellow
   3, 1,  2, 5, 10, 2,  // Yellow
   3, 1, 10, 5, 11, 2,  // Yellow
   3, 1, 11, 5,  9, 2,  // Yellow
   3, 1,  9, 5,  1, 2,  // Yellow
   3, 1,  1, 5,  5, 2,  // Yellow
   3, 1,  5, 5,  7, 2,  // Yellow
   3, 1,  7, 5,  6, 2,  // Yellow
   3, 1,  6, 5,  2, 2,  // Yellow
   4, 1,  6, 5, 10, 2,  // Yellow
   4, 1, 10, 5,  8, 2,  // Yellow
   4, 1,  8, 5,  9, 2,  // Yellow
   4, 1,  9, 5,  5, 2,  // Yellow
   7, 1,  5, 5,  9, 2,  // Yellow
   7, 1,  9, 5, 11, 2,  // Yellow
   7, 1, 11, 5, 10, 2,  // Yellow
   7, 1, 10, 5,  6, 2,  // Yellow
  12, 0, 14, 3, 18, 1,  // Red
  12, 0, 18, 3, 16, 1,  // Red
  12, 0, 16, 3, 17, 1,  // Red
  12, 0, 17, 3, 13, 1,  // Red
  12, 0, 13, 3, 21, 1,  // Red
  12, 0, 21, 3, 20, 1,  // Red
  12, 0, 20, 3, 22, 1,  // Red
  12, 0, 22, 3, 14, 1,  // Red
  15, 0, 14, 3, 22, 1,  // Red
  15, 0, 22, 3, 23, 1,  // Red
  15, 0, 23, 3, 21, 1,  // Red
  15, 0, 21, 3, 13, 1,  // Red
  15, 0, 13, 3, 17, 1,  // Red
  15, 0, 17, 3, 19, 1,  // Red
  15, 0, 19, 3, 18, 1,  // Red
  15, 0, 18, 3, 14, 1,  // Red
  16, 0, 18, 3, 22, 1,  // Red
  16, 0, 22, 3, 20, 1,  // Red
  16, 0, 20, 3, 21, 1,  // Red
  16, 0, 21, 3, 17, 1,  // Red
  19, 0, 17, 3, 21, 1,  // Red
  19, 0, 21, 3, 23, 1,  // Red
  19, 0, 23, 3, 22, 1,  // Red
  19, 0, 22, 3, 18, 1,  // Red
  24, 3, 26, 6, 30, 7,  // Green
  24, 3, 30, 6, 28, 7,  // Green
  24, 3, 28, 6, 29, 7,  // Green
  24, 3, 29, 6, 25, 7,  // Green
  24, 3, 25, 6, 33, 7,  // Green
  24, 3, 33, 6, 32, 7,  // Green
  24, 3, 32, 6, 34, 7,  // Green
  24, 3, 34, 6, 26, 7,  // Green
  27, 3, 26, 6, 34, 7,  // Green
  27, 3, 34, 6, 35, 7,  // Green
  27, 3, 35, 6, 33, 7,  // Green
  27, 3, 33, 6, 25, 7,  // Green
  27, 3, 25, 6, 29, 7,  // Green
  27, 3, 29, 6, 31, 7,  // Green
  27, 3, 31, 6, 30, 7,  // Green
  27, 3, 30, 6, 26, 7,  // Green
  28, 3, 30, 6, 34, 7,  // Green
  28, 3, 34, 6, 32, 7,  // Green
  28, 3, 32, 6, 33, 7,  // Green
  28, 3, 33, 6, 29, 7,  // Green
  31, 3, 29, 6, 33, 7,  // Green
  31, 3, 33, 6, 35, 7,  // Green
  31, 3, 35, 6, 34, 7,  // Green
  31, 3, 34, 6, 30, 7   // Green
);

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
);

// 建立MeshView
MeshView meshview;

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

[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

6 則留言:

  1. 老師您好,一年前受到您網站的幫助,混了一年Java工程師的經驗,聽說Java9九月要出了,您還會出下一本書嗎?

    http://www.ithome.com.tw/news/95757

    回覆刪除
    回覆
    1. 謝謝你的建議,目前沒有計劃,但世事難料,或許會寫,但要看出版商,現在出版商很不景氣

      刪除
  2. 現在出版商真的很不景氣,也很少有人在買書了,都上網查居多,加上簡體書,出版商真的很不好做…

    還是感謝您之前的照顧,謝謝…

    回覆刪除
    回覆
    1. 不用客氣,只是互相分享而已,若有需要幫忙,請告訴我。

      現在真的很少人在買書,學生也是如此,寧可影印,也不願意買紙本,所以現在出版業真的很慘,好在我不是靠這維生,不然真的會餓死。

      寫書只是為了一個小小的夢想,每當想到一個新主題,個性使然,總是迫不及待想要把它寫下來,至於有沒有人要看,從來都不是我的首要目的,而每當拿到新書,就是在等這一刻,偷笑都會偷笑很久,這種感覺真的無法與別人分享。

      寫作是條孤單寂寞的路,只有自己最瞭解。

      刪除
  3. 老師好久沒來這裡看看了…
    看這裡還有在更新,真的很感動,也證明老師的身體還可以再寫20年呀…XD

    回覆刪除
    回覆
    1. 謝謝你的支持,不知道還能做多久,只要能寫就繼續寫下去,謝謝你

      刪除