Bring the anvil's horn back to its reference proportion, rebuild the book's metal furniture so no two overlapping faces share a plane, and release 0.2.0.
This commit is contained in:
parent
fc167f32d9
commit
8a049987a6
82 changed files with 9725 additions and 5064 deletions
142
scripts/check-model.ts
Normal file
142
scripts/check-model.ts
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
* Checks one model, straight from the folder it is written in.
|
||||
*
|
||||
* bun scripts/check-model.ts my-registry wooden-hoe
|
||||
* bun scripts/check-model.ts contemporary-props ceramic-vase --size 900 --angles 6
|
||||
*
|
||||
* Why this exists rather than reusing the kit-wide gate: the gate rebuilds the
|
||||
* registry and reinstalls it into the demo before it checks anything, and those
|
||||
* two steps write files the whole repository shares. One person can run them
|
||||
* safely. Several workers cannot, because each install overwrites the last and
|
||||
* every one of them then verifies somebody else's code. That has already
|
||||
* happened once here: a cart was fixed, the reinstall was skipped, and the old
|
||||
* geometry passed while the new geometry was never looked at.
|
||||
*
|
||||
* So this touches nothing outside the registry's own `renders/`. It imports the
|
||||
* model directly, builds it, measures it, asks whether any of it floats, and
|
||||
* draws it. The kit-wide gate still runs afterwards, once, in one place.
|
||||
*
|
||||
* The render is the point. Every measurement below can pass on a model that
|
||||
* looks nothing like the thing it is named after, and no geometric check ever
|
||||
* written can say "that is not a hoe".
|
||||
*
|
||||
* `.isMesh` rather than `instanceof Mesh` throughout, on purpose. Two copies of
|
||||
* three can be loaded at once -- the kits import from `three`, the renderer from
|
||||
* `three/webgpu` -- and across copies `instanceof` matches nothing. The failure
|
||||
* is silent and total: the traversal samples no geometry, finds no components,
|
||||
* and reports every model clean.
|
||||
*/
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
|
||||
import { Box3, Vector3, type Object3D } from 'three/webgpu'
|
||||
|
||||
import { encodePng, renderObject, tile, type Frame } from './raster.ts'
|
||||
import { findFloating } from './support.ts'
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
const flag = (name: string): string | undefined => {
|
||||
const at = args.indexOf(`--${name}`)
|
||||
return at >= 0 ? args[at + 1] : undefined
|
||||
}
|
||||
|
||||
const positional = args.filter((a, i) => !a.startsWith('--') && !args[i - 1]?.startsWith('--'))
|
||||
const [registry, id] = positional
|
||||
if (!registry || !id) {
|
||||
throw new Error('usage: bun scripts/check-model.ts <registry-dir> <model-id> [--size N] [--angles N]')
|
||||
}
|
||||
|
||||
const size = Number(flag('size') ?? 720)
|
||||
const angles = Number(flag('angles') ?? 0)
|
||||
const outDir = flag('out') ?? `${registry}/renders`
|
||||
|
||||
type Built = {
|
||||
root: Object3D
|
||||
parts: Record<string, unknown>
|
||||
actions?: Record<string, unknown>
|
||||
getConfig(): Record<string, unknown>
|
||||
update(dt: number): void
|
||||
dispose(): void
|
||||
}
|
||||
|
||||
const module_ = await import(
|
||||
`../${registry}/models/${id}/model.ts`
|
||||
) as { createModel?: (overrides?: Record<string, unknown>) => Built }
|
||||
if (!module_.createModel) throw new Error(`${registry}/models/${id}/model.ts does not export createModel`)
|
||||
|
||||
const model = module_.createModel()
|
||||
model.update(0.42) // catch anything animated mid-motion
|
||||
model.root.updateMatrixWorld(true)
|
||||
|
||||
/* ----------------------------------------------------------------- measure */
|
||||
|
||||
let triangles = 0
|
||||
const slots = new Set<string>()
|
||||
model.root.traverse((object) => {
|
||||
const mesh = object as {
|
||||
isMesh?: boolean
|
||||
geometry?: { getIndex(): { count: number } | null; getAttribute(n: string): { count: number } }
|
||||
userData?: Record<string, { materialSlot?: string }>
|
||||
}
|
||||
if (!mesh.isMesh || !mesh.geometry) return
|
||||
const index = mesh.geometry.getIndex()
|
||||
triangles += (index ? index.count : mesh.geometry.getAttribute('position').count) / 3
|
||||
const slot = mesh.userData?.vibe3d?.materialSlot
|
||||
if (slot) slots.add(slot)
|
||||
})
|
||||
|
||||
const box = new Box3().setFromObject(model.root)
|
||||
const extent = box.getSize(new Vector3())
|
||||
const support = findFloating(model.root, { resolution: 96 })
|
||||
|
||||
console.log(`\n${registry}/${id}`)
|
||||
console.log(` ${triangles} triangles · ${extent.x.toFixed(2)} x ${extent.y.toFixed(2)} x ${extent.z.toFixed(2)} m`)
|
||||
console.log(` parts: ${Object.keys(model.parts).join(', ') || '(none)'}`)
|
||||
console.log(` slots: ${[...slots].sort().join(', ') || '(none)'}`)
|
||||
console.log(` actions: ${Object.keys(model.actions ?? {}).join(', ') || '(none)'}`)
|
||||
console.log(` config: ${Object.keys(model.getConfig()).join(', ')}`)
|
||||
|
||||
/* -------------------------------------------------------------- structure */
|
||||
|
||||
let failed = false
|
||||
const fail = (message: string): void => {
|
||||
console.log(` FAIL ${message}`)
|
||||
failed = true
|
||||
}
|
||||
|
||||
if (triangles === 0) fail('no geometry at all')
|
||||
if (!Number.isFinite(extent.x + extent.y + extent.z)) fail('bounds are not finite')
|
||||
if (support.floating.length > 0) {
|
||||
fail(`${support.floating.length} piece(s) float, in ${support.components} components:`)
|
||||
for (const piece of support.floating) {
|
||||
console.log(
|
||||
` ${(piece.clearance * 1000).toFixed(0)}mm clear, ${piece.voxels} voxels, parts: ${piece.parts.join(', ')}`,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
console.log(` rests on the ground · ${support.components} connected component(s)`)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- picture */
|
||||
|
||||
await mkdir(outDir, { recursive: true })
|
||||
let frame: Frame
|
||||
if (angles > 1) {
|
||||
// A single three-quarter view is how a model gets called finished while it is
|
||||
// still wrong from the other side. The fence only looks thin edge on.
|
||||
const frames: Frame[] = []
|
||||
for (let i = 0; i < angles; i += 1) {
|
||||
const spun = module_.createModel!()
|
||||
spun.update(0.42)
|
||||
frames.push(renderObject(spun.root, { size, spin: (i / angles) * Math.PI * 2 }))
|
||||
spun.dispose()
|
||||
}
|
||||
frame = tile(frames, size, angles)
|
||||
} else {
|
||||
frame = renderObject(model.root, { size })
|
||||
}
|
||||
const file = `${outDir}/${id}${angles > 1 ? '-turntable' : ''}.png`
|
||||
await writeFile(file, encodePng(frame))
|
||||
console.log(`\n ${file} — now LOOK at it`)
|
||||
|
||||
model.dispose()
|
||||
process.exit(failed ? 1 : 0)
|
||||
|
|
@ -92,10 +92,10 @@ for (const [label, patch] of CASES) {
|
|||
const seatTris = triangles(model.parts.seat.anchor)
|
||||
const seatTop = Math.max(...seatTris.flatMap((t) => [t[1]!, t[4]!, t[7]!]))
|
||||
const legTris = triangles(model.parts.legs.anchor)
|
||||
const other = [
|
||||
...legTris,
|
||||
...(model.parts.stretcher ? triangles(model.parts.stretcher.anchor) : []),
|
||||
]
|
||||
// The bench used to carry a stretcher and no longer does: the reference has
|
||||
// none, and the open span under the seat is most of what separates a bench
|
||||
// from a table. Only the legs can stand proud of the seat now.
|
||||
const other = legTris
|
||||
const peak = Math.max(...other.flatMap((t) => [t[1]!, t[4]!, t[7]!]))
|
||||
const proud = peak - seatTop
|
||||
worstProud = Math.max(worstProud, proud)
|
||||
|
|
|
|||
|
|
@ -68,10 +68,30 @@ function expect(label: string, condition: boolean): void {
|
|||
|
||||
/* ------------------------------------------------------------ measurement */
|
||||
|
||||
/**
|
||||
* Linear luminance below which a part has no colour left to show.
|
||||
*
|
||||
* Vertex colours are linear, and the palette lives between about 0.03 and 0.36
|
||||
* there, so a lift written as -0.28 is an enormous move rather than a gentle
|
||||
* darkening. Every such lift is relative to a palette constant, and when a
|
||||
* constant is measured against its reference and moved down, every part hanging
|
||||
* off it can go through zero at once. That happened here to nine parts across
|
||||
* six models in a single edit.
|
||||
*
|
||||
* It is invisible in every other check. The geometry is fine, nothing floats,
|
||||
* the slots resolve, the triangle count is unchanged. It is only visible in the
|
||||
* render, and there it does not even look black: a zero albedo contributes
|
||||
* nothing, so all that survives is the white specular highlight and the part
|
||||
* comes out NEUTRAL GREY. A market stall built entirely of oak rendered as a
|
||||
* grey steel frame, and nothing said so.
|
||||
*/
|
||||
const COLOUR_FLOOR = 0.009
|
||||
|
||||
function inspect(root: Object3D) {
|
||||
let meshes = 0
|
||||
let triangles = 0
|
||||
let nonFinite = 0
|
||||
const crushed: string[] = []
|
||||
root.traverse((object) => {
|
||||
if (!(object instanceof Mesh) || !object.geometry.getAttribute('position')) return
|
||||
meshes += 1
|
||||
|
|
@ -80,12 +100,21 @@ function inspect(root: Object3D) {
|
|||
triangles += (index ? index.count : position.count) / 3
|
||||
const array = position.array as ArrayLike<number>
|
||||
for (let i = 0; i < array.length; i += 1) if (!Number.isFinite(array[i])) nonFinite += 1
|
||||
const colour = object.geometry.getAttribute('color')
|
||||
if (!colour || colour.count === 0) return
|
||||
let r = 0, g = 0, b = 0
|
||||
for (let i = 0; i < colour.count; i += 1) {
|
||||
r += colour.getX(i); g += colour.getY(i); b += colour.getZ(i)
|
||||
}
|
||||
const luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / colour.count
|
||||
if (luminance < COLOUR_FLOOR) crushed.push(`${object.name || 'unnamed'} (${luminance.toFixed(5)})`)
|
||||
})
|
||||
const size = new Box3().setFromObject(root).getSize(new Vector3())
|
||||
return {
|
||||
meshes,
|
||||
triangles,
|
||||
nonFinite,
|
||||
crushed,
|
||||
size: [+size.x.toFixed(2), +size.y.toFixed(2), +size.z.toFixed(2)] as [number, number, number],
|
||||
}
|
||||
}
|
||||
|
|
@ -409,7 +438,10 @@ const CASES: readonly Case[] = [
|
|||
maxSize: [8.2, 9.0, 7.4] },
|
||||
{ id: 'wooden-fence', make: as(createFence), patch: { sections: 5, railCount: 4 },
|
||||
parts: 2, ownSlot: 'oak', borrowSlot: 'oak', closed: true,
|
||||
variants: [{ sections: 1 }, { railCount: 1 }, { railCount: 4 }, { rough: 0 }, { brace: 0 }] , maxSize: [5.3, 1.5, 0.45] },
|
||||
variants: [{ sections: 1 }, { railCount: 1 }, { railCount: 4 }, { rough: 0 }, { brace: 0 }] ,
|
||||
// Deeper than it was: the brace used to stop in mid-air and now rakes back
|
||||
// to the ground, which is the only way a free-standing panel stands up.
|
||||
maxSize: [5.3, 1.5, 0.95] },
|
||||
{ id: 'wooden-stool', make: as(createStool), patch: { legCount: 4, splay: 0.35 },
|
||||
parts: 2, ownSlot: 'oak', borrowSlot: 'oak', closed: true,
|
||||
variants: [{ legCount: 5 }, { splay: 0 }] , maxSize: [0.5, 0.55, 0.5] },
|
||||
|
|
@ -432,14 +464,14 @@ const CASES: readonly Case[] = [
|
|||
parts: 4, ownSlot: 'iron', borrowSlot: 'oak', closed: true,
|
||||
variants: [{ bandCount: 0 }, { bandCount: 1 }, { depth: 0.7 }] , maxSize: [1, 0.62, 0.62] },
|
||||
{ id: 'wooden-bench', make: as(createBench), nothingAbove: 'seat', restsOn: ['legs'], patch: { length: 2.1, splay: 0.4 },
|
||||
parts: 3, ownSlot: 'oak', borrowSlot: 'oak', closed: true,
|
||||
parts: 2, ownSlot: 'oak', borrowSlot: 'oak', closed: true,
|
||||
variants: [{ splay: 0 }, { inset: 0.02 }, { width: 0.45 }] , maxSize: [1.7, 0.5, 0.35] },
|
||||
{ id: 'pitch-torch', make: as(createTorch), patch: { wrapLength: 0.42, flameHeight: 2.2 },
|
||||
parts: 3, ownSlot: 'char', borrowSlot: 'oak', radial: true, radialPart: 'shaft',
|
||||
variants: [{ flicker: 0 }, { radius: 0.04 }] , maxSize: [0.14, 0.95, 0.14] },
|
||||
{ id: 'hay-bale', make: as(createBale), patch: { ropeCount: 3, wisps: 40 },
|
||||
{ id: 'hay-bale', make: as(createBale), patch: { ropeCount: 4, wisps: 60 },
|
||||
parts: 3, ownSlot: 'cloth', borrowSlot: 'straw', closed: true,
|
||||
variants: [{ ropeCount: 0 }, { wisps: 0 }, { ropeCount: 1 }] , maxSize: [1.14, 0.68, 0.68] },
|
||||
variants: [{ ropeCount: 0 }, { wisps: 0 }, { ropeCount: 1 }] , maxSize: [1.25, 0.9, 1.25] },
|
||||
{ id: 'linen-sack', make: as(createSack), patch: { fill: 0.45, ears: 5 },
|
||||
parts: 3, ownSlot: 'cloth', borrowSlot: 'cloth', closed: true,
|
||||
variants: [{ ears: 0 }, { fill: 1 }, { collar: 0.28 }],
|
||||
|
|
@ -472,7 +504,7 @@ const CASES: readonly Case[] = [
|
|||
// not contain the wall it was bolted to.
|
||||
parts: 3, ownSlot: 'iron', borrowSlot: 'oak',
|
||||
variants: [{ plankCount: 1 }, { drop: 0.3 }, { reach: 1 }, { postHeight: 3.2 }],
|
||||
maxSize: [0.95, 3.7, 1.0] },
|
||||
maxSize: [1.15, 3.7, 1.85] },
|
||||
{ id: 'leather-book', make: as(createBook), patch: { bands: 5, clasps: 2 },
|
||||
parts: 3, ownSlot: 'brass', borrowSlot: 'leather', closed: true,
|
||||
variants: [{ bands: 0 }, { clasps: 0 }, { thickness: 0.14 }],
|
||||
|
|
@ -482,8 +514,14 @@ const CASES: readonly Case[] = [
|
|||
shellRatio: 0.85, variants: [{ fill: 0 }, { seal: 0 }, { hue: 0.7 }],
|
||||
maxSize: [0.09, 0.15, 0.09] },
|
||||
{ id: 'coin-pouch', make: as(createPouch), patch: { coins: 18, fill: 0.4 },
|
||||
parts: 3, ownSlot: 'brass', borrowSlot: 'leather', radial: true, radialPart: 'pouch',
|
||||
shellRatio: 0.8, variants: [{ coins: 0 }, { fill: 1 }, { coinRadius: 0.02 }],
|
||||
parts: 3, ownSlot: 'steel', borrowSlot: 'leather', radial: true, radialPart: 'pouch',
|
||||
// Back on the default shell ratio. At 0.8 the net reached BEHIND the skin:
|
||||
// the pouch now carries whipstitches, small solid bars half sunk into the
|
||||
// wall, and their buried inner faces sit well above 0.8 of the widest
|
||||
// radius in their band. They are correctly wound and permanently hidden,
|
||||
// and the check called all fifteen of them reversed. At 0.94 it sees 44
|
||||
// outer faces, comfortably over its own minimum of 20, and none reversed.
|
||||
variants: [{ coins: 0 }, { fill: 1 }, { coinRadius: 0.02 }],
|
||||
maxSize: [0.32, 0.14, 0.32] },
|
||||
{ id: 'wicker-basket', make: as(createBasket), patch: { stakes: 14, rows: 9 },
|
||||
parts: 3, ownSlot: 'produce', borrowSlot: 'oak', radial: true, radialPart: 'rim',
|
||||
|
|
@ -526,6 +564,8 @@ for (const testCase of CASES) {
|
|||
expect('no NaN/Infinity vertices', report.nonFinite === 0)
|
||||
expect('bounds finite', report.size.every(Number.isFinite))
|
||||
expect('within lowpoly budget (< 2500 triangles)', report.triangles < 2500)
|
||||
expect(`no part crushed to black${report.crushed.length ? ' — CRUSHED: ' + report.crushed.join(', ') : ''}`,
|
||||
report.crushed.length === 0)
|
||||
if (testCase.nothingAbove) {
|
||||
const top = model.parts[testCase.nothingAbove]
|
||||
const above: string[] = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue