JavaFX 3DのSphareに貼るテクスチャのマッピング(続) - torutkのブログ
ã®ç¶ãã§ãã
ååã®ãããã
ååã¯ãJavaFX 3Dã®çé¢ã¸è²¼ãä»ãããã¯ã¹ãã£ç»åã®è¡¨ç¤ºã縦æ¹åã«æ½°ããæ§ç¸ã«ãªã£ã¦ãããããããããããã¯ã¹ãã£ç»åãæ£ç©åçå³æ³ã®å°å³æå½±å¤æãããã¦ãããã¨ã§ããããã表示ãå®ç¾ãããã¨ãã§ãããã¨ã示ãã¾ããã
çé¢ã®uvãããã³ã°
3次å
ç´äº¤åº§æ¨ç³»XYZã®çé¢ã«ããã¯ã¹ãã£ããããè²¼ãå ´åã®ãããã³ã°ï¼uvãããã³ã°ï¼ã¯ã
https://en.wikipedia.org/wiki/UV_mapping
ã«ããã°æ¬¡ã®å¼ã¨ãªãã¾ãã
u = 0.5 + arctan2(dz, dx) / 2Ï v = 0.5 - arcsin(dy) / Ï (dx, dy, dz)ã¯ãçé¢ä¸ã®ç¹Pã«ãããåç¹ã¸ã®åä½ãã¯ãã«
ãªãã(u, vï¼ã¯ãã¯ã¹ãã£ã¨ãªãç»åã®å·¦ä¸ãåç¹ã¨ããå¹
ãuã縦ãvã¨ãã座æ¨ã§ãã
XYZ軸ã®XY軸ã¯ç»é¢ã®æ¨ªã»ç¸¦æ¹åãZ軸ã¯ç»é¢ã®å¥¥è¡æ¹åã¨ãªãã¾ãã
JavaFXã«ãããçé¢ã®uvãããã³ã°
JDK 8ã®JavaFXã§ã¯ã©ã®ããã«çé¢ã®uvãããã³ã°ãå®è£
ãã¦ãããã調ã¹ã¦ã¿ã¾ãã
JDK 8ã«æ·»ä»ãããã½ã¼ã¹ãã¡ã¤ã«ï¼javafx-src.zipï¼ã«ãJavaFXã®APIã®ã½ã¼ã¹ãå«ã¾ãã¦ãã¾ãã
ãã®ä¸ã«ããjavafx.scene.shape.Sphereã¯ã©ã¹ã®ã¡ã½ãã createMesh ã«uvãããã³ã°ã®å¦çãè¨è¼ããã¦ããããã§ãã
static TriangleMesh createMesh(int div, float r) { : }
div ã¯ãSphereã®ã³ã³ã¹ãã©ã¯ã¿ã®ç¬¬2å¼æ°ã§åå²æ°ï¼çãããªã´ã³ã§æ§æããã¨ãã®ããªã´ã³æ°ï¼ã§ãã
é常çç¥ããã®ã§ããã©ã«ãã®64ãé©ç¨ããã¾ãã
r ã¯ãSphereã®åå¾ã§ãã
ãã®ã¡ã½ããã®ä¸ã§uvãããã³ã°è¨ç®ããã¦ãã主è¦ãªç®æã¯æ¬¡ã¨ãªãã¾ãã
for (int y = 0; y < div2 - 1; ++y) { float va = rDiv * (y + 1 - div2 / 2) * 2 * (float) Math.PI; float sin_va = (float) Math.sin(va); float cos_va = (float) Math.cos(va); float ty = 0.5f + sin_va * 0.5f; for (int i = 0; i < div; ++i) { double a = rDiv * i * 2 * (float) Math.PI; float hSin = (float) Math.sin(a); float hCos = (float) Math.cos(a); points[pPos + 0] = hSin * cos_va * r; points[pPos + 2] = hCos * cos_va * r; points[pPos + 1] = sin_va * r; tPoints[tPos + 0] = 1 - rDiv * i; tPoints[tPos + 1] = ty; <-- ãããåé¡ pPos += 3; tPos += 2; } tPoints[tPos + 0] = 0; tPoints[tPos + 1] = ty; tPos += 2; }
vaã¯ãçé¢ä¸ã®ç¹ã極座æ¨ã§è¡¨ããã¨ãã®åç´æ¹åã®è§åº¦ã§ï¼-2/Ï,2/Ï]ãåãã¾ãã
aã¯ãçé¢ä¸ã®ç¹ã極座æ¨ã§è¡¨ããã¨ãã®æ°´å¹³æ¹åã®è§åº¦ã§ã(0, 2Ï]ãåãã¾ãã
pointsã¯çé¢ä¸ã®ç¹ã®åº§æ¨ï¼x, y, zï¼ãæ ¼ç´ããtPointsã¯ãã¯ã¹ãã£ç»åä¸ã®ç¹ã®åº§æ¨ï¼u, vï¼ãæ ¼ç´ããã¨æããã¾ãã
ããã§ã
tPoints[tPos + 1] = ty;
ã¨ããã®ãåé¡ç®æã§ã¯ãªããã¨ä»®å®ãã¾ããtyã¯
float ty = 0.5f + sin_va * 0.5f;
ã¨ãªã£ã¦ãããçé¢ä¸ã®ç¹ã極座æ¨ã§è¡¨ããã¨ãã®åç´æ¹åã®è§åº¦ããsiné¢æ°ã§ãã¯ã¹ãã£ç»åä¸ã®ç¹ã®åº§æ¨ã«å¤æãã¦ãã¾ãã
ããããåè¿°ã®Wikipediaã®UVãããã³ã°ã®å¼ã§ããã°ãæ¬æ¥ã¯ã0.5 - arcsin(-sin(va)) / Ï ã¨ãªãã®ãæ£ãã¨æããã¾ãã
ããã§ãjavafx.scene.shape.Sphereã®ã½ã¼ã¹ãã¡ã¤ã«ï¼Sphere.javaï¼ã
float ty = 0.5f + (float) (Math.asin(sin_va) / Math.PI);
ã¨æ¸ãç´ãã¦ã¿ã¾ããããã®Shere.javaãã³ã³ãã¤ã«ããçæãããSphere.classãã
JDKã¤ã³ã¹ãã¼ã«ãã£ã¬ã¯ããªã®jre/lib/ext/jfxrt.jar ã®ä¸ã®Sphere.classã¨å·®ãæ¿ãã¾ãã
å·®ãæ¿ãåå¾ã®è¡¨ç¤ºãè¦ã¦ã¿ã¾ãã
ã¾ã使ç¨ãããã¯ã¹ãã£ç»åã¯æ¬¡ã§ãã
UVãããã³ã°ä¿®æ£å | UVãããã³ã°ä¿®æ£å¾ |
---|---|
ã¨ãããã¨ã§ãå·®ãæ¿ãå¾ã¯ä»ã®å¤ãã®3Dã°ã©ãã£ãã¯ã©ã¤ãã©ãªã«ãããçé¢ã®ãã¯ã¹ãã£ã¨åã表ç¾ã¨ãªãã¾ããã
ãã®å ã¯
ä¸è¬çãªãªã¼ãã³ã½ã¼ã¹ãªããã°å ±åãããªã®ã§ãJavaã®ãã°ãã¼ã¿ãã¼ã¹ã®ãµã¤ããéãã
http://bugs.java.com/
"Sphere texture"ã§æ¤ç´¢ãã¦ã¿ãã¨ãããã¾ãã«ãã®åé¡ãåå¨ãã¦ãã¾ããã
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8092112
ããã³ã¡ã³ããè¦ãéããæåã¯ä¿®æ£ãããä»å¾enumãç¨æãã¦ãã¯ã¹ãã£ãããã³ã°æ¹å¼ãé¸æå¯è½ã¨ããããï¼ä»ã¯å®è£ ããã¦ããªãï¼ã¨ãã£ããã¨ã®ããã§ãã