Serve either kit from the reference generator, and rebuild the pepper mill against the photograph it never had.

This commit is contained in:
CRTkafa 2026-09-01 05:49:23 +07:00
parent 8f7ceb1abb
commit 6a65991ec3
3 changed files with 138 additions and 44 deletions

View file

@ -42,7 +42,7 @@
"flutes": { "flutes": {
"type": "number", "type": "number",
"label": "Flutes", "label": "Flutes",
"min": 8, "min": 0,
"max": 28, "max": 28,
"step": 1 "step": 1
}, },

View file

@ -58,14 +58,16 @@ export interface PepperMillConfig {
} }
export const pepperMillDefaults: PepperMillConfig = { export const pepperMillDefaults: PepperMillConfig = {
height: 0.23, height: 0.28,
baseRadius: 0.03, baseRadius: 0.03,
// The waist is what separates a mill from a rolling pin. Below ~0.5 it // 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 // reads as an hourglass, above ~0.7 the profile goes straight. Measured
// flutes are doing all the work alone. // against the reference this one was already right: 58% against its 60%.
waist: 0.58, waist: 0.58,
waistAt: 0.5, waistAt: 0.55,
flutes: 16, // NONE by default, because the reference has none. See the header: the
// flutes were carrying an argument the proportions should have been making.
flutes: 0,
segments: 32, segments: 32,
seed: 23, seed: 23,
} }
@ -108,7 +110,10 @@ export function createModel(overrides: Partial<PepperMillConfig> = {}) {
const segments = Math.max(12, Math.round(config.segments)) const segments = Math.max(12, Math.round(config.segments))
const waistFraction = Math.min(0.68, Math.max(0.45, config.waist)) 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 waistAt = Math.min(0.6, Math.max(0.42, config.waistAt))
const flutes = Math.max(8, Math.min(28, Math.round(config.flutes))) // 0 is a real answer, not a floor to clamp away: a plain turned mill is
// the common one, and the slider could not reach it.
const wanted = Math.round(config.flutes)
const flutes = wanted <= 0 ? 0 : Math.max(8, Math.min(28, wanted))
// The cap takes the top ~16% of the height and overlaps the neck by a // 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 // few millimetres, so the parting line is a step rather than a seam of
@ -126,8 +131,14 @@ export function createModel(overrides: Partial<PepperMillConfig> = {}) {
// step down going up — drum, belly, head — or the object turns into a // 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 // chess bishop. It still follows the waist up when the waist is fat, so
// the swell never dips below the flute tops. // the swell never dips below the flute tops.
const upperR = R * Math.max(0.72, waistFraction * 1.08) // 0.83 of the drum, measured off the reference: the shaft under the head
const upperY = bodyH * 0.74 // comes back out almost to the collar's width. At 0.72 the top half was
// a neck, and a body that only ever narrows going up is a bottle.
const upperR = R * Math.max(0.83, waistFraction * 1.2)
// The swell carries almost to the top. Stopping it at 0.74 left a
// quarter of the shaft to fall away into a neck, and a body that only
// narrows going up is a bottle whatever is standing on it.
const upperY = bodyH * 0.86
/* ------------------------------------------------------------- body */ /* ------------------------------------------------------------- body */
const waistLo = waistY - bandHalf const waistLo = waistY - bandHalf
@ -154,11 +165,12 @@ export function createModel(overrides: Partial<PepperMillConfig> = {}) {
// ends go under the surface within a couple of millimetres. // ends go under the surface within a couple of millimetres.
{ y: waistHi + (upperY - waistHi) * 0.4, radius: ((W + upperR) / 2) * 1.02 }, { y: waistHi + (upperY - waistHi) * 0.4, radius: ((W + upperR) / 2) * 1.02 },
{ y: upperY, radius: upperR }, { y: upperY, radius: upperR },
{ y: bodyH * 0.83, radius: upperR * 0.9 }, { y: bodyH * 0.95, radius: upperR * 0.99 },
// The throat: the belly turns in to a short neck the cap's lip steps // The neck is a hair narrower than the shaft and nothing more. The
// out over, so the parting line reads as a groove under the head. // cap's lip steps out OVER it, so the parting line is a groove; the
{ y: bodyH * 0.91, radius: R * 0.56 }, // reference has no throat at all and the one here was 0.52 R, which
{ y: bodyH, radius: R * 0.52 }, // is what made the head read as a stopper on a bottle.
{ y: bodyH, radius: R * 0.78 },
] ]
const woodBase = tint('wood', jitter(random, 0.02)) const woodBase = tint('wood', jitter(random, 0.02))
@ -212,17 +224,17 @@ export function createModel(overrides: Partial<PepperMillConfig> = {}) {
// so rotation.y grinds. // so rotation.y grinds.
const capH = H - seat const capH = H - seat
const domeH = capH * 0.6 const domeH = capH * 0.6
// An OBLATE dome that overhangs the neck, measured off the reference:
// its widest point is 0.87 R against a 0.78 R neck and it gets there in
// the first third of its height. At 0.61 R it was narrower than the
// shaft below it, which is a bullet, not a head.
const capLevels: Level[] = [ const capLevels: Level[] = [
{ y: 0, radius: R * 0.55 }, { y: 0, radius: R * 0.80 },
// The lip rolls out well past the neck so the cap reads as a { y: 0.003, radius: R * 0.86 },
// separate piece that comes off, not a continuation of the profile. { y: domeH * 0.35, radius: R * 0.87 },
{ y: 0.004, radius: R * 0.6 }, { y: domeH * 0.68, radius: R * 0.74 },
// The head swells a touch before rounding over: a straight-sided cap { y: domeH * 0.88, radius: R * 0.52 },
// read as a bottle top, and this is the swell that makes it a turban. { y: domeH, radius: R * 0.34 },
{ 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)), { const dome = latheGeometry(capLevels, segments, [0, 0, 0], tint('wood', jitter(random, 0.02)), {
colourTop: tint('wood', 0.05), colourTop: tint('wood', 0.05),

View file

@ -13,20 +13,27 @@
* instruments, not art. A reference lit from a dramatic angle hides exactly the * instruments, not art. A reference lit from a dramatic angle hides exactly the
* silhouette detail we need to compare against. * silhouette detail we need to compare against.
* *
* Output goes to `references/`, which is NOT tracked: the corpus is tens of * It serves either kit. The two keep their metadata in different places, which
* megabytes and belongs to the private studio repo, not to the registry that * is the only thing that made this medieval-only before: `my-registry` has one
* consumers clone. * `meta.ts` holding every entry, `contemporary-props` has a `meta.json` beside
* each model. Both carry a `title`, so the difference is where to read it from
* and nothing else. What DOES differ per kit is the last clause of the prompt:
* asking for "historically plausible medieval construction" while photographing
* a fire extinguisher produces a fire extinguisher with rivets and a leather
* strap.
* *
* bun scripts/reference-shots.ts → only the missing ones * Output goes to `references/`, one corpus for both kits, which is safe because
* bun scripts/reference-shots.ts --force → regenerate everything * the ids are unique across them. It is NOT tracked: tens of megabytes that
* bun scripts/reference-shots.ts log-pile ... → only these * belong to the studio, not to the registry consumers clone.
*
* bun scripts/reference-shots.ts my-registry → only the missing
* bun scripts/reference-shots.ts contemporary-props --force → all of them
* bun scripts/reference-shots.ts contemporary-props pepper-mill coffee-mug
*/ */
import { execFileSync } from 'node:child_process' import { execFileSync } from 'node:child_process'
import { existsSync, mkdirSync, readdirSync } from 'node:fs' import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path' import { join } from 'node:path'
import { MODEL_META } from '../my-registry/meta.ts'
/** The Codex binary ships inside the VS Code ChatGPT extension. */ /** The Codex binary ships inside the VS Code ChatGPT extension. */
function findCodex(): string { function findCodex(): string {
const root = join(process.env.USERPROFILE ?? '', '.vscode', 'extensions') const root = join(process.env.USERPROFILE ?? '', '.vscode', 'extensions')
@ -45,11 +52,29 @@ function findCodex(): string {
return found return found
} }
/**
* What the objects are, per registry.
*
* Not decoration: it is the clause that keeps the generator in the right
* century. Without it the medieval kit gets modern reproductions and the
* contemporary one gets everything upholstered in leather.
*/
const STYLE: Record<string, string> = {
'my-registry':
'historically plausible medieval construction',
'contemporary-props':
'an ordinary present-day object of the kind in everyday use now, '
+ 'plain and unstyled, no retro or vintage treatment',
}
/** /**
* Extra wording for models whose name alone would send the generator somewhere * Extra wording for models whose name alone would send the generator somewhere
* useless. "Phial" produces perfume bottles; "sack" produces modern hessian. * useless. "Phial" produces perfume bottles; "sack" produces modern hessian;
* "pepper mill" without the crown and the collar produces a wooden bottle,
* which is exactly what the model of it currently looks like.
*/ */
const HINT: Record<string, string> = { const HINT: Record<string, string> = {
// --- medieval ---
'bronze-bell': 'a bronze bell hanging in a simple wooden swinging frame', 'bronze-bell': 'a bronze bell hanging in a simple wooden swinging frame',
'cart-wheel': 'a wooden spoked cart wheel with an iron tyre, standing upright', 'cart-wheel': 'a wooden spoked cart wheel with an iron tyre, standing upright',
'coin-pouch': 'a small drawstring leather coin purse, closed, resting on its base', 'coin-pouch': 'a small drawstring leather coin purse, closed, resting on its base',
@ -77,9 +102,53 @@ const HINT: Record<string, string> = {
'wooden-shovel': 'a medieval wooden shovel with an iron-shod blade', 'wooden-shovel': 'a medieval wooden shovel with an iron-shod blade',
'wooden-stool': 'a three-legged wooden milking stool', 'wooden-stool': 'a three-legged wooden milking stool',
'wooden-bench': 'a plain wooden bench with plank legs', 'wooden-bench': 'a plain wooden bench with plank legs',
// --- contemporary, built ---
'ceramic-vase': 'a plain glazed ceramic vase, empty, with no flowers in it',
'coffee-mug': 'a plain glazed stoneware coffee mug with a loop handle, empty, seen so the handle is to one side',
'wine-glass': 'an empty stemmed wine glass in clear glass',
'pepper-mill': 'a tall wooden table pepper mill: a turned wooden body with a small metal crown knob on top and the grinder collar at its base',
'stockpot': 'a stainless steel lidded stockpot with two riveted side handles',
'traffic-cone': 'an orange PVC traffic cone with a white reflective band, on its square base',
// --- contemporary, next in the build order ---
'street-bollard': 'a black cast iron street bollard set into a pavement',
'gas-cylinder': 'an industrial gas cylinder with a valve handwheel and a caged guard',
'fire-extinguisher': 'a red fire extinguisher with a squeeze lever, hose and pressure gauge',
'pedestal-basin': 'a white ceramic pedestal wash basin',
'jersey-barrier': 'a single concrete jersey traffic barrier section',
'picnic-table': 'a wooden picnic table with bench seats attached to an A-frame',
} }
function prompt(id: string, title: string): string { /**
* Title per model id, from wherever the kit keeps it.
*
* `my-registry` is a TypeScript record and has to be imported; the others keep
* a `meta.json` beside each model, which is the shape the newer kit uses and
* the one anything after it will.
*/
async function titles(registry: string): Promise<Record<string, string>> {
if (registry === 'my-registry') {
const { MODEL_META } = await import('../my-registry/meta.ts')
return Object.fromEntries(
Object.entries(MODEL_META as Record<string, { title: string }>)
.map(([id, meta]) => [id, meta.title]),
)
}
const dir = join(process.cwd(), registry, 'models')
if (!existsSync(dir)) throw new Error(`no such registry: ${registry}/models`)
const out: Record<string, string> = {}
for (const id of readdirSync(dir)) {
// `core` is the shared vocabulary, not a model.
if (id === 'core') continue
const meta = join(dir, id, 'meta.json')
if (!existsSync(meta)) continue
out[id] = (JSON.parse(readFileSync(meta, 'utf8')) as { title?: string }).title ?? id
}
return out
}
function prompt(id: string, title: string, style: string): string {
const subject = HINT[id] ?? title.toLowerCase() const subject = HINT[id] ?? title.toLowerCase()
return [ return [
'Use your image generation tool to create ONE photographic reference image', 'Use your image generation tool to create ONE photographic reference image',
@ -88,9 +157,8 @@ function prompt(id: string, title: string): string {
'Requirements: a single object, three-quarter view from slightly above,', 'Requirements: a single object, three-quarter view from slightly above,',
'the WHOLE object visible with clear space around it, resting on the', 'the WHOLE object visible with clear space around it, resting on the',
'ground, plain dark neutral background, even studio lighting with soft', 'ground, plain dark neutral background, even studio lighting with soft',
'shadows, sharp focus throughout, historically plausible medieval', `shadows, sharp focus throughout, ${style}, no people, no hands, no text,`,
'construction, no people, no hands, no text, no watermark, no props', 'no watermark, no props other than the object itself.',
'other than the object itself.',
'', '',
`Save the image to the current working directory as exactly ${id}.png.`, `Save the image to the current working directory as exactly ${id}.png.`,
'Do not create any other file. When done, print only the saved path.', 'Do not create any other file. When done, print only the saved path.',
@ -99,28 +167,42 @@ function prompt(id: string, title: string): string {
const args = process.argv.slice(2) const args = process.argv.slice(2)
const force = args.includes('--force') const force = args.includes('--force')
const only = args.filter((a) => !a.startsWith('--')) const positional = args.filter((a) => !a.startsWith('--'))
const registry = positional[0]
const only = positional.slice(1)
if (!registry || !(registry in STYLE)) {
console.error(
`Usage: bun scripts/reference-shots.ts <${Object.keys(STYLE).join('|')}> [id ...] [--force]`,
)
process.exit(1)
}
const codex = findCodex() const codex = findCodex()
const outDir = join(process.cwd(), 'references') const outDir = join(process.cwd(), 'references')
mkdirSync(outDir, { recursive: true }) mkdirSync(outDir, { recursive: true })
const ids = Object.keys(MODEL_META).filter((id) => (only.length === 0 ? true : only.includes(id))) const known = await titles(registry)
const todo = ids.filter((id) => force || !existsSync(join(outDir, `${id}.png`))) const ids = Object.keys(known).filter((id) => (only.length === 0 ? true : only.includes(id)))
const unknown = only.filter((id) => !(id in known))
if (unknown.length > 0) throw new Error(`not in ${registry}: ${unknown.join(', ')}`)
console.log(`${todo.length} reference(s) to generate (${ids.length - todo.length} already present)`) const todo = ids.filter((id) => force || !existsSync(join(outDir, `${id}.png`)))
console.log(
`${registry}: ${todo.length} reference(s) to generate `
+ `(${ids.length - todo.length} already present of ${ids.length})`,
)
let done = 0 let done = 0
let failed = 0 let failed = 0
for (const id of todo) { for (const id of todo) {
const title = (MODEL_META as Record<string, { title: string }>)[id]!.title
process.stdout.write(` ${id} … `) process.stdout.write(` ${id} … `)
try { try {
execFileSync(codex, [ execFileSync(codex, [
'exec', 'exec',
'--skip-git-repo-check', '--skip-git-repo-check',
'--dangerously-bypass-approvals-and-sandbox', '--dangerously-bypass-approvals-and-sandbox',
prompt(id, title), prompt(id, known[id]!, STYLE[registry]!),
], { cwd: outDir, stdio: 'pipe', timeout: 10 * 60_000 }) ], { cwd: outDir, stdio: 'pipe', timeout: 10 * 60_000 })
const ok = existsSync(join(outDir, `${id}.png`)) const ok = existsSync(join(outDir, `${id}.png`))
console.log(ok ? 'ok' : 'NO FILE') console.log(ok ? 'ok' : 'NO FILE')