Published
Edited
Dec 6, 2018
1 star
Insert cell
Insert cell
{
const renderer = new THREE.WebGLRenderer({antialias: true});
const controls = new THREE.OrbitControls(camera, renderer.domElement);
invalidation.then(() => (controls.dispose(), renderer.dispose()));
renderer.setSize(width, height);
renderer.setPixelRatio(devicePixelRatio);
controls.addEventListener("change", () => renderer.render(scene, camera));
renderer.render(scene, camera);
return renderer.domElement;
}
Insert cell
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
scene.add(line);
scene.add(spheres);
scene.add(lights);
return scene;
}
Insert cell
Insert cell
line = {
const geometry = new THREE.Geometry();
const material = new THREE.LineBasicMaterial({ color: 0xff00ff });
POINT_DATA.forEach(point => {
geometry.vertices.push(new THREE.Vector3(point[0], point[1], point[2]));
});
return new THREE.Line(geometry, material);
}
Insert cell
Insert cell
spheres = {
const sphereGeometry = new THREE.SphereBufferGeometry(1, 32, 32);
const sphereMaterial = new THREE.MeshPhongMaterial({
color: 0x156289,
emissive: 0x072534,
side: THREE.DoubleSide,
flatShading: true
});
return POINT_DATA.reduce((acc, point) => {
const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
sphere.position.set(point[0], point[1], point[2]);
return acc.add(sphere);
}, new THREE.Group());
}
Insert cell
Insert cell
lights = {
return LIGHT_DATA.reduce((acc, d) => {
const pl = new THREE.PointLight(0xffffff, 1, 0);
pl.position.set(d[0], d[1], d[2]);
return acc.add(pl);
}, new THREE.Group());
}
Insert cell
Insert cell
camera = {
const fov = 45;
const aspect = width / height;
const near = 1;
const far = 1000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(0, 0, 50)
camera.lookAt(new THREE.Vector3(...POINT_DATA[1]));
return camera;
}
Insert cell
Insert cell
height = 600
Insert cell
Insert cell
THREE = {
const THREE = window.THREE = await require("three@0.99.0/build/three.min.js");
await require("three@0.99.0/examples/js/controls/OrbitControls.js").catch(() => {});
return THREE;
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more