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,161 @@
1
+ import * as THREE from 'three';
2
+ import { EYE_TAG } from '../geometry/animal-skin.js';
3
+ import { NO_ANIMAL_OPTIONS, cachePerOptions } from '../geometry/animal-options.js';
4
+ import { rigHorse } from '../rendering/animal-horse-figure.js';
5
+ import { horsePose } from './animal-bearing.js';
6
+
7
+ // ════════════════════════════════════════════════════════════════════════
8
+ // A horse that does not move, written into a builder of plain geometry (a camp's, a battlefield's): the same horse a
9
+ // rider sits, posed on its skeleton and cast. At a picket line it stands as horses stand: a hind leg rested, an ear
10
+ // turned, its head up or down at its fodder; on a battlefield it lies on its side.
11
+ // ════════════════════════════════════════════════════════════════════════
12
+ const MODELS = 3, // horses to cast from, each with its own white markings
13
+ POINTS = [0.03, 0.026, 0.024],
14
+ COAT_GAIN = 1.5, // a coded coat's colour is lifted by this, to match a ridden horse's
15
+ WHITE = [0.62, 0.6, 0.56],
16
+ HALF_BARREL = 0.26, // metres from a lying horse's spine line to the ground under its flank
17
+ SPINE_UP = 1.1, // and from a standing horse's hooves to its spine line, the line it rolls over about
18
+ LIE_ROLL = 1.5, // radians a fallen horse lies over on its side
19
+ modelsOf = cachePerOptions(),
20
+ _m = new THREE.Matrix4(),
21
+ _r = new THREE.Matrix4(),
22
+ _b = new THREE.Matrix4(),
23
+ _c = new THREE.Matrix4();
24
+ // what one step of a stored number is worth: a compact geometry keeps colours and bone weights as bytes (geometry/builder.js)
25
+ const unitOf = attribute => (attribute.normalized ? 1 / (attribute.array instanceof Uint8Array ? 255 : 65535) : 1);
26
+ let boneRows = new Float64Array(0); // each bone's pose as twelve numbers (three rows of a 4 x 4 matrix), refilled for every horse
27
+
28
+ // The models are made the first time a still horse is wanted, for each world's options: unsaddled, in a coded coat (codedCoat of
29
+ // geometry/animal-horse-coat.js), at the detail between near and far; only posed and cast, so they have no material.
30
+ function model(i, options) {
31
+ return (modelsOf(options)[i] ??= rigHorse(null, null, 0, false, 'riding', i, [1, 1], null, options));
32
+ }
33
+ /**
34
+ * Lets the models go: each horse is posed from where the one before it on its model left the skeleton, so a place's builders
35
+ * that must cast the same horses wherever and however often they run begin from new models.
36
+ * @param {import('../geometry/animal-options.js').AnimalKitOptions} [options] The world whose models go.
37
+ */
38
+ function forgetStillHorses(options = NO_ANIMAL_OPTIONS) {
39
+ const models = modelsOf(options);
40
+ for (const i in models) delete models[i];
41
+ }
42
+
43
+ /**
44
+ * Casts a horse at (x, y, z), facing yaw, into a builder, or into a kit's builders: its hide into the cloth's and its eyes into
45
+ * the glass's, which is dark and wet and catches the sky.
46
+ * @param {object} into A `GeometryBuilder`, or { cloth, glass } builders.
47
+ * @param {number} x Metres.
48
+ * @param {number} y Metres.
49
+ * @param {number} z Metres.
50
+ * @param {number} yaw Radians.
51
+ * @param {number[]} col Its coat, linear [r, g, b].
52
+ * @param {() => number} R A random source for which horse it is and how it stands.
53
+ * @param {boolean} [graze] Its head down.
54
+ * @param {boolean} [fallen] Lying dead on a side (HALF_BARREL, SPINE_UP and LIE_ROLL say how it lies).
55
+ * @param {import('../geometry/animal-options.js').AnimalKitOptions} [options]
56
+ */
57
+ function stillHorse(into, x, y, z, yaw, col, R, graze = false, fallen = false, options = NO_ANIMAL_OPTIONS) {
58
+ const gb = into.cloth ?? into,
59
+ wet = into.glass ?? into;
60
+ col = col.map(v => v * COAT_GAIN);
61
+ const H = model(Math.floor(R() * MODELS) % MODELS, options),
62
+ Q = H.rig,
63
+ mesh = H.mesh,
64
+ geo = H.near,
65
+ P = geo.attributes.position,
66
+ N = geo.attributes.normal,
67
+ C = geo.attributes.color,
68
+ max = Math.max(...col),
69
+ grey = max - Math.min(...col) < 0.08 * (max + 0.05) + 0.012,
70
+ red = !grey && R() < 0.35, // a chestnut's mane and legs are its own colour
71
+ points = grey ? col.map(v => v * 0.55) : red ? col.map(v => v * 0.85) : POINTS,
72
+ M0 = gb.M,
73
+ W0 = wet.M;
74
+ // a few moments of standing, from a moment of its own, settle the legs, the ears and the tail
75
+ H.graze = graze ? 1 : 0;
76
+ H.down = fallen ? 1 : 0;
77
+ Q.seed = R() * 100;
78
+ Q.px = null;
79
+ mesh.updateMatrixWorld(true);
80
+ for (let i = 0, t = R() * 60; i < 40; i++) horsePose(H, 0.1, (t += 0.1), 0);
81
+ mesh.updateMatrixWorld(true);
82
+ mesh.skeleton.update();
83
+ _m.makeTranslation(x, y, z).multiply(_r.makeRotationY(yaw));
84
+ if (fallen)
85
+ _m.multiply(_r.makeTranslation(0, HALF_BARREL, 0))
86
+ .multiply(_r.makeRotationZ((R() < 0.5 ? 1 : -1) * LIE_ROLL))
87
+ .multiply(_r.makeTranslation(0, -SPINE_UP, 0));
88
+ // Each vertex is posed by its bones' matrices blended by its weights, read straight from the arrays (Three.js's
89
+ // applyBoneTransform makes a matrix product a vertex and held the page for 370 ms in a camp of 60 horses). A bone's matrix
90
+ // takes a point of the skin to where its bone has carried it; `_c` then sets the posed horse where it stands.
91
+ const bones = mesh.skeleton.bones,
92
+ inverses = mesh.skeleton.boneInverses,
93
+ skin = mesh.geometry.attributes,
94
+ joint = skin.skinIndex.array,
95
+ weight = skin.skinWeight.array,
96
+ tags = geo.attributes.aTag.array,
97
+ p = P.array,
98
+ n = N.array, // a normal's scale does not matter: it is turned, then made one long
99
+ c = C.array,
100
+ colourUnit = unitOf(C),
101
+ weightUnit = unitOf(skin.skinWeight);
102
+ if (boneRows.length < bones.length * 12) boneRows = new Float64Array(bones.length * 12);
103
+ for (let b = 0; b < bones.length; b++) {
104
+ const e = _b.multiplyMatrices(bones[b].matrixWorld, inverses[b]).multiply(mesh.bindMatrix).elements;
105
+ for (let row = 0; row < 3; row++) for (let col = 0; col < 4; col++) boneRows[b * 12 + row * 4 + col] = e[col * 4 + row];
106
+ }
107
+ const T = _c.multiplyMatrices(_m, mesh.bindMatrixInverse).elements;
108
+ gb.M = wet.M = null;
109
+ for (let i = 0; i < P.count; i++) {
110
+ const k = i * 3,
111
+ px = p[k],
112
+ py = p[k + 1],
113
+ pz = p[k + 2],
114
+ nx = n[k],
115
+ ny = n[k + 1],
116
+ nz = n[k + 2];
117
+ let qx = 0,
118
+ qy = 0,
119
+ qz = 0,
120
+ qw = 0,
121
+ mx = 0,
122
+ my = 0,
123
+ mz = 0;
124
+ for (let j = i * 4; j < i * 4 + 4; j++) {
125
+ const w = weight[j] * weightUnit;
126
+ if (w === 0) continue;
127
+ const r = joint[j] * 12;
128
+ qx += w * (boneRows[r] * px + boneRows[r + 1] * py + boneRows[r + 2] * pz + boneRows[r + 3]);
129
+ qy += w * (boneRows[r + 4] * px + boneRows[r + 5] * py + boneRows[r + 6] * pz + boneRows[r + 7]);
130
+ qz += w * (boneRows[r + 8] * px + boneRows[r + 9] * py + boneRows[r + 10] * pz + boneRows[r + 11]);
131
+ qw += w;
132
+ mx += w * (boneRows[r] * nx + boneRows[r + 1] * ny + boneRows[r + 2] * nz);
133
+ my += w * (boneRows[r + 4] * nx + boneRows[r + 5] * ny + boneRows[r + 6] * nz);
134
+ mz += w * (boneRows[r + 8] * nx + boneRows[r + 9] * ny + boneRows[r + 10] * nz);
135
+ }
136
+ // a normal is turned by the matrices as a point just off the skin is, without their shift
137
+ const wx = T[0] * mx + T[4] * my + T[8] * mz,
138
+ wy = T[1] * mx + T[5] * my + T[9] * mz,
139
+ wz = T[2] * mx + T[6] * my + T[10] * mz,
140
+ length = Math.hypot(wx, wy, wz) || 1,
141
+ body = c[k] * colourUnit,
142
+ dark = c[k + 1] * colourUnit,
143
+ white = c[k + 2] * colourUnit,
144
+ eye = tags[i] === EYE_TAG;
145
+ (eye ? wet : gb).raw(
146
+ T[0] * qx + T[4] * qy + T[8] * qz + T[12] * qw,
147
+ T[1] * qx + T[5] * qy + T[9] * qz + T[13] * qw,
148
+ T[2] * qx + T[6] * qy + T[10] * qz + T[14] * qw,
149
+ wx / length,
150
+ wy / length,
151
+ wz / length,
152
+ eye ? 0 : col[0] * body + points[0] * dark + WHITE[0] * white, // a black pane: no lamplight behind it
153
+ eye ? 0 : col[1] * body + points[1] * dark + WHITE[1] * white,
154
+ eye ? 0 : col[2] * body + points[2] * dark + WHITE[2] * white,
155
+ );
156
+ }
157
+ gb.M = M0;
158
+ wet.M = W0;
159
+ }
160
+
161
+ export { HALF_BARREL, LIE_ROLL, SPINE_UP, forgetStillHorses, stillHorse };
@@ -0,0 +1,43 @@
1
+ import { NO_ANIMAL_OPTIONS } from '../geometry/animal-options.js';
2
+ import { buildCattle } from '../rendering/animal-cattle-figure.js';
3
+ import { packPose, skinArrays, weldOf } from './animal-herd-cast.js';
4
+ import { strideFrames } from './animal-bearing.js';
5
+ import { rigHorse } from '../rendering/animal-horse-figure.js';
6
+
7
+ // ════════════════════════════════════════════════════════════════════════
8
+ // A marching troop's beasts (a column of riders, its baggage oxen) as the moments they are drawn from, cast as arrays on a pool's
9
+ // workers or, where there are none, on the page: its saddled horse standing, fallen and at the moments of each pace, or its ox standing and
10
+ // at the moments of its walk, from the skin of detail q (0 the far one, 1 the middle one, for a beast close by).
11
+ // ════════════════════════════════════════════════════════════════════════
12
+ const SADDLE_CLOTH = 0x5a3a2e, // a brown cloth, unless the world gives its troops their own (`troop` of animal-options.js)
13
+ PALE_COAT = 0xa9a39a; // a pale coat, which each horse's tint colours
14
+
15
+ /**
16
+ * A troop's saddled horse or ox cast as arrays: the skin's colours and tags, the beast standing (and, a horse, fallen) with how
17
+ * high its back stands, and each pace's moments with how far one stride carries it and, at each moment, its back's rise and
18
+ * pitch and the stride's phase (for a rider to sit).
19
+ * @param {{ beast: string, q: number, paces: number[][] }} input beast: 'horse' or a cattle build ('ox'); q: the skin's detail
20
+ * (0 the far one, 1 the middle one, for a beast close by); paces: [[speed in metres a second, moments], ...].
21
+ * @param {import('../geometry/animal-options.js').AnimalKitOptions} [options] The troop's saddle cloth and coat, and the world's
22
+ * builds.
23
+ */
24
+ function troopArrays({ beast, q, paces }, options = NO_ANIMAL_OPTIONS) {
25
+ const cloth = options.troop?.saddleCloth ?? SADDLE_CLOTH,
26
+ coat = options.troop?.coat ?? PALE_COAT,
27
+ H = beast === 'horse' ? rigHorse(null, coat, cloth, true, 'riding', false, [q, q], null, options) : buildCattle(beast, [q, q], options);
28
+ H.graze = 0;
29
+ const stand = strideFrames(H, 0, 1),
30
+ weld = weldOf(H.far); // the skin's repeated points drawn once (animal-herd-cast.js)
31
+ return {
32
+ ...skinArrays(H, H.far, weld),
33
+ stand: packPose(stand.frames[0], weld),
34
+ standRise: stand.rises[0],
35
+ fallen: beast === 'horse' ? packPose(strideFrames(H, 0, 1, true).frames[0], weld) : null,
36
+ paces: paces.map(([speed, moments]) => {
37
+ const { frames, stride, rises, pitches, phases } = strideFrames(H, speed, moments);
38
+ return { frames: frames.map(frame => packPose(frame, weld)), stride, rises, pitches, phases };
39
+ }),
40
+ };
41
+ }
42
+
43
+ export { troopArrays };
@@ -1,3 +1,4 @@
1
+ import { wrapRadians } from '../math/periodic.js';
1
2
  import * as THREE from 'three';
2
3
  import { clamp } from '../math/scalar.js';
3
4
 
@@ -10,65 +11,65 @@ import { clamp } from '../math/scalar.js';
10
11
  export function createArmReach({ elbowDirection, minBend, maxBend }) {
11
12
  const _to = new THREE.Vector3(), // scratch
12
13
  _end = new THREE.Vector3(),
13
- _g = new THREE.Vector3(),
14
+ localGrip = new THREE.Vector3(),
14
15
  _elbow = new THREE.Vector3(),
15
16
  _want = new THREE.Vector3(),
16
- _a = new THREE.Vector3(),
17
- _b = new THREE.Vector3(),
17
+ armDirection = new THREE.Vector3(),
18
+ targetDirection = new THREE.Vector3(),
18
19
  _size = new THREE.Vector3(),
19
20
  _hand = new THREE.Matrix4(),
20
21
  _item = new THREE.Matrix4(),
21
22
  _inv = new THREE.Matrix4(),
22
- _q = new THREE.Quaternion(),
23
+ shoulderRotation = new THREE.Quaternion(),
23
24
  _swivel = new THREE.Quaternion(),
24
- _x = new THREE.Quaternion(),
25
+ elbowRotation = new THREE.Quaternion(),
25
26
  NONE = new THREE.Quaternion(),
26
27
  X_AXIS = new THREE.Vector3(1, 0, 0);
27
28
 
28
- // Turns the upper arm `arm` and the forearm `fore` of one side (s: 1 the right, -1 the left) by weight k toward the pose in which
29
+ // Turns the upper arm `arm` and the forearm `fore` of one side (side is 1 for right, −1 for left) by the given weight toward the pose in which
29
30
  // the point `grip` (in the own space of the bone of what the hand `hand` holds, taken at its place `rest` and unturned)
30
31
  // comes to `target` in the world. The arm's parent's world matrix must be current.
31
- function reachArm(arm, fore, hand, rest, grip, target, s, k) {
32
- if (k <= 0) return;
32
+ function reachArm(arm, fore, hand, rest, grip, target, side, weight) {
33
+ if (weight <= 0) return;
33
34
  // the target from the shoulder, in the frame the arm hangs in
34
35
  _inv.copy(arm.parent.matrixWorld).invert();
35
36
  _to.copy(target).applyMatrix4(_inv).sub(arm.position);
36
37
  // what the hand holds at `grip`, in the forearm's frame: through the hand as it is turned, and the held bone as it rests
37
38
  hand.updateMatrix();
38
39
  _item.compose(rest, NONE, _size.setScalar(1 / hand.scale.x)); // what is held keeps its own size in a larger hand, shown or not
39
- _g.copy(grip).applyMatrix4(_item).applyMatrix4(_hand.copy(hand.matrix));
40
+ localGrip.copy(grip).applyMatrix4(_item).applyMatrix4(_hand.copy(hand.matrix));
40
41
  // the elbow's bend that puts the grip as far from the shoulder as the target is (or as far as the arm reaches)
41
42
  const l1 = -fore.position.y,
42
- rho = Math.hypot(_g.y, _g.z),
43
- phi = Math.atan2(_g.z, _g.y);
43
+ rho = Math.hypot(localGrip.y, localGrip.z),
44
+ phi = Math.atan2(localGrip.z, localGrip.y);
44
45
  if (l1 <= 0 || rho <= Number.EPSILON) return;
45
46
  const far = _to.length(),
46
- c = clamp((_g.x * _g.x + l1 * l1 + rho * rho - far * far) / (2 * l1 * rho), -1, 1),
47
- turn = Math.acos(c);
47
+ cosReachAngle = clamp((localGrip.x * localGrip.x + l1 * l1 + rho * rho - far * far) / (2 * l1 * rho), -1, 1),
48
+ turn = Math.acos(cosReachAngle);
48
49
  let bend = turn - phi;
49
- bend = Math.atan2(Math.sin(bend), Math.cos(bend));
50
+ bend = wrapRadians(bend);
50
51
  if (bend > maxBend || bend < minBend) {
51
- const other = Math.atan2(Math.sin(-turn - phi), Math.cos(-turn - phi));
52
+ const other = wrapRadians(-turn - phi);
52
53
  if (Math.abs(other - (maxBend + minBend) / 2) < Math.abs(bend - (maxBend + minBend) / 2)) bend = other;
53
54
  }
54
55
  bend = clamp(bend, minBend, maxBend);
55
56
  // the end of the arm so bent, in the upper arm's own frame, turned onto the target, then swung about the line to the target
56
57
  // until the elbow is as near as it gets to where an elbow goes
57
- _x.setFromAxisAngle(X_AXIS, bend);
58
- _end.copy(_g).applyQuaternion(_x).add(fore.position);
59
- _q.setFromUnitVectors(_a.copy(_end).normalize(), _b.copy(_to).normalize());
60
- _elbow.copy(fore.position).applyQuaternion(_q);
61
- _want.set(s * elbowDirection[0], elbowDirection[1], elbowDirection[2]);
62
- _elbow.addScaledVector(_b, -_elbow.dot(_b));
63
- _want.addScaledVector(_b, -_want.dot(_b));
58
+ elbowRotation.setFromAxisAngle(X_AXIS, bend);
59
+ _end.copy(localGrip).applyQuaternion(elbowRotation).add(fore.position);
60
+ shoulderRotation.setFromUnitVectors(armDirection.copy(_end).normalize(), targetDirection.copy(_to).normalize());
61
+ _elbow.copy(fore.position).applyQuaternion(shoulderRotation);
62
+ _want.set(side * elbowDirection[0], elbowDirection[1], elbowDirection[2]);
63
+ _elbow.addScaledVector(targetDirection, -_elbow.dot(targetDirection));
64
+ _want.addScaledVector(targetDirection, -_want.dot(targetDirection));
64
65
  if (_elbow.lengthSq() > 1e-10 && _want.lengthSq() > 1e-10) {
65
66
  _elbow.normalize();
66
67
  _want.normalize();
67
- const swing = Math.atan2(_a.crossVectors(_elbow, _want).dot(_b), _elbow.dot(_want));
68
- _q.premultiply(_swivel.setFromAxisAngle(_b, swing));
68
+ const swing = Math.atan2(armDirection.crossVectors(_elbow, _want).dot(targetDirection), _elbow.dot(_want));
69
+ shoulderRotation.premultiply(_swivel.setFromAxisAngle(targetDirection, swing));
69
70
  }
70
- arm.quaternion.slerp(_q, k);
71
- fore.rotation.x += (bend - fore.rotation.x) * k;
71
+ arm.quaternion.slerp(shoulderRotation, weight);
72
+ fore.rotation.x += (bend - fore.rotation.x) * weight;
72
73
  }
73
74
  return reachArm;
74
75
  }
@@ -0,0 +1,191 @@
1
+ import { clamp } from '../math/scalar.js';
2
+
3
+ const _inverseTarget = {
4
+ elements: new Float64Array(16),
5
+ };
6
+
7
+ // Inverts a 4x4 column-major affine matrix (such as a Three.js Matrix4) into `out` without allocating.
8
+ // Returns false if the matrix is singular.
9
+ function invertMatrix4(elements, out) {
10
+ const n11 = elements[0],
11
+ n21 = elements[1],
12
+ n31 = elements[2],
13
+ n41 = elements[3],
14
+ n12 = elements[4],
15
+ n22 = elements[5],
16
+ n32 = elements[6],
17
+ n42 = elements[7],
18
+ n13 = elements[8],
19
+ n23 = elements[9],
20
+ n33 = elements[10],
21
+ n43 = elements[11],
22
+ n14 = elements[12],
23
+ n24 = elements[13],
24
+ n34 = elements[14],
25
+ n44 = elements[15];
26
+
27
+ const t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
28
+ t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
29
+ t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
30
+ t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
31
+
32
+ const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
33
+ if (Math.abs(det) < 1e-14) return false;
34
+ const invDet = 1 / det;
35
+
36
+ out[0] = t11 * invDet;
37
+ out[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * invDet;
38
+ out[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * invDet;
39
+ out[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * invDet;
40
+
41
+ out[4] = t12 * invDet;
42
+ out[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * invDet;
43
+ out[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * invDet;
44
+ out[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * invDet;
45
+
46
+ out[8] = t13 * invDet;
47
+ out[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * invDet;
48
+ out[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * invDet;
49
+ out[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * invDet;
50
+
51
+ out[12] = t14 * invDet;
52
+ out[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * invDet;
53
+ out[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * invDet;
54
+ out[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * invDet;
55
+ return true;
56
+ }
57
+
58
+ function transformPoint(out, x, y, z, elements) {
59
+ out.x = elements[0] * x + elements[4] * y + elements[8] * z + elements[12];
60
+ out.y = elements[1] * x + elements[5] * y + elements[9] * z + elements[13];
61
+ out.z = elements[2] * x + elements[6] * y + elements[10] * z + elements[14];
62
+ return out;
63
+ }
64
+
65
+ function transformUnitDirection(out, dx, dy, dz, elements) {
66
+ const rx = elements[0] * dx + elements[4] * dy + elements[8] * dz,
67
+ ry = elements[1] * dx + elements[5] * dy + elements[9] * dz,
68
+ rz = elements[2] * dx + elements[6] * dy + elements[10] * dz,
69
+ len = Math.hypot(rx, ry, rz);
70
+ if (len > 1e-8) {
71
+ out.x = rx / len;
72
+ out.y = ry / len;
73
+ out.z = rz / len;
74
+ } else {
75
+ out.x = 0;
76
+ out.y = 0;
77
+ out.z = 1;
78
+ }
79
+ return out;
80
+ }
81
+
82
+ /**
83
+ * Position between two endpoints at a fraction of the flight duration.
84
+ * Coordinates use positive y up and gravity is a positive acceleration (m/s^2).
85
+ * The destination may move between samples. The supplied vector is reused.
86
+ */
87
+ export function sampleBallisticArc(position, from, to, phase, duration, gravity = 9.81) {
88
+ const progress = clamp(phase, 0, 1);
89
+ position.lerpVectors(from, to, progress);
90
+ position.y += 0.5 * gravity * duration * duration * progress * (1 - progress);
91
+ return position;
92
+ }
93
+
94
+ /**
95
+ * Samples both world position and unit tangent direction `(position, direction)` along a ballistic arc
96
+ * from `from` to `to` at normalized `phase` in `[0, 1]` over `duration` seconds.
97
+ * Supports downward gravity sag and lateral crosswind bow without allocating.
98
+ */
99
+ export function sampleBallisticFlight(
100
+ position,
101
+ direction,
102
+ from,
103
+ to,
104
+ phase,
105
+ duration,
106
+ { gravity = 9.81, windX = 0, windZ = 0, windDrag = 0.08 } = {},
107
+ ) {
108
+ const u = clamp(phase, 0, 1),
109
+ spanSeconds = Math.max(1e-4, duration),
110
+ dx = to.x - from.x,
111
+ dy = to.y - from.y,
112
+ dz = to.z - from.z,
113
+ arcLift = 0.5 * gravity * spanSeconds * spanSeconds,
114
+ windBowX = windX * windDrag * spanSeconds * spanSeconds,
115
+ windBowZ = windZ * windDrag * spanSeconds * spanSeconds,
116
+ arch = u * (1 - u),
117
+ slope = 1 - 2 * u;
118
+
119
+ position.x = from.x + dx * u + windBowX * arch;
120
+ position.y = from.y + dy * u + arcLift * arch;
121
+ position.z = from.z + dz * u + windBowZ * arch;
122
+
123
+ const vx = dx + windBowX * slope,
124
+ vy = dy + arcLift * slope,
125
+ vz = dz + windBowZ * slope,
126
+ speed = Math.hypot(vx, vy, vz);
127
+ if (speed > 1e-8) {
128
+ direction.x = vx / speed;
129
+ direction.y = vy / speed;
130
+ direction.z = vz / speed;
131
+ } else {
132
+ direction.x = 0;
133
+ direction.y = 0;
134
+ direction.z = 1;
135
+ }
136
+ return position;
137
+ }
138
+
139
+ /**
140
+ * Computes the lodged sticking point and unit orientation in a target's local frame (or world space when
141
+ * `targetMatrixWorld` is null) so an arrow, bolt, or thrown blade stays embedded in a moving bone, shield, or surface.
142
+ */
143
+ export function solveBallisticLodge(
144
+ localPosition,
145
+ localDirection,
146
+ worldImpact,
147
+ worldDirection,
148
+ targetMatrixWorld = null,
149
+ penetrationMeters = 0.06,
150
+ ) {
151
+ const dirLen = Math.hypot(worldDirection.x, worldDirection.y, worldDirection.z),
152
+ ux = dirLen > 1e-8 ? worldDirection.x / dirLen : 0,
153
+ uy = dirLen > 1e-8 ? worldDirection.y / dirLen : 0,
154
+ uz = dirLen > 1e-8 ? worldDirection.z / dirLen : 1,
155
+ wx = worldImpact.x + ux * penetrationMeters,
156
+ wy = worldImpact.y + uy * penetrationMeters,
157
+ wz = worldImpact.z + uz * penetrationMeters;
158
+
159
+ if (targetMatrixWorld?.elements && invertMatrix4(targetMatrixWorld.elements, _inverseTarget.elements)) {
160
+ transformPoint(localPosition, wx, wy, wz, _inverseTarget.elements);
161
+ transformUnitDirection(localDirection, ux, uy, uz, _inverseTarget.elements);
162
+ return localPosition;
163
+ }
164
+
165
+ localPosition.x = wx;
166
+ localPosition.y = wy;
167
+ localPosition.z = wz;
168
+ localDirection.x = ux;
169
+ localDirection.y = uy;
170
+ localDirection.z = uz;
171
+ return localPosition;
172
+ }
173
+
174
+ /**
175
+ * Evaluates a previously solved lodged projectile into world-space `worldPosition` and `worldDirection`
176
+ * without allocating. Pass the current `targetMatrixWorld` of the struck shield, bone, or object, or null for static ground.
177
+ */
178
+ export function evaluateBallisticLodge(worldPosition, worldDirection, localPosition, localDirection, targetMatrixWorld = null) {
179
+ if (targetMatrixWorld?.elements) {
180
+ transformPoint(worldPosition, localPosition.x, localPosition.y, localPosition.z, targetMatrixWorld.elements);
181
+ transformUnitDirection(worldDirection, localDirection.x, localDirection.y, localDirection.z, targetMatrixWorld.elements);
182
+ return worldPosition;
183
+ }
184
+ worldPosition.x = localPosition.x;
185
+ worldPosition.y = localPosition.y;
186
+ worldPosition.z = localPosition.z;
187
+ worldDirection.x = localDirection.x;
188
+ worldDirection.y = localDirection.y;
189
+ worldDirection.z = localDirection.z;
190
+ return worldPosition;
191
+ }
@@ -0,0 +1,46 @@
1
+ import { sstep } from '../math/scalar.js';
2
+ import { ankleOffset, solePitch, solveBipedLeg } from './biped-leg.js';
3
+
4
+ /**
5
+ * Sample either a live or baked stride without frame history. Rig lengths, hip
6
+ * height, stride (distance per complete cycle), swing clearance and standing
7
+ * stagger are in the same units. Grade is rise per unit forward; duty is the
8
+ * fraction each foot supports the body. Angles rotate about +X, forward is +Z.
9
+ * The result and both legs are reused until the next call.
10
+ */
11
+ export function createBipedCycle({ rig, foot }) {
12
+ const leg = () => ({ thigh: 0, knee: 0, foot: 0, forward: 0, height: 0 });
13
+ const pose = { hipHeight: 0, left: leg(), right: leg() };
14
+ const ankle = [0, 0],
15
+ angles = [0, 0];
16
+ const reach = rig.thigh + rig.shin - 0.0005;
17
+
18
+ function target(leg, phase, stride, duty, clearance, grade, slope, roll, stagger) {
19
+ const swing = Math.max(0, (phase - duty) / (1 - duty));
20
+ // Match ground velocity on both sides of the swing boundary.
21
+ const track = stagger + stride * (duty / 2 - phase + sstep(0, 1, swing));
22
+ const pitch = roll * solePitch(foot, phase, duty, false, foot.heelStrike, foot.pushOff);
23
+ ankleOffset(ankle, rig, pitch, slope);
24
+ const arch = Math.sin(Math.PI * swing);
25
+ leg.forward = track + ankle[0];
26
+ leg.height = grade * track + ankle[1] + clearance * arch * arch;
27
+ leg.foot = pitch + slope;
28
+ pose.hipHeight = Math.min(pose.hipHeight, leg.height + Math.sqrt(Math.max(0, reach * reach - leg.forward * leg.forward)));
29
+ }
30
+ function solve(leg) {
31
+ solveBipedLeg(angles, rig, leg.forward, leg.height - pose.hipHeight);
32
+ leg.thigh = angles[0];
33
+ leg.knee = angles[1];
34
+ leg.foot -= leg.thigh + leg.knee;
35
+ }
36
+ return function sample(phase, stride, duty, clearance, grade, hipHeight, roll = 1, stagger = 0) {
37
+ const cyclePhase = phase - Math.floor(phase),
38
+ slope = -Math.atan(grade);
39
+ pose.hipHeight = hipHeight;
40
+ target(pose.left, cyclePhase, stride, duty, clearance, grade, slope, roll, -stagger);
41
+ target(pose.right, (cyclePhase + 0.5) % 1, stride, duty, clearance, grade, slope, roll, stagger);
42
+ solve(pose.left);
43
+ solve(pose.right);
44
+ return pose;
45
+ };
46
+ }
@@ -0,0 +1,40 @@
1
+ import { clamp, lerp, sstep } from '../math/scalar.js';
2
+
3
+ // Two-bone leg from hip to ankle in the fore-and-aft plane: for an ankle at (forward, up) from the hip, the thigh's and the
4
+ // knee's rotation, written into out.
5
+ export function solveBipedLeg(out, rig, forward, up, minReach = Math.abs(rig.thigh - rig.shin)) {
6
+ const reach = clamp(Math.sqrt(forward * forward + up * up), minReach, rig.thigh + rig.shin - 1e-4),
7
+ bend = Math.acos(clamp((reach * reach - rig.thigh * rig.thigh - rig.shin * rig.shin) / (2 * rig.thigh * rig.shin), -1, 1));
8
+ out[0] = -(Math.atan2(forward, -up) + Math.atan2(rig.shin * Math.sin(bend), rig.thigh + rig.shin * Math.cos(bend)));
9
+ out[1] = bend;
10
+ }
11
+ // The pitch of a foot's sole (toes down is more) at share u of its stride: it lands on its heel with the toes up by `strike`,
12
+ // lies flat while the body passes over it, rolls up onto its toes until the heel has risen by `push`, and in the air comes
13
+ // round from toes down to toes up. A step backwards (`back`) does it the other way round.
14
+ export function solePitch(foot, u, duty, back, strike, push) {
15
+ const planted = u < duty;
16
+ let s = planted ? u / duty : (u - duty) / (1 - duty);
17
+ if (back) s = 1 - s;
18
+ return planted ? push * sstep(foot.riseAt, 1, s) - strike * sstep(foot.flatAt, 0, s) : lerp(push, -strike, sstep(0.08, 0.8, s));
19
+ }
20
+ // Where a foot's ankle is from the point of its sole under the ankle when it lies flat, written into out (forward, up), for a
21
+ // sole pitched by `pitch` (about the ball of the foot with the heel up, about the heel with the toes up) on ground that itself
22
+ // pitches by `slope` (both radians, toes down is more).
23
+ export function ankleOffset(out, rig, pitch, slope) {
24
+ const cosPitch = Math.cos(pitch),
25
+ sinPitch = Math.sin(pitch),
26
+ forward =
27
+ pitch >= 0
28
+ ? rig.ballOffset - rig.ballOffset * cosPitch + rig.ankleHeight * sinPitch
29
+ : -rig.heelOffset + rig.heelOffset * cosPitch + rig.ankleHeight * sinPitch,
30
+ up = pitch >= 0 ? rig.ballOffset * sinPitch + rig.ankleHeight * cosPitch : -rig.heelOffset * sinPitch + rig.ankleHeight * cosPitch;
31
+ if (slope) {
32
+ const cosSlope = Math.cos(slope),
33
+ sinSlope = Math.sin(slope);
34
+ out[0] = forward * cosSlope + up * sinSlope;
35
+ out[1] = up * cosSlope - forward * sinSlope;
36
+ } else {
37
+ out[0] = forward;
38
+ out[1] = up;
39
+ }
40
+ }