roamwright 0.4.0 → 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 (549) hide show
  1. package/.prettierrc.yaml +12 -0
  2. package/CONTRIBUTING.md +21 -14
  3. package/README.md +38 -42
  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/bedding.js +141 -0
  67. package/geometry/builder-cells.js +50 -0
  68. package/geometry/builder-frame.js +48 -0
  69. package/geometry/builder.js +200 -177
  70. package/geometry/card-emblem.js +437 -0
  71. package/geometry/catenary-canvas.js +396 -0
  72. package/geometry/cell-mask.js +25 -0
  73. package/geometry/cloth-folds.js +143 -0
  74. package/geometry/crawl-shapes.js +71 -0
  75. package/geometry/creased-sheet.js +40 -35
  76. package/geometry/crowd-dress.js +315 -0
  77. package/geometry/crowd-far.js +174 -0
  78. package/geometry/crowd-look.js +42 -0
  79. package/geometry/crowd-weld.js +218 -0
  80. package/geometry/ear.js +44 -39
  81. package/geometry/erosion.js +71 -45
  82. package/geometry/face-grid.js +85 -65
  83. package/geometry/field-map.js +59 -0
  84. package/geometry/figure-arms.js +339 -0
  85. package/geometry/figure-beard.js +250 -0
  86. package/geometry/figure-body.js +297 -0
  87. package/geometry/figure-bow.js +105 -0
  88. package/geometry/figure-cloak.js +189 -0
  89. package/geometry/figure-clothes.js +337 -0
  90. package/geometry/figure-face-grids.js +75 -0
  91. package/geometry/figure-gear.js +446 -0
  92. package/geometry/figure-hair-far.js +151 -0
  93. package/geometry/figure-hair-hangs.js +108 -0
  94. package/geometry/figure-hair-patch.js +66 -0
  95. package/geometry/figure-hair.js +320 -0
  96. package/geometry/figure-hands.js +321 -0
  97. package/geometry/figure-head-features.js +280 -0
  98. package/geometry/figure-head.js +375 -0
  99. package/geometry/figure-headwear.js +223 -0
  100. package/geometry/figure-legs.js +231 -0
  101. package/geometry/figure-limbs.js +39 -0
  102. package/geometry/figure-sculpt.js +82 -0
  103. package/geometry/figure-skin.js +97 -0
  104. package/geometry/figure-skirts.js +303 -0
  105. package/geometry/figure-trunk.js +411 -0
  106. package/geometry/flier-corvid-body.js +322 -0
  107. package/geometry/flier-corvid-wings.js +154 -0
  108. package/geometry/flier-long-body.js +195 -0
  109. package/geometry/flier-shapes.js +219 -0
  110. package/geometry/flier-soaring-bird.js +84 -0
  111. package/geometry/foliage.js +187 -14
  112. package/geometry/fort-city-walls.js +479 -0
  113. package/geometry/fort-gate-approach.js +233 -0
  114. package/geometry/fort-great-walls.js +280 -0
  115. package/geometry/fort-keep.js +297 -0
  116. package/geometry/fort-parts.js +261 -0
  117. package/geometry/fort-polyline.js +261 -0
  118. package/geometry/fort-portal.js +96 -0
  119. package/geometry/fort-ring-wall.js +267 -0
  120. package/geometry/fort-seawall.js +104 -0
  121. package/geometry/fort-terrace-gates.js +323 -0
  122. package/geometry/fort-terrace-plan.js +250 -0
  123. package/geometry/fort-terrace-wall.js +345 -0
  124. package/geometry/garment-tags.js +11 -3
  125. package/geometry/grid-gather.js +69 -0
  126. package/geometry/grid-sample.js +185 -0
  127. package/geometry/hair-gathers.js +57 -42
  128. package/geometry/hair-locks.js +42 -42
  129. package/geometry/hair-patch.js +24 -20
  130. package/geometry/hair-shell.js +43 -31
  131. package/geometry/head-presets.js +103 -0
  132. package/geometry/head-profile.js +26 -15
  133. package/geometry/head-shape.js +123 -95
  134. package/geometry/heightfield.js +50 -24
  135. package/geometry/horizon-angles.js +166 -0
  136. package/geometry/house-kit-body.js +195 -0
  137. package/geometry/house-kit-courtyard-parts.js +340 -0
  138. package/geometry/house-kit-courtyard-roof.js +223 -0
  139. package/geometry/house-kit-courtyard.js +409 -0
  140. package/geometry/house-kit-cut.js +29 -0
  141. package/geometry/house-kit-extras.js +192 -0
  142. package/geometry/house-kit-forms.js +298 -0
  143. package/geometry/house-kit-frame.js +74 -0
  144. package/geometry/house-kit-marks.js +93 -0
  145. package/geometry/house-kit-openings.js +193 -0
  146. package/geometry/house-kit-palette.js +54 -0
  147. package/geometry/house-kit-pool.js +71 -0
  148. package/geometry/house-kit-roofs.js +151 -0
  149. package/geometry/house-kit.js +202 -0
  150. package/geometry/index-parts.js +2 -2
  151. package/geometry/instance-visibility.js +12 -12
  152. package/geometry/instances.js +17 -17
  153. package/geometry/lamp-wash.js +65 -0
  154. package/geometry/land-clearings.js +83 -0
  155. package/geometry/land-ditches.js +290 -0
  156. package/geometry/land-dry-basin.js +327 -0
  157. package/geometry/land-dunes.js +150 -0
  158. package/geometry/land-earthworks.js +432 -0
  159. package/geometry/land-edge.js +292 -0
  160. package/geometry/land-mound-faces.js +349 -0
  161. package/geometry/land-near-relief.js +102 -0
  162. package/geometry/land-sheet.js +220 -0
  163. package/geometry/land-town-ground.js +256 -0
  164. package/geometry/land-waters.js +228 -0
  165. package/geometry/land-wildness.js +123 -0
  166. package/geometry/lathed-vessel.js +293 -0
  167. package/geometry/outline-grid.js +11 -10
  168. package/geometry/outline-segments.js +74 -0
  169. package/geometry/part-ranges.js +38 -3
  170. package/geometry/path-field.js +98 -34
  171. package/geometry/placement.js +52 -52
  172. package/geometry/planked-floor.js +149 -0
  173. package/geometry/plant-broadleaf.js +268 -0
  174. package/geometry/plant-shrub.js +198 -0
  175. package/geometry/plant-tints.js +80 -0
  176. package/geometry/plant-trees.js +453 -0
  177. package/geometry/plant-tussock.js +107 -0
  178. package/geometry/point-buckets.js +50 -0
  179. package/geometry/primitives.js +117 -59
  180. package/geometry/prop-battlefield.js +69 -0
  181. package/geometry/prop-camp.js +175 -0
  182. package/geometry/prop-door.js +26 -0
  183. package/geometry/prop-harbour.js +105 -0
  184. package/geometry/prop-haycock.js +60 -0
  185. package/geometry/prop-sacks.js +74 -0
  186. package/geometry/prop-sheaf.js +68 -0
  187. package/geometry/prop-street.js +69 -0
  188. package/geometry/prop-tents.js +396 -0
  189. package/geometry/prop-tombs.js +80 -0
  190. package/geometry/prop-trade.js +393 -0
  191. package/geometry/prop-vehicles.js +218 -0
  192. package/geometry/props.js +58 -0
  193. package/geometry/room-arcade.js +134 -0
  194. package/geometry/room-dome.js +188 -0
  195. package/geometry/room-flames.js +138 -0
  196. package/geometry/room-frame.js +106 -0
  197. package/geometry/room-furniture.js +260 -0
  198. package/geometry/room-hearth.js +98 -0
  199. package/geometry/room-kit.js +59 -0
  200. package/geometry/room-openings.js +142 -0
  201. package/geometry/room-stairs.js +180 -0
  202. package/geometry/room-surfaces.js +272 -0
  203. package/geometry/sagging-tube.js +27 -27
  204. package/geometry/sampled-surface.js +123 -77
  205. package/geometry/scatter-grid.js +49 -6
  206. package/geometry/sculpt.js +97 -93
  207. package/geometry/ship-fittings.js +350 -0
  208. package/geometry/ship-hull.js +460 -0
  209. package/geometry/ship-kit.js +208 -0
  210. package/geometry/ship-lines.js +69 -0
  211. package/geometry/ship-oars.js +150 -0
  212. package/geometry/ship-presets.js +131 -0
  213. package/geometry/ship-rig.js +374 -0
  214. package/geometry/ship-sails.js +148 -0
  215. package/geometry/shore-grid.js +81 -34
  216. package/geometry/strata-field.js +131 -98
  217. package/geometry/strata-tiles.js +108 -94
  218. package/geometry/stream.js +96 -59
  219. package/geometry/swept-tube.js +124 -0
  220. package/geometry/terrain-chunks.js +216 -123
  221. package/geometry/terrain-extension.js +29 -13
  222. package/geometry/town-courtyard-inn.js +272 -0
  223. package/geometry/town-ground.js +76 -0
  224. package/geometry/town-houses.js +343 -0
  225. package/geometry/town-lights.js +254 -0
  226. package/geometry/town-lots.js +172 -0
  227. package/geometry/town-plan.js +370 -0
  228. package/geometry/town-works.js +465 -0
  229. package/geometry/village-layout.js +181 -0
  230. package/geometry/village-yards.js +167 -0
  231. package/geometry/wall-runs.js +64 -0
  232. package/index.js +138 -2
  233. package/math/cell-edge.js +16 -16
  234. package/math/cell-key.js +6 -0
  235. package/math/circle-clearances.js +19 -0
  236. package/math/cloth-textures.js +6 -6
  237. package/math/cloud-textures.js +22 -26
  238. package/math/color.js +14 -14
  239. package/math/curve.js +26 -22
  240. package/math/lamp-texels.js +43 -0
  241. package/math/lit-share.js +22 -0
  242. package/math/mountain-ranges.js +379 -205
  243. package/math/noise.js +101 -49
  244. package/math/particle-noise.js +28 -28
  245. package/math/periodic.js +11 -5
  246. package/math/random.js +24 -15
  247. package/math/rectangles.js +58 -0
  248. package/math/rock-texture.js +22 -17
  249. package/math/scalar.js +5 -5
  250. package/math/surface-textures.js +74 -59
  251. package/math/wandering-path.js +40 -0
  252. package/math/ways.js +120 -0
  253. package/motion/action-dynamics.js +398 -0
  254. package/motion/animal-bearing.js +247 -0
  255. package/motion/animal-canine-bearing.js +178 -0
  256. package/motion/animal-canine-cast.js +131 -0
  257. package/motion/animal-cattle-cast.js +64 -0
  258. package/motion/animal-herd-cast.js +154 -0
  259. package/motion/animal-horse-still.js +161 -0
  260. package/motion/animal-troop-cast.js +43 -0
  261. package/motion/arm-reach.js +27 -26
  262. package/motion/ballistic-arc.js +191 -0
  263. package/motion/biped-cycle.js +46 -0
  264. package/motion/biped-leg.js +40 -0
  265. package/motion/biped-posture.js +459 -0
  266. package/motion/biped-stride.js +226 -140
  267. package/motion/boat-sailing.js +214 -0
  268. package/motion/contact-transition.js +32 -0
  269. package/motion/crowd-alarms.js +72 -42
  270. package/motion/crowd-attention.js +108 -0
  271. package/motion/crowd-beasts.js +203 -0
  272. package/motion/crowd-camp.js +295 -0
  273. package/motion/crowd-figure.js +100 -0
  274. package/motion/crowd-herd.js +86 -0
  275. package/motion/crowd-hold.js +130 -0
  276. package/motion/crowd-pose.js +296 -0
  277. package/motion/crowd-poses.js +481 -0
  278. package/motion/crowd-routine.js +126 -67
  279. package/motion/crowd-town.js +166 -0
  280. package/motion/crowd-water.js +143 -0
  281. package/motion/daily-clock.js +9 -9
  282. package/motion/deck-surface.js +40 -0
  283. package/motion/figure-acts.js +411 -0
  284. package/motion/figure-arms.js +437 -0
  285. package/motion/figure-blade-slide.js +149 -0
  286. package/motion/figure-body-place.js +180 -0
  287. package/motion/figure-bones.js +118 -0
  288. package/motion/figure-bow-draw.js +70 -0
  289. package/motion/figure-fingers.js +215 -0
  290. package/motion/figure-gaze.js +205 -0
  291. package/motion/figure-gestures.js +452 -0
  292. package/motion/figure-grip.js +134 -0
  293. package/motion/figure-head.js +287 -0
  294. package/motion/figure-legs.js +264 -0
  295. package/motion/figure-links.js +293 -0
  296. package/motion/figure-locomotion.js +391 -0
  297. package/motion/figure-mount-up.js +180 -0
  298. package/motion/figure-mount.js +201 -0
  299. package/motion/figure-pose-frame.js +375 -0
  300. package/motion/figure-pose-table.js +156 -0
  301. package/motion/figure-pose.js +343 -0
  302. package/motion/figure-seat.js +267 -0
  303. package/motion/figure-sway.js +125 -0
  304. package/motion/flier-corvid-pose.js +74 -0
  305. package/motion/flier-flight-air.js +122 -0
  306. package/motion/flier-flight-echelon.js +164 -0
  307. package/motion/flier-flight-roost.js +131 -0
  308. package/motion/flier-swarm-flight.js +252 -0
  309. package/motion/formation.js +193 -0
  310. package/motion/ground-lookahead.js +5 -5
  311. package/motion/instance-sight.js +15 -8
  312. package/motion/melee-contact.js +143 -0
  313. package/motion/moorings.js +48 -0
  314. package/motion/path-steering.js +358 -0
  315. package/motion/player.js +41 -32
  316. package/motion/quadruped.js +244 -168
  317. package/motion/spaces.js +90 -38
  318. package/motion/speech-cadence.js +304 -0
  319. package/motion/vessel-motion.js +57 -0
  320. package/motion/walk-grid.js +235 -0
  321. package/motion/weather.js +133 -26
  322. package/motion/wind.js +58 -13
  323. package/package.json +33 -6
  324. package/rendering/alpha-mips.js +340 -0
  325. package/rendering/animal-camel-figure.js +29 -0
  326. package/rendering/animal-canine-figure.js +59 -0
  327. package/rendering/animal-cattle-figure.js +36 -0
  328. package/rendering/animal-horse-figure.js +49 -0
  329. package/rendering/atmosphere.js +86 -0
  330. package/rendering/camera-track.js +156 -0
  331. package/rendering/cart-track.js +92 -0
  332. package/rendering/caster-motion.js +6 -5
  333. package/rendering/cell-lod-options.js +46 -0
  334. package/rendering/cell-lod.js +754 -113
  335. package/rendering/cloth-material.js +140 -0
  336. package/rendering/cloud-dome.js +30 -30
  337. package/rendering/cloud-field.js +2 -2
  338. package/rendering/compilation-schedule.js +79 -14
  339. package/rendering/contact-shadows.js +7 -4
  340. package/rendering/context.js +57 -6
  341. package/rendering/crowd-batches.js +420 -0
  342. package/rendering/crowd-herd.js +198 -0
  343. package/rendering/crowd-rig.js +132 -0
  344. package/rendering/crowd-skinning.js +62 -19
  345. package/rendering/crowd-update.js +419 -0
  346. package/rendering/crowd-visibility.js +107 -0
  347. package/rendering/crust.js +18 -12
  348. package/rendering/day-cycle-defaults.js +200 -0
  349. package/rendering/day-cycle.js +487 -0
  350. package/rendering/daylight.js +4 -6
  351. package/rendering/detail-range.js +29 -0
  352. package/rendering/dispose-meshes.js +18 -0
  353. package/rendering/dof.js +20 -13
  354. package/rendering/effects-frame.js +149 -0
  355. package/rendering/effects-water-rises.js +221 -0
  356. package/rendering/energy-stream.js +128 -0
  357. package/rendering/eye-adapt.js +14 -14
  358. package/rendering/facade-glass-material.js +105 -0
  359. package/rendering/far-shadow.js +89 -62
  360. package/rendering/field-surface.js +138 -0
  361. package/rendering/figure-shield.js +105 -0
  362. package/rendering/figure-skeleton.js +329 -0
  363. package/rendering/fire-light-watch.js +197 -0
  364. package/rendering/fire-pools.js +148 -0
  365. package/rendering/flame-sources.js +86 -0
  366. package/rendering/flier-bird-looks.js +97 -0
  367. package/rendering/flier-corvid-figure.js +67 -0
  368. package/rendering/flier-long-body-company.js +169 -0
  369. package/rendering/flier-swarm.js +186 -0
  370. package/rendering/flocks.js +82 -78
  371. package/rendering/garment-material.js +147 -51
  372. package/rendering/glow-lines.js +13 -13
  373. package/rendering/glsl-literal.js +19 -0
  374. package/rendering/ground-marks.js +316 -0
  375. package/rendering/hair-strands.js +45 -31
  376. package/rendering/height-haze.js +80 -33
  377. package/rendering/height-probe.js +164 -22
  378. package/rendering/house-kit-meshes.js +124 -0
  379. package/rendering/interior-bake.js +807 -0
  380. package/rendering/label-layout.js +56 -0
  381. package/rendering/label-range.js +41 -0
  382. package/rendering/lamp-light-map.js +159 -0
  383. package/rendering/lamp-maps.js +62 -0
  384. package/rendering/lamp-wash.js +51 -0
  385. package/rendering/light-budget.js +71 -55
  386. package/rendering/light-points.js +21 -5
  387. package/rendering/local-lights.js +39 -8
  388. package/rendering/material-lod.js +49 -50
  389. package/rendering/memory-estimate.js +84 -0
  390. package/rendering/moored-fleet.js +186 -0
  391. package/rendering/part-costs.js +104 -0
  392. package/rendering/particle-bursts.js +386 -0
  393. package/rendering/particle-emitters.js +135 -99
  394. package/rendering/particle-light-bursts.js +189 -0
  395. package/rendering/particles.js +212 -101
  396. package/rendering/pen-flocks.js +118 -0
  397. package/rendering/piece-batch.js +298 -11
  398. package/rendering/planar-reflection-options.js +159 -0
  399. package/rendering/planar-reflection.js +806 -103
  400. package/rendering/plant-cells.js +122 -0
  401. package/rendering/plant-reeds.js +113 -0
  402. package/rendering/plant-shade-trees.js +239 -0
  403. package/rendering/plant-tuft-patch.js +122 -0
  404. package/rendering/post-shaders.js +98 -31
  405. package/rendering/post.js +107 -87
  406. package/rendering/pressed-cover.js +135 -0
  407. package/rendering/prop-dig.js +136 -0
  408. package/rendering/rain-streaks.js +67 -0
  409. package/rendering/room-light.js +250 -0
  410. package/rendering/room-materials.js +78 -0
  411. package/rendering/room-space.js +111 -0
  412. package/rendering/scene-lights.js +106 -0
  413. package/rendering/sea-shaders.js +94 -37
  414. package/rendering/settlement-approach.js +226 -0
  415. package/rendering/settlement-dissolve.js +89 -0
  416. package/rendering/settlement-quarter-warm.js +55 -0
  417. package/rendering/settlement-quarter.js +477 -0
  418. package/rendering/settlement-switch.js +42 -0
  419. package/rendering/settlement-town.js +110 -0
  420. package/rendering/shader-warmup.js +101 -44
  421. package/rendering/shadow-alignment.js +4 -4
  422. package/rendering/shadow-depth.js +47 -25
  423. package/rendering/ship-meshes.js +150 -0
  424. package/rendering/shot-cuts.js +68 -0
  425. package/rendering/sky-occlusion.js +56 -29
  426. package/rendering/sky-pmrem.js +216 -0
  427. package/rendering/sky.js +126 -54
  428. package/rendering/smoke-shadows.js +201 -0
  429. package/rendering/stage-framing.js +182 -0
  430. package/rendering/stage-lights.js +46 -39
  431. package/rendering/stain-material.js +74 -0
  432. package/rendering/static-point-shadow.js +65 -26
  433. package/rendering/still-casters.js +77 -27
  434. package/rendering/strata-material.js +12 -12
  435. package/rendering/stream-flow.js +10 -10
  436. package/rendering/street-lamps.js +166 -0
  437. package/rendering/sunbeam-motes.js +670 -0
  438. package/rendering/surface-light.js +65 -6
  439. package/rendering/surface-material.js +306 -0
  440. package/rendering/surface-projection.js +32 -0
  441. package/rendering/surface-snippets.js +314 -0
  442. package/rendering/taa.js +75 -44
  443. package/rendering/talus.js +15 -15
  444. package/rendering/terrain-rock.js +7 -7
  445. package/rendering/texture-fills.js +8 -8
  446. package/rendering/textures.js +28 -28
  447. package/rendering/tree-impostor.js +929 -0
  448. package/rendering/vehicle-train.js +92 -0
  449. package/rendering/viewport.js +67 -4
  450. package/rendering/wakes.js +24 -24
  451. package/rendering/water-material.js +304 -103
  452. package/rendering/waypoint-beacons.js +191 -0
  453. package/rendering/world-matrices.js +38 -40
  454. package/ruff.toml +20 -0
  455. package/runtime/cue-cursor.js +21 -0
  456. package/runtime/device-quality.js +13 -2
  457. package/runtime/device.js +73 -0
  458. package/runtime/diagnostic-log.js +12 -4
  459. package/runtime/effect-sites.js +85 -0
  460. package/runtime/figure-orders.js +59 -0
  461. package/runtime/first-use.js +36 -28
  462. package/runtime/foley-script.js +124 -0
  463. package/runtime/foley-strides.js +333 -0
  464. package/runtime/frame-pacing.js +47 -0
  465. package/runtime/frame-yield.js +18 -0
  466. package/runtime/gpu-timing.js +15 -11
  467. package/runtime/grid-cache.js +16 -6
  468. package/runtime/grid-rows.js +44 -5
  469. package/runtime/hand-over.js +47 -24
  470. package/runtime/land-bake.js +78 -0
  471. package/runtime/lazy-sets.js +105 -0
  472. package/runtime/pool.js +73 -17
  473. package/runtime/quality-fit.js +60 -28
  474. package/runtime/region-pass-lay.js +40 -0
  475. package/runtime/region-pass.js +78 -0
  476. package/runtime/search.js +26 -22
  477. package/runtime/settlement-reach.js +42 -0
  478. package/runtime/sound-calls.js +113 -0
  479. package/runtime/sound-impacts.js +297 -0
  480. package/runtime/sound-voices.js +194 -0
  481. package/runtime/soundscape.js +282 -0
  482. package/runtime/spatial-audio.js +79 -30
  483. package/runtime/steady-frames.js +221 -0
  484. package/runtime/withdrawable-task.js +46 -0
  485. package/runtime/worker.js +7 -0
  486. package/scripts/app-parts.mjs +118 -0
  487. package/scripts/bake-revisions.mjs +81 -0
  488. package/scripts/browser-scripts.mjs +64 -0
  489. package/scripts/bundle.mjs +192 -0
  490. package/scripts/check-app.sh +26 -0
  491. package/scripts/eslint-config.mjs +119 -0
  492. package/scripts/format.sh +92 -0
  493. package/scripts/keep-builds.mjs +158 -0
  494. package/scripts/layers.mjs +112 -0
  495. package/scripts/lint.sh +49 -0
  496. package/scripts/module-graph.mjs +123 -0
  497. package/scripts/pre-commit.sh +38 -0
  498. package/scripts/serve.py +5 -3
  499. package/scripts/site.mjs +358 -0
  500. package/scripts/test-runner.sh +42 -0
  501. package/scripts/vendor.mjs +221 -0
  502. package/scripts/verify-publish.mjs +175 -0
  503. package/scripts/world.mk +59 -0
  504. package/tools/README.md +73 -0
  505. package/tools/contact-sheet.cjs +137 -0
  506. package/tools/cpu-profile.cjs +275 -0
  507. package/tools/cpu-profile.test.cjs +98 -0
  508. package/tools/first-draws.cjs +395 -0
  509. package/tools/flight-guard.cjs +482 -0
  510. package/tools/flight-guard.test.cjs +153 -0
  511. package/tools/flight-profile.cjs +145 -0
  512. package/tools/frame-bench.cjs +336 -0
  513. package/tools/frame-parts.cjs +365 -0
  514. package/tools/ios-sim.sh +145 -0
  515. package/tools/load-audit.cjs +201 -0
  516. package/tools/look-compare.cjs +304 -0
  517. package/tools/look-guard.cjs +407 -0
  518. package/tools/look-guard.test.cjs +93 -0
  519. package/tools/look-stats.cjs +185 -0
  520. package/tools/look-stats.test.cjs +71 -0
  521. package/tools/memory-audit.cjs +323 -0
  522. package/tools/page-driver.cjs +320 -0
  523. package/tools/page-driver.test.cjs +219 -0
  524. package/tools/program-census-report.cjs +191 -0
  525. package/tools/program-census.cjs +465 -0
  526. package/tools/program-census.test.cjs +332 -0
  527. package/tools/remote-runner.sh +265 -0
  528. package/tools/runners.test.cjs +59 -0
  529. package/tools/scene-audit-beat.cjs +344 -0
  530. package/tools/scene-audit-sheet.cjs +282 -0
  531. package/tools/scene-audit.cjs +471 -0
  532. package/tools/scene-audit.test.cjs +201 -0
  533. package/tools/scene-batch.cjs +219 -0
  534. package/tools/scene-bench.cjs +149 -0
  535. package/tools/scene-bench.test.cjs +33 -0
  536. package/tools/scene-run.cjs +443 -0
  537. package/tools/scene-run.test.cjs +94 -0
  538. package/tools/servers.sh +59 -0
  539. package/tools/shader-arrival.cjs +316 -0
  540. package/tools/shader-renewal.cjs +53 -0
  541. package/tools/shader-renewal.test.cjs +115 -0
  542. package/tools/speed-guard.cjs +258 -0
  543. package/tools/stills.cjs +492 -0
  544. package/tools/stills.test.cjs +49 -0
  545. package/tools/turns.sh +7 -0
  546. package/tools/yaml.cjs +158 -0
  547. package/examples/viaduct.css +0 -75
  548. package/rendering/light-shafts.js +0 -131
  549. package/rendering/road-surface.js +0 -63
