roamwright 0.20.1 → 0.54.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 (516) hide show
  1. package/.prettierrc.yaml +12 -0
  2. package/CONTRIBUTING.md +19 -14
  3. package/README.md +35 -16
  4. package/examples/animals.html +49 -0
  5. package/examples/animals.js +209 -0
  6. package/examples/crowds.html +50 -0
  7. package/examples/crowds.js +268 -0
  8. package/examples/effects.html +53 -0
  9. package/examples/effects.js +343 -0
  10. package/examples/figure-motion.html +55 -0
  11. package/examples/figure-motion.js +265 -0
  12. package/examples/figure.html +49 -0
  13. package/examples/figure.js +238 -0
  14. package/examples/fliers.html +53 -0
  15. package/examples/fliers.js +292 -0
  16. package/examples/fortification.html +54 -0
  17. package/examples/fortification.js +288 -0
  18. package/examples/house-kit.html +48 -0
  19. package/examples/house-kit.js +175 -0
  20. package/examples/index.html +26 -16
  21. package/examples/island.html +48 -0
  22. package/examples/island.js +134 -52
  23. package/examples/land.html +54 -0
  24. package/examples/land.js +392 -0
  25. package/examples/props-and-plants.html +53 -0
  26. package/examples/props-and-plants.js +275 -0
  27. package/examples/rooms.html +48 -0
  28. package/examples/rooms.js +242 -0
  29. package/examples/ships.html +51 -0
  30. package/examples/ships.js +235 -0
  31. package/examples/showcase.css +320 -0
  32. package/examples/small-world-land.js +151 -0
  33. package/examples/small-world-life.js +160 -0
  34. package/examples/small-world-town.js +127 -0
  35. package/examples/small-world.html +57 -0
  36. package/examples/small-world.js +226 -0
  37. package/examples/soundscape.html +138 -0
  38. package/examples/soundscape.js +467 -0
  39. package/examples/stage-kits.js +300 -0
  40. package/examples/stage.js +374 -0
  41. package/examples/towns.html +50 -0
  42. package/examples/towns.js +325 -0
  43. package/examples/viaduct-camera.js +8 -4
  44. package/examples/viaduct-landscape.js +28 -17
  45. package/examples/viaduct.html +45 -43
  46. package/examples/viaduct.js +68 -92
  47. package/geometry/animal-camel-body.js +410 -0
  48. package/geometry/animal-camel-head.js +118 -0
  49. package/geometry/animal-canine-body.js +361 -0
  50. package/geometry/animal-canine-breeds.js +316 -0
  51. package/geometry/animal-canine-head.js +337 -0
  52. package/geometry/animal-cattle-body.js +391 -0
  53. package/geometry/animal-cattle-coat.js +42 -0
  54. package/geometry/animal-cattle-head.js +152 -0
  55. package/geometry/animal-hen.js +248 -0
  56. package/geometry/animal-horse-body.js +446 -0
  57. package/geometry/animal-horse-bridle.js +171 -0
  58. package/geometry/animal-horse-coat.js +68 -0
  59. package/geometry/animal-horse-face.js +162 -0
  60. package/geometry/animal-horse-hair.js +304 -0
  61. package/geometry/animal-horse-head.js +133 -0
  62. package/geometry/animal-horse-tack.js +157 -0
  63. package/geometry/animal-options.js +59 -0
  64. package/geometry/animal-shapes.js +21 -0
  65. package/geometry/animal-skin.js +390 -0
  66. package/geometry/builder-cells.js +10 -2
  67. package/geometry/builder-frame.js +2 -1
  68. package/geometry/builder.js +15 -4
  69. package/geometry/card-emblem.js +437 -0
  70. package/geometry/catenary-canvas.js +396 -0
  71. package/geometry/cloth-folds.js +143 -0
  72. package/geometry/crawl-shapes.js +71 -0
  73. package/geometry/creased-sheet.js +7 -2
  74. package/geometry/crowd-dress.js +315 -0
  75. package/geometry/crowd-far.js +174 -0
  76. package/geometry/crowd-look.js +42 -0
  77. package/geometry/crowd-weld.js +218 -0
  78. package/geometry/ear.js +9 -4
  79. package/geometry/erosion.js +7 -4
  80. package/geometry/face-grid.js +26 -6
  81. package/geometry/field-map.js +59 -0
  82. package/geometry/figure-arms.js +339 -0
  83. package/geometry/figure-beard.js +250 -0
  84. package/geometry/figure-body.js +297 -0
  85. package/geometry/figure-bow.js +105 -0
  86. package/geometry/figure-cloak.js +189 -0
  87. package/geometry/figure-clothes.js +337 -0
  88. package/geometry/figure-face-grids.js +75 -0
  89. package/geometry/figure-gear.js +446 -0
  90. package/geometry/figure-hair-far.js +151 -0
  91. package/geometry/figure-hair-hangs.js +108 -0
  92. package/geometry/figure-hair-patch.js +66 -0
  93. package/geometry/figure-hair.js +320 -0
  94. package/geometry/figure-hands.js +321 -0
  95. package/geometry/figure-head-features.js +280 -0
  96. package/geometry/figure-head.js +375 -0
  97. package/geometry/figure-headwear.js +223 -0
  98. package/geometry/figure-legs.js +231 -0
  99. package/geometry/figure-limbs.js +39 -0
  100. package/geometry/figure-sculpt.js +82 -0
  101. package/geometry/figure-skin.js +97 -0
  102. package/geometry/figure-skirts.js +303 -0
  103. package/geometry/figure-trunk.js +411 -0
  104. package/geometry/flier-corvid-body.js +322 -0
  105. package/geometry/flier-corvid-wings.js +154 -0
  106. package/geometry/flier-long-body.js +195 -0
  107. package/geometry/flier-shapes.js +219 -0
  108. package/geometry/flier-soaring-bird.js +84 -0
  109. package/geometry/foliage.js +177 -4
  110. package/geometry/fort-city-walls.js +479 -0
  111. package/geometry/fort-gate-approach.js +233 -0
  112. package/geometry/fort-great-walls.js +280 -0
  113. package/geometry/fort-keep.js +297 -0
  114. package/geometry/fort-parts.js +261 -0
  115. package/geometry/fort-polyline.js +261 -0
  116. package/geometry/fort-portal.js +96 -0
  117. package/geometry/fort-ring-wall.js +267 -0
  118. package/geometry/fort-seawall.js +104 -0
  119. package/geometry/fort-terrace-gates.js +323 -0
  120. package/geometry/fort-terrace-plan.js +250 -0
  121. package/geometry/fort-terrace-wall.js +345 -0
  122. package/geometry/garment-tags.js +11 -3
  123. package/geometry/grid-gather.js +69 -0
  124. package/geometry/grid-sample.js +185 -0
  125. package/geometry/hair-gathers.js +19 -4
  126. package/geometry/hair-locks.js +1 -1
  127. package/geometry/hair-patch.js +6 -2
  128. package/geometry/hair-shell.js +14 -2
  129. package/geometry/head-presets.js +103 -0
  130. package/geometry/head-profile.js +13 -2
  131. package/geometry/head-shape.js +51 -23
  132. package/geometry/heightfield.js +26 -9
  133. package/geometry/horizon-angles.js +166 -0
  134. package/geometry/house-kit-body.js +195 -0
  135. package/geometry/house-kit-courtyard-parts.js +340 -0
  136. package/geometry/house-kit-courtyard-roof.js +223 -0
  137. package/geometry/house-kit-courtyard.js +409 -0
  138. package/geometry/house-kit-cut.js +29 -0
  139. package/geometry/house-kit-extras.js +192 -0
  140. package/geometry/house-kit-forms.js +298 -0
  141. package/geometry/house-kit-frame.js +74 -0
  142. package/geometry/house-kit-marks.js +93 -0
  143. package/geometry/house-kit-openings.js +193 -0
  144. package/geometry/house-kit-palette.js +54 -0
  145. package/geometry/house-kit-pool.js +71 -0
  146. package/geometry/house-kit-roofs.js +151 -0
  147. package/geometry/house-kit.js +202 -0
  148. package/geometry/instances.js +4 -4
  149. package/geometry/lamp-wash.js +65 -0
  150. package/geometry/land-clearings.js +83 -0
  151. package/geometry/land-ditches.js +290 -0
  152. package/geometry/land-dry-basin.js +327 -0
  153. package/geometry/land-dunes.js +150 -0
  154. package/geometry/land-earthworks.js +432 -0
  155. package/geometry/land-edge.js +292 -0
  156. package/geometry/land-mound-faces.js +349 -0
  157. package/geometry/land-near-relief.js +102 -0
  158. package/geometry/land-sheet.js +220 -0
  159. package/geometry/land-town-ground.js +256 -0
  160. package/geometry/land-waters.js +228 -0
  161. package/geometry/land-wildness.js +123 -0
  162. package/geometry/lathed-vessel.js +293 -0
  163. package/geometry/outline-grid.js +5 -4
  164. package/geometry/outline-segments.js +74 -0
  165. package/geometry/part-ranges.js +35 -0
  166. package/geometry/path-field.js +35 -1
  167. package/geometry/planked-floor.js +149 -0
  168. package/geometry/plant-broadleaf.js +268 -0
  169. package/geometry/plant-shrub.js +198 -0
  170. package/geometry/plant-tints.js +80 -0
  171. package/geometry/plant-trees.js +453 -0
  172. package/geometry/plant-tussock.js +107 -0
  173. package/geometry/primitives.js +65 -23
  174. package/geometry/prop-battlefield.js +69 -0
  175. package/geometry/prop-camp.js +175 -0
  176. package/geometry/prop-door.js +26 -0
  177. package/geometry/prop-harbour.js +105 -0
  178. package/geometry/prop-haycock.js +60 -0
  179. package/geometry/prop-sacks.js +74 -0
  180. package/geometry/prop-sheaf.js +68 -0
  181. package/geometry/prop-street.js +69 -0
  182. package/geometry/prop-tents.js +396 -0
  183. package/geometry/prop-tombs.js +80 -0
  184. package/geometry/prop-trade.js +393 -0
  185. package/geometry/prop-vehicles.js +218 -0
  186. package/geometry/props.js +58 -0
  187. package/geometry/room-arcade.js +134 -0
  188. package/geometry/room-dome.js +188 -0
  189. package/geometry/room-flames.js +138 -0
  190. package/geometry/room-frame.js +106 -0
  191. package/geometry/room-furniture.js +260 -0
  192. package/geometry/room-hearth.js +98 -0
  193. package/geometry/room-kit.js +59 -0
  194. package/geometry/room-openings.js +142 -0
  195. package/geometry/room-stairs.js +180 -0
  196. package/geometry/room-surfaces.js +272 -0
  197. package/geometry/sampled-surface.js +24 -10
  198. package/geometry/scatter-grid.js +6 -3
  199. package/geometry/sculpt.js +5 -1
  200. package/geometry/ship-fittings.js +350 -0
  201. package/geometry/ship-hull.js +460 -0
  202. package/geometry/ship-kit.js +208 -0
  203. package/geometry/ship-lines.js +69 -0
  204. package/geometry/ship-oars.js +150 -0
  205. package/geometry/ship-presets.js +131 -0
  206. package/geometry/ship-rig.js +374 -0
  207. package/geometry/ship-sails.js +148 -0
  208. package/geometry/shore-grid.js +5 -1
  209. package/geometry/strata-field.js +44 -11
  210. package/geometry/strata-tiles.js +20 -6
  211. package/geometry/stream.js +32 -17
  212. package/geometry/swept-tube.js +124 -0
  213. package/geometry/terrain-chunks.js +139 -51
  214. package/geometry/terrain-extension.js +24 -8
  215. package/geometry/town-courtyard-inn.js +272 -0
  216. package/geometry/town-ground.js +76 -0
  217. package/geometry/town-houses.js +343 -0
  218. package/geometry/town-lights.js +254 -0
  219. package/geometry/town-lots.js +172 -0
  220. package/geometry/town-plan.js +370 -0
  221. package/geometry/town-works.js +465 -0
  222. package/geometry/village-layout.js +181 -0
  223. package/geometry/village-yards.js +167 -0
  224. package/geometry/wall-runs.js +64 -0
  225. package/index.js +134 -3
  226. package/math/cloud-textures.js +3 -7
  227. package/math/curve.js +5 -1
  228. package/math/lamp-texels.js +43 -0
  229. package/math/lit-share.js +22 -0
  230. package/math/mountain-ranges.js +177 -54
  231. package/math/periodic.js +6 -0
  232. package/math/rectangles.js +8 -2
  233. package/math/rock-texture.js +17 -12
  234. package/math/surface-textures.js +24 -9
  235. package/math/wandering-path.js +40 -0
  236. package/math/ways.js +120 -0
  237. package/motion/action-dynamics.js +398 -0
  238. package/motion/animal-bearing.js +247 -0
  239. package/motion/animal-canine-bearing.js +178 -0
  240. package/motion/animal-canine-cast.js +131 -0
  241. package/motion/animal-cattle-cast.js +64 -0
  242. package/motion/animal-herd-cast.js +154 -0
  243. package/motion/animal-horse-still.js +161 -0
  244. package/motion/animal-troop-cast.js +43 -0
  245. package/motion/arm-reach.js +3 -2
  246. package/motion/ballistic-arc.js +182 -2
  247. package/motion/biped-cycle.js +4 -2
  248. package/motion/biped-leg.js +4 -1
  249. package/motion/biped-posture.js +459 -0
  250. package/motion/biped-stride.js +142 -32
  251. package/motion/boat-sailing.js +214 -0
  252. package/motion/contact-transition.js +5 -6
  253. package/motion/crowd-alarms.js +36 -6
  254. package/motion/crowd-attention.js +108 -0
  255. package/motion/crowd-beasts.js +203 -0
  256. package/motion/crowd-camp.js +295 -0
  257. package/motion/crowd-figure.js +100 -0
  258. package/motion/crowd-herd.js +86 -0
  259. package/motion/crowd-hold.js +130 -0
  260. package/motion/crowd-pose.js +296 -0
  261. package/motion/crowd-poses.js +481 -0
  262. package/motion/crowd-routine.js +44 -14
  263. package/motion/crowd-town.js +166 -0
  264. package/motion/crowd-water.js +143 -0
  265. package/motion/deck-surface.js +4 -2
  266. package/motion/figure-acts.js +411 -0
  267. package/motion/figure-arms.js +437 -0
  268. package/motion/figure-blade-slide.js +149 -0
  269. package/motion/figure-body-place.js +180 -0
  270. package/motion/figure-bones.js +118 -0
  271. package/motion/figure-bow-draw.js +70 -0
  272. package/motion/figure-fingers.js +215 -0
  273. package/motion/figure-gaze.js +205 -0
  274. package/motion/figure-gestures.js +452 -0
  275. package/motion/figure-grip.js +134 -0
  276. package/motion/figure-head.js +287 -0
  277. package/motion/figure-legs.js +264 -0
  278. package/motion/figure-links.js +293 -0
  279. package/motion/figure-locomotion.js +391 -0
  280. package/motion/figure-mount-up.js +180 -0
  281. package/motion/figure-mount.js +201 -0
  282. package/motion/figure-pose-frame.js +375 -0
  283. package/motion/figure-pose-table.js +156 -0
  284. package/motion/figure-pose.js +343 -0
  285. package/motion/figure-seat.js +267 -0
  286. package/motion/figure-sway.js +125 -0
  287. package/motion/flier-corvid-pose.js +74 -0
  288. package/motion/flier-flight-air.js +122 -0
  289. package/motion/flier-flight-echelon.js +164 -0
  290. package/motion/flier-flight-roost.js +131 -0
  291. package/motion/flier-swarm-flight.js +252 -0
  292. package/motion/formation.js +193 -0
  293. package/motion/instance-sight.js +8 -1
  294. package/motion/melee-contact.js +143 -0
  295. package/motion/moorings.js +48 -0
  296. package/motion/path-steering.js +358 -0
  297. package/motion/player.js +7 -6
  298. package/motion/quadruped.js +109 -33
  299. package/motion/spaces.js +58 -6
  300. package/motion/speech-cadence.js +304 -0
  301. package/motion/vessel-motion.js +57 -0
  302. package/motion/walk-grid.js +235 -0
  303. package/motion/weather.js +70 -12
  304. package/motion/wind.js +27 -1
  305. package/package.json +27 -4
  306. package/rendering/alpha-mips.js +340 -0
  307. package/rendering/animal-camel-figure.js +29 -0
  308. package/rendering/animal-canine-figure.js +59 -0
  309. package/rendering/animal-cattle-figure.js +36 -0
  310. package/rendering/animal-horse-figure.js +49 -0
  311. package/rendering/atmosphere.js +86 -0
  312. package/rendering/camera-track.js +156 -0
  313. package/rendering/{road-surface.js → cart-track.js} +40 -11
  314. package/rendering/caster-motion.js +2 -1
  315. package/rendering/cell-lod-options.js +46 -0
  316. package/rendering/cell-lod.js +665 -80
  317. package/rendering/cloth-material.js +140 -0
  318. package/rendering/cloud-dome.js +2 -2
  319. package/rendering/compilation-schedule.js +18 -10
  320. package/rendering/contact-shadows.js +5 -2
  321. package/rendering/context.js +47 -8
  322. package/rendering/crowd-batches.js +420 -0
  323. package/rendering/crowd-herd.js +198 -0
  324. package/rendering/crowd-rig.js +132 -0
  325. package/rendering/crowd-skinning.js +52 -9
  326. package/rendering/crowd-update.js +419 -0
  327. package/rendering/crowd-visibility.js +107 -0
  328. package/rendering/day-cycle-defaults.js +200 -0
  329. package/rendering/day-cycle.js +487 -0
  330. package/rendering/daylight.js +1 -3
  331. package/rendering/detail-range.js +6 -5
  332. package/rendering/dof.js +11 -4
  333. package/rendering/effects-frame.js +149 -0
  334. package/rendering/effects-water-rises.js +221 -0
  335. package/rendering/energy-stream.js +128 -0
  336. package/rendering/facade-glass-material.js +105 -0
  337. package/rendering/far-shadow.js +81 -54
  338. package/rendering/field-surface.js +138 -0
  339. package/rendering/figure-shield.js +105 -0
  340. package/rendering/figure-skeleton.js +329 -0
  341. package/rendering/fire-light-watch.js +197 -0
  342. package/rendering/fire-pools.js +148 -0
  343. package/rendering/flame-sources.js +86 -0
  344. package/rendering/flier-bird-looks.js +97 -0
  345. package/rendering/flier-corvid-figure.js +67 -0
  346. package/rendering/flier-long-body-company.js +169 -0
  347. package/rendering/flier-swarm.js +186 -0
  348. package/rendering/flocks.js +6 -2
  349. package/rendering/garment-material.js +145 -49
  350. package/rendering/glsl-literal.js +19 -0
  351. package/rendering/ground-marks.js +316 -0
  352. package/rendering/hair-strands.js +38 -24
  353. package/rendering/height-haze.js +80 -33
  354. package/rendering/height-probe.js +15 -3
  355. package/rendering/house-kit-meshes.js +124 -0
  356. package/rendering/interior-bake.js +807 -0
  357. package/rendering/label-layout.js +13 -3
  358. package/rendering/label-range.js +5 -2
  359. package/rendering/lamp-light-map.js +159 -0
  360. package/rendering/lamp-maps.js +62 -0
  361. package/rendering/lamp-wash.js +51 -0
  362. package/rendering/light-budget.js +19 -3
  363. package/rendering/light-points.js +21 -5
  364. package/rendering/local-lights.js +27 -7
  365. package/rendering/material-lod.js +5 -6
  366. package/rendering/memory-estimate.js +84 -0
  367. package/rendering/moored-fleet.js +186 -0
  368. package/rendering/part-costs.js +104 -0
  369. package/rendering/particle-bursts.js +386 -0
  370. package/rendering/particle-emitters.js +61 -25
  371. package/rendering/particle-light-bursts.js +189 -0
  372. package/rendering/particles.js +134 -34
  373. package/rendering/pen-flocks.js +118 -0
  374. package/rendering/piece-batch.js +282 -6
  375. package/rendering/planar-reflection-options.js +159 -0
  376. package/rendering/planar-reflection.js +780 -77
  377. package/rendering/plant-cells.js +122 -0
  378. package/rendering/plant-reeds.js +113 -0
  379. package/rendering/plant-shade-trees.js +239 -0
  380. package/rendering/plant-tuft-patch.js +122 -0
  381. package/rendering/post-shaders.js +84 -21
  382. package/rendering/post.js +39 -19
  383. package/rendering/pressed-cover.js +135 -0
  384. package/rendering/prop-dig.js +136 -0
  385. package/rendering/room-light.js +250 -0
  386. package/rendering/room-materials.js +78 -0
  387. package/rendering/room-space.js +111 -0
  388. package/rendering/scene-lights.js +106 -0
  389. package/rendering/sea-shaders.js +83 -26
  390. package/rendering/settlement-approach.js +226 -0
  391. package/rendering/settlement-dissolve.js +89 -0
  392. package/rendering/settlement-quarter-warm.js +55 -0
  393. package/rendering/settlement-quarter.js +477 -0
  394. package/rendering/settlement-switch.js +42 -0
  395. package/rendering/settlement-town.js +110 -0
  396. package/rendering/shader-warmup.js +80 -36
  397. package/rendering/shadow-depth.js +40 -18
  398. package/rendering/ship-meshes.js +150 -0
  399. package/rendering/shot-cuts.js +68 -0
  400. package/rendering/sky-occlusion.js +42 -15
  401. package/rendering/sky-pmrem.js +216 -0
  402. package/rendering/sky.js +112 -50
  403. package/rendering/smoke-shadows.js +201 -0
  404. package/rendering/stage-framing.js +182 -0
  405. package/rendering/stage-lights.js +46 -39
  406. package/rendering/stain-material.js +74 -0
  407. package/rendering/static-point-shadow.js +62 -23
  408. package/rendering/still-casters.js +77 -27
  409. package/rendering/strata-material.js +2 -2
  410. package/rendering/street-lamps.js +166 -0
  411. package/rendering/sunbeam-motes.js +670 -0
  412. package/rendering/surface-light.js +65 -6
  413. package/rendering/surface-material.js +306 -0
  414. package/rendering/surface-projection.js +32 -0
  415. package/rendering/surface-snippets.js +314 -0
  416. package/rendering/taa.js +49 -18
  417. package/rendering/tree-impostor.js +929 -0
  418. package/rendering/vehicle-train.js +92 -0
  419. package/rendering/viewport.js +67 -4
  420. package/rendering/water-material.js +270 -82
  421. package/rendering/waypoint-beacons.js +191 -0
  422. package/rendering/world-matrices.js +0 -2
  423. package/ruff.toml +20 -0
  424. package/runtime/cue-cursor.js +21 -0
  425. package/runtime/device-quality.js +13 -2
  426. package/runtime/device.js +73 -0
  427. package/runtime/diagnostic-log.js +11 -3
  428. package/runtime/effect-sites.js +85 -0
  429. package/runtime/figure-orders.js +59 -0
  430. package/runtime/first-use.js +8 -5
  431. package/runtime/foley-script.js +124 -0
  432. package/runtime/foley-strides.js +333 -0
  433. package/runtime/frame-pacing.js +18 -4
  434. package/runtime/frame-yield.js +18 -0
  435. package/runtime/gpu-timing.js +8 -4
  436. package/runtime/grid-cache.js +16 -6
  437. package/runtime/grid-rows.js +5 -5
  438. package/runtime/hand-over.js +7 -2
  439. package/runtime/land-bake.js +78 -0
  440. package/runtime/lazy-sets.js +105 -0
  441. package/runtime/pool.js +17 -3
  442. package/runtime/quality-fit.js +59 -27
  443. package/runtime/region-pass-lay.js +40 -0
  444. package/runtime/region-pass.js +78 -0
  445. package/runtime/search.js +6 -2
  446. package/runtime/settlement-reach.js +42 -0
  447. package/runtime/sound-calls.js +113 -0
  448. package/runtime/sound-impacts.js +297 -0
  449. package/runtime/sound-voices.js +194 -0
  450. package/runtime/soundscape.js +282 -0
  451. package/runtime/spatial-audio.js +69 -20
  452. package/runtime/steady-frames.js +221 -0
  453. package/runtime/withdrawable-task.js +19 -8
  454. package/scripts/app-parts.mjs +118 -0
  455. package/scripts/bake-revisions.mjs +81 -0
  456. package/scripts/browser-scripts.mjs +64 -0
  457. package/scripts/bundle.mjs +192 -0
  458. package/scripts/check-app.sh +26 -0
  459. package/scripts/eslint-config.mjs +119 -0
  460. package/scripts/format.sh +92 -0
  461. package/scripts/keep-builds.mjs +158 -0
  462. package/scripts/layers.mjs +112 -0
  463. package/scripts/lint.sh +49 -0
  464. package/scripts/module-graph.mjs +123 -0
  465. package/scripts/pre-commit.sh +38 -0
  466. package/scripts/serve.py +5 -3
  467. package/scripts/site.mjs +358 -0
  468. package/scripts/test-runner.sh +42 -0
  469. package/scripts/vendor.mjs +221 -0
  470. package/scripts/verify-publish.mjs +175 -0
  471. package/scripts/world.mk +59 -0
  472. package/tools/README.md +73 -0
  473. package/tools/contact-sheet.cjs +137 -0
  474. package/tools/cpu-profile.cjs +275 -0
  475. package/tools/cpu-profile.test.cjs +98 -0
  476. package/tools/first-draws.cjs +395 -0
  477. package/tools/flight-guard.cjs +482 -0
  478. package/tools/flight-guard.test.cjs +153 -0
  479. package/tools/flight-profile.cjs +145 -0
  480. package/tools/frame-bench.cjs +336 -0
  481. package/tools/frame-parts.cjs +365 -0
  482. package/tools/ios-sim.sh +145 -0
  483. package/tools/load-audit.cjs +201 -0
  484. package/tools/look-compare.cjs +304 -0
  485. package/tools/look-guard.cjs +407 -0
  486. package/tools/look-guard.test.cjs +93 -0
  487. package/tools/look-stats.cjs +185 -0
  488. package/tools/look-stats.test.cjs +71 -0
  489. package/tools/memory-audit.cjs +323 -0
  490. package/tools/page-driver.cjs +320 -0
  491. package/tools/page-driver.test.cjs +219 -0
  492. package/tools/program-census-report.cjs +191 -0
  493. package/tools/program-census.cjs +465 -0
  494. package/tools/program-census.test.cjs +332 -0
  495. package/tools/remote-runner.sh +265 -0
  496. package/tools/runners.test.cjs +59 -0
  497. package/tools/scene-audit-beat.cjs +344 -0
  498. package/tools/scene-audit-sheet.cjs +282 -0
  499. package/tools/scene-audit.cjs +471 -0
  500. package/tools/scene-audit.test.cjs +201 -0
  501. package/tools/scene-batch.cjs +219 -0
  502. package/tools/scene-bench.cjs +149 -0
  503. package/tools/scene-bench.test.cjs +33 -0
  504. package/tools/scene-run.cjs +443 -0
  505. package/tools/scene-run.test.cjs +94 -0
  506. package/tools/servers.sh +59 -0
  507. package/tools/shader-arrival.cjs +316 -0
  508. package/tools/shader-renewal.cjs +53 -0
  509. package/tools/shader-renewal.test.cjs +115 -0
  510. package/tools/speed-guard.cjs +258 -0
  511. package/tools/stills.cjs +492 -0
  512. package/tools/stills.test.cjs +49 -0
  513. package/tools/turns.sh +7 -0
  514. package/tools/yaml.cjs +158 -0
  515. package/examples/viaduct.css +0 -75
  516. package/rendering/light-shafts.js +0 -131
@@ -0,0 +1,374 @@
1
+ /**
2
+ * A vessel's rig: masts with their tops, yards square or lateen, her sails (ship-sails.js), shrouds set up with deadeyes at
3
+ * the rail and ratlines where sailors climb, stays, and the running rigging (braces, lifts, sheets) brought down to the rail.
4
+ * Builders: parts.spar, parts.rig (rope), parts.set and parts.furl (the canvas either way). Bow to -z.
5
+ * A lateen yard is drawn in one of three poses (spec.lateenYard, lateenMast): hoisted as she sails, lowered along her as
6
+ * she lies at rest, or apart from her hull in both for a boat that does both (lateenYardParts).
7
+ * @module
8
+ */
9
+ import { dim } from '../math/color.js';
10
+ import { createHash } from '../math/random.js';
11
+ import { clamp, lerp } from '../math/scalar.js';
12
+ import { GB } from './builder.js';
13
+ import { C, TRS, createUnitShapes, stick, without } from './primitives.js';
14
+ import { IRON, TAR } from './ship-hull.js';
15
+ import { shipLines } from './ship-lines.js';
16
+ import { HEMP, SPAR, createShipSails } from './ship-sails.js';
17
+
18
+ const RATLINE_GAP = 0.42; // metres between the rungs of rope a sailor climbs
19
+ // The poses a lateen yard is built in (spec.lateenYard as a boat is built, lateenMast): hoisted at its mast as she sails, the
20
+ // default; stowed, lowered along the boat, for a boat that never sets sail, drawn up on a shore or laid up; apart, left out of
21
+ // her builders for a boat that both sails and lies, to be built of her own in both poses (lateenYardParts).
22
+ const HOISTED = 'hoisted',
23
+ STOWED = 'stowed',
24
+ APART = 'apart';
25
+
26
+ /**
27
+ * Makes the rig builder, with the seeded hash that shades its cloths and the unit shapes its spars and ropes are cut from.
28
+ *
29
+ * @param {object} [options]
30
+ * @param {(x: number, y: number, salt: number) => number} [options.hash] - A seeded hash to [0, 1), as `createHash(seed)` makes.
31
+ * @param {ReturnType<typeof createUnitShapes>} [options.shapes] - Unit shapes, as `createUnitShapes` makes.
32
+ * @returns {{ buildRig: (parts: object, spec: object, lines: object, far?: boolean) => void,
33
+ * lateenYardParts: (spec: object, far?: boolean) => object }} buildRig puts every mast of the spec, its stays and her
34
+ * bowsprit into the parts; lateenYardParts builds a lateen yard apart from her hull in both poses, `{ hoisted, stowed }`,
35
+ * each `{ spar, rig, sail }` as builder arrays (`GB.parts`), null where a pose has none of a kind.
36
+ */
37
+ export function createShipRig({ hash = createHash(), shapes = createUnitShapes() } = {}) {
38
+ const { canvas, clothTone, squareSail, furledSquare, rags } = createShipSails({ hash, shapes }),
39
+ GASKET = without(shapes.cyl6, '+y', '-y'); // a run of a gasket's loop: a rod without its ends, which lie within the next run
40
+
41
+ // Where a rope from aloft is made fast at the rail: a point inside the bulwark at z.
42
+ const railPoint = (lines, side, z) => {
43
+ const zz = clamp(z, -lines.L * 0.92, lines.L * 0.92);
44
+ return [side * lines.inner(zz, lines.top(zz)), lines.top(zz) - 0.05, zz];
45
+ };
46
+
47
+ // Shrouds from under the masthead (or the top) down to the rail either side, each set up by a pair of deadeyes and its
48
+ // lanyard on a channel outside the hull, with ratlines between them where the mast is tall enough to be climbed.
49
+ function shrouds(parts, lines, z, head, count, climb) {
50
+ const { rig, spar, iron } = parts;
51
+ for (const s of [-1, 1]) {
52
+ const feet = [];
53
+ for (let k = 0; k < count; k++) {
54
+ const fz = z - 0.25 + k * 0.6,
55
+ [fx, fy] = railPoint(lines, s, fz),
56
+ x = s * (Math.abs(fx) + 0.22),
57
+ foot = [x, fy + 0.4, fz];
58
+ feet.push(foot);
59
+ stick(rig, foot, [s * 0.3, head, z], 0.022, TAR);
60
+ spar.add(shapes.cyl6, dim(C(SPAR), 0.5), TRS(x, fy + 0.32, fz, 0.2, 0.08, 0.2, 0, 0, Math.PI / 2)); // the upper deadeye
61
+ spar.add(shapes.cyl6, dim(C(SPAR), 0.5), TRS(x, fy - 0.06, fz, 0.2, 0.08, 0.2, 0, 0, Math.PI / 2)); // and the lower
62
+ stick(rig, [x, fy + 0.3, fz], [x, fy, fz], 0.03, HEMP); // the lanyard between them
63
+ iron.add(shapes.box, IRON, TRS(x, fy - 0.7, fz, 0.04, 0.66, 0.06)); // the chain plate down the side
64
+ }
65
+ if (count > 1) {
66
+ const fz0 = z - 0.4,
67
+ fz1 = z - 0.1 + count * 0.6,
68
+ [cx, cy] = railPoint(lines, s, z + count * 0.3);
69
+ spar.box(s * (Math.abs(cx) + 0.12), cy - 0.12, (fz0 + fz1) / 2, 0.32, 0.08, fz1 - fz0, dim(C(SPAR), 0.75)); // the channel
70
+ }
71
+ if (!climb) continue;
72
+ const span = head - feet[0][1];
73
+ for (let h = 0.45; h < span - 0.5; h += RATLINE_GAP) {
74
+ const t = h / span,
75
+ on = f => [lerp(f[0], s * 0.3, t), lerp(f[1], head, t), lerp(f[2], z, t)];
76
+ stick(rig, on(feet[0]), on(feet[count - 1]), 0.009, HEMP);
77
+ }
78
+ }
79
+ }
80
+
81
+ // A square-rigged mast stepped at z: lower mast, a top on trestle-trees (the main with a crow's nest), a topmast, its
82
+ // yards with their sails, braces and lifts, and shrouds.
83
+ function squareMast(parts, spec, lines, m, far) {
84
+ const { spar, rig, set } = parts,
85
+ y0 = lines.deck(m.z),
86
+ tall = m.height > 13,
87
+ topY = y0 + m.height * (tall ? 0.62 : 0.92),
88
+ wood = C(SPAR),
89
+ cloth = C(spec.sail),
90
+ thick = clamp(m.height / 40, 0.16, 0.62);
91
+ spar.add(far ? shapes.cyl6 : shapes.cyl16, wood, TRS(0, y0 - 1.0, m.z, thick, (tall ? m.height * 0.62 : m.height) + 1.0, thick));
92
+ if (tall) {
93
+ spar.add(
94
+ far ? shapes.cyl6 : shapes.cyl16,
95
+ dim(wood, 0.9),
96
+ TRS(0, topY - 0.6, m.z, thick * 0.58, m.height * 0.38 + 0.6, thick * 0.58),
97
+ );
98
+ spar.box(0, topY, m.z, 2.1, 0.09, 1.7, dim(wood, 0.8)); // the top
99
+ }
100
+ m.yards.forEach(([up, halfWidth, drop], n) => {
101
+ const y = y0 + m.height * up,
102
+ z = m.z - thick * 0.7;
103
+ stick(spar, [-halfWidth - 0.35, y, z], [halfWidth + 0.35, y, z], clamp(halfWidth / 30, 0.08, 0.22), wood);
104
+ if (spec.rags) {
105
+ if (!far) rags(parts.furl, [-halfWidth + 0.3, y, z + 0.1], [halfWidth - 0.3, y, z + 0.1], drop, cloth, Math.round(m.z * 3) + n, 9);
106
+ } else {
107
+ squareSail(set, rig, z, y - 0.12, halfWidth, drop, cloth, Math.round(m.z * 3) + n, far);
108
+ furledSquare(parts, z, y, halfWidth, dim(cloth, 0.92), far);
109
+ }
110
+ if (far) return;
111
+ for (const s of [-1, 1]) {
112
+ stick(rig, [s * (halfWidth + 0.3), y, z], railPoint(lines, s, m.z + Math.max(3, m.height * 0.25)), 0.014, HEMP); // a brace
113
+ stick(rig, [s * halfWidth, y, z], [0, y + m.height * 0.12, m.z], 0.012, HEMP); // a lift
114
+ if (!spec.rags) stick(set, [s * halfWidth * 0.95, y - drop, z - 0.25], railPoint(lines, s, m.z + 1.4), 0.016, HEMP); // a sheet, seen while she sails
115
+ }
116
+ });
117
+ if (far) return;
118
+ if (tall) {
119
+ for (const s of [-1, 1]) spar.box(s * 0.5, topY - 0.3, m.z, 0.12, 0.3, 1.5, dim(wood, 0.7)); // the trestle-trees under the top
120
+ if (m.nest) {
121
+ const post = k => [Math.cos((k / 10) * Math.PI * 2) * 0.95, topY + 0.09, m.z + Math.sin((k / 10) * Math.PI * 2) * 0.78];
122
+ for (let k = 0; k < 10; k++) {
123
+ const [px, py, pz] = post(k),
124
+ [qx, , qz] = post(k + 1);
125
+ spar.add(shapes.cyl6, dim(wood, 0.85), TRS(px, py, pz, 0.05, 0.95, 0.05));
126
+ stick(spar, [px, py + 0.95, pz], [qx, py + 0.95, qz], 0.06, dim(wood, 0.75)); // the hoop round the nest
127
+ }
128
+ }
129
+ }
130
+ shrouds(parts, lines, m.z, topY - 0.1, tall ? 5 : 2, m.height > 8);
131
+ pinRail(parts, lines, m.z, y0);
132
+ }
133
+ // A fife rail round the mast's foot with belaying pins, the falls of the halyards coiled on the deck below it.
134
+ function pinRail(parts, lines, z, y0) {
135
+ const { spar, rig } = parts,
136
+ w = Math.min(0.75, lines.inner(z, y0) * 0.5),
137
+ wood = dim(C(SPAR), 0.8);
138
+ for (const s of [-1, 1]) {
139
+ spar.box(s * w, y0, z + 0.55, 0.1, 0.85, 0.1, wood);
140
+ spar.box(s * w, y0, z - 0.55, 0.1, 0.85, 0.1, wood);
141
+ }
142
+ spar.box(0, y0 + 0.8, z + 0.55, w * 2 + 0.2, 0.08, 0.12, wood);
143
+ for (let x = -w + 0.15; x < w; x += 0.22) spar.add(shapes.cyl6, dim(wood, 1.2), TRS(x, y0 + 0.72, z + 0.55, 0.035, 0.26, 0.035));
144
+ for (const s of [-1, 1])
145
+ for (let k = 0; k < 3; k++)
146
+ rig.add(shapes.cyl16, HEMP, TRS(s * w * 0.5, y0 + k * 0.04, z + 1.0, 0.5 - k * 0.06, 0.04, 0.5 - k * 0.06));
147
+ }
148
+
149
+ // Where a lateen mast's head, the sling of its yard, the yard's two ends and the sail's after corner lie.
150
+ function lateenLines(lines, m) {
151
+ const y0 = lines.deck(m.z),
152
+ [len, up, angle] = m.yard,
153
+ head = [0, y0 + m.height, m.z - 0.12 * m.height],
154
+ sling = [0, y0 + m.height * up, m.z - 0.12 * m.height * up],
155
+ dir = [0, Math.sin(angle), Math.cos(angle)],
156
+ tack = [0, sling[1] - dir[1] * len * 0.42, sling[2] - dir[2] * len * 0.42];
157
+ return {
158
+ y0,
159
+ len,
160
+ head,
161
+ sling,
162
+ tack,
163
+ peak: [0, sling[1] + dir[1] * len * 0.58, sling[2] + dir[2] * len * 0.58],
164
+ clew: [0, lines.top(lines.L * 0.6) + 0.35, Math.min(lines.L * 0.78, tack[2] + len * 0.82)],
165
+ };
166
+ }
167
+
168
+ // A lateen sail set, into gb: a sheet of cloths between yard and foot, deeply bellied to leeward (the wind's side is `windward`,
169
+ // +1 starboard), with stitched panel seams, scalloped foot hem, yard lashings, and sheet to the lee rail.
170
+ function lateenSail(gb, spec, lines, m, far, windward) {
171
+ const { len, tack, peak, clew } = lateenLines(lines, m),
172
+ COLS = far ? 2 : 10,
173
+ ROWS = far ? 1 : 6,
174
+ lee = -windward,
175
+ at = (i, j) => {
176
+ const s = i / COLS,
177
+ t = j / ROWS, // along the yard, and down from it toward the foot
178
+ luff = [lerp(tack[0], peak[0], s), lerp(tack[1], peak[1], s), lerp(tack[2], peak[2], s)],
179
+ foot = [lerp(tack[0], clew[0], s), lerp(tack[1], clew[1], s) + 0.16 * Math.sin(s * Math.PI), lerp(tack[2], clew[2], s)],
180
+ belly = Math.sin(s * Math.PI) * Math.sin(t * Math.PI * 0.86) * len * 0.135 * (1 - 0.42 * s);
181
+ return [lerp(luff[0], foot[0], t) + lee * belly, lerp(luff[1], foot[1], t), lerp(luff[2], foot[2], t) - 0.04 * belly];
182
+ };
183
+ canvas(gb, COLS, ROWS, at, (i, j) => {
184
+ const seam = !far && i > 0 && i < COLS && i % 2 === 0 ? 0.88 : 1;
185
+ return dim(clothTone(C(spec.sail), i, j, ROWS, m.z), seam);
186
+ });
187
+ if (!far) {
188
+ for (let i = 0; i < COLS; i++) stick(gb, at(i, ROWS), at(i + 1, ROWS), 0.014, HEMP);
189
+ // Yard robands lashing the luff edge along the sloping lateen yard.
190
+ for (let i = 1; i < COLS; i += 2) {
191
+ const p = at(i, 0);
192
+ stick(gb, p, [0, p[1] + 0.09, p[2]], 0.01, HEMP);
193
+ }
194
+ stick(gb, at(COLS, ROWS), railPoint(lines, lee, lines.L * 0.75), 0.012, HEMP); // the sheet
195
+ }
196
+ }
197
+
198
+ // The point the share t of the way from a to b.
199
+ const between = (a, b, t) => [lerp(a[0], b[0], t), lerp(a[1], b[1], t), lerp(a[2], b[2], t)];
200
+
201
+ // The sail gathered into a bundle along its yard, from a little within `from` to a little short of `to`, hanging just under the
202
+ // spar between those two points of it.
203
+ function furledAlong(furl, from, to, tone, far) {
204
+ const a = between(from, to, 0.07),
205
+ b = between(from, to, 0.9);
206
+ stick(furl, [a[0], a[1] - 0.1, a[2]], [b[0], b[1] - 0.1, b[2]], far ? 0.18 : 0.15, tone, far ? shapes.cyl6 : shapes.cyl);
207
+ }
208
+
209
+ // The hoisted yard's spar: from a little beyond its tack to a little beyond its peak. Its two ends.
210
+ function hoistedYard(spar, lines, m) {
211
+ const { tack, peak } = lateenLines(lines, m),
212
+ from = [0, tack[1], tack[2] - 0.15],
213
+ to = [0, peak[1], peak[2] + 0.2];
214
+ stick(spar, from, to, 0.07, C(SPAR));
215
+ return [from, to];
216
+ }
217
+
218
+ // Its ropes while it is hoisted: the tack lashed at the stem-head, and the halyard's tie from the mast's head to its sling.
219
+ function hoistedRopes(rig, lines, m) {
220
+ const { head, sling, tack } = lateenLines(lines, m);
221
+ stick(rig, tack, [0, lines.top(-lines.L), -lines.L * 0.96], 0.014, HEMP);
222
+ stick(rig, head, sling, 0.02, HEMP);
223
+ }
224
+
225
+ // Where a lateen yard lies once it is lowered along the boat (a boat beached, moored or rowed leaves nothing standing that the
226
+ // wind can take): fore and aft to starboard of the mast, a bundle's breadth clear of it, from a rest on her forward quarters to
227
+ // one abreast her after quarters, rising and falling with her sheer between them; its after end overhangs her stern as far as
228
+ // the yard is longer than that.
229
+ function stowedLines(lines, m, spec) {
230
+ const [len] = m.yard,
231
+ ahead = -lines.L * 0.73,
232
+ abaft = lines.L * 0.73,
233
+ aside = 0.1 + m.height * 0.012 + 0.1, // the mast's thickness at its foot (lateenMast) and a hand's room
234
+ // its axis over a rest: the thickness of the rest and of the spar over an open boat's cap rail, a crutch's height over a deck
235
+ over = z => (spec.open ? lines.top(z) + 0.07 : lines.deck(z) + 0.8) + 0.035,
236
+ heel = [aside, over(ahead), ahead];
237
+ return { aside, heel, after: [aside, over(ahead) + ((over(abaft) - over(ahead)) * len) / (abaft - ahead), ahead + len] };
238
+ }
239
+
240
+ // What the lowered yard lies on at the station z: in an open boat a tab on the cap rail reaching in under it; on a deck, a
241
+ // crutch standing on the deck, its fork under the spar.
242
+ function yardRest(spar, lines, spec, x, z, wood) {
243
+ if (spec.open) {
244
+ const side = lines.frame(z, 1)[0] - 0.07, // her planking's inner face at the rail (the 0.07 her inside leaves)
245
+ from = x - 0.1;
246
+ spar.box((from + side + 0.03) / 2, lines.top(z), z, side + 0.03 - from, 0.07, 0.16, wood);
247
+ return;
248
+ }
249
+ const foot = lines.deck(z);
250
+ stick(spar, [x, foot, z], [x, foot + 0.8, z], 0.05, wood);
251
+ for (const s of [-1, 1]) stick(spar, [x, foot + 0.68, z], [x + s * 0.12, foot + 0.94, z], 0.03, wood);
252
+ }
253
+
254
+ // The yard stowed: the spar lowered along the boat, the sail furled and tied under it; and, near, the two rests it lies on,
255
+ // its gaskets, and its ropes made fast: the halyard from the mast's head to its sling, its heel lashed to the stem-head and its
256
+ // after end guyed to the stern-head.
257
+ function stowedYard(parts, spec, lines, m, far) {
258
+ const { spar, rig, furl } = parts,
259
+ { aside, heel, after } = stowedLines(lines, m, spec),
260
+ wood = C(SPAR);
261
+ stick(spar, heel, after, 0.07, wood);
262
+ furledAlong(furl, heel, after, dim(C(spec.sail), 0.72), far);
263
+ if (far) return;
264
+ for (const z of [heel[2], lines.L * 0.73]) yardRest(spar, lines, spec, aside, z, wood);
265
+ // gaskets round spar and sail, a loop over the spar, down each side and under the bundle, of rod without its ends (hidden
266
+ // where each run meets the next)
267
+ const loop = [
268
+ [0, 0.05],
269
+ [-0.12, -0.06],
270
+ [0, -0.2],
271
+ [0.12, -0.06],
272
+ ],
273
+ len = m.yard[0];
274
+ for (let d = 0.8; d < len - 0.8; d += 0.85) {
275
+ const p = between(heel, after, d / len);
276
+ for (let k = 0; k < loop.length; k++)
277
+ stick(
278
+ rig,
279
+ [p[0] + loop[k][0], p[1] + loop[k][1], p[2]],
280
+ [p[0] + loop[(k + 1) % 4][0], p[1] + loop[(k + 1) % 4][1], p[2]],
281
+ 0.012,
282
+ HEMP,
283
+ GASKET,
284
+ );
285
+ }
286
+ stick(rig, lateenLines(lines, m).head, between(heel, after, 0.42), 0.02, HEMP); // the halyard, to the yard's sling
287
+ stick(rig, heel, [0, lines.top(-lines.L), -lines.L * 0.96], 0.012, HEMP); // its heel lashed to the stem-head
288
+ stick(rig, after, [0, lines.top(lines.L), lines.L * 0.98], 0.014, HEMP); // its after end guyed to the stern-head
289
+ }
290
+
291
+ // A lateen mast: a short pole raked forward and its long yard in one of the three poses. Hoisted, the yard is slung near the
292
+ // mast's head, its tack low by the stem and its peak high aft; her sail under it is set (the wind on her port side;
293
+ // `parts.setOther`, if given, takes it set with the wind on her starboard side, for a boat that goes about), in rags
294
+ // (`spec.rags`), or furled along the yard. Stowed, the yard lies along the boat with the sail furled under it. Apart, only her
295
+ // set sails are drawn here: the yard in both poses is built of her own (lateenYardParts). Her shrouds, a side, always.
296
+ function lateenMast(parts, spec, lines, m, far) {
297
+ const { spar, rig, set, setOther, furl } = parts,
298
+ { y0, len, head, tack, peak } = lateenLines(lines, m),
299
+ pose = spec.lateenYard ?? HOISTED,
300
+ cloth = C(spec.sail);
301
+ stick(spar, [0, y0 - 0.3, m.z], head, 0.1 + m.height * 0.012, C(SPAR), far ? shapes.cyl6 : shapes.taper);
302
+ if (pose === STOWED) stowedYard(parts, spec, lines, m, far);
303
+ else {
304
+ // her sail under the yard as she carries it at sea: set from either side, or left hanging in rags
305
+ if (spec.rags) {
306
+ if (!far) rags(furl, tack, peak, len * 0.25, cloth, Math.round(m.z), 7);
307
+ } else {
308
+ lateenSail(set, spec, lines, m, far, -1);
309
+ if (setOther) lateenSail(setOther, spec, lines, m, far, 1);
310
+ }
311
+ // the yard of the hull itself, and what belongs to it alone: its sail furled along it, and its two ropes
312
+ if (pose === HOISTED) {
313
+ const [from, to] = hoistedYard(spar, lines, m);
314
+ if (!spec.rags) furledAlong(furl, from, to, dim(cloth, 0.72), far);
315
+ if (!far) hoistedRopes(rig, lines, m);
316
+ }
317
+ }
318
+ if (far) return;
319
+ stick(rig, head, railPoint(lines, 1, m.z + 0.9), 0.014, TAR); // a shroud a side
320
+ stick(rig, head, railPoint(lines, -1, m.z + 0.9), 0.014, TAR);
321
+ }
322
+
323
+ // A lateen boat's yard apart from her hull, as arrays for the page to mesh (rendering/ship-meshes.js): `hoisted` (the spar and its two ropes,
324
+ // shown while she sails) and `stowed` (the spar, its rests, gaskets and ropes, and the sail furled under it, shown while she
325
+ // lies), each { spar, rig, sail }, a null where a pose has none of a kind. Every lateen mast of the spec.
326
+ function lateenYardParts(spec, far = false) {
327
+ const lines = shipLines(spec),
328
+ apart = { hoisted: { spar: new GB(), rig: new GB(), sail: null }, stowed: { spar: new GB(), rig: new GB(), sail: new GB() } };
329
+ for (const m of spec.masts ?? []) {
330
+ if (m.rig !== 'lateen') continue;
331
+ hoistedYard(apart.hoisted.spar, lines, m);
332
+ if (!far) hoistedRopes(apart.hoisted.rig, lines, m);
333
+ stowedYard({ spar: apart.stowed.spar, rig: apart.stowed.rig, furl: apart.stowed.sail }, spec, lines, m, far);
334
+ }
335
+ const arrays = gb => (gb?.count ? gb.parts(!gb.wide) : null);
336
+ for (const pose of Object.values(apart)) for (const kind of ['spar', 'rig', 'sail']) pose[kind] = arrays(pose[kind]);
337
+ return apart;
338
+ }
339
+
340
+ // A bowsprit run out over the stem, and the stay from the foremast to its end.
341
+ function bowsprit(parts, spec, lines) {
342
+ const { L } = lines,
343
+ bow = lines.deck(-L + 1) + 0.5,
344
+ end = [0, bow + L * 0.2, -L - L * 0.42];
345
+ stick(parts.spar, [0, bow, -L + 2.4], end, clamp(L / 100, 0.08, 0.17), C(SPAR));
346
+ stick(parts.rig, end, [0, lines.keel(-L) * 0.2 + 0.4, -L - 0.2 - (spec.rake?.[0] ?? 0) * L], 0.02, TAR); // the bobstay
347
+ const fore = spec.masts[0];
348
+ stick(parts.rig, [0, lines.deck(fore.z) + fore.height * 0.62, fore.z], end, 0.022, TAR); // the forestay
349
+ }
350
+
351
+ // Every mast of a spec, its stays fore and aft, and the bowsprit where she has one.
352
+ function buildRig(parts, spec, lines, far = false) {
353
+ for (const m of spec.masts ?? []) {
354
+ if (m.rig === 'lateen') lateenMast(parts, spec, lines, m, far);
355
+ else squareMast(parts, spec, lines, m, far);
356
+ }
357
+ if (far || !spec.masts) return;
358
+ const { L } = lines;
359
+ spec.masts.forEach((m, i) => {
360
+ if (m.rig === 'lateen') return;
361
+ const head = lines.deck(m.z) + m.height * (m.height > 13 ? 0.62 : 0.92),
362
+ ahead = spec.masts[i - 1];
363
+ if (ahead)
364
+ stick(parts.rig, [0, head, m.z], [0, lines.deck(ahead.z) + 1.2, ahead.z], 0.02, TAR); // a stay to the foot of the mast ahead
365
+ else if (!(spec.gear ?? []).includes('bowsprit')) stick(parts.rig, [0, head, m.z], [0, lines.top(-L) + 0.2, -L * 0.98], 0.02, TAR); // the forestay
366
+ stick(parts.rig, [0, lines.deck(m.z) + m.height, m.z], railPoint(lines, 0, clamp(m.z + m.height * 0.5, -L, L - 0.4)), 0.016, TAR); // the backstay
367
+ });
368
+ if ((spec.gear ?? []).includes('bowsprit')) bowsprit(parts, spec, lines);
369
+ }
370
+
371
+ return { buildRig, lateenYardParts };
372
+ }
373
+
374
+ export { APART as YARD_APART, HOISTED as YARD_HOISTED, STOWED as YARD_STOWED };
@@ -0,0 +1,148 @@
1
+ /**
2
+ * A vessel's canvas: square sails set (bellied by a following wind, cloths sewn side by side, patched, reefed) and furled
3
+ * on their yards, a sail's cloth shaded cell by cell, and the rags left of a sail that has rotted on its yard. Used by the
4
+ * rig (ship-rig.js). Bow to -z.
5
+ * @module
6
+ */
7
+ import { dim } from '../math/color.js';
8
+ import { createHash } from '../math/random.js';
9
+ import { lerp } from '../math/scalar.js';
10
+ import { catenaryCanvas } from './catenary-canvas.js';
11
+ import { createUnitShapes, stick } from './primitives.js';
12
+ import { sampleSurface as surf } from './sampled-surface.js';
13
+
14
+ const HEMP = [0.36, 0.3, 0.2],
15
+ SPAR = 0x7d6850; // oiled fir, greyed by the weather
16
+ const mix = (a, b, t) => [lerp(a[0], b[0], t), lerp(a[1], b[1], t), lerp(a[2], b[2], t)];
17
+
18
+ /**
19
+ * Makes the sail builders, with the seeded hash that shades and patches the cloths and the unit shapes of a furled sail.
20
+ *
21
+ * @param {object} [options]
22
+ * @param {(x: number, y: number, salt: number) => number} [options.hash] - A seeded hash to [0, 1), as `createHash(seed)` makes.
23
+ * @param {ReturnType<typeof createUnitShapes>} [options.shapes] - Unit shapes, as `createUnitShapes` makes.
24
+ * @returns {{ canvas: Function, clothTone: Function, squareSail: Function, furledSquare: Function, rags: Function }} canvas(gb,
25
+ * cols, rows, at(i, j), colour(i, j)) a sheet seen from both sides; clothTone(tone, i, j, rows, seed) a cloth's shade;
26
+ * squareSail(gb, rig, z, y, halfWidth, drop, tone, seed, far) a square sail set from its yard; furledSquare(parts, z, y,
27
+ * halfWidth, tone, far) one furled on top of it; rags(gb, from, to, longest, tone, seed, strips) strips of a rotted sail.
28
+ */
29
+ export function createShipSails({ hash = createHash(), shapes = createUnitShapes() } = {}) {
30
+ // A sail's cloth: the sheet at(i, j) on a grid of cols x rows, smoothly shaded and seen from both sides, each cell coloured.
31
+ function canvas(gb, cols, rows, at, colour) {
32
+ surf(
33
+ gb,
34
+ cols,
35
+ rows,
36
+ (u, v) => at(Math.round(u * cols), Math.round(v * rows)),
37
+ (u, v) => colour(Math.floor(u * cols), Math.floor(v * rows)),
38
+ {
39
+ back: true,
40
+ },
41
+ );
42
+ }
43
+ // A cloth's shade: sewn in vertical cloths each a little different, darker toward the foot, a patch here and there.
44
+ const clothTone = (tone, i, j, rows, seed) =>
45
+ dim(hash(i + seed * 5, j, 216) < 0.04 ? mix(tone, [0.3, 0.26, 0.2], 0.3) : tone, 0.93 + 0.08 * hash(i, seed, 217) - 0.05 * (j / rows));
46
+
47
+ // A square sail set from a yard at height y on a mast at z: catenary-bellied by a following wind, leeches scalloped,
48
+ // vertical cloths stitched with seam darkening, reef bands sewn, and head robands lashed to the yard.
49
+ function squareSail(gb, rig, z, y, halfWidth, drop, tone, seed, far) {
50
+ const cols = far ? 2 : 12,
51
+ rows = far ? 2 : 8,
52
+ footHalfWidth = halfWidth * 0.96,
53
+ sailZ = z - 0.25,
54
+ corners = [
55
+ [-halfWidth, y, sailZ],
56
+ [halfWidth, y, sailZ],
57
+ [footHalfWidth, y - drop, sailZ],
58
+ [-footHalfWidth, y - drop, sailZ],
59
+ ];
60
+ catenaryCanvas(gb, corners, {
61
+ columns: cols,
62
+ rows,
63
+ sag: far ? 0 : 0.02 * drop,
64
+ edgeSagU: 0.15,
65
+ edgeSagV: 0.05,
66
+ belly: drop * 0.27,
67
+ bellyDir: [0, 0, -1],
68
+ scallopU: far ? 0 : halfWidth * 0.085,
69
+ scallopV: far ? 0 : drop * 0.065,
70
+ panelsU: far ? 1 : 6,
71
+ seamDarken: far ? 0 : 0.15,
72
+ panelVariation: far ? 0 : 0.055,
73
+ hemDarken: 0.09,
74
+ reefBands: !far && drop > 2.2 ? [0.25, 0.5] : null,
75
+ reefDarken: 0.13,
76
+ seed,
77
+ color: tone,
78
+ back: true,
79
+ });
80
+ if (far || !rig) return;
81
+ const edgePoint = (u, v) => {
82
+ const hw = lerp(halfWidth, footHalfWidth, v);
83
+ const pullU = halfWidth * 0.085 * Math.abs(Math.sin(v * Math.PI));
84
+ const pullV = drop * 0.065 * Math.abs(Math.sin(u * Math.PI)) * v;
85
+ const puff = drop * 0.27 * Math.sin(u * Math.PI) * Math.sin(Math.min(1, v * 1.12) * Math.PI * 0.78);
86
+ const x = lerp(-hw, hw, u) + pullU * (1 - 2 * u);
87
+ const py = y - v * drop + pullV - 0.02 * drop * Math.sin(u * Math.PI) * (Math.sin(v * Math.PI) + 0.15 * (1 - Math.sin(v * Math.PI)));
88
+ return [x, py, sailZ - puff];
89
+ };
90
+ // Bolt-rope hems down both curved leeches and along the arched foot roach.
91
+ for (let j = 0; j < rows; j++) {
92
+ const v0 = j / rows,
93
+ v1 = (j + 1) / rows;
94
+ stick(gb, edgePoint(0, v0), edgePoint(0, v1), 0.016, HEMP);
95
+ stick(gb, edgePoint(1, v0), edgePoint(1, v1), 0.016, HEMP);
96
+ }
97
+ for (let i = 0; i < cols; i++) {
98
+ stick(gb, edgePoint(i / cols, 1), edgePoint((i + 1) / cols, 1), 0.015, HEMP);
99
+ }
100
+ // Rope robands lashing the head of the sail up to the yard spar.
101
+ const lashingCount = Math.max(4, Math.min(10, Math.round(halfWidth * 1.4)));
102
+ for (let i = 0; i <= lashingCount; i++) {
103
+ const u = i / lashingCount,
104
+ lx = lerp(-halfWidth * 0.96, halfWidth * 0.96, u);
105
+ stick(rig, [lx, y + 0.02, sailZ], [lx, y + 0.14, z], 0.011, HEMP);
106
+ }
107
+ if (drop > 2.2) {
108
+ for (let i = 1; i < cols; i += 2) {
109
+ const p = edgePoint(i / cols, 0.25);
110
+ stick(gb, p, [p[0], p[1] - 0.28, p[2] - 0.06], 0.009, HEMP);
111
+ }
112
+ }
113
+ }
114
+ // The same sail gathered up on top of its yard, tied with gaskets.
115
+ function furledSquare(parts, z, y, halfWidth, tone, far) {
116
+ stick(parts.furl, [-halfWidth, y + 0.05, z], [halfWidth, y + 0.05, z], far ? 0.4 : 0.36, tone, far ? shapes.cyl6 : shapes.cyl);
117
+ if (far) return;
118
+ for (let x = -halfWidth + 0.5; x < halfWidth; x += 1.0) stick(parts.rig, [x, y - 0.14, z], [x, y + 0.28, z], 0.4, HEMP, shapes.cyl6);
119
+ }
120
+
121
+ // What is left of a sail that has rotted on its yard: strips of cloth from `from` to `to` (two points along the yard), each
122
+ // hanging its own length and stirring a little, into the furled canvas (a ship in rags has no other).
123
+ function rags(gb, from, to, longest, tone, seed, strips) {
124
+ for (let k = 0; k < strips; k++) {
125
+ const t0 = (k + 0.1) / strips,
126
+ t1 = (k + 0.9) / strips,
127
+ hang = longest * (0.25 + 0.75 * hash(k, seed, 985)),
128
+ cut = 0.35 * hash(k, seed + 3, 987), // how much narrower its torn foot is
129
+ grey = dim(tone, 0.7 + 0.5 * hash(k, seed, 986)),
130
+ along = t => [lerp(from[0], to[0], t), lerp(from[1], to[1], t) - 0.1, lerp(from[2], to[2], t)];
131
+ surf(
132
+ gb,
133
+ 2,
134
+ 6,
135
+ (u, v) => {
136
+ const [x, y, z] = along(lerp(t0, t1, 0.5 + (u - 0.5) * (1 - cut * v)));
137
+ return [x + Math.sin(v * 3 + k) * 0.15 * v, y - v * hang, z + Math.sin(v * 3 + k) * 0.18 * v + 0.4 * v * v];
138
+ },
139
+ grey,
140
+ { back: dim(grey, 0.75) },
141
+ );
142
+ }
143
+ }
144
+
145
+ return { canvas, clothTone, squareSail, furledSquare, rags };
146
+ }
147
+
148
+ export { HEMP, SPAR };
@@ -103,7 +103,11 @@ export function createShoreGrid() {
103
103
  columnFraction = u - column,
104
104
  rowFraction = v - row,
105
105
  gridIndex = row * pointsPerSide + column;
106
- return lerp(lerp(grid[gridIndex], grid[gridIndex + 1], columnFraction), lerp(grid[gridIndex + pointsPerSide], grid[gridIndex + pointsPerSide + 1], columnFraction), rowFraction);
106
+ return lerp(
107
+ lerp(grid[gridIndex], grid[gridIndex + 1], columnFraction),
108
+ lerp(grid[gridIndex + pointsPerSide], grid[gridIndex + pointsPerSide + 1], columnFraction),
109
+ rowFraction,
110
+ );
107
111
  }
108
112
 
109
113
  return { bakeShore, layOutShore, shoreDistance, shoreGrid };
@@ -3,11 +3,40 @@ import { createNoise } from '../math/noise.js';
3
3
  import { createHash, mulberry32 } from '../math/random.js';
4
4
  import { SRGB2LIN } from '../math/color.js';
5
5
 
6
- // Heightfields are square and centred on the origin. All lengths and elevations are metres.
6
+ /**
7
+ * Bedded rock for the cliffs of a square heightfield centred on the origin: where cliffs stand, and the face, ledge, joints and
8
+ * relief of each point of their meshes. All lengths and elevations are metres.
9
+ *
10
+ * @param {object} options
11
+ * @param {number} [options.seed=0] Seed of the beds, joints and relief.
12
+ * @param {number} options.cells Cells along each side of the heightfield.
13
+ * @param {number} options.spacing Metres between its samples.
14
+ * @param {number[]} [options.levels=[0.5, 1, 2]] Grid spacing of each level of detail, finest first, in metres.
15
+ * @param {[number, number]} [options.slopeRange=[0.8, 1.08]] Exposure (rise over run) at which rock begins, and is whole.
16
+ * @param {[number, number]} [options.bedRange=[-80, 460]] Elevations the beds are laid between.
17
+ * @param {[number, number]} [options.dip=[0, 0]] How the beds tilt: metres they rise for each metre along +X and along +Z.
18
+ * @param {{ height: number, width: number }} [options.fold={ height: 18, width: 240 }] How far the beds are folded up and down,
19
+ * and over what width.
20
+ * @param {{ blocks: number, blocksSpread: number, beds: number, chips: number }} [options.joints] Sizes of the joints' cells:
21
+ * the large blocks through many beds (`blocks`, larger by up to `blocksSpread` in some bands), the blocks that change from bed
22
+ * to bed, and the chips broken off their faces at the finest level. Defaults: 7.5, 3, 3.1 and 1.25.
23
+ */
7
24
  // Exposure is the caller's rise/run attenuated to zero wherever rock must be excluded.
