🧊three.js
Also known as Three.js, ThreeJS, three
A free JavaScript library for 3D on the web. It makes WebGL much easier to use.
Think of it like
It is like toy blocks for 3D on the web. You snap a scene, a camera and a light together.
Example
Noah adds a spinning 3D logo to his landing page with about 20 lines of three.js.
Why it matters
Designers and web coders can add real 3D to pages. They do not need to learn hard graphics code.
Definition
Example code
javascript
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 100);
const cube = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshNormalMaterial());
scene.add(cube);
camera.position.z = 3;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
renderer.render(scene, camera);Common mistake
Key takeaways
- 1On top of WebGL. Hides the hard parts.
- 2Scene, camera, light. The building blocks.
- 3Keep models light. For fast pages.