diff --git a/models.lock.json b/models.lock.json index 6e3d234..424377a 100644 --- a/models.lock.json +++ b/models.lock.json @@ -67,7 +67,7 @@ "address": "@medieval-kit/wooden-barrel", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.921Z", + "installedAt": "2026-08-23T04:07:08.688Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-barrel\\model.ts", @@ -82,11 +82,11 @@ "address": "@medieval-kit/core", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.903Z", + "installedAt": "2026-08-23T04:07:08.667Z", "files": [ { "path": "src\\models\\medieval-kit\\core\\geometry.ts", - "sourceHash": "cc31b4aa717efc038158f5cf6d8de9b5329665eadf5be2120adaddaf7f15ebdc" + "sourceHash": "b47141c115c48d48e3a4c643fe9634343458288688ea586f044e6a7e7cdbaad5" }, { "path": "src\\models\\medieval-kit\\core\\index.ts", @@ -129,7 +129,7 @@ "address": "@medieval-kit/wooden-crate", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.925Z", + "installedAt": "2026-08-23T04:07:08.693Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-crate\\model.ts", @@ -144,7 +144,7 @@ "address": "@medieval-kit/kit", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.931Z", + "installedAt": "2026-08-23T04:07:08.700Z", "files": [], "dependencies": [] }, @@ -152,7 +152,7 @@ "address": "@medieval-kit/iron-anvil", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.910Z", + "installedAt": "2026-08-23T04:07:08.676Z", "files": [ { "path": "src\\models\\medieval-kit\\iron-anvil\\model.ts", @@ -167,7 +167,7 @@ "address": "@medieval-kit/wooden-bucket", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.924Z", + "installedAt": "2026-08-23T04:07:08.690Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-bucket\\model.ts", @@ -182,7 +182,7 @@ "address": "@medieval-kit/wooden-fence", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.926Z", + "installedAt": "2026-08-23T04:07:08.694Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-fence\\model.ts", @@ -197,7 +197,7 @@ "address": "@medieval-kit/wooden-hoe", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.928Z", + "installedAt": "2026-08-23T04:07:08.695Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-hoe\\model.ts", @@ -212,7 +212,7 @@ "address": "@medieval-kit/wooden-ladder", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.929Z", + "installedAt": "2026-08-23T04:07:08.696Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-ladder\\model.ts", @@ -227,7 +227,7 @@ "address": "@medieval-kit/wooden-pitchfork", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.930Z", + "installedAt": "2026-08-23T04:07:08.697Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-pitchfork\\model.ts", @@ -242,7 +242,7 @@ "address": "@medieval-kit/wooden-shovel", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.930Z", + "installedAt": "2026-08-23T04:07:08.698Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-shovel\\model.ts", @@ -257,7 +257,7 @@ "address": "@medieval-kit/wooden-stool", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.931Z", + "installedAt": "2026-08-23T04:07:08.700Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-stool\\model.ts", @@ -272,7 +272,7 @@ "address": "@medieval-kit/cart-wheel", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.906Z", + "installedAt": "2026-08-23T04:07:08.671Z", "files": [ { "path": "src\\models\\medieval-kit\\cart-wheel\\model.ts", @@ -287,7 +287,7 @@ "address": "@medieval-kit/log-pile", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.915Z", + "installedAt": "2026-08-23T04:07:08.680Z", "files": [ { "path": "src\\models\\medieval-kit\\log-pile\\model.ts", @@ -302,7 +302,7 @@ "address": "@medieval-kit/trestle-table", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.919Z", + "installedAt": "2026-08-23T04:07:08.686Z", "files": [ { "path": "src\\models\\medieval-kit\\trestle-table\\model.ts", @@ -317,7 +317,7 @@ "address": "@medieval-kit/wooden-chest", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.924Z", + "installedAt": "2026-08-23T04:07:08.691Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-chest\\model.ts", @@ -332,7 +332,7 @@ "address": "@medieval-kit/hay-bale", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.909Z", + "installedAt": "2026-08-23T04:07:08.674Z", "files": [ { "path": "src\\models\\medieval-kit\\hay-bale\\model.ts", @@ -347,7 +347,7 @@ "address": "@medieval-kit/pitch-torch", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.917Z", + "installedAt": "2026-08-23T04:07:08.682Z", "files": [ { "path": "src\\models\\medieval-kit\\pitch-torch\\model.ts", @@ -362,7 +362,7 @@ "address": "@medieval-kit/wooden-bench", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.923Z", + "installedAt": "2026-08-23T04:07:08.689Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-bench\\model.ts", @@ -377,7 +377,7 @@ "address": "@medieval-kit/linen-sack", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.914Z", + "installedAt": "2026-08-23T04:07:08.679Z", "files": [ { "path": "src\\models\\medieval-kit\\linen-sack\\model.ts", @@ -392,7 +392,7 @@ "address": "@medieval-kit/oak-tankard", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.915Z", + "installedAt": "2026-08-23T04:07:08.681Z", "files": [ { "path": "src\\models\\medieval-kit\\oak-tankard\\model.ts", @@ -407,7 +407,7 @@ "address": "@medieval-kit/straw-broom", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.918Z", + "installedAt": "2026-08-23T04:07:08.683Z", "files": [ { "path": "src\\models\\medieval-kit\\straw-broom\\model.ts", @@ -422,7 +422,7 @@ "address": "@medieval-kit/bronze-bell", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.905Z", + "installedAt": "2026-08-23T04:07:08.669Z", "files": [ { "path": "src\\models\\medieval-kit\\bronze-bell\\model.ts", @@ -437,7 +437,7 @@ "address": "@medieval-kit/iron-lantern", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.912Z", + "installedAt": "2026-08-23T04:07:08.677Z", "files": [ { "path": "src\\models\\medieval-kit\\iron-lantern\\model.ts", @@ -452,7 +452,7 @@ "address": "@medieval-kit/tavern-sign", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.919Z", + "installedAt": "2026-08-23T04:07:08.685Z", "files": [ { "path": "src\\models\\medieval-kit\\tavern-sign\\model.ts", @@ -467,7 +467,7 @@ "address": "@medieval-kit/coin-pouch", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.907Z", + "installedAt": "2026-08-23T04:07:08.672Z", "files": [ { "path": "src\\models\\medieval-kit\\coin-pouch\\model.ts", @@ -482,7 +482,7 @@ "address": "@medieval-kit/glass-phial", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.908Z", + "installedAt": "2026-08-23T04:07:08.673Z", "files": [ { "path": "src\\models\\medieval-kit\\glass-phial\\model.ts", @@ -497,7 +497,7 @@ "address": "@medieval-kit/leather-book", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.913Z", + "installedAt": "2026-08-23T04:07:08.678Z", "files": [ { "path": "src\\models\\medieval-kit\\leather-book\\model.ts", @@ -512,7 +512,7 @@ "address": "@medieval-kit/wicker-basket", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-22T07:04:36.920Z", + "installedAt": "2026-08-23T04:07:08.687Z", "files": [ { "path": "src\\models\\medieval-kit\\wicker-basket\\model.ts", diff --git a/my-registry/models/core/geometry.ts b/my-registry/models/core/geometry.ts index 7c939bc..46d4a0c 100644 --- a/my-registry/models/core/geometry.ts +++ b/my-registry/models/core/geometry.ts @@ -702,6 +702,36 @@ export function mergeColoured(geometries: readonly BufferGeometry[]): BufferGeom export function bendGeometry(geometry: BufferGeometry, curvature: number): BufferGeometry { if (Math.abs(curvature) < 1e-9) return geometry const position = geometry.getAttribute('position') + + // A bend needs something to bend. + // + // Every vertex is mapped by its own Y, so the curve only exists where there + // are Y levels to sample it at. Hand this a `boxGeometry` -- two levels, top + // and bottom -- and there is no midpoint to displace: the top face swings to + // one angle, the bottom to another, and the result is a sheared wedge that + // looks nothing like an arc. It fails silently, which is the expensive part. + // + // This session found the same mistake in three separate models: the + // tankard's handle, and both the brace and the curl of the tavern sign. In + // each the author had written a curve, the geometry had never curved, and + // the renders had been shipping the wedge. Three is a pattern, so the + // helper refuses rather than waiting for a fourth. + // + // The fix is never to nudge the curvature -- it is to give the piece levels + // (a lathe or a stack of them), or to use `arcBarGeometry`, which sweeps a + // real arc and takes the two things that actually matter: where the ends go. + const seen = new Set() + for (let i = 0; i < position.count && seen.size < 3; i += 1) { + seen.add(Math.round(position.getY(i) * 1e5)) + } + if (seen.size < 3) { + throw new Error( + `bendGeometry: geometry has ${seen.size} distinct Y level(s); a bend needs at least 3. ` + + 'Two levels shear into a wedge instead of curving. Build the piece with ' + + 'levels (latheGeometry / staveGeometry) or use arcBarGeometry.', + ) + } + const radius = 1 / curvature for (let i = 0; i < position.count; i += 1) { const y = position.getY(i) diff --git a/src/models/medieval-kit/core/geometry.ts b/src/models/medieval-kit/core/geometry.ts index 7c939bc..46d4a0c 100644 --- a/src/models/medieval-kit/core/geometry.ts +++ b/src/models/medieval-kit/core/geometry.ts @@ -702,6 +702,36 @@ export function mergeColoured(geometries: readonly BufferGeometry[]): BufferGeom export function bendGeometry(geometry: BufferGeometry, curvature: number): BufferGeometry { if (Math.abs(curvature) < 1e-9) return geometry const position = geometry.getAttribute('position') + + // A bend needs something to bend. + // + // Every vertex is mapped by its own Y, so the curve only exists where there + // are Y levels to sample it at. Hand this a `boxGeometry` -- two levels, top + // and bottom -- and there is no midpoint to displace: the top face swings to + // one angle, the bottom to another, and the result is a sheared wedge that + // looks nothing like an arc. It fails silently, which is the expensive part. + // + // This session found the same mistake in three separate models: the + // tankard's handle, and both the brace and the curl of the tavern sign. In + // each the author had written a curve, the geometry had never curved, and + // the renders had been shipping the wedge. Three is a pattern, so the + // helper refuses rather than waiting for a fourth. + // + // The fix is never to nudge the curvature -- it is to give the piece levels + // (a lathe or a stack of them), or to use `arcBarGeometry`, which sweeps a + // real arc and takes the two things that actually matter: where the ends go. + const seen = new Set() + for (let i = 0; i < position.count && seen.size < 3; i += 1) { + seen.add(Math.round(position.getY(i) * 1e5)) + } + if (seen.size < 3) { + throw new Error( + `bendGeometry: geometry has ${seen.size} distinct Y level(s); a bend needs at least 3. ` + + 'Two levels shear into a wedge instead of curving. Build the piece with ' + + 'levels (latheGeometry / staveGeometry) or use arcBarGeometry.', + ) + } + const radius = 1 / curvature for (let i = 0; i < position.count; i += 1) { const y = position.getY(i)