{"id":3139,"date":"2013-11-12T09:31:35","date_gmt":"2013-11-12T00:31:35","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3139"},"modified":"2017-02-01T11:06:27","modified_gmt":"2017-02-01T02:06:27","slug":"post-3139","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3139","title":{"rendered":"\u3010D3.js&#038;Three.js\u3011\u5404\u90fd\u9053\u5e9c\u770c\u306e\u4eba\u53e3\u306b\u5408\u308f\u305b\u3066\u9ad8\u3055\u3092\u5909\u3048\u3066\u307f\u305f\uff083D\u5730\u56f3\uff09"},"content":{"rendered":"<p><span class=\"removed_link\" title=\"http:\/\/shimz.me\/example\/threejs\/03\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/d3threejsjapan2.jpg\" alt=\"d3threejsjapan2\" width=\"590\" height=\"327\" class=\"aligncenter size-full wp-image-3140\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/d3threejsjapan2.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/d3threejsjapan2-271x150.jpg 271w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/span><\/p>\n<p><span class=\"removed_link\" title=\"http:\/\/shimz.me\/example\/threejs\/03\/\">example<\/span><\/p>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3137\">\u6628\u65e5\u306e\u8a18\u4e8b<\/a>\u306e\u7d9a\u304d\u3067\u3059\u3002<br \/>\n\u5404\u90fd\u9053\u5e9c\u770c\u306e\u4eba\u53e3\u30c7\u30fc\u30bf\u3092\u5143\u306bMesh\u306e\u539a\u307f\u3092\u5909\u3048\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u4eba\u53e3\u306e\u591a\u3044\u770c\u307b\u3069\u9ad8\u304f\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js decode:true \" >d3.json(&quot;japan.geojson&quot;, function(json) {\n    d3main(json);\n});\n\n\nfunction d3main(json) {\n    var container;\n    var camera, scene, renderer;\n    var mesh;\n    \n    initScene();\n\n\n    function initScene() {\n\tcontainer = document.createElement('div');\n\tdocument.body.appendChild(container);\n\t\n\t\/\/\u30b7\u30fc\u30f3\u306e\u8ffd\u52a0\n\tscene = new THREE.Scene();\n\t\n\t\/\/\u30ab\u30e1\u30e9\u306e\u8a2d\u5b9a\n\tcamera = new THREE.PerspectiveCamera(70, window.innerWidth \/ window.innerHeight, 1, 10000);\n\tcamera.position.set(0, 0, 200);\n\t\n\tcontrols = new THREE.TrackballControls( camera );\n\t\n\tscene.add(camera);\n\t\n\t\/\/\u30e9\u30a4\u30c6\u30a3\u30f3\u30b0\u306e\u8a2d\u5b9a\n\tvar light = new THREE.DirectionalLight(0xffffff, 2);\n\tlight.position.set(1, -4, 1).normalize();\n\tscene.add(light);\n\t\n\t\/\/geojson\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\n\tvar geodata = json.features;\n\t\n\t\/\/\u6295\u5f71\u6cd5\u6307\u5b9a\n\tvar mercator = d3.geo.equirectangular();\n\t\n\t\/\/path\u5909\u63db\u95a2\u6570\u751f\u6210\n\tvar path = d3.geo.path().projection(mercator);\n\t\n\t\/\/\u8868\u793a\u4f4d\u7f6e\u8abf\u6574\n\tvar translate = mercator.translate();\n\ttranslate[0] = -2200;\n\ttranslate[1] = 550;\n\tmercator.translate(translate);\n\t\n\t\/\/\u30b9\u30b1\u30fc\u30eb\u6307\u5b9a\n\tmercator.scale(900);\n\t    \n\tvar max = d3.max(geodata, function(d){ return +d.properties['jinkou_\u4eba\u53e3']})\n\t\n\tvar colorScale = d3.scale.linear().domain([0, max]).range([&quot;#00cc00&quot;, &quot;#cc0000&quot;]);\n\tvar amountScale = d3.scale.linear().domain([0, max]).range([0, 60]);\n\t\n\t\/\/geoJSON\u2192svg path\u2192three.js mesh\u5909\u63db    \n\tvar countries = [];\n\tfor (i = 0 ; i &lt; geodata.length ; i++) {\n\t    var geoFeature = geodata[i];\n\t    var properties = geoFeature.properties;\n\t    var feature = path(geoFeature);\n\t\n\t    \/\/svg\u30d1\u30b9\u3092three.js\u306emesh\u306b\u5909\u63db\n\t    var gmesh = transformSVGPathExposed(feature);\n\t\n\t    for (j = 0 ; j &lt; gmesh.length ; j++) {\n\t\tcountries.push({&quot;data&quot;: properties, &quot;mesh&quot;: gmesh[j]});\n\t    }\n\t}\n\t\n\t\/\/mesh\u8ffd\u52a0\n\tfor (i = 0 ; i &lt; countries.length ; i++) {\n\t    var color = colorScale(countries[i].data['jinkou_\u4eba\u53e3']);\n\t    var material = new THREE.MeshPhongMaterial({\n\t\tcolor: color,\n\t\topacity:0.9\n\t    });\n\t    \n\t    var amount = ~~(amountScale(countries[i].data['jinkou_\u4eba\u53e3']));\n\t    \n\t    var shape3d = countries[i].mesh.extrude({\n\t\tamount: amount,\n\t\tbevelEnabled: false\n\t    });\n\t    var toAdd = new THREE.Mesh(shape3d, material);\n\t   toAdd.rotation.x = 60;\n\t    toAdd.position.z = - ~~(60 - amount);\n\t    scene.add(toAdd);\n\t}\n\t\n\t\n\t\/\/\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\n\trenderer = new THREE.WebGLRenderer();\n\trenderer.setSize(window.innerWidth, window.innerHeight);\n\t\n\tcontainer.appendChild(renderer.domElement);\n\trenderer.render(scene, camera);\n\t    \n\tanimate();\n    }\n\n  \n    function animate() {\n\trequestAnimationFrame( animate ); \n\trenderer.render( scene, camera ); \n\tcontrols.update();\n    }  \n  \n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example \u6628\u65e5\u306e\u8a18\u4e8b\u306e\u7d9a\u304d\u3067\u3059\u3002 \u5404\u90fd\u9053\u5e9c\u770c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3140,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,53],"tags":[],"class_list":["post-3139","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","category-three-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=3139"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3139\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/3140"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}