/
index.html
78 lines (66 loc) · 2.56 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<head>
<style> body { margin: 0; } </style>
<script type="importmap">{ "imports": {
"three": "//unpkg.com/three/build/three.module.js",
"three/addons/": "//unpkg.com/three/examples/jsm/"
}}</script>
<script type="module">
import * as THREE from 'three';
window.THREE = { ...THREE };
</script>
<script src="//unpkg.com/three-conic-polygon-geometry" defer></script>
<!-- <script src="../../dist/three-conic-polygon-geometry.js" defer></script>-->
</head>
<body>
<div id="viz"></div>
<script type="module">
import { TrackballControls } from 'three/addons/controls/TrackballControls.js';
fetch('../geojson/ne_110m_admin_0_countries.geojson').then(res => res.json()).then(countries =>
{
const materials = [
new THREE.MeshBasicMaterial({ side: THREE.DoubleSide, color: 'green', opacity: 0.1, transparent: true }), // side material
new THREE.MeshBasicMaterial({ side: THREE.DoubleSide, color: 'red', opacity: 0.7, transparent: true }), // bottom cap material
new THREE.MeshBasicMaterial({ color: 'red', opacity: 0.7, transparent: true, wireframe: true }) // top cap material
];
const polygonMeshes = [];
countries.features.forEach(({ properties, geometry }) => {
const polygons = geometry.type === 'Polygon' ? [geometry.coordinates] : geometry.coordinates;
const alt = 50;
polygons.forEach(coords => {
polygonMeshes.push(
new THREE.Mesh(
new THREE.ConicPolygonGeometry(coords, alt / 10, alt, true, true, true, 1),
materials
)
);
});
});
// Setup renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('viz').appendChild(renderer.domElement);
// Setup scene
const scene = new THREE.Scene();
polygonMeshes.forEach(mesh => scene.add(mesh));
scene.add(new THREE.AmbientLight(0xbbbbbb));
scene.add(new THREE.DirectionalLight(0xffffff, 0.6));
// Setup camera
const camera = new THREE.PerspectiveCamera();
camera.aspect = window.innerWidth/ window.innerHeight;
camera.updateProjectionMatrix();
camera.position.z = 200;
// Add camera controls
const tbControls = new TrackballControls(camera, renderer.domElement);
tbControls.minDistance = 1;
tbControls.rotateSpeed = 5;
tbControls.zoomSpeed = 0.8;
// Kick-off renderer
(function animate() { // IIFE
// Frame cycle
tbControls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
})();
});
</script>
</body>