Published
Edited
Oct 4, 2020
Insert cell
Insert cell
{
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(width, height);
renderer.setPixelRatio(devicePixelRatio);
camera.position.x = 0;
camera.position.y = 0;
camera.position.z = 0;
try {
var counter = 1;
while (counter < 300) {
counter += 1;
const t = Date.now();
const { x, y, z } = vertex(
[t / 100, Math.sin(t / 5000) * 45],
radius * 1.75
);

// camera.position.x = x;
// camera.position.y = y;
// camera.position.z = z;
camera.lookAt(new THREE.Vector3(x, y, z)); //scene.position);
renderer.render(scene, camera);
yield renderer.domElement;
}
} finally {
renderer.dispose();
}
}
Insert cell
Insert cell
Insert cell
function vertex([longitude, latitude], radius) {
const lambda = longitude * Math.PI / 180;
const phi = latitude * Math.PI / 180;
return new THREE.Vector3(
radius * Math.cos(phi) * Math.cos(lambda),
radius * Math.sin(phi),
-radius * Math.cos(phi) * Math.sin(lambda)
);
}
Insert cell
Insert cell
function wireframe(multilinestring, radius, material) {
const geometry = new THREE.Geometry();
for (const P of multilinestring.coordinates) {
for (let p0, p1 = vertex(P[0], radius), i = 1; i < P.length; ++i) {
geometry.vertices.push(p0 = p1, p1 = vertex(P[i], radius));
}
}
return new THREE.LineSegments(geometry, material);
}
Insert cell
Insert cell
land = {
const response = await fetch("https://cdn.jsdelivr.net/npm/world-atlas@2/land-50m.json");
const topology = await response.json();
const mesh = topojson.mesh(topology, topology.objects.land);
return wireframe(mesh, radius, new THREE.LineBasicMaterial({color: 0xff0000}));
}
Insert cell
graticule = {
const mesh = graticule10();
return wireframe(mesh, radius, new THREE.LineBasicMaterial({color: 0xaaaaaa}));
}
Insert cell
sphere = {
var texture = new THREE.Texture(image);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
// texture.repeat.set(fitTo, fitTo);
texture.needsUpdate = true;

var geometry = new THREE.SphereGeometry(radius, radius, radius * 2);
var material = new THREE.MeshBasicMaterial({
//color: new THREE.Color('rgba(200,200,200,0.03)'),
wireframe: true,
map: texture
});
var sphere = new THREE.Mesh(geometry, material);
return sphere;
}
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color('#222');
//scene.add(graticule);
scene.add(sphere);
scene.add(land);
return scene;
}
Insert cell
camera = {
const fov = 170;
const aspect = width / height;
const near = 1;
const far = 1000;
return new THREE.PerspectiveCamera(fov, aspect, near, far);
}
Insert cell
radius = 200
Insert cell
height = width
Insert cell
function graticule10() { // See https://github.com/d3/d3-geo/issues/95
return {
type: "MultiLineString",
coordinates: [].concat(
Array.from(
range(-180, 180, 10),
x => x % 90 ? meridian(x, -80, 80) : meridian(x, -90, 90)
),
Array.from(
range(-80, 80 + 1e-6, 10),
y => parallel(y, -180, 180)
)
)
};
}
Insert cell
function meridian(x, y0, y1, dy = 2.5) {
return Array.from(range(y0, y1 + 1e-6, dy), y => [x, y]);
}
Insert cell
function parallel(y, x0, x1, dx = 2.5) {
return Array.from(range(x0, x1 + 1e-6, dx), x => [x, y]);
}
Insert cell
function* range(start, stop, step) {
for (let i = 0, v = start; v < stop; v = start + (++i * step)) {
yield v;
}
}
Insert cell
image = await FileAttachment("bathymetry_diffuse_4k.jpg").image()
Insert cell
topojson = require("topojson-client@3")
Insert cell
THREE = require("three@0.99.0/build/three.min.js")
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