Prompt specification
Build or customize the Three.js 3D scene "Type case with reusable letter blocks" 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: Type case with reusable letter blocks
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/type-case-with-reusable-letter-blocks-x2513
Scene Description Prompt:
A voxel movable-type case with mirrored reusable letter blocks and an empty composing slot. One HTML file using Three.js from cdnjs.
Working Three.js Starter (type-case-with-reusable-letter-blocks-x2513):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<title>Voxel Movable Type — mirrored sorts & an empty composing slot</title>
<style>
:root{
--cream:#efe3ca; --amber:#ffb454; --ink:#0d1014; --dim:#9a8f7c;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#0d1014;
font-family:"Iowan Old Style","Palatino Linotype",Georgia,serif;color:var(--cream)}
#app{position:fixed;inset:0}
canvas{display:block;touch-action:none}
.hud{position:fixed;inset:0;pointer-events:none;z-index:5}
.panel{
position:absolute;padding:14px 18px;border:1px solid rgba(239,227,202,.18);
background:rgba(12,14,18,.62);backdrop-filter:blur(6px);border-radius:3px;
box-shadow:0 10px 30px rgba(0,0,0,.45);
}
#title{top:22px;left:24px;max-width:330px}
#title h1{margin:0;font-size:21px;letter-spacing:.24em;font-weight:600}
#title .sub{margin:7px 0 0;font-size:12.5px;letter-spacing:.06em;color:var(--dim);font-style:italic}
#title .rule{height:1px;background:linear-gradient(90deg,var(--amber),transparent);margin:11px 0 0;opacity:.8}
#help{bottom:22px;left:24px;max-width:310px;font-size:12px;line-height:1.55;color:var(--dim)}
#help b{color:var(--cream);font-weight:600}
#help .k{font-family:ui-monospace,Menlo,Consolas,monospace;color:var(--amber);
border:1px solid rgba(255,180,84,.35);border-radius:3px;padding:0 4px;font-size:11px}
#help h2{margin:0 0 8px;font-size:11px;letter-spacing:.28em;color:var(--cream);font-weight:600}
#status{bottom:22px;right:24px;min-width:250px;text-align:right;font-size:13px}
#status .k{font-size:10px;letter-spacing:.26em;color:var(--dim);display:block;margin-top:8px}
#status .v{font-family:ui-monospace,Menlo,Consolas,monospace;color:var(--amber);font-size:16px;letter-spacing:.14em}
#tags{position:absolute;inset:0}
.tag{position:absolute;transform:translate(-50%,-50%);white-space:nowrap;
font-size:10.5px;letter-spacing:.3em;color:rgba(239,227,202,.72);
text-shadow:0 2px 8px rgba(0,0,0,.9);padding-bottom:7px}
.tag:after{content:"";position:absolute;left:50%;bottom:0;width:1px;height:6px;
background:linear-gradient(rgba(255,180,84,.7),transparent)}
.tag.amber{color:var(--amber)}
#flash{position:absolute;inset:0;background:radial-gradient(circle at 70% 55%,rgba(255,180,84,.22),transparent 55%);
opacity:0;transition:opacity .35s}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<div class="panel" id="title">
<h1>VOXEL MOVABLE TYPE</h1>
<p class="sub">mirrored reusable sorts · one empty composing slot</p>
<div class="rule"></div>
</div>
<div class="panel" id="help">
<h2>WORKING THE CASE</h2>
<div><span class="k">drag</span> a sort — lift it, drop it in the composing slot</div>
<div><span class="k">A–Z</span> <span class="k">0–9</span> — set type into the slot</div>
<div><span class="k">⌫</span> — return the last sort to the case</div>
<div><span class="k">↵</span> — pull an impression</div>
<div><span class="k">F</span> — turn the held sort (flip its face)</div>
<div style="margin-top:7px;opacity:.75">drag empty space to orbit · right-drag to pan · wheel to zoom</div>
</div>
<div class="panel" id="status">
<span class="k">composing slot</span><span class="v" id="slotStr">(empty)</span>
<span class="k">held</span><span class="v" id="heldStr">—</span>
</div>
<div id="tags">
<div class="tag" id="tagCase">TYPE CASE</div>
<div class="tag amber" id="tagGalley">COMPOSING SLOT</div>
<div class="tag" id="tagPaper">IMPRESSION</div>
</div>
<div id="flash"></div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ────────────────────────────── 5×7 voxel typeface ───────────────────────── */
const FONT = {
A:['.###.','#...#','#...#','#####','#...#','#...#','#...#'],
B:['####.','#...#','#...#','####.','#...#','#...#','####.'],
C:['.###.','#...#','#....','#....','#....','#....','.###.'],
D:['####.','#...#','#...#','#...#','#...#','#...#','####.'],
E:['#####','#....','#....','####.','#....','#....','#####'],
F:['#####','#....','#....','####.','#....','#....','#....'],
G:['.###.','#...#','#....','#.###','#...#','#...#','.###.'],
H:['#...#','#...#','#...#','#####','#...#','#...#','#...#'],
I:['#####','..#..','..#..','..#..','..#..','..#..','#####'],
J:['..###','...#.','...#.','...#.','...#.','#..#.','.##..'],
K:['#...#','#..#.','#.#..','##...','#.#..','#..#.','#...#'],
L:['#....','#....','#....','#....','#....','#....','#####'],
M:['#...#','##.##','#.#.#','#...#','#...#','#...#','#...#'],
N:['#...#','##..#','#.#.#','#..##','#...#','#...#','#...#'],
O:['.###.','#...#','#...#','#...#','#...#','#...#','.###.'],
P:['####.','#...#','#...#','####.','#....','#....','#....'],
Q:['.###.','#...#','#...#','#...#','#.#.#','#..#.','.##.#'],
R:['####.','#...#','#...#','####.','#.#..','#..#.','#...#'],
S:['.####','#....','#....','.###.','....#','....#','####.'],
T:['#####','..#..','..#..','..#..','..#..','..#..','..#..'],
U:['#...#','#...#','#...#','#...#','#...#','#...#','.###.'],
V:['#...#','#...#','#...#','#...#','#...#','.#.#.','..#..'],
W:['#...#','#...#','#...#','#...#','#.#.#','##.##','#...#'],
X:['#...#','#...#','.#.#.','..#..','.#.#.','#...#','#...#'],
Y:['#...#','#...#','.#.#.','..#..','..#..','..#..','..#..'],
Z:['#####','....#','...#.','..#..','.#...','#....','#####'],
'0':['.###.','#...#','#..##','#.#.#','##..#','#...#','.###.'],
'1':['..#..','.##..','..#..','..#..','..#..','..#..','.###.'],
'2':['.###.','#...#','....#','...#.','..#..','.#...','#####'],
'3':['#####','...#.','..#..','...#.','....#','#...#','.###.'],
'4':['...#.','..##.','.#.#.','#..#.','#####','...#.','...#.'],
'5':['#####','#....','####.','....#','....#','#...#','.###.'],
'6':['..##.','.#...','#....','####.','#...#','#...#','.###.'],
'7':['#####','....#','...#.','..#..','.#...','.#...','.#...'],
'8':['.###.','#...#','#...#','.###.','#...#','#...#','.###.'],
'9':['.###.','#...#','#...#','.####','....#','...#.','.##..']
};
/* ────────────────────────────────── renderer ──────────────────────────────── */
const container = document.getElementById('app');
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.02;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x11141a);
scene.fog = new THREE.Fog(0x11141a, 26, 62);
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, 0.1, 200);
/* ───────────────────────────── procedural textures ────────────────────────── */
function makeWood(){
const c=document.createElement('canvas'); c.width=c.height=512; const x=c.getContext('2d');
x.fillStyle='#7a5333'; x.fillRect(0,0,512,512);
for(let i=0;i<2200;i++){
const y=Math.random()*512, w=40+Math.random()*300, h=0.6+Math.random()*2.4;
const t=Math.random();
x.fillStyle = t<.33 ? `rgba(58,36,18,${.05+Math.random()*.16})`
: t<.66 ? `rgba(160,112,66,${.04+Math.random()*.14})`
: `rgba(40,24,12,${.03+Math.random()*.12})`;
x.fillRect(Math.random()*512-w/2, y, w, h);
}
for(let k=0;k<5;k++){
const cx=Math.random()*512, cy=Math.random()*512;
for(let r=8;r>0;r-=1.4){
x.strokeStyle=`rgba(52,32,16,${.05+ (8-r)*.012})`; x.lineWidth=1.6;
x.beginPath(); x.ellipse(cx,cy,r*7,r*3.4,Math.random()*.6,0,Math.PI*2); x.stroke();
}
}
const tex=new THREE.CanvasTexture(c); tex.colorSpace=THREE.SRGBColorSpace;
tex.wrapS=tex.wrapT=THREE.RepeatWrapping; tex.repeat.set(2,2);
return tex;
}
const woodTex = makeWood();
const woodMat = new THREE.MeshStandardMaterial({map:woodTex, roughness:.78, metalness:.04});
/* ─────────────────────────────────── lights ───────────────────────────────── */
scene.add(new THREE.HemisphereLight(0xbcd2e8, 0x2a1c12, .55));
const key = new THREE.DirectionalLight(0xfff1d8, 2.05);
key.position.set(7.5, 13, 8.5); key.castShadow=true;
key.shadow.mapSize.set(2048,2048);
key.shadow.camera.left=-18; key.shadow.camera.right=18;
key.shadow.camera.top=18; key.shadow.camera.bottom=-18;
key.shadow.camera.near=1; key.shadow.camera.far=44; key.shadow.bias=-0.0009;
scene.add(key);
const rim = new THREE.DirectionalLight(0x86a9d6, .75); rim.position.set(-9,7,-10); scene.add(rim);
const warm = new THREE.PointLight(0xffcf95, .55, 34, 2); warm.position.set(-2,5.5,4.5); scene.add(warm);
/* ──────────────────────────────── the table ───────────────────────────────── */
const tableTex = woodTex.clone(); tableTex.needsUpdate=true; tableTex.repeat.set(9,9);
const table = new THREE.Mesh(new THREE.PlaneGeometry(90,90),
new THREE.MeshStandardMaterial({map:tableTex,color:0x6a523a,roughness:.92,metalness:.03}));
table.rotation.x=-Math.PI/2; table.receiveShadow=true; scene.add(table);
/* ─────────────────────── geometry helper: merged voxel boxes ─────────────── */
function boxesToGeometry(items){
const pos=[],nor=[],uv=[];
for(const it of items){
const g=new THREE.BoxGeometry(it.w,it.h,it.d);
if(it.rot) g.rotateY(it.rot);
g.translate(it.x||0,it.y||0,it.z||0);
const ng=g.toNonIndexed();
const p=ng.getAttribute('position'), n=ng.getAttribute('normal'), u=ng.getAttribute('uv');
for(let i=0;i<p.count;i++){
pos.push(p.getX(i),p.getY(i),p.getZ(i));
nor.push(n.getX(i),n.getY(i),n.getZ(i));
uv.push(u.getX(i),u.getY(i),u.getZ(i));
}
ng.dispose(); g.dispose();
}
const geo=new THREE.BufferGeometry();
geo.setAttribute('position',new THREE.Float32BufferAttribute(pos,3));
geo.setAttribute('normal',new THREE.Float32BufferAttribute(nor,3));
geo.setAttribute('uv',new THREE.Float32BufferAttribute(uv,2));
geo.computeBoundingSphere();
return geo;
}
/* ───────────────────────────── the wooden type case ───────────────────────── */
const CASE={x0:-4.8,x1:4.8,z0:-3.6,z1:3.6,cols:5,rows:4,wall:.30,baseH:.20,divH:.55};
const CELL_W=(CASE.x1-CASE.x0)/CASE.cols, CELL_D=(CASE.z1-CASE.z0)/CASE.rows;
const caseGroup=new THREE.Group(); scene.add(caseGroup);
function woodBox(w,h,d,x,y,z,mat){
const m=new THREE.Mesh(new THREE.BoxGeometry(w,h,d), mat||woodMat);
m.position.set(x,y,z); m.castShadow=true; m.receiveShadow=true; caseGroup.add(m); return m;
}
const ow=(CASE.x1-CASE.x0)+CASE.wall*2, od=(CASE.z1-CASE.z0)+CASE.wall*2;
woodBox(ow,CASE.baseH,od,0,CASE.baseH/2,0); // base
const wallH=.95;
woodBox(ow,wallH,CASE.wall,0,CASE.baseH+wallH/2,CASE.z0-CASE.wall/2); // back
woodBox(ow,wallH,CASE.wall,0,CASE.baseH+wallH/2,CASE.z1+CASE.wall/2); // front
woodBox(CASE.wall,wallH,CASE.z1-CASE.z0,CASE.x0-CASE.wall/2,CASE.baseH+wallH/2,0);
woodBox(CASE.wall,wallH,CASE.z1-CASE.z0,CASE.x1+CASE.wall/2,CASE.baseH+wallH/2,0);
for(let i=1;i<CASE.cols;i++)
woodBox(.12,CASE.divH,CASE.z1-CASE.z0,CASE.x0+CELL_W*i,CASE.baseH+CASE.divH/2,0);
for(let j=1;j<CASE.rows;j++)
woodBox(CASE.x1-CASE.x0,CASE.divH,.12,0,CASE.baseH+CASE.divH/2,CASE.z0+CELL_D*j);
/* ───────────────────────── the composing slot (galley) ────────────────────── */
const GAL={cx:9.0,cz:0,innerW:6.4,innerD:1.6,baseH:.18,frameH:.34,slots:5};
const slotW=GAL.innerW/GAL.slots;
const galley=new THREE.Group(); scene.add(galley);
function steelBox(w,h,d,x,y,z){
const m=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),
new THREE.MeshStandardMaterial({color:0x33373f,metalness:.92,roughness:.34}));
m.position.set(x,y,z); m.castShadow=true; m.receiveShadow=true; galley.add(m); return m;
}
steelBox(GAL.innerW+.5,GAL.baseH,GAL.innerD+.5,GAL.cx,GAL.baseH/2,GAL.cz);
steelBox(GAL.innerW+.5,GAL.frameH,.16,GAL.cx,GAL.baseH+GAL.frameH/2,GAL.cz-GAL.innerD/2-.08);
steelBox(GAL.innerW+.5,GAL.frameH,.16,GAL.cx,GAL.baseH+GAL.frameH/2,GAL.cz+GAL.innerD/2+.08);
steelBox(.16,GAL.frameH,GAL.innerD+.5,GAL.cx-GAL.innerW/2-.08,GAL.baseH+GAL.frameH/2,GAL.cz);
steelBox(.16,GAL.frameH,GAL.innerD+.5,GAL.cx+GAL.innerW/2+.08,GAL.baseH+GAL.frameH/2,GAL.cz);
/* guide marks etched into the galley floor */
const pulse=(function galleyGuides(){
const c=document.createElement('canvas'); c.width=1024; c.height=256; const x=c.getContext('2d');
x.clearRect(0,0,1024,256);
x.strokeStyle='rgba(255,180,84,.55)'; x.lineWidth=3; x.setLineDash([14,12]);
for(let i=0;i<GAL.slots;i++){
const px=1024/GAL.slots*i+12, w=1024/GAL.slots-24;
x.strokeRect(px,42,w,172);
}
x.setLineDash([]); x.strokeStyle='rgba(255,180,84,.28)'; x.lineWidth=2;
x.strokeRect(8,8,1008,240);
const t=new THREE.CanvasTexture(c); t.colorSpace=THREE.SRGBColorSpace;
const floor=new THREE.Mesh(new THREE.PlaneGeometry(GAL.innerW,GAL.innerD),
new THREE.MeshStandardMaterial({map:t,transparent:true,roughness:.55,metalness:.5,
emissive:0xff9c33,emissiveMap:t,emissiveIntensity:.22}));
floor.rotation.x=-Math.PI/2; floor.position.set(GAL.cx,GAL.baseH+.004,GAL.cz);
galley.add(floor);
const glow=new THREE.Mesh(new THREE.PlaneGeometry(GAL.innerW,GAL.innerD),
new THREE.MeshBasicMaterial({color:0xffa53c,transparent:true,opacity:.07,depthWrite:false}));
glow.rotation.x=-Math.PI/2; glow.position.set(GAL.cx,GAL.baseH+.012,GAL.cz); galley.add(glow);
return glow;
})();
/* ───────────────────────────── the sorts (letter blocks) ─────────────────── */
const PX=.12;
function glyphGeometry(letter,mirrored){
const pat=FONT[letter]||FONT['?']||FONT['A'];
const items=[];
for(let r=0;r<pat.length;r++){
for(let c=0;c<pat[r].length;c++){
if(pat[r][c]==='#'){
const cc = mirrored ? (pat[r].length-1-c) : c; // ← mirrored face
items.push({w:PX*.92,h:.12,d:PX*.92,
x:(cc-(pat[r].length-1)/2)*PX, y:.21, z:(r-(pat.length-1)/2)*PX});
}
}
}
return boxesToGeometry(items);
}
const bodyMat=new THREE.MeshStandardMaterial({color:0x9aa0a8,metalness:.88,roughness:.38});
const glyphBaseMat=new THREE.MeshStandardMaterial({color:0x24272d,metalness:.55,roughness:.42});
const blocks=[], pickables=[];
function makeBlock(letter){
const grp=new THREE.Group();
const body=new THREE.Mesh(boxesToGeometry([
{w:.80,h:.22,d:1.05,y:.04},
{w:.60,h:.09,d:.82,y:-.115}
]),bodyMat);
body.castShadow=true; body.receiveShadow=true; grp.add(body);
const gMat=glyphBaseMat.clone();
const glyph=new THREE.Mesh(glyphGeometry(letter,true),gMat);
glyph.castShadow=true; grp.add(glyph);
const b={grp,body,glyph,gMat,letter,mirrored:true,home:new THREE.Vector3(),
target:new THREE.Vector3(),slot:-1,inGalley:false,press:-1,held:false};
body.userData.block=b; glyph.userData.block=b;
pickables.push(body,glyph); blocks.push(b);
scene.add(grp);
return b;
}
const LETTERS='ABCDEFGHIJKLMNOPQRST';
const DIGITS='01234567890123456789';
let cellIdx=0;
for(let j=0;j<CASE.rows;j++){
for(let i=0;i<CASE.cols;i++){
const cx=CASE.x0+CELL_W*(i+.5), cz=CASE.z0+CELL_D*(j+.5);
const L=LETTERS[cellIdx%20], D=DIGITS[cellIdx%20];
const a=makeBlock(L), d=makeBlock(D);
const j1=(Math.random()-.5)*.10, j2=(Math.random()-.5)*.10;
a.home.set(cx-.46,CASE.baseH+.155,cz-.32+j1); a.grp.position.copy(a.home);
a.target.copy(a.home); a.grp.rotation.y=(Math.random()-.5)*.10;
d.home.set(cx+.46,CASE.baseH+.155,cz+.30+j2); d.grp.position.copy(d.home);
d.target.copy(d.home); d.grp.rotation.y=(Math.random()-.5)*.10;
cellIdx++;
}
}
/* selection outline */
const sel=new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(.88,.05,1.13)),
new THREE.LineBasicMaterial({color:0xffb454,transparent:true,opacity:.95}));
sel.visible=false; scene.add(sel);
/* ─────────────────────────────── the impression sheet ─────────────────────── */
const paperCanvas=document.createElement('canvas'); paperCanvas.width=1024; paperCanvas.height=430;
const pctx=paperCanvas.getContext('2d');
const grain=[]; for(let i=0;i<2600;i++) grain.push([Math.random()*1024,Math.random()*430,Math.random()*2.2+.4,Math.random()]);
const paperTex=new THREE.CanvasTexture(paperCanvas); paperTex.colorSpace=THREE.SRGBColorSpace;
const paper=new THREE.Mesh(new THREE.PlaneGeometry(6.6,2.7),
new THREE.MeshStandardMaterial({map:paperTex,roughness:.95,metalness:0}));
paper.rotation.x=-Math.PI/2; paper.position.set(GAL.cx,.014,3.6); paper.receiveShadow=true; scene.add(paper);
function drawPaper(str){
const c=pctx;
c.fillStyle='#efe6d2'; c.fillRect(0,0,1024,430);
c.fillStyle='rgba(120,100,70,.10)';
for(const g of grain){ c.beginPath(); c.arc(g[0],g[1],g[2],0,6.283); c.fill(); }
c.strokeStyle='rgba(90,70,45,.25)'; c.lineWidth=2;
c.strokeRect(16,16,992,398);
c.textAlign='center';
c.fillStyle='rgba(70,58,40,.55)'; c.font='500 22px Georgia, serif';
c.fillText('S O R T F A C E S ( M I R R O R E D )',512,56);
if(str){
c.save(); c.translate(512,116); c.scale(-1,1);
c.fillStyle='rgba(40,34,26,.55)'; c.font='600 54px Georgia, serif';
c.fillText(str,0,0); c.restore();
c.fillStyle='rgba(40,34,26,.5)'; c.font='500 22px Georgia, serif';
c.fillText('I M P R E S S I O N',512,214);
c.strokeStyle='rgba(40,34,26,.35)'; c.lineWidth=3;
c.beginPath(); c.moveTo(120,300); c.lineTo(904,300); c.stroke();
c.fillStyle='#221c14'; c.font='600 132px Georgia, serif';
c.fillText(str,512,394);
}else{
c.fillStyle='rgba(60,50,35,.35)'; c.font='italic 46px Georgia, serif';
c.fillText('— empty composing slot —',512,250);
}
paperTex.needsUpdate=true;
}
drawPaper('');
/* ──────────────────────────── composed-slot helpers ───────────────────────── */
function slotPos(i){ return new THREE.Vector3(GAL.cx+(i-(GAL.slots-1)/2)*slotW, GAL.baseH+.155, GAL.cz); }
function galleyBlocks(){ return blocks.filter(b=>b.inGalley).sort((a,b)=>a.slot-b.slot); }
function composedString(){ return galleyBlocks().map(b=>b.letter).join(''); }
function freeSlot(){
const used=new Set(blocks.filter(b=>b.inGalley).map(b=>b.slot));
for(let i=0;i<GAL.slots;i++) if(!used.has(i)) return i;
return -1;
}
function sendToSlot(b,idx){
b.slot=idx; b.inGalley=true;
b.target.copy(slotPos(idx)); b.target.y=GAL.baseH+.155;
b.gMat.color.setHex(0x0d0f13); b.gMat.roughness=.22; b.gMat.metalness=.35;
}
function sendHome(b){
b.inGalley=false; b.slot=-1;
b.target.copy(b.home);
b.gMat.color.setHex(0x24272d); b.gMat.roughness=.42; b.gMat.metalness=.55;
}
/* ─────────────────────── camera controls (hand rolled) ───────────────────── */
const camTarget=new THREE.Vector3(2.0,.35,.2);
let radius=19.5, phi=.98, theta=.40;
function updateCamera(){
camera.position.setFromSpherical(new THREE.Spherical(radius,phi,theta)).add(camTarget);
camera.lookAt(camTarget);
}
updateCamera();
/* ───────────────────────────── pointer interaction ────────────────────────── */
const ray=new THREE.Raycaster(), ndc=new THREE.Vector2();
const dragPlane=new THREE.Plane(new THREE.Vector3(0,1,0),-1.05);
const groundPlane=new THREE.Plane(new THREE.Vector3(0,1,0),0);
let mode='none', lastX=0,lastY=0, heldBlock=null, selected=null;
const tmp=new THREE.Vector3();
function setNDC(e){
ndc.set((e.clientX/innerWidth)*2-1, -(e.clientY/innerHeight)*2+1);
ray.setFromCamera(ndc,camera);
}
renderer.domElement.addEventListener('contextmenu',e=>e.preventDefault());
renderer.domElement.addEventListener('pointerdown',e=>{
renderer.domElement.setPointerCapture(e.pointerId);
setNDC(e);
if(e.button===2||e.shiftKey){ mode='pan'; lastX=e.clientX; lastY=e.clientY; return; }
const hits=ray.intersectObjects(pickables,false);
if(hits.length){
const b=hits[0].object.userData.block;
selected=b; b.held=true;
heldBlock=b; mode='drag';
if(ray.ray.intersectPlane(dragPlane,tmp)) b.offset=b.grp.position.clone().sub(tmp);
else b.offset=new THREE.Vector3();
b.grp.position.y=1.05; b.target.copy(b.grp.position);
updateStatus();
}else{ mode='orbit'; lastX=e.clientX; lastY=e.clientY; }
});
window.addEventListener('pointermove',e=>{
if(mode==='orbit'){
theta-=(e.clientX-lastX)*.005;
phi=Math.max(.22,Math.min(1.42,phi-(e.clientY-lastY)*.005));
lastX=e.clientX; lastY=e.clientY;
}else if(mode==='pan'){
const s=radius*.0013, right=new THREE.Vector3().setFromMatrixColumn(camera.matrix,0),
up=new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
camTarget.addScaledVector(right,-(e.clientX-lastX)*s).addScaledVector(up,(e.clientY-lastY)*s);
camTarget.x=Math.max(-14,Math.min(18,camTarget.x));
camTarget.z=Math.max(-12,Math.min(12,camTarget.z));
lastX=e.clientX; lastY=e.clientY;
}else if(mode==='drag'&&heldBlock){
setNDC(e);
if(ray.ray.intersectPlane(dragPlane,tmp)){
tmp.add(heldBlock.offset); tmp.y=1.05;
heldBlock.grp.position.copy(tmp); heldBlock.target.copy(tmp);
}
}
});
window.addEventListener('pointerup',e=>{
if(mode==='drag'&&heldBlock){
setNDC(e);
const g=new THREE.Vector3();
if(ray.ray.intersectPlane(groundPlane,g)){
const inGalley = g.x>GAL.cx-GAL.innerW/2-.35 && g.x<GAL.cx+GAL.innerW/2+.35 &&
Math.abs(g.z-GAL.cz)<GAL.innerD/2+.45;
if(inGalley){
const old=heldBlock.slot;
if(old>=0) heldBlock.slot=-1;
let idx=-1,best=1e9;
for(let i=0;i<GAL.slots;i++){
if(blocks.some(b=>b!==heldBlock&&b.inGalley&&b.slot===i)) continue;
const d=Math.abs(slotPos(i).x-g.x);
if(d<best){best=d; idx=i;}
}
if(idx>=0) sendToSlot(heldBlock,idx); else sendHome(heldBlock);
}else sendHome(heldBlock);
}
heldBlock.held=false; heldBlock=null; mode='none';
updateStatus();
}else mode='none';
});
renderer.domElement.addEventListener('wheel',e=>{
e.preventDefault();
radius=Math.max(8,Math.min(42,radius*Math.exp(e.deltaY*.0011)));
},{passive:false});
/* ─────────────────────────────── keyboard input ─────────────────────────── */
function flipHeld(){
const b=heldBlock||selected; if(!b) return;
b.mirrored=!b.mirrored;
const old=b.glyph.geometry; b.glyph.geometry=glyphGeometry(b.letter,b.mirrored); old.dispose();
}
window.addEventListener('keydown',e=>{
const k=e.key;
if(k==='Enter'){ e.preventDefault(); pullImpression(); return; }
if(k==='Backspace'){ e.preventDefault();
const gb=galleyBlocks(); if(gb.length){ sendHome(gb[gb.length-1]); updateStatus(); } return; }
if(k==='f'||k==='F'){ flipHeld(); return; }
if(k.length===1 && FONT[k]){
const idx=freeSlot(); if(idx<0) return;
const b=blocks.find(bb=>bb.letter===k && !bb.inGalley);
if(b){ sendToSlot(b,idx); selected=b; updateStatus(); }
}
});
function pullImpression(){
const str=composedString();
for(const b of galleyBlocks()) b.press=0;
drawPaper(str);
const f=document.getElementById('flash'); f.style.opacity='1';
setTimeout(()=>f.style.opacity='0',90);
updateStatus();
}
/* ───────────────────────────── status + tag overlay ──────────────────────── */
const slotStr=document.getElementById('slotStr'), heldStr=document.getElementById('heldStr');
function updateStatus(){
const s=composedString();
slotStr.textContent = s? s : '(empty)';
heldStr.textContent = (heldBlock||selected)? (heldBlock||selected).letter : '—';
}
const tags=[{el:document.getElementById('tagCase'),p:new THREE.Vector3(0,1.35,-2.4)},
{el:document.getElementById('tagGalley'),p:new THREE.Vector3(GAL.cx,1.05,0)},
{el:document.getElementById('tagPaper'),p:new THREE.Vector3(GAL.cx,.35,4.3)}];
function updateTags(){
for(const t of tags){
const v=t.p.clone().project(camera);
const x=(v.x*.5+.5)*innerWidth, y=(-v.y*.5+.5)*innerHeight;
t.el.style.transform=`translate(-50%,-50%) translate(${x.toFixed(1)}px,${y.toFixed(1)}px)`;
t.el.style.opacity = (v.z<1 && x>-200 && x<innerWidth+200)? .95 : 0;
}
}
/* ───────────────────────────────── animation ──────────────────────────────── */
const clock=new THREE.Clock();
function animate(){
requestAnimationFrame(animate);
const dt=Math.min(clock.getDelta(),.05);
updateCamera();
for(const b of blocks){
if(b.held){ b.grp.position.lerp(b.target,.4); continue; }
if(b.press>=0){
b.press=Math.min(1,b.press+dt*3.2);
b.grp.position.lerp(b.target,.22);
b.grp.position.y=b.target.y-.085*Math.sin(b.press*Math.PI);
}else{
b.grp.position.lerp(b.target,.13);
b.grp.rotation.y+=(0-b.grp.rotation.y)*.12;
}
}
if(pulse){ pulse.material.opacity=.05+.045*Math.sin(clock.elapsedTime*1.7); }
if(selected||heldBlock){
const b=heldBlock||selected;
sel.visible=true; sel.position.copy(b.grp.position); sel.position.y=b.grp.position.y-.16;
} else sel.visible=false;
updateTags();
renderer.render(scene,camera);
}
updateStatus(); animate();
window.addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
</script>
</body>
</html>
```
**What it is**
- **Type case** — a voxel-built wooden tray with 20 compartments, each holding two sorts (a letter and a digit) rendered as stepped pixel glyphs on gunmetal type bodies.
- **Mirrored faces** — every glyph is rasterized from a hand-authored 5×7 pixel font and column-reversed, so each sort reads backwards from above, exactly like real letterpress type.
- **Empty composing slot** — a steel galley with etched slot guides and a pulsing amber glow; it starts empty.
- **Interaction** — drag any sort (custom orbit/pan/zoom camera written inline), type `A–Z`/`0–9` to set type, `⌫` to return a sort, `F` to turn the held sort, `Enter` to pull an impression.
- **Impression sheet** — the paper shows the reversed sort faces on top and the correctly-reading impression below, demonstrating why the type has to be mirrored.
Only the Three.js core ES module from cdnjs is imported; all camera controls, geometry merging, textures, and fonts are implemented directly in the file.
```