Take the oak out

Five attempts and it was never good. The last one is better than the cabbage
that prompted the complaint, and "better than the version you called ugly" is
not a standard worth shipping against — every other model here would have to
carry it.

The constraint underneath is real and worth recording, because it is not a
tuning problem and no sixth attempt was going to find it. The kit's budget is
2500 triangles a model. The oak wanted a bole you can see, limbs radiating out
of it, and a dome of foliage over the lot; at 2500 that is roughly 128 for the
trunk, 880 for the boughs and 1400 for the crown, and 1400 buys about forty
masses. Forty masses hung on twelve limbs is twelve clusters, and twelve
clusters do not make a dome — from a third of the compass you see the gaps
between them. A turntable says so plainly where a single three-quarter view
does not, which is the other thing to keep: I judged this model on one angle
for four rounds.

Everything else in this kit is something a person made, with flat faces and
straight edges, and lowpoly is not a compromise for those — it is close to how
they are actually built. A tree is the one subject where the budget genuinely
bites, and the honest options were to except it from the budget, to abandon
realism for a deliberately stylised shape, or to drop it. Dropped.

Out with it goes the `leaf` slot and its palette key, since the oak was the
only thing using either. Back to thirteen slots. `bark` stays, because the log
pile uses it; `limestone` stays, because the trough and the grindstone do.
`scripts/probe-tree.ts` goes too — it measured one model against one pair of
photographs and there is no longer a model.

37 models, 30 390 triangles, thirteen material slots, all checks pass, 0
floating cases, GLB round-trip clean, Conformant, documentation in step.
This commit is contained in:
CRTkafa 2026-08-27 07:25:26 +00:00
parent 7ddfc6c097
commit 37aa839be9
16 changed files with 13 additions and 1712 deletions

View file

@ -1,188 +0,0 @@
/**
* Measures the oak against the numbers taken off the reference photographs.
*
* Rendering the tree and looking at it says "the crown is a ring of separate
* balls". That is a real observation and a useless one to act on, because it
* does not say by how much or where. This prints the four numbers the
* references gave, measured off the built geometry the same way they were
* measured off the photographs:
*
* crown width / height reference 1.32 – 1.43
* height of the widest point reference 0.24
* bole width / height at 0.02 reference 0.130, at 0.10 reference 0.073
*
* and one number the photographs cannot give, because a photograph of a tree
* is a single connected mass by definition: how many SEPARATE PIECES the crown
* is in. A crown of one piece is foliage. A crown of fourteen is broccoli.
*/
import { Box3, Vector3, type Mesh, type Object3D } from 'three'
import { createModel } from '@/models/medieval-kit/oak-tree/model.ts'
const model = createModel()
const box = new Box3().setFromObject(model.root)
const size = box.getSize(new Vector3())
const H = size.y
const W = Math.max(size.x, size.z)
console.log(`overall ${size.x.toFixed(2)} x ${size.y.toFixed(2)} x ${size.z.toFixed(2)}`)
console.log(`CROWN WIDTH / HEIGHT = ${(W / H).toFixed(3)} (reference 1.32 – 1.43)`)
/** Every triangle of a part, in world space. */
function triangles(part: Object3D): Float32Array[] {
const out: Float32Array[] = []
part.updateWorldMatrix(true, true)
part.traverse((child) => {
const mesh = child as Mesh
if (!mesh.isMesh) return
const pos = mesh.geometry.getAttribute('position')
const v = new Vector3()
const tri = new Float32Array(9)
for (let i = 0; i < pos.count; i += 3) {
for (let k = 0; k < 3; k += 1) {
v.fromBufferAttribute(pos, i + k).applyMatrix4(mesh.matrixWorld)
tri[k * 3] = v.x; tri[k * 3 + 1] = v.y; tri[k * 3 + 2] = v.z
}
out.push(tri.slice())
}
})
return out
}
// --- width profile, sampled the same way the photographs were: by height band
const N = 25
const bands: Array<{ min: number; max: number }> = Array.from(
{ length: N }, () => ({ min: Infinity, max: -Infinity }),
)
for (const t of triangles(model.root)) {
for (let k = 0; k < 3; k += 1) {
const y = t[k * 3 + 1]!
const r = Math.hypot(t[k * 3]!, t[k * 3 + 2]!)
const b = Math.min(N - 1, Math.max(0, Math.floor(((y - box.min.y) / H) * N)))
// The EXTENT of the row, not twice its radius.
//
// The photographs were measured by counting how far apart the leftmost and
// rightmost tree pixels were on each row. Measuring our own geometry as
// 2 x max-radius instead is a different quantity on any tree that is not
// symmetric -- which is every tree -- and it read 42% for a crown whose
// widest ROW is much lower down. Comparing a number against a reference
// means measuring it the same way the reference was measured.
bands[b]!.min = Math.min(bands[b]!.min, t[k * 3]!)
bands[b]!.max = Math.max(bands[b]!.max, t[k * 3]!)
}
}
let widest = { at: 0, w: 0 }
console.log('\nheight% width profile')
for (let b = 0; b < N; b += 1) {
const w = bands[b]!.max === -Infinity ? 0 : bands[b]!.max - bands[b]!.min
const pct = ((b + 0.5) / N) * 100
if (w > widest.w) widest = { at: pct, w }
console.log(` ${pct.toFixed(0).padStart(3)}% ${w.toFixed(2).padStart(6)} ${'#'.repeat(Math.round((w / W) * 46))}`)
}
console.log(`widest at ${widest.at.toFixed(0)}% of height (reference 24%)`)
// --- where the crown starts. The reference's lowest leaves are at 11% of the
// height and it is at full width by 24%; a crown that reaches lower than that
// is a bush, and one that starts higher is a lollipop.
if (model.parts.crown) {
const ys = triangles(model.parts.crown.anchor).flatMap((t) => [t[1]!, t[4]!, t[7]!])
console.log(`crown hangs from ${(((Math.min(...ys)) - box.min.y) / H * 100).toFixed(0)}% of the height (reference 11%)`)
}
// --- the bole, measured at the two heights the photograph was measured at
const trunkTris = triangles(model.parts.trunk.anchor)
for (const at of [0.02, 0.06, 0.1, 0.38]) {
const y = box.min.y + H * at
let r = 0
for (const t of trunkTris) {
for (let k = 0; k < 3; k += 1) {
if (Math.abs(t[k * 3 + 1]! - y) < H * 0.012) r = Math.max(r, Math.hypot(t[k * 3]!, t[k * 3 + 2]!))
}
}
console.log(`bole at ${(at * 100).toFixed(0).padStart(2)}% of height: ${(r * 2 / H).toFixed(4)} of height wide`)
}
/**
* How many separate pieces is the crown in?
*
* The same voxel trick the support check uses: drop every triangle corner into
* a grid, then flood fill through the 26 neighbours. Two clumps that overlap
* share cells and come out as one piece; two that merely sit near each other
* do not.
*/
const crown = model.parts.crown?.anchor
if (crown) {
const cell = W / 90
const key = (x: number, y: number, z: number): string => `${x},${y},${z}`
const cells = new Set<string>()
for (const t of triangles(crown)) {
// Sample along each edge as well as at the corners, or a large flat facet
// spans several cells and tears into separate pieces on its own.
for (let e = 0; e < 3; e += 1) {
const a = e * 3
const b = ((e + 1) % 3) * 3
const steps = Math.max(1, Math.ceil(
Math.hypot(t[b]! - t[a]!, t[b + 1]! - t[a + 1]!, t[b + 2]! - t[a + 2]!) / (cell * 0.6),
))
for (let s = 0; s <= steps; s += 1) {
const f = s / steps
cells.add(key(
Math.round((t[a]! + (t[b]! - t[a]!) * f) / cell),
Math.round((t[a + 1]! + (t[b + 1]! - t[a + 1]!) * f) / cell),
Math.round((t[a + 2]! + (t[b + 2]! - t[a + 2]!) * f) / cell),
))
}
}
}
const seen = new Set<string>()
const sizes: Array<{ count: number; cells: string[] }> = []
for (const start of cells) {
if (seen.has(start)) continue
let count = 0
const piece: string[] = []
const stack = [start]
seen.add(start)
while (stack.length > 0) {
const at = stack.pop()!
count += 1
piece.push(at)
const [x, y, z] = at.split(',').map(Number) as [number, number, number]
for (let dx = -1; dx <= 1; dx += 1) {
for (let dy = -1; dy <= 1; dy += 1) {
for (let dz = -1; dz <= 1; dz += 1) {
const n = key(x + dx, y + dy, z + dz)
if (cells.has(n) && !seen.has(n)) { seen.add(n); stack.push(n) }
}
}
}
}
sizes.push({ count, cells: piece })
}
sizes.sort((a, b) => b.count - a.count)
console.log(`\nCROWN IS IN ${sizes.length} PIECE(S) (gaps are wanted; the support check owns whether any of them float)`)
// WHERE a piece is matters more than how big it is: a tear low down means
// the bottom limbs have outrun the rest, a tear at one bearing means a gap
// between two neighbours, a tear far out means a limb reaching past its
// fellows. Guessing which of the three it was cost two rounds of tuning that
// each fixed nothing.
for (const piece of sizes.slice(0, 6)) {
let y0 = Infinity, y1 = -Infinity, r0 = Infinity, r1 = -Infinity
const bearings: number[] = []
for (const c of piece.cells) {
const [x, y, z] = c.split(',').map(Number) as [number, number, number]
const yy = (y * cell - box.min.y) / H * 100
const rr = Math.hypot(x * cell, z * cell)
if (yy < y0) y0 = yy
if (yy > y1) y1 = yy
if (rr < r0) r0 = rr
if (rr > r1) r1 = rr
bearings.push(((Math.atan2(z, x) * 180) / Math.PI + 360) % 360)
}
bearings.sort((a, b) => a - b)
console.log(` ${String(piece.count).padStart(6)} cells `
+ `height ${y0.toFixed(0)}-${y1.toFixed(0)}% `
+ `radius ${r0.toFixed(1)}-${r1.toFixed(1)}m `
+ `bearing ${bearings[0]!.toFixed(0)}-${bearings[bearings.length - 1]!.toFixed(0)}deg`)
}
}
model.dispose()

View file

@ -56,7 +56,6 @@ import { createModel as createCart } from '@/models/medieval-kit/hand-cart/model
import { createModel as createVeg } from '@/models/medieval-kit/vegetables/model.ts'
import { createModel as createShield } from '@/models/medieval-kit/round-shield/model.ts'
import { createModel as createForge } from '@/models/medieval-kit/forge-hearth/model.ts'
import { createModel as createOak } from '@/models/medieval-kit/oak-tree/model.ts'
import { createModel as createTrough } from '@/models/medieval-kit/stone-trough/model.ts'
import { createModel as createGrind } from '@/models/medieval-kit/grindstone/model.ts'
import { createModel as createStall } from '@/models/medieval-kit/market-stall/model.ts'
@ -348,10 +347,6 @@ const CASES: readonly Case[] = [
parts: 2, ownSlot: 'water', borrowSlot: 'stone',
variants: [{ water: 0 }, { wall: 0.12 }, { wall: 0.34 }, { height: 0.25 }],
maxSize: [2.8, 0.8, 1.1] },
{ id: 'oak-tree', make: as(createOak), patch: { limbs: 11, spread: 1.5 },
parts: 3, ownSlot: 'leaf', borrowSlot: 'oak',
variants: [{ leafiness: 0 }, { limbs: 3 }, { autumn: 1 }, { spread: 0.6 }, { height: 3 }],
maxSize: [22, 14, 22] },
{ id: 'forge-hearth', make: as(createForge), patch: { kerbBlocks: 24, chimney: 1.6 },
parts: 4, ownSlot: 'stone', borrowSlot: 'oak',
variants: [{ lit: 0 }, { kerbBlocks: 8 }, { chimney: 0.3 }],