@developerz.ai/ts23d 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (567) hide show
  1. package/.claude/agents/bug-hunter.md +21 -0
  2. package/.claude/agents/docs-author.md +13 -0
  3. package/.claude/agents/dx-auditor.md +14 -0
  4. package/.claude/agents/primitive-author.md +22 -0
  5. package/.claude/agents/recipe-author.md +36 -0
  6. package/.claude/agents/visual-reviewer.md +23 -0
  7. package/.claude/commands/feature.md +28 -0
  8. package/.claude/commands/new-recipe.md +19 -0
  9. package/.claude/commands/release.md +14 -0
  10. package/.claude/commands/verify.md +9 -0
  11. package/.claude/skills/author-recipe/SKILL.md +93 -0
  12. package/CHANGELOG.md +90 -0
  13. package/CLAUDE.md +85 -0
  14. package/LICENSE +21 -0
  15. package/README.md +385 -2
  16. package/dist/chunk-6b05mnmx.js +19 -0
  17. package/dist/chunk-6b05mnmx.js.map +11 -0
  18. package/dist/chunk-7rtfjh9f.js +45 -0
  19. package/dist/chunk-7rtfjh9f.js.map +10 -0
  20. package/dist/chunk-8j4c28jt.js +4085 -0
  21. package/dist/chunk-8j4c28jt.js.map +46 -0
  22. package/dist/chunk-d1fv6hrm.js +2532 -0
  23. package/dist/chunk-d1fv6hrm.js.map +43 -0
  24. package/dist/chunk-dbq4qf52.js +902 -0
  25. package/dist/chunk-dbq4qf52.js.map +25 -0
  26. package/dist/chunk-drna2rny.js +836 -0
  27. package/dist/chunk-drna2rny.js.map +17 -0
  28. package/dist/chunk-dxvypr7y.js +89 -0
  29. package/dist/chunk-dxvypr7y.js.map +11 -0
  30. package/dist/chunk-f6yme003.js +1589 -0
  31. package/dist/chunk-f6yme003.js.map +30 -0
  32. package/dist/chunk-hg7pf34j.js +465 -0
  33. package/dist/chunk-hg7pf34j.js.map +19 -0
  34. package/dist/chunk-jq4e17tj.js +1031 -0
  35. package/dist/chunk-jq4e17tj.js.map +21 -0
  36. package/dist/chunk-y63c6zcv.js +2668 -0
  37. package/dist/chunk-y63c6zcv.js.map +53 -0
  38. package/dist/cli/args.d.ts +30 -0
  39. package/dist/cli/bin.d.ts +2 -0
  40. package/dist/cli/bin.js +348 -0
  41. package/dist/cli/bin.js.map +15 -0
  42. package/dist/cli/load.d.ts +2 -0
  43. package/dist/cli/manifest.d.ts +53 -0
  44. package/dist/cli/render-cmds.d.ts +12 -0
  45. package/dist/cli/run.d.ts +1 -0
  46. package/dist/cli/texture-cache.d.ts +4 -0
  47. package/dist/core/asset.d.ts +10 -0
  48. package/dist/core/definition.d.ts +155 -0
  49. package/dist/core/errors.d.ts +17 -0
  50. package/dist/core/family.d.ts +23 -0
  51. package/dist/core/index.d.ts +9 -0
  52. package/dist/core/index.js +69 -0
  53. package/dist/core/index.js.map +9 -0
  54. package/dist/core/mesh.d.ts +35 -0
  55. package/dist/core/part.d.ts +114 -0
  56. package/dist/core/png.d.ts +1 -0
  57. package/dist/core/rng.d.ts +12 -0
  58. package/dist/core/transform.d.ts +20 -0
  59. package/dist/core/vec.d.ts +11 -0
  60. package/dist/core/world.d.ts +16 -0
  61. package/dist/export/bin-writer.d.ts +16 -0
  62. package/dist/export/container.d.ts +3 -0
  63. package/dist/export/credits.d.ts +4 -0
  64. package/dist/export/glb-options.d.ts +48 -0
  65. package/dist/export/glb.d.ts +8 -0
  66. package/dist/export/hierarchy.d.ts +23 -0
  67. package/dist/export/index.d.ts +5 -0
  68. package/dist/export/index.js +40 -0
  69. package/dist/export/index.js.map +9 -0
  70. package/dist/export/lights.d.ts +8 -0
  71. package/dist/export/lod-coverage.d.ts +12 -0
  72. package/dist/export/materials.d.ts +23 -0
  73. package/dist/export/merge-pivots.d.ts +6 -0
  74. package/dist/export/metadata.d.ts +21 -0
  75. package/dist/export/motion.d.ts +9 -0
  76. package/dist/export/optimize-parts.d.ts +26 -0
  77. package/dist/export/primitive.d.ts +3 -0
  78. package/dist/export/tangents.d.ts +2 -0
  79. package/dist/export/textures.d.ts +22 -0
  80. package/dist/export/version.d.ts +2 -0
  81. package/dist/grammar/index.d.ts +2 -0
  82. package/dist/grammar/index.js +16 -0
  83. package/dist/grammar/index.js.map +9 -0
  84. package/dist/grammar/split.d.ts +21 -0
  85. package/dist/grammar/whyte.d.ts +5 -0
  86. package/dist/index.d.ts +11 -0
  87. package/dist/index.js +457 -0
  88. package/dist/index.js.map +9 -0
  89. package/dist/kinds/building.d.ts +44 -0
  90. package/dist/kinds/faces.d.ts +27 -0
  91. package/dist/kinds/head-armour.d.ts +5 -0
  92. package/dist/kinds/head-beard.d.ts +6 -0
  93. package/dist/kinds/head-bust.d.ts +5 -0
  94. package/dist/kinds/head-extras.d.ts +15 -0
  95. package/dist/kinds/head-face.d.ts +8 -0
  96. package/dist/kinds/head-garb.d.ts +4 -0
  97. package/dist/kinds/head-geom.d.ts +7 -0
  98. package/dist/kinds/head-hair.d.ts +4 -0
  99. package/dist/kinds/head-layout.d.ts +29 -0
  100. package/dist/kinds/head-mesh.d.ts +31 -0
  101. package/dist/kinds/head-mouth.d.ts +4 -0
  102. package/dist/kinds/head-params.d.ts +116 -0
  103. package/dist/kinds/head-presets.d.ts +19 -0
  104. package/dist/kinds/head-rim.d.ts +10 -0
  105. package/dist/kinds/head-tone.d.ts +10 -0
  106. package/dist/kinds/head-torso.d.ts +35 -0
  107. package/dist/kinds/head.d.ts +39 -0
  108. package/dist/kinds/hull-lines.d.ts +65 -0
  109. package/dist/kinds/hull-skin.d.ts +6 -0
  110. package/dist/kinds/hull.d.ts +14 -0
  111. package/dist/kinds/index.d.ts +16 -0
  112. package/dist/kinds/index.js +78 -0
  113. package/dist/kinds/index.js.map +9 -0
  114. package/dist/kinds/mass.d.ts +15 -0
  115. package/dist/kinds/openings.d.ts +30 -0
  116. package/dist/kinds/planned.d.ts +6 -0
  117. package/dist/kinds/roof-chimney.d.ts +16 -0
  118. package/dist/kinds/roof-shape.d.ts +64 -0
  119. package/dist/kinds/roof.d.ts +31 -0
  120. package/dist/kinds/vegetation-fronds.d.ts +15 -0
  121. package/dist/kinds/vegetation-impostor.d.ts +9 -0
  122. package/dist/kinds/vegetation-leaves.d.ts +15 -0
  123. package/dist/kinds/vegetation-mesh.d.ts +21 -0
  124. package/dist/kinds/vegetation-params.d.ts +90 -0
  125. package/dist/kinds/vegetation-presets.d.ts +20 -0
  126. package/dist/kinds/vegetation-skeleton.d.ts +20 -0
  127. package/dist/kinds/vegetation.d.ts +42 -0
  128. package/dist/kinds/vehicle.d.ts +42 -0
  129. package/dist/material/cc0.d.ts +4 -0
  130. package/dist/material/define.d.ts +34 -0
  131. package/dist/material/generator.d.ts +4 -0
  132. package/dist/material/index.d.ts +9 -0
  133. package/dist/material/index.js +70 -0
  134. package/dist/material/index.js.map +9 -0
  135. package/dist/material/library.d.ts +7 -0
  136. package/dist/material/material-def.d.ts +30 -0
  137. package/dist/material/paint/bond.d.ts +3 -0
  138. package/dist/material/paint/canvas.d.ts +39 -0
  139. package/dist/material/paint/cell.d.ts +4 -0
  140. package/dist/material/paint/cells-round.d.ts +5 -0
  141. package/dist/material/paint/cells.d.ts +7 -0
  142. package/dist/material/paint/compose.d.ts +5 -0
  143. package/dist/material/paint/concrete.d.ts +3 -0
  144. package/dist/material/paint/courses.d.ts +31 -0
  145. package/dist/material/paint/decode-png.d.ts +6 -0
  146. package/dist/material/paint/default-sheet.d.ts +4 -0
  147. package/dist/material/paint/fabric.d.ts +4 -0
  148. package/dist/material/paint/foliage-broad.d.ts +5 -0
  149. package/dist/material/paint/foliage-common.d.ts +35 -0
  150. package/dist/material/paint/foliage-compound.d.ts +4 -0
  151. package/dist/material/paint/foliage-conifer.d.ts +5 -0
  152. package/dist/material/paint/foliage-raster.d.ts +26 -0
  153. package/dist/material/paint/foliage.d.ts +3 -0
  154. package/dist/material/paint/image-strip.d.ts +4 -0
  155. package/dist/material/paint/kit.d.ts +5 -0
  156. package/dist/material/paint/masks.d.ts +3 -0
  157. package/dist/material/paint/metal.d.ts +3 -0
  158. package/dist/material/paint/noise.d.ts +9 -0
  159. package/dist/material/paint/normal.d.ts +8 -0
  160. package/dist/material/paint/orm.d.ts +8 -0
  161. package/dist/material/paint/planks.d.ts +3 -0
  162. package/dist/material/paint/plates.d.ts +3 -0
  163. package/dist/material/paint/shapes.d.ts +8 -0
  164. package/dist/material/paint/slate.d.ts +3 -0
  165. package/dist/material/paint/stamp.d.ts +3 -0
  166. package/dist/material/paint/strip.d.ts +3 -0
  167. package/dist/material/paint/surface.d.ts +5 -0
  168. package/dist/material/paint/types.d.ts +65 -0
  169. package/dist/material/paint/validate.d.ts +3 -0
  170. package/dist/material/palette.d.ts +14 -0
  171. package/dist/material/shader-godot.d.ts +2 -0
  172. package/dist/material/shader-three.d.ts +2 -0
  173. package/dist/material/shader.d.ts +46 -0
  174. package/dist/material/slots.d.ts +5 -0
  175. package/dist/material/texture-source.d.ts +34 -0
  176. package/dist/material/trim-sheet.d.ts +38 -0
  177. package/dist/neural/generator.d.ts +25 -0
  178. package/dist/neural/images.d.ts +17 -0
  179. package/dist/neural/index.d.ts +2 -0
  180. package/dist/neural/index.js +14 -0
  181. package/dist/neural/index.js.map +9 -0
  182. package/dist/passes/bake-ao.d.ts +17 -0
  183. package/dist/passes/grime.d.ts +15 -0
  184. package/dist/passes/index.d.ts +6 -0
  185. package/dist/passes/index.js +22 -0
  186. package/dist/passes/index.js.map +9 -0
  187. package/dist/passes/livery.d.ts +19 -0
  188. package/dist/passes/optimize-cache.d.ts +15 -0
  189. package/dist/passes/optimize-weld.d.ts +15 -0
  190. package/dist/passes/optimize.d.ts +28 -0
  191. package/dist/passes/ray-grid.d.ts +23 -0
  192. package/dist/passes/weighted-normals.d.ts +8 -0
  193. package/dist/primitives/beam.d.ts +17 -0
  194. package/dist/primitives/bevel-box.d.ts +13 -0
  195. package/dist/primitives/box.d.ts +16 -0
  196. package/dist/primitives/cell.d.ts +20 -0
  197. package/dist/primitives/check.d.ts +12 -0
  198. package/dist/primitives/closed.d.ts +11 -0
  199. package/dist/primitives/erosion.d.ts +22 -0
  200. package/dist/primitives/font-5x7.d.ts +3 -0
  201. package/dist/primitives/heightfield.d.ts +16 -0
  202. package/dist/primitives/index.d.ts +23 -0
  203. package/dist/primitives/index.js +81 -0
  204. package/dist/primitives/index.js.map +9 -0
  205. package/dist/primitives/lathe-facets.d.ts +8 -0
  206. package/dist/primitives/lathe.d.ts +26 -0
  207. package/dist/primitives/lattice.d.ts +30 -0
  208. package/dist/primitives/loft.d.ts +15 -0
  209. package/dist/primitives/mc-table.d.ts +2 -0
  210. package/dist/primitives/member.d.ts +19 -0
  211. package/dist/primitives/noise.d.ts +34 -0
  212. package/dist/primitives/planar.d.ts +10 -0
  213. package/dist/primitives/prism.d.ts +13 -0
  214. package/dist/primitives/sculpt-edit.d.ts +56 -0
  215. package/dist/primitives/sculpt-tree.d.ts +23 -0
  216. package/dist/primitives/sculpt.d.ts +27 -0
  217. package/dist/primitives/sdf-grid.d.ts +17 -0
  218. package/dist/primitives/sdf-ops.d.ts +37 -0
  219. package/dist/primitives/sdf.d.ts +21 -0
  220. package/dist/primitives/strip-uv.d.ts +11 -0
  221. package/dist/primitives/surface-nets.d.ts +7 -0
  222. package/dist/primitives/sweep.d.ts +19 -0
  223. package/dist/primitives/terrain-color.d.ts +30 -0
  224. package/dist/primitives/terrain-grid.d.ts +36 -0
  225. package/dist/primitives/text-layout.d.ts +22 -0
  226. package/dist/primitives/text.d.ts +27 -0
  227. package/dist/primitives/tiled.d.ts +22 -0
  228. package/dist/primitives/transport.d.ts +17 -0
  229. package/dist/primitives/triangulate.d.ts +2 -0
  230. package/dist/primitives/value-noise.d.ts +10 -0
  231. package/dist/qa/checks.d.ts +11 -0
  232. package/dist/qa/clash.d.ts +2 -0
  233. package/dist/qa/floating.d.ts +5 -0
  234. package/dist/qa/gates.d.ts +12 -0
  235. package/dist/qa/geometry.d.ts +21 -0
  236. package/dist/qa/index.d.ts +12 -0
  237. package/dist/qa/index.js +78 -0
  238. package/dist/qa/index.js.map +9 -0
  239. package/dist/qa/inside.d.ts +12 -0
  240. package/dist/qa/inspect.d.ts +18 -0
  241. package/dist/qa/lods.d.ts +12 -0
  242. package/dist/qa/measures.d.ts +4 -0
  243. package/dist/qa/occlusion.d.ts +3 -0
  244. package/dist/qa/sanity.d.ts +7 -0
  245. package/dist/qa/types.d.ts +12 -0
  246. package/dist/render/beauty.d.ts +40 -0
  247. package/dist/render/camera.d.ts +33 -0
  248. package/dist/render/depth-map.d.ts +38 -0
  249. package/dist/render/font.d.ts +1 -0
  250. package/dist/render/ground.d.ts +13 -0
  251. package/dist/render/index.d.ts +10 -0
  252. package/dist/render/index.js +47 -0
  253. package/dist/render/index.js.map +9 -0
  254. package/dist/render/lighting.d.ts +27 -0
  255. package/dist/render/lod-strip.d.ts +5 -0
  256. package/dist/render/metrics.d.ts +37 -0
  257. package/dist/render/options.d.ts +28 -0
  258. package/dist/render/photo-match.d.ts +19 -0
  259. package/dist/render/raster.d.ts +25 -0
  260. package/dist/render/resolve.d.ts +11 -0
  261. package/dist/render/review-prompt.d.ts +2 -0
  262. package/dist/render/review-warnings.d.ts +34 -0
  263. package/dist/render/review.d.ts +24 -0
  264. package/dist/render/scene.d.ts +18 -0
  265. package/dist/render/shade.d.ts +22 -0
  266. package/dist/render/sheet.d.ts +15 -0
  267. package/dist/render/texture.d.ts +15 -0
  268. package/dist/render/thumbnail.d.ts +8 -0
  269. package/dist/render/vis-buffer.d.ts +18 -0
  270. package/dist/testing/assert.d.ts +21 -0
  271. package/dist/testing/compiled.d.ts +15 -0
  272. package/dist/testing/hash.d.ts +1 -0
  273. package/dist/testing/index.d.ts +4 -0
  274. package/dist/testing/index.js +134 -0
  275. package/dist/testing/index.js.map +13 -0
  276. package/dist/testing/snapshot.d.ts +13 -0
  277. package/docs/README.md +56 -0
  278. package/docs/architecture/README.md +68 -0
  279. package/docs/architecture/adding-a-kind.md +44 -0
  280. package/docs/architecture/adding-a-primitive.md +49 -0
  281. package/docs/architecture/errors.md +47 -0
  282. package/docs/architecture/glb-production.md +214 -0
  283. package/docs/architecture/gltf-capabilities.md +117 -0
  284. package/docs/architecture/materials.md +151 -0
  285. package/docs/decisions/001-recipe-compiler-over-ai-meshes.md +27 -0
  286. package/docs/decisions/002-typescript-not-json.md +22 -0
  287. package/docs/decisions/003-shared-trim-sheet.md +21 -0
  288. package/docs/decisions/004-z-up-metres.md +21 -0
  289. package/docs/decisions/005-zero-runtime-deps.md +21 -0
  290. package/docs/decisions/006-single-package-subpath-exports.md +20 -0
  291. package/docs/decisions/007-cpu-contact-sheets.md +21 -0
  292. package/docs/decisions/008-surface-materials.md +21 -0
  293. package/docs/decisions/009-gltf-front-axis.md +21 -0
  294. package/docs/decisions/README.md +15 -0
  295. package/docs/idea/01-vision.md +117 -0
  296. package/docs/idea/02-dsl.md +343 -0
  297. package/docs/idea/03-ir.md +97 -0
  298. package/docs/idea/04-materials.md +114 -0
  299. package/docs/idea/05-agent-loop.md +141 -0
  300. package/docs/idea/06-qa.md +101 -0
  301. package/docs/idea/07-what-fits.md +45 -0
  302. package/docs/idea/08-neural-adapters.md +78 -0
  303. package/docs/idea/09-kinds.md +105 -0
  304. package/docs/idea/10-sculpting.md +166 -0
  305. package/docs/idea/11-materials-authoring.md +132 -0
  306. package/docs/idea/12-blender-bridge.md +136 -0
  307. package/docs/idea/13-asset-pipeline-research.md +89 -0
  308. package/docs/landscape.md +49 -0
  309. package/docs/plans/roadmap.md +139 -0
  310. package/examples/build-with-bun.ts +41 -0
  311. package/llms.txt +47 -0
  312. package/package.json +100 -4
  313. package/recipes/README.md +38 -0
  314. package/recipes/asteroid/README.md +46 -0
  315. package/recipes/asteroid/asteroid.ts +336 -0
  316. package/recipes/boulders/README.md +28 -0
  317. package/recipes/boulders/boulders.ts +117 -0
  318. package/recipes/boxcar/README.md +53 -0
  319. package/recipes/boxcar/boxcar.ts +1000 -0
  320. package/recipes/cargo_container_scifi/README.md +52 -0
  321. package/recipes/cargo_container_scifi/cargo_container_scifi.ts +461 -0
  322. package/recipes/dropship/README.md +84 -0
  323. package/recipes/dropship/dropship.ts +1144 -0
  324. package/recipes/eiffel_tower/README.md +110 -0
  325. package/recipes/eiffel_tower/eiffel_tower.ts +781 -0
  326. package/recipes/goblin_head/README.md +75 -0
  327. package/recipes/goblin_head/goblin_head.ts +38 -0
  328. package/recipes/human_head/README.md +68 -0
  329. package/recipes/human_head/human_head.ts +38 -0
  330. package/recipes/loco_440/README.md +32 -0
  331. package/recipes/loco_440/loco_440.ts +1404 -0
  332. package/recipes/material_swatches/README.md +21 -0
  333. package/recipes/material_swatches/material_swatches.ts +189 -0
  334. package/recipes/mountain_range/README.md +45 -0
  335. package/recipes/mountain_range/mountain_range.ts +128 -0
  336. package/recipes/oak/README.md +30 -0
  337. package/recipes/oak/oak.ts +19 -0
  338. package/recipes/orc_head/README.md +78 -0
  339. package/recipes/orc_head/orc_head.ts +41 -0
  340. package/recipes/palm/README.md +30 -0
  341. package/recipes/palm/palm.ts +19 -0
  342. package/recipes/pine/README.md +29 -0
  343. package/recipes/pine/pine.ts +19 -0
  344. package/recipes/signal_gantry/README.md +36 -0
  345. package/recipes/signal_gantry/signal_gantry.ts +522 -0
  346. package/recipes/station_halt/README.md +39 -0
  347. package/recipes/station_halt/station_halt.ts +722 -0
  348. package/recipes/t34/README.md +44 -0
  349. package/recipes/t34/t34.ts +1068 -0
  350. package/recipes/tiger_1/README.md +75 -0
  351. package/recipes/tiger_1/tiger_1.ts +1370 -0
  352. package/recipes/water_tower/README.md +40 -0
  353. package/recipes/water_tower/water_tower.ts +542 -0
  354. package/src/cli/args.ts +125 -0
  355. package/src/cli/bin.ts +7 -0
  356. package/src/cli/load.ts +17 -0
  357. package/src/cli/manifest.ts +95 -0
  358. package/src/cli/render-cmds.ts +66 -0
  359. package/src/cli/run.ts +192 -0
  360. package/src/cli/texture-cache.ts +24 -0
  361. package/src/core/asset.ts +129 -0
  362. package/src/core/definition.ts +156 -0
  363. package/src/core/errors.ts +50 -0
  364. package/src/core/family.ts +50 -0
  365. package/src/core/index.ts +66 -0
  366. package/src/core/mesh.ts +114 -0
  367. package/src/core/part.ts +130 -0
  368. package/src/core/png.ts +49 -0
  369. package/src/core/rng.ts +49 -0
  370. package/src/core/transform.ts +90 -0
  371. package/src/core/vec.ts +26 -0
  372. package/src/core/world.ts +80 -0
  373. package/src/export/bin-writer.ts +79 -0
  374. package/src/export/container.ts +35 -0
  375. package/src/export/credits.ts +25 -0
  376. package/src/export/glb-options.ts +53 -0
  377. package/src/export/glb.ts +187 -0
  378. package/src/export/hierarchy.ts +122 -0
  379. package/src/export/index.ts +34 -0
  380. package/src/export/lights.ts +49 -0
  381. package/src/export/lod-coverage.ts +71 -0
  382. package/src/export/materials.ts +126 -0
  383. package/src/export/merge-pivots.ts +146 -0
  384. package/src/export/metadata.ts +62 -0
  385. package/src/export/motion.ts +70 -0
  386. package/src/export/optimize-parts.ts +80 -0
  387. package/src/export/primitive.ts +35 -0
  388. package/src/export/tangents.ts +75 -0
  389. package/src/export/textures.ts +88 -0
  390. package/src/export/version.ts +6 -0
  391. package/src/grammar/index.ts +4 -0
  392. package/src/grammar/split.ts +87 -0
  393. package/src/grammar/whyte.ts +20 -0
  394. package/src/index.ts +14 -0
  395. package/src/kinds/building.ts +153 -0
  396. package/src/kinds/faces.ts +138 -0
  397. package/src/kinds/head-armour.ts +181 -0
  398. package/src/kinds/head-beard.ts +133 -0
  399. package/src/kinds/head-bust.ts +184 -0
  400. package/src/kinds/head-extras.ts +150 -0
  401. package/src/kinds/head-face.ts +242 -0
  402. package/src/kinds/head-garb.ts +181 -0
  403. package/src/kinds/head-geom.ts +31 -0
  404. package/src/kinds/head-hair.ts +193 -0
  405. package/src/kinds/head-layout.ts +63 -0
  406. package/src/kinds/head-mesh.ts +195 -0
  407. package/src/kinds/head-mouth.ts +111 -0
  408. package/src/kinds/head-params.ts +162 -0
  409. package/src/kinds/head-presets.ts +155 -0
  410. package/src/kinds/head-rim.ts +128 -0
  411. package/src/kinds/head-tone.ts +52 -0
  412. package/src/kinds/head-torso.ts +230 -0
  413. package/src/kinds/head.ts +176 -0
  414. package/src/kinds/hull-lines.ts +160 -0
  415. package/src/kinds/hull-skin.ts +83 -0
  416. package/src/kinds/hull.ts +209 -0
  417. package/src/kinds/index.ts +63 -0
  418. package/src/kinds/mass.ts +110 -0
  419. package/src/kinds/openings.ts +141 -0
  420. package/src/kinds/planned.ts +12 -0
  421. package/src/kinds/roof-chimney.ts +100 -0
  422. package/src/kinds/roof-shape.ts +230 -0
  423. package/src/kinds/roof.ts +250 -0
  424. package/src/kinds/vegetation-fronds.ts +126 -0
  425. package/src/kinds/vegetation-impostor.ts +118 -0
  426. package/src/kinds/vegetation-leaves.ts +168 -0
  427. package/src/kinds/vegetation-mesh.ts +174 -0
  428. package/src/kinds/vegetation-params.ts +147 -0
  429. package/src/kinds/vegetation-presets.ts +184 -0
  430. package/src/kinds/vegetation-skeleton.ts +168 -0
  431. package/src/kinds/vegetation.ts +199 -0
  432. package/src/kinds/vehicle.ts +144 -0
  433. package/src/material/cc0.ts +41 -0
  434. package/src/material/define.ts +130 -0
  435. package/src/material/generator.ts +63 -0
  436. package/src/material/index.ts +60 -0
  437. package/src/material/library.ts +196 -0
  438. package/src/material/material-def.ts +84 -0
  439. package/src/material/paint/bond.ts +60 -0
  440. package/src/material/paint/canvas.ts +101 -0
  441. package/src/material/paint/cell.ts +39 -0
  442. package/src/material/paint/cells-round.ts +119 -0
  443. package/src/material/paint/cells.ts +111 -0
  444. package/src/material/paint/compose.ts +53 -0
  445. package/src/material/paint/concrete.ts +62 -0
  446. package/src/material/paint/courses.ts +85 -0
  447. package/src/material/paint/decode-png.ts +106 -0
  448. package/src/material/paint/default-sheet.ts +73 -0
  449. package/src/material/paint/fabric.ts +63 -0
  450. package/src/material/paint/foliage-broad.ts +126 -0
  451. package/src/material/paint/foliage-common.ts +93 -0
  452. package/src/material/paint/foliage-compound.ts +135 -0
  453. package/src/material/paint/foliage-conifer.ts +143 -0
  454. package/src/material/paint/foliage-raster.ts +196 -0
  455. package/src/material/paint/foliage.ts +23 -0
  456. package/src/material/paint/image-strip.ts +88 -0
  457. package/src/material/paint/kit.ts +37 -0
  458. package/src/material/paint/masks.ts +46 -0
  459. package/src/material/paint/metal.ts +109 -0
  460. package/src/material/paint/noise.ts +52 -0
  461. package/src/material/paint/normal.ts +52 -0
  462. package/src/material/paint/orm.ts +108 -0
  463. package/src/material/paint/planks.ts +101 -0
  464. package/src/material/paint/plates.ts +72 -0
  465. package/src/material/paint/shapes.ts +28 -0
  466. package/src/material/paint/slate.ts +52 -0
  467. package/src/material/paint/stamp.ts +40 -0
  468. package/src/material/paint/strip.ts +48 -0
  469. package/src/material/paint/surface.ts +60 -0
  470. package/src/material/paint/types.ts +94 -0
  471. package/src/material/paint/validate.ts +74 -0
  472. package/src/material/palette.ts +46 -0
  473. package/src/material/shader-godot.ts +77 -0
  474. package/src/material/shader-three.ts +103 -0
  475. package/src/material/shader.ts +100 -0
  476. package/src/material/slots.ts +18 -0
  477. package/src/material/texture-source.ts +86 -0
  478. package/src/material/trim-sheet.ts +166 -0
  479. package/src/neural/generator.ts +37 -0
  480. package/src/neural/images.ts +27 -0
  481. package/src/neural/index.ts +10 -0
  482. package/src/passes/bake-ao.ts +183 -0
  483. package/src/passes/grime.ts +37 -0
  484. package/src/passes/index.ts +8 -0
  485. package/src/passes/livery.ts +66 -0
  486. package/src/passes/optimize-cache.ts +175 -0
  487. package/src/passes/optimize-weld.ts +147 -0
  488. package/src/passes/optimize.ts +85 -0
  489. package/src/passes/ray-grid.ts +237 -0
  490. package/src/passes/weighted-normals.ts +125 -0
  491. package/src/primitives/beam.ts +60 -0
  492. package/src/primitives/bevel-box.ts +140 -0
  493. package/src/primitives/box.ts +90 -0
  494. package/src/primitives/cell.ts +115 -0
  495. package/src/primitives/check.ts +49 -0
  496. package/src/primitives/closed.ts +74 -0
  497. package/src/primitives/erosion.ts +183 -0
  498. package/src/primitives/font-5x7.ts +117 -0
  499. package/src/primitives/heightfield.ts +101 -0
  500. package/src/primitives/index.ts +56 -0
  501. package/src/primitives/lathe-facets.ts +45 -0
  502. package/src/primitives/lathe.ts +174 -0
  503. package/src/primitives/lattice.ts +131 -0
  504. package/src/primitives/loft.ts +174 -0
  505. package/src/primitives/mc-table.ts +41 -0
  506. package/src/primitives/member.ts +130 -0
  507. package/src/primitives/noise.ts +157 -0
  508. package/src/primitives/planar.ts +55 -0
  509. package/src/primitives/prism.ts +85 -0
  510. package/src/primitives/sculpt-edit.ts +212 -0
  511. package/src/primitives/sculpt-tree.ts +226 -0
  512. package/src/primitives/sculpt.ts +80 -0
  513. package/src/primitives/sdf-grid.ts +131 -0
  514. package/src/primitives/sdf-ops.ts +145 -0
  515. package/src/primitives/sdf.ts +83 -0
  516. package/src/primitives/strip-uv.ts +26 -0
  517. package/src/primitives/surface-nets.ts +161 -0
  518. package/src/primitives/sweep.ts +162 -0
  519. package/src/primitives/terrain-color.ts +85 -0
  520. package/src/primitives/terrain-grid.ts +137 -0
  521. package/src/primitives/text-layout.ts +85 -0
  522. package/src/primitives/text.ts +197 -0
  523. package/src/primitives/tiled.ts +93 -0
  524. package/src/primitives/transport.ts +85 -0
  525. package/src/primitives/triangulate.ts +42 -0
  526. package/src/primitives/value-noise.ts +62 -0
  527. package/src/qa/checks.ts +110 -0
  528. package/src/qa/clash.ts +177 -0
  529. package/src/qa/floating.ts +63 -0
  530. package/src/qa/gates.ts +126 -0
  531. package/src/qa/geometry.ts +187 -0
  532. package/src/qa/index.ts +28 -0
  533. package/src/qa/inside.ts +114 -0
  534. package/src/qa/inspect.ts +107 -0
  535. package/src/qa/lods.ts +97 -0
  536. package/src/qa/measures.ts +67 -0
  537. package/src/qa/occlusion.ts +166 -0
  538. package/src/qa/sanity.ts +137 -0
  539. package/src/qa/types.ts +17 -0
  540. package/src/render/beauty.ts +115 -0
  541. package/src/render/camera.ts +142 -0
  542. package/src/render/depth-map.ts +191 -0
  543. package/src/render/font.ts +76 -0
  544. package/src/render/ground.ts +87 -0
  545. package/src/render/index.ts +34 -0
  546. package/src/render/lighting.ts +121 -0
  547. package/src/render/lod-strip.ts +34 -0
  548. package/src/render/metrics.ts +147 -0
  549. package/src/render/options.ts +81 -0
  550. package/src/render/photo-match.ts +28 -0
  551. package/src/render/raster.ts +143 -0
  552. package/src/render/resolve.ts +109 -0
  553. package/src/render/review-prompt.ts +59 -0
  554. package/src/render/review-warnings.ts +92 -0
  555. package/src/render/review.ts +103 -0
  556. package/src/render/scene.ts +119 -0
  557. package/src/render/shade.ts +204 -0
  558. package/src/render/sheet.ts +88 -0
  559. package/src/render/texture.ts +97 -0
  560. package/src/render/thumbnail.ts +75 -0
  561. package/src/render/vis-buffer.ts +119 -0
  562. package/src/testing/assert.ts +115 -0
  563. package/src/testing/compiled.ts +31 -0
  564. package/src/testing/hash.ts +14 -0
  565. package/src/testing/index.ts +14 -0
  566. package/src/testing/snapshot.ts +37 -0
  567. package/src/types/gltf-validator.d.ts +13 -0
@@ -0,0 +1,1404 @@
1
+ // American 4-4-0 in "Jupiter" colours (Schenectady 1868, Central Pacific No. 60; 1979 replica at
2
+ // Golden Spike NHP): 5 ft 4 in (1.626 m) drivers, 16 × 24 in cylinders, 1.435 m gauge; engine +
3
+ // tender ≈ 17.4 m × 2.8 m × 4.6 m (overall box estimated from the photo with drivers as ruler).
4
+ // A family over the Whyte arrangement: the frame, boiler and rods are laid out from it.
5
+
6
+ import {
7
+ applyAffine,
8
+ beam,
9
+ box,
10
+ type Check,
11
+ clear,
12
+ cylinder,
13
+ defineFamily,
14
+ frame,
15
+ grime,
16
+ hex,
17
+ inspect,
18
+ type Lod,
19
+ lathe,
20
+ livery,
21
+ type Mesh,
22
+ merge,
23
+ noOverlap,
24
+ place,
25
+ planar,
26
+ prism,
27
+ touches,
28
+ translate,
29
+ type Vec2,
30
+ type Vec3,
31
+ whyteAxles,
32
+ } from '@developerz.ai/ts23d';
33
+
34
+ const blue = hex('#2446a8');
35
+ const blueDark = hex('#182f73');
36
+ const red = hex('#b3241d');
37
+ const brass = hex('#c9a24a');
38
+ const jacket = hex('#1f2536');
39
+ const black = hex('#151515');
40
+ const iron = hex('#2e2e30');
41
+ const wood = hex('#6b4a2e');
42
+ const woodLight = hex('#8a6640');
43
+ const glass = hex('#2b3a44');
44
+ const ballast = hex('#8f8a80');
45
+ const tieWood = hex('#4a3a2c');
46
+ const rail = hex('#5c5650');
47
+
48
+ // Track and wheels (metres; +X forward, Z up).
49
+ const GAUGE = 1.435;
50
+ const HEAD = 0.072;
51
+ const TIE_H = 0.15;
52
+ const RAIL_H = 0.14;
53
+ const RAIL_TOP = TIE_H + RAIL_H;
54
+ const RAIL_Y = GAUGE / 2 + HEAD / 2;
55
+ const TREAD_W = 0.13;
56
+ const DRIVER_R = 0.813;
57
+ const LEAD_R = 0.38;
58
+ const TENDER_R = 0.38;
59
+ /** Gap between wheel rims; gives the (estimated) 8 ft driver wheelbase with 1.626 m drivers. */
60
+ const SPACING = 0.814;
61
+ const CRANK = 0.3;
62
+ const SPEED = 4;
63
+ const FRAME_Y = 0.5;
64
+ const CYL_Z = 1.42;
65
+ const ROD_Y = 0.98;
66
+ const BOILER_Z = 2.4;
67
+ const BOILER_R = 0.62;
68
+ const SMOKEBOX_R = 0.68;
69
+ const DECK_Z = 1.75;
70
+
71
+ interface Params {
72
+ /** Whyte notation; the frame, boiler and rods are laid out from it. */
73
+ readonly arrangement: string;
74
+ readonly number: string;
75
+ readonly name: string;
76
+ }
77
+
78
+ // ---------------------------------------------------------------- wheels
79
+
80
+ /** Flangeless tread + spoked centre in local space (axis Y, outer face +Y), at lateral `y`. */
81
+ function wheelMesh(lod: Lod, r: number, y: number, spokes: number, crankAngle: number | null) {
82
+ if (lod === 2)
83
+ return cylinder({
84
+ radius: r,
85
+ length: TREAD_W,
86
+ segments: 6,
87
+ axis: 'y',
88
+ at: [0, y, 0],
89
+ color: red,
90
+ });
91
+ const segs = [28, 14, 8][lod] ?? 8;
92
+ const out = TREAD_W;
93
+ const parts: Mesh[] = [
94
+ // Tyre (tread) and rim, red centre.
95
+ lathe({
96
+ profile: [
97
+ [r - 0.06, y - out / 2],
98
+ [r - 0.004, y - out / 2],
99
+ [r, y - out / 2 + 0.01],
100
+ [r, y + out / 2 - 0.01],
101
+ [r - 0.004, y + out / 2],
102
+ [r - 0.06, y + out / 2],
103
+ ],
104
+ segments: segs,
105
+ axis: 'y',
106
+ color: iron,
107
+ }),
108
+ lathe({
109
+ profile: [
110
+ [r - 0.06, y + 0.03],
111
+ [r - 0.1, y + 0.03],
112
+ [r - 0.1, y - 0.03],
113
+ [r - 0.06, y - 0.03],
114
+ ],
115
+ segments: segs,
116
+ axis: 'y',
117
+ color: red,
118
+ }),
119
+ // Hub with a brass cap.
120
+ lathe({
121
+ profile: [
122
+ [0.0, y - 0.07],
123
+ [r * 0.2, y - 0.07],
124
+ [r * 0.2, y + 0.06],
125
+ [r * 0.12, y + 0.09],
126
+ [0, y + 0.09],
127
+ ],
128
+ segments: Math.max(8, segs / 2),
129
+ axis: 'y',
130
+ color: red,
131
+ }),
132
+ ];
133
+ if (spokes > 0) {
134
+ for (let i = 0; i < spokes; i++) {
135
+ const a = (i / spokes) * Math.PI * 2;
136
+ parts.push(
137
+ beam({
138
+ from: [Math.cos(a) * r * 0.18, y, Math.sin(a) * r * 0.18],
139
+ to: [Math.cos(a) * (r - 0.09), y, Math.sin(a) * (r - 0.09)],
140
+ width: r * 0.06,
141
+ height: 0.04,
142
+ color: red,
143
+ }),
144
+ );
145
+ }
146
+ } else {
147
+ parts.push(
148
+ lathe({
149
+ profile: [
150
+ [r - 0.09, y - 0.02],
151
+ [r * 0.2, y - 0.02],
152
+ [r * 0.2, y + 0.02],
153
+ [r - 0.09, y + 0.02],
154
+ ],
155
+ segments: segs,
156
+ axis: 'y',
157
+ color: red,
158
+ }),
159
+ );
160
+ }
161
+ if (crankAngle !== null && lod < 2) {
162
+ // Counterweight: a crescent between the spokes opposite the crank pin.
163
+ const c = crankAngle + Math.PI;
164
+ const arc = lod === 0 ? 10 : 5;
165
+ const poly: Vec2[] = [];
166
+ for (let i = 0; i <= arc; i++) {
167
+ const a = c - 0.75 + (1.5 * i) / arc;
168
+ poly.push([Math.cos(a) * (r - 0.1), Math.sin(a) * (r - 0.1)]);
169
+ }
170
+ for (let i = arc; i >= 0; i--) {
171
+ const a = c - 0.45 + (0.9 * i) / arc;
172
+ poly.push([Math.cos(a) * r * 0.42, Math.sin(a) * r * 0.42]);
173
+ }
174
+ parts.push(
175
+ translate(prism({ profile: poly, depth: 0.07, plane: 'xz', color: red }), [0, y, 0]),
176
+ );
177
+ }
178
+ return merge(parts);
179
+ }
180
+
181
+ /** Flange ring on the inboard side of a tread (kept separate so tread diameter measures true). */
182
+ const flangeMesh = (lod: Lod, r: number, y: number, s: number): Mesh =>
183
+ lathe({
184
+ profile: [
185
+ [r - 0.02, y - s * 0.028],
186
+ [r + 0.028, y - s * 0.028],
187
+ [r + 0.028, y],
188
+ [r - 0.02, y],
189
+ ],
190
+ segments: [28, 16, 8][lod] ?? 8,
191
+ axis: 'y',
192
+ color: iron,
193
+ });
194
+
195
+ // ---------------------------------------------------------------- small builders
196
+
197
+ function cable(points: readonly Vec3[], d: number, color: Vec3): Mesh {
198
+ return merge(
199
+ points
200
+ .slice(1)
201
+ .map((to, i) => beam({ from: points[i] as Vec3, to, width: d, segments: 6, color })),
202
+ );
203
+ }
204
+
205
+ /** Block capitals on a 4 × 6 grid as stroke segments. */
206
+ const GLYPHS: Record<string, readonly (readonly [number, number, number, number])[]> = {
207
+ J: [
208
+ [4, 6, 4, 1],
209
+ [4, 1, 3, 0],
210
+ [3, 0, 1, 0],
211
+ [1, 0, 0, 1],
212
+ ],
213
+ U: [
214
+ [0, 6, 0, 1],
215
+ [0, 1, 1, 0],
216
+ [1, 0, 3, 0],
217
+ [3, 0, 4, 1],
218
+ [4, 1, 4, 6],
219
+ ],
220
+ P: [
221
+ [0, 0, 0, 6],
222
+ [0, 6, 3, 6],
223
+ [3, 6, 4, 5],
224
+ [4, 5, 4, 4],
225
+ [4, 4, 3, 3],
226
+ [3, 3, 0, 3],
227
+ ],
228
+ I: [
229
+ [2, 0, 2, 6],
230
+ [1, 0, 3, 0],
231
+ [1, 6, 3, 6],
232
+ ],
233
+ T: [
234
+ [0, 6, 4, 6],
235
+ [2, 6, 2, 0],
236
+ ],
237
+ E: [
238
+ [0, 0, 0, 6],
239
+ [0, 6, 4, 6],
240
+ [0, 3, 3, 3],
241
+ [0, 0, 4, 0],
242
+ ],
243
+ R: [
244
+ [0, 0, 0, 6],
245
+ [0, 6, 3, 6],
246
+ [3, 6, 4, 5],
247
+ [4, 5, 4, 4],
248
+ [4, 4, 3, 3],
249
+ [3, 3, 0, 3],
250
+ [2, 3, 4, 0],
251
+ ],
252
+ '6': [
253
+ [4, 6, 0, 6],
254
+ [0, 6, 0, 0],
255
+ [0, 0, 4, 0],
256
+ [4, 0, 4, 3],
257
+ [4, 3, 0, 3],
258
+ ],
259
+ '0': [
260
+ [0, 0, 0, 6],
261
+ [0, 6, 4, 6],
262
+ [4, 6, 4, 0],
263
+ [4, 0, 0, 0],
264
+ ],
265
+ '2': [
266
+ [0, 6, 4, 6],
267
+ [4, 6, 4, 3],
268
+ [4, 3, 0, 3],
269
+ [0, 3, 0, 0],
270
+ [0, 0, 4, 0],
271
+ ],
272
+ '1': [[2, 0, 2, 6]],
273
+ };
274
+
275
+ /** Text as stroke quads (u right, v up), CCW in (u, v). Unknown glyphs leave a space. */
276
+ function lettering(text: string, h: number): Vec2[][] {
277
+ const k = h / 6;
278
+ const t = 0.9 * k;
279
+ const out: Vec2[][] = [];
280
+ [...text].forEach((ch, i) => {
281
+ for (const [x0, y0, x1, y1] of GLYPHS[ch] ?? []) {
282
+ const a: Vec2 = [(x0 + i * 5.5) * k, y0 * k];
283
+ const b: Vec2 = [(x1 + i * 5.5) * k, y1 * k];
284
+ const l = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1;
285
+ const d: Vec2 = [((b[0] - a[0]) / l) * (t / 2), ((b[1] - a[1]) / l) * (t / 2)];
286
+ const n: Vec2 = [-d[1], d[0]];
287
+ out.push([
288
+ [a[0] - n[0] - d[0], a[1] - n[1] - d[1]],
289
+ [b[0] - n[0] + d[0], b[1] - n[1] + d[1]],
290
+ [b[0] + n[0] + d[0], b[1] + n[1] + d[1]],
291
+ [a[0] + n[0] - d[0], a[1] + n[1] - d[1]],
292
+ ]);
293
+ }
294
+ });
295
+ return out;
296
+ }
297
+
298
+ /** Lettering on a ±Y side wall, centred on (x, z), readable from outside. */
299
+ function sideText(text: string, h: number, s: number, x: number, y: number, z: number, c: Vec3) {
300
+ const quads = lettering(text, h);
301
+ const w = Math.max(...quads.flat().map((q) => q[0]));
302
+ const u: Vec3 = [-s, 0, 0];
303
+ const n: Vec3 = [0, s, 0];
304
+ return merge(
305
+ quads.map((q) =>
306
+ applyAffine(
307
+ planar({ points: q.map(([a, b]): Vec3 => [a - w / 2, b - h / 2, 0]), color: c }),
308
+ frame(u, [0, 0, 1], n, [x, y + s * 0.006, z]),
309
+ ),
310
+ ),
311
+ );
312
+ }
313
+
314
+ /** Run a check only at LODs where `part` exists. */
315
+ const whenBuilt =
316
+ (part: string, check: Check): Check =>
317
+ (asset) =>
318
+ asset.parts.some((p) => p.name === part && p.mesh) ? check(asset) : [];
319
+
320
+ // ---------------------------------------------------------------- the family
321
+
322
+ /**
323
+ * Every `*_l` part mirrors its `*_r` twin across y = 0. (The library's `symmetric('_l', '_r')`
324
+ * rewrites the first `_l` in the name, so `axle_lead_0_wheel_l` became `axle_read_0_wheel_l`.)
325
+ */
326
+ const mirrored: Check = (asset) => {
327
+ const q = inspect(asset);
328
+ return q.parts('*_l').flatMap((l) => {
329
+ const r = `${l.slice(0, -2)}_r`;
330
+ const a = q.bounds(l);
331
+ const b = q.bounds(r);
332
+ if (!a || !b) return [{ part: l, message: `'${l}' has no mirror '${r}'`, fix: `add '${r}'` }];
333
+ const off = Math.abs(a.min[1] + b.max[1]) + Math.abs(a.max[1] + b.min[1]);
334
+ return off > 0.04
335
+ ? [
336
+ {
337
+ part: l,
338
+ message: `'${l}' / '${r}' off mirror by ${(off * 50).toFixed(1)} cm`,
339
+ fix: 'mirror it',
340
+ },
341
+ ]
342
+ : [];
343
+ });
344
+ };
345
+
346
+ /** A plain bearing: a ring whose bore lies on the axle surface (10 sides, like the axle). */
347
+ const bearing = (x: number, z: number, y: number, color: Vec3): Mesh =>
348
+ lathe({
349
+ profile: [
350
+ [0.07, y - 0.06],
351
+ [0.13, y - 0.06],
352
+ [0.13, y + 0.06],
353
+ [0.07, y + 0.06],
354
+ [0.07, y - 0.06],
355
+ ],
356
+ segments: 10,
357
+ axis: 'y',
358
+ at: [x, 0, z],
359
+ color,
360
+ });
361
+
362
+ /**
363
+ * What holds a frame on an axle: a bearing ring at LOD0/1; at LOD2 (no axles) a plate from the
364
+ * frame out to the wheel's inner face.
365
+ */
366
+ const support = (lod: Lod, x: number, z: number, s: number, frameY: number): Mesh =>
367
+ lod < 2
368
+ ? bearing(x, z, s * frameY, iron)
369
+ : box({
370
+ size: [0.3, GAUGE / 2 - frameY + 0.04, 0.3],
371
+ at: [x, s * ((frameY - 0.04 + GAUGE / 2) / 2), z - 0.15],
372
+ color: iron,
373
+ });
374
+
375
+ const americanFamily = defineFamily<Params>({
376
+ kind: 'vehicle',
377
+ tags: ['rail', 'steam', '19th-century'],
378
+ sources: [
379
+ 'https://en.wikipedia.org/wiki/Jupiter_(locomotive) (Schenectady 1868, 4-4-0, 5 ft 4 in drivers, 16 × 24 in cylinders, standard gauge)',
380
+ 'https://en.wikipedia.org/wiki/4-4-0 (American type: 2-axle lead truck, 2 coupled axles)',
381
+ 'https://en.wikipedia.org/wiki/Standard-gauge_railway (1435 mm)',
382
+ 'docs/reference/loco-photo-match.png (owner reference: Jupiter photo + procedural match)',
383
+ ],
384
+ real: {
385
+ length: 17.4,
386
+ width: 2.8,
387
+ height: 4.6,
388
+ tolerance: 0.05,
389
+ measures: [
390
+ {
391
+ label: 'driver diameter (5 ft 4 in)',
392
+ axis: 'z',
393
+ value: 1.626,
394
+ parts: ['axle_driver_0_wheel_l'],
395
+ source: 'https://en.wikipedia.org/wiki/Jupiter_(locomotive)',
396
+ },
397
+ {
398
+ label: 'lead truck wheel diameter (30 in, typical; not in the Jupiter infobox)',
399
+ axis: 'z',
400
+ value: 0.762,
401
+ parts: ['axle_lead_0_wheel_l'],
402
+ },
403
+ {
404
+ label: 'rail centres (1435 mm gauge + 72 mm head)',
405
+ axis: 'y',
406
+ value: GAUGE + HEAD,
407
+ between: ['track_rail_l', 'track_rail_r'],
408
+ source: 'https://en.wikipedia.org/wiki/Standard-gauge_railway',
409
+ },
410
+ {
411
+ label: 'driver wheelbase (8 ft, estimated from the reference photo)',
412
+ axis: 'x',
413
+ value: 2.44,
414
+ between: ['axle_driver_0_wheel_l', 'axle_driver_1_wheel_l'],
415
+ },
416
+ {
417
+ label: 'boiler barrel diameter (49 in, typical)',
418
+ axis: 'y',
419
+ value: 1.24,
420
+ parts: ['boiler_barrel'],
421
+ },
422
+ {
423
+ label: 'funnel stack height (estimated from the reference photo)',
424
+ axis: 'z',
425
+ value: 1.6,
426
+ parts: ['stack'],
427
+ },
428
+ ],
429
+ },
430
+ // A 17 m engine + tender + its own track: LOD2 keeps 16 wheels, boiler, stack and pilot.
431
+ budget: { triangles: [60000, 15000, 1500] },
432
+ checks: [
433
+ clear('axle_*', 'boiler*'),
434
+ clear('cab', 'boiler*'),
435
+ noOverlap('axle_driver_*_wheel_l'),
436
+ touches('boiler_barrel', 'frame'),
437
+ touches('cab', 'frame'),
438
+ whenBuilt('crosshead_l', touches('crosshead_l', 'guides')),
439
+ mirrored,
440
+ ],
441
+ defaults: { arrangement: '4-4-0', number: '60', name: 'JUPITER' },
442
+ build(ctx, p) {
443
+ const lod = ctx.lod;
444
+ const segs = ctx.pick([28, 14, 6]);
445
+ const spokes = ctx.pick([16, 8, 0]);
446
+
447
+ // ---- Wheel arrangement from Whyte; rear driver at x = 0 ----
448
+ const layout = whyteAxles(p.arrangement, {
449
+ leading: LEAD_R,
450
+ driving: DRIVER_R,
451
+ trailing: LEAD_R,
452
+ spacing: SPACING,
453
+ });
454
+ const rearDriver = Math.min(...layout.filter((a) => a.role === 'driving').map((a) => a.x));
455
+ const axles = layout.map((a) => ({
456
+ ...a,
457
+ // The lead truck sits ahead of the cylinders, a little further out than the even spacing.
458
+ x: a.x - rearDriver + (a.role === 'leading' ? 0.6 : 0),
459
+ }));
460
+ const drivers = axles.filter((a) => a.role === 'driving').sort((a, b) => b.x - a.x);
461
+ const leads = axles.filter((a) => a.role === 'leading').sort((a, b) => b.x - a.x);
462
+ const front = Math.max(...axles.map((a) => a.x + a.radius));
463
+ const frontDriver = drivers[0]?.x ?? 2.44;
464
+ const truckX = leads.length ? leads.reduce((s, a) => s + a.x, 0) / leads.length : front - 0.8;
465
+ const smokeFront = front + 0.22;
466
+ const beamX = smokeFront + 0.3;
467
+ const pilotTip = beamX + 0.95;
468
+ const cabFront = -0.9;
469
+ const cabRear = -3.3;
470
+ const tenderFront = cabRear - 0.25;
471
+ const tenderRear = tenderFront - 5.6;
472
+
473
+ // ---- Track: ties + rails, its own part, the length of the train ----
474
+ ctx.group('track');
475
+ const tieCount = Math.round((pilotTip - tenderRear) / 0.6);
476
+ const ties: Mesh[] = [];
477
+ if (lod < 2) {
478
+ for (let i = 0; i < tieCount; i += lod === 0 ? 1 : 2) {
479
+ const x = tenderRear + 0.3 + i * 0.6;
480
+ ties.push(box({ size: [0.23, 2.6, TIE_H], at: [x, 0, 0], color: tieWood, strip: 'wood' }));
481
+ // Tie plates under each rail foot: what the rail actually bears on.
482
+ for (const s of [1, -1])
483
+ ties.push(
484
+ box({ size: [0.2, 0.12, 0.012], at: [x, s * RAIL_Y, TIE_H - 0.011], color: rail }),
485
+ );
486
+ }
487
+ ties.push(
488
+ box({
489
+ size: [pilotTip - tenderRear, 2.7, 0.04],
490
+ at: [(pilotTip + tenderRear) / 2, 0, 0],
491
+ color: ballast,
492
+ strip: 'concrete',
493
+ }),
494
+ );
495
+ } else {
496
+ ties.push(
497
+ box({
498
+ size: [pilotTip - tenderRear, 2.6, TIE_H],
499
+ at: [(pilotTip + tenderRear) / 2, 0, 0],
500
+ color: tieWood,
501
+ }),
502
+ );
503
+ }
504
+ ctx.part('track_ties', grime(merge(ties), { ground: 0.2, groundStrength: 0.3 }), {
505
+ parent: 'track',
506
+ });
507
+ const railProfile: Vec2[] =
508
+ lod === 0
509
+ ? [
510
+ [-0.065, 0],
511
+ [0.065, 0],
512
+ [0.065, 0.012],
513
+ [0.01, 0.03],
514
+ [0.009, 0.1],
515
+ [HEAD / 2, 0.105],
516
+ [HEAD / 2, RAIL_H],
517
+ [-HEAD / 2, RAIL_H],
518
+ [-HEAD / 2, 0.105],
519
+ [-0.009, 0.1],
520
+ [-0.01, 0.03],
521
+ [-0.065, 0.012],
522
+ ]
523
+ : [
524
+ [-0.05, 0],
525
+ [0.05, 0],
526
+ [HEAD / 2, RAIL_H],
527
+ [-HEAD / 2, RAIL_H],
528
+ ];
529
+ for (const [side, s] of [
530
+ ['l', 1],
531
+ ['r', -1],
532
+ ] as const) {
533
+ const r = prism({
534
+ profile: railProfile,
535
+ depth: pilotTip - tenderRear,
536
+ plane: 'yz',
537
+ color: rail,
538
+ strip: 'iron',
539
+ });
540
+ ctx.part(
541
+ `track_rail_${side}`,
542
+ translate(r, [(pilotTip + tenderRear) / 2, s * RAIL_Y, TIE_H]),
543
+ { parent: 'track' },
544
+ );
545
+ }
546
+
547
+ // ---- Locomotive ----
548
+ ctx.group('locomotive');
549
+ const wheelsets: string[] = [];
550
+ const cranks: string[] = [];
551
+ const rails = ['track_rail_l', 'track_rail_r'];
552
+ const driverRps = SPEED / (2 * Math.PI * DRIVER_R);
553
+ const wheelset = (
554
+ name: string,
555
+ x: number,
556
+ r: number,
557
+ parent: string,
558
+ crankAngle: number | null,
559
+ spokeCount: number,
560
+ clearOf: string[],
561
+ ): void => {
562
+ const z = RAIL_TOP + r;
563
+ ctx.group(name, {
564
+ at: [x, 0, z],
565
+ parent,
566
+ motion: { kind: 'spin', axis: [0, 1, 0], rps: SPEED / (2 * Math.PI * r) },
567
+ clearOf: [...rails, ...clearOf],
568
+ });
569
+ wheelsets.push(name);
570
+ const ty = GAUGE / 2 + TREAD_W / 2;
571
+ for (const [side, s] of [
572
+ ['l', 1],
573
+ ['r', -1],
574
+ ] as const) {
575
+ // Right-hand cranks lead the left by 90° (quartering).
576
+ const ca = crankAngle === null ? null : crankAngle + (s > 0 ? 0 : Math.PI / 2);
577
+ const w = wheelMesh(lod, r, 0, spokeCount, ca);
578
+ ctx.part(
579
+ `${name}_wheel_${side}`,
580
+ translate(s > 0 ? w : place(w, { yaw: Math.PI, roll: 0 }), [0, s * ty, 0]),
581
+ { parent: name },
582
+ );
583
+ if (lod < 2)
584
+ ctx.part(`${name}_flange_${side}`, flangeMesh(lod, r, s * (GAUGE / 2), s), {
585
+ parent: name,
586
+ });
587
+ if (ca !== null && lod < 2) {
588
+ const c = `${name}_crank_${side}`;
589
+ cranks.push(c);
590
+ ctx.part(
591
+ c,
592
+ cylinder({
593
+ radius: 0.055,
594
+ length: 0.24,
595
+ segments: 10,
596
+ axis: 'y',
597
+ at: [Math.cos(ca) * CRANK, s * (ty + 0.14), Math.sin(ca) * CRANK],
598
+ color: iron,
599
+ }),
600
+ { parent: name },
601
+ );
602
+ }
603
+ }
604
+ if (lod < 2)
605
+ ctx.part(
606
+ `${name}_axle`,
607
+ cylinder({
608
+ radius: 0.07,
609
+ length: GAUGE + 0.1,
610
+ segments: 10,
611
+ axis: 'y',
612
+ color: iron,
613
+ }),
614
+ { parent: name },
615
+ );
616
+ };
617
+
618
+ // Frame: bar frames inside the wheels, buffer beam, cylinders and saddle, firebox.
619
+ const frameParts: Mesh[] = [];
620
+ for (const s of [1, -1]) {
621
+ frameParts.push(
622
+ box({
623
+ size: [beamX - cabRear, 0.1, 0.28],
624
+ at: [(beamX + cabRear) / 2, s * FRAME_Y, 0.9],
625
+ color: iron,
626
+ }),
627
+ );
628
+ }
629
+ frameParts.push(
630
+ box({ size: [0.25, 2.3, 0.32], at: [beamX - 0.1, 0, 0.85], color: red, strip: 'wood' }),
631
+ box({
632
+ size: [cabFront - cabRear + 0.3, 2.5, 0.12],
633
+ at: [(cabFront + cabRear) / 2, 0, DECK_Z - 0.12],
634
+ color: wood,
635
+ strip: 'wood',
636
+ }),
637
+ // Firebox between the frames ahead of the cab.
638
+ box({ size: [1.2, 1.0, 1.1], at: [cabFront - 0.3, 0, 1.0], color: jacket }),
639
+ // Cross-stretchers that tie the frames to the boiler.
640
+ box({ size: [0.3, 1.1, 0.9], at: [frontDriver + 1.2, 0, 1.18], color: iron }),
641
+ );
642
+ const cylX = truckX + 0.05;
643
+ const guideFront = cylX - 0.5;
644
+ const guideRear = frontDriver + 1.0;
645
+ for (const s of [1, -1]) {
646
+ frameParts.push(
647
+ // Cylinder with brass-banded heads, saddle up to the smokebox.
648
+ lathe({
649
+ profile: [
650
+ [0.22, cylX - 0.5],
651
+ [0.25, cylX - 0.46],
652
+ [0.25, cylX + 0.46],
653
+ [0.22, cylX + 0.5],
654
+ ],
655
+ segments: segs,
656
+ axis: 'x',
657
+ at: [0, s * ROD_Y, CYL_Z],
658
+ color: blue,
659
+ caps: true,
660
+ }),
661
+ box({
662
+ size: [1.0, ROD_Y - FRAME_Y, 0.55],
663
+ at: [cylX, s * (FRAME_Y + (ROD_Y - FRAME_Y) / 2), CYL_Z - 0.2],
664
+ color: blueDark,
665
+ }),
666
+ );
667
+ if (lod < 2)
668
+ for (const dx of [-0.5, 0.5])
669
+ frameParts.push(
670
+ lathe({
671
+ profile: [
672
+ [0.255, -0.015],
673
+ [0.255, 0.015],
674
+ ],
675
+ segments: segs,
676
+ axis: 'x',
677
+ at: [cylX + dx, s * ROD_Y, CYL_Z],
678
+ color: brass,
679
+ }),
680
+ );
681
+ }
682
+ for (const d of drivers)
683
+ for (const s of [1, -1]) frameParts.push(support(lod, d.x, RAIL_TOP + d.radius, s, FRAME_Y));
684
+ ctx.part('frame', grime(merge(frameParts), { ground: 1.2, groundStrength: 0.35 }), {
685
+ parent: 'locomotive',
686
+ });
687
+ // Crosshead guides (bars above and below the crosshead path), mounted on a yoke.
688
+ const guides: Mesh[] = [];
689
+ for (const s of [1, -1]) {
690
+ for (const dz of [0.11, -0.11])
691
+ guides.push(
692
+ box({
693
+ size: [guideFront - guideRear, 0.06, 0.04],
694
+ at: [(guideFront + guideRear) / 2, s * ROD_Y, CYL_Z + dz - 0.02],
695
+ color: iron,
696
+ }),
697
+ );
698
+ guides.push(
699
+ box({
700
+ size: [0.08, ROD_Y - FRAME_Y + 0.05, 0.3],
701
+ at: [guideRear, s * (FRAME_Y + (ROD_Y - FRAME_Y) / 2), CYL_Z - 0.15],
702
+ color: iron,
703
+ }),
704
+ );
705
+ }
706
+ if (lod < 2) ctx.part('guides', merge(guides), { parent: 'locomotive' });
707
+
708
+ // Wheelsets: lead truck (with its own frame), coupled drivers.
709
+ if (leads.length) {
710
+ ctx.part(
711
+ 'lead_truck',
712
+ merge(
713
+ [1, -1]
714
+ .map((s) =>
715
+ box({
716
+ size: [
717
+ Math.abs((leads[0]?.x ?? 0) - (leads[leads.length - 1]?.x ?? 0)) + 0.5,
718
+ 0.08,
719
+ 0.18,
720
+ ],
721
+ at: [truckX, s * 0.45, RAIL_TOP + LEAD_R - 0.09],
722
+ color: iron,
723
+ }),
724
+ )
725
+ .concat([
726
+ box({
727
+ size: [0.3, 1.0, 0.45],
728
+ at: [truckX, 0, RAIL_TOP + LEAD_R - 0.05],
729
+ color: iron,
730
+ }),
731
+ ])
732
+ .concat(
733
+ leads.flatMap((a) =>
734
+ [1, -1].map((s) => support(lod, a.x, RAIL_TOP + a.radius, s, 0.45)),
735
+ ),
736
+ ),
737
+ ),
738
+ { parent: 'locomotive' },
739
+ );
740
+ }
741
+ leads.forEach((a, i) => {
742
+ wheelset(`axle_lead_${i}`, a.x, a.radius, 'locomotive', null, ctx.pick([10, 8, 0]), [
743
+ 'lead_truck',
744
+ ]);
745
+ });
746
+ drivers.forEach((a, i) => {
747
+ wheelset(`axle_driver_${i}`, a.x, a.radius, 'locomotive', 0, spokes, [
748
+ 'frame',
749
+ 'rod_side_l',
750
+ 'rod_side_r',
751
+ 'rod_main_l',
752
+ 'rod_main_r',
753
+ ]);
754
+ });
755
+
756
+ // Side rods (coupling the drivers) and main rods (crosshead → front crank), crossheads.
757
+ // Real motion is a circular translation; the DSL has spin/slide/sway, so each rod slides
758
+ // vertically through the crank throw (side) or horizontally through the stroke (main).
759
+ if (lod < 2) {
760
+ const zA = RAIL_TOP + DRIVER_R;
761
+ for (const [side, s] of [
762
+ ['l', 1],
763
+ ['r', -1],
764
+ ] as const) {
765
+ const ca = s > 0 ? 0 : Math.PI / 2;
766
+ const cx = Math.cos(ca) * CRANK;
767
+ const cz = Math.sin(ca) * CRANK;
768
+ const yS = s * (GAUGE / 2 + TREAD_W + 0.1);
769
+ const xs = drivers.map((d) => d.x + cx);
770
+ const sideRod = merge([
771
+ beam({
772
+ from: [Math.min(...xs) - 0.08, 0, 0],
773
+ to: [Math.max(...xs) + 0.08, 0, 0],
774
+ width: 0.05,
775
+ height: 0.11,
776
+ color: iron,
777
+ }),
778
+ ...xs.map((x) =>
779
+ cylinder({
780
+ radius: 0.09,
781
+ length: 0.06,
782
+ segments: 12,
783
+ axis: 'y',
784
+ at: [x, 0, 0],
785
+ color: iron,
786
+ }),
787
+ ),
788
+ ]);
789
+ ctx.part(`rod_side_${side}`, sideRod, {
790
+ parent: 'locomotive',
791
+ at: [0, yS, zA + cz],
792
+ motion: { kind: 'slide', offset: [0, 0, CRANK], hz: driverRps },
793
+ clearOf: [...cranks, `rod_main_${side}`, ...wheelsets.map((w) => `${w}_wheel_${side}`)],
794
+ });
795
+ const crossX = (guideFront + guideRear) / 2;
796
+ const yM = s * ROD_Y;
797
+ ctx.part(
798
+ `crosshead_${side}`,
799
+ merge([
800
+ box({ size: [0.26, 0.14, 0.18], at: [0, 0, -0.09], color: brass }),
801
+ beam({
802
+ from: [0, 0, 0],
803
+ to: [cylX - 0.5 - crossX, 0, 0],
804
+ width: 0.06,
805
+ segments: 8,
806
+ color: iron,
807
+ }),
808
+ ]),
809
+ {
810
+ parent: 'locomotive',
811
+ at: [crossX, yM, CYL_Z],
812
+ motion: { kind: 'slide', offset: [CRANK, 0, 0], hz: driverRps },
813
+ clearOf: ['guides', 'frame', `rod_main_${side}`],
814
+ },
815
+ );
816
+ const fx = (drivers[0]?.x ?? frontDriver) + cx;
817
+ ctx.part(
818
+ `rod_main_${side}`,
819
+ merge([
820
+ beam({
821
+ from: [0, 0, 0],
822
+ to: [fx - crossX, 0, zA + cz - CYL_Z],
823
+ width: 0.05,
824
+ height: 0.13,
825
+ color: iron,
826
+ }),
827
+ cylinder({
828
+ radius: 0.1,
829
+ length: 0.06,
830
+ segments: 12,
831
+ axis: 'y',
832
+ at: [fx - crossX, 0, zA + cz - CYL_Z],
833
+ color: iron,
834
+ }),
835
+ ]),
836
+ {
837
+ parent: 'locomotive',
838
+ at: [crossX, s * (ROD_Y + 0.0), CYL_Z],
839
+ motion: { kind: 'slide', offset: [CRANK, 0, 0], hz: driverRps },
840
+ clearOf: [
841
+ ...cranks,
842
+ `crosshead_${side}`,
843
+ 'guides',
844
+ `rod_side_${side}`,
845
+ ...wheelsets.map((w) => `${w}_wheel_${side}`),
846
+ ],
847
+ },
848
+ );
849
+ ctx.emitter(`cylinder_steam_${side}`, {
850
+ kind: 'steam',
851
+ at: [cylX + 0.5, s * ROD_Y, CYL_Z - 0.2],
852
+ dir: [0.3, s * 0.6, -0.3],
853
+ rate: 25,
854
+ life: 1.2,
855
+ size: [0.15, 0.9],
856
+ color: hex('#e8e8e8'),
857
+ speed: 2,
858
+ spreadDeg: 30,
859
+ when: 'moving',
860
+ });
861
+ }
862
+ }
863
+
864
+ // ---- Boiler: smokebox, barrel with brass bands, wagon-top, domes, bell, stack, headlamp ----
865
+ const barrelFront = smokeFront - 1.05;
866
+ const barrelRear = cabFront + 0.05;
867
+ ctx.part(
868
+ 'boiler_barrel',
869
+ lathe({
870
+ profile: [
871
+ [BOILER_R, barrelRear],
872
+ [BOILER_R, barrelRear + 1.0],
873
+ [BOILER_R * 0.95, barrelRear + 1.4],
874
+ [BOILER_R * 0.95, barrelFront],
875
+ ],
876
+ segments: segs,
877
+ axis: 'x',
878
+ at: [0, 0, BOILER_Z],
879
+ color: jacket,
880
+ caps: true,
881
+ }),
882
+ { parent: 'locomotive' },
883
+ );
884
+ // Saddle from the frame up to the boiler.
885
+ ctx.part(
886
+ 'boiler_saddle',
887
+ merge([
888
+ box({
889
+ size: [0.9, 1.1, BOILER_Z - 1.04],
890
+ at: [smokeFront - 0.55, 0, 1.04],
891
+ color: blueDark,
892
+ }),
893
+ ]),
894
+ { parent: 'locomotive' },
895
+ );
896
+ const smoke: Mesh[] = [
897
+ lathe({
898
+ profile: [
899
+ [SMOKEBOX_R, barrelFront - 0.02],
900
+ [SMOKEBOX_R, smokeFront - 0.06],
901
+ [SMOKEBOX_R - 0.04, smokeFront],
902
+ [0.4, smokeFront + 0.03],
903
+ [0, smokeFront + 0.05],
904
+ ],
905
+ segments: segs,
906
+ axis: 'x',
907
+ at: [0, 0, BOILER_Z],
908
+ color: black,
909
+ caps: true,
910
+ }),
911
+ ];
912
+ if (lod < 2) {
913
+ // Number plate on the smokebox door, brass ring.
914
+ smoke.push(
915
+ lathe({
916
+ profile: [
917
+ [0.14, smokeFront + 0.05],
918
+ [0.14, smokeFront + 0.07],
919
+ [0, smokeFront + 0.07],
920
+ ],
921
+ segments: 16,
922
+ axis: 'x',
923
+ at: [0, 0, BOILER_Z],
924
+ color: brass,
925
+ }),
926
+ );
927
+ const bands = lod === 0 ? 7 : 3;
928
+ for (let i = 0; i <= bands; i++) {
929
+ const x = barrelRear + 0.1 + ((barrelFront - barrelRear - 0.2) * i) / bands;
930
+ const r = x < barrelRear + 1.2 ? BOILER_R : BOILER_R * 0.95;
931
+ smoke.push(
932
+ lathe({
933
+ profile: [
934
+ [r + 0.008, x - 0.025],
935
+ [r + 0.008, x + 0.025],
936
+ ],
937
+ segments: segs,
938
+ axis: 'x',
939
+ at: [0, 0, BOILER_Z],
940
+ color: brass,
941
+ }),
942
+ );
943
+ }
944
+ }
945
+ ctx.part('boiler_front', merge(smoke), { parent: 'locomotive' });
946
+
947
+ // Stack: Jupiter's big funnel (balloon) stack with a capped rim.
948
+ const stackBase = BOILER_Z + SMOKEBOX_R - 0.06;
949
+ const stackX = smokeFront - 0.45;
950
+ ctx.part(
951
+ 'stack',
952
+ lathe({
953
+ profile:
954
+ lod < 2
955
+ ? [
956
+ [0.26, 0],
957
+ [0.2, 0.12],
958
+ [0.19, 0.55],
959
+ [0.3, 0.75],
960
+ [0.52, 1.35],
961
+ [0.56, 1.42],
962
+ [0.54, 1.5],
963
+ [0.42, 1.56],
964
+ [0.2, 1.6],
965
+ ]
966
+ : [
967
+ [0.22, 0],
968
+ [0.19, 0.55],
969
+ [0.56, 1.42],
970
+ [0.3, 1.6],
971
+ ],
972
+ segments: segs,
973
+ at: [stackX, 0, stackBase],
974
+ color: black,
975
+ caps: true,
976
+ }),
977
+ { parent: 'locomotive' },
978
+ );
979
+ ctx.emitter('stack_smoke', {
980
+ kind: 'smoke',
981
+ parent: 'locomotive',
982
+ at: [stackX, 0, stackBase + 1.62],
983
+ rate: 18,
984
+ life: 4,
985
+ size: [0.5, 3],
986
+ color: hex('#4a4a4a'),
987
+ speed: 2.5,
988
+ spreadDeg: 12,
989
+ when: 'always',
990
+ });
991
+ // Domes: brass steam dome over the wagon-top, blue sand dome with brass bands; bell between.
992
+ const dome = (x: number, h: number, r: number, c: Vec3): Mesh =>
993
+ lathe({
994
+ profile:
995
+ lod < 2
996
+ ? [
997
+ [r + 0.12, -0.08],
998
+ [r + 0.02, 0.0],
999
+ [r, 0.05],
1000
+ [r, h * 0.6],
1001
+ [r * 0.95, h * 0.72],
1002
+ [r * 0.7, h * 0.9],
1003
+ [r * 0.3, h],
1004
+ [0, h],
1005
+ ]
1006
+ : [
1007
+ [r + 0.1, -0.08],
1008
+ [r, h * 0.6],
1009
+ [0, h],
1010
+ ],
1011
+ segments: segs,
1012
+ at: [x, 0, BOILER_Z + BOILER_R * 0.95 - 0.06],
1013
+ color: c,
1014
+ });
1015
+ const steamX = barrelRear + 0.55;
1016
+ const sandX = (stackX + steamX) / 2 + 0.35;
1017
+ const domes: Mesh[] = [dome(steamX, 0.78, 0.33, brass), dome(sandX, 0.62, 0.3, blue)];
1018
+ if (lod < 2) {
1019
+ domes.push(
1020
+ lathe({
1021
+ profile: [
1022
+ [0.315, 0.3],
1023
+ [0.315, 0.36],
1024
+ ],
1025
+ segments: segs,
1026
+ at: [sandX, 0, BOILER_Z + BOILER_R * 0.95 - 0.06],
1027
+ color: brass,
1028
+ }),
1029
+ // Whistle on the steam dome.
1030
+ lathe({
1031
+ profile: [
1032
+ [0.03, 0],
1033
+ [0.03, 0.12],
1034
+ [0.06, 0.14],
1035
+ [0.06, 0.3],
1036
+ [0.02, 0.34],
1037
+ ],
1038
+ segments: 10,
1039
+ at: [steamX - 0.12, 0, BOILER_Z + BOILER_R * 0.95 + 0.7],
1040
+ color: brass,
1041
+ caps: true,
1042
+ }),
1043
+ );
1044
+ // Bell in its yoke.
1045
+ const bellX = (sandX + steamX) / 2;
1046
+ const bellZ = BOILER_Z + BOILER_R * 0.95 + 0.32;
1047
+ domes.push(
1048
+ lathe({
1049
+ profile: [
1050
+ [0.2, 0],
1051
+ [0.18, 0.04],
1052
+ [0.13, 0.2],
1053
+ [0.11, 0.3],
1054
+ [0.04, 0.33],
1055
+ ],
1056
+ segments: segs,
1057
+ at: [bellX, 0, bellZ - 0.16],
1058
+ color: brass,
1059
+ caps: true,
1060
+ }),
1061
+ beam({
1062
+ from: [bellX, 0.24, BOILER_Z + BOILER_R * 0.95 - 0.04],
1063
+ to: [bellX, 0.24, bellZ + 0.22],
1064
+ width: 0.04,
1065
+ color: brass,
1066
+ }),
1067
+ beam({
1068
+ from: [bellX, -0.24, BOILER_Z + BOILER_R * 0.95 - 0.04],
1069
+ to: [bellX, -0.24, bellZ + 0.22],
1070
+ width: 0.04,
1071
+ color: brass,
1072
+ }),
1073
+ beam({
1074
+ from: [bellX, 0.24, bellZ + 0.22],
1075
+ to: [bellX, -0.24, bellZ + 0.22],
1076
+ width: 0.04,
1077
+ color: brass,
1078
+ }),
1079
+ );
1080
+ }
1081
+ ctx.part('boiler_domes', merge(domes), { parent: 'locomotive' });
1082
+
1083
+ // Headlamp: the big box lamp on a bracket on the smokebox, lens forward.
1084
+ const lampZ = BOILER_Z + SMOKEBOX_R + 0.02;
1085
+ const lamp: Mesh[] = [
1086
+ box({ size: [0.5, 0.18, 0.1], at: [smokeFront - 0.18, 0, lampZ - 0.12], color: blueDark }),
1087
+ box({ size: [0.55, 0.5, 0.6], at: [smokeFront - 0.15, 0, lampZ - 0.02], color: blue }),
1088
+ prism({
1089
+ profile: [
1090
+ [-0.3, 0],
1091
+ [0.3, 0],
1092
+ [0.18, 0.18],
1093
+ [-0.18, 0.18],
1094
+ ],
1095
+ depth: 0.55,
1096
+ plane: 'yz',
1097
+ color: blueDark,
1098
+ centred: true,
1099
+ }).positions.length
1100
+ ? translate(
1101
+ prism({
1102
+ profile: [
1103
+ [-0.3, 0],
1104
+ [0.3, 0],
1105
+ [0.18, 0.18],
1106
+ [-0.18, 0.18],
1107
+ ],
1108
+ depth: 0.55,
1109
+ plane: 'yz',
1110
+ color: blueDark,
1111
+ }),
1112
+ [smokeFront - 0.15, 0, lampZ + 0.58],
1113
+ )
1114
+ : box({ size: [0.1, 0.1, 0.1], color: blue }),
1115
+ ];
1116
+ if (lod < 2)
1117
+ lamp.push(
1118
+ lathe({
1119
+ profile: [
1120
+ [0.2, 0],
1121
+ [0.2, 0.04],
1122
+ [0.16, 0.05],
1123
+ [0, 0.05],
1124
+ ],
1125
+ segments: segs,
1126
+ axis: 'x',
1127
+ at: [smokeFront + 0.125, 0, lampZ + 0.28],
1128
+ color: hex('#f2e2a0'),
1129
+ }),
1130
+ box({ size: [0.04, 0.56, 0.04], at: [smokeFront + 0.125, 0, lampZ + 0.56], color: brass }),
1131
+ box({ size: [0.04, 0.56, 0.04], at: [smokeFront + 0.125, 0, lampZ - 0.02], color: brass }),
1132
+ lathe({
1133
+ profile: [
1134
+ [0.08, 0],
1135
+ [0.06, 0.12],
1136
+ [0.1, 0.16],
1137
+ [0.02, 0.2],
1138
+ ],
1139
+ segments: 10,
1140
+ at: [smokeFront - 0.15, 0, lampZ + 0.76],
1141
+ color: brass,
1142
+ caps: true,
1143
+ }),
1144
+ );
1145
+ ctx.part('headlamp', merge(lamp), { parent: 'locomotive' });
1146
+
1147
+ // Running boards with brass edging, sand pipes, handrails.
1148
+ const boards: Mesh[] = [];
1149
+ const boardZ = RAIL_TOP + 2 * DRIVER_R + 0.06;
1150
+ for (const s of [1, -1]) {
1151
+ boards.push(
1152
+ box({
1153
+ size: [barrelFront - cabFront, 0.42, 0.04],
1154
+ at: [(barrelFront + cabFront) / 2, s * 0.95, boardZ],
1155
+ color: blue,
1156
+ }),
1157
+ box({
1158
+ size: [0.12, 0.42, boardZ - 1.04],
1159
+ at: [frontDriver + 1.0, s * 0.95, 1.04],
1160
+ color: iron,
1161
+ }),
1162
+ );
1163
+ if (lod < 2)
1164
+ boards.push(
1165
+ box({
1166
+ size: [barrelFront - cabFront - 0.1, 0.02, 0.06],
1167
+ at: [(barrelFront + cabFront) / 2 + 0.05, s * 1.165, boardZ - 0.01],
1168
+ color: brass,
1169
+ }),
1170
+ cable(
1171
+ [
1172
+ [cabFront - 0.02, s * (BOILER_R + 0.1), BOILER_Z + 0.25],
1173
+ [smokeFront - 0.15, s * (SMOKEBOX_R + 0.1), BOILER_Z + 0.25],
1174
+ ],
1175
+ 0.03,
1176
+ brass,
1177
+ ),
1178
+ );
1179
+ if (lod === 0)
1180
+ for (const x of [cabFront + 0.4, barrelRear + 2.2, barrelFront - 0.2])
1181
+ boards.push(
1182
+ beam({
1183
+ from: [x, s * (BOILER_R + 0.02), BOILER_Z + 0.25],
1184
+ to: [x, s * (BOILER_R + 0.1), BOILER_Z + 0.25],
1185
+ width: 0.025,
1186
+ color: brass,
1187
+ }),
1188
+ );
1189
+ }
1190
+ ctx.part('running_boards', merge(boards), { parent: 'locomotive' });
1191
+
1192
+ // Pilot (cowcatcher): a V of slats from the buffer beam to the point.
1193
+ const pilot: Mesh[] = [];
1194
+ const slats = ctx.pick([9, 5, 2]);
1195
+ const pz0 = RAIL_TOP + 0.08;
1196
+ const pz1 = 1.0;
1197
+ for (const s of [1, -1]) {
1198
+ for (let i = 0; i < slats; i++) {
1199
+ const t = i / (slats - 1);
1200
+ const y = s * (0.08 + t * 1.0);
1201
+ pilot.push(
1202
+ beam({
1203
+ from: [beamX + 0.03, y, pz1],
1204
+ to: [pilotTip - Math.abs(y) * 0.85, y * 0.55, pz0 + 0.02],
1205
+ width: 0.05,
1206
+ height: 0.06,
1207
+ color: blue,
1208
+ }),
1209
+ );
1210
+ }
1211
+ pilot.push(
1212
+ beam({
1213
+ from: [beamX + 0.03, s * 1.1, pz1],
1214
+ to: [pilotTip, 0, pz1 - 0.15],
1215
+ width: 0.07,
1216
+ color: blueDark,
1217
+ }),
1218
+ beam({
1219
+ from: [beamX + 0.03, s * 1.1, pz0 + 0.05],
1220
+ to: [pilotTip, 0, pz0],
1221
+ width: 0.07,
1222
+ color: blueDark,
1223
+ }),
1224
+ );
1225
+ }
1226
+ pilot.push(
1227
+ beam({ from: [beamX + 0.03, 0, pz1], to: [pilotTip, 0, pz0], width: 0.08, color: blueDark }),
1228
+ );
1229
+ ctx.part('pilot', merge(pilot), { parent: 'locomotive' });
1230
+
1231
+ // Cab: maroon-red wooden cab with windows and an arched roof.
1232
+ const cabW = 2.5;
1233
+ const cabH = 1.95;
1234
+ const cab: Mesh[] = [
1235
+ box({
1236
+ size: [cabFront - cabRear, cabW, cabH],
1237
+ at: [(cabFront + cabRear) / 2, 0, DECK_Z],
1238
+ color: red,
1239
+ strip: 'wood',
1240
+ }),
1241
+ translate(
1242
+ prism({
1243
+ profile: Array.from({ length: 9 }, (_, i): Vec2 => {
1244
+ const a = Math.PI * (i / 8);
1245
+ return [Math.cos(a) * 1.35, Math.sin(a) * 0.22];
1246
+ }),
1247
+ depth: cabFront - cabRear + 0.4,
1248
+ plane: 'yz',
1249
+ color: hex('#2a2a2a'),
1250
+ }),
1251
+ [(cabFront + cabRear) / 2, 0, DECK_Z + cabH],
1252
+ ),
1253
+ ];
1254
+ if (lod < 2) {
1255
+ for (const s of [1, -1]) {
1256
+ for (const [i, x] of [cabFront - 0.55, cabRear + 0.6].entries())
1257
+ cab.push(
1258
+ box({
1259
+ size: [0.55, 0.02, 0.7],
1260
+ at: [x, s * (cabW / 2 + 0.01), DECK_Z + 0.95],
1261
+ color: glass,
1262
+ }),
1263
+ box({
1264
+ size: [0.63, 0.03, 0.06],
1265
+ at: [x, s * (cabW / 2 + 0.015), DECK_Z + 1.67 + (i === 0 ? 0 : 0)],
1266
+ color: brass,
1267
+ }),
1268
+ );
1269
+ cab.push(
1270
+ box({
1271
+ size: [0.02, 0.5, 0.6],
1272
+ at: [cabFront + 0.01, s * 0.95, DECK_Z + 1.05],
1273
+ color: glass,
1274
+ }),
1275
+ box({
1276
+ size: [cabFront - cabRear - 0.1, 0.03, 0.05],
1277
+ at: [(cabFront + cabRear) / 2, s * (cabW / 2 + 0.015), DECK_Z + 0.25],
1278
+ color: brass,
1279
+ }),
1280
+ );
1281
+ }
1282
+ if (lod === 0)
1283
+ for (const s of [1, -1])
1284
+ cab.push(
1285
+ sideText(
1286
+ p.number,
1287
+ 0.3,
1288
+ s,
1289
+ (cabFront + cabRear) / 2,
1290
+ s * (cabW / 2 + 0.003),
1291
+ DECK_Z + 0.5,
1292
+ brass,
1293
+ ),
1294
+ );
1295
+ }
1296
+ ctx.part('cab', merge(cab), { parent: 'locomotive' });
1297
+
1298
+ // ---- Tender: its own group, two four-wheel trucks, wood load, lettered panel ----
1299
+ ctx.group('tender');
1300
+ const tLen = tenderFront - tenderRear;
1301
+ const tz = RAIL_TOP + TENDER_R * 2 + 0.22;
1302
+ const trucks = [tenderFront - 1.25, tenderRear + 1.25];
1303
+ const tender: Mesh[] = [
1304
+ box({ size: [tLen, 2.5, 0.2], at: [(tenderFront + tenderRear) / 2, 0, tz], color: iron }),
1305
+ box({
1306
+ size: [tLen - 0.2, 2.4, 1.15],
1307
+ at: [(tenderFront + tenderRear) / 2 - 0.05, 0, tz + 0.2],
1308
+ color: blue,
1309
+ }),
1310
+ box({ size: [0.3, 0.5, 0.15], at: [tenderFront + 0.1, 0, tz + 0.02], color: iron }),
1311
+ ];
1312
+ for (const x of trucks)
1313
+ tender.push(
1314
+ box({
1315
+ size: [0.4, 1.0, tz - (RAIL_TOP + TENDER_R) + 0.02],
1316
+ at: [x, 0, RAIL_TOP + TENDER_R - 0.02],
1317
+ color: iron,
1318
+ }),
1319
+ ...[1, -1].map((s) =>
1320
+ box({
1321
+ size: [1.4, 0.08, 0.2],
1322
+ at: [x, s * 0.45, RAIL_TOP + TENDER_R - 0.1],
1323
+ color: iron,
1324
+ }),
1325
+ ),
1326
+ ...[0.45, -0.45].flatMap((dx) =>
1327
+ [1, -1].map((s) => support(lod, x + dx, RAIL_TOP + TENDER_R, s, 0.45)),
1328
+ ),
1329
+ );
1330
+ if (lod < 2) {
1331
+ // Flared coping rail round the top, and the stacked cordwood.
1332
+ for (const s of [1, -1])
1333
+ tender.push(
1334
+ box({
1335
+ size: [tLen - 0.2, 0.06, 0.25],
1336
+ at: [(tenderFront + tenderRear) / 2 - 0.05, s * 1.2, tz + 1.35],
1337
+ color: blueDark,
1338
+ }),
1339
+ );
1340
+ tender.push(
1341
+ box({ size: [0.06, 2.4, 0.25], at: [tenderRear + 0.08, 0, tz + 1.35], color: blueDark }),
1342
+ );
1343
+ const rows = lod === 0 ? 4 : 2;
1344
+ for (let r = 0; r < rows; r++)
1345
+ for (let k = 0; k < (lod === 0 ? 9 : 4); k++) {
1346
+ const y = -1.0 + (2.0 * (k + (r % 2) * 0.5)) / (lod === 0 ? 9 : 4);
1347
+ if (Math.abs(y) > 1.05) continue;
1348
+ tender.push(
1349
+ cylinder({
1350
+ radius: 0.11,
1351
+ length: 1.2 + ctx.rng.range(-0.1, 0.1),
1352
+ segments: 7,
1353
+ axis: 'x',
1354
+ at: [tenderFront - 1.0, y, tz + 1.46 + r * 0.19],
1355
+ color: ctx.rng.next() > 0.5 ? wood : woodLight,
1356
+ }),
1357
+ );
1358
+ }
1359
+ // Lettered panel: red, brass edged, the engine's name.
1360
+ for (const s of [1, -1]) {
1361
+ tender.push(
1362
+ box({
1363
+ size: [2.6, 0.02, 0.5],
1364
+ at: [(tenderFront + tenderRear) / 2 - 0.3, s * 1.205, tz + 0.5],
1365
+ color: red,
1366
+ }),
1367
+ );
1368
+ if (lod === 0)
1369
+ tender.push(
1370
+ sideText(
1371
+ p.name,
1372
+ 0.3,
1373
+ s,
1374
+ (tenderFront + tenderRear) / 2 - 0.3,
1375
+ s * 1.215,
1376
+ tz + 0.75,
1377
+ brass,
1378
+ ),
1379
+ );
1380
+ }
1381
+ }
1382
+ ctx.part(
1383
+ 'tender_body',
1384
+ livery(merge(tender), {
1385
+ rules: [{ color: [0.55, 0.55, 0.6], facing: 'under', multiply: true }],
1386
+ }),
1387
+ { parent: 'tender' },
1388
+ );
1389
+ trucks.forEach((tx, t) => {
1390
+ [0.45, -0.45].forEach((dx, a) => {
1391
+ wheelset(`axle_tender_${t}_${a}`, tx + dx, TENDER_R, 'tender', null, ctx.pick([0, 0, 0]), [
1392
+ 'tender_body',
1393
+ ]);
1394
+ });
1395
+ });
1396
+ },
1397
+ });
1398
+
1399
+ /** American 4-4-0 in Jupiter colours. */
1400
+ export const loco_440 = americanFamily.variant({
1401
+ name: 'loco_440',
1402
+ description:
1403
+ 'American 4-4-0 "Jupiter" — funnel stack, brass domes, bell, box headlamp, slatted pilot, red spoked drivers with rods, tender, track',
1404
+ });