Code

Three.js

Hello Cube

Beginner The Three.js hello-world — a scene, PerspectiveCamera, WebGLRenderer, and a rotating cube with MeshNormalMaterial. Three.js Docs

import * as THREE from 'three';

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x1a1a2e);

const camera = new THREE.PerspectiveCamera(60, W / H, 0.1, 100);
camera.position.set(0, 0, 3);

const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setSize(W, H);

const geometry = new THREE.BoxGeometry(1.2, 1.2, 1.2);
const material = new THREE.MeshNormalMaterial();
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

function animate() {
  cube.rotation.x += 0.008;
  cube.rotation.y += 0.012;
  renderer.render(scene, camera);
  requestAnimationFrame(animate);
}
animate();