The first thing in this kit that grew rather than got made, and the first one
built entirely against reference photographs from the start rather than after
three rounds of guessing.
Two references, generated with the same Codex tool the rest of the kit now
uses: one oak in full leaf and the same tree bare. Both of them contradicted
what I was about to build, and the default lowpoly tree -- a tall pole with a
ball on it -- turns out to be wrong in every measurement that matters.
crown width / tree height 1.32 to 1.43. An open-grown oak is half again
as WIDE as it is tall. Nothing else in this kit
is wider than it is tall.
widest at 24% of the height. Not halfway up: a quarter,
just above the ground, because the lowest limbs
are the longest and leave almost horizontally.
bole runs to 72% of the height as one continuous stem. It
does not fork low into equal leaders, which is
what the leafy photograph alone suggested and
the winter one disproved.
bole width / height 0.130 at 2% of the height, 0.073 at 10%. It
nearly halves in the bottom tenth and then
barely tapers at all for a quarter of the tree.
The taper table in the model is those rows, read off the photograph one at a
time. The limbs SWEEP -- out at a shallow angle, turning up at the end -- which
comes free from bending each limb along its own axis before rotating it into
place, and which cost a correction I had not expected: bending a limb swings
its whole chord up by half the arc, so every limb was arriving 0.21 rad high
and the crown's widest point had climbed to 38%. Aiming low by exactly what the
bend will lift is the fix, and it is a constant.
Measuring is the whole story of this one. `scripts/probe-tree.ts` prints the
four reference numbers off the built geometry the same way they came off the
photographs, plus one a photograph cannot give: how many separate pieces the
crown is in. A crown is one piece. This one was four, then one, then two, then
one again, and the flood fill was right every time my eye was vague.
Four things it caught that looking would not have:
- Forks throwing DOWNWARD. The rise of a fork is sin(splay) * sin(spin), so
the sign of the PRODUCT decides it. I constrained the spin and alternated
the splay, which left every second fork pointing at the floor. The
measurement said so plainly while the reasoning said the opposite.
- The crown torn in two, and not where I kept looking. Locating the loose
piece -- height 10-64%, bearing 228-313, reaching 5.7 m where the main mass
stopped at 4.5 -- ended four rounds of widening clumps and evening out
bearings, none of which were the gap. The gap was the MIDDLE: pushing the
leaves outboard to open the space under the crown had taken the inside out
with it, and nine lobes hung off a bare hub. The reference's crown is full
from the bole outward; the clear space is underneath.
- Occlusion, exonerated. Turning it off entirely changed the clipping by
nothing at all, which took two minutes and saved a redesign.
- My own metric, wrong twice. It counted every dark pixel in the crown's box
and 87% of what it found was the cast shadow, so it read 10.8% clipping on
a crown that was barely clipping. And it measured the reference by row
width but our own geometry by twice its radius, which is a different
quantity on anything that is not symmetric.
Colour is measured too, and the measurement contradicted me again: I was about
to bake a top-to-bottom gradient into the crown, and sampled in three bands the
reference reads 0.362, 0.336, 0.324 -- no gradient at all. What is there is
local, a spread of 0.45 in lightness within one band. Foliage varies leaf to
leaf, not top to bottom. Chasing that 0.45 with tint, mottle and occlusion all
at once put 2.2% of the crown through the floor into pure black against the
reference's 0.19%, which is the straw trap for the third time: a statistic taken
off fine detail cannot be added on top of the machinery that already
reproduces it.
The bark is measured off the WINTER photograph after the summer one gave a
colour 28 degrees too green -- a trunk under a full crown is lit through the
leaves. Low saturation made it worse than the hue did: a nearly neutral colour
takes its hue from its light, and this renderer's blue-grey sky dragged the
rendered bole to hue 119 on a tree whose bark is brown.
Finished: hue 79.6 against 77.9, saturation 0.386 against 0.381, lightness
0.386 against 0.373, 0.00% clipped. Crown 1.325 wide for its height, in one
piece, hanging from 8% where the reference hangs from 11%.
The honest limits. What fills a real winter silhouette is thousands of twigs
and no budget here reaches them, so `leafiness: 0` is a bare tree of LIMBS --
a good dead or winter tree, not a photograph of one. And the crown still
carries more of its width high than the reference does: widest at 50% against
24%, on a reference profile that is nearly flat from 24 to 44 so the peak is
softer than the number sounds.
2310 triangles, inside the kit's 2500 budget, which cost a side off every clump
and a level off every fork -- but not one clump, because the count is what
holds the crown together. 35 models, 31 404 triangles, thirteen material slots,
all checks pass, 0 floating cases, GLB round-trip clean, Conformant.
188 lines
7.7 KiB
TypeScript
188 lines
7.7 KiB
TypeScript
/**
|
|
* 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} SEPARATE PIECE(S) (a crown should be 1)`)
|
|
// 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()
|