Published
Edited
Jul 27, 2019
6 forks
53 stars
Also listed in…
3D
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Fetch dem data as 256 x 256 array
// Mt. Nabewari, Japan
dem = fetchTile({z: 13, x: 7262, y: 3232})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// TODO: 0.2: handcrafted
heightScale = d => 0.2 * (d-elevRange[0])/(elevRange[1]-elevRange[0]);
Insert cell
// Scale xy cooridinates to [0, 1]
xyContour = scaleContour(contours, 1/256)
Insert cell
// 3D lineString meshes of contours
contourLineStrings = {
const lines = [];
xyContour.forEach(polygon => {
// Set color based on elevation
const lineColor = color(polygon.value);
// 2D to 3D: be carefull about right-handed / lef-handed system
polygon.coordinates.forEach(rings => {
rings.forEach(points => {
const points3 = points.map(([x, y]) => [y-0.5, x-0.5, heightScale(polygon.value)]);
lines.push(lineString(points3, lineColor));
});
});
});
return lines;
}
Insert cell
// Create lineString mesh with given coordinates and color
function lineString(points, color) {
const material = new THREE.LineBasicMaterial({color: color, blending: THREE.AdditiveBlending});
const geometry = new THREE.Geometry();
points.forEach(p => {
geometry.vertices.push(new THREE.Vector3(...p));
});

return new THREE.Line(geometry, material);
}
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x333333);
contourLineStrings.forEach(l => scene.add(l));
return scene;
}
Insert cell
camera = {
const fov = 45;
const aspect = width / height;
const near = 0.01;
const far = 1000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(0.5, 0.5, 0.5);
camera.up.set(0, 0, 1);
camera.lookAt(new THREE.Vector3(0, 0, 0));
return camera;
}
Insert cell
height = 500
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more