For your agent
A drop-in Three.js isometric room cutaway system with automatic 360° orbit wall-clipping, shadow-safe clipping (so cut-away roofs and near walls cast no phantom shadows), solid stencil-buffer cut caps (so sliced walls, chimneys, and columns look solid instead of hollow), wall-trim inset (so proud wainscoting and shelves don’t float), an architectural diorama plinth, and a radial studio surround.
Extracted from the 3D tabletop stage of D20 Adventures. Try the interactive demo →
src/cutaway.ts — the entire cutaway system (~370 lines, zero dependencies beyond three). Manages 5 world-space THREE.Planes, material clipShadows patching/restoration, stencil-buffer solid cut caps, orbit quadrant switching with hysteresis, the diorama plinth mesh, and the radial studio backdrop.src/rooms.ts & src/textures.ts — three self-contained procedural demo rooms (Tavern Study, Stone Crypt, Alchemist Loft) with canvas-generated albedo/bump textures and zero external assets.Copy src/cutaway.ts into your project and wire it to your existing WebGLRenderer, Scene, and room root Object3D:
import * as THREE from "three"
import { createIsometricCutaway } from "./cutaway"
const cutaway = createIsometricCutaway({
renderer,
scene,
world: roomGroup,
room: { min: [-3.6, 0, -3.1], max: [3.6, 3.45, 3.1] },
cutHeight: 2.75,
wallTrim: 0.16, // cuts just inside near walls so proud trim/shelves don't float
wallThickness: 0.36, // keeps the two far walls solid to their outer face
clipShadows: true, // keeps cut-away roofs out of directional shadow maps
solidCaps: true, // fills sliced walls, chimneys, and columns with solid stencil caps
plinth: true,
})
// Frame an isometric camera
const { position, target, fov } = cutaway.frame({
azimuth: 45,
elevation: 35,
distance: 16.5,
fov: 24,
})
camera.fov = fov
camera.updateProjectionMatrix()
camera.position.copy(position)
controls.target.copy(target)
// In your animation loop — automatically flips the two near walls as you orbit:
cutaway.update(camera)
// Clean up and restore original materials when leaving cutaway mode:
cutaway.dispose()
clipShadows mattersIn Three.js, renderer.clippingPlanes clips fragments on screen, not during shadow map rendering. Without enabling renderer.localClippingEnabled = true and setting material.clippingPlanes + material.clipShadows = true on the room's meshes, the invisible cut-away ceiling still blocks your directional key light. Toggle Clip shadows in the live demo to see the difference immediately.
npm install
npm run dev
npm run build
Built for D20 Adventures · MIT License.