BUILD REQUEST - PL-115 Wrecking Yard - please build this now I'm sending you this as my request: please build the one-file HTML app described below. Start now and do the whole build in your answer to this message. - This is a build job, not a document to summarize, review or discuss. Don't ask me anything first: if a detail is unclear, pick the most sensible option and keep going. - The spec is everything between the BEGIN SPEC and END SPEC lines. Follow all of it exactly. - If your tool can create files, also save the finished file as PL-115-wrecking-yard.html. ===== BEGIN SPEC ===== PL-115 — Wrecking Yard: Hand-Built Physics Demolition Sandbox — Very Hard WHAT THIS TESTS: Writing a real 3D rigid-body physics engine from scratch (no physics library), real-time Voronoi fracture, keeping 1,500+ pieces of debris smooth, a playable sandbox UI, and honestly measuring its own physics. Build "Wrecking Yard": a playable Three.js demolition sandbox at golden hour. I swing a wrecking ball, fire cannonballs and set off charges to bring down brick towers, a glass greenhouse, a wooden bridge and a stone arch. Every piece breaks, tumbles, stacks and settles with believable physics. It should be so satisfying that people watch the replay twice. THE HARD RULE: WRITE THE PHYSICS YOURSELF - Do NOT use any physics library (no cannon, ammo, rapier, oimo, havok, jolt, matter or similar). Three.js is allowed for rendering only. Write your own rigid-body engine in the file. - It must have: boxes, spheres and convex hulls (for fracture pieces); a broadphase (spatial hash or sweep-and-prune); narrowphase with real contact points (SAT or GJK/EPA); a sequential-impulse solver with friction, restitution, warm starting and at least 8 iterations; a fixed 1/120 s step with an accumulator; and sleeping for bodies at rest. - Named fails: stacks that jitter, sink or slowly explode; bricks passing through each other or the ground; debris that never settles; a tower that falls like one solid block; fake "physics" that just plays canned animations. THE YARD (scene) - Dusty ground with tire tracks, a chain-link fence, a crane holding the wrecking ball on a chain, and a warm low sun with long shadows (one shadow-casting light, soft PCF shadows, plus fog and dust in the air). - Five targets, each built from real separate bodies: 1. Brick tower: 10 floors, 300+ bricks in a running bond, with mortar color gaps. 2. Glass greenhouse: thin glass panes on a frame. The glass shatters into Voronoi shards with sparkle, and the frame bends and falls. 3. Wooden bridge: planks on two beams across a ditch, with rope joints between planks (distance constraints) so it sags and swings. 4. Stone arch: 15 wedge-shaped voussoirs that stand up ONLY because they push on each other. Remove the keystone and the whole arch falls. 5. Domino line: 120 dominoes curving across the yard into a stack of barrels. - Everything starts asleep and perfectly still. Nothing may drift, slide or fall on its own in the first 30 seconds. FRACTURE (real time) - When an impact impulse on a brick, stone or pane is over its material's strength, it breaks into 4 to 12 convex Voronoi pieces around the impact point. Each piece is a new rigid body with the right mass (by volume), inherits the velocity, and shows a rough inner face in a darker color. - Materials: brick (medium strength, heavy), glass (weak, light, shatters into many shards), wood (splinters into long pieces), stone (strong, very heavy). - Pieces under 0.05 volume turn into short-lived dust particles instead of bodies so the body count stays sane. TOOLS (bottom toolbar, also number keys) 1. Wrecking ball: drag to pull it back, release to swing. The chain is a real chain of linked bodies, not a fixed arc. 2. Cannon: click a spot to fire a heavy iron ball in an arc at it, with a visible trajectory preview. 3. Charge: place up to 5 charges and press Detonate. Each gives a radial impulse that falls off with distance, plus a flash, smoke and a camera shake. 4. Grab: pick up any body with a spring and fling it. 5. Rebuild: puts everything back exactly as it started. - Slow-motion button (0.25x), Pause, Step one physics frame, and Replay: replays the last 20 s of physics exactly from recorded inputs, with an orbiting camera. - Orbit, pan and zoom camera, plus a "follow the ball" camera. On iPhone everything works by touch, with 44 px buttons. HUD - Top-left in monospace: FPS, physics ms per step, awake bodies, sleeping bodies, contacts, total bodies, and pieces made by fracture. Every number is read live from the engine. - A "Destruction" score that counts the real mass knocked off its starting spot (in kg). PERFORMANCE - 60 fps on a laptop with 1,500 bodies awake, and at least 30 fps on iPhone with 600. Use InstancedMesh per material, reuse arrays, create no garbage in the hot loop, and cap the bodies at 2,500 by turning the oldest small debris into dust. BUILD CONTRACT Deliver ONE self-contained index.html with inline CSS and JS, with Three.js loaded from a public CDN with a pinned version. No other files. It must open straight from a file in desktop Chrome and iPhone Safari. HONEST TESTING Expose a read-only window.__phys with: bodies (id, shape, material, position, velocity, asleep), contacts, step time, energy and fracture count. Add ?test=1, which runs these headless physics tests (no rendering needed) and logs PASS/FAIL with numbers to the console and to window.__testResults: - Stack test: a 20-box tower resting for 20 s stays standing; the top box drifts under 2 cm and every box falls asleep. - Pyramid test: a 10-row box pyramid (55 boxes) settles with no box moving over 1 cm after 10 s. - Arch test: the 15-stone arch stands for 30 s, and after the keystone is removed, at least 12 stones end up below half their starting height. - Restitution test: a sphere with restitution 0.5 dropped from 4 m bounces to 1 m ±15%. - Friction test: a box on a 20° ramp with friction 0.6 stays put; with friction 0.2 it slides. - Tunneling test: a 300 m/s cannonball at a 10 cm thick wall hits it or breaks it and never passes through without a contact. - Energy test: in a closed box of 200 bouncing spheres with no friction and restitution 1, total energy never rises more than 2% over 10 s. - Fracture test: the pieces of every broken body add up to its original volume within 3%. - Determinism: the same inputs replayed twice give identical body positions (to 6 decimals) after 20 s. - Performance: the average physics step with 1,500 awake bodies, reported in ms. Under 8 ms counts as a pass. - Zero console errors, and a check that the source contains no physics library import. WORK LOOP AND OUTPUT You are an agent with a terminal and a browser, so use them: build in stages (engine → stacking tests → fracture → scene → tools → polish), and run ?test=1 after every stage before moving on. Run it in a real headless browser, read the console, and take screenshots at 1280x720 and 390x844: the scene at rest, mid-swing, mid-collapse, and settled rubble. Look at them, and fix and retest until every check passes. Never weaken a test to make it pass. Mark anything you could not run as UNMEASURED and never invent numbers. If you are chat-only: first list each checklist item with how your code meets it, then give one corrected complete file. Final output: ONE complete index.html code block, then the PASS/FAIL/UNMEASURED table with every measured number. No snippets. OUTPUT STRATEGY (critical — this fixes truncation failures) Do NOT write the entire app as a single output block. Use multiple file-write calls and build the file in stages: 1. Write index.html skeleton with CSS + HUD + main loop placeholder. 2. Append the physics engine core (bodies, broadphase, narrowphase, solver) via separate file edits/appends. 3. Append fracture, scene builders, tools, and the ?test=1 harness in further separate writes. Keep every single response under ~20K tokens. After the file is complete, run ?test=1 in a headless browser and fix what fails before declaring done. Your final reply should be a short summary + the PASS/FAIL table only, not the code. ===== END SPEC ===== Now build it. Reply with ONE complete HTML file in ONE code block.