{"id":3137,"date":"2013-11-11T16:48:55","date_gmt":"2013-11-11T07:48:55","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3137"},"modified":"2017-02-01T11:06:18","modified_gmt":"2017-02-01T02:06:18","slug":"post-3137","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3137","title":{"rendered":"D3.js\u3067\u8aad\u307f\u8fbc\u3093\u3060geoJSON\u30c7\u30fc\u30bf\u3092three.js\u3092\u4f7f\u3063\u30663D\u8868\u793a\u3059\u308b\u3002"},"content":{"rendered":"<p>\u30de\u30a6\u30b9\u3067\u30b0\u30ea\u30b0\u30ea\u3067\u304d\u308b\u3002<br \/>\n<span class=\"removed_link\" title=\"http:\/\/shimz.me\/example\/threejs\/02\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/d3threejsjapan.jpg\" alt=\"d3threejsjapan\" width=\"590\" height=\"474\" class=\"aligncenter size-full wp-image-3138\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/d3threejsjapan.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/d3threejsjapan-187x150.jpg 187w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/span><\/p>\n<p><span class=\"removed_link\" title=\"http:\/\/shimz.me\/example\/threejs\/02\/\">example<\/span><\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p><a href=\"https:\/\/github.com\/asutherland\/d3-threeD\">d3-threeD<\/a>\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\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, 300);\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, 1, 1).normalize();\n\tscene.add(light);\n\t\n\t\/\/\u76ee\u5370\u7528\u306e\u30ad\u30e5\u30fc\u30d6\u3092\u8ffd\u52a0\n\tvar geometry = new THREE.CubeGeometry(20, 20, 20);\n\tvar material = new THREE.MeshLambertMaterial({color:0x0000ff})\n\tmesh = new THREE.Mesh(geometry, material);\n\tscene.add(mesh);\n\t\n\t\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\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\n\t    var material = new THREE.MeshPhongMaterial({\n\t\tcolor: Math.floor(Math.random() * 0xFFFFFF), \n\t\topacity:1\n\t    });\n\t    \n\t    var shape3d = countries[i].mesh.extrude({\n\t\tamount: 20,\n\t\tbevelEnabled: false\n\t    });\n\t    var toAdd = new THREE.Mesh(shape3d, material);\n\t    toAdd.rotation.x = 60;\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}\n<\/pre>\n<p>\u8868\u793a\u4f4d\u7f6e\u306e\u8abf\u6574\u3068\u304b\u304c\u7d50\u69cb\u9762\u5012\u3067\u3057\u305f\u3002<br \/>\namount\u3067\u7121\u7406\u3084\u308a\u539a\u307f\u3092\u4ed8\u3051\u3066\u3044\u308b\u306e\u3067\u3001\u3042\u3093\u307e\u308a\u7dba\u9e97\u306b\u8868\u793a\u3067\u304d\u3066\u307e\u305b\u3093\u3002<br \/>\n\u3061\u3083\u3093\u3068\u4f7f\u3044\u3053\u306a\u3059\u306b\u306f\u3001Three.js\u3092\u52c9\u5f37\u3057\u306a\u3044\u3068\u306a\u3089\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30de\u30a6\u30b9\u3067\u30b0\u30ea\u30b0\u30ea\u3067\u304d\u308b\u3002 example \u30b5\u30f3\u30d7\u30eb&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3138,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,53],"tags":[],"class_list":["post-3137","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\/3137","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=3137"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3137\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/3138"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}