8
- export function createStrataField({ seed = 0, cells, spacing, levels = [0.5, 1, 2], slopeRange = [0.8, 1.08], bedRange = [-80, 460] }) {
9
- const stride = cells + 1, half = cells * spacing / 2;
10
- const { fbm, vnoise } = createNoise(seed), hash2 = createHash(seed);
25
+ export function createStrataField({
26
+ seed = 0,
27
+ cells,
28
+ spacing,
29
+ levels = [0.5, 1, 2],
30
+ slopeRange = [0.8, 1.08],
31
+ bedRange = [-80, 460],
32
+ dip = [0, 0],
33
+ fold = { height: 18, width: 240 },
34
+ joints: jointSizes = { blocks: 7.5, blocksSpread: 3, beds: 3.1, chips: 1.25 },
35
+ }) {
36
+ const stride = cells + 1,
37
+ half = (cells * spacing) / 2;
38
+ const { fbm, vnoise } = createNoise(seed),
39
+ hash2 = createHash(seed);
11
40
  let heights, colours;
12
41
  function setGround(input) {
13
42
  heights = input.heights;
@@ -185,7 +214,9 @@ export function createStrataField({ seed = 0, cells, spacing, levels = [0.5, 1,
185
214
  nearRight = heights[k + 1],
186
215
  farLeft = heights[k + stride],
187
216
  farRight = heights[k + stride + 1];
188
- return tx + tz <= 1 ? nearLeft + (nearRight - nearLeft) * tx + (farLeft - nearLeft) * tz : farRight + (farLeft - farRight) * (1 - tx) + (nearRight - farRight) * (1 - tz);
217
+ return tx + tz <= 1
218
+ ? nearLeft + (nearRight - nearLeft) * tx + (farLeft - nearLeft) * tz
219
+ : farRight + (farLeft - farRight) * (1 - tx) + (nearRight - farRight) * (1 - tz);
189
220
  }
190
221
  function cliffMask(x, z) {
191
222
  return mask ? bilerp(mask, locate(x, z), 1, 0) : 0;
@@ -256,7 +287,7 @@ export function createStrataField({ seed = 0, cells, spacing, levels = [0.5, 1,
256
287
  nz /= nl;
257
288
  const h = meshHeight(x, z),
258
289
  gridSpacing = levels[levelIndex];
259
- const yy = h + 0.045 * x - 0.022 * z + 18 * (fbm(x / 240, z / 240, 3, 533) - 0.5); // beds dip gently to the east and are folded a little
290
+ const yy = h + dip[0] * x + dip[1] * z + fold.height * (fbm(x / fold.width, z / fold.width, 3, 533) - 0.5); // the beds dip and fold
260
291
  const bed = bedAt(yy),
261
292
  hard = clamp(bedProfile.hard[bed] + (bd - 0.5) * 0.3, 0, 1),
262
293
  bedThickness = bedProfile.thick[bed],
@@ -278,24 +309,26 @@ export function createStrataField({ seed = 0, cells, spacing, levels = [0.5, 1,
278
309
  const dhx = upper ? heights[k + stride + 1] - heights[k + stride] : heights[k + 1] - heights[k];
279
310
  const dhz = upper ? heights[k + stride + 1] - heights[k + 1] : heights[k + stride] - heights[k];
280
311
  const rise = Math.max((Math.abs(dhx) + Math.abs(dhz)) / spacing, 0.5);
281
- const sampleRise = gridSpacing * rise, resolved = sstep(4, 9, bedThickness / sampleRise);
312
+ const sampleRise = gridSpacing * rise,
313
+ resolved = sstep(4, 9, bedThickness / sampleRise);
282
314
  const edgeFade = sstep(0, sampleRise * 1.5, bedThickness * Math.min(u, 1 - u));
283
315
  const ra = u / f,
284
316
  rb = (1 - u) / (1 - f),
285
317
  tri = Math.max(0, (ra + rb - Math.sqrt((ra - rb) ** 2 + 0.06)) * 0.5); // the lip of each face worn round
286
318
  const ds = A * tri * resolved;
287
319
  // joints: large blocks through many beds, smaller ones that change from bed to bed, and the chips broken off their faces
288
- joints(x, z, 7.5 + 3 * bd, 540, 1.0);
320
+ joints(x, z, jointSizes.blocks + jointSizes.blocksSpread * bd, 540, 1.0);
289
321
  let dj = jnt.off;
290
322
  const e1 = jnt.edge;
291
- joints(x + bed * 1.7, z - bed * 2.3, 3.1, 560 + bed, 0.5);
323
+ joints(x + bed * 1.7, z - bed * 2.3, jointSizes.beds, 560 + bed, 0.5);
292
324
  dj += jnt.off * (levelIndex === 0 ? 1 : levelIndex === 1 ? 0.5 : 0) * resolved * edgeFade;
293
325
  const e2 = jnt.edge;
294
326
  if (levelIndex === 0) {
295
- joints(x - bed * 0.7, z + bed * 1.3, 1.25, 580 + bed, 0.2);
327
+ joints(x - bed * 0.7, z + bed * 1.3, jointSizes.chips, 580 + bed, 0.2);
296
328
  dj += jnt.off * resolved * edgeFade;
297
329
  }
298
- const groove = 0.6 * sstep(0.9, 0, e1) * (levelIndex === 2 ? 0 : 1) + 0.3 * sstep(0.45, 0, e2) * (levelIndex === 0 ? 1 : 0) * resolved * edgeFade;
330
+ const groove =
331
+ 0.6 * sstep(0.9, 0, e1) * (levelIndex === 2 ? 0 : 1) + 0.3 * sstep(0.45, 0, e2) * (levelIndex === 0 ? 1 : 0) * resolved * edgeFade;
299
332
  dj = Math.max(dj - groove, 0);
300
333
  // relief: broad buttresses and bays, and creased (not rounded) swells at a few metres
301
334
  let dn = 1.0 * fbm(x / 31, z / 31, 3, 520) + 0.5 * vnoise((x + z) / 47, yy / 19, 521);