medieval-kit/my-registry/models/wooden-ladder/model.ts
CRT 50c7fc60b9 Translate the whole repository to English
The kit is going public, so everything a reader sees is now English:
27 model sources, the core vocabulary, meta.ts (titles, descriptions and
every slider label), the viewer UI, all script output, REFERENCE.md and
the READMEs.

Rules applied: only comments, doc comments and human-facing strings were
touched. Identifiers, numbers, logic, registry item ids, part names and
material slot names are unchanged — those are a published contract and
were already English.

Verified rather than assumed: for all 53 changed .ts files the code
skeleton (source with comments stripped and string contents replaced by a
placeholder) is byte-identical before and after. Full gate is green —
typecheck, registry conformance, ~510 model checks, GLB round trip and a
production build.

Also fixed here:
- index.html and viewer.html were missed by the translation pass because
  the file list only covered .ts/.md/.css. Both had lang="tr" and Turkish
  titles.
- The viewer formatted triangle counts with toLocaleString('tr-TR'), which
  prints 15.425 rather than 15,425.
- REFERENCE.md's model table header did not match what
  scripts/catalog-table.ts emits, so the next regeneration would have
  silently changed it. Aligned to the generator.
- Removed scripts/probe.ts and scripts/zdiag.ts; they were throwaway
  diagnostics that got committed by accident.
2026-08-21 14:35:13 +07:00

98 lines
2.9 KiB
TypeScript

/**
* @medieval-kit/wooden-ladder
*
* Two rails with rungs between them. The cheapest model in the kit and one of
* the highest in scene value: it suggests vertical movement in a scene.
*
* The rungs go INTO the rails (a housed joint), so no surface sits on the same
* plane as the surface of the rails.
*/
import { Color } from 'three'
import {
chamferedBoxGeometry,
createKitModel,
jitter,
MEDIEVAL_PALETTE,
mergeColoured,
} from '../core/index.ts'
export interface WoodenLadderConfig {
readonly height: number
/** Distance between the rails (metres). */
readonly width: number
readonly rungCount: number
/** How much the rails narrow towards the top. 0 = parallel. */
readonly taper: number
readonly seed: number
}
export const woodenLadderDefaults: WoodenLadderConfig = {
height: 2.2,
width: 0.42,
rungCount: 8,
taper: 0.18,
seed: 4,
}
export type WoodenLadderParts = 'rails' | 'rungs'
export function createModel(overrides: Partial<WoodenLadderConfig> = {}) {
return createKitModel<WoodenLadderConfig, 'oak', WoodenLadderParts>({
id: 'wooden-ladder',
defaults: woodenLadderDefaults,
slots: ['oak'],
build: ({ config, random }) => {
const tint = new Color()
const shade = (lift = 0): Color => {
tint.copy(MEDIEVAL_PALETTE.oak)
tint.offsetHSL(jitter(random, 0.012), jitter(random, 0.05), lift + jitter(random, 0.055))
return tint
}
const railThickness = config.width * 0.1
const half = config.width / 2
// The rails converge towards the top; this single detail stops the ladder
// from being "two boards" and makes it a ladder.
const lean = half * config.taper
const rails = [-1, 1].map((side) => {
const rail = chamferedBoxGeometry(
[railThickness, railThickness * 1.35],
[railThickness * 0.85, railThickness * 1.15],
config.height,
railThickness * 0.16,
[0, 0, 0],
shade(),
)
// Lean it slightly around the Z axis: bottom end out, top end in.
rail.rotateZ((side * -lean) / config.height)
rail.translate(side * half, 0, 0)
return rail
})
const rungs = []
const count = Math.max(2, config.rungCount)
for (let i = 0; i < count; i += 1) {
const t = (i + 0.5) / count
const y = -config.height / 2 + t * config.height
// The rung is a little LONGER than the rail gap at that height, so that
// its ends stay inside the rails.
const span = (half - lean * t) * 2 + railThickness * 0.9
rungs.push(chamferedBoxGeometry(
[span, railThickness * 1.05],
[span, railThickness * 1.05],
railThickness * 0.8,
railThickness * 0.16,
[0, y, 0],
shade(0.03),
))
}
return {
rails: { slot: 'oak', geometry: mergeColoured(rails) },
rungs: { slot: 'oak', geometry: mergeColoured(rungs) },
}
},
}, overrides)
}