TEST 027
Turn an idea into a 3D city with Claude and a free Google project
Short answer
Give Claude a short written brief for a scene and Three Live's rules page, ask for a Three Live scene, then paste the code it writes into the Three Live playground and press Compile & View. On an iPhone, Quick Look opens the same model in AR. The city in the reel took three passes: Claude fixed its first version after Three Live's checker rejected it.
Three Live is a free, open-source project in Google's GitHub organisation (its README says it is not an officially supported Google product, and it is in beta). It does not write anything itself: you, or Claude, write a short Three.js script, and Three Live turns it into a real 3D model you can spin, zoom and open in AR.
The brief behind the city
This is the part of the written brief Claude worked from, word for word:
Propose three candidate objects a stranger would not believe came from one sentence and now stands on a real desk in AR, each feasible as a procedural Three.js script inside the sandbox limits (think: hundreds of instanced parts, emissive windows, layered detail; e.g. a night city block with lit windows, a mechanical orrery, a spiral library). For each: one line of appeal, the sentence a user would type, feasibility risk. Pick one. Write the real scene.js and compile it with the CLI.Claude picked the city and summed it up in one line, which became the first comment of its code:
A tiny city block at night on a stone slab: glass towers with lit windows, streetlights, a little park, and one landmark tower with an emerald crown.Set it up (no install, no account)
- Open the Three Live playground on a computer or phone.
- Select all the code in the "Three.js code to compile" box and paste the city's code below in its place.
- Press Compile & View. The city appears and spins.
- Drag to orbit, pinch or scroll to zoom.
- On an iPhone, tap Quick Look (.usdz), then AR, and point at the floor or a table. Or press Save .glb or Save .usdz to keep the model.
- To build your own: give Claude your idea plus the rules page and ask for a Three Live scene, then paste what it writes into step 2. Your city will differ: Claude writes new code each time.
The city's code
It uses a fixed random seed, so it rebuilds this exact city.
// Request (one sentence): "A tiny city block at night on a stone slab: glass towers with
// lit windows, streetlights, a little park, and one landmark tower with an emerald crown."
// Real-world size: 36 cm slab, so in AR it stands on a table at true scale.
// deterministic random (mulberry32) so every compile gives the same city
let seed = 20261109;
const rnd = () => { seed |= 0; seed = (seed + 0x6D2B79F5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
const SLAB = 0.36, SLAB_H = 0.035, TOP = SLAB_H;
const m = new THREE.Matrix4();
const box = new THREE.BoxGeometry(1, 1, 1);
// write the matrix elements directly (scale + translate, no rotation): fastest path in the sandbox
const put = (im, i, x, y, z, sx, sy, sz) => { const el = m.elements; el[0] = sx; el[5] = sy; el[10] = sz; el[12] = x; el[13] = y; el[14] = z; im.setMatrixAt(i, m); };
// --- slab: dark stone with an emerald inlay around the top edge
const slab = new THREE.Mesh(new THREE.BoxGeometry(SLAB, SLAB_H, SLAB),
new THREE.MeshPhysicalMaterial({ color: 0x141416, roughness: 0.45, clearcoat: 0.6, clearcoatRoughness: 0.3 }));
slab.name = 'slab'; slab.position.y = SLAB_H / 2; scene.add(slab);
const inlay = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: 0x10B981, emissive: 0x10B981, emissiveIntensity: 2.2 }), 4);
inlay.name = 'emerald-inlay';
const e = SLAB / 2 - 0.006;
put(inlay, 0, 0, TOP + 0.0006, e, SLAB - 0.012, 0.0012, 0.002);
put(inlay, 1, 0, TOP + 0.0006, -e, SLAB - 0.012, 0.0012, 0.002);
put(inlay, 2, e, TOP + 0.0006, 0, 0.002, 0.0012, SLAB - 0.012);
put(inlay, 3, -e, TOP + 0.0006, 0, 0.002, 0.0012, SLAB - 0.012);
scene.add(inlay);
// --- streets (asphalt) and 4 x 4 raised city blocks (concrete)
const asphalt = new THREE.Mesh(new THREE.BoxGeometry(0.32, 0.002, 0.32), new THREE.MeshStandardMaterial({ color: 0x1c1d21, roughness: 0.85 }));
asphalt.name = 'streets'; asphalt.position.y = TOP + 0.001; scene.add(asphalt);
const BLOCK = 0.062, PITCH = 0.08, centers = [-0.12, -0.04, 0.04, 0.12];
const blocks = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: 0x3a3b40, roughness: 0.9 }), 16);
blocks.name = 'city-blocks';
let bi = 0;
for (const bx of centers) for (const bz of centers) put(blocks, bi++, bx, TOP + 0.003, bz, BLOCK, 0.002, BLOCK);
scene.add(blocks);
const G = TOP + 0.004; // ground level on top of a block
// lane markings: dashed cream lines down the middle of each street
const dashes = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: 0xEDE6DA, roughness: 0.6, emissive: 0xEDE6DA, emissiveIntensity: 0.15 }), 6 * 16);
dashes.name = 'lane-markings';
let di = 0;
for (const s of [-0.08, 0, 0.08]) for (let k = 0; k < 16; k++) {
const p = -0.15 + k * 0.02;
put(dashes, di++, s, TOP + 0.0021, p, 0.0008, 0.0002, 0.008);
put(dashes, di++, p, TOP + 0.0021, s, 0.008, 0.0002, 0.0008);
}
scene.add(dashes);
// --- towers: glass bodies, setback tiers, lit windows
const PARK = '1,2', LANDMARK = '1,1';
const towers = [];
for (let ix = 0; ix < 4; ix++) for (let iz = 0; iz < 4; iz++) {
const key = ix + ',' + iz;
if (key === PARK) continue;
const cx = centers[ix], cz = centers[iz];
if (key === LANDMARK) { towers.push({ x: cx, z: cz, w: 0.034, d: 0.034, h: 0.25, landmark: true }); continue; }
const centre = (ix === 1 || ix === 2) && (iz === 1 || iz === 2);
const lots = rnd() < 0.35 ? [[0, 0, 0.05, 0.05]] : [[-0.0155, -0.0155, 0.024, 0.024], [0.0155, -0.0155, 0.024, 0.024], [-0.0155, 0.0155, 0.024, 0.024], [0.0155, 0.0155, 0.024, 0.024]];
for (const [ox, oz, w, d] of lots) {
const base = centre ? 0.09 : 0.035;
const h = base + rnd() * (centre ? 0.11 : 0.08) + (w > 0.03 ? 0.02 : 0);
towers.push({ x: cx + ox, z: cz + oz, w: w * (0.86 + rnd() * 0.1), d: d * (0.86 + rnd() * 0.1), h });
}
}
// bodies: body + optional setback tier on tall towers
const tiers = [];
for (const t of towers) {
if (t.h > 0.12) {
const lower = t.h * (0.62 + rnd() * 0.12);
tiers.push({ x: t.x, z: t.z, w: t.w, d: t.d, y0: G, h: lower });
tiers.push({ x: t.x, z: t.z, w: t.w * 0.72, d: t.d * 0.72, y0: G + lower, h: t.h - lower });
} else tiers.push({ x: t.x, z: t.z, w: t.w, d: t.d, y0: G, h: t.h });
}
const glass = new THREE.MeshPhysicalMaterial({ color: 0x1b1d22, roughness: 0.22, metalness: 0.35, clearcoat: 1, clearcoatRoughness: 0.12 });
const bodies = new THREE.InstancedMesh(box, glass, tiers.length);
bodies.name = 'tower-bodies';
tiers.forEach((b, i) => put(bodies, i, b.x, b.y0 + b.h / 2, b.z, b.w, b.h, b.d));
scene.add(bodies);
// windows: a grid on every face of every tier; about 55% lit, in three warmths
const FLOOR = 0.0075, COL = 0.0062, WW = 0.0036, WH = 0.0042, WD = 0.0007;
const lit = [[], [], []];
for (const b of tiers) {
const floors = Math.floor((b.h - 0.004) / FLOOR);
for (const face of [0, 1, 2, 3]) {
const span = face < 2 ? b.w : b.d;
const cols = Math.max(1, Math.floor((span - 0.003) / COL));
for (let f = 0; f < floors; f++) {
const y = b.y0 + 0.004 + f * FLOOR + WH / 2;
for (let c = 0; c < cols; c++) {
if (rnd() > 0.55) continue;
const u = (c - (cols - 1) / 2) * COL;
const r = rnd(), bucket = r < 0.6 ? 0 : r < 0.9 ? 1 : 2;
if (face === 0) lit[bucket].push([b.x + u, y, b.z + b.d / 2 + WD / 2, WW, WH, WD]);
else if (face === 1) lit[bucket].push([b.x + u, y, b.z - b.d / 2 - WD / 2, WW, WH, WD]);
else if (face === 2) lit[bucket].push([b.x + b.w / 2 + WD / 2, y, b.z + u, WD, WH, WW]);
else lit[bucket].push([b.x - b.w / 2 - WD / 2, y, b.z + u, WD, WH, WW]);
}
}
}
}
const warmths = [[0xF2C98A, 1.6, 'windows-warm'], [0xEDE6DA, 2.4, 'windows-cream'], [0xFFE2B0, 3.2, 'windows-bright']];
lit.forEach((list, k) => {
const [col, inten, name] = warmths[k];
const w = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: col, emissive: col, emissiveIntensity: inten, roughness: 0.4 }), list.length);
w.name = name;
list.forEach((p, i) => put(w, i, p[0], p[1], p[2], p[3], p[4], p[5]));
scene.add(w);
});
// rooftop plant: tanks and units on the shorter towers
const roofBits = [];
for (const b of tiers) {
const isTop = !tiers.some((o) => o !== b && o.x === b.x && o.z === b.z && o.y0 > b.y0);
if (!isTop || b.w < 0.02) continue;
roofBits.push([b.x + (rnd() - 0.5) * b.w * 0.4, b.y0 + b.h, b.z + (rnd() - 0.5) * b.d * 0.4, b.w * 0.32, 0.006, b.d * 0.26]);
}
const units = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: 0x55565c, roughness: 0.7 }), roofBits.length);
units.name = 'rooftop-units';
roofBits.forEach((p, i) => put(units, i, p[0], p[1] + p[4] / 2, p[2], p[3], p[4], p[5]));
scene.add(units);
// --- landmark: emerald crown, spire and beacon on the tallest tower
const L = towers.find((t) => t.landmark);
const crown = new THREE.Mesh(new THREE.CylinderGeometry(0.0085, 0.0125, 0.03, 4, 1), new THREE.MeshStandardMaterial({ color: 0x10B981, emissive: 0x10B981, emissiveIntensity: 2.6, roughness: 0.3 }));
crown.name = 'landmark-crown'; crown.rotation.y = Math.PI / 4; crown.position.set(L.x, G + L.h + 0.015, L.z); scene.add(crown);
const spire = new THREE.Mesh(new THREE.CylinderGeometry(0.0006, 0.0016, 0.05, 8), new THREE.MeshStandardMaterial({ color: 0xc9ccd2, metalness: 0.6, roughness: 0.25 }));
spire.name = 'landmark-spire'; spire.position.set(L.x, G + L.h + 0.055, L.z); scene.add(spire);
const beacon = new THREE.Mesh(new THREE.SphereGeometry(0.0022, 12, 8), new THREE.MeshStandardMaterial({ color: 0x10B981, emissive: 0x10B981, emissiveIntensity: 4 }));
beacon.name = 'landmark-beacon'; beacon.position.set(L.x, G + L.h + 0.081, L.z); scene.add(beacon);
// --- park: lawn, paths, trees
const [px, pz] = [centers[1], centers[2]];
const lawn = new THREE.Mesh(new THREE.BoxGeometry(BLOCK - 0.004, 0.0015, BLOCK - 0.004), new THREE.MeshStandardMaterial({ color: 0x1d3328, roughness: 0.95 }));
lawn.name = 'park-lawn'; lawn.position.set(px, G + 0.0008, pz); scene.add(lawn);
const path = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: 0x6b6a66, roughness: 0.9 }), 2);
path.name = 'park-paths';
put(path, 0, px, G + 0.0017, pz, BLOCK - 0.004, 0.0004, 0.004);
put(path, 1, px, G + 0.0017, pz, 0.004, 0.0004, BLOCK - 0.004);
scene.add(path);
const treeSpots = [];
for (let i = 0; i < 18; i++) {
const x = (rnd() - 0.5) * (BLOCK - 0.012), z = (rnd() - 0.5) * (BLOCK - 0.012);
if (Math.abs(x) < 0.005 || Math.abs(z) < 0.005) continue;
treeSpots.push([px + x, pz + z, 0.6 + rnd() * 0.5]);
}
const trunks = new THREE.InstancedMesh(new THREE.CylinderGeometry(0.0006, 0.0008, 1, 6), new THREE.MeshStandardMaterial({ color: 0x3b2f27, roughness: 0.9 }), treeSpots.length);
const canopies = new THREE.InstancedMesh(new THREE.SphereGeometry(1, 10, 8), new THREE.MeshStandardMaterial({ color: 0x24402f, roughness: 0.85 }), treeSpots.length);
trunks.name = 'tree-trunks'; canopies.name = 'tree-canopies';
treeSpots.forEach(([x, z, s], i) => {
put(trunks, i, x, G + 0.004 * s, z, 1, 0.008 * s, 1);
put(canopies, i, x, G + 0.0105 * s, z, 0.0052 * s, 0.0058 * s, 0.0052 * s);
});
scene.add(trunks, canopies);
// --- streetlights along every street, and cars
const lamps = [];
for (const s of [-0.16, -0.08, 0, 0.08, 0.16]) for (let k = 0; k < 4; k++) {
const p = centers[k];
lamps.push([s + 0.0035, p - 0.025]); lamps.push([p + 0.025, s - 0.0035]);
}
const poles = new THREE.InstancedMesh(new THREE.CylinderGeometry(0.0004, 0.0005, 1, 6), new THREE.MeshStandardMaterial({ color: 0x8a8c92, metalness: 0.5, roughness: 0.4 }), lamps.length);
const bulbs = new THREE.InstancedMesh(new THREE.SphereGeometry(1, 8, 6), new THREE.MeshStandardMaterial({ color: 0xffe9c4, emissive: 0xFFD9A0, emissiveIntensity: 5 }), lamps.length);
poles.name = 'streetlight-poles'; bulbs.name = 'streetlight-bulbs';
lamps.forEach(([x, z], i) => { put(poles, i, x, TOP + 0.002 + 0.006, z, 1, 0.012, 1); put(bulbs, i, x, TOP + 0.0145, z, 0.0013, 0.0013, 0.0013); });
scene.add(poles, bulbs);
const carSpots = [];
for (const s of [-0.08, 0, 0.08]) for (let k = 0; k < 6; k++) {
const p = -0.14 + rnd() * 0.28, lane = rnd() < 0.5 ? -0.004 : 0.004;
if (rnd() < 0.5) carSpots.push([s + lane, p, 0]); else carSpots.push([p, s + lane, 1]);
}
const cars = new THREE.InstancedMesh(box, new THREE.MeshPhysicalMaterial({ color: 0xEDE6DA, roughness: 0.3, clearcoat: 1 }), carSpots.length);
const heads = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: 0xffffff, emissive: 0xFFF1D6, emissiveIntensity: 4 }), carSpots.length);
cars.name = 'cars'; heads.name = 'car-headlights';
const tints = [0xEDE6DA, 0x55575d, 0x2a2c31, 0x8f9096];
carSpots.forEach(([x, z, along], i) => {
if (along === 0) { put(cars, i, x, TOP + 0.0035, z, 0.0034, 0.0026, 0.0072); put(heads, i, x, TOP + 0.0034, z + 0.0037, 0.0028, 0.0008, 0.0004); }
else { put(cars, i, x, TOP + 0.0035, z, 0.0072, 0.0026, 0.0034); put(heads, i, x + 0.0037, TOP + 0.0034, z, 0.0004, 0.0008, 0.0028); }
cars.setColorAt(i, new THREE.Color(tints[i % 4]));
});
scene.add(cars, heads);
// glowing parts carry their light colour as base colour too: GLB export keeps base colour, USDZ keeps emissive
// --- light for viewers without an environment: moonlight key, cool ambient
const moon = new THREE.DirectionalLight(0xdfe6ff, 1.4); moon.position.set(-0.6, 1.2, 0.8); scene.add(moon);
scene.add(new THREE.AmbientLight(0x8890a0, 0.35));
const glow = new THREE.PointLight(0xffd9a0, 0.6, 0.6); glow.position.set(0, 0.12, 0); scene.add(glow);The catch
- The AR view is a still model: the windows glow, the cars do not move.
- Scenes have limits (about 1,000 meshes and 100,000 vertices); code that loads images from the web or uses its own animation loop shows a plain grey shape with no error.
- The playground's share link for this city is too long for a QR code; open it on the phone directly.