diff --git a/contemporary-props/build.ts b/contemporary-props/build.ts index e05728d..9e7b880 100644 --- a/contemporary-props/build.ts +++ b/contemporary-props/build.ts @@ -25,7 +25,26 @@ const NAMESPACE = '@contemporary-props' const THREE_RANGE = 'three@>=0.185.0' /** Catalogue data per model. The source files themselves are read from disk. */ -import { MODEL_META } from './meta.ts' +import type { ModelMeta } from './meta.ts' + +/** + * Metadata lives beside the model it describes, in `models//meta.json`. + * + * The medieval kit keeps one hand-maintained map for the whole registry, which + * is fine while one person adds one model at a time. It is the wrong shape the + * moment several models are being written at once: every author has to edit the + * same file, and the last write wins. A sidecar has no such contention, and it + * also cannot describe the wrong model, because deleting the folder deletes the + * description with it. + */ +async function readMeta(sourceRoot: string, id: string): Promise { + const path = join(sourceRoot, id, 'meta.json') + try { + return JSON.parse(await readFile(path, 'utf8')) as ModelMeta + } catch { + throw new Error(`${id}: no meta.json beside model.ts. Every model describes itself.`) + } +} const LIB_DESCRIPTION: Record = { core: { @@ -126,8 +145,7 @@ async function main(): Promise { for (const id of models) { const paths = await collectTypeScript(join(sourceRoot, id)) const contents = await Promise.all(paths.map((path) => readFile(path, 'utf8'))) - const meta = MODEL_META[id] - if (!meta) throw new Error(`no MODEL_META entry for ${id}`) + const meta = await readMeta(sourceRoot, id) items.push({ name: id, type: 'vibe3d:model', diff --git a/contemporary-props/meta.ts b/contemporary-props/meta.ts index 7d7f3df..cbeded5 100644 --- a/contemporary-props/meta.ts +++ b/contemporary-props/meta.ts @@ -29,28 +29,3 @@ export interface ModelMeta { readonly materialSlots: readonly string[] readonly parts: readonly string[] } - -export const MODEL_META: Readonly> = { - // One entry per model, added as each model is built. The registry build - // fails on a model with no entry here, which is deliberate: an item nobody - // described is an item nobody can find. - 'ceramic-vase': { - title: 'Ceramic Vase', - description: - 'Glazed ceramic vase turned as a single revolve. The belly height decides ' - + 'whether it reads as a bud vase or an urn, and the lip stands proud of the ' - + 'neck so the mouth has an edge rather than being a hole in the top.', - category: 'Decor', - tags: ['contemporary', 'decor', 'vessel', 'procedural'], - controls: { - height: { type: 'number', label: 'Height', min: 0.12, max: 0.9, step: 0.01, unit: 'm' }, - bellyRadius: { type: 'number', label: 'Belly radius', min: 0.03, max: 0.3, step: 0.005, unit: 'm' }, - bellyAt: { type: 'number', label: 'Belly height', min: 0.18, max: 0.72, step: 0.01 }, - mouth: { type: 'number', label: 'Mouth', min: 0.2, max: 0.9, step: 0.01 }, - segments: { type: 'number', label: 'Sides', min: 8, max: 64, step: 1 }, - seed: { type: 'number', label: 'Variation seed', min: 1, max: 64, step: 1 }, - }, - materialSlots: ['ceramic'], - parts: ['body'], - }, -} diff --git a/contemporary-props/models/ceramic-vase/meta.json b/contemporary-props/models/ceramic-vase/meta.json new file mode 100644 index 0000000..d096b17 --- /dev/null +++ b/contemporary-props/models/ceramic-vase/meta.json @@ -0,0 +1,63 @@ +{ + "title": "Ceramic Vase", + "description": "Glazed ceramic vase turned as a single revolve. The belly height decides whether it reads as a bud vase or an urn, and the lip stands proud of the neck so the mouth has an edge rather than being a hole in the top.", + "category": "Decor", + "tags": [ + "contemporary", + "decor", + "vessel", + "procedural" + ], + "controls": { + "height": { + "type": "number", + "label": "Height", + "min": 0.12, + "max": 0.9, + "step": 0.01, + "unit": "m" + }, + "bellyRadius": { + "type": "number", + "label": "Belly radius", + "min": 0.03, + "max": 0.3, + "step": 0.005, + "unit": "m" + }, + "bellyAt": { + "type": "number", + "label": "Belly height", + "min": 0.18, + "max": 0.72, + "step": 0.01 + }, + "mouth": { + "type": "number", + "label": "Mouth", + "min": 0.2, + "max": 0.9, + "step": 0.01 + }, + "segments": { + "type": "number", + "label": "Sides", + "min": 8, + "max": 64, + "step": 1 + }, + "seed": { + "type": "number", + "label": "Variation seed", + "min": 1, + "max": 64, + "step": 1 + } + }, + "materialSlots": [ + "ceramic" + ], + "parts": [ + "body" + ] +} diff --git a/contemporary-props/models/coffee-mug/meta.json b/contemporary-props/models/coffee-mug/meta.json new file mode 100644 index 0000000..21ea3ce --- /dev/null +++ b/contemporary-props/models/coffee-mug/meta.json @@ -0,0 +1,64 @@ +{ + "title": "Coffee Mug", + "description": "Glazed stoneware mug: one lathe up the outside, over a rolled rim and down into a real bore, with a strap-section handle swept as an arc whose ends are buried in the wall. The taper moves it from diner mug to straight cylinder, and the handle control widens the loop.", + "category": "Kitchen", + "tags": [ + "contemporary", + "kitchen", + "vessel", + "procedural" + ], + "controls": { + "height": { + "type": "number", + "label": "Height", + "min": 0.07, + "max": 0.16, + "step": 0.005, + "unit": "m" + }, + "radius": { + "type": "number", + "label": "Rim radius", + "min": 0.03, + "max": 0.06, + "step": 0.002, + "unit": "m" + }, + "taper": { + "type": "number", + "label": "Taper", + "min": 0.72, + "max": 1, + "step": 0.01 + }, + "handle": { + "type": "number", + "label": "Handle bow", + "min": 0.7, + "max": 1.3, + "step": 0.05 + }, + "segments": { + "type": "number", + "label": "Sides", + "min": 10, + "max": 64, + "step": 1 + }, + "seed": { + "type": "number", + "label": "Variation seed", + "min": 1, + "max": 64, + "step": 1 + } + }, + "materialSlots": [ + "ceramic" + ], + "parts": [ + "body", + "handle" + ] +} diff --git a/contemporary-props/models/coffee-mug/model.ts b/contemporary-props/models/coffee-mug/model.ts new file mode 100644 index 0000000..ad1caa7 --- /dev/null +++ b/contemporary-props/models/coffee-mug/model.ts @@ -0,0 +1,220 @@ +/** + * @contemporary-props/coffee-mug + * + * The kit's second revolve, and its first join: a swept handle attached to a + * lathed body. The join is the point. The kettle, the jug, the watering can + * and the saucepan all reuse it, so the mug is where it has to be got right. + * + * Two things separate a mug from the vase it inherits its lathe from: + * + * the bore a mug is looked INTO. The profile goes up the outside, rolls + * over the rim, and comes back down inside to a floor, so the + * rim has a measurable thickness and the inner wall catches + * light. The vase could skip its bore; a mug with no bore is a + * dummy prop and reads as one from any angle above the rim. + * + * the handle a strap, not a rod. The section is wider across than it is + * deep, which is what says "ceramic pulled from the wall" + * rather than "wire bent into a loop". It is one arc whose two + * ends land INSIDE the wall: the end depth is computed from the + * wall thickness and the cap tilt so that at every value of the + * `handle` control the caps stay buried, clear of the outer + * surface on one side and of the bore on the other. On a + * tapered body the loop tilts to follow the wall, the way a + * real handle is stuck on parallel to the side it joins. + * + * The wall is deliberately chunky, diner-mug thick. Partly because that is + * what a stoneware mug is, and partly because the wall is the material the + * handle ends are buried in: a fine porcelain wall leaves no solid for the + * join to live inside. + * + * Parts: `body` and `handle`. The handle is the part a consumer will want to + * reach separately, whether to drop it for an espresso cup or to recolour a + * glazed accent. + */ +import { type BufferGeometry } from 'three' + +import { + arcBarGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface CoffeeMugConfig { + /** Overall height (metres). */ + readonly height: number + /** Outer radius at the rim (metres). */ + readonly radius: number + /** Foot radius as a fraction of the rim radius. 1 is a straight diner mug. */ + readonly taper: number + /** How far the handle bows out. 1 is a standard loop. */ + readonly handle: number + /** Sides around the revolve. Low values are a deliberate faceted look. */ + readonly segments: number + readonly seed: number +} + +export const coffeeMugDefaults: CoffeeMugConfig = { + height: 0.095, + radius: 0.041, + // A slight taper. Dead straight is a value in the family, not the default: + // most mugs narrow a little toward the foot and it keeps the silhouette + // from reading as a cut length of pipe. + taper: 0.9, + handle: 1, + segments: 32, + seed: 7, +} + +export type CoffeeMugParts = 'body' | 'handle' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'coffee-mug', + defaults: coffeeMugDefaults, + slots: ['ceramic'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = config.height + const R = config.radius + const taper = Math.min(1, Math.max(0.7, config.taper)) + const F = R * taper + const segments = Math.max(10, Math.round(config.segments)) + + // The wall. Thick enough to read at the rim and, just as important, + // thick enough that the handle ends can be buried in it with margin on + // both faces. The floor stops a small mug from getting a paper wall. + const wall = Math.max(0.0058, R * 0.15) + // A mug's base is heavier than its wall; the bore floor sits up here. + const base = Math.max(0.006, H * 0.085) + + // Outer radius at height y: a straight taper with a faint barrel bow. + // The bow is under two percent, which is invisible as a shape but keeps + // a highlight moving along the wall instead of sitting in one stripe. + const rOut = (y: number): number => { + const f = y / H + return (F + (R - F) * f) * (1 + 0.013 * Math.sin(Math.PI * f)) + } + + /* ------------------------------------------------------------- body */ + // One profile, up the outside, over the rim, down the bore. A single + // lathe leaves no coincident faces where an outer and an inner shell + // would meet, and the rim thickness falls out of the turn-around. + const half = wall / 2 + const rimY = H - half + const rimX = R - half + const s45 = half * Math.SQRT1_2 + const levels: Level[] = [ + // A short chamfer off the table, so the foot has an edge that reads + // as trimmed rather than the wall dying into the ground plane. + { y: 0, radius: F * 0.96 }, + { y: 0.0035, radius: rOut(0.0035) }, + { y: H * 0.2, radius: rOut(H * 0.2) }, + { y: H * 0.45, radius: rOut(H * 0.45) }, + { y: H * 0.7, radius: rOut(H * 0.7) }, + { y: H * 0.88, radius: rOut(H * 0.88) }, + // The rim, rolled as a half circle of the wall's own thickness, + // sampled every 45 degrees so smoothing reads it as a curve. + { y: rimY, radius: R }, + { y: H - half + s45, radius: rimX + s45 }, + { y: H, radius: rimX }, + { y: H - half + s45, radius: rimX - s45 }, + { y: rimY, radius: R - wall }, + // Down the bore. Same profile as the outside, one wall in, so the + // rim reads as an even thickness from every angle that sees into it. + { y: H * 0.66, radius: rOut(H * 0.66) - wall }, + { y: H * 0.42, radius: rOut(H * 0.42) - wall }, + { y: base + 0.0025, radius: rOut(base + 0.0025) - wall }, + { y: base, radius: rOut(base + 0.0025) - wall - 0.0012 }, + ] + + const glaze = tint('ceramic', jitter(random, 0.02)) + const body = latheGeometry( + levels, + segments, + [0, 0, 0], + glaze, + // The index ramp runs foot -> rim -> floor, so the outside lightens + // toward the rim the way thinning glaze does, and the bore stays a + // touch lighter than the outside, which stops it going to mud once + // the renderer shades the cavity. + { colourTop: tint('ceramic', 0.05), capBottom: true, capTop: true }, + ) + + /* ----------------------------------------------------------- handle */ + // Strap section: deeper across (z, along the wall) than radially. Built + // square by arcBarGeometry, flattened by a scale before it moves. + const scaleT = R / 0.041 + const tRad = Math.min(0.0072, Math.max(0.0048, 0.006 * scaleT)) + const widthZ = Math.min(0.0135, Math.max(0.0088, 0.0115 * scaleT)) + + // Where the loop leaves the wall. + const topY = H * 0.78 + const botY = H * 0.36 + const wallTop = rOut(topY) + const wallBot = rOut(botY) + + // End angle past 90 degrees turns the ends in toward the wall; the + // `handle` control widens the bow. Capped where the cap tilt would + // start pushing corners through the bore. + const bow = Math.min(1.3, Math.max(0.7, config.handle)) + const thetaE = (Math.PI / 180) * Math.min(125, Math.max(109, 95 + 23 * bow)) + + // Bury depth for the end caps. The cap is a tilted rectangle: its + // corners reach `capTilt` past the end centre radially, and at the + // strap's z-edges the round wall has receded by `recess`. The depth + // sits centred between "corner breaks out of the wall" and "corner + // breaks into the bore", with margin on both sides. + const capTilt = Math.abs(Math.cos(thetaE)) * (tRad / 2) + const recess = wallBot - Math.sqrt(Math.max(0, wallBot * wallBot - (widthZ / 2) ** 2)) + const dMin = recess + 0.0006 + capTilt + const dMax = wall - 0.0006 - capTilt + const depth = dMin < dMax ? (dMin + dMax) / 2 : wall * 0.5 + + const eTop = { x: wallTop - depth, y: topY } + const eBot = { x: wallBot - depth, y: botY } + const chordX = eTop.x - eBot.x + const chordY = eTop.y - eBot.y + const chord = Math.hypot(chordX, chordY) + const rLoop = chord / 2 / Math.sin(thetaE) + // Tilt that lays the loop's chord along the wall slope, so on a tapered + // body both ends sit at the same depth instead of one floating proud. + const alpha = Math.atan2(-chordX, chordY) + + const strap = arcBarGeometry( + rLoop, tRad, -thetaE, thetaE, 22, [0, 0, 0], + // The body's own glaze colour: a handle tinted separately shows the + // join as a colour edge before it shows it as geometry. + glaze.clone(), + ) + // Flatten to a strap, tilt to the wall, then carry to the wall. Built + // at the origin in the XY plane, which is already the vertical plane + // the loop lives in, so no other rotation is needed. + strap.scale(1, 1, widthZ / tRad) + strap.rotateZ(alpha) + const endBotX = rLoop * Math.cos(thetaE) + const endBotY = -rLoop * Math.sin(thetaE) + strap.translate( + eBot.x - (Math.cos(alpha) * endBotX - Math.sin(alpha) * endBotY), + eBot.y - (Math.sin(alpha) * endBotX + Math.cos(alpha) * endBotY), + 0, + ) + + const bodyPieces: BufferGeometry[] = [body] + // Smoothed at 50: the rim's 45 degree steps round over, while the foot + // chamfer against the base cap stays an edge. The handle smooths along + // its sweep at 40 and keeps its four strap edges crisp, which is what + // makes the section read as a section. + return { + body: { slot: 'ceramic' as const, geometry: smoothNormals(mergeColoured(bodyPieces), 50) }, + handle: { slot: 'ceramic' as const, geometry: smoothNormals(strap, 40) }, + } + }, + }, overrides) +} diff --git a/contemporary-props/models/pepper-mill/meta.json b/contemporary-props/models/pepper-mill/meta.json new file mode 100644 index 0000000..98a8ba6 --- /dev/null +++ b/contemporary-props/models/pepper-mill/meta.json @@ -0,0 +1,72 @@ +{ + "title": "Pepper Mill", + "description": "Turned wooden pepper mill with a fluted waist grip and a stainless hex crown. The cap is its own part hinged on the mill's axis, so the twist action grinds. The waist and its height move it from a squat bistro mill to a tall waiter's mill.", + "category": "Kitchen", + "tags": [ + "contemporary", + "kitchen", + "tableware", + "procedural" + ], + "controls": { + "height": { + "type": "number", + "label": "Height", + "min": 0.15, + "max": 0.4, + "step": 0.01, + "unit": "m" + }, + "baseRadius": { + "type": "number", + "label": "Base radius", + "min": 0.02, + "max": 0.045, + "step": 0.001, + "unit": "m" + }, + "waist": { + "type": "number", + "label": "Waist", + "min": 0.45, + "max": 0.68, + "step": 0.01 + }, + "waistAt": { + "type": "number", + "label": "Waist height", + "min": 0.42, + "max": 0.6, + "step": 0.01 + }, + "flutes": { + "type": "number", + "label": "Flutes", + "min": 8, + "max": 28, + "step": 1 + }, + "segments": { + "type": "number", + "label": "Sides", + "min": 12, + "max": 64, + "step": 1 + }, + "seed": { + "type": "number", + "label": "Variation seed", + "min": 1, + "max": 64, + "step": 1 + } + }, + "materialSlots": [ + "wood", + "stainless" + ], + "parts": [ + "body", + "cap" + ] +} diff --git a/contemporary-props/models/pepper-mill/model.ts b/contemporary-props/models/pepper-mill/model.ts new file mode 100644 index 0000000..caf39e8 --- /dev/null +++ b/contemporary-props/models/pepper-mill/model.ts @@ -0,0 +1,269 @@ +/** + * @contemporary-props/pepper-mill + * + * Table pepper mill: the longest profile curve in the kit at the lowest cost, + * and the first radial cut. + * + * The body is one lathe and the whole object is decided by where that curve + * turns. Reading from the table up: a drum for the grinder housing, a turn + * inward to the waist, a swell back out to an upper belly that stays narrower + * than the base, then a quick fall into the neck the cap sits over. The upper + * belly NARROWER than the base is the load-bearing choice: make them equal and + * the silhouette is a baluster, make the top wider and it is a chess queen + * about to tip over. + * + * The flutes are what stop it reading as a chess piece even so. A lathe cannot + * cut a groove, so the grip is built the other way round: a radial array of + * slim chamfered bars standing a millimetre proud of the waist. Because the + * waist is the narrowest point of the profile, a straight vertical bar held at + * a fixed radius is proud exactly in the middle and sinks into the body at + * both ends on its own — no cap, no fade, both ends terminate inside the + * solid. The proud height is recomputed against the actual profile for every + * configuration, so a fat waist under a low bulge cannot push a bar end + * through the surface. + * + * Parts: `body` and `cap`. The cap is its own part with its origin at the seat + * so `cap.anchor.rotation.y` is the grinding action, and the `twist` action + * does exactly that. A turned dome is rotationally invisible, so the motion is + * carried by the crown: the stainless finial nut is a 6-segment lathe — a hex + * acorn — and its facets are what you see move. + */ +import { type BufferGeometry } from 'three' + +import { + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface PepperMillConfig { + /** Overall height, finial included (metres). */ + readonly height: number + /** Radius of the base drum (metres). */ + readonly baseRadius: number + /** Waist radius as a fraction of the base radius. */ + readonly waist: number + /** Where the waist sits, as a fraction of the body height. */ + readonly waistAt: number + /** Number of grip flutes around the waist. */ + readonly flutes: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const pepperMillDefaults: PepperMillConfig = { + height: 0.23, + baseRadius: 0.03, + // The waist is what separates a mill from a rolling pin. Below ~0.5 it + // reads as an hourglass, above ~0.7 the profile goes straight and the + // flutes are doing all the work alone. + waist: 0.58, + waistAt: 0.5, + flutes: 16, + segments: 32, + seed: 23, +} + +export type PepperMillParts = 'body' | 'cap' + +export interface PepperMillActions { + /** Turns the cap — the grind. Default is a sixth of a turn. */ + twist(radians?: number): void +} + +/** Linear read of a lathe profile at an arbitrary height. */ +function radiusAt(levels: readonly Level[], y: number): number { + if (y <= levels[0]!.y) return levels[0]!.radius + for (let i = 0; i < levels.length - 1; i += 1) { + const a = levels[i]! + const b = levels[i + 1]! + if (y <= b.y) { + const t = (y - a.y) / Math.max(1e-9, b.y - a.y) + return a.radius + t * (b.radius - a.radius) + } + } + return levels.at(-1)!.radius +} + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'pepper-mill', + defaults: pepperMillDefaults, + slots: ['wood', 'stainless'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = Math.min(0.45, Math.max(0.12, config.height)) + // The radius is clamped against the height, not just on its own: a mill + // is between roughly two and six diameters tall. Outside that band the + // squat end turns into a jar on a pedestal and the thin end into a + // taper candle, and both were seen in a render before this clamp. + const R = Math.min(H * 0.21, Math.max(H * 0.08, Math.min(0.05, Math.max(0.015, config.baseRadius)))) + const segments = Math.max(12, Math.round(config.segments)) + const waistFraction = Math.min(0.68, Math.max(0.45, config.waist)) + const waistAt = Math.min(0.6, Math.max(0.42, config.waistAt)) + const flutes = Math.max(8, Math.min(28, Math.round(config.flutes))) + + // The cap takes the top ~16% of the height and overlaps the neck by a + // few millimetres, so the parting line is a step rather than a seam of + // two coplanar rings. + const bodyH = H * 0.84 + const seat = bodyH - 0.004 + + const W = R * waistFraction + const waistY = bodyH * waistAt + // The grip is a band, not a point: the waist holds its radius for a + // stretch so the flutes sit on something, and the cove into and out of + // it is what makes the profile a mill rather than a bottle. + const bandHalf = bodyH * 0.09 + // The upper belly is clearly SMALLER than the drum: the masses must + // step down going up — drum, belly, head — or the object turns into a + // chess bishop. It still follows the waist up when the waist is fat, so + // the swell never dips below the flute tops. + const upperR = R * Math.max(0.72, waistFraction * 1.08) + const upperY = bodyH * 0.74 + + /* ------------------------------------------------------------- body */ + const waistLo = waistY - bandHalf + const waistHi = waistY + bandHalf + // The shoulder backs off when the waist sits low, so the cove into the + // grip keeps some run and the drum does not turn into a pedestal. + const shoulderY = Math.min(bodyH * 0.3, waistLo - bodyH * 0.08) + const drumTop = shoulderY - bodyH * 0.1 + const bodyLevels: Level[] = [ + { y: 0, radius: R * 0.97 }, + // Crisp foot, same reasoning as the vase: the profile must leave the + // table vertically or the mill looks like it is sinking into it. + { y: 0.005, radius: R }, + // The grinder drum: a near-cylinder, because that is the one straight + // stretch a mill has and softening it is what turned the first render + // into a crayon. + { y: drumTop, radius: R * 0.985 }, + { y: shoulderY, radius: R * 0.93 }, + { y: (shoulderY + waistLo) / 2, radius: ((R * 0.93 + W) / 2) * 1.015 }, + { y: waistLo, radius: W * 1.01 }, + { y: waistY, radius: W }, + { y: waistHi, radius: W * 1.01 }, + // The rise off the grip band is deliberately quick, so the flute bar + // ends go under the surface within a couple of millimetres. + { y: waistHi + (upperY - waistHi) * 0.4, radius: ((W + upperR) / 2) * 1.02 }, + { y: upperY, radius: upperR }, + { y: bodyH * 0.83, radius: upperR * 0.9 }, + // The throat: the belly turns in to a short neck the cap's lip steps + // out over, so the parting line reads as a groove under the head. + { y: bodyH * 0.91, radius: R * 0.56 }, + { y: bodyH, radius: R * 0.52 }, + ] + + const woodBase = tint('wood', jitter(random, 0.02)) + const pieces: BufferGeometry[] = [ + latheGeometry(bodyLevels, segments, [0, 0, 0], woodBase, { + colourTop: tint('wood', 0.04), + capBottom: true, + capTop: true, + }), + ] + + /* ----------------------------------------------------------- flutes */ + // Half the vertical span of a flute bar: the grip band plus enough of + // the cove beyond it for the profile to rise over the bar ends. + const fluteHalf = bodyH * 0.13 + // How far a bar stands proud of the waist. Capped by the profile: the + // bar ends must stay under the surface, including the flat-to-flat + // shrink of the revolve's polygon. + const inscribed = Math.cos(Math.PI / segments) + const endRadius = Math.min( + radiusAt(bodyLevels, waistY - fluteHalf), + radiusAt(bodyLevels, waistY + fluteHalf), + ) * inscribed + const proud = Math.max(0.0005, Math.min(R * 0.04, endRadius - W - 0.0005)) + const depth = R * 0.22 + // Nearly touching: the grip reads from the narrow dark gaps between + // ridges, not from the ridges themselves. + const barWidth = Math.min((2 * Math.PI * W) / flutes * 0.72, R * 0.2) + const barCentreRadius = W + proud - depth / 2 + + for (let i = 0; i < flutes; i += 1) { + const angle = (i / flutes) * Math.PI * 2 + const bar = chamferedBoxGeometry( + [barWidth, depth], + [barWidth, depth], + fluteHalf * 2, + Math.min(0.0008, barWidth * 0.25), + [0, 0, 0], + // Subtle: the flutes are turned from the same blank as the body, + // so they may not jump in tone. Relief and occlusion carry them. + tint('wood', jitter(random, 0.015)), + ) + // Built at the origin, turned, then carried out to the waist. + bar.rotateY(angle) + bar.translate(Math.sin(angle) * barCentreRadius, waistY, Math.cos(angle) * barCentreRadius) + pieces.push(bar) + } + + /* -------------------------------------------------------------- cap */ + // Everything below is LOCAL to the seat: the part's origin sits there + // so rotation.y grinds. + const capH = H - seat + const domeH = capH * 0.6 + const capLevels: Level[] = [ + { y: 0, radius: R * 0.55 }, + // The lip rolls out well past the neck so the cap reads as a + // separate piece that comes off, not a continuation of the profile. + { y: 0.004, radius: R * 0.6 }, + // The head swells a touch before rounding over: a straight-sided cap + // read as a bottle top, and this is the swell that makes it a turban. + { y: domeH * 0.3, radius: R * 0.61 }, + { y: domeH * 0.6, radius: R * 0.55 }, + { y: domeH * 0.85, radius: R * 0.42 }, + { y: domeH, radius: R * 0.32 }, + ] + const dome = latheGeometry(capLevels, segments, [0, 0, 0], tint('wood', jitter(random, 0.02)), { + colourTop: tint('wood', 0.05), + capBottom: true, + capTop: true, + }) + + // The crown: a hex acorn, 6 segments on purpose. Its base is sunk into + // the dome, its facets are what make the twist visible. + const nutR = R * 0.22 + const nutLevels: Level[] = [ + { y: domeH - 0.003, radius: nutR * 0.72 }, + { y: domeH + 0.0008, radius: nutR }, + { y: capH * 0.87, radius: nutR }, + { y: capH * 0.95, radius: nutR * 0.7 }, + { y: capH, radius: nutR * 0.36 }, + ] + const nut = latheGeometry(nutLevels, 6, [0, 0, 0], tint('stainless', jitter(random, 0.02), 0.5), { + colourTop: tint('stainless', 0.04, 0.5), + capBottom: true, + capTop: true, + }) + + // 40 degrees: the revolve and the dome smooth, the foot, the lip, the + // flute chamfers and the hex facets all turn harder than that and stay + // edges. + return { + body: { slot: 'wood' as const, geometry: smoothNormals(mergeColoured(pieces), 40) }, + cap: { + slot: 'wood' as const, + geometry: smoothNormals(mergeColoured([dome]), 40), + extras: [{ slot: 'stainless' as const, geometry: smoothNormals(mergeColoured([nut]), 30) }], + origin: [0, seat, 0] as const, + }, + } + }, + + actions: ({ parts }) => ({ + twist: (radians = Math.PI / 3) => { + parts.cap.anchor.rotation.y += radians + }, + }), + }, overrides) +} diff --git a/contemporary-props/models/stockpot/meta.json b/contemporary-props/models/stockpot/meta.json new file mode 100644 index 0000000..199d8cd --- /dev/null +++ b/contemporary-props/models/stockpot/meta.json @@ -0,0 +1,58 @@ +{ + "title": "Lidded Stockpot", + "description": "Stainless stockpot with a rolled rim, two riveted strap lugs standing clear of the wall, and a separable lid whose flange sits inside the mouth. The rim curl and the sit-in step are the read; the liftLid action takes the lid straight off the seat.", + "category": "Kitchen", + "tags": [ + "contemporary", + "kitchen", + "cookware", + "vessel", + "procedural" + ], + "controls": { + "diameter": { + "type": "number", + "label": "Diameter", + "min": 0.14, + "max": 0.4, + "step": 0.01, + "unit": "m" + }, + "height": { + "type": "number", + "label": "Height", + "min": 0.1, + "max": 0.36, + "step": 0.01, + "unit": "m" + }, + "lidDome": { + "type": "number", + "label": "Lid dome", + "min": 0.05, + "max": 0.22, + "step": 0.01 + }, + "segments": { + "type": "number", + "label": "Sides", + "min": 16, + "max": 64, + "step": 1 + }, + "seed": { + "type": "number", + "label": "Variation seed", + "min": 1, + "max": 64, + "step": 1 + } + }, + "materialSlots": [ + "stainless" + ], + "parts": [ + "body", + "lid" + ] +} diff --git a/contemporary-props/models/stockpot/model.ts b/contemporary-props/models/stockpot/model.ts new file mode 100644 index 0000000..2751755 --- /dev/null +++ b/contemporary-props/models/stockpot/model.ts @@ -0,0 +1,264 @@ +/** + * @contemporary-props/stockpot + * + * The kit's first metal vessel, and it exists to settle three details that + * every metal vessel afterwards reuses: the rolled rim, the riveted lug, and + * the separable sit-in lid. + * + * The rolled rim is the whole read. A pot without one is a cylinder, so the + * rim here is a real curl: the profile reaches the top of the wall and then + * travels 280 degrees around a small circle — down into the crevice under the + * roll, out, over the top, and back in — before tucking into the bore. That + * traversal direction is not decorative: the lathe orients faces by which way + * the profile walks (up gives outward, out gives down, down gives inward), so + * a curl sampled the obvious way, straight over the top from the wall, comes + * out inside-out on its underside. Walking the circle in one consistent sense + * keeps every face of the curl pointing at the air it actually touches. + * + * Unlike the vase, the pot models a short bore: a real interior wall drops + * from inside the rim to a false floor at 42% of the height. The vase never + * shows its inside; this object's one action is lifting the lid off, and an + * open pot that is a hollow shell with the world visible through it is worse + * than any number of extra triangles. The floor is deep enough to sit in + * occlusion shadow and shallow enough that nothing pays for the part of the + * bore no camera reaches. + * + * The lid is one profile too: a flange that drops inside the mouth (a lid + * that merely rests on top reads as a plate), a step that seats on the rim, a + * rolled edge matching the pot's, a dome, and the knob — stem, flare, cap — + * continued from the same curve so the whole lid is a single connected solid. + * The knob keeps a fixed hand size rather than scaling with the pot, for the + * same reason the lugs do: hands do not scale with cookware. + * + * Each lug is a strap loop swept as a square-section arc, tilted up 25 + * degrees and standing about 30mm clear of the wall so a hand fits, with both + * ends buried inside a chamfered mounting plate that is itself embedded into + * the wall. The rivet heads sit over the buried strap ends, which is where a + * rivet would actually be. + * + * One slot, `stainless`, everywhere. A stainless stockpot really is one + * material; the lugs and rivets separate from the body by tint and by the + * occlusion crevices around the plate, not by a material change. + * + * Parts: `body` and `lid`. The lid's anchor sits at the rim plane, so + * `liftLid` is a straight translation and anything the consumer stood on the + * lid rises with it. + */ +import { type BufferGeometry } from 'three' + +import { + arcBarGeometry, + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface StockpotConfig { + /** Body outer diameter (metres). */ + readonly diameter: number + /** Body height to the rim (metres). The lid and knob add to it. */ + readonly height: number + /** Lid dome rise as a fraction of the body radius. Low is a saucepot lid, high a casserole. */ + readonly lidDome: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const stockpotDefaults: StockpotConfig = { + // A 26 x 24 cm pot, roughly eleven litres: unmistakably a stockpot rather + // than a saucepan, and still a size that exists in an ordinary kitchen. + diameter: 0.26, + height: 0.24, + lidDome: 0.16, + segments: 48, + seed: 7, +} + +export type StockpotParts = 'body' | 'lid' + +export interface StockpotActions { + /** Lifts the lid clear of the rim, or seats it again. No argument toggles. */ + liftLid(lifted?: boolean): void +} + +const clampDiameter = (v: number): number => Math.min(0.4, Math.max(0.14, v)) +const clampHeight = (v: number): number => Math.min(0.36, Math.max(0.1, v)) + +const deg = (d: number): number => (d * Math.PI) / 180 + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'stockpot', + defaults: stockpotDefaults, + slots: ['stainless'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const R = clampDiameter(config.diameter) / 2 + const H = clampHeight(config.height) + const segments = Math.max(16, Math.round(config.segments)) + // Roll radius: scales gently with the pot but stays in the few-millimetre + // band a pressed rim actually has. Bigger and the rim reads as a pipe + // welded on; smaller and it vanishes at prop distance. + const rr = Math.min(0.0045, Math.max(0.002, R * 0.026)) + const wall = 0.004 + const bore = R - wall + const floorY = H * 0.42 + + const steel = tint('stainless', jitter(random, 0.02)) + + /* ------------------------------------------------------------- body */ + + const bodyLevels: Level[] = [ + { y: 0, radius: R * 0.96 }, + // A short chamfer off the table, then the wall. Stockpot walls are + // straight; the character lives entirely at the top. + { y: 0.006, radius: R }, + { y: H * 0.45, radius: R }, + // Tangent point where the wall meets the roll. + { y: H - rr, radius: R }, + ] + // The curl, walked in increasing angle so every face points outward: + // under the roll (200-280), out and over the top (280-450), back in + // toward the mouth (450-480). + for (let a = 200; a <= 480; a += 40) { + bodyLevels.push({ + y: H - rr + Math.sin(deg(a)) * rr, + radius: R + rr + Math.cos(deg(a)) * rr, + }) + } + bodyLevels.push( + // Tuck from the inner lip into the bore, then the false floor. + { y: H - rr * 0.8, radius: bore }, + { y: floorY + 0.005, radius: bore }, + { y: floorY, radius: bore - 0.004 }, + ) + + const pieces: BufferGeometry[] = [ + latheGeometry(bodyLevels, segments, [0, 0, 0], steel, { + capBottom: true, + capTop: true, // the false floor, facing up inside the bore + }), + ] + + /* ------------------------------------------------------------- lugs */ + + const ra = 0.021 + R * 0.024 // loop radius: mostly hand, a little pot + const bar = 0.009 // strap section; thinner reads as wire + const tilt = deg(18) + const lugY = Math.min(H - 0.03, H * 0.8) + // Ends of the 260-degree arc sit at (±cos40, -sin40) of the loop's local + // frame; the centre is placed so those ends land just outside the wall + // surface, buried inside the plate. + const endIn = Math.sin(deg(40)) * ra * Math.cos(tilt) + const endDown = Math.sin(deg(40)) * ra * Math.sin(tilt) + const plateW = 0.046 + R * 0.04 + const plateH = 0.032 + + for (const spin of [0, Math.PI]) { + const loop = arcBarGeometry(ra, bar, deg(-40), deg(220), 20, [0, 0, 0], + tint('stainless', 0.01)) + // Built in XY with the bulge up: turn the spread onto the tangent (Z), + // then lean the bulge out and 18 degrees above horizontal. + loop.rotateY(-Math.PI / 2) + loop.rotateZ(tilt - Math.PI / 2) + loop.translate(R + 0.001 + endIn, lugY, 0) + loop.rotateY(spin) + pieces.push(loop) + + // Mounting plate, embedded 5mm into the wall so its corners cannot + // daylight on a small pot where the flat plate leaves the curve. + const plate = chamferedBoxGeometry([0.01, plateW], [0.01, plateW], plateH, + 0.0012, [R + 0.001, lugY, 0], tint('stainless', -0.03)) + plate.rotateY(spin) + pieces.push(plate) + + // Rivet heads on the plate's lower half, clear of the strap, where the + // rivets that hold the plate to the wall actually sit. Under the strap + // ends they exist but cannot be seen, which is the same as not existing. + for (const side of [-1, 1]) { + const rivet = latheGeometry([ + { y: 0, radius: 0.005 }, + { y: 0.0024, radius: 0.0041 }, + { y: 0.0038, radius: 0.0018 }, + ], 10, [0, 0, 0], tint('stainless', -0.06)) + rivet.rotateZ(-Math.PI / 2) + rivet.translate(R + 0.0045, lugY - 0.009, side * 0.011) + rivet.rotateY(spin) + pieces.push(rivet) + } + } + + /* -------------------------------------------------------------- lid */ + + const flange = bore - 0.0008 + const domeH = R * Math.min(0.22, Math.max(0.04, config.lidDome)) + const knobBase = 0.007 + domeH + const lidLevels: Level[] = [ + // Flange: drops inside the mouth. Its bottom is capped so the lifted + // lid shows a closed underside rather than a hollow shell. + { y: -0.011, radius: flange * 0.9 }, + { y: -0.008, radius: flange }, + { y: -0.0005, radius: flange }, + // Seat step: walked outward, so it faces DOWN onto the rim. + { y: 0.0008, radius: R + rr * 1.4 }, + // Rolled lid edge, matching the pot's roll in reach. + { y: 0.0035, radius: R + rr * 2 }, + { y: 0.006, radius: R + rr * 1.2 }, + ] + // The dome is an elliptical arc, not straight lines to the knob: three + // linear levels read as a tent at any dome height worth having. + for (const phi of [18, 36, 54, 72, 84]) { + lidLevels.push({ + y: 0.006 + Math.sin(deg(phi)) * domeH, + radius: Math.cos(deg(phi)) * (R + rr * 1.2), + }) + } + lidLevels.push( + // Knob: fixed hand size, continued from the same profile. + { y: knobBase + 0.001, radius: 0.0065 }, + { y: knobBase + 0.014, radius: 0.0065 }, + { y: knobBase + 0.02, radius: 0.0125 }, + { y: knobBase + 0.024, radius: 0.0125 }, + { y: knobBase + 0.0265, radius: 0.0075 }, + { y: knobBase + 0.028, radius: 0.003 }, + ) + + const lid = latheGeometry(lidLevels, segments, [0, 0, 0], + tint('stainless', jitter(random, 0.02)), { capBottom: true, capTop: true }) + + // Smoothed at 40 degrees: the drum, the curl and the dome read as the + // pressed surfaces they are, while the strap's square section, the rim + // crevice, the seat step and every chamfer turn harder than that and + // survive as edges. + return { + body: { slot: 'stainless' as const, geometry: smoothNormals(mergeColoured(pieces), 40) }, + lid: { + slot: 'stainless' as const, + geometry: smoothNormals(mergeColoured([lid]), 40), + // Anchor at the rim plane: geometry is seat-relative, so lifting the + // lid is a translation of the anchor and nothing else. + origin: [0, H, 0] as const, + }, + } + }, + + actions: ({ parts, getConfig }) => { + let lifted = false + return { + liftLid(next?: boolean): void { + lifted = next ?? !lifted + const c = getConfig() + parts.lid.anchor.position.y = + clampHeight(c.height) + (lifted ? clampDiameter(c.diameter) * 0.55 : 0) + }, + } + }, + }, overrides) +} diff --git a/contemporary-props/models/traffic-cone/meta.json b/contemporary-props/models/traffic-cone/meta.json new file mode 100644 index 0000000..e3ed60b --- /dev/null +++ b/contemporary-props/models/traffic-cone/meta.json @@ -0,0 +1,66 @@ +{ + "title": "Traffic Cone", + "description": "Hi-vis cone on a stepped square base. The wall is one concave profile and the retroreflective collars are y-ranges of that profile stood 3 mm proud, which is the banding pattern every striped revolve in the kit copies.", + "category": "Street", + "tags": [ + "contemporary", + "street", + "roadworks", + "safety", + "procedural" + ], + "controls": { + "height": { + "type": "number", + "label": "Height", + "min": 0.3, + "max": 1.2, + "step": 0.01, + "unit": "m" + }, + "baseWidth": { + "type": "number", + "label": "Base width", + "min": 0.2, + "max": 0.6, + "step": 0.01, + "unit": "m" + }, + "collars": { + "type": "number", + "label": "Collars", + "min": 1, + "max": 2, + "step": 1 + }, + "flare": { + "type": "number", + "label": "Wall sag", + "min": 0, + "max": 1, + "step": 0.05 + }, + "segments": { + "type": "number", + "label": "Sides", + "min": 12, + "max": 64, + "step": 1 + }, + "seed": { + "type": "number", + "label": "Variation seed", + "min": 1, + "max": 64, + "step": 1 + } + }, + "materialSlots": [ + "plastic", + "retroreflective" + ], + "parts": [ + "base", + "body" + ] +} diff --git a/contemporary-props/models/traffic-cone/model.ts b/contemporary-props/models/traffic-cone/model.ts new file mode 100644 index 0000000..86ea034 --- /dev/null +++ b/contemporary-props/models/traffic-cone/model.ts @@ -0,0 +1,197 @@ +/** + * @contemporary-props/traffic-cone + * + * The clearest outline in the set, and the object where colour banding on a + * revolve gets defined. Every striped revolve after this one — the bollard, + * the channelizer drum, the barber pole if it ever comes — should copy the + * collar technique here rather than invent its own. + * + * The technique: the body is ONE radius profile, a single function of height, + * and a band is nothing but a y-range of that profile emitted into a different + * slot's geometry. Both sides of a boundary sample the profile at the same t, + * so the seam is watertight by construction, with no coincident faces and no + * gap. The collars additionally stand 3 mm proud of the wall — real cone + * sleeves are a wrap, not a print — which buys three things at once: the step + * ring catches light at the top and bottom of the band, the silhouette shows + * the sleeve, and the normal seam between the two geometries is hidden on an + * edge that is supposed to be there. + * + * The profile itself is not a straight cone. A moulded cone sags: the wall + * leaves the base wide and flares in quickly, then climbs to the tip nearly + * straight. That is a power curve, (1-t)^p with p above 1, and `flare` moves p. + * At flare 0 the profile is the straight cone of a traffic-cone pictogram, + * which is deliberately still in range. + * + * The base is square with a stepped lip: two chamfered tiers, the upper one + * smaller, which is how the moulding actually looks and what stops the cone + * reading as a witch's hat on a board. The body is planted 8 mm into the + * upper tier so nothing coincides with the base's top face. + * + * Parts: `base` and `body`. They are separate because a knocked-over cone is + * half the reason the object exists in scenes, and tipping is a rotation of + * the body against its base only in the cheap staged sense; more honestly, + * the base is the part a consumer recolours (recycled black PVC bases are + * everywhere) while the body stays hi-vis. + */ +import { type BufferGeometry } from 'three' + +import { + chamferedBoxGeometry, + createKitModel, + createTinter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface TrafficConeConfig { + /** Overall height (metres). 0.45 site cone up to 1.0 motorway cone. */ + readonly height: number + /** Square base width (metres). Clamped against height so the cone stays stable and stays a cone. */ + readonly baseWidth: number + /** Retroreflective collars: 1 (single wide sleeve) or 2 (motorway pair). */ + readonly collars: number + /** How concave the wall is. 0 is a straight cone, 1 a heavy moulded sag. */ + readonly flare: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const trafficConeDefaults: TrafficConeConfig = { + height: 0.75, + baseWidth: 0.4, + collars: 2, + flare: 0.55, + segments: 28, + seed: 7, +} + +export type TrafficConeParts = 'base' | 'body' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'traffic-cone', + defaults: trafficConeDefaults, + slots: ['plastic', 'retroreflective'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = Math.min(1.2, Math.max(0.3, config.height)) + // The base is clamped RELATIVE to the height. Real cones keep the base + // between roughly half and two thirds of the height; outside that the + // object either topples (too narrow) or reads as a pyramid on a raft. + const w = Math.min(0.6, Math.max(0.2, + Math.min(H * 0.72, Math.max(H * 0.42, config.baseWidth)))) + const collars = Math.round(config.collars) >= 2 ? 2 : 1 + const p = 1 + 0.9 * Math.min(1, Math.max(0, config.flare)) + const segments = Math.max(12, Math.round(config.segments)) + + // Spread kept low on the body: hi-vis orange is a controlled colour and + // a lightness jitter that is charming on ceramic drifts it toward salmon. + const bodyOrange = tint('retroreflective', -0.02, 0.4) + const baseOrange = tint('retroreflective', -0.09, 0.5) + const sleeveWhite = tint('paper', 0.03, 0.4) + + /* ------------------------------------------------------------- base */ + // Two chamfered tiers, the upper sunk 3 mm into the lower so its bottom + // face ends inside the solid rather than level with the lower's top. + const h1 = 0.014 + H * 0.010 + const h2 = 0.012 + H * 0.008 + const w2 = w * 0.8 + const baseTop = h1 - 0.003 + h2 + + const basePieces: BufferGeometry[] = [ + chamferedBoxGeometry([w, w], [w * 0.96, w * 0.96], h1, 0.006, + [0, h1 / 2, 0], baseOrange), + chamferedBoxGeometry([w2, w2], [w2 * 0.94, w2 * 0.94], h2, 0.005, + [0, h1 - 0.003 + h2 / 2, 0], tint('retroreflective', -0.07, 0.5)), + ] + + /* ------------------------------------------------------------- body */ + const bodyH = H - baseTop + const rFoot = w * 0.34 + const rTip = Math.min(0.02 + H * 0.008, rFoot * 0.45) + // The whole cone in one line. Everything below samples this and only + // this, which is what makes the banding seam-free. + const profile = (t: number): number => rTip + (rFoot - rTip) * Math.pow(1 - t, p) + const levelAt = (t: number, proud = 0): Level => + ({ y: baseTop + bodyH * t, radius: profile(t) + proud }) + + // Band positions as fractions of the body. The two-collar layout is the + // motorway one: the wider band on top, a gap, a narrower band below. + const bands: ReadonlyArray = + collars === 2 ? [[0.42, 0.56], [0.64, 0.85]] : [[0.5, 0.86]] + const proud = 0.003 + + // Interior samples on the concave curve, endpoints exact. + const sample = (t0: number, t1: number, proudBy: number): Level[] => { + const steps = Math.max(2, Math.ceil((t1 - t0) / 0.045)) + const levels: Level[] = [] + for (let i = 0; i <= steps; i += 1) { + levels.push(levelAt(t0 + ((t1 - t0) * i) / steps, proudBy)) + } + return levels + } + + const plasticPieces: BufferGeometry[] = [] + const collarPieces: BufferGeometry[] = [] + + const cuts = [0, ...bands.flat(), 1] + for (let i = 0; i < cuts.length - 1; i += 1) { + const t0 = cuts[i]! + const t1 = cuts[i + 1]! + const isBand = i % 2 === 1 + if (isBand) { + // A collar is the same profile span pushed out by `proud`, with a + // flat step ring at each end (two levels at one y) and OPEN ends: + // the first and last level sit ON the cone wall, so the sleeve + // meets the body on the body's own edge rings. + const levels: Level[] = [ + levelAt(t0), + ...sample(t0, t1, proud), + levelAt(t1), + ] + collarPieces.push(latheGeometry(levels, segments, [0, 0, 0], sleeveWhite, + { capBottom: false, capTop: false })) + continue + } + const first = i === 0 + const last = i === cuts.length - 2 + const levels: Level[] = sample(t0, last ? 1 - 0.008 / bodyH : t1, 0) + if (first) { + // Plant the foot 8 mm inside the base's upper tier. The bottom cap + // is buried in solid plastic, which is the only place a cap that + // nothing should ever see is allowed to be. + levels.unshift({ y: baseTop - 0.008, radius: profile(0) }) + } + if (last) { + // Blunt rolled tip. A cone does not come to a point; the mould + // rounds it off at about 70% of the tip radius. + levels.push({ y: H, radius: rTip * 0.7 }) + } + plasticPieces.push(latheGeometry(levels, segments, [0, 0, 0], bodyOrange, + { capBottom: first, capTop: last })) + } + + // Smoothed at 40 degrees: the concave wall and the sleeve faces read as + // curves, while the collar step rings, the blunt tip and every base + // chamfer turn through more than that and stay edges. + return { + base: { + slot: 'plastic' as const, + geometry: smoothNormals(mergeColoured(basePieces), 40), + }, + body: { + slot: 'plastic' as const, + geometry: smoothNormals(mergeColoured(plasticPieces), 40), + extras: [{ + slot: 'retroreflective' as const, + geometry: smoothNormals(mergeColoured(collarPieces), 40), + }], + }, + } + }, + }, overrides) +} diff --git a/contemporary-props/models/wine-glass/meta.json b/contemporary-props/models/wine-glass/meta.json new file mode 100644 index 0000000..0a64271 --- /dev/null +++ b/contemporary-props/models/wine-glass/meta.json @@ -0,0 +1,72 @@ +{ + "title": "Wine Glass", + "description": "Stemmed wine glass turned as one continuous revolve with a real wall: the profile runs up the outside, steps across the rim, and returns down the inside to a dished floor. Bowl radius and rim tuck move it from a wide red through a white to a small port glass.", + "category": "Tableware", + "tags": [ + "contemporary", + "tableware", + "glassware", + "vessel", + "procedural" + ], + "controls": { + "height": { + "type": "number", + "label": "Height", + "min": 0.12, + "max": 0.3, + "step": 0.005, + "unit": "m" + }, + "bowlRadius": { + "type": "number", + "label": "Bowl radius", + "min": 0.025, + "max": 0.065, + "step": 0.001, + "unit": "m" + }, + "bowlFraction": { + "type": "number", + "label": "Bowl depth", + "min": 0.32, + "max": 0.62, + "step": 0.01 + }, + "rim": { + "type": "number", + "label": "Rim tuck", + "min": 0.52, + "max": 0.95, + "step": 0.01 + }, + "stemRadius": { + "type": "number", + "label": "Stem thickness", + "min": 0.0035, + "max": 0.008, + "step": 0.0005, + "unit": "m" + }, + "segments": { + "type": "number", + "label": "Sides", + "min": 12, + "max": 64, + "step": 1 + }, + "seed": { + "type": "number", + "label": "Variation seed", + "min": 1, + "max": 64, + "step": 1 + } + }, + "materialSlots": [ + "glass" + ], + "parts": [ + "body" + ] +} diff --git a/contemporary-props/models/wine-glass/model.ts b/contemporary-props/models/wine-glass/model.ts new file mode 100644 index 0000000..358153d --- /dev/null +++ b/contemporary-props/models/wine-glass/model.ts @@ -0,0 +1,196 @@ +/** + * @contemporary-props/wine-glass + * + * Second object in the kit, and it is here to prove two things before anything + * expensive depends on them: wall thickness on a revolve, and the glass slot. + * + * The vase got away with a wall of zero thickness because ceramic is opaque + * and the bore is dark. Glass is not opaque. Look through a wine glass and + * what you actually see of it is its edges: the bright ellipse of the rim, the + * disc edge of the foot, and the thick mass where the bowl closes onto the + * stem. So the bowl here is a real shell: the profile runs UP the outside, + * steps across the rim, and comes back DOWN the inside to a dished floor that + * sits well above the outer bottom. That step across the rim is the whole + * point — a single-surface bowl in a transparent material has a rim one + * triangle wide, which flickers, and a bowl bottom with nothing in it, which + * reads as a soap bubble on a stick. + * + * One continuous lathe carries foot, stem, bowl and inner surface. Not three + * stacked pieces, for the reason the lathe exists at all: stacked revolves + * leave coincident faces where they meet, and in a transparent material every + * internal face is visible forever. + * + * The stem is the hard part of the silhouette. Too thick and the object is a + * goblet; too thin and at prop distance it disappears and the bowl floats. + * The config exposes it, clamped to 3.5–8 mm radius, which spans a delicate + * tasting glass to a sturdy bistro stem and nothing outside what a stem is. + * + * The family: bowl radius and rim tuck move it from a wide tucked-in red + * through a narrower white to a small open port glass; bowl depth against + * total height trades stem for bowl. + * + * Parts: `body` alone. Nothing on a wine glass moves, and slicing one revolve + * into named thirds would only invent seams. + */ +import { type BufferGeometry } from 'three' + +import { + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface WineGlassConfig { + /** Overall height (metres). */ + readonly height: number + /** Widest radius of the bowl (metres). */ + readonly bowlRadius: number + /** Bowl height as a fraction of the overall height. */ + readonly bowlFraction: number + /** Rim radius as a fraction of the bowl radius. Low values tuck the rim in. */ + readonly rim: number + /** Stem radius (metres). The goblet/disappearing line is clamped at both ends. */ + readonly stemRadius: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const wineGlassDefaults: WineGlassConfig = { + height: 0.215, + bowlRadius: 0.044, + // Just under half. More bowl than this reads as a brandy balloon, more stem + // reads as laboratory glassware. + bowlFraction: 0.48, + rim: 0.68, + stemRadius: 0.0045, + segments: 40, + seed: 7, +} + +export type WineGlassParts = 'body' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'wine-glass', + defaults: wineGlassDefaults, + slots: ['glass'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const clamp = (v: number, lo: number, hi: number): number => Math.min(hi, Math.max(lo, v)) + + const H = clamp(config.height, 0.12, 0.3) + const bowlR = clamp(config.bowlRadius, 0.025, Math.min(0.065, H * 0.42)) + const bowlH = H * clamp(config.bowlFraction, 0.32, 0.62) + const rimR = bowlR * clamp(config.rim, 0.52, 0.95) + // The stem is clamped twice: absolutely, and against the bowl. The + // absolute clamp keeps it a stem at all; the relative one stops a small + // glass given a fat stem turning into a candlestick, which is exactly + // what the first render of that corner was. + const stemR = clamp(config.stemRadius, 0.0035, Math.min(0.008, bowlR * 0.2)) + // The foot follows the bowl rather than being free: a foot wider than + // the bowl is a cake stand, a foot narrower than three stem widths falls + // over in the hand and in the eye. + const footR = Math.max(bowlR * 0.78, stemR * 3) + // Wall thickness scales gently with the bowl so a big balloon does not + // end up with cigarette-paper walls, floored where thinner would vanish. + const wall = Math.max(0.0016, bowlR * 0.042) + const bowlBaseY = H - bowlH + + /** + * Outer bowl profile, u = 0 at the stem junction, 1 at the rim. + * Below the belly an eased sine gives the rounded bottom; above it a + * cosine ease tucks the wall back in toward the rim, with a nonzero + * slope at the top so the rim tilts slightly inward like a red should. + */ + const bellyU = 0.45 + const rOut = (u: number): number => + u <= bellyU + ? bowlR * Math.sin((u / bellyU) * (Math.PI / 2)) ** 0.8 + : rimR + (bowlR - rimR) * Math.cos(((u - bellyU) / (1 - bellyU)) * (Math.PI / 2)) ** 1.35 + const yAt = (u: number): number => bowlBaseY + bowlH * u + + // The foot's vertical build scales with the glass: fixed heights that + // look right on a 21 cm red are a bell jar on a 12 cm port glass. + const fs = clamp(H / 0.215, 0.65, 1.15) + // Stem levels are fractions of the run between foot and bowl, so a short + // glass with a deep bowl cannot fold the stem back through the foot. + const footTipY = 0.0165 * fs + const s = (t: number): number => footTipY + (bowlBaseY - footTipY) * t + + const levels: Level[] = [ + // Foot: a disc with a rolled edge, rising as a shallow dome. The edge + // band is what the eye gets of the foot through the glass above it. + { y: 0, radius: footR * 0.985 }, + { y: 0.0018 * fs, radius: footR }, + { y: 0.0032 * fs, radius: footR * 0.94 }, + { y: 0.007 * fs, radius: footR * 0.5 }, + { y: 0.0125 * fs, radius: Math.max(footR * 0.2, stemR * 1.9) }, + { y: footTipY, radius: stemR * 1.5 }, + // Stem: a hair of entasis. Dead straight looks extruded; the swell at + // the top is where the pull into the bowl begins. + { y: s(0.22), radius: stemR * 1.06 }, + { y: s(0.6), radius: stemR * 0.94 }, + { y: s(0.93), radius: stemR * 1.05 }, + // Bowl, outside, base to rim. The lowest samples are floored at the + // stem radius: on a squat bowl the raw curve starts below the stem and + // the profile pinches in before flaring, which reads as a crack. + { y: yAt(0.03), radius: Math.max(rOut(0.03), stemR * 1.2) }, + { y: yAt(0.07), radius: Math.max(rOut(0.07), stemR * 1.45) }, + { y: yAt(0.13), radius: rOut(0.13) }, + { y: yAt(0.21), radius: rOut(0.21) }, + { y: yAt(0.31), radius: rOut(0.31) }, + { y: yAt(bellyU), radius: bowlR }, + { y: yAt(0.57), radius: rOut(0.57) }, + { y: yAt(0.7), radius: rOut(0.7) }, + { y: yAt(0.82), radius: rOut(0.82) }, + { y: yAt(0.92), radius: rOut(0.92) }, + { y: H, radius: rimR }, + // The rim: two levels at the same height, one wall thickness apart. + // The quad between them is the flat annulus that carries the whole + // top of the silhouette. + { y: H, radius: rimR - wall }, + // Inside, descending. Same profile inset by the wall, stopped short of + // the bottom so the bowl closes onto a solid mass above the stem. + { y: yAt(0.92), radius: rOut(0.92) - wall }, + { y: yAt(0.8), radius: rOut(0.8) - wall }, + { y: yAt(0.66), radius: rOut(0.66) - wall }, + { y: yAt(0.52), radius: rOut(0.52) - wall }, + { y: yAt(bellyU), radius: bowlR - wall }, + { y: yAt(0.36), radius: rOut(0.36) - wall }, + { y: yAt(0.27), radius: rOut(0.27) - wall }, + { y: yAt(0.2), radius: rOut(0.2) - wall }, + // Dished floor, then the cap closes it. Its height above the outer + // base is the thick lens of glass every stemmed glass has where the + // bowl was gathered onto the stem, and it is the third edge (after + // rim and foot) that makes transparent glass readable. + { y: yAt(0.13), radius: bowlR * 0.16 }, + ] + + const pieces: BufferGeometry[] = [ + latheGeometry( + levels, + Math.max(12, Math.round(config.segments)), + [0, 0, 0], + tint('glass', jitter(random, 0.02)), + // Slightly lighter along the run of the profile, which ends on the + // inner surface: light collects in the bowl rather than on the foot. + { colourTop: tint('glass', 0.05), capBottom: true, capTop: true }, + ), + ] + + // 40 degrees: the walls and the stem are curves and smooth out, while + // the rim annulus, the foot edge and the floor cap all turn through + // close to a right angle and keep their edges — and on glass the edges + // are the object. + return { + body: { slot: 'glass' as const, geometry: smoothNormals(mergeColoured(pieces), 40) }, + } + }, + }, overrides) +} diff --git a/media/cover.png b/media/cover.png index e87757e..0a98d89 100644 Binary files a/media/cover.png and b/media/cover.png differ diff --git a/media/kit.png b/media/kit.png index 347e980..2bc2474 100644 Binary files a/media/kit.png and b/media/kit.png differ diff --git a/media/models.png b/media/models.png index c009026..67c2d86 100644 Binary files a/media/models.png and b/media/models.png differ diff --git a/models.lock.json b/models.lock.json index deeed4e..5c712bc 100644 --- a/models.lock.json +++ b/models.lock.json @@ -677,15 +677,15 @@ "address": "@contemporary-props/core", "source": "file:contemporary-props/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-28T11:55:55.316Z", + "installedAt": "2026-08-28T13:01:08.200Z", "files": [ { "path": "src\\models\\contemporary-props\\core\\geometry.ts", - "sourceHash": "b47141c115c48d48e3a4c643fe9634343458288688ea586f044e6a7e7cdbaad5" + "sourceHash": "00ec2d2b459c909612841820f0afd2db97dc85729baec695493f6ec609178fbc" }, { "path": "src\\models\\contemporary-props\\core\\index.ts", - "sourceHash": "82ec12371362c5e72d4b5049f35c3c249276f4dde0f2a94c6db97dc8789d172e" + "sourceHash": "fd3705b61a7df5290b2d05d67ed9d18a9cc1db2aa2d2466b14093744453d33be" }, { "path": "src\\models\\contemporary-props\\core\\kit.ts", @@ -719,6 +719,104 @@ "dependencies": [ "three@>=0.185.0" ] + }, + "@contemporary-props/ceramic-vase": { + "address": "@contemporary-props/ceramic-vase", + "source": "file:contemporary-props/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-28T13:01:08.203Z", + "files": [ + { + "path": "src\\models\\contemporary-props\\ceramic-vase\\model.ts", + "sourceHash": "ab7a91d0e4090ecbf6118b25b5c5cf21a06c68570d1b3df21b1b9c240e4c0537" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] + }, + "@contemporary-props/coffee-mug": { + "address": "@contemporary-props/coffee-mug", + "source": "file:contemporary-props/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-28T13:01:08.204Z", + "files": [ + { + "path": "src\\models\\contemporary-props\\coffee-mug\\model.ts", + "sourceHash": "3ac9a507c369cb4c3a3badb53f818a2b8e985560da690108923692431b74e39e" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] + }, + "@contemporary-props/pepper-mill": { + "address": "@contemporary-props/pepper-mill", + "source": "file:contemporary-props/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-28T13:01:08.206Z", + "files": [ + { + "path": "src\\models\\contemporary-props\\pepper-mill\\model.ts", + "sourceHash": "132dd1816b7c74badc307d3b9d05fff0c0c9754508e740145a50e568ff34b1ff" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] + }, + "@contemporary-props/stockpot": { + "address": "@contemporary-props/stockpot", + "source": "file:contemporary-props/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-28T13:01:08.209Z", + "files": [ + { + "path": "src\\models\\contemporary-props\\stockpot\\model.ts", + "sourceHash": "f0f618489a6d6fd27624918a29eb6109f8287dad50dd939cce69a29b38a224e4" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] + }, + "@contemporary-props/traffic-cone": { + "address": "@contemporary-props/traffic-cone", + "source": "file:contemporary-props/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-28T13:01:08.211Z", + "files": [ + { + "path": "src\\models\\contemporary-props\\traffic-cone\\model.ts", + "sourceHash": "0a6f387c3fbc9b2883137d65efdc17abafc74a20ba11d681e0b8fc13757beac4" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] + }, + "@contemporary-props/wine-glass": { + "address": "@contemporary-props/wine-glass", + "source": "file:contemporary-props/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-28T13:01:08.215Z", + "files": [ + { + "path": "src\\models\\contemporary-props\\wine-glass\\model.ts", + "sourceHash": "b50c1fda8b9accdbb1751e1009ae02c36b54c69dc4e4fff3a8c2dd2957b81c77" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] + }, + "@contemporary-props/kit": { + "address": "@contemporary-props/kit", + "source": "file:contemporary-props/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-28T13:01:08.215Z", + "files": [], + "dependencies": [] } } } diff --git a/scripts/raster.ts b/scripts/raster.ts index 59ba1c3..628cae3 100644 --- a/scripts/raster.ts +++ b/scripts/raster.ts @@ -307,10 +307,41 @@ function raster(frame: Frame, camera: PerspectiveCamera, triangles: readonly Tri } } -/** Contact shadow: flatten the model onto the y=floor plane and draw it dark. */ -function contactShadow(frame: Frame, camera: PerspectiveCamera, triangles: readonly Triangle[], floor: number): void { +/** + * Contact shadow: flatten the model onto the floor and darken what lands there. + * + * With a falloff, and that is the whole difference between a shadow and a + * stain. Flattening everything at full strength is right for a barrel, whose + * mass sits on the ground anyway, and badly wrong for anything with a raised + * part standing in a vertical plane: a mug's handle flattens to its own reach + * by its own width and lands on the floor as a hard black bar beside the mug, + * reading as a separate object lying there. It was the first thing anyone + * noticed in the first picture this kit produced. + * + * So a triangle contributes by how close it is to the floor. The scale is the + * model's own height rather than a constant, because a 7 m mill and a 0.1 m mug + * should both cast something that looks like contact rather than like paint. + */ +function contactShadow( + frame: Frame, + camera: PerspectiveCamera, + triangles: readonly Triangle[], + floor: number, + height: number, +): void { + // A quarter of the model's height. Above that a piece is not touching + // anything and has no business darkening the floor. + const reach = Math.max(1e-4, height * 0.25) for (const tri of triangles) { if (tri.unlit) continue + // Skip only when the WHOLE triangle is out of reach. The strength itself + // is worked out per pixel below: taking one value for the triangle looks + // fine on a wall and tears a fan apart, because neighbouring triangles in + // a base cap have different centre heights and alternate light and dark. + // On the first vase that came out as a black starburst around the foot, + // which is a worse artifact than the bar it replaced. + const lowest = Math.min(tri.a.y, tri.b.y, tri.c.y) - floor + if (lowest >= reach) continue const flat = (v: Vector3): Vector3 => new Vector3(v.x, floor + 0.0005, v.z) const pa = project(flat(tri.a), camera, frame) const pb = project(flat(tri.b), camera, frame) @@ -330,8 +361,13 @@ function contactShadow(frame: Frame, camera: PerspectiveCamera, triangles: reado const w1 = ((pc.x - pb.x) * (py - pb.y) - (px - pb.x) * (pc.y - pb.y)) / area const w2 = 1 - w0 - w1 if (w0 < 0 || w1 < 0 || w2 < 0) continue + // w1 -> a, w2 -> b, w0 -> c, matching the colour interpolation. + const above = (tri.a.y * w1 + tri.b.y * w2 + tri.c.y * w0) - floor + if (above >= reach) continue + const strength = Math.pow(1 - above / reach, 1.6) const i = (y * frame.width + x) * 3 - for (let k = 0; k < 3; k += 1) frame.colour[i + k] = frame.colour[i + k]! * 0.55 + const darken = 1 - 0.45 * strength + for (let k = 0; k < 3; k += 1) frame.colour[i + k] = frame.colour[i + k]! * darken } } } @@ -574,7 +610,7 @@ export function renderObject(root: Object3D, options: RenderOptions): Frame { const triangles = collect(root) const frame = newFrame(size, tall, ground) const { camera, floor } = frameCamera(root, size, tall, towards) - contactShadow(frame, camera, triangles, floor) + contactShadow(frame, camera, triangles, floor, new Box3().setFromObject(root).getSize(new Vector3()).y) raster(frame, camera, triangles) return frame } diff --git a/src/models/contemporary-props/ceramic-vase/model.ts b/src/models/contemporary-props/ceramic-vase/model.ts new file mode 100644 index 0000000..0eb21e7 --- /dev/null +++ b/src/models/contemporary-props/ceramic-vase/model.ts @@ -0,0 +1,128 @@ +/** + * @contemporary-props/ceramic-vase + * + * First object in the kit, and it is here to settle the revolve. + * + * Almost everything with a round section that follows depends on the same + * profile machinery: the mug, the pepper mill, the stockpot, the basin, the + * bollard, the traffic cone, every knob, foot and column. So the vase is built + * as a curve rather than as a shape. Four control heights carry it, and each + * one is named after what it does to the silhouette: + * + * foot where it meets the table, narrower than the belly so the vase + * looks placed rather than poured + * belly the widest point, and the parameter that decides whether this is + * a bud vase or an urn + * shoulder where the wall turns back in, and the one place a generated + * vessel usually goes wrong: put it too high and the profile reads + * as a bottle, too low and it reads as a bowl + * lip the mouth, rolled slightly proud of the neck so the rim catches + * light and the opening does not look like a hole cut in a solid + * + * The wall has no thickness. A vase is looked at from outside and the inside of + * the neck is dark at every angle a prop is seen from, so modelling the bore + * would spend triangles on something nothing ever sees. The rim reads because + * the lip steps out, not because there is a wall behind it. + * + * Parts: `body` alone. There is nothing here that moves or that a consumer + * would want to reach separately, and inventing parts to look thorough makes + * the protocol noisier without making the model more useful. + */ +import { type BufferGeometry } from 'three' + +import { + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface CeramicVaseConfig { + /** Overall height (metres). */ + readonly height: number + /** Widest radius, at the belly (metres). */ + readonly bellyRadius: number + /** Where the belly sits, as a fraction of the height. */ + readonly bellyAt: number + /** Mouth radius as a fraction of the belly radius. */ + readonly mouth: number + /** Sides around the revolve. Low values are a deliberate faceted look. */ + readonly segments: number + readonly seed: number +} + +export const ceramicVaseDefaults: CeramicVaseConfig = { + height: 0.32, + bellyRadius: 0.105, + // Just below the middle. A belly at or above half height reads as a bottle, + // and this is the single number that decides whether the silhouette is right. + bellyAt: 0.42, + mouth: 0.52, + segments: 32, + seed: 11, +} + +export type CeramicVaseParts = 'body' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'ceramic-vase', + defaults: ceramicVaseDefaults, + slots: ['ceramic'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = config.height + const belly = config.bellyRadius + const bellyY = H * Math.min(0.72, Math.max(0.18, config.bellyAt)) + const mouth = belly * Math.min(0.9, Math.max(0.2, config.mouth)) + + // The foot is a fraction of the belly rather than a free parameter: a + // vase whose base can be set independently can be given a base wider + // than its body, and there is no value of that which looks like a vase. + const foot = belly * 0.62 + const shoulderY = bellyY + (H - bellyY) * 0.58 + const neck = mouth * 1.04 + + const levels: Level[] = [ + { y: 0, radius: foot * 0.94 }, + // A short straight rise off the table before the curve starts. Without + // it the profile leaves the ground at an angle and the vase looks like + // it is sinking into the surface. + { y: H * 0.035, radius: foot }, + { y: bellyY * 0.55, radius: belly * 0.93 }, + { y: bellyY, radius: belly }, + { y: shoulderY, radius: belly * 0.74 }, + { y: H * 0.93, radius: neck }, + // The lip: proud of the neck by a hair, so the mouth has an edge to + // catch light rather than being a hole in the top. + { y: H * 0.97, radius: neck * 1.09 }, + { y: H, radius: neck * 1.06 }, + ] + + const pieces: BufferGeometry[] = [ + latheGeometry( + levels, + Math.max(8, Math.round(config.segments)), + [0, 0, 0], + tint('ceramic', jitter(random, 0.02)), + // Glaze pools slightly toward the foot and thins over the shoulder, + // so the top is a touch lighter. It is a small difference and it is + // what stops a single-slot object reading as flat plastic. + { colourTop: tint('ceramic', 0.05), capBottom: true, capTop: false }, + ), + ] + + // Smoothed at 40 degrees. The wall is a curve and reads as one; the + // lip, the foot and the base cap all turn through more than that and + // stay as edges. Flat shading put a visible band at every level of the + // profile, which on a glazed white surface is the first thing you see. + return { + body: { slot: 'ceramic' as const, geometry: smoothNormals(mergeColoured(pieces), 40) }, + } + }, + }, overrides) +} diff --git a/src/models/contemporary-props/coffee-mug/model.ts b/src/models/contemporary-props/coffee-mug/model.ts new file mode 100644 index 0000000..ad1caa7 --- /dev/null +++ b/src/models/contemporary-props/coffee-mug/model.ts @@ -0,0 +1,220 @@ +/** + * @contemporary-props/coffee-mug + * + * The kit's second revolve, and its first join: a swept handle attached to a + * lathed body. The join is the point. The kettle, the jug, the watering can + * and the saucepan all reuse it, so the mug is where it has to be got right. + * + * Two things separate a mug from the vase it inherits its lathe from: + * + * the bore a mug is looked INTO. The profile goes up the outside, rolls + * over the rim, and comes back down inside to a floor, so the + * rim has a measurable thickness and the inner wall catches + * light. The vase could skip its bore; a mug with no bore is a + * dummy prop and reads as one from any angle above the rim. + * + * the handle a strap, not a rod. The section is wider across than it is + * deep, which is what says "ceramic pulled from the wall" + * rather than "wire bent into a loop". It is one arc whose two + * ends land INSIDE the wall: the end depth is computed from the + * wall thickness and the cap tilt so that at every value of the + * `handle` control the caps stay buried, clear of the outer + * surface on one side and of the bore on the other. On a + * tapered body the loop tilts to follow the wall, the way a + * real handle is stuck on parallel to the side it joins. + * + * The wall is deliberately chunky, diner-mug thick. Partly because that is + * what a stoneware mug is, and partly because the wall is the material the + * handle ends are buried in: a fine porcelain wall leaves no solid for the + * join to live inside. + * + * Parts: `body` and `handle`. The handle is the part a consumer will want to + * reach separately, whether to drop it for an espresso cup or to recolour a + * glazed accent. + */ +import { type BufferGeometry } from 'three' + +import { + arcBarGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface CoffeeMugConfig { + /** Overall height (metres). */ + readonly height: number + /** Outer radius at the rim (metres). */ + readonly radius: number + /** Foot radius as a fraction of the rim radius. 1 is a straight diner mug. */ + readonly taper: number + /** How far the handle bows out. 1 is a standard loop. */ + readonly handle: number + /** Sides around the revolve. Low values are a deliberate faceted look. */ + readonly segments: number + readonly seed: number +} + +export const coffeeMugDefaults: CoffeeMugConfig = { + height: 0.095, + radius: 0.041, + // A slight taper. Dead straight is a value in the family, not the default: + // most mugs narrow a little toward the foot and it keeps the silhouette + // from reading as a cut length of pipe. + taper: 0.9, + handle: 1, + segments: 32, + seed: 7, +} + +export type CoffeeMugParts = 'body' | 'handle' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'coffee-mug', + defaults: coffeeMugDefaults, + slots: ['ceramic'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = config.height + const R = config.radius + const taper = Math.min(1, Math.max(0.7, config.taper)) + const F = R * taper + const segments = Math.max(10, Math.round(config.segments)) + + // The wall. Thick enough to read at the rim and, just as important, + // thick enough that the handle ends can be buried in it with margin on + // both faces. The floor stops a small mug from getting a paper wall. + const wall = Math.max(0.0058, R * 0.15) + // A mug's base is heavier than its wall; the bore floor sits up here. + const base = Math.max(0.006, H * 0.085) + + // Outer radius at height y: a straight taper with a faint barrel bow. + // The bow is under two percent, which is invisible as a shape but keeps + // a highlight moving along the wall instead of sitting in one stripe. + const rOut = (y: number): number => { + const f = y / H + return (F + (R - F) * f) * (1 + 0.013 * Math.sin(Math.PI * f)) + } + + /* ------------------------------------------------------------- body */ + // One profile, up the outside, over the rim, down the bore. A single + // lathe leaves no coincident faces where an outer and an inner shell + // would meet, and the rim thickness falls out of the turn-around. + const half = wall / 2 + const rimY = H - half + const rimX = R - half + const s45 = half * Math.SQRT1_2 + const levels: Level[] = [ + // A short chamfer off the table, so the foot has an edge that reads + // as trimmed rather than the wall dying into the ground plane. + { y: 0, radius: F * 0.96 }, + { y: 0.0035, radius: rOut(0.0035) }, + { y: H * 0.2, radius: rOut(H * 0.2) }, + { y: H * 0.45, radius: rOut(H * 0.45) }, + { y: H * 0.7, radius: rOut(H * 0.7) }, + { y: H * 0.88, radius: rOut(H * 0.88) }, + // The rim, rolled as a half circle of the wall's own thickness, + // sampled every 45 degrees so smoothing reads it as a curve. + { y: rimY, radius: R }, + { y: H - half + s45, radius: rimX + s45 }, + { y: H, radius: rimX }, + { y: H - half + s45, radius: rimX - s45 }, + { y: rimY, radius: R - wall }, + // Down the bore. Same profile as the outside, one wall in, so the + // rim reads as an even thickness from every angle that sees into it. + { y: H * 0.66, radius: rOut(H * 0.66) - wall }, + { y: H * 0.42, radius: rOut(H * 0.42) - wall }, + { y: base + 0.0025, radius: rOut(base + 0.0025) - wall }, + { y: base, radius: rOut(base + 0.0025) - wall - 0.0012 }, + ] + + const glaze = tint('ceramic', jitter(random, 0.02)) + const body = latheGeometry( + levels, + segments, + [0, 0, 0], + glaze, + // The index ramp runs foot -> rim -> floor, so the outside lightens + // toward the rim the way thinning glaze does, and the bore stays a + // touch lighter than the outside, which stops it going to mud once + // the renderer shades the cavity. + { colourTop: tint('ceramic', 0.05), capBottom: true, capTop: true }, + ) + + /* ----------------------------------------------------------- handle */ + // Strap section: deeper across (z, along the wall) than radially. Built + // square by arcBarGeometry, flattened by a scale before it moves. + const scaleT = R / 0.041 + const tRad = Math.min(0.0072, Math.max(0.0048, 0.006 * scaleT)) + const widthZ = Math.min(0.0135, Math.max(0.0088, 0.0115 * scaleT)) + + // Where the loop leaves the wall. + const topY = H * 0.78 + const botY = H * 0.36 + const wallTop = rOut(topY) + const wallBot = rOut(botY) + + // End angle past 90 degrees turns the ends in toward the wall; the + // `handle` control widens the bow. Capped where the cap tilt would + // start pushing corners through the bore. + const bow = Math.min(1.3, Math.max(0.7, config.handle)) + const thetaE = (Math.PI / 180) * Math.min(125, Math.max(109, 95 + 23 * bow)) + + // Bury depth for the end caps. The cap is a tilted rectangle: its + // corners reach `capTilt` past the end centre radially, and at the + // strap's z-edges the round wall has receded by `recess`. The depth + // sits centred between "corner breaks out of the wall" and "corner + // breaks into the bore", with margin on both sides. + const capTilt = Math.abs(Math.cos(thetaE)) * (tRad / 2) + const recess = wallBot - Math.sqrt(Math.max(0, wallBot * wallBot - (widthZ / 2) ** 2)) + const dMin = recess + 0.0006 + capTilt + const dMax = wall - 0.0006 - capTilt + const depth = dMin < dMax ? (dMin + dMax) / 2 : wall * 0.5 + + const eTop = { x: wallTop - depth, y: topY } + const eBot = { x: wallBot - depth, y: botY } + const chordX = eTop.x - eBot.x + const chordY = eTop.y - eBot.y + const chord = Math.hypot(chordX, chordY) + const rLoop = chord / 2 / Math.sin(thetaE) + // Tilt that lays the loop's chord along the wall slope, so on a tapered + // body both ends sit at the same depth instead of one floating proud. + const alpha = Math.atan2(-chordX, chordY) + + const strap = arcBarGeometry( + rLoop, tRad, -thetaE, thetaE, 22, [0, 0, 0], + // The body's own glaze colour: a handle tinted separately shows the + // join as a colour edge before it shows it as geometry. + glaze.clone(), + ) + // Flatten to a strap, tilt to the wall, then carry to the wall. Built + // at the origin in the XY plane, which is already the vertical plane + // the loop lives in, so no other rotation is needed. + strap.scale(1, 1, widthZ / tRad) + strap.rotateZ(alpha) + const endBotX = rLoop * Math.cos(thetaE) + const endBotY = -rLoop * Math.sin(thetaE) + strap.translate( + eBot.x - (Math.cos(alpha) * endBotX - Math.sin(alpha) * endBotY), + eBot.y - (Math.sin(alpha) * endBotX + Math.cos(alpha) * endBotY), + 0, + ) + + const bodyPieces: BufferGeometry[] = [body] + // Smoothed at 50: the rim's 45 degree steps round over, while the foot + // chamfer against the base cap stays an edge. The handle smooths along + // its sweep at 40 and keeps its four strap edges crisp, which is what + // makes the section read as a section. + return { + body: { slot: 'ceramic' as const, geometry: smoothNormals(mergeColoured(bodyPieces), 50) }, + handle: { slot: 'ceramic' as const, geometry: smoothNormals(strap, 40) }, + } + }, + }, overrides) +} diff --git a/src/models/contemporary-props/core/geometry.ts b/src/models/contemporary-props/core/geometry.ts index 46d4a0c..afac52d 100644 --- a/src/models/contemporary-props/core/geometry.ts +++ b/src/models/contemporary-props/core/geometry.ts @@ -1,4 +1,4 @@ -import { BufferAttribute, BufferGeometry, Color } from 'three' +import { BufferAttribute, BufferGeometry, Color, Vector3 } from 'three' import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js' /** @@ -6,8 +6,14 @@ import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js' * * Everything is generated NON-INDEXED. The reason: on non-indexed geometry * computeVertexNormals() gives every triangle its own normal, so flat shading - * becomes a natural consequence of the geometry — no material flag is needed. - * In lowpoly that is exactly what we want. + * becomes a natural consequence of the geometry and no material flag is needed. + * + * That was the whole answer in a kit with a lowpoly budget, where a barrel is + * meant to read as staves. This kit has no such budget and is full of turned + * and pressed objects that are genuinely smooth: a kettle, a basin, a mug, a + * bollard, a traffic cone. Flat shading those puts visible bands across every + * curve, so `smoothNormals` below is the way out, applied per object rather + * than globally, because the choice belongs to the object. * * Position frame: point(a, r, y) = (sin a · r, y, cos a · r) * So a = 0 → the +Z direction; as a grows it turns toward +X. @@ -868,3 +874,75 @@ export function mottleGeometry( colour.needsUpdate = true return geometry } + +/** + * Averages normals across edges that are not creases, in place. + * + * Non-indexed geometry has no idea which triangles are neighbours, so this + * finds out the only way available: vertices at the same POSITION belong + * together. Positions are quantised before comparison because two triangles + * that share an edge were generated from the same numbers and land on the same + * point to the last bit, while anything merely close is a different corner. + * + * The crease angle is what makes it usable. Averaging every shared vertex + * would round the rim of the vase into the wall and the foot into the table, + * which is how a smoothed lowpoly object turns to soap. Only faces that agree + * to within the crease angle are averaged with each other, so a curve comes + * out smooth and an edge stays an edge, with no hand-marked smoothing groups. + * + * @param crease Degrees. 30 keeps chamfers crisp; 60 smooths all but hard + * corners; above about 80 everything melts together. + */ +export function smoothNormals(geometry: BufferGeometry, crease = 40): BufferGeometry { + const position = geometry.getAttribute('position') + if (!position || geometry.getIndex()) return geometry + const count = position.count + const limit = Math.cos((crease * Math.PI) / 180) + + // Face normal per triangle, computed once. + const faceNormal = new Float32Array((count / 3) * 3) + const ax = new Vector3(), bx = new Vector3(), cx = new Vector3() + const e1 = new Vector3(), e2 = new Vector3(), n = new Vector3() + for (let f = 0; f < count / 3; f += 1) { + ax.fromBufferAttribute(position, f * 3) + bx.fromBufferAttribute(position, f * 3 + 1) + cx.fromBufferAttribute(position, f * 3 + 2) + n.copy(e1.subVectors(bx, ax)).cross(e2.subVectors(cx, ax)) + if (n.lengthSq() > 0) n.normalize() + faceNormal[f * 3] = n.x; faceNormal[f * 3 + 1] = n.y; faceNormal[f * 3 + 2] = n.z + } + + // Which faces meet at each position. + const at = new Map() + const key = (i: number): string => { + const x = Math.round(position.getX(i) * 1e5) + const y = Math.round(position.getY(i) * 1e5) + const z = Math.round(position.getZ(i) * 1e5) + return `${x},${y},${z}` + } + for (let i = 0; i < count; i += 1) { + const k = key(i) + const list = at.get(k) + if (list) list.push(Math.floor(i / 3)) + else at.set(k, [Math.floor(i / 3)]) + } + + const out = new Float32Array(count * 3) + const sum = new Vector3() + for (let i = 0; i < count; i += 1) { + const face = Math.floor(i / 3) + n.set(faceNormal[face * 3]!, faceNormal[face * 3 + 1]!, faceNormal[face * 3 + 2]!) + sum.set(0, 0, 0) + for (const other of at.get(key(i)) ?? [face]) { + const m = new Vector3(faceNormal[other * 3]!, faceNormal[other * 3 + 1]!, faceNormal[other * 3 + 2]!) + // Only neighbours on the same side of the crease contribute. A face + // beyond it keeps its own normal and the edge survives. + if (m.dot(n) >= limit) sum.add(m) + } + if (sum.lengthSq() === 0) sum.copy(n) + sum.normalize() + out[i * 3] = sum.x; out[i * 3 + 1] = sum.y; out[i * 3 + 2] = sum.z + } + geometry.setAttribute('normal', new BufferAttribute(out, 3)) + return geometry +} diff --git a/src/models/contemporary-props/core/index.ts b/src/models/contemporary-props/core/index.ts index 369a420..599f91f 100644 --- a/src/models/contemporary-props/core/index.ts +++ b/src/models/contemporary-props/core/index.ts @@ -14,6 +14,7 @@ export { prismGeometry, roughenGeometry, staveGeometry, + smoothNormals, taperedBoxGeometry, } from './geometry.ts' export type { Level, MottleOptions, RoughenOptions, SheetLevel, Vec3 } from './geometry.ts' diff --git a/src/models/contemporary-props/pepper-mill/model.ts b/src/models/contemporary-props/pepper-mill/model.ts new file mode 100644 index 0000000..caf39e8 --- /dev/null +++ b/src/models/contemporary-props/pepper-mill/model.ts @@ -0,0 +1,269 @@ +/** + * @contemporary-props/pepper-mill + * + * Table pepper mill: the longest profile curve in the kit at the lowest cost, + * and the first radial cut. + * + * The body is one lathe and the whole object is decided by where that curve + * turns. Reading from the table up: a drum for the grinder housing, a turn + * inward to the waist, a swell back out to an upper belly that stays narrower + * than the base, then a quick fall into the neck the cap sits over. The upper + * belly NARROWER than the base is the load-bearing choice: make them equal and + * the silhouette is a baluster, make the top wider and it is a chess queen + * about to tip over. + * + * The flutes are what stop it reading as a chess piece even so. A lathe cannot + * cut a groove, so the grip is built the other way round: a radial array of + * slim chamfered bars standing a millimetre proud of the waist. Because the + * waist is the narrowest point of the profile, a straight vertical bar held at + * a fixed radius is proud exactly in the middle and sinks into the body at + * both ends on its own — no cap, no fade, both ends terminate inside the + * solid. The proud height is recomputed against the actual profile for every + * configuration, so a fat waist under a low bulge cannot push a bar end + * through the surface. + * + * Parts: `body` and `cap`. The cap is its own part with its origin at the seat + * so `cap.anchor.rotation.y` is the grinding action, and the `twist` action + * does exactly that. A turned dome is rotationally invisible, so the motion is + * carried by the crown: the stainless finial nut is a 6-segment lathe — a hex + * acorn — and its facets are what you see move. + */ +import { type BufferGeometry } from 'three' + +import { + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface PepperMillConfig { + /** Overall height, finial included (metres). */ + readonly height: number + /** Radius of the base drum (metres). */ + readonly baseRadius: number + /** Waist radius as a fraction of the base radius. */ + readonly waist: number + /** Where the waist sits, as a fraction of the body height. */ + readonly waistAt: number + /** Number of grip flutes around the waist. */ + readonly flutes: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const pepperMillDefaults: PepperMillConfig = { + height: 0.23, + baseRadius: 0.03, + // The waist is what separates a mill from a rolling pin. Below ~0.5 it + // reads as an hourglass, above ~0.7 the profile goes straight and the + // flutes are doing all the work alone. + waist: 0.58, + waistAt: 0.5, + flutes: 16, + segments: 32, + seed: 23, +} + +export type PepperMillParts = 'body' | 'cap' + +export interface PepperMillActions { + /** Turns the cap — the grind. Default is a sixth of a turn. */ + twist(radians?: number): void +} + +/** Linear read of a lathe profile at an arbitrary height. */ +function radiusAt(levels: readonly Level[], y: number): number { + if (y <= levels[0]!.y) return levels[0]!.radius + for (let i = 0; i < levels.length - 1; i += 1) { + const a = levels[i]! + const b = levels[i + 1]! + if (y <= b.y) { + const t = (y - a.y) / Math.max(1e-9, b.y - a.y) + return a.radius + t * (b.radius - a.radius) + } + } + return levels.at(-1)!.radius +} + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'pepper-mill', + defaults: pepperMillDefaults, + slots: ['wood', 'stainless'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = Math.min(0.45, Math.max(0.12, config.height)) + // The radius is clamped against the height, not just on its own: a mill + // is between roughly two and six diameters tall. Outside that band the + // squat end turns into a jar on a pedestal and the thin end into a + // taper candle, and both were seen in a render before this clamp. + const R = Math.min(H * 0.21, Math.max(H * 0.08, Math.min(0.05, Math.max(0.015, config.baseRadius)))) + const segments = Math.max(12, Math.round(config.segments)) + const waistFraction = Math.min(0.68, Math.max(0.45, config.waist)) + const waistAt = Math.min(0.6, Math.max(0.42, config.waistAt)) + const flutes = Math.max(8, Math.min(28, Math.round(config.flutes))) + + // The cap takes the top ~16% of the height and overlaps the neck by a + // few millimetres, so the parting line is a step rather than a seam of + // two coplanar rings. + const bodyH = H * 0.84 + const seat = bodyH - 0.004 + + const W = R * waistFraction + const waistY = bodyH * waistAt + // The grip is a band, not a point: the waist holds its radius for a + // stretch so the flutes sit on something, and the cove into and out of + // it is what makes the profile a mill rather than a bottle. + const bandHalf = bodyH * 0.09 + // The upper belly is clearly SMALLER than the drum: the masses must + // step down going up — drum, belly, head — or the object turns into a + // chess bishop. It still follows the waist up when the waist is fat, so + // the swell never dips below the flute tops. + const upperR = R * Math.max(0.72, waistFraction * 1.08) + const upperY = bodyH * 0.74 + + /* ------------------------------------------------------------- body */ + const waistLo = waistY - bandHalf + const waistHi = waistY + bandHalf + // The shoulder backs off when the waist sits low, so the cove into the + // grip keeps some run and the drum does not turn into a pedestal. + const shoulderY = Math.min(bodyH * 0.3, waistLo - bodyH * 0.08) + const drumTop = shoulderY - bodyH * 0.1 + const bodyLevels: Level[] = [ + { y: 0, radius: R * 0.97 }, + // Crisp foot, same reasoning as the vase: the profile must leave the + // table vertically or the mill looks like it is sinking into it. + { y: 0.005, radius: R }, + // The grinder drum: a near-cylinder, because that is the one straight + // stretch a mill has and softening it is what turned the first render + // into a crayon. + { y: drumTop, radius: R * 0.985 }, + { y: shoulderY, radius: R * 0.93 }, + { y: (shoulderY + waistLo) / 2, radius: ((R * 0.93 + W) / 2) * 1.015 }, + { y: waistLo, radius: W * 1.01 }, + { y: waistY, radius: W }, + { y: waistHi, radius: W * 1.01 }, + // The rise off the grip band is deliberately quick, so the flute bar + // ends go under the surface within a couple of millimetres. + { y: waistHi + (upperY - waistHi) * 0.4, radius: ((W + upperR) / 2) * 1.02 }, + { y: upperY, radius: upperR }, + { y: bodyH * 0.83, radius: upperR * 0.9 }, + // The throat: the belly turns in to a short neck the cap's lip steps + // out over, so the parting line reads as a groove under the head. + { y: bodyH * 0.91, radius: R * 0.56 }, + { y: bodyH, radius: R * 0.52 }, + ] + + const woodBase = tint('wood', jitter(random, 0.02)) + const pieces: BufferGeometry[] = [ + latheGeometry(bodyLevels, segments, [0, 0, 0], woodBase, { + colourTop: tint('wood', 0.04), + capBottom: true, + capTop: true, + }), + ] + + /* ----------------------------------------------------------- flutes */ + // Half the vertical span of a flute bar: the grip band plus enough of + // the cove beyond it for the profile to rise over the bar ends. + const fluteHalf = bodyH * 0.13 + // How far a bar stands proud of the waist. Capped by the profile: the + // bar ends must stay under the surface, including the flat-to-flat + // shrink of the revolve's polygon. + const inscribed = Math.cos(Math.PI / segments) + const endRadius = Math.min( + radiusAt(bodyLevels, waistY - fluteHalf), + radiusAt(bodyLevels, waistY + fluteHalf), + ) * inscribed + const proud = Math.max(0.0005, Math.min(R * 0.04, endRadius - W - 0.0005)) + const depth = R * 0.22 + // Nearly touching: the grip reads from the narrow dark gaps between + // ridges, not from the ridges themselves. + const barWidth = Math.min((2 * Math.PI * W) / flutes * 0.72, R * 0.2) + const barCentreRadius = W + proud - depth / 2 + + for (let i = 0; i < flutes; i += 1) { + const angle = (i / flutes) * Math.PI * 2 + const bar = chamferedBoxGeometry( + [barWidth, depth], + [barWidth, depth], + fluteHalf * 2, + Math.min(0.0008, barWidth * 0.25), + [0, 0, 0], + // Subtle: the flutes are turned from the same blank as the body, + // so they may not jump in tone. Relief and occlusion carry them. + tint('wood', jitter(random, 0.015)), + ) + // Built at the origin, turned, then carried out to the waist. + bar.rotateY(angle) + bar.translate(Math.sin(angle) * barCentreRadius, waistY, Math.cos(angle) * barCentreRadius) + pieces.push(bar) + } + + /* -------------------------------------------------------------- cap */ + // Everything below is LOCAL to the seat: the part's origin sits there + // so rotation.y grinds. + const capH = H - seat + const domeH = capH * 0.6 + const capLevels: Level[] = [ + { y: 0, radius: R * 0.55 }, + // The lip rolls out well past the neck so the cap reads as a + // separate piece that comes off, not a continuation of the profile. + { y: 0.004, radius: R * 0.6 }, + // The head swells a touch before rounding over: a straight-sided cap + // read as a bottle top, and this is the swell that makes it a turban. + { y: domeH * 0.3, radius: R * 0.61 }, + { y: domeH * 0.6, radius: R * 0.55 }, + { y: domeH * 0.85, radius: R * 0.42 }, + { y: domeH, radius: R * 0.32 }, + ] + const dome = latheGeometry(capLevels, segments, [0, 0, 0], tint('wood', jitter(random, 0.02)), { + colourTop: tint('wood', 0.05), + capBottom: true, + capTop: true, + }) + + // The crown: a hex acorn, 6 segments on purpose. Its base is sunk into + // the dome, its facets are what make the twist visible. + const nutR = R * 0.22 + const nutLevels: Level[] = [ + { y: domeH - 0.003, radius: nutR * 0.72 }, + { y: domeH + 0.0008, radius: nutR }, + { y: capH * 0.87, radius: nutR }, + { y: capH * 0.95, radius: nutR * 0.7 }, + { y: capH, radius: nutR * 0.36 }, + ] + const nut = latheGeometry(nutLevels, 6, [0, 0, 0], tint('stainless', jitter(random, 0.02), 0.5), { + colourTop: tint('stainless', 0.04, 0.5), + capBottom: true, + capTop: true, + }) + + // 40 degrees: the revolve and the dome smooth, the foot, the lip, the + // flute chamfers and the hex facets all turn harder than that and stay + // edges. + return { + body: { slot: 'wood' as const, geometry: smoothNormals(mergeColoured(pieces), 40) }, + cap: { + slot: 'wood' as const, + geometry: smoothNormals(mergeColoured([dome]), 40), + extras: [{ slot: 'stainless' as const, geometry: smoothNormals(mergeColoured([nut]), 30) }], + origin: [0, seat, 0] as const, + }, + } + }, + + actions: ({ parts }) => ({ + twist: (radians = Math.PI / 3) => { + parts.cap.anchor.rotation.y += radians + }, + }), + }, overrides) +} diff --git a/src/models/contemporary-props/stockpot/model.ts b/src/models/contemporary-props/stockpot/model.ts new file mode 100644 index 0000000..2751755 --- /dev/null +++ b/src/models/contemporary-props/stockpot/model.ts @@ -0,0 +1,264 @@ +/** + * @contemporary-props/stockpot + * + * The kit's first metal vessel, and it exists to settle three details that + * every metal vessel afterwards reuses: the rolled rim, the riveted lug, and + * the separable sit-in lid. + * + * The rolled rim is the whole read. A pot without one is a cylinder, so the + * rim here is a real curl: the profile reaches the top of the wall and then + * travels 280 degrees around a small circle — down into the crevice under the + * roll, out, over the top, and back in — before tucking into the bore. That + * traversal direction is not decorative: the lathe orients faces by which way + * the profile walks (up gives outward, out gives down, down gives inward), so + * a curl sampled the obvious way, straight over the top from the wall, comes + * out inside-out on its underside. Walking the circle in one consistent sense + * keeps every face of the curl pointing at the air it actually touches. + * + * Unlike the vase, the pot models a short bore: a real interior wall drops + * from inside the rim to a false floor at 42% of the height. The vase never + * shows its inside; this object's one action is lifting the lid off, and an + * open pot that is a hollow shell with the world visible through it is worse + * than any number of extra triangles. The floor is deep enough to sit in + * occlusion shadow and shallow enough that nothing pays for the part of the + * bore no camera reaches. + * + * The lid is one profile too: a flange that drops inside the mouth (a lid + * that merely rests on top reads as a plate), a step that seats on the rim, a + * rolled edge matching the pot's, a dome, and the knob — stem, flare, cap — + * continued from the same curve so the whole lid is a single connected solid. + * The knob keeps a fixed hand size rather than scaling with the pot, for the + * same reason the lugs do: hands do not scale with cookware. + * + * Each lug is a strap loop swept as a square-section arc, tilted up 25 + * degrees and standing about 30mm clear of the wall so a hand fits, with both + * ends buried inside a chamfered mounting plate that is itself embedded into + * the wall. The rivet heads sit over the buried strap ends, which is where a + * rivet would actually be. + * + * One slot, `stainless`, everywhere. A stainless stockpot really is one + * material; the lugs and rivets separate from the body by tint and by the + * occlusion crevices around the plate, not by a material change. + * + * Parts: `body` and `lid`. The lid's anchor sits at the rim plane, so + * `liftLid` is a straight translation and anything the consumer stood on the + * lid rises with it. + */ +import { type BufferGeometry } from 'three' + +import { + arcBarGeometry, + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface StockpotConfig { + /** Body outer diameter (metres). */ + readonly diameter: number + /** Body height to the rim (metres). The lid and knob add to it. */ + readonly height: number + /** Lid dome rise as a fraction of the body radius. Low is a saucepot lid, high a casserole. */ + readonly lidDome: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const stockpotDefaults: StockpotConfig = { + // A 26 x 24 cm pot, roughly eleven litres: unmistakably a stockpot rather + // than a saucepan, and still a size that exists in an ordinary kitchen. + diameter: 0.26, + height: 0.24, + lidDome: 0.16, + segments: 48, + seed: 7, +} + +export type StockpotParts = 'body' | 'lid' + +export interface StockpotActions { + /** Lifts the lid clear of the rim, or seats it again. No argument toggles. */ + liftLid(lifted?: boolean): void +} + +const clampDiameter = (v: number): number => Math.min(0.4, Math.max(0.14, v)) +const clampHeight = (v: number): number => Math.min(0.36, Math.max(0.1, v)) + +const deg = (d: number): number => (d * Math.PI) / 180 + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'stockpot', + defaults: stockpotDefaults, + slots: ['stainless'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const R = clampDiameter(config.diameter) / 2 + const H = clampHeight(config.height) + const segments = Math.max(16, Math.round(config.segments)) + // Roll radius: scales gently with the pot but stays in the few-millimetre + // band a pressed rim actually has. Bigger and the rim reads as a pipe + // welded on; smaller and it vanishes at prop distance. + const rr = Math.min(0.0045, Math.max(0.002, R * 0.026)) + const wall = 0.004 + const bore = R - wall + const floorY = H * 0.42 + + const steel = tint('stainless', jitter(random, 0.02)) + + /* ------------------------------------------------------------- body */ + + const bodyLevels: Level[] = [ + { y: 0, radius: R * 0.96 }, + // A short chamfer off the table, then the wall. Stockpot walls are + // straight; the character lives entirely at the top. + { y: 0.006, radius: R }, + { y: H * 0.45, radius: R }, + // Tangent point where the wall meets the roll. + { y: H - rr, radius: R }, + ] + // The curl, walked in increasing angle so every face points outward: + // under the roll (200-280), out and over the top (280-450), back in + // toward the mouth (450-480). + for (let a = 200; a <= 480; a += 40) { + bodyLevels.push({ + y: H - rr + Math.sin(deg(a)) * rr, + radius: R + rr + Math.cos(deg(a)) * rr, + }) + } + bodyLevels.push( + // Tuck from the inner lip into the bore, then the false floor. + { y: H - rr * 0.8, radius: bore }, + { y: floorY + 0.005, radius: bore }, + { y: floorY, radius: bore - 0.004 }, + ) + + const pieces: BufferGeometry[] = [ + latheGeometry(bodyLevels, segments, [0, 0, 0], steel, { + capBottom: true, + capTop: true, // the false floor, facing up inside the bore + }), + ] + + /* ------------------------------------------------------------- lugs */ + + const ra = 0.021 + R * 0.024 // loop radius: mostly hand, a little pot + const bar = 0.009 // strap section; thinner reads as wire + const tilt = deg(18) + const lugY = Math.min(H - 0.03, H * 0.8) + // Ends of the 260-degree arc sit at (±cos40, -sin40) of the loop's local + // frame; the centre is placed so those ends land just outside the wall + // surface, buried inside the plate. + const endIn = Math.sin(deg(40)) * ra * Math.cos(tilt) + const endDown = Math.sin(deg(40)) * ra * Math.sin(tilt) + const plateW = 0.046 + R * 0.04 + const plateH = 0.032 + + for (const spin of [0, Math.PI]) { + const loop = arcBarGeometry(ra, bar, deg(-40), deg(220), 20, [0, 0, 0], + tint('stainless', 0.01)) + // Built in XY with the bulge up: turn the spread onto the tangent (Z), + // then lean the bulge out and 18 degrees above horizontal. + loop.rotateY(-Math.PI / 2) + loop.rotateZ(tilt - Math.PI / 2) + loop.translate(R + 0.001 + endIn, lugY, 0) + loop.rotateY(spin) + pieces.push(loop) + + // Mounting plate, embedded 5mm into the wall so its corners cannot + // daylight on a small pot where the flat plate leaves the curve. + const plate = chamferedBoxGeometry([0.01, plateW], [0.01, plateW], plateH, + 0.0012, [R + 0.001, lugY, 0], tint('stainless', -0.03)) + plate.rotateY(spin) + pieces.push(plate) + + // Rivet heads on the plate's lower half, clear of the strap, where the + // rivets that hold the plate to the wall actually sit. Under the strap + // ends they exist but cannot be seen, which is the same as not existing. + for (const side of [-1, 1]) { + const rivet = latheGeometry([ + { y: 0, radius: 0.005 }, + { y: 0.0024, radius: 0.0041 }, + { y: 0.0038, radius: 0.0018 }, + ], 10, [0, 0, 0], tint('stainless', -0.06)) + rivet.rotateZ(-Math.PI / 2) + rivet.translate(R + 0.0045, lugY - 0.009, side * 0.011) + rivet.rotateY(spin) + pieces.push(rivet) + } + } + + /* -------------------------------------------------------------- lid */ + + const flange = bore - 0.0008 + const domeH = R * Math.min(0.22, Math.max(0.04, config.lidDome)) + const knobBase = 0.007 + domeH + const lidLevels: Level[] = [ + // Flange: drops inside the mouth. Its bottom is capped so the lifted + // lid shows a closed underside rather than a hollow shell. + { y: -0.011, radius: flange * 0.9 }, + { y: -0.008, radius: flange }, + { y: -0.0005, radius: flange }, + // Seat step: walked outward, so it faces DOWN onto the rim. + { y: 0.0008, radius: R + rr * 1.4 }, + // Rolled lid edge, matching the pot's roll in reach. + { y: 0.0035, radius: R + rr * 2 }, + { y: 0.006, radius: R + rr * 1.2 }, + ] + // The dome is an elliptical arc, not straight lines to the knob: three + // linear levels read as a tent at any dome height worth having. + for (const phi of [18, 36, 54, 72, 84]) { + lidLevels.push({ + y: 0.006 + Math.sin(deg(phi)) * domeH, + radius: Math.cos(deg(phi)) * (R + rr * 1.2), + }) + } + lidLevels.push( + // Knob: fixed hand size, continued from the same profile. + { y: knobBase + 0.001, radius: 0.0065 }, + { y: knobBase + 0.014, radius: 0.0065 }, + { y: knobBase + 0.02, radius: 0.0125 }, + { y: knobBase + 0.024, radius: 0.0125 }, + { y: knobBase + 0.0265, radius: 0.0075 }, + { y: knobBase + 0.028, radius: 0.003 }, + ) + + const lid = latheGeometry(lidLevels, segments, [0, 0, 0], + tint('stainless', jitter(random, 0.02)), { capBottom: true, capTop: true }) + + // Smoothed at 40 degrees: the drum, the curl and the dome read as the + // pressed surfaces they are, while the strap's square section, the rim + // crevice, the seat step and every chamfer turn harder than that and + // survive as edges. + return { + body: { slot: 'stainless' as const, geometry: smoothNormals(mergeColoured(pieces), 40) }, + lid: { + slot: 'stainless' as const, + geometry: smoothNormals(mergeColoured([lid]), 40), + // Anchor at the rim plane: geometry is seat-relative, so lifting the + // lid is a translation of the anchor and nothing else. + origin: [0, H, 0] as const, + }, + } + }, + + actions: ({ parts, getConfig }) => { + let lifted = false + return { + liftLid(next?: boolean): void { + lifted = next ?? !lifted + const c = getConfig() + parts.lid.anchor.position.y = + clampHeight(c.height) + (lifted ? clampDiameter(c.diameter) * 0.55 : 0) + }, + } + }, + }, overrides) +} diff --git a/src/models/contemporary-props/traffic-cone/model.ts b/src/models/contemporary-props/traffic-cone/model.ts new file mode 100644 index 0000000..86ea034 --- /dev/null +++ b/src/models/contemporary-props/traffic-cone/model.ts @@ -0,0 +1,197 @@ +/** + * @contemporary-props/traffic-cone + * + * The clearest outline in the set, and the object where colour banding on a + * revolve gets defined. Every striped revolve after this one — the bollard, + * the channelizer drum, the barber pole if it ever comes — should copy the + * collar technique here rather than invent its own. + * + * The technique: the body is ONE radius profile, a single function of height, + * and a band is nothing but a y-range of that profile emitted into a different + * slot's geometry. Both sides of a boundary sample the profile at the same t, + * so the seam is watertight by construction, with no coincident faces and no + * gap. The collars additionally stand 3 mm proud of the wall — real cone + * sleeves are a wrap, not a print — which buys three things at once: the step + * ring catches light at the top and bottom of the band, the silhouette shows + * the sleeve, and the normal seam between the two geometries is hidden on an + * edge that is supposed to be there. + * + * The profile itself is not a straight cone. A moulded cone sags: the wall + * leaves the base wide and flares in quickly, then climbs to the tip nearly + * straight. That is a power curve, (1-t)^p with p above 1, and `flare` moves p. + * At flare 0 the profile is the straight cone of a traffic-cone pictogram, + * which is deliberately still in range. + * + * The base is square with a stepped lip: two chamfered tiers, the upper one + * smaller, which is how the moulding actually looks and what stops the cone + * reading as a witch's hat on a board. The body is planted 8 mm into the + * upper tier so nothing coincides with the base's top face. + * + * Parts: `base` and `body`. They are separate because a knocked-over cone is + * half the reason the object exists in scenes, and tipping is a rotation of + * the body against its base only in the cheap staged sense; more honestly, + * the base is the part a consumer recolours (recycled black PVC bases are + * everywhere) while the body stays hi-vis. + */ +import { type BufferGeometry } from 'three' + +import { + chamferedBoxGeometry, + createKitModel, + createTinter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface TrafficConeConfig { + /** Overall height (metres). 0.45 site cone up to 1.0 motorway cone. */ + readonly height: number + /** Square base width (metres). Clamped against height so the cone stays stable and stays a cone. */ + readonly baseWidth: number + /** Retroreflective collars: 1 (single wide sleeve) or 2 (motorway pair). */ + readonly collars: number + /** How concave the wall is. 0 is a straight cone, 1 a heavy moulded sag. */ + readonly flare: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const trafficConeDefaults: TrafficConeConfig = { + height: 0.75, + baseWidth: 0.4, + collars: 2, + flare: 0.55, + segments: 28, + seed: 7, +} + +export type TrafficConeParts = 'base' | 'body' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'traffic-cone', + defaults: trafficConeDefaults, + slots: ['plastic', 'retroreflective'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = Math.min(1.2, Math.max(0.3, config.height)) + // The base is clamped RELATIVE to the height. Real cones keep the base + // between roughly half and two thirds of the height; outside that the + // object either topples (too narrow) or reads as a pyramid on a raft. + const w = Math.min(0.6, Math.max(0.2, + Math.min(H * 0.72, Math.max(H * 0.42, config.baseWidth)))) + const collars = Math.round(config.collars) >= 2 ? 2 : 1 + const p = 1 + 0.9 * Math.min(1, Math.max(0, config.flare)) + const segments = Math.max(12, Math.round(config.segments)) + + // Spread kept low on the body: hi-vis orange is a controlled colour and + // a lightness jitter that is charming on ceramic drifts it toward salmon. + const bodyOrange = tint('retroreflective', -0.02, 0.4) + const baseOrange = tint('retroreflective', -0.09, 0.5) + const sleeveWhite = tint('paper', 0.03, 0.4) + + /* ------------------------------------------------------------- base */ + // Two chamfered tiers, the upper sunk 3 mm into the lower so its bottom + // face ends inside the solid rather than level with the lower's top. + const h1 = 0.014 + H * 0.010 + const h2 = 0.012 + H * 0.008 + const w2 = w * 0.8 + const baseTop = h1 - 0.003 + h2 + + const basePieces: BufferGeometry[] = [ + chamferedBoxGeometry([w, w], [w * 0.96, w * 0.96], h1, 0.006, + [0, h1 / 2, 0], baseOrange), + chamferedBoxGeometry([w2, w2], [w2 * 0.94, w2 * 0.94], h2, 0.005, + [0, h1 - 0.003 + h2 / 2, 0], tint('retroreflective', -0.07, 0.5)), + ] + + /* ------------------------------------------------------------- body */ + const bodyH = H - baseTop + const rFoot = w * 0.34 + const rTip = Math.min(0.02 + H * 0.008, rFoot * 0.45) + // The whole cone in one line. Everything below samples this and only + // this, which is what makes the banding seam-free. + const profile = (t: number): number => rTip + (rFoot - rTip) * Math.pow(1 - t, p) + const levelAt = (t: number, proud = 0): Level => + ({ y: baseTop + bodyH * t, radius: profile(t) + proud }) + + // Band positions as fractions of the body. The two-collar layout is the + // motorway one: the wider band on top, a gap, a narrower band below. + const bands: ReadonlyArray = + collars === 2 ? [[0.42, 0.56], [0.64, 0.85]] : [[0.5, 0.86]] + const proud = 0.003 + + // Interior samples on the concave curve, endpoints exact. + const sample = (t0: number, t1: number, proudBy: number): Level[] => { + const steps = Math.max(2, Math.ceil((t1 - t0) / 0.045)) + const levels: Level[] = [] + for (let i = 0; i <= steps; i += 1) { + levels.push(levelAt(t0 + ((t1 - t0) * i) / steps, proudBy)) + } + return levels + } + + const plasticPieces: BufferGeometry[] = [] + const collarPieces: BufferGeometry[] = [] + + const cuts = [0, ...bands.flat(), 1] + for (let i = 0; i < cuts.length - 1; i += 1) { + const t0 = cuts[i]! + const t1 = cuts[i + 1]! + const isBand = i % 2 === 1 + if (isBand) { + // A collar is the same profile span pushed out by `proud`, with a + // flat step ring at each end (two levels at one y) and OPEN ends: + // the first and last level sit ON the cone wall, so the sleeve + // meets the body on the body's own edge rings. + const levels: Level[] = [ + levelAt(t0), + ...sample(t0, t1, proud), + levelAt(t1), + ] + collarPieces.push(latheGeometry(levels, segments, [0, 0, 0], sleeveWhite, + { capBottom: false, capTop: false })) + continue + } + const first = i === 0 + const last = i === cuts.length - 2 + const levels: Level[] = sample(t0, last ? 1 - 0.008 / bodyH : t1, 0) + if (first) { + // Plant the foot 8 mm inside the base's upper tier. The bottom cap + // is buried in solid plastic, which is the only place a cap that + // nothing should ever see is allowed to be. + levels.unshift({ y: baseTop - 0.008, radius: profile(0) }) + } + if (last) { + // Blunt rolled tip. A cone does not come to a point; the mould + // rounds it off at about 70% of the tip radius. + levels.push({ y: H, radius: rTip * 0.7 }) + } + plasticPieces.push(latheGeometry(levels, segments, [0, 0, 0], bodyOrange, + { capBottom: first, capTop: last })) + } + + // Smoothed at 40 degrees: the concave wall and the sleeve faces read as + // curves, while the collar step rings, the blunt tip and every base + // chamfer turn through more than that and stay edges. + return { + base: { + slot: 'plastic' as const, + geometry: smoothNormals(mergeColoured(basePieces), 40), + }, + body: { + slot: 'plastic' as const, + geometry: smoothNormals(mergeColoured(plasticPieces), 40), + extras: [{ + slot: 'retroreflective' as const, + geometry: smoothNormals(mergeColoured(collarPieces), 40), + }], + }, + } + }, + }, overrides) +} diff --git a/src/models/contemporary-props/wine-glass/model.ts b/src/models/contemporary-props/wine-glass/model.ts new file mode 100644 index 0000000..358153d --- /dev/null +++ b/src/models/contemporary-props/wine-glass/model.ts @@ -0,0 +1,196 @@ +/** + * @contemporary-props/wine-glass + * + * Second object in the kit, and it is here to prove two things before anything + * expensive depends on them: wall thickness on a revolve, and the glass slot. + * + * The vase got away with a wall of zero thickness because ceramic is opaque + * and the bore is dark. Glass is not opaque. Look through a wine glass and + * what you actually see of it is its edges: the bright ellipse of the rim, the + * disc edge of the foot, and the thick mass where the bowl closes onto the + * stem. So the bowl here is a real shell: the profile runs UP the outside, + * steps across the rim, and comes back DOWN the inside to a dished floor that + * sits well above the outer bottom. That step across the rim is the whole + * point — a single-surface bowl in a transparent material has a rim one + * triangle wide, which flickers, and a bowl bottom with nothing in it, which + * reads as a soap bubble on a stick. + * + * One continuous lathe carries foot, stem, bowl and inner surface. Not three + * stacked pieces, for the reason the lathe exists at all: stacked revolves + * leave coincident faces where they meet, and in a transparent material every + * internal face is visible forever. + * + * The stem is the hard part of the silhouette. Too thick and the object is a + * goblet; too thin and at prop distance it disappears and the bowl floats. + * The config exposes it, clamped to 3.5–8 mm radius, which spans a delicate + * tasting glass to a sturdy bistro stem and nothing outside what a stem is. + * + * The family: bowl radius and rim tuck move it from a wide tucked-in red + * through a narrower white to a small open port glass; bowl depth against + * total height trades stem for bowl. + * + * Parts: `body` alone. Nothing on a wine glass moves, and slicing one revolve + * into named thirds would only invent seams. + */ +import { type BufferGeometry } from 'three' + +import { + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + smoothNormals, + type Level, +} from '../core/index.ts' + +export interface WineGlassConfig { + /** Overall height (metres). */ + readonly height: number + /** Widest radius of the bowl (metres). */ + readonly bowlRadius: number + /** Bowl height as a fraction of the overall height. */ + readonly bowlFraction: number + /** Rim radius as a fraction of the bowl radius. Low values tuck the rim in. */ + readonly rim: number + /** Stem radius (metres). The goblet/disappearing line is clamped at both ends. */ + readonly stemRadius: number + /** Sides around the revolve. */ + readonly segments: number + readonly seed: number +} + +export const wineGlassDefaults: WineGlassConfig = { + height: 0.215, + bowlRadius: 0.044, + // Just under half. More bowl than this reads as a brandy balloon, more stem + // reads as laboratory glassware. + bowlFraction: 0.48, + rim: 0.68, + stemRadius: 0.0045, + segments: 40, + seed: 7, +} + +export type WineGlassParts = 'body' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'wine-glass', + defaults: wineGlassDefaults, + slots: ['glass'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const clamp = (v: number, lo: number, hi: number): number => Math.min(hi, Math.max(lo, v)) + + const H = clamp(config.height, 0.12, 0.3) + const bowlR = clamp(config.bowlRadius, 0.025, Math.min(0.065, H * 0.42)) + const bowlH = H * clamp(config.bowlFraction, 0.32, 0.62) + const rimR = bowlR * clamp(config.rim, 0.52, 0.95) + // The stem is clamped twice: absolutely, and against the bowl. The + // absolute clamp keeps it a stem at all; the relative one stops a small + // glass given a fat stem turning into a candlestick, which is exactly + // what the first render of that corner was. + const stemR = clamp(config.stemRadius, 0.0035, Math.min(0.008, bowlR * 0.2)) + // The foot follows the bowl rather than being free: a foot wider than + // the bowl is a cake stand, a foot narrower than three stem widths falls + // over in the hand and in the eye. + const footR = Math.max(bowlR * 0.78, stemR * 3) + // Wall thickness scales gently with the bowl so a big balloon does not + // end up with cigarette-paper walls, floored where thinner would vanish. + const wall = Math.max(0.0016, bowlR * 0.042) + const bowlBaseY = H - bowlH + + /** + * Outer bowl profile, u = 0 at the stem junction, 1 at the rim. + * Below the belly an eased sine gives the rounded bottom; above it a + * cosine ease tucks the wall back in toward the rim, with a nonzero + * slope at the top so the rim tilts slightly inward like a red should. + */ + const bellyU = 0.45 + const rOut = (u: number): number => + u <= bellyU + ? bowlR * Math.sin((u / bellyU) * (Math.PI / 2)) ** 0.8 + : rimR + (bowlR - rimR) * Math.cos(((u - bellyU) / (1 - bellyU)) * (Math.PI / 2)) ** 1.35 + const yAt = (u: number): number => bowlBaseY + bowlH * u + + // The foot's vertical build scales with the glass: fixed heights that + // look right on a 21 cm red are a bell jar on a 12 cm port glass. + const fs = clamp(H / 0.215, 0.65, 1.15) + // Stem levels are fractions of the run between foot and bowl, so a short + // glass with a deep bowl cannot fold the stem back through the foot. + const footTipY = 0.0165 * fs + const s = (t: number): number => footTipY + (bowlBaseY - footTipY) * t + + const levels: Level[] = [ + // Foot: a disc with a rolled edge, rising as a shallow dome. The edge + // band is what the eye gets of the foot through the glass above it. + { y: 0, radius: footR * 0.985 }, + { y: 0.0018 * fs, radius: footR }, + { y: 0.0032 * fs, radius: footR * 0.94 }, + { y: 0.007 * fs, radius: footR * 0.5 }, + { y: 0.0125 * fs, radius: Math.max(footR * 0.2, stemR * 1.9) }, + { y: footTipY, radius: stemR * 1.5 }, + // Stem: a hair of entasis. Dead straight looks extruded; the swell at + // the top is where the pull into the bowl begins. + { y: s(0.22), radius: stemR * 1.06 }, + { y: s(0.6), radius: stemR * 0.94 }, + { y: s(0.93), radius: stemR * 1.05 }, + // Bowl, outside, base to rim. The lowest samples are floored at the + // stem radius: on a squat bowl the raw curve starts below the stem and + // the profile pinches in before flaring, which reads as a crack. + { y: yAt(0.03), radius: Math.max(rOut(0.03), stemR * 1.2) }, + { y: yAt(0.07), radius: Math.max(rOut(0.07), stemR * 1.45) }, + { y: yAt(0.13), radius: rOut(0.13) }, + { y: yAt(0.21), radius: rOut(0.21) }, + { y: yAt(0.31), radius: rOut(0.31) }, + { y: yAt(bellyU), radius: bowlR }, + { y: yAt(0.57), radius: rOut(0.57) }, + { y: yAt(0.7), radius: rOut(0.7) }, + { y: yAt(0.82), radius: rOut(0.82) }, + { y: yAt(0.92), radius: rOut(0.92) }, + { y: H, radius: rimR }, + // The rim: two levels at the same height, one wall thickness apart. + // The quad between them is the flat annulus that carries the whole + // top of the silhouette. + { y: H, radius: rimR - wall }, + // Inside, descending. Same profile inset by the wall, stopped short of + // the bottom so the bowl closes onto a solid mass above the stem. + { y: yAt(0.92), radius: rOut(0.92) - wall }, + { y: yAt(0.8), radius: rOut(0.8) - wall }, + { y: yAt(0.66), radius: rOut(0.66) - wall }, + { y: yAt(0.52), radius: rOut(0.52) - wall }, + { y: yAt(bellyU), radius: bowlR - wall }, + { y: yAt(0.36), radius: rOut(0.36) - wall }, + { y: yAt(0.27), radius: rOut(0.27) - wall }, + { y: yAt(0.2), radius: rOut(0.2) - wall }, + // Dished floor, then the cap closes it. Its height above the outer + // base is the thick lens of glass every stemmed glass has where the + // bowl was gathered onto the stem, and it is the third edge (after + // rim and foot) that makes transparent glass readable. + { y: yAt(0.13), radius: bowlR * 0.16 }, + ] + + const pieces: BufferGeometry[] = [ + latheGeometry( + levels, + Math.max(12, Math.round(config.segments)), + [0, 0, 0], + tint('glass', jitter(random, 0.02)), + // Slightly lighter along the run of the profile, which ends on the + // inner surface: light collects in the bowl rather than on the foot. + { colourTop: tint('glass', 0.05), capBottom: true, capTop: true }, + ), + ] + + // 40 degrees: the walls and the stem are curves and smooth out, while + // the rim annulus, the foot edge and the floor cap all turn through + // close to a right angle and keep their edges — and on glass the edges + // are the object. + return { + body: { slot: 'glass' as const, geometry: smoothNormals(mergeColoured(pieces), 40) }, + } + }, + }, overrides) +}