@@ -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 };
@@ -1,66 +1,113 @@
1
+ /**
2
+ * Measure signed distance to a land outline directly or bake distances for repeated shoreline queries.
3
+ * @module
4
+ */
5
+
1
6
  import { clamp, lerp } from '../math/scalar.js';
2
7
 
3
- // The edges of a closed outline, as the distance to it is worked out from them.
8
+ /**
9
+ * Prepare edges once for repeated {@link outlineDistance} queries. The last point connects to the first.
10
+ * @param {[number, number][]} outline - Ordered [x, z] vertices of a closed polygon in metres.
11
+ */
4
12
  export const outlineEdges = outline =>
5
13
  outline.map(([x, z], i) => {
6
- const [ex, ez] = outline[(i + 1) % outline.length],
7
- dx = ex - x,
8
- dz = ez - z;
9
- return { x, z, dx, dz, ez, inv: 1 / (dx * dx + dz * dz || 1) };
14
+ const [endX, endZ] = outline[(i + 1) % outline.length],
15
+ dx = endX - x,
16
+ dz = endZ - z;
17
+ return { x, z, dx, dz, ez: endZ, inv: 1 / (dx * dx + dz * dz || 1) };
10
18
  });
11
- // The signed distance from (x, z) to an outline's edges: positive inside it.
19
+ /**
20
+ * Measure distance to the closest point on a polygon edge. The sign is positive
21
+ * inland, zero on the boundary and negative outside, for either winding order.
22
+ * @param {ReturnType<typeof outlineEdges>} edges - Precomputed edges of one land outline.
23
+ * @param {number} x - World X in metres.
24
+ * @param {number} z - World Z in metres.
25
+ */
12
26
  export function outlineDistance(edges, x, z) {
13
27
  let inside = false,
14
28
  best = Infinity;
15
- for (const e of edges) {
16
- const px = x - e.x,
17
- pz = z - e.z;
18
- if (e.z > z !== e.ez > z && px < (pz * e.dx) / e.dz) inside = !inside;
19
- const t = clamp((px * e.dx + pz * e.dz) * e.inv, 0, 1);
20
- best = Math.min(best, (px - e.dx * t) ** 2 + (pz - e.dz * t) ** 2);
29
+ for (const edge of edges) {
30
+ const px = x - edge.x,
31
+ pz = z - edge.z;
32
+ if (edge.z > z !== edge.ez > z && px < (pz * edge.dx) / edge.dz) inside = !inside;
33
+ const edgeFraction = clamp((px * edge.dx + pz * edge.dz) * edge.inv, 0, 1);
34
+ best = Math.min(best, (px - edge.dx * edgeFraction) ** 2 + (pz - edge.dz * edgeFraction) ** 2);
21
35
  }
22
36
  return Math.sqrt(best) * (inside ? 1 : -1);
23
37
  }
24
38
 
39
+ /**
40
+ * Cache shoreline distances for frequent terrain or material queries. Allocate a
41
+ * square grid, bake one or more land outlines, then sample it by world position.
42
+ * Baking keeps the largest signed distance across all outlines at each grid point.
43
+ * Queries interpolate four neighbouring samples and clamp to the grid near its edge.
44
+ * @example
45
+ * ```js
46
+ * import { createShoreGrid } from 'roamwright/geometry/shore-grid.js';
47
+ *
48
+ * const shore = createShoreGrid();
49
+ * shore.layOutShore(-8, -8, 1, 17);
50
+ * shore.bakeShore([[[-4, -4], [4, -4], [4, 4], [-4, 4]]]);
51
+ * const inland = shore.shoreDistance(0, 0); // 4 metres
52
+ * const offshore = shore.shoreDistance(6, 0); // -2 metres
53
+ * ```
54
+ */
25
55
  export function createShoreGrid() {
26
- let grid = null, // the distances, n to a side
27
- n = 0,
56
+ let grid = null, // the distance samples, with pointsPerSide along each edge
57
+ pointsPerSide = 0,
28
58
  x0 = 0,
29
59
  z0 = 0,
30
60
  step = 0; // metres from one point of the grid to the next
31
61
 
32
- // Lays the grid out empty over the square from (x0, z0): n points a side, `step` metres apart.
62
+ /**
63
+ * Replace any existing grid with zeroed storage.
64
+ * @param {number} cornerX - Smallest sample X in metres.
65
+ * @param {number} cornerZ - Smallest sample Z in metres.
66
+ * @param {number} spacing - Positive distance between samples in metres.
67
+ * @param {number} points - Samples along each side, at least two.
68
+ */
33
69
  function layOutShore(cornerX, cornerZ, spacing, points) {
34
70
  x0 = cornerX;
35
71
  z0 = cornerZ;
36
72
  step = spacing;
37
- n = points;
38
- grid = new Float32Array(n * n);
73
+ pointsPerSide = points;
74
+ grid = new Float32Array(pointsPerSide * pointsPerSide);
39
75
  }
40
- // The grid's distances: what a bake fills and a later visit reads back (core/kept.js).
76
+ /**
77
+ * Restore a matching cached grid by writing into this buffer after layout.
78
+ * @returns {Float32Array | null} The live row-major distances, or null before layout.
79
+ */
41
80
  const shoreGrid = () => grid;
42
- // Fills the grid from the land's outlines, each a closed line of [x, z] points.
81
+ /** @param {[number, number][][]} outlines - Land polygons to rasterize into the allocated grid. */
43
82
  function bakeShore(outlines) {
44
83
  const edges = outlines.map(outlineEdges);
45
- for (let j = 0; j < n; j++)
46
- for (let i = 0; i < n; i++) {
84
+ for (let row = 0; row < pointsPerSide; row++)
85
+ for (let i = 0; i < pointsPerSide; i++) {
47
86
  const x = x0 + i * step,
48
- z = z0 + j * step;
49
- let d = -Infinity;
50
- for (const outline of edges) d = Math.max(d, outlineDistance(outline, x, z));
51
- grid[j * n + i] = d;
87
+ z = z0 + row * step;
88
+ let landDistance = -Infinity;
89
+ for (const outline of edges) landDistance = Math.max(landDistance, outlineDistance(outline, x, z));
90
+ grid[row * pointsPerSide + i] = landDistance;
52
91
  }
53
92
  }
54
- // The signed distance from (x, z) to the shore, in metres: positive inland.
93
+ /**
94
+ * @param {number} x - World X in metres.
95
+ * @param {number} z - World Z in metres.
96
+ * @returns {number} Interpolated signed distance in metres, positive inland.
97
+ */
55
98
  function shoreDistance(x, z) {
56
- const u = clamp((x - x0) / step, 0, n - 1.001),
57
- v = clamp((z - z0) / step, 0, n - 1.001),
58
- i = Math.floor(u),
59
- j = Math.floor(v),
60
- a = u - i,
61
- b = v - j,
62
- k = j * n + i;
63
- return lerp(lerp(grid[k], grid[k + 1], a), lerp(grid[k + n], grid[k + n + 1], a), b);
99
+ const u = clamp((x - x0) / step, 0, pointsPerSide - 1.001),
100
+ v = clamp((z - z0) / step, 0, pointsPerSide - 1.001),
101
+ column = Math.floor(u),
102
+ row = Math.floor(v),
103
+ columnFraction = u - column,
104
+ rowFraction = v - row,
105
+ gridIndex = row * pointsPerSide + column;
106
+ return lerp(
107
+ lerp(grid[gridIndex], grid[gridIndex + 1], columnFraction),
108
+ lerp(grid[gridIndex + pointsPerSide], grid[gridIndex + pointsPerSide + 1], columnFraction),
109
+ rowFraction,
110
+ );
64
111
  }
65
112
 
66
113
  return { bakeShore, layOutShore, shoreDistance, shoreGrid };