{"id":17075,"date":"2022-04-04T18:48:37","date_gmt":"2022-04-04T09:48:37","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=17075"},"modified":"2023-05-27T20:51:23","modified_gmt":"2023-05-27T11:51:23","slug":"%e3%80%90three-js%e3%80%91%e6%a6%82%e8%a6%81","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=17075","title":{"rendered":"\u3010Three.js\u3011\u57fa\u672c"},"content":{"rendered":"<h2>Three.js\u3068\u306f\uff1f<\/h2>\n<p>three\u3068\u306f3D\u306e3\u3092\u82f1\u8a9e\u306b\u3057\u305f\u3082\u306e\u3067\u3059\u3002WebGL\u306e\u6280\u8853\u3092\u4f7f\u3063\u3066Web\u30d6\u30e9\u30a6\u30b6\u4e0a\u30673D\u8868\u73fe\u3092\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u30ea\u30ea\u30fc\u30b9\u30ce\u30fc\u30c8<\/h2>\n<table>\n<tbody>\n<tr>\n<th>\u30d0\u30fc\u30b8\u30e7\u30f3<\/th>\n<th>\u30ea\u30ea\u30fc\u30b9\u5e74\u6708<\/th>\n<th>\u5099\u8003<\/th>\n<\/tr>\n<tr>\n<td>83<\/td>\n<td>2016\/12<\/td>\n<td>WebGL2\u5bfe\u5fdc\u304c\u59cb\u307e\u3063\u305f\u3002<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>2019\/1<\/td>\n<td>WebGL2\u306e\u4e00\u90e8\u306e\u6a5f\u80fd\u306e\u307f\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td>134<\/td>\n<td>2021\/10<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>137<\/td>\n<td>2022\/1<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>140<\/td>\n<td>2022\/5<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>WebGL\u3068\u306e\u9055\u3044\u306f\uff1f<\/h2>\n<p>\u901a\u5e38\u306eWebGL\u3060\u3068\u4f8b\u3048\u3070\u7acb\u65b9\u4f53\u4e00\u3064\u8868\u73fe\u3059\u308b\u3060\u3051\u3067\u3082\u591a\u304f\u306eJavaScript\u30b3\u30fc\u30c9\u3084\u3001GLSL\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u5fc5\u8981\u304c\u3042\u308a\u5c02\u9580\u77e5\u8b58\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002Three.js\u3092\u4f7f\u3046\u3053\u3068\u306b\u3088\u3063\u3066JavaScript\u306e\u77e5\u8b58\u3060\u3051\u3067WebGL\u306e\u5b9f\u88c5\u3092\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>Three.js\u306f\u4f55\u304c\u3067\u304d\u308b\u306e\u304b\uff1f<\/h2>\n<p>\u30de\u30a6\u30b9\u306e\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3067\u8272\u30053D\u3092\u52d5\u304b\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u5177\u4f53\u4f8b<\/h2>\n<h3>Zenly<\/h3>\n<p>\u30af\u30eb\u30af\u30eb\u5730\u7403\u3092\u56de\u305b\u307e\u3059\u3002<\/p>\n<h3>\u30de\u30a4\u30f3\u30af\u30e9\u30d5\u30c8<\/h3>\n<p>\u3053\u308c\u3082\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u57fa\u790e<\/h2>\n<h3>\u30b7\u30fc\u30f3(Scene)<\/h3>\n<p>\u8868\u73fe\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u5834\u6240\u306e\u3053\u3068\u3067\u3059\u3002\u8981\u306f\u30d6\u30e9\u30a6\u30b6\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<h4>\u30b7\u30fc\u30f3\u3092\u8ffd\u52a0\u3059\u308b<\/h4>\n<pre class=\"lang:default decode:true\">const scene = new THREE.Scene();<\/pre>\n<h3>\u30ab\u30e1\u30e9(Camera)<\/h3>\n<p>\u30b7\u30fc\u30f3\u3092\u30ab\u30e1\u30e9\u3067\u64ae\u3063\u305f\u308a\u5199\u3059\u3053\u3068\u3067\u3059\u3002<\/p>\n<h4>PerspectiveCamera(\u8996\u91ce\u89d2\u3001\u30a2\u30b9\u30da\u30af\u30c8\u6bd4\u3001\u958b\u59cb\u8ddd\u96e2\u3001\u7d42\u4e86\u8ddd\u96e2\uff09<\/h4>\n<p>\u5927\u4f53\u306f\u3053\u308c\u304c\u4f7f\u308f\u308c\u308b\u3002<\/p>\n<h5>\u8996\u91ce\u89d2<\/h5>\n<p>\u30ab\u30e1\u30e9\u306e\u3069\u3053\u304b\u3089\u3069\u3053\u307e\u3067\u3092\u5199\u3059\u306e\u304b\u3002<\/p>\n<h5>\u30a2\u30b9\u30da\u30af\u30c8\u6bd4<\/h5>\n<p>\u753b\u9762\u306e\u6a2a\u5e45\u3068\u7e26\u5e45\u306e\u6bd4\u7387\u306e\u3053\u3068\u3002<\/p>\n<h5>\u958b\u59cb\u8ddd\u96e2\u3001\u7d42\u4e86\u8ddd\u96e2<\/h5>\n<p>\u30ab\u30e1\u30e9\u304c\u5b9f\u969b\u306b\u5199\u3059\u8ddd\u96e2<\/p>\n<pre class=\"lang:default decode:true \">const camera = new THREE.PerspectiveCamera(\r\n    50,\r\n    window.innerWidth \/ window.innerHeight,\r\n    0.1,\r\n    1000\r\n);<\/pre>\n<h3>\u30ec\u30f3\u30c0\u30e9\u30fc(Renderer)<\/h3>\n<p>\u30ab\u30e1\u30e9\u3067\u64ae\u5f71\u3057\u305f\u3082\u306e\u3092\u30d6\u30e9\u30a6\u30b6\u306b\u5199\u305b\u308b\u3088\u3046\u306b\u5909\u63db\u3057\u3066\u304f\u308c\u308b\u3082\u306e\u3002\u30d6\u30e9\u30a6\u30b6\u306b\u5199\u3059\u305f\u3081\u306e\u5909\u63db\u5668\u3002<\/p>\n<h4>WebGL Renderer<\/h4>\n<p>three.js\u3067\u4e00\u822c\u7684\u306b\u4f7f\u308f\u308c\u308b\u30ec\u30f3\u30c0\u30e9\u30fc\u3002<\/p>\n<pre class=\"lang:default decode:true\">\/\/ \u30ec\u30f3\u30c0\u30e9\u30fc\u3092\u8ffd\u52a0\r\nconst renderer = new THREE.WebGL1Renderer();\r\ndocument.body.appendChild(renderer.domElement);<\/pre>\n<h2>\u30b8\u30aa\u30e1\u30c8\u30ea\u30fc<\/h2>\n<p>\u5f62\u72b6\u306e\u9aa8\u683c\u3092\u8868\u3059\u3002<\/p>\n<ul>\n<li>\u7403\u4f53<\/li>\n<li>\u7acb\u65b9\u4f53<\/li>\n<li>\u30c9\u30fc\u30ca\u30c4\u578b\u306e3D\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/li>\n<\/ul>\n<h3>\u8abf\u3079\u65b9<\/h3>\n<p>\u30b8\u30aa\u30e1\u30c8\u30ea\u30fc\u306b\u306f\u305f\u304f\u3055\u3093\u306e\u7a2e\u985e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>three.js\u306e\u516c\u5f0f\u30b5\u30a4\u30c8\u3067\u300cgeometry\u300d\u3068\u691c\u7d22\u3059\u308c\u3070\u3044\u308d\u3093\u306ageometry\u304c\u51fa\u3066\u304d\u307e\u3059\u3002<\/p>\n<h3>\u7a2e\u985e<\/h3>\n<h4>BoxGeometry<\/h4>\n<p>\u76f4\u65b9\u4f53<\/p>\n<h3>\u5b9f\u88c5<\/h3>\n<pre class=\"lang:default decode:true\">const geometry = new THREE.SphereGeometry(\u7403\u4f53\u306e\u534a\u5f84,\u30ef\u30a4\u30c9\u30bb\u30b0\u30e1\u30f3\u30c8\uff08\u7403\u4f53\u306b\u8fd1\u3065\u3051\u308b\u304b\uff09,\u30cf\u30a4\u30c8\u30bb\u30b0\u30e1\u30f3\u30c8(\u7403\u4f53\u306b\u8fd1\u3065\u3051\u308b\u304b));<\/pre>\n<h2>\u30de\u30c6\u30ea\u30a2\u30eb\uff08\u8cea\u611f\uff09<\/h2>\n<p>\u8272\u306a\u3069\u3002<\/p>\n<h3>MeshPhongMaterial<\/h3>\n<p>\u30d5\u30a9\u30f3\u30fb\u30b7\u30a7\u30fc\u30c7\u30a3\u30f3\u30b0\u3068\u8a00\u3046\u3001\u5149\u6ca2\u611f\u306e\u3042\u308b\u8cea\u611f\u3092\u8868\u73fe\u3067\u304d\u308b\u30de\u30c6\u30ea\u30a2\u30eb<\/p>\n<h3>MeshPhysicalMaterial<\/h3>\n<p>\u91d1\u5c5e\u611f\u3092\u8868\u73fe\u3067\u304d\u308b\u3002<\/p>\n<h3>MeshBasicMaterial<\/h3>\n<p>\u5f71\u304c\u3064\u304b\u305a\u5747\u4e00\u306a\u8cea\u611f\u306b\u306a\u308b\u3002<\/p>\n<h3>\u30c6\u30af\u30b9\u30c1\u30e3\u30fc<\/h3>\n<p>\u8cea\u611f\u306b\u753b\u50cf\u3092\u8ffd\u52a0\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3067\u5bfe\u5fdc\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">\/\/ \u30c6\u30af\u30b9\u30c1\u30e3\u30fc\u3092\u8ffd\u52a0\r\nconst texture = new THREE.TextureLoader().load(\".\/textures\/earth.jpg\");\r\n\/\/ \u30de\u30c6\u30ea\u30a2\u30eb\u3092\u4f5c\u6210\r\nconst material = new THREE.MeshPhysicalMaterial({map:texture});<\/pre>\n<p>MeshPhysicalMaterial<\/p>\n<div>\n<div>\u91d1\u5c5e\u88fd\u3092\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/div>\n<\/div>\n<pre class=\"lang:default decode:true \">const material = new THREE.MeshPhysicalMaterial({color: \"#000\"});<\/pre>\n<h2>\u30e1\u30c3\u30b7\u30e5\u5316<\/h2>\n<p>\u30b8\u30aa\u30e1\u30c8\u30ea\u30fc\uff08\u9aa8\u683c\uff09\u3068\u30de\u30c6\u30ea\u30a2\u30eb\uff08\u8272\uff09\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u3082\u306e\u3002<\/p>\n<pre class=\"lang:default decode:true \">\/\/ \u30e1\u30c3\u30b7\u30e5\u306e\u4f5c\u6210\r\nconst mesh = new THREE.Mesh(geometry,material);\r\n\/\/ \u30b7\u30fc\u30f3\u306b\u30e1\u30c3\u30b7\u30e5\u3092\u8ffd\u52a0\r\nscene.add(mesh);<\/pre>\n<h2>\u5e73\u884c\u5149\u6e90\u3092\u8ffd\u52a0<\/h2>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3060\u3068\u7403\u4f53\u304c\u6697\u3044\u307e\u307e\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u51e6\u7406\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u5149\u3092\u5f53\u3066\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\/\/ \u5e73\u884c\u5149\u6e90\u3092\u8ffd\u52a0\r\nconst directionalLight = new THREE.DirectionalLight(0xffffff,2);\r\n\/\/ \u30b7\u30fc\u30f3\u306b\u5e73\u884c\u5149\u6e90\u3092\u8ffd\u52a0\r\nscene.add(directionalLight);<\/pre>\n<h2>\u30dd\u30a4\u30f3\u30c8\u5149\u6e90\u3092\u8ffd\u52a0<\/h2>\n<pre class=\"lang:default decode:true\">\/\/ \u30dd\u30a4\u30f3\u30c8\u5149\u6e90\u3092\u8ffd\u52a0\r\nconst pointLight = new THREE.PointLight(0xffffff,1);\r\npointLight.position.set(200,200,200);\r\n\/\/ \u30b7\u30fc\u30f3\u306b\u30dd\u30a4\u30f3\u30c8\u5149\u6e90\u3092\u8ffd\u52a0\r\nscene.add(pointLight);<\/pre>\n<h3>\u30dd\u30a4\u30f3\u30c8\u5149\u6e90\u306e\u5834\u6240<\/h3>\n<pre class=\"lang:default decode:true\">\/\/ \u30dd\u30a4\u30f3\u30c8\u5149\u6e90\u304c\u3069\u3053\u306b\u3042\u308b\u304b\r\nconst pointLightHelper = new THREE.PointLightHelper(pointLight,100);\r\nscene.add(pointLightHelper);<\/pre>\n<h2>\u30de\u30a6\u30b9\u64cd\u4f5c\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002(\u30ab\u30e1\u30e9\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc)<\/h2>\n<p>\u30de\u30a6\u30b9\u3067\u7403\u4f53\u3092\u56de\u8ee2\u3001\u30db\u30a4\u30fc\u30eb\u64cd\u4f5c\u3067\u9060\u8fd1\u64cd\u4f5c\u304c\u3067\u304d\u308b\u3002<\/p>\n<h4>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u4f5c\u6210<\/h4>\n<pre class=\"lang:default decode:true\">\/\/ \u30ab\u30e1\u30e9\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u6210\r\nconst controls = new THREE.OrbitControls(camera, canvasElement);<\/pre>\n<h4>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u5236\u5fa1<\/h4>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3060\u3068\u6a5f\u68b0\u7684\u306a\u52d5\u304d\u3067\u3059\u304c\u3001\u3053\u308c\u3089\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u6ed1\u3089\u304b\u306b\u52d5\u304f\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \"> \/\/ \u6ed1\u3089\u304b\u306b\u30ab\u30e1\u30e9\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u5236\u5fa1\u3059\u308b\r\ncontrols.enableDamping = true;\r\ncontrols.dampingFactor = 0.2;<\/pre>\n<h3>OrbitControls<\/h3>\n<p>Three.js\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u672c\u4f53\u306b\u306f\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001Three.js\u3068\u306f\u5225\u9014\u8aad\u307f\u8fbc\u3080\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>\u5ea7\u6a19\u8ef8<\/h2>\n<h3>X\u8ef8<\/h3>\n<p>\u8d64\u3044\u7dda\u3001\u6a2a<\/p>\n<h3>Y\u8ef8<\/h3>\n<p>\u7dd1\u306e\u7dda\u3001\u7e26<\/p>\n<h3>Z\u8ef8<\/h3>\n<p>\u9752\u3044\u7dda\u3001\u5965\u884c\u304d<\/p>\n","protected":false},"excerpt":{"rendered":"Three.js\u3068\u306f\uff1f three\u3068\u306f3D\u306e3\u3092\u82f1\u8a9e\u306b\u3057\u305f\u3082\u306e\u3067\u3059\u3002WebGL\u306e\u6280\u8853\u3092\u4f7f\u3063\u3066Web\u30d6\u30e9\u30a6\u30b6\u4e0a\u30673D\u8868\u73fe\u3092\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002 \u30ea\u30ea\u30fc\u30b9\u30ce\u30fc\u30c8 \u30d0\u30fc\u30b8\u30e7\u30f3 \u30ea\u30ea\u30fc\u30b9\u5e74\u6708 \u5099\u8003 83 2016\/12 WebG [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17075"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17075"}],"version-history":[{"count":19,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17075\/revisions"}],"predecessor-version":[{"id":20267,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17075\/revisions\/20267"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17075"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}