Published
Edited
Jan 2, 2022
Fork of Three.js
1 fork
4 stars
Insert cell
Insert cell
renderer.domElement
Insert cell
// Continuously updates
{
while (true) {
containerGroup.rotation.z += 0.01;
renderer.render(scene, camera);
yield null;
}
}
Insert cell
height = 600
Insert cell
md`# Data and Grid`
Insert cell
grid = (n, gridSize) => {
const max = gridSize - 1;
const snapped = Math.round(n * max) / max;
return snapped * 2 - 1;
};
Insert cell
Insert cell
Insert cell
Insert cell
containerGroup = {
const material = new THREE.MeshNormalMaterial();
const geometry = new THREE.BoxGeometry(1, 1, 1);

const containerGroup = new THREE.Group()

const meshes = Array.from(new Array(chunks)).map(() => {
const material = new THREE.MeshStandardMaterial({
metalness: 0,
roughness: 1,
wireframe: true
//? 因其通过randonMesh生成,所以此处color相当于 default,真正设置还是在randomMesh里
})
const mesh = new THREE.Mesh(geometry, material)
randomMesh(mesh)

return mesh
})
meshes.forEach(m => containerGroup.add(m))
return containerGroup;
}
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
scene.add(containerGroup);
// scene.add(threeForceData)
return scene;
}
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(2, 2, -2)
camera.lookAt(new THREE.Vector3(0, 0, 0));
return camera;
}
Insert cell
renderer = {
const renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(width, height);
renderer.setPixelRatio(devicePixelRatio);
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.addEventListener("change", () => renderer.render(scene, camera));
invalidation.then(() => (controls.dispose(), renderer.dispose()));
// const tbControls = new THREE.OrbitControls(camera, renderer.domElement);
// (function animate() { // IIFE
// threeForceData.tickFrame();

// // Frame cycle
// tbControls.update();
// renderer.render(scene, camera);
// requestAnimationFrame(animate);
// })();
return renderer;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
random = CSUtils.random
Insert cell
Insert cell
gsap = gs.gsap
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