ã¡ãã£ã¨ä»ã¨ã¯æ¯è²ã®éãã©ã¤ãã©ãªãcsg.jsãã®ç´¹ä»
17æ¥ç®ã® id:edvakf ããã®ãWebGLでライフゲームãã«ç¶ãã¦18æ¥ç®æ å½ã®nakamura001ã§ãã
ä»åã¯æè¿ç®ã«ãã csg.js ã¨ããã¡ãã£ã¨å¤ãã£ãWebGLã®ã©ã¤ãã©ãªãç´¹ä»ãã¾ãã
ãã®ã©ã¤ãã©ãªã¯2ã¤ã®3Dã¢ãã«ãåæããããå·®åãè¡ã£ã3Dã¢ãã«ãä½æããäºãå¯è½ã§ãã
ç°¡åãªããã°ã©ã ãæ¸ãã¤ã¤è§£èª¬ãã¾ãã®ã§ã¿ãªãããè¯ããã°å®éã«å ¥åãã¦è©¦ãã¤ã¤è¦ã¦ä¸ããã
åæºå
ã©ã¤ãã©ãªã«ã¯ãµã³ãã«ãæãã®ã§ããã¡ãã£ã¨ã ãããªã¥ã¼ã ãæãã®ã§å®éã«æ°ã«ãã¹ãç®æãã¡ãã£ã¨åããã¥ãããªã£ã¦ãã¾ãããã®çºãæ¬å½ã«å¿ è¦ãªè¦ç´ ã ããå«ãã ãã³ãã¬ã¼ãã¨ãªããã¡ã¤ã«ãæºåãã¾ãããå®éã«æãåãããªããèªã¿ããæ¹ã¯こちらããDLãã¦ããç¶ããèªãã§ä¸ããã
åä½ç¢ºèª
ãã³ãã¬ã¼ãã®ãã¡ã¤ã«ãDLã解åããä¸ãã index.html ãã¡ã¤ã«ãWebGL対å¿ã®ãã©ã¦ã¶ã§éãã¦ã¿ã¦ä¸ããã
ãã¥ã¼ã(ç«æ¹ä½)ã表示ããããã¨æãã¾ãããã¦ã¹ã§ãã©ãã°ããã¨å転ãããäºãåºæ¥ã¾ãã
ããã°ã©ã 解説
次㫠index.html ãã¡ã¤ã«ãã¨ãã£ã¿ã§éãã¦ä¸ãããããã¦ããã¡ã¤ã«ã®ä¸ãã以ä¸ã®è¨è¿°é¨åã確èªãã¦ä¸ããããã§ã¯ãã¥ã¼ããä½æãããã®ã¡ãã·ã¥ããã¥ã¼ã¢ã¼ã«æ¸¡ãã¦æç»ãè¡ãªã£ã¦ãã¾ãã
// â»ããã§Meshã®æ¼ç®ãè¡ã var cube = CSG.cube({ center: [-0.25, -0.25, -0.25] }); cube.setColor(1, 1, 0); var solid = cube; // æçµçãªã¡ãã·ã¥ãçæ viewer.mesh = solid.toMesh(); viewer.gl.ondraw();
以éã®è§£èª¬ã§ã¯ãâ»ããã§Meshã®æ¼ç®ãè¡ããã®ã³ã¡ã³ããããæçµçãªã¡ãã·ã¥ãçæãã³ã¡ã³ãã®éã®é¨åãè²ã ã¨å¤æ´ã㦠csg.js ã§ã©ããªäºãåºæ¥ãããç´¹ä»ãã¦ããã¾ãã
union(2ã¤ã®3ã¢ãã«ãåæ)
unionã¡ã½ããã使ç¨ããã¨2ã¤ã®3Dã¢ãã«ãåæããäºãåºæ¥ã¾ããããã°ã©ã ããã®æ§ã«æ¸ãæãã¦ã¿ã¦ä¸ããã
// â»ããã§Meshã®æ¼ç®ãè¡ã var cube = CSG.cube({ center: [-0.25, -0.25, -0.25] }); cube.setColor(1, 1, 0); var sphere = CSG.sphere({ radius: 1.3, center: [0.25, 0.25, 0.25] }); sphere.setColor(0, 0.5, 0); var solid = cube.union(sphere); // æçµçãªã¡ãã·ã¥ãçæ viewer.mesh = solid.toMesh(); viewer.gl.ondraw();
subtract(å¼ã)
次ã«å¼æ°ã«æå®ãã3Dã¢ãã«ãå¼ãsubtractã¡ã½ããã試ãã¦ã¿ã¾ãã
var solid = cube.union(sphere); ã®é¨åã var solid = cube.subtract(sphere); ã«å¤ãã¦ã¿ã¦ä¸ããã
ãæç»çµæã
intersect(交ãã£ãé¨åãæ®ã)
intersectã¡ã½ããã§ã¯å¼æ°ã«æå®ãã3Dã¢ãã«ã¨éãªãé¨åãæ®ãã¾ããintersectã«å¤æ´ãã¦å®è¡ãã¦ã¿ã¦ä¸ããã
ãæç»çµæã
ãªããããã§ã¯cubeãsphereãªã©ã©ã¤ãã©ãªãæä¾ãã¦ãã3Dã¢ãã«ã使ç¨ãã¾ãããä»å±ã®ãµã³ãã« more.html ãè¦ãã°åããããã«3Dã¢ãã«ãã¼ã¿(é ç¹ã¯æ³ç·ãã¼ã¿ãªã©)ãèªã¿è¾¼ã¾ãã¦è¡¨ç¤ºãããäºã«ã対å¿ãã¦ãã¾ãã
more.html ã§ã¯ gourd.js ãã3Dã¢ãã«ãã¼ã¿ãèªã¿è¾¼ãã§ä½¿ã£ã¦ãã¾ãã gourd.js ãã¡ã¤ã«ã«ãã®æ§ã«3Dã¢ãã«è¡¨ç¤ºã«å¿
è¦ãªæ
å ±ãè¨è¿°ããã¦ãã¾ãã
ãã¦ã csg.js ã¨ããã©ã¤ãã©ãªãã¡ãã£ã¨ä»ã®ã©ã¤ãã©ãªã¨ã¯æ¯è²ãç°ãªãäºãç解åºæ¥ãã§ããããï¼ç¢ºãã«ã¡ãã£ã¨ä½¿ãæãæ©ãã©ã¤ãã©ãªã§ã¯æãã¾ãã3Dã¢ããªã³ã°ãã¼ã«ãä½æããã¨ããªã©ã«ãã®æ§ãªæ©è½ãå«ããã¨ããå ´é¢ãªã©ã§ä½¿ããããªæ°ããã¾ãããçãããè¯ãã£ããã©ããã§ä½¿ã£ã¦ã¿ã¦ä¸ããã