Get started with three.js CDN

MIT licensed

Three.js: Open-source library for interactive 3D web graphics.

Tags:
  • 3d
  • WebGL

Stable version

Copied!

How to start using three.js CDN


// Import Three.js library
const Three = require('three');

// Create scene, camera, and renderer
const scene = new Three.Scene();
const camera = new Three.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new Three.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// Create a box geometry
const geometry = new Three.BoxGeometry(1, 1, 1);

// Create a material for the box
const material = new Three.MeshBasicMaterial({ color: 0x00ff00 });

// Create a mesh using the geometry and material
const cube = new Three.Mesh(geometry, material);
scene.add(cube);

// Position the camera
camera.position.z = 5;

// Animation loop
function animate() {
  requestAnimationFrame(animate);
  cube.rotation.x += 0.01;
  cube.rotation.y += 0.01;
  renderer.render(scene, camera);
}
animate();
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions