Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
A basic Three.js program that renders a spinning cube in a browser canvas.
# threejs/demo/main.js
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('canvas') });
renderer.setSize(window.innerWidth, window.innerHeight);
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();Three.js is a popular open-source 3D JavaScript library that simplifies creating, displaying, and animating 3D graphics in web browsers using WebGL. It provides abstractions for cameras, lights, materials, geometries, and scene management, making 3D web development accessible and efficient.
Origin & Creator
Three.js was created by Ricardo Cabello (mr.doob) in 2010 and has since evolved with contributions from a global community of developers.
Industrial Note
Three.js is widely used in web-based games, AR/VR, data visualization, product configurators, architectural walkthroughs, and interactive marketing websites, providing powerful 3D experiences without requiring native apps.