Prompt specification
Build or customize the Three.js 3D scene "House inside a block outline" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: House inside a block outline
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/house-inside-a-block-outline-x1329
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts nested geographic regions. Place a house within a clearly outlined street block. Add separate labels for building and block, keeping the smaller object's boundary distinct from the larger area's boundary. Voxel style.
Working Three.js Starter (house-inside-a-block-outline-x1329):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Nested Regions — Voxel Map</title>
<style>
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#070b14;
font-family:"Segoe UI",Inter,system-ui,-apple-system,sans-serif;color:#e8eefc}
#app{position:fixed;inset:0}
canvas{display:block}
/* ---- projected labels ---- */
#overlay{position:fixed;inset:0;pointer-events:none;z-index:5}
#leaders{position:absolute;inset:0;width:100%;height:100%;overflow:visible}
.lbl{position:absolute;transform:translate(-50%,-100%);
display:flex;align-items:center;gap:8px;padding:7px 11px 7px 9px;
background:rgba(9,13,24,.82);border:1px solid rgba(255,255,255,.10);
border-left:3px solid var(--c);border-radius:7px;
backdrop-filter:blur(6px);white-space:nowrap;
box-shadow:0 8px 22px rgba(0,0,0,.45)}
.lbl i{width:9px;height:9px;border-radius:50%;background:var(--c);
box-shadow:0 0 10px var(--c);flex:0 0 auto}
.lbl b{display:block;font-size:12px;letter-spacing:.10em;font-weight:700}
.lbl span{display:block;font-size:10px;color:#93a3c2;letter-spacing:.05em;margin-top:2px}
/* ---- hud ---- */
#hud{position:fixed;inset:0;pointer-events:none;z-index:6}
.card{position:absolute;background:rgba(9,13,24,.74);border:1px solid rgba(255,255,255,.08);
border-radius:12px;backdrop-filter:blur(8px);padding:13px 15px;
box-shadow:0 12px 34px rgba(0,0,0,.45)}
#title{top:16px;left:16px;max-width:290px}
#title h1{margin:0;font-size:15px;letter-spacing:.14em}
#title p{margin:6px 0 0;font-size:11.5px;line-height:1.5;color:#94a4c3}
#legend{bottom:16px;left:16px}
#legend h2{margin:0 0 9px;font-size:10px;letter-spacing:.2em;color:#7f8fb0}
#legend ul{list-style:none;margin:0;padding:0;font-size:11.5px}
#legend li{display:flex;align-items:center;gap:9px;padding:3.5px 0;color:#dbe4f7}
#legend li em{font-style:normal;color:#8494b3;font-size:10px;margin-left:auto;padding-left:14px}
#legend u{width:14px;height:14px;border-radius:3px;display:inline-block}
#tools{top:16px;right:16px;display:flex;gap:7px;padding:9px}
#tools button{pointer-events:auto;cursor:pointer;font:inherit;font-size:11px;letter-spacing:.08em;
color:#cbd8f0;background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.13);
border-radius:7px;padding:7px 11px;transition:.18s}
#tools button:hover{background:rgba(255,255,255,.13);color:#fff;border-color:rgba(255,255,255,.3)}
#hint{bottom:16px;right:16px;font-size:10.5px;color:#7f8fb0;letter-spacing:.06em}
@media (max-width:760px){#title{max-width:210px}#legend{display:none}}
</style>
</head>
<body>
<div id="app"></div>
<div id="overlay"><svg id="leaders"></svg></div>
<div id="hud">
<div class="card" id="title">
<h1>NESTED REGIONS</h1>
<p>A voxel county → district → street block → house, each with its own
boundary colour so the building outline stays distinct from the block outline.</p>
</div>
<div class="card" id="legend">
<h2>ADMINISTRATIVE LEVELS</h2>
<ul>
<li><u style="background:#3b4cca"></u>Vale County <em>region</em></li>
<li><u style="background:#f6a623"></u>Old Town District <em>district</em></li>
<li><u style="background:#f5f7ff"></u>Maple Street Block <em>block</em></li>
<li><u style="background:#ff3ea5"></u>Brick House <em>building</em></li>
</ul>
</div>
<div class="card" id="tools">
<button data-f="region">COUNTY</button>
<button data-f="block">BLOCK</button>
<button data-f="house">HOUSE</button>
</div>
<div class="card" id="hint">drag = orbit · wheel = zoom</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================================================
VOXEL WORLD DEFINITION
============================================================ */
const W = 64, H = 64;
const wx = i => i - W/2 + 0.5;
const wz = j => j - H/2 + 0.5;
const DISTRICT = {i0:11, i1:37, j0:17, j1:39};
const BLOCK = {i0:15, i1:27, j0:22, j1:32}; // curb included
const HOUSE = {i0:17, i1:22, j0:24, j1:29}; // building footprint
const C = {
grass: [0x74c158, 0x6ab34f, 0x82ca62, 0x60a647],
garden: 0x4f9c45,
road: 0x323947, road2: 0x2b313d,
walk: 0x99a3b4,
conc: 0xb9c1cf,
curb: 0xf6f8ff,
dash: 0xf0c04a,
brick: [0xc0563a, 0xb74f34, 0xc85c3e],
roof: [0xe0653f, 0xcf4a2c, 0x9e3320],
door: 0x6d4128,
glass: 0x8fd6ff,
trunk: 0x6a4a30, leaf: [0x3f9a3f, 0x54b34a, 0x398c39],
car: [0xe74c3c, 0x3a8fd8, 0xecc13a, 0xe6eaee],
tire: 0x15181f
};
let seed = 20240917;
const rnd = () => (seed = (seed*1664525 + 1013904223) >>> 0) / 4294967296;
function terrainH(i,j){
const x=i-W/2, z=j-H/2;
let h = 1 + Math.round(Math.cos(x*0.27)*Math.sin(z*0.23)*0.9);
const d = Math.hypot(x,z);
if (d > 24) h += Math.floor((d-24)/9);
return Math.max(1, Math.min(4, h));
}
const inRect = (i,j,r) => i>=r.i0 && i<=r.i1 && j>=r.j0 && j<=r.j1;
// Chebyshev-ish distance from a rect (0 = inside)
function rectDist(i,j,r){
const dx = Math.max(r.i0-i, 0, i-r.i1);
const dz = Math.max(r.j0-j, 0, j-r.j1);
return Math.max(dx,dz);
}
const isPerimeter = (i,j,r) =>
inRect(i,j,r) && (i===r.i0 || i===r.i1 || j===r.j0 || j===r.j1);
/* ============================================================
SCENE
============================================================ */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080d18);
scene.fog = new THREE.Fog(0x080d18, 120, 300);
const camera = new THREE.PerspectiveCamera(48, innerWidth/innerHeight, 0.5, 600);
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.getElementById('app').appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xbcd6ff, 0x1d2740, 0.85));
const sun = new THREE.DirectionalLight(0xfff0d2, 1.7);
sun.position.set(48, 62, 26);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
const sc = sun.shadow.camera;
sc.left=-58; sc.right=58; sc.top=58; sc.bottom=-58; sc.near=1; sc.far=220;
sun.shadow.bias = -0.0006; sun.shadow.normalBias = 0.02;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x5f83ff, 0.42);
fill.position.set(-40, 26, -34);
scene.add(fill);
/* base plate + grid */
const plate = new THREE.Mesh(
new THREE.PlaneGeometry(520,520),
new THREE.MeshBasicMaterial({color:0x0b1120})
);
plate.rotation.x = -Math.PI/2; plate.position.y = -0.08;
scene.add(plate);
const grid = new THREE.GridHelper(360, 60, 0x1d2b45, 0x141d31);
grid.position.y = -0.05; scene.add(grid);
/* ============================================================
VOXEL BUCKETS
============================================================ */
const G = {
ground: [], region: [], district: [], curb: [],
house: [], foliage: [], cars: [], marks: []
};
const box = (L,x,y,z,sx,sy,sz,c)=>L.push({x,y,z,sx,sy,sz,c});
for (let i=0;i<W;i++) for (let j=0;j<H;j++){
const inD = inRect(i,j,DISTRICT);
const inB = inRect(i,j,BLOCK);
const inH = inRect(i,j,HOUSE);
const dB = rectDist(i,j,BLOCK);
const dH = rectDist(i,j,HOUSE);
const h = inD ? 2 : terrainH(i,j);
let color;
if (inD){
if (inB) color = isPerimeter(i,j,BLOCK) ? C.curb : C.conc;
else if (dB === 1) color = ((i+j)&1) ? C.road : C.road2;
else if (dB === 2) color = C.walk;
else color = C.garden;
} else {
color = C.grass[(i*7+j*3)%C.grass.length];
}
box(G.ground, wx(i), h/2, wz(j), 1, h, 1, color);
/* lane dashes (centre of the road ring) */
if (inD && dB===1 && ((i+j)%4===0))
box(G.marks, wx(i), h+0.045, wz(j), 0.95, 0.09, 0.95, C.dash);
/* house property ring — the BUILDING boundary (magenta) */
if (inD && dH===1 && !inH)
box(G.house, wx(i), h+0.13, wz(j), 0.94, 0.26, 0.94, 0xff3ea5);
/* block curb — the BLOCK boundary (white) */
if (inD && inB && isPerimeter(i,j,BLOCK))
box(G.curb, wx(i), h+0.35, wz(j), 0.98, 0.70, 0.98, C.curb);
}
/* county (region) boundary wall -------------------------------- */
for (let i=0;i<W;i++) for (let j=0;j<H;j++){
const edge = (i===0||i===W-1||j===0||j===H-1);
if (!edge) continue;
const corner = (i===0||i===W-1) && (j===0||j===H-1);
const t = terrainH(i,j);
const hh = t + 3 + (corner ? 1.6 : 0);
box(G.region, wx(i), hh/2, wz(j), 1, hh, 1, corner ? 0x4f63e8 : 0x3b4cca);
}
/* district boundary wall --------------------------------------- */
for (let i=DISTRICT.i0;i<=DISTRICT.i1;i++) for (let j=DISTRICT.j0;j<=DISTRICT.j1;j++){
if (!isPerimeter(i,j,DISTRICT)) continue;
const corner = (i===DISTRICT.i0||i===DISTRICT.i1) && (j===DISTRICT.j0||j===DISTRICT.j1);
const hh = 3 + (corner ? 1.3 : 0);
box(G.district, wx(i), 2 + hh/2, wz(j), 1, hh, 1, corner ? 0xffc04d : 0xf6a623);
}
/* the house -------------------------------------------------------- */
const HTOP = 5; // wall top (ground=2)
for (let i=HOUSE.i0;i<=HOUSE.i1;i++) for (let j=HOUSE.j0;j<=HOUSE.j1;j++){
const edge = isPerimeter(i,j,HOUSE);
if (!edge) continue;
const isDoor = (i===19 && j===29);
const isWin = (i===18||i===21) && j===29;
const c = isDoor ? C.door : C.brick[(i+j)%C.brick.length];
const hh = isDoor ? 2.3 : 3;
box(G.house, wx(i), 2 + hh/2, wz(j), 1, hh, 1, c);
if (isWin){
box(G.house, wx(i), 3.55, wz(j)+0.53, 0.62, 0.95, 0.14, C.glass);
}
}
/* back window */
box(G.house, wx(19), 3.55, wz(24)-0.53, 0.62, 0.95, 0.14, C.glass);
/* doorstep */
box(G.house, wx(19), 2.06, wz(30)-0.15, 0.9, 0.14, 0.5, 0x8d97a8);
/* stepped roof: 5x5 eave -> 3x3 -> 1x1 */
for (let i=HOUSE.i0;i<=HOUSE.i1;i++) for (let j=HOUSE.j0;j<=HOUSE.j1;j++)
box(G.house, wx(i), HTOP+0.5, wz(j), 1, 1, 1, C.roof[0]);
for (let i=HOUSE.i0+1;i<=HOUSE.i1-1;i++) for (let j=HOUSE.j0+1;j<=HOUSE.j1-1;j++)
box(G.house, wx(i), HTOP+1.5, wz(j), 1, 1, 1, C.roof[1]);
box(G.house, wx(19.5), HTOP+2.5, wz(26.5), 1, 1, 1, C.roof[2]);
/* chimney */
box(G.house, wx(21), HTOP+3.4, wz(25), 0.5, 1.8, 0.5, 0x6d6a66);
/* trees ----------------------------------------------------------- */
function tree(x,z,g){
const s = 0.8 + rnd()*0.5;
box(G.foliage, x, g+0.55*s, z, 0.36*s, 1.1*s, 0.36*s, C.trunk);
box(G.foliage, x, g+1.55*s, z, 1.5*s, 1.3*s, 1.5*s, C.leaf[(rnd()*3)|0]);
box(G.foliage, x, g+2.35*s, z, 0.95*s, 0.95*s, 0.95*s, C.leaf[(rnd()*3)|0]);
}
for (let n=0;n<520;n++){
const i = 2+((rnd()*(W-4))|0), j = 2+((rnd()*(H-4))|0);
if (rectDist(i,j,BLOCK) <= 3) continue;
if (rectDist(i,j,DISTRICT) <= 1) continue;
const g = inRect(i,j,DISTRICT) ? 2 : terrainH(i,j);
if (rnd() < 0.55) tree(wx(i), wz(j), g);
}
/* cars on the block's ring road ---------------------------------- */
function car(x,z,axis,col){
const w = axis==='z' ? 0.78 : 1.55, d = axis==='z' ? 1.55 : 0.78;
const dx = axis==='z' ? 0 : 1, dz = axis==='z' ? 1 : 0;
box(G.cars, x, 2.34, z, w, 0.46, d, col);
box(G.cars, x - dx*0.18, 2.78, z - dz*0.18, w*0.8, 0.42, d*0.5, C.glass);
for (const s of [-1,1]){
box(G.cars, x + dz*s*0.78, 2.12, z + dx*s*0.78, dx?0.42:0.3, 0.34, dz?0.42:0.3, C.tire);
box(G.cars, x - dz*s*0.78, 2.12, z - dx*s*0.78, dx?0.42:0.3, 0.34, dz?0.42:0.3, C.tire);
}
}
car(wx(BLOCK.i0-1), wz(24.4), 'z', C.car[0]);
car(wx(BLOCK.i0-1), wz(28.6), 'z', C.car[1]);
car(wx(BLOCK.i1+1), wz(25.6), 'z', C.car[3]);
car(wx(BLOCK.i1+1), wz(29.4), 'z', C.car[2]);
car(wx(18.4), wz(BLOCK.j0-1), 'x', C.car[1]);
car(wx(24.6), wz(BLOCK.j0-1), 'x', C.car[0]);
car(wx(19.2), wz(BLOCK.j1+1), 'x', C.car[2]);
car(wx(25.4), wz(BLOCK.j1+1), 'x', C.car[3]);
/* ============================================================
BUILD INSTANCED MESHES
============================================================ */
const geo = new THREE.BoxGeometry(1,1,1);
const dummy = new THREE.Object3D(), tmpC = new THREE.Color();
function build(list, mat){
const m = new THREE.InstancedMesh(geo, mat, list.length);
list.forEach((b,i)=>{
dummy.position.set(b.x,b.y,b.z);
dummy.scale.set(b.sx,b.sy,b.sz);
dummy.updateMatrix();
m.setMatrixAt(i, dummy.matrix);
tmpC.set(b.c); m.setColorAt(i, tmpC);
});
m.instanceMatrix.needsUpdate = true;
if (m.instanceColor) m.instanceColor.needsUpdate = true;
m.castShadow = true; m.receiveShadow = true; m.frustumCulled = false;
scene.add(m);
return m;
}
const lam = (emissive=0x000000) => new THREE.MeshLambertMaterial({color:0xffffff, emissive});
build(G.ground, lam(0x000000));
build(G.region, lam(0x101a44));
build(G.district, lam(0x3a2400));
build(G.curb, lam(0x39445e));
build(G.house, lam(0x000000));
build(G.foliage, lam(0x000000));
build(G.cars, lam(0x000000));
build(G.marks, lam(0x3a2e00));
/* ============================================================
LABELS (hand-rolled projection, no addons)
============================================================ */
const V = (x,y,z)=>new THREE.Vector3(x,y,z);
const labelDefs = [
{title:'VALE COUNTY', sub:'Region · 64 × 64 voxels', c:'#3b4cca',
anchor:V(-31.5, 6.0, -31.5), lift:V(-31.5, 13.5, -31.5), dx:-130, dy:-24},
{title:'OLD TOWN DISTRICT', sub:'District · inside the county', c:'#f6a623',
anchor:V(-20.5, 5.5, -14.5), lift:V(-20.5, 12.0, -14.5), dx:120, dy:-30},
{title:'MAPLE STREET BLOCK', sub:'Block · white curb boundary', c:'#f6f8ff',
anchor:V(-16.5, 2.8, -9.5), lift:V(-16.5, 8.5, -9.5), dx:104, dy:26},
{title:'BRICK HOUSE', sub:'Building · magenta footprint', c:'#ff3ea5',
anchor:V(-12.0, 2.3, -5.0), lift:V(-12.0, 13.0, -5.0), dx:44, dy:-52}
];
const svg = document.getElementById('leaders');
const NS = 'http://www.w3.org/2000/svg';
labelDefs.forEach(L=>{
const el = document.createElement('div');
el.className = 'lbl';
el.style.setProperty('--c', L.c);
el.innerHTML = `<i></i><div><b>${L.title}</b><span>${L.sub}</span></div>`;
document.getElementById('overlay').appendChild(el);
L.el = el;
L.line = document.createElementNS(NS,'line');
L.line.setAttribute('stroke', L.c);
L.line.setAttribute('stroke-width','1.4');
L.line.setAttribute('stroke-opacity','.65');
L.line.setAttribute('stroke-dasharray','4 4');
svg.appendChild(L.line);
L.dot = document.createElementNS(NS,'circle');
L.dot.setAttribute('r','3.4');
L.dot.setAttribute('fill', L.c);
svg.appendChild(L.dot);
});
function project(v){
const p = v.clone().project(camera);
return {x:(p.x*0.5+0.5)*innerWidth, y:(-p.y*0.5+0.5)*innerHeight, z:p.z};
}
function updateLabels(){
labelDefs.forEach(L=>{
const a = project(L.anchor), b = project(L.lift);
const vis = a.z < 1 && b.z < 1;
L.el.style.display = vis ? 'flex' : 'none';
L.line.style.display = vis ? '' : 'none';
L.dot.style.display = vis ? '' : 'none';
if (!vis) return;
const bx = b.x + L.dx, by = b.y + L.dy;
L.el.style.left = bx+'px';
L.el.style.top = by+'px';
L.line.setAttribute('x1',a.x); L.line.setAttribute('y1',a.y);
L.line.setAttribute('x2',bx); L.line.setAttribute('y2',by);
L.dot.setAttribute('cx',a.x); L.dot.setAttribute('cy',a.y);
});
}
/* ============================================================
CAMERA CONTROLS (implemented inline)
============================================================ */
const cam = {theta:-2.35, phi:0.92, radius:96, target:new THREE.Vector3(0,1.5,0)};
let goal = null, touched = false;
addEventListener('pointerdown', e=>{
if (e.target.closest('#tools')) return;
drag.x = e.clientX; drag.y = e.clientY; drag.on = true; goal = null;
});
const drag = {on:false, x:0, y:0};
addEventListener('pointermove', e=>{
if (!drag.on) return;
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
drag.x = e.clientX; drag.y = e.clientY;
touched = true;
cam.theta -= dx*0.006;
cam.phi = Math.max(0.18, Math.min(1.46, cam.phi + dy*0.005));
});
addEventListener('pointerup', ()=> drag.on = false);
addEventListener('wheel', e=>{
e.preventDefault();
touched = true; goal = null;
cam.radius = Math.max(26, Math.min(190, cam.radius * (1 + e.deltaY*0.0011)));
}, {passive:false});
document.querySelectorAll('#tools button').forEach(b=>{
b.addEventListener('click', ()=>{
touched = true;
const f = b.dataset.f;
if (f === 'region') goal = {theta:cam.theta, phi:0.92, radius:96, target:new THREE.Vector3(0,1.5,0)};
if (f === 'block') goal = {theta:-2.35, phi:0.86, radius:46, target:new THREE.Vector3(-14,2,-6)};
if (f === 'house') goal = {theta:-2.55, phi:1.02, radius:22, target:new THREE.Vector3(-12,4,-5)};
});
});
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
/* ============================================================
LOOP
============================================================ */
const clock = new THREE.Clock();
function animate(){
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (goal){
let dt2 = ((goal.theta - cam.theta + Math.PI) % (Math.PI*2)) - Math.PI;
cam.theta += dt2*0.08;
cam.phi += (goal.phi - cam.phi)*0.08;
cam.radius+= (goal.radius - cam.radius)*0.08;
cam.target.lerp(goal.target, 0.08);
if (Math.abs(dt2) < 0.002 && Math.abs(goal.radius-cam.radius) < 0.2 &&
cam.target.distanceTo(goal.target) < 0.2) goal = null;
} else if (!touched){
cam.theta += 0.0014; // gentle idle orbit
}
const sp = Math.sin(cam.phi), cp = Math.cos(cam.phi);
camera.position.set(
cam.target.x + cam.radius*sp*Math.sin(cam.theta),
cam.target.y + cam.radius*cp,
cam.target.z + cam.radius*sp*Math.cos(cam.theta)
);
camera.lookAt(cam.target);
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```