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,481 @@
1
+ /**
2
+ * Auxiliary bone poses and forward-kinematics solver for the 17-bone instanced crowd rig:
3
+ * well windlass cranking, hanging, writhing, riding, melee combat, ready formation, fallen sprawl,
4
+ * kneeling (including fire-tending), ground sitting, and zero-allocation Euler bone walking.
5
+ * @module
6
+ */
7
+
8
+ import { clamp, lerp, sstep, TAU } from '../math/scalar.js';
9
+ import { createHash } from '../math/random.js';
10
+ import { ANKLE, BOOT_HEEL, BOOT_TOE, HIPS, SHANK, THIGH } from './figure-bones.js';
11
+ import { solveBipedLeg } from './biped-leg.js';
12
+ import { CROWD_BONES } from '../geometry/crowd-weld.js';
13
+
14
+ const defaultHash = createHash(42);
15
+
16
+ /** Standard well crank axle height above ground (metres). */
17
+ export const WELL_CRANK = 1.45;
18
+ /** Standard well crank handle radius (metres). */
19
+ export const WELL_ARM = 0.25;
20
+ /** Distance (metres) a crowd figure stands in front of a well crank axle. */
21
+ export const WELL_STAND = 0.66;
22
+
23
+ const WELL_RAISE = 11;
24
+ const WELL_DROP = 3.5;
25
+ const WELL_TURNS = 7;
26
+ const wellState = { angle: 0, up: 0, turning: false };
27
+
28
+ /**
29
+ * Evaluates a shared well windlass cycle (winding up over 11 s in 7 turns, then lowering over 3.5 s).
30
+ * Returns a shared scratch object `{ angle, up, turning }`.
31
+ *
32
+ * @param {number} t Clock time in seconds.
33
+ * @param {number} phase Per-well phase offset in seconds.
34
+ * @returns {{ angle: number, up: number, turning: boolean }}
35
+ */
36
+ export function windlass(t, phase) {
37
+ const c = (t + phase) % (WELL_RAISE + WELL_DROP);
38
+ if (c < WELL_RAISE) {
39
+ const u = c / WELL_RAISE;
40
+ wellState.angle = u * WELL_TURNS * TAU;
41
+ wellState.up = u;
42
+ wellState.turning = true;
43
+ } else {
44
+ const u = sstep(0, 1, (c - WELL_RAISE) / WELL_DROP);
45
+ wellState.angle = (1 - u) * WELL_TURNS * TAU;
46
+ wellState.up = 1 - u;
47
+ wellState.turning = false;
48
+ }
49
+ return wellState;
50
+ }
51
+
52
+ const SHOULDER_Y = 1.36;
53
+ const UPPER_ARM = 0.3;
54
+ const FOREARM = 0.3;
55
+
56
+ /**
57
+ * Solves a two-bone reach placing both hands on a rotating well crank handle in front of the figure.
58
+ *
59
+ * @param {object[]} b Crowd rig bones.
60
+ * @param {object} head Head bone.
61
+ * @param {number} t Clock time in seconds.
62
+ * @param {number} phase Windlass phase in seconds.
63
+ * @param {number} [wellStand=WELL_STAND] Distance from crank axle (metres).
64
+ * @param {number} [wellArm=WELL_ARM] Crank radius (metres).
65
+ * @param {number} [wellCrank=WELL_CRANK] Crank axle height (metres).
66
+ * @returns {boolean} True while actively turning the crank.
67
+ */
68
+ export function crankPose(b, head, t, phase, wellStand = WELL_STAND, wellArm = WELL_ARM, wellCrank = WELL_CRANK) {
69
+ const w = windlass(t, phase);
70
+ if (!w.turning) return false;
71
+ const forward = wellStand - wellArm * Math.cos(w.angle),
72
+ rise = wellCrank + wellArm * Math.sin(w.angle) - SHOULDER_Y,
73
+ reach = clamp(Math.hypot(forward, rise), 0.15, UPPER_ARM + FOREARM - 0.01),
74
+ bend = Math.PI - Math.acos(clamp((UPPER_ARM ** 2 + FOREARM ** 2 - reach ** 2) / (2 * UPPER_ARM * FOREARM), -1, 1)),
75
+ toward = Math.atan2(forward, -rise),
76
+ lag = Math.atan2(FOREARM * Math.sin(bend), UPPER_ARM + FOREARM * Math.cos(bend));
77
+ b[0].rotation.x = 0.12 + 0.06 * Math.cos(w.angle);
78
+ head.rotation.x = 0.2;
79
+ for (let i = 0; i < 2; i++) {
80
+ const s = i ? 1 : -1;
81
+ b[2 + i * 2].rotation.set(-(toward - lag), -s * 0.05, -s * 0.12);
82
+ b[3 + i * 2].rotation.x = -bend;
83
+ b[13 + i].rotation.set(-0.1, 0, 0);
84
+ }
85
+ return true;
86
+ }
87
+
88
+ /**
89
+ * Suspended pose with arms spread and raised, head hanging, and legs straight.
90
+ * @param {object[]} b Crowd rig bones.
91
+ * @param {object} head Head bone.
92
+ */
93
+ export function hangPose(b, head) {
94
+ b[0].position.set(0, 0, 0);
95
+ b[0].rotation.set(0.06, 0, 0);
96
+ head.rotation.set(0.55, 0.25, 0.1);
97
+ for (let i = 0; i < 2; i++) {
98
+ const s = i ? 1 : -1;
99
+ b[2 + i * 2].rotation.set(0, 0, -s * 1.95);
100
+ b[3 + i * 2].rotation.x = -0.12;
101
+ b[13 + i].rotation.set(0.3, 0, 0);
102
+ b[6 + i * 2].rotation.set(0.05, 0, 0);
103
+ b[7 + i * 2].rotation.x = 0.12;
104
+ b[15 + i].rotation.x = 0.55;
105
+ }
106
+ }
107
+
108
+ const WRITHE_SLOW = 0.55;
109
+
110
+ /**
111
+ * Bound-and-struggling pose with wrists raised above the head and asynchronous head/knee motion.
112
+ * @param {object[]} b Crowd rig bones.
113
+ * @param {object} head Head bone.
114
+ * @param {number} t Clock time in seconds.
115
+ * @param {number} ph Individual phase seed.
116
+ */
117
+ export function writhePose(b, head, t, ph) {
118
+ const lift = Math.max(0, Math.sin(t * WRITHE_SLOW + ph)) ** 2,
119
+ strain = Math.sin(t * WRITHE_SLOW * 1.7 + ph * 1.3),
120
+ knee = Math.max(0, Math.sin(t * WRITHE_SLOW * 0.8 + ph * 0.7));
121
+ b[0].position.set(0, -0.02 - 0.03 * knee, 0);
122
+ b[0].rotation.set(0.04 - 0.05 * lift, 0.09 * strain, 0.05 * strain);
123
+ head.rotation.set(0.62 - 0.6 * lift, 0.35 * Math.sin(t * WRITHE_SLOW * 0.6 + ph * 2), 0.12 * strain);
124
+ for (let i = 0; i < 2; i++) {
125
+ const s = i ? 1 : -1,
126
+ drawn = i ? knee : 0.3 * knee;
127
+ b[2 + i * 2].rotation.set(0.08, 0, -s * (2.62 + 0.06 * s * strain));
128
+ b[3 + i * 2].rotation.x = -0.25 - 0.15 * lift;
129
+ b[13 + i].rotation.set(0.2, 0, 0);
130
+ b[6 + i * 2].rotation.set(-0.5 * drawn, 0, s * 0.06);
131
+ b[7 + i * 2].rotation.x = 0.1 + 0.9 * drawn;
132
+ b[15 + i].rotation.x = 0.5 - 0.3 * drawn;
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Seated-astride-a-mount pose rocked by the mount's stride pitch `rock` (radians).
138
+ * @param {object[]} b Crowd rig bones.
139
+ * @param {object} head Head bone.
140
+ * @param {number} rest Idle breath sway.
141
+ * @param {number} shift Idle look shift.
142
+ * @param {number} rock Forward/back stride rock (radians).
143
+ */
144
+ export function ridePose(b, head, rest, shift, rock) {
145
+ b[0].position.set(0, -0.47, 0);
146
+ b[0].rotation.set(0.07 + 0.02 * rest + rock, 0.05 * shift, 0);
147
+ head.rotation.set(0.03 - 0.6 * rock, 0.22 * shift, 0);
148
+ for (let i = 0; i < 2; i++) {
149
+ const s = i ? 1 : -1;
150
+ b[6 + i * 2].rotation.set(-1.0, 0, s * 0.44);
151
+ b[7 + i * 2].rotation.x = 1.2;
152
+ b[15 + i].rotation.x = -0.12;
153
+ b[2 + i * 2].rotation.set(-0.4, 0, -s * 0.1);
154
+ b[3 + i * 2].rotation.x = -0.95;
155
+ b[13 + i].rotation.set(-0.1, 0, 0);
156
+ }
157
+ }
158
+
159
+ const BLOWS = 0.54;
160
+ const PARRY_END = 0.74;
161
+ const STRUCK = 0.1;
162
+
163
+ /**
164
+ * Melee combat pose with four stances (shield-wall, heavy cut, point thrust, skirmisher) and
165
+ * asynchronous strikes, parries, and struck recoils.
166
+ *
167
+ * @param {object[]} b Crowd rig bones.
168
+ * @param {object} head Head bone.
169
+ * @param {object} g Crowd figure (`ph`, `vary`).
170
+ * @param {number} t Clock time in seconds.
171
+ * @param {number} walking Walk blend `[0, 1]`.
172
+ * @param {(x: number, y: number, salt?: number) => number} [hash] Seeded 2D hash returning `[0, 1)`.
173
+ */
174
+ export function fightPose(b, head, g, t, walking, hash = defaultHash) {
175
+ const cadence = 0.42 + 0.46 * ((g.ph * 7.31) % 1),
176
+ at = t * cadence + g.ph,
177
+ n = Math.floor(at),
178
+ beat = at - n,
179
+ pick = hash(n, (g.ph * 13) | 0, 91),
180
+ blow = pick < BLOWS ? 1 : 0,
181
+ parry = !blow && pick < PARRY_END ? Math.sin(Math.PI * sstep(0.08, 0.78, beat)) : 0,
182
+ struck = pick > 1 - STRUCK ? Math.sin(Math.PI * sstep(0.1, 0.75, beat)) : 0,
183
+ style = (g.ph * 5.71) % 1,
184
+ shieldWall = style < 0.35,
185
+ heavyCut = style >= 0.35 && style < 0.65,
186
+ point = style >= 0.65 && style < 0.85,
187
+ wind = blow * sstep(0.05, 0.42, beat) * (1 - sstep(0.48, 0.57, beat)),
188
+ cut = blow * sstep(0.48, 0.57, beat) * (1 - sstep(0.72, 1, beat)),
189
+ weave = (1 - blow) * Math.sin(t * (1.4 + 0.8 * g.vary) + g.ph * 5);
190
+
191
+ const basePitch = shieldWall ? 0.16 : point ? 0.14 : 0.08;
192
+ const baseTwist = shieldWall ? 0.42 : heavyCut ? 0.22 : point ? 0.35 : 0.28;
193
+ b[0].rotation.x += basePitch + (point ? 0.3 : heavyCut ? 0.24 : 0.18) * cut - 0.1 * wind - 0.32 * struck + 0.08 * parry;
194
+ b[0].rotation.y += baseTwist - (point ? 0.35 : heavyCut ? 0.65 : 0.48) * wind + (heavyCut ? 0.32 : 0.2) * cut - 0.18 * parry;
195
+ head.rotation.set(0.05 + 0.08 * parry - 0.36 * struck, -baseTwist * 0.75 + 0.3 * wind, 0.15 * struck - 0.06 * parry);
196
+
197
+ if (point) {
198
+ b[4].rotation.set(-0.88 + 0.38 * wind - 0.72 * cut + 0.08 * weave + 0.12 * parry, 0.1, -0.15);
199
+ b[5].rotation.x = -1.05 - 0.9 * wind + 1.0 * cut - 0.2 * parry;
200
+ b[14].rotation.set(0.32 * wind - 0.28 * cut, 0, 0);
201
+ } else if (shieldWall) {
202
+ b[4].rotation.set(-0.62 - 0.85 * wind - 0.35 * cut + 0.06 * weave + 0.15 * parry, 0.22, -0.14 - 0.12 * wind);
203
+ b[5].rotation.x = -0.95 - 0.55 * wind + 0.75 * cut - 0.25 * parry;
204
+ b[14].rotation.set(-0.18 + 0.3 * wind - 0.18 * cut, 0, 0);
205
+ } else if (heavyCut) {
206
+ b[4].rotation.set(-0.78 - 1.95 * wind + 0.35 * cut + 0.09 * weave, 0.12, -0.22 - 0.38 * wind);
207
+ b[5].rotation.x = -0.35 - 0.95 * wind + 0.15 * cut;
208
+ b[14].rotation.set(-0.38 + 0.55 * wind - 0.12 * cut, 0, 0);
209
+ } else {
210
+ b[4].rotation.set(-0.92 - 1.25 * wind + 0.18 * cut + 0.16 * weave - 0.2 * parry, 0.18, -0.28 - 0.24 * wind);
211
+ b[5].rotation.x = -0.62 - 0.65 * wind + 0.45 * cut - 0.3 * parry;
212
+ b[14].rotation.set(-0.22 + 0.38 * wind, 0, 0);
213
+ }
214
+
215
+ const shieldLift = (shieldWall ? -0.78 : -0.52) - 0.38 * parry - 0.48 * struck + 0.12 * wind;
216
+ const shieldAcross = (shieldWall ? 0.98 : 0.78) + 0.22 * parry - 0.2 * wind;
217
+ b[2].rotation.set(shieldLift, shieldAcross, (shieldWall ? 0.05 : 0.14) + 0.38 * struck - 0.12 * parry);
218
+ b[3].rotation.x = (shieldWall ? -1.48 : -1.24) + 0.2 * cut + 0.58 * struck - 0.16 * parry;
219
+
220
+ if (walking > 0.5) return;
221
+ const lunge = point ? cut : shieldWall ? 0.55 * cut : 0.45 * cut;
222
+ const crouch = (shieldWall ? 0.09 : 0.055) + 0.055 * lunge + 0.045 * parry;
223
+ b[0].position.y -= crouch;
224
+ b[0].position.z += 0.09 * lunge - 0.065 * struck - 0.03 * parry;
225
+ b[6].rotation.x = -0.42 - 0.12 * (shieldWall ? 1 : 0) - 0.32 * lunge - 0.12 * parry;
226
+ b[7].rotation.x = 0.52 + 0.14 * (shieldWall ? 1 : 0) + 0.32 * lunge + 0.14 * parry;
227
+ b[15].rotation.x = -0.1;
228
+ b[8].rotation.x = 0.18 + 0.16 * lunge;
229
+ b[9].rotation.x = 0.34 + 0.12 * lunge + 0.08 * parry;
230
+ b[16].rotation.x = -0.48;
231
+ }
232
+
233
+ /**
234
+ * Armed formation-ready stance with varied shield heights, weapon rests, and alert weight shifts.
235
+ * @param {object[]} b Crowd rig bones.
236
+ * @param {object} head Head bone.
237
+ * @param {object} g Crowd figure (`ph`, `vary`).
238
+ * @param {number} t Clock time in seconds.
239
+ * @param {number} walking Walk blend `[0, 1]`.
240
+ */
241
+ export function readyPose(b, head, g, t, walking) {
242
+ if (walking > 0.45) {
243
+ b[2].rotation.x = lerp(b[2].rotation.x, -0.42, walking);
244
+ b[2].rotation.y = lerp(b[2].rotation.y, 0.45, walking);
245
+ b[3].rotation.x = lerp(b[3].rotation.x, -0.85, walking);
246
+ b[4].rotation.x = lerp(b[4].rotation.x, -0.25, walking);
247
+ b[5].rotation.x = lerp(b[5].rotation.x, -0.55, walking);
248
+ return;
249
+ }
250
+ const breath = Math.sin(t * (0.85 + 0.35 * g.vary) + g.ph),
251
+ scan = Math.sin(t * (0.35 + 0.2 * g.vary) + g.ph * 2.3),
252
+ stance = (g.ph * 4.13) % 1;
253
+ const braced = stance < 0.38,
254
+ relaxed = stance >= 0.72;
255
+ b[0].position.y -= braced ? 0.045 : relaxed ? 0.01 : 0.025;
256
+ b[0].rotation.x += (braced ? 0.07 : 0.03) + 0.018 * breath;
257
+ b[0].rotation.y += (braced ? 0.24 : relaxed ? -0.08 : 0.12) + 0.04 * scan;
258
+ head.rotation.set(0.02 + 0.04 * breath, 0.22 * scan - (braced ? 0.15 : 0), 0.02 * breath);
259
+
260
+ b[2].rotation.set(braced ? -0.56 : relaxed ? -0.22 : -0.38, braced ? 0.76 : relaxed ? 0.28 : 0.52, braced ? 0.08 : -0.14);
261
+ b[3].rotation.x = (braced ? -1.28 : relaxed ? -0.52 : -0.92) + 0.04 * breath;
262
+
263
+ if (braced) {
264
+ b[4].rotation.set(-0.62 + 0.04 * breath, 0.12, -0.18);
265
+ b[5].rotation.x = -0.85;
266
+ b[14].rotation.set(-0.12, 0, 0);
267
+ } else if (relaxed) {
268
+ b[4].rotation.set(-0.18 + 0.03 * breath, 0.05, 0.22);
269
+ b[5].rotation.x = -0.36;
270
+ b[14].rotation.set(0.08, 0, 0);
271
+ } else {
272
+ b[4].rotation.set(-0.92 + 0.05 * breath, 0.08, -0.12);
273
+ b[5].rotation.x = -1.25;
274
+ b[14].rotation.set(0.18, 0, 0);
275
+ }
276
+
277
+ const lead = braced ? 0.22 : 0.1;
278
+ b[6].rotation.x = -lead;
279
+ b[7].rotation.x = lead * 1.35;
280
+ b[15].rotation.x = -lead * 0.35;
281
+ b[8].rotation.x = lead * 0.55;
282
+ b[9].rotation.x = lead * 0.65;
283
+ b[16].rotation.x = -lead * 0.9;
284
+ }
285
+
286
+ /**
287
+ * Uneven fallen casualty sprawl blended onto the current pose as `g.fall` increases.
288
+ * @param {object[]} b Crowd rig bones.
289
+ * @param {object} head Head bone.
290
+ * @param {object} g Crowd figure (`ph`, `vary`, `fall`).
291
+ * @param {number} blend Sprawl blend weight `[0, 1]`.
292
+ */
293
+ export function fallenPose(b, head, g, blend) {
294
+ const s1 = Math.sin(g.ph * 3.17),
295
+ s2 = Math.cos(g.ph * 5.43),
296
+ faceDown = g.fall < 0;
297
+ b[0].rotation.x = lerp(b[0].rotation.x, faceDown ? 0.08 : -0.05, blend);
298
+ b[0].rotation.y = lerp(b[0].rotation.y, 0.28 * s1, blend);
299
+ head.rotation.x = lerp(head.rotation.x, faceDown ? -0.25 : 0.22, blend);
300
+ head.rotation.y = lerp(head.rotation.y, (0.55 + 0.35 * Math.abs(s2)) * (s1 >= 0 ? 1 : -1), blend);
301
+ head.rotation.z = lerp(head.rotation.z, 0.18 * s2, blend);
302
+
303
+ b[2].rotation.set(
304
+ lerp(b[2].rotation.x, -0.35 - 0.55 * Math.abs(s1), blend),
305
+ lerp(b[2].rotation.y, 0.25 * s2, blend),
306
+ lerp(b[2].rotation.z, -0.55 - 0.65 * g.vary, blend),
307
+ );
308
+ b[3].rotation.x = lerp(b[3].rotation.x, -0.45 - 0.75 * Math.abs(s2), blend);
309
+ b[4].rotation.set(
310
+ lerp(b[4].rotation.x, -0.25 - 0.8 * g.vary, blend),
311
+ lerp(b[4].rotation.y, -0.2 * s1, blend),
312
+ lerp(b[4].rotation.z, 0.45 + 0.75 * Math.abs(s1), blend),
313
+ );
314
+ b[5].rotation.x = lerp(b[5].rotation.x, -0.3 - 0.85 * g.vary, blend);
315
+
316
+ const drawLeft = s1 > 0;
317
+ const kneeBend = 0.35 + 0.75 * g.vary;
318
+ b[6].rotation.set(
319
+ lerp(b[6].rotation.x, drawLeft ? -kneeBend * 0.55 : -0.08, blend),
320
+ 0,
321
+ lerp(b[6].rotation.z, -0.14 - 0.16 * g.vary, blend),
322
+ );
323
+ b[7].rotation.x = lerp(b[7].rotation.x, drawLeft ? kneeBend : 0.15, blend);
324
+ b[8].rotation.set(
325
+ lerp(b[8].rotation.x, drawLeft ? -0.1 : -kneeBend * 0.55, blend),
326
+ 0,
327
+ lerp(b[8].rotation.z, 0.14 + 0.16 * Math.abs(s2), blend),
328
+ );
329
+ b[9].rotation.x = lerp(b[9].rotation.x, drawLeft ? 0.18 : kneeBend, blend);
330
+ }
331
+
332
+ const KNEEL = { thigh: 0.35, shin: 0.06, foot: 0.8, drop: 0.47, bow: 0.22, head: 0.32, cloak: 0.75 };
333
+ const FEED = { arm: [-0.9, 0.06], fore: -0.5, wrist: [0.15, 1.45] };
334
+
335
+ /**
336
+ * Kneeling pose on open ground; when `firewood` is true, reaches forward with the right hand to tend a fire.
337
+ * @param {object[]} b Crowd rig bones.
338
+ * @param {object} head Head bone.
339
+ * @param {object|null} cloak Cloak bone, if present.
340
+ * @param {number} rest Idle breath sway.
341
+ * @param {number} shift Idle look shift.
342
+ * @param {boolean} [firewood=false] True to reach forward holding firewood.
343
+ */
344
+ export function kneelPose(b, head, cloak, rest, shift, firewood = false) {
345
+ const bow = KNEEL.bow + 0.03 * rest;
346
+ b[0].position.set(0, -KNEEL.drop, 0.02);
347
+ b[0].rotation.set(bow, 0.04 * shift, 0);
348
+ head.rotation.set(KNEEL.head + 0.04 * rest, 0.08 * shift, 0);
349
+ for (let i = 0; i < 2; i++) {
350
+ const s = i ? 1 : -1;
351
+ b[6 + i * 2].rotation.set(-KNEEL.thigh - bow, 0, s * 0.06);
352
+ b[7 + i * 2].rotation.x = Math.PI / 2 + KNEEL.thigh - KNEEL.shin;
353
+ b[15 + i].rotation.x = KNEEL.foot;
354
+ b[2 + i * 2].rotation.set(-0.3, -s * 0.1, -s * 0.12);
355
+ b[3 + i * 2].rotation.x = -0.75 - 0.04 * rest;
356
+ b[13 + i].rotation.set(-0.1, 0, 0);
357
+ }
358
+ if (firewood) {
359
+ b[4].rotation.set(FEED.arm[0] + 0.05 * rest, 0, -FEED.arm[1]);
360
+ b[5].rotation.x = FEED.fore;
361
+ b[14].rotation.set(FEED.wrist[0], FEED.wrist[1], 0);
362
+ }
363
+ if (cloak) cloak.rotation.set(KNEEL.cloak, 0, 0);
364
+ }
365
+
366
+ /** Shared rigid-boot leg rig constants used by crowd gait and ground-sitting poses. */
367
+ export const CROWD_LEG_RIG = { thigh: THIGH, shin: SHANK, ankleHeight: ANKLE, heelOffset: BOOT_HEEL, ballOffset: BOOT_TOE };
368
+
369
+ const GROUND = { drop: 0.82, ankle: 0.42, lean: 0.3, splay: 0.16, cloak: 0.9 };
370
+ const GROUND_LEG = [0, 0];
371
+ solveBipedLeg(GROUND_LEG, CROWD_LEG_RIG, GROUND.ankle, GROUND.drop - (HIPS - ANKLE));
372
+
373
+ /**
374
+ * Sitting on bare ground with knees drawn up and forearms resting over them.
375
+ * @param {object[]} b Crowd rig bones.
376
+ * @param {object} head Head bone.
377
+ * @param {object|null} cloak Cloak bone, if present.
378
+ * @param {number} rest Idle breath sway.
379
+ * @param {number} shift Idle look shift.
380
+ */
381
+ export function groundPose(b, head, cloak, rest, shift) {
382
+ const lean = GROUND.lean + 0.03 * rest;
383
+ b[0].position.set(0, -GROUND.drop, 0);
384
+ b[0].rotation.set(lean, 0.05 * shift, 0);
385
+ head.rotation.set(0.08 + 0.05 * rest, 0.16 * shift, 0.03 * rest);
386
+ for (let i = 0; i < 2; i++) {
387
+ const s = i ? 1 : -1;
388
+ b[6 + i * 2].rotation.set(GROUND_LEG[0] - lean, 0, s * GROUND.splay);
389
+ b[7 + i * 2].rotation.x = GROUND_LEG[1];
390
+ b[15 + i].rotation.x = -GROUND_LEG[0] - GROUND_LEG[1];
391
+ b[2 + i * 2].rotation.set(-0.55 - 0.04 * i, -s * 0.1, -s * 0.2);
392
+ b[3 + i * 2].rotation.x = -0.85 - 0.06 * rest;
393
+ b[13 + i].rotation.set(0.1, 0, 0);
394
+ }
395
+ if (cloak) cloak.rotation.set(GROUND.cloak, 0, 0);
396
+ }
397
+
398
+ const _local = new Float64Array(9);
399
+
400
+ /**
401
+ * Evaluates world-space transforms (three basis columns + translation, 12 numbers per bone)
402
+ * for all 17 bones of a crowd rig using plain XYZ Euler angles, writing into `out`.
403
+ *
404
+ * @param {{ bones: object[], parentOf: number[], order: number[], base: { elements: ArrayLike<number> } }} rig Crowd rig (`crowdRig`).
405
+ * @param {Float64Array} out Output buffer of length at least `CROWD_BONES * 12`.
406
+ */
407
+ export function walkBones(rig, out) {
408
+ const { bones, parentOf, order, base } = rig,
409
+ W = out,
410
+ L = _local,
411
+ P = base.elements;
412
+ for (let n = 0; n < CROWD_BONES; n++) {
413
+ const i = order[n],
414
+ bone = bones[i],
415
+ r = bone.rotation,
416
+ p = bone.position,
417
+ sc = bone.scale,
418
+ a = r.x ? Math.cos(r.x) : 1,
419
+ b = r.x ? Math.sin(r.x) : 0,
420
+ c = r.y ? Math.cos(r.y) : 1,
421
+ d = r.y ? Math.sin(r.y) : 0,
422
+ e = r.z ? Math.cos(r.z) : 1,
423
+ f = r.z ? Math.sin(r.z) : 0,
424
+ ae = a * e,
425
+ af = a * f,
426
+ be = b * e,
427
+ bf = b * f;
428
+ L[0] = c * e * sc.x;
429
+ L[1] = (af + be * d) * sc.x;
430
+ L[2] = (bf - ae * d) * sc.x;
431
+ L[3] = -c * f * sc.y;
432
+ L[4] = (ae - bf * d) * sc.y;
433
+ L[5] = (be + af * d) * sc.y;
434
+ L[6] = d * sc.z;
435
+ L[7] = -b * c * sc.z;
436
+ L[8] = a * c * sc.z;
437
+ const up = parentOf[i],
438
+ o = i * 12;
439
+ let x0, x1, x2, y0, y1, y2, z0, z1, z2, t0, t1, t2;
440
+ if (up < 0) {
441
+ x0 = P[0];
442
+ x1 = P[1];
443
+ x2 = P[2];
444
+ y0 = P[4];
445
+ y1 = P[5];
446
+ y2 = P[6];
447
+ z0 = P[8];
448
+ z1 = P[9];
449
+ z2 = P[10];
450
+ t0 = P[12];
451
+ t1 = P[13];
452
+ t2 = P[14];
453
+ } else {
454
+ const q = up * 12;
455
+ x0 = W[q];
456
+ x1 = W[q + 1];
457
+ x2 = W[q + 2];
458
+ y0 = W[q + 3];
459
+ y1 = W[q + 4];
460
+ y2 = W[q + 5];
461
+ z0 = W[q + 6];
462
+ z1 = W[q + 7];
463
+ z2 = W[q + 8];
464
+ t0 = W[q + 9];
465
+ t1 = W[q + 10];
466
+ t2 = W[q + 11];
467
+ }
468
+ for (let col = 0; col < 3; col++) {
469
+ const lx = L[col * 3],
470
+ ly = L[col * 3 + 1],
471
+ lz = L[col * 3 + 2],
472
+ k = o + col * 3;
473
+ W[k] = x0 * lx + y0 * ly + z0 * lz;
474
+ W[k + 1] = x1 * lx + y1 * ly + z1 * lz;
475
+ W[k + 2] = x2 * lx + y2 * ly + z2 * lz;
476
+ }
477
+ W[o + 9] = x0 * p.x + y0 * p.y + z0 * p.z + t0;
478
+ W[o + 10] = x1 * p.x + y1 * p.y + z1 * p.z + t1;
479
+ W[o + 11] = x2 * p.x + y2 * p.y + z2 * p.z + t2;
480
+ }
481
+ }
@@ -1,3 +1,4 @@
1
+ import { wrapRadians } from '../math/periodic.js';
1
2
  import { sstep } from '../math/scalar.js';
2
3
 
3
4
  /**
@@ -26,13 +27,24 @@ export function walkRound(points, speed, { retrace = false, clearAt, rng: random
26
27
  if (!points.length || !Number.isFinite(speed) || speed <= 0) throw new RangeError('Expected waypoints and a positive walking speed');
27
28
  const seq = retrace ? points.concat(points.slice(1, -1).reverse()) : points;
28
29
  const legs = [];
29
- let time = 0, distance = 0;
30
+ let time = 0,
31
+ distance = 0;
30
32
  for (let i = 0; i < seq.length; i++) {
31
- const startPoint = seq[i], endPoint = seq[(i + 1) % seq.length];
32
- if (!Number.isFinite(startPoint.x) || !Number.isFinite(startPoint.z) || !Number.isFinite(endPoint.x) || !Number.isFinite(endPoint.z)
33
- || !Number.isFinite(endPoint.w ?? 0) || (endPoint.w ?? 0) < 0) throw new RangeError('Invalid waypoint');
34
- const dx = endPoint.x - startPoint.x, dz = endPoint.z - startPoint.z;
35
- const len = Math.hypot(dx, dz), tw = len / speed;
33
+ const startPoint = seq[i],
34
+ endPoint = seq[(i + 1) % seq.length];
35
+ if (
36
+ !Number.isFinite(startPoint.x) ||
37
+ !Number.isFinite(startPoint.z) ||
38
+ !Number.isFinite(endPoint.x) ||
39
+ !Number.isFinite(endPoint.z) ||
40
+ !Number.isFinite(endPoint.w ?? 0) ||
41
+ (endPoint.w ?? 0) < 0
42
+ )
43
+ throw new RangeError('Invalid waypoint');
44
+ const dx = endPoint.x - startPoint.x,
45
+ dz = endPoint.z - startPoint.z;
46
+ const len = Math.hypot(dx, dz),
47
+ tw = len / speed;
36
48
  if (clearAt) {
37
49
  const steps = Math.max(1, Math.ceil(len / 0.5));
38
50
  for (let j = 0; j <= steps; j++) {
@@ -40,16 +52,37 @@ export function walkRound(points, speed, { retrace = false, clearAt, rng: random
40
52
  }
41
53
  }
42
54
  legs.push({
43
- x0: startPoint.x, z0: startPoint.z, dx, dz, len, travel: distance, t0: time, tw,
44
- dir: Math.atan2(dx, dz), yaw: endPoint.yaw, hide: endPoint.hide, start: startPoint.w > 0, stop: endPoint.w > 0, role: endPoint.role,
55
+ x0: startPoint.x,
56
+ z0: startPoint.z,
57
+ dx,
58
+ dz,
59
+ len,
60
+ travel: distance,
61
+ t0: time,
62
+ tw,
63
+ dir: Math.atan2(dx, dz),
64
+ yaw: endPoint.yaw,
65
+ hide: endPoint.hide,
66
+ start: startPoint.w > 0,
67
+ stop: endPoint.w > 0,
68
+ role: endPoint.role,
45
69
  });
46
70
  time += tw + (endPoint.w || 0);
47
71
  distance += len;
48
72
  }
49
73
  const { x, z } = seq[0];
50
74
  return {
51
- ax: x, az: z, bx: x, bz: z, sp: 0, walkSpeed: speed, legs: time ? legs : null,
52
- distance, T: time, ph: random ? random() * time : 0, s: random ? size + random() * spread : size,
75
+ ax: x,
76
+ az: z,
77
+ bx: x,
78
+ bz: z,
79
+ sp: 0,
80
+ walkSpeed: speed,
81
+ legs: time ? legs : null,
82
+ distance,
83
+ T: time,
84
+ ph: random ? random() * time : 0,
85
+ s: random ? size + random() * spread : size,
53
86
  };
54
87
  }
55
88
 
@@ -201,12 +234,9 @@ export function createWalkFit({ collideIn, hit, onDeck, worldSpace }, { body = 0
201
234
  };
202
235
  }
203
236
 
204
- // Kept for applications importing the crowd selector from its original module.
205
- export { detailLevel } from '../rendering/detail-range.js';
206
-
207
237
  /** Turns a heading `dir` towards `want` at `rate` a second over `gap` seconds, at once after a gap of more than `snap` seconds. */
208
238
  export function easeHeading(dir, want, gap, rate, snap = 0.2) {
209
239
  if (gap > snap || gap < 0) return want;
210
240
  const turn = want - dir;
211
- return dir + Math.atan2(Math.sin(turn), Math.cos(turn)) * Math.min(1, gap * rate);
241
+ return dir + wrapRadians(turn) * Math.min(1, gap * rate);
212
242
  }