Playbook and Three.js code kit for detailed dioramas: classic pixel art, stroked toon or pixel + stroke; two intake gates for look and model sourcing; free orbit, palette snap and ink; animated toy-scale cast; per-entity frame QA.
JavaScript agent-skillagent-skill-repositoryagent-skillsai-agentscreative-codingdioramagame-artpixel-artpixelationprocedural-artprocedural-generationskillthree-jsthreejswebgl
import test from 'node:test';
import assert from 'node:assert/strict';
import {pathToFileURL} from 'node:url';
import {createPoseBounds} from '../templates/pose-bounds.mjs';
const T=await import(pathToFileURL(process.env.THREE_MODULE_PATH||'/Users/apple/Desktop/monstertruck/node_modules/three/build/three.module.js'));
const q=createPoseBounds(T),near=(a,b)=>assert(Math.abs(a-b)<1e-6,`${a} != ${b}`);
const make=()=>new T.Mesh(new T.BoxGeometry(1,1,1),new T.MeshBasicMaterial());
test('actual transformed vertices, not copied constructor dimensions',()=>{const m=make();m.geometry.translate(3,0,0);m.position.x=4;near(q.measure(m).bounds.getCenter(new T.Vector3()).x,7);});
test('hidden and transparent occupied geometry is retained',()=>{const m=make();m.visible=false;m.material.transparent=true;m.material.opacity=0;assert(q.measure(m).vertexCount>0);});
test('parent translation/rotation cancels in its own local frame',()=>{const root=new T.Group(),m=make();root.add(m);root.position.set(7,4,-2);root.rotation.y=.8;const b=q.measure(m,{frame:root}).bounds;near(b.min.x,-.5);near(b.max.z,.5);});
test('morph deformation changes live bounds despite stale geometry boundingBox',()=>{const g=new T.BoxGeometry(1,1,1),morph=g.attributes.position.clone();for(let i=0;i<morph.count;i++)morph.setX(i,morph.getX(i)+2);g.morphAttributes.position=[morph];g.computeBoundingBox();const m=new T.Mesh(g,new T.MeshBasicMaterial());m.morphTargetInfluences[0]=0;near(q.measure(m).bounds.min.x,-.5);m.morphTargetInfluences[0]=1;near(q.measure(m).bounds.min.x,1.5);assert.equal(q.measure(m).method,'cpu-morphed-active-vertices');});
function rig(){const g=new T.BoxGeometry(1,1,1),n=g.attributes.position.count;g.setAttribute('skinIndex',new T.Uint16BufferAttribute(new Uint16Array(n*4),4));const weights=new Float32Array(n*4);for(let i=0;i<n;i++)weights[i*4]=1;g.setAttribute('skinWeight',new T.Float32BufferAttribute(weights,4));const mesh=new T.SkinnedMesh(g,new T.MeshBasicMaterial()),bone=new T.Bone();mesh.add(bone);mesh.updateMatrixWorld(true);mesh.bind(new T.Skeleton([bone]));return {mesh,bone};}
test('actual imported-style skin follows the current bone, not bind pose',()=>{const {mesh,bone}=rig();near(q.measure(mesh).bounds.min.y,-.5);bone.position.y=2;const result=q.measure(mesh);near(result.bounds.min.y,1.5);assert.equal(result.method,'cpu-skinned-active-vertices');});
test('skinned attached bind inverse refreshes after parent relocation',()=>{const {mesh,bone}=rig(),root=new T.Group();root.add(mesh);root.position.x=7;bone.position.x=2;near(q.measure(mesh).bounds.getCenter(new T.Vector3()).x,9);near(q.measure(mesh,{frame:root}).bounds.getCenter(new T.Vector3()).x,2);});
test('rigid instancing requires exact instance and measures its real transform',()=>{const m=new T.InstancedMesh(new T.BoxGeometry(1,1,1),new T.MeshBasicMaterial(),2);m.setMatrixAt(0,new T.Matrix4());m.setMatrixAt(1,new T.Matrix4().makeTranslation(5,0,0));assert.throws(()=>q.measure(m),/instance/);near(q.measure(m,{instanceId:1}).bounds.min.x,4.5);assert.throws(()=>q.measure(m,{instanceId:2}),/instance/);});
test('unreferenced geometry outliers do not inflate active indexed range',()=>{const g=new T.BufferGeometry();g.setAttribute('position',new T.Float32BufferAttribute([0,0,0,1,0,0,0,1,0,900,900,900],3));g.setIndex([0,1,2]);const r=q.measure(new T.Mesh(g,new T.MeshBasicMaterial()),{includePoints:true});near(r.bounds.max.x,1);assert.equal(r.points.length,3);});
test('empty, collapsed and malformed ranges fail closed',()=>{const m=make();m.geometry.setDrawRange(0,0);assert.throws(()=>q.measure(m),/empty/);m.geometry.setDrawRange(1,3);assert.throws(()=>q.measure(m),/malformed/);const g=new T.BufferGeometry();g.setAttribute('position',new T.Float32BufferAttribute(new Float32Array(9),3));assert.throws(()=>q.measure(new T.Mesh(g,new T.MeshBasicMaterial())),/collapsed/);});
test('NaN geometry and invalid transforms fail closed',()=>{const m=make();m.geometry.attributes.position.setX(0,NaN);assert.throws(()=>q.measure(m),/nonfinite/);const n=make();n.scale.x=0;assert.throws(()=>q.measure(n),/transform/);});
test('unsupported GPU displacement is unknown/error, not excluded',()=>{const m=make();m.material=new T.ShaderMaterial();assert.throws(()=>q.measure(m),/shader/);m.material=new T.MeshStandardMaterial({displacementMap:new T.Texture()});assert.throws(()=>q.measure(m),/displacement/);});
test('invalid index and missing skeleton fail closed',()=>{const m=make();m.geometry.index.setX(0,9999);assert.throws(()=>q.measure(m),/index/);const {mesh}=rig();mesh.skeleton=undefined;assert.throws(()=>q.measure(mesh),/skeleton/);});