The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
// Hello world: a living room lit by the afternoon sun through a window, the sky, and a floor lamp.
import * as THREE from "three";
export default function hello() {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x87b8eb);
const sun = new THREE.DirectionalLight(0xffffff, 3);
sun.position.set(87.0, 46.9, -15.3); // elevation 28, azimuth 100 degrees
scene.add(sun);
scene.add(new THREE.HemisphereLight(0xffffff, 0x8d8d8d, 3));
const lamp = new THREE.PointLight(0xffc880, 3);
lamp.position.set(-2.6, 1.6, -2.5);
scene.add(lamp);
const plaster = new THREE.MeshStandardMaterial({ color: 0xd9d4cc, roughness: 0.92 });
const oak = new THREE.MeshStandardMaterial({ color: 0x8c6239, roughness: 0.55 });
const fabric = new THREE.MeshStandardMaterial({ color: 0x2e4a7a, roughness: 0.95 });
const ceramic = new THREE.MeshStandardMaterial({ color: 0xf2efe8, roughness: 0.15 });
const brass = new THREE.MeshStandardMaterial({ color: new THREE.Color().setRGB(0.91, 0.78, 0.42), metalness: 1, roughness: 0.3 });
const lampShade = new THREE.MeshStandardMaterial({ color: 0xfff1dc, emissive: 0xffc880, emissiveIntensity: 1, roughness: 0.9, side: THREE.DoubleSide });
const add = (mesh, x, y, z) => (mesh.position.set(x, y, z), scene.add(mesh));
const box = (w, h, d, x, y, z, mat) => add(new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat), x, y, z);
// 6 x 3 x 6 m room, 0.3 m walls; a 2.2 x 1.6 m window in the +X wall (sill 0.8 m)
box(6.6, 0.3, 6.6, 0, -0.15, 0, oak);
box(6.6, 0.3, 6.6, 0, 3.15, 0, plaster);
box(6.6, 3, 0.3, 0, 1.5, -3.15, plaster);
box(6.6, 3, 0.3, 0, 1.5, 3.15, plaster);
box(0.3, 3, 6, -3.15, 1.5, 0, plaster);
box(0.3, 3, 1.3, 3.15, 1.5, -2.35, plaster);
box(0.3, 3, 2.5, 3.15, 1.5, 1.75, plaster);
box(0.3, 0.8, 2.2, 3.15, 0.4, -0.6, plaster);
box(0.3, 0.6, 2.2, 3.15, 2.7, -0.6, plaster);
// sofa, table, vase, floor lamp
box(2.2, 0.45, 0.9, -1.4, 0.225, -2.2, fabric);
box(2.2, 0.5, 0.25, -1.4, 0.7, -2.55, fabric);
box(1.2, 0.06, 0.7, 0.2, 0.45, -0.9, oak);
for (const [x, z] of [[-0.3, -1.15], [0.7, -1.15], [-0.3, -0.65], [0.7, -0.65]]) box(0.05, 0.42, 0.05, x, 0.21, z, oak);
add(new THREE.Mesh(new THREE.SphereGeometry(0.16, 64, 48), ceramic), 0, 0.64, -0.9);
add(new THREE.Mesh(new THREE.CylinderGeometry(0.02, 0.02, 1.5, 24), brass), -2.6, 0.75, -2.5);
add(new THREE.Mesh(new THREE.CylinderGeometry(0.16, 0.22, 0.3, 48, 1, true), lampShade), -2.6, 1.6, -2.5);
const camera = new THREE.PerspectiveCamera(58, 16 / 9, 0.05, 200);
camera.position.set(-2.3, 1.45, 2.4);
camera.lookAt(1.0, 0.9, -1.2);
return { scene, camera };
}