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,247 @@
1
+ import * as THREE from 'three';
2
+ import { cycleDelta } from '../math/periodic.js';
3
+ import { TAU, sstep } from '../math/scalar.js';
4
+ import { solveEquineBearing } from './action-dynamics.js';
5
+ import { BONE, stepRig } from './quadruped.js';
6
+
7
+ // ════════════════════════════════════════════════════════════════════════
8
+ // A horse's bearing on top of its gait (motion/quadruped.js moves the legs): the neck that nods with the walk, leads
9
+ // rein turns and reaches out at a gallop, asynchronous ears that swivel and flick, a multi-joint tail that swishes and
10
+ // streams, a hind leg rested with settled hip weight at a halt; and the moments of its stride as plain geometry, for the
11
+ // hundreds of a troop.
12
+ // ════════════════════════════════════════════════════════════════════════
13
+ const NECK = 0, // the channels of a horse's bearing, each eased towards its target
14
+ TAIL = 1,
15
+ EARS = 2,
16
+ REST = 3,
17
+ DOWN = 4,
18
+ GRAZE = 5,
19
+ GRAZE_BEND = [1.15, 0.6, -0.6], // how far the neck, its upper half and the head bend to bring a horse's muzzle to the grass (H.grazeBend for another beast)
20
+ _frame = { x: 0, y: 0, z: 0, yaw: 0, s: 1, ground: null },
21
+ _manner = { dy: 0, dz: 0, pitch: 0, roll: 0, hips: 0, chest: 0, legs: [0, 1, 2, 3].map(() => ({ y: 0, z: 0, a3: 0, a4: 0, w: 0 })) },
22
+ _equineParams = {
23
+ timeSeconds: 0,
24
+ seed: 1,
25
+ still: 1,
26
+ brisk: 0,
27
+ run: 0,
28
+ stridePhase: 0,
29
+ yawRate: 0,
30
+ turnLead: 0,
31
+ restWeight: 0,
32
+ restSide: 1,
33
+ };
34
+
35
+ // Poses a horse for this frame from where it is: under its rider a (a figure), or wherever its own mesh stands. Returns how far
36
+ // its back has risen with the stride, for the rider to sit. H.down (0 to 1) lays it out as fallen; H.graze lowers its head to the
37
+ // ground. ground: the height of the ground at (x, z), which a ridden horse's hooves keep to (nothing here reads the world, so a
38
+ // worker can pose a beast too). The same bearing serves any beast on the four-legged skeleton (rendering/animal-cattle-figure.js, rendering/animal-camel-figure.js).
39
+ function horsePose(H, dt, t, speed, a = null, ground = null) {
40
+ const Q = H.rig,
41
+ B = Q.bones,
42
+ S = H.s,
43
+ M = _manner,
44
+ F = _frame,
45
+ e = H.mesh.matrixWorld.elements,
46
+ seed = Q.seed ?? (Q.seed = Math.random() * 100),
47
+ near = !a || !a.hi || a.hi.visible;
48
+ if (H.mesh.geometry !== (near ? H.near : H.far)) H.mesh.geometry = near ? H.near : H.far; // the far skin from a distance, as its rider's
49
+ F.x = a ? a.x : e[12];
50
+ F.y = a ? a.y : e[13];
51
+ F.z = a ? a.z : e[14];
52
+ F.yaw = a ? a.yaw : Math.atan2(e[8], e[10]);
53
+ F.s = Math.hypot(e[0], e[1], e[2]) || 1;
54
+ F.ground = a && a.fixY === null ? ground : null;
55
+ const u = Q.u,
56
+ brisk = sstep(0.04, 0.5, u),
57
+ run = sstep(1.2, 2.4, u),
58
+ still = 1 - brisk,
59
+ down = H.down || 0,
60
+ wheeling = Math.abs(a ? a.spin || Q.yawRate : Q.yawRate) > 0.35 ? 1 : 0,
61
+ easy = Math.min(1, dt * 4);
62
+ S[NECK] += (0.22 * run - 0.1 * sstep(0.6, 1.1, u) * (1 - run) + 0.1 * still * Math.sin(t * 0.21 + seed) - S[NECK]) * easy;
63
+ S[TAIL] += (0.75 * run + 0.2 * brisk - S[TAIL]) * easy;
64
+ S[EARS] += (0.6 * run - S[EARS]) * easy;
65
+ S[REST] += ((still > 0.9 && !wheeling && Math.sin(t * 0.11 + seed * 3) > 0.2 ? 1 : 0) - S[REST]) * Math.min(1, dt * 1.5);
66
+ S[DOWN] += (down - S[DOWN]) * Math.min(1, dt * 6);
67
+ S[GRAZE] += ((H.graze || 0) * still * (1 - wheeling) - S[GRAZE]) * Math.min(1, dt * 2);
68
+
69
+ // Alternate which hind leg rests across slow idle cycles so standing horses shift weight over time.
70
+ const restCycle = Math.floor((t * 0.11 + seed * 3 + Math.PI / 2) / TAU),
71
+ lazy = (restCycle + (seed > 50 ? 1 : 0)) % 2 ? 2 : 3,
72
+ restSide = lazy === 2 ? -1 : 1;
73
+
74
+ _equineParams.timeSeconds = t;
75
+ _equineParams.seed = seed;
76
+ _equineParams.still = still;
77
+ _equineParams.brisk = brisk;
78
+ _equineParams.run = run;
79
+ _equineParams.stridePhase = Q.ph;
80
+ _equineParams.yawRate = a ? a.spin || Q.yawRate : Q.yawRate;
81
+ _equineParams.turnLead = a && !Number.isNaN(a.turn) ? cycleDelta(a.yaw, a.turn, TAU) : 0;
82
+ _equineParams.restWeight = S[REST];
83
+ _equineParams.restSide = restSide;
84
+ const eq = solveEquineBearing(_equineParams);
85
+
86
+ // At a halt a horse rests one hind leg on its toe with settled hip weight; fallen, its legs lie loose.
87
+ const joints = Q.joints;
88
+ M.dy = -0.02 * Q.leg * S[REST];
89
+ M.roll = eq.hipRoll * (1 - S[DOWN]);
90
+ for (let k = 0; k < 4; k++) {
91
+ const leg = M.legs[k],
92
+ L = Q.legs[k],
93
+ len = L.len[0] + L.len[1] + L.len[2];
94
+ leg.w = 0;
95
+ if (k === lazy && S[REST] > 0.01) {
96
+ leg.w = S[REST];
97
+ leg.y = 0.012 * Q.leg;
98
+ leg.z = L.fz + 0.06 * Q.leg;
99
+ leg.a3 = 0.32;
100
+ leg.a4 = 0.75;
101
+ }
102
+ if (S[DOWN] > 0.01) {
103
+ leg.w = S[DOWN];
104
+ leg.y = joints[L.bone][1] - 0.78 * len;
105
+ leg.z = joints[L.bone][2] + (L.hind ? -0.3 : 0.34) * len + (k % 2 ? 0.1 : -0.06) * len;
106
+ leg.a3 = L.hind ? 0.35 : 0.5;
107
+ leg.a4 = 0.6;
108
+ }
109
+ }
110
+ stepRig(Q, F, dt, M);
111
+
112
+ // Neck and head: level over the body's rocking, nodding with stride and breath, leading rein turns, reaching out at a gallop.
113
+ const level = -(Q.pitch + B[BONE.chest].rotation.x) * 0.75,
114
+ nod =
115
+ brisk *
116
+ (0.045 * (1 - sstep(0.55, 0.75, u)) * Math.sin(Q.ph * TAU * 2 + 0.6) + 0.07 * sstep(1.2, 1.5, u) * Math.sin(Q.ph * TAU + 2.2)),
117
+ low = S[GRAZE],
118
+ awake = 1 - S[DOWN],
119
+ freeHead = (1 - low) * awake,
120
+ bend = H.grazeBend || GRAZE_BEND;
121
+ B[BONE.neck].rotation.set(
122
+ level * 0.6 + S[NECK] * 0.7 + nod + eq.neckPitch * freeHead + 0.5 * S[DOWN] + bend[0] * low,
123
+ eq.neckYaw * freeHead,
124
+ 0,
125
+ );
126
+ B[BONE.neck2].rotation.set(
127
+ level * 0.4 + S[NECK] * 0.3 + nod * 0.5 + eq.neck2Pitch * freeHead + bend[1] * low,
128
+ eq.neck2Yaw * (0.5 + 0.5 * freeHead),
129
+ 0,
130
+ );
131
+ B[BONE.head].rotation.set(
132
+ -S[NECK] * 0.9 - nod * 0.8 + eq.headPitch * freeHead + bend[2] * low,
133
+ eq.headYaw * (0.4 + 0.6 * freeHead),
134
+ eq.headRoll * freeHead,
135
+ );
136
+ B[BONE.jaw].rotation.x = 0.03 + 0.04 * still * sstep(0.7, 1, Math.sin(t * 0.7 + seed)) * (0.5 + 0.5 * Math.sin(t * 6));
137
+
138
+ // Ears: asynchronous listening swivels and independent flicks, laid back at a gallop.
139
+ B[BONE.earL].rotation.set(-S[EARS] + eq.earLeftPitch * awake, 0, eq.earLeftRoll * awake);
140
+ B[BONE.earR].rotation.set(-S[EARS] + eq.earRightPitch * awake, 0, eq.earRightRoll * awake);
141
+
142
+ // Tail: carried out behind at speed, phase-lagged wave swishing across its three segments.
143
+ B[BONE.tail].rotation.set(S[TAIL] * 0.55, eq.tailYaw0 * awake, 0);
144
+ B[BONE.tail + 1].rotation.set(S[TAIL] * 0.4 + 0.05 * run * Math.sin(Q.ph * TAU), eq.tailYaw1 * awake, 0);
145
+ B[BONE.tail + 2].rotation.set(S[TAIL] * 0.25, eq.tailYaw2 * awake, 0);
146
+ return Q.y * F.s;
147
+ }
148
+
149
+ const _p = new THREE.Vector3(),
150
+ _n = new THREE.Vector3();
151
+
152
+ // A beast's skin (its far one unless another is given) as it stands posed now, as a plain geometry of its own.
153
+ function castBeast(H, src = H.far) {
154
+ const mesh = H.mesh,
155
+ geo = new THREE.BufferGeometry(),
156
+ P = src.attributes.position,
157
+ N = src.attributes.normal,
158
+ n = P.count,
159
+ pos = new Float32Array(n * 3),
160
+ nor = new Int8Array(n * 3);
161
+ mesh.geometry = src;
162
+ mesh.updateMatrixWorld(true);
163
+ mesh.skeleton.update();
164
+ for (let i = 0; i < n; i++) {
165
+ // a normal goes through the bones as the point just off the skin does
166
+ _n.set(P.getX(i) + N.getX(i) * 0.01, P.getY(i) + N.getY(i) * 0.01, P.getZ(i) + N.getZ(i) * 0.01);
167
+ mesh.applyBoneTransform(i, _p.fromBufferAttribute(P, i));
168
+ mesh.applyBoneTransform(i, _n);
169
+ _n.sub(_p).normalize();
170
+ pos.set([_p.x, _p.y, _p.z], i * 3);
171
+ nor.set([Math.round(_n.x * 127), Math.round(_n.y * 127), Math.round(_n.z * 127)], i * 3);
172
+ }
173
+ geo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
174
+ geo.setAttribute('normal', new THREE.BufferAttribute(nor, 3, true));
175
+ geo.setAttribute('color', src.attributes.color);
176
+ if (src.attributes.aTag) geo.setAttribute('aTag', src.attributes.aTag);
177
+ return geo;
178
+ }
179
+
180
+ // A horse's stride at `speed` (metres a second) caught at `n` even moments, each a plain geometry, with how far one stride carries
181
+ // it: for a marching troop, which draws hundreds of horses from a handful of such moments (animal-troop-cast.js). At speed 0, one
182
+ // geometry of the horse standing; with `down`, one of it fallen. cast(H): what is kept of each moment (its far skin, castBeast).
183
+ // With each moment, what its rider sits: how far the back has risen (metres), how far it has pitched (radians) and the stride's
184
+ // phase there (0 to 1), as a ridden horse gives them.
185
+ function strideFrames(H, speed, n, down = false, cast = castBeast) {
186
+ const STEP = 1 / 240,
187
+ Q = H.rig,
188
+ mesh = H.mesh,
189
+ frames = [],
190
+ rises = [],
191
+ pitches = [],
192
+ phases = [];
193
+ let z = 0,
194
+ t = 0,
195
+ rise = 0;
196
+ const advance = () => {
197
+ z += speed * STEP;
198
+ t += STEP;
199
+ mesh.position.set(0, 0, z);
200
+ mesh.updateMatrixWorld(true);
201
+ rise = horsePose(H, STEP, t, speed);
202
+ };
203
+ const catchMoment = () => {
204
+ frames.push(cast(H));
205
+ rises.push(rise);
206
+ pitches.push(Q.pitch);
207
+ phases.push(Q.ph);
208
+ };
209
+ H.down = down ? 1 : 0;
210
+ Q.px = null;
211
+ for (let i = 0; i < 720; i++) advance(); // long enough to settle into the gait
212
+ if (!speed) catchMoment();
213
+ else
214
+ for (let k = 0; k < n; k++) {
215
+ // on to the moment the stride's phase reaches k / n (the phase wraps at 1)
216
+ const ahead = () => (Q.ph - k / n + 1.5) % 1 >= 0.5;
217
+ for (let guard = 0; guard < 2400 && ahead(); guard++) advance();
218
+ for (let guard = 0; guard < 2400 && !ahead(); guard++) advance();
219
+ catchMoment();
220
+ }
221
+ H.down = 0;
222
+ mesh.position.set(0, 0, 0);
223
+ return { frames, rises, pitches, phases, stride: (Q.gait.travel * Q.leg) / Q.gait.duty };
224
+ }
225
+
226
+ // A beast's geometries for a crowd's herd (animal-herd-cast.js): standing with its head at `steps` + 1 even heights from up to down at the
227
+ // grass, and the moments of its walk at `speed` (metres a second); cast as strideFrames says.
228
+ function herdFrames(H, speed, moments, steps = 4, cast = castBeast) {
229
+ const S = H.s,
230
+ heads = [];
231
+ H.graze = 1;
232
+ H.rig.px = null;
233
+ H.mesh.position.set(0, 0, 0);
234
+ H.mesh.updateMatrixWorld(true);
235
+ let t = 0;
236
+ for (let i = 0; i < 400; i++) horsePose(H, 1 / 60, (t += 1 / 60), 0); // settled at graze: its weight off a hind leg
237
+ for (let k = 0; k <= steps; k++) {
238
+ S[GRAZE] = k / steps;
239
+ horsePose(H, 0, t, 0); // no time passes: only the head goes down
240
+ heads.push(cast(H));
241
+ }
242
+ H.graze = 0;
243
+ S[GRAZE] = 0;
244
+ return { heads, walk: strideFrames(H, speed, moments, false, cast) };
245
+ }
246
+
247
+ export { castBeast, herdFrames, horsePose, strideFrames };
@@ -0,0 +1,178 @@
1
+ import { clamp, sstep, TAU } from '../math/scalar.js';
2
+ import { BONE, LEGS, stepRig } from './quadruped.js';
3
+
4
+ // ════════════════════════════════════════════════════════════════════════
5
+ // A canine's bearing: what its body does on top of its gait (motion/quadruped.js moves the legs). It crouches before a
6
+ // spring and stretches through it, sits, lies down, lies dead; its head goes to what holds its attention; its jaw
7
+ // pants, snarls and bites; its ears, hackles and tail say the rest.
8
+ // ════════════════════════════════════════════════════════════════════════
9
+ const CROUCH = 0, // the channels of a canine's bearing, each eased towards its target
10
+ SIT = 1,
11
+ LIE = 2,
12
+ LIMP = 3,
13
+ REACH = 4,
14
+ SNARL = 5,
15
+ NECK_X = 6,
16
+ NECK_Y = 7,
17
+ JAW = 8,
18
+ TAIL = 9,
19
+ EARS = 10,
20
+ CHANNELS = 11,
21
+ SIT_BACK = 0.78, // how far the back tips up when a dog sits, radians
22
+ _want = new Float32Array(CHANNELS),
23
+ _manner = { dy: 0, dz: 0, pitch: 0, hips: 0, chest: 0, legs: [0, 1, 2, 3].map(() => ({ y: 0, z: 0, a3: 0, a4: 0, w: 0 })) },
24
+ _frame = { x: 0, y: 0, z: 0, yaw: 0, s: 1, ground: null };
25
+
26
+ // Takes a foot off the ground towards a place of its own, by weight w; several such claims on one foot are averaged.
27
+ function hold(leg, w, y, z, a3, a4) {
28
+ if (w <= 0) return;
29
+ const k = w / (leg.w + w);
30
+ leg.y += (y - leg.y) * k;
31
+ leg.z += (z - leg.z) * k;
32
+ leg.a3 += (a3 - leg.a3) * k;
33
+ leg.a4 += (a4 - leg.a4) * k;
34
+ leg.w = Math.min(1, leg.w + w);
35
+ }
36
+
37
+ // Where the head should turn to, as a turn of the neck to the side: towards the place it watches ({ x, z }), if it is in sight.
38
+ function gazeYaw(a, F) {
39
+ if (!F) return null;
40
+ const dx = F.x - a.x,
41
+ dz = F.z - a.z;
42
+ if (dx * dx + dz * dz < 2) return null;
43
+ let dy = Math.atan2(dx, dz) - a.yaw;
44
+ dy -= Math.round(dy / TAU) * TAU;
45
+ return Math.abs(dy) < 1.9 ? clamp(dy, -1, 1) : null;
46
+ }
47
+
48
+ /**
49
+ * Poses a canine for this frame, on top of its gait: crouching, springing, sitting, lying, lying dead, its head to what it
50
+ * watches, its jaw, lips, ears, hackles and tail.
51
+ * @param {object} a The animal: its rig (`canineRig`, with `u` its speed against its legs), group, place (x, y, z), yaw, seed,
52
+ * pose ('prowl', 'guard', 'strike', 'cower', 'sit', 'kneel' or 'dead') and fixY (null while its feet follow the ground).
53
+ * @param {number} dt Seconds since the last frame.
54
+ * @param {number} t Seconds of the clock.
55
+ * @param {{ w: number, cr: number, reach: number, jaw: number, worry: number } | null} blow A blow being struck, by weight w: cr a
56
+ * crouch, reach a spring's stretch, jaw a bite, worry the shaking of what it has caught.
57
+ * @param {((x: number, z: number) => number) | null} [ground] The ground's height, for feet that follow it; null to stand on y.
58
+ * @param {{ x: number, z: number } | null} [watch] What it looks at. Defaults to `a.lookAt`.
59
+ * @returns {number} How far its group should rise: nothing, since the body rises on its own legs.
60
+ */
61
+ function caninePose(a, dt, t, blow, ground = null, watch = a.lookAt) {
62
+ const Q = a.rig,
63
+ B = Q.bones,
64
+ joints = Q.joints,
65
+ h = Q.leg,
66
+ S = a.hs || (a.hs = new Float32Array(CHANNELS)),
67
+ W = _want,
68
+ M = _manner,
69
+ pose = a.pose,
70
+ dead = pose === 'dead',
71
+ wary = pose === 'prowl' || pose === 'guard' || pose === 'strike',
72
+ fx = blow ? blow.w : 0,
73
+ worry = blow ? blow.worry * fx : 0,
74
+ run = sstep(0.9, 1.7, Q.u || 0),
75
+ brisk = sstep(0.05, 0.6, Q.u || 0);
76
+ W[CROUCH] = Math.max(pose === 'prowl' ? 0.35 : pose === 'cower' ? 0.6 : 0, blow ? blow.cr * fx : 0);
77
+ W[SIT] = pose === 'sit' ? 1 : 0;
78
+ W[LIE] = pose === 'kneel' ? 1 : 0;
79
+ W[LIMP] = dead ? 1 : 0;
80
+ W[REACH] = blow ? blow.reach * fx : 0;
81
+ W[SNARL] = dead ? 0.3 : Math.max(Q.breed.leer, wary ? 0.8 : 0, blow ? Math.max(blow.cr, blow.jaw) * fx : 0);
82
+ // the head: low and forward on the hunt and at a run, turned to what it watches when it stands
83
+ const look = dead || brisk > 0.5 ? null : gazeYaw(a, watch),
84
+ idle = Math.sin(t * 0.37 + a.seed * 30) * 0.3 * (1 - brisk);
85
+ W[NECK_Y] = look === null ? idle : idle * 0.25 + look * 0.75;
86
+ W[NECK_X] = dead
87
+ ? 0.5
88
+ : 0.3 * run + (pose === 'prowl' ? 0.45 : 0) + 0.35 * W[CROUCH] - 0.2 * W[REACH] + 0.5 * worry + (pose === 'cower' ? 0.3 : 0);
89
+ const pant = run > 0.3 ? 0.2 + 0.05 * Math.sin(t * 15 + a.seed * 9) : 0;
90
+ W[JAW] = dead ? 0.3 : Math.max(pant, W[SNARL] * 0.14, blow ? blow.jaw * fx * 0.85 : 0) * (1 - 0.7 * worry);
91
+ W[TAIL] = dead ? 0 : pose === 'cower' ? -0.6 : 0.85 * run + 0.25 * brisk + (wary ? 0.45 : 0) + 0.5 * W[REACH];
92
+ W[EARS] = dead ? 0.4 : Math.max(W[SNARL], run * 0.8, pose === 'cower' ? 1 : 0);
93
+ const quick = Math.min(1, dt * (blow ? 20 : 5));
94
+ for (let i = 0; i < CHANNELS; i++) S[i] += (W[i] - S[i]) * quick;
95
+
96
+ // the body's manner, and the feet it takes off the ground
97
+ const sit = S[SIT],
98
+ lie = S[LIE],
99
+ limp = S[LIMP],
100
+ reach = S[REACH],
101
+ tip = -SIT_BACK * sit,
102
+ sy = joints[LEGS[0]][1] - joints[0][1], // the shoulders from the root: a sitting dog turns about them
103
+ sz = joints[LEGS[0]][2] - joints[0][2],
104
+ floor = joints[LEGS[0] + 1][1] - 0.06 * h; // how far the chest is from the ground
105
+ M.pitch = tip + 0.1 * S[CROUCH] * (1 - limp) - 0.3 * reach;
106
+ M.dy = -0.26 * h * S[CROUCH] - floor * lie - (sy * Math.cos(tip) - sz * Math.sin(tip) - sy) - (a.cur ? a.cur[6] : 0);
107
+ M.dz = -(sy * Math.sin(tip) + sz * Math.cos(tip) - sz) + 0.12 * h * reach;
108
+ M.chest = -0.22 * reach + 0.1 * Math.sin(t * 29) * worry;
109
+ M.hips = 0.2 * reach;
110
+ const rootY = joints[0][1] + M.dy,
111
+ rootZ = joints[0][2] + M.dz;
112
+ for (let k = 0; k < 4; k++) {
113
+ const leg = M.legs[k],
114
+ hind = k > 1,
115
+ L = Q.legs[k],
116
+ // the leg's pivot as the body will carry it
117
+ oy = joints[L.bone][1] - joints[0][1],
118
+ oz = joints[L.bone][2] - joints[0][2],
119
+ py = rootY + oy * Math.cos(M.pitch) - oz * Math.sin(M.pitch),
120
+ pz = rootZ + oy * Math.sin(M.pitch) + oz * Math.cos(M.pitch),
121
+ len = L.len[0] + L.len[1] + L.len[2],
122
+ odd = k % 2 ? 1 : -1;
123
+ leg.w = 0;
124
+ // sitting and lying, the hocks are on the ground with the paws ahead of them; lying, so are the forearms
125
+ if (hind) hold(leg, Math.max(sit, lie), 0, pz + 0.3 * h + odd * 0.02 * h, -1.25, 0);
126
+ else hold(leg, lie, 0, pz + 0.52 * h + odd * 0.03 * h, -1.3, 0);
127
+ // a spring: the forelegs thrown forward, the hind legs trailing
128
+ if (hind) hold(leg, reach, py - 0.5 * len, pz - 0.82 * len, 0.5, 0.9);
129
+ else hold(leg, reach, py - 0.42 * len, pz + 0.78 * len + odd * 0.05 * len, -0.25, 0.3);
130
+ // dead on its side: the legs lie loose
131
+ if (hind) hold(leg, limp, py - 0.82 * len, pz - (0.25 + odd * 0.12) * len, 0.3, 0.6);
132
+ else hold(leg, limp, py - 0.8 * len, pz + (0.3 + odd * 0.14) * len, 0.25, 0.7);
133
+ }
134
+ const F = _frame,
135
+ free = a.fixY === null || a.fixY === undefined;
136
+ F.x = a.x;
137
+ F.y = a.y;
138
+ F.z = a.z;
139
+ F.yaw = a.yaw;
140
+ F.s = a.group.scale.y;
141
+ F.ground = free && !dead ? ground : null;
142
+ stepRig(Q, F, dt, M);
143
+
144
+ // neck and head, kept level over whatever the body does
145
+ const level = -(Q.pitch + B[BONE.chest].rotation.x) * 0.8,
146
+ nx = S[NECK_X],
147
+ ny = S[NECK_Y],
148
+ nod = 0.04 * brisk * (1 - run) * Math.sin(Q.ph * TAU * 2),
149
+ shake = worry ? Math.sin(t * 29) * 0.4 * worry : 0;
150
+ B[BONE.neck].rotation.set(level * 0.6 + nx * 0.6 + nod, ny * 0.35 + shake * 0.3, 0);
151
+ B[BONE.neck2].rotation.set(level * 0.4 + nx * 0.4, ny * 0.35 + shake * 0.3, 0);
152
+ B[BONE.head].rotation.set(-nx * 0.45 - nod * 0.5 + 0.25 * limp, ny * 0.4 + shake * 0.5, shake * 0.3 + ny * 0.12 + Q.breed.tilt);
153
+ B[BONE.jaw].rotation.x = S[JAW];
154
+ // lips lifted off the teeth, ears laid back, hackles up
155
+ const snarl = S[SNARL],
156
+ lip = joints[BONE.lip],
157
+ head = joints[BONE.head],
158
+ crest = joints[BONE.crest],
159
+ chest = joints[BONE.chest];
160
+ B[BONE.lip].position.set(lip[0] - head[0], lip[1] - head[1] + snarl * 0.02 * Q.breed.head * h, lip[2] - head[2]);
161
+ B[BONE.crest].position.set(0, crest[1] - chest[1] + snarl * 0.045 * h, crest[2] - chest[2] + snarl * 0.02 * h);
162
+ const twitch = sstep(0.96, 1, Math.sin(t * 0.9 + a.seed * 40)) * Math.sin(t * 30) * 0.2;
163
+ B[BONE.earL].rotation.set(-0.9 * S[EARS] + twitch, 0, 0.25 * S[EARS]);
164
+ B[BONE.earR].rotation.set(-0.9 * S[EARS], 0, -0.25 * S[EARS]);
165
+ // the tail: streaming behind at a run, up when it threatens, tucked when it cowers; it sways, each joint after the last
166
+ const lift = S[TAIL],
167
+ sway = (0.16 * (1 - run) + 0.08) * (1 - limp),
168
+ beat = t * (1.7 + 2.5 * brisk) + a.seed * 20;
169
+ for (let i = 0; i < 3; i++)
170
+ B[BONE.tail + i].rotation.set(
171
+ lift * (i ? 0.25 : 0.7) + 0.06 * run * Math.sin(Q.ph * TAU - i),
172
+ sway * Math.sin(beat - i * 0.9) * (1 + i * 0.4),
173
+ 0,
174
+ );
175
+ return 0;
176
+ }
177
+
178
+ export { caninePose };
@@ -0,0 +1,131 @@
1
+ import * as THREE from 'three';
2
+ import { geometryOf } from '../geometry/builder.js';
3
+ import { NO_ANIMAL_OPTIONS } from '../geometry/animal-options.js';
4
+ import { canineBodies, canineRig } from '../geometry/animal-canine-body.js';
5
+ import { caninePose } from './animal-canine-bearing.js';
6
+ import { castBeast } from './animal-bearing.js';
7
+ import { BONE, bindRig } from './quadruped.js';
8
+
9
+ // ════════════════════════════════════════════════════════════════════════
10
+ // A herd's canine (a street dog, a cat: a breed on the four-legged skeleton, geometry/animal-canine-body.js) cast as still poses for
11
+ // the crowds (animal-herd-cast.js), as the rats of a swarm are: its walk at the herd's pace caught at even moments, and its rests at a halt, each a
12
+ // series from standing to the full of it: nosing at the ground, sitting, lying down. Arithmetic only, so a pool's workers can cast it.
13
+ // Cast at the skeleton's own size (a canine's withers WITHERS model units high); the crowd draws it at its own.
14
+ // ════════════════════════════════════════════════════════════════════════
15
+ const STEP = 1 / 240, // seconds a step of the cast
16
+ SETTLE = 720, // steps to settle into a gait or a stand
17
+ STEPS = 4, // poses after standing in each rest's series
18
+ SIT_FULL = 0.97, // the share of its sit (or lie) at which a canine counts as down: its bearing eases there and never quite arrives
19
+ BEARING = { sit: 'sit', lie: 'kneel' }, // the bearing (animal-canine-bearing.js) each rest is cast from
20
+ MIDDLE = 1, // the detail of a herd canine's near skin (canineBodies): finer rings than its far skin, without a figure's locks and teeth
21
+ // nosing at the ground: how far the neck's two joints and the head bow at the full of it, radians
22
+ SNIFF = { neck: 0.95, neck2: 0.55, head: 0.35 };
23
+
24
+ // The canine's skins [far, middle] on its skeleton, standing at the origin on level ground, with what moves it.
25
+ function rigged(look, options) {
26
+ const bodies = canineBodies(look, MIDDLE, true, options).map(arrays => geometryOf(arrays)), // ears on both faces: a herd's material shows one
27
+ { rig } = canineRig(look, options),
28
+ mesh = new THREE.SkinnedMesh(bodies[1]),
29
+ group = new THREE.Group();
30
+ bindRig(mesh, rig);
31
+ group.add(mesh);
32
+ return {
33
+ H: { mesh, near: bodies[1], far: bodies[0] },
34
+ a: { rig, pose: 'idle', seed: 0.41, x: 0, y: 0, z: 0, yaw: 0, group, fixY: 0, cur: null, hs: null },
35
+ };
36
+ }
37
+
38
+ // One step of the cast: the canine moved on `ahead` metres and posed.
39
+ function step(c, ahead, t) {
40
+ c.a.z += ahead;
41
+ c.a.group.position.z = c.a.z;
42
+ caninePose(c.a, STEP, t, null);
43
+ c.a.group.updateMatrixWorld(true);
44
+ }
45
+
46
+ // Its walk at `speed` (metres a second at the skeleton's size) caught at n even moments of its stride, and the metres one stride covers.
47
+ function walkOf(c, speed, n, cast) {
48
+ const Q = c.a.rig,
49
+ frames = [];
50
+ let t = 0,
51
+ turned = 0;
52
+ const advance = () => {
53
+ const ph = Q.ph;
54
+ step(c, speed * STEP, (t += STEP));
55
+ turned += (Q.ph - ph + 1) % 1;
56
+ };
57
+ for (let i = 0; i < SETTLE; i++) advance();
58
+ turned = 0;
59
+ for (let i = 0; i < SETTLE; i++) advance();
60
+ const stride = (speed * SETTLE * STEP) / turned;
61
+ for (let k = 0; k < n; k++) {
62
+ // on to the moment the stride's phase reaches k / n (the phase wraps at 1)
63
+ const ahead = () => (Q.ph - k / n + 1.5) % 1 >= 0.5;
64
+ for (let guard = 0; guard < 2400 && ahead(); guard++) advance();
65
+ for (let guard = 0; guard < 2400 && !ahead(); guard++) advance();
66
+ frames.push(cast());
67
+ }
68
+ return { frames, stride };
69
+ }
70
+
71
+ // It stands still: settled on its feet with its bearing at rest.
72
+ function stand(c) {
73
+ c.a.pose = 'idle';
74
+ c.a.hs = null;
75
+ for (let i = 0; i < SETTLE; i++) step(c, 0, i * STEP);
76
+ }
77
+
78
+ // A rest's series: standing, then STEPS poses on to the full of it.
79
+ function restOf(c, rest, cast) {
80
+ stand(c);
81
+ const series = [cast()],
82
+ B = c.a.rig.bones;
83
+ if (rest === 'sniff') {
84
+ const base = [B[BONE.neck].rotation.x, B[BONE.neck2].rotation.x, B[BONE.head].rotation.x];
85
+ for (let k = 1; k <= STEPS; k++) {
86
+ const f = k / STEPS;
87
+ B[BONE.neck].rotation.x = base[0] + SNIFF.neck * f;
88
+ B[BONE.neck2].rotation.x = base[1] + SNIFF.neck2 * f;
89
+ B[BONE.head].rotation.x = base[2] + SNIFF.head * f;
90
+ c.a.group.updateMatrixWorld(true);
91
+ series.push(cast());
92
+ }
93
+ return series;
94
+ }
95
+ // sitting or lying down: its bearing eases into it, caught as it passes each step of the way
96
+ const channel = rest === 'sit' ? 1 : 2;
97
+ c.a.pose = BEARING[rest];
98
+ let t = 0;
99
+ for (let k = 1; k <= STEPS; k++)
100
+ for (let guard = 0; guard < 2400; guard++) {
101
+ step(c, 0, (t += STEP));
102
+ if (c.a.hs[channel] >= (SIT_FULL * k) / STEPS) {
103
+ series.push(cast());
104
+ break;
105
+ }
106
+ }
107
+ return series;
108
+ }
109
+
110
+ /**
111
+ * A canine of `look` for a herd (motion/animal-herd-cast.js): its skins [middle, far], a skin cast as it stands now, and its rests
112
+ * and walk cast as `cast` says.
113
+ * @param {{ look: object, size: number, speed: number, moments: number, rests: string[] }} input look: its look (`canineBodies`);
114
+ * size: the crowd's size of it (its withers against WITHERS model units); speed: the herd's pace, metres a second at that size;
115
+ * moments: how many moments of its walk are cast; rests: what it does at a halt ('sniff', 'sit' or 'lie').
116
+ * @param {import('../geometry/animal-options.js').AnimalKitOptions} [options]
117
+ */
118
+ function canineHerd({ look, size, speed, moments, rests }, options = NO_ANIMAL_OPTIONS) {
119
+ const c = rigged(look, options);
120
+ return {
121
+ skins: [c.H.near, c.H.far],
122
+ skin: k => castBeast(c.H, k ? c.H.far : c.H.near),
123
+ // the pace at the skeleton's size that is the same gait as `speed` at the crowd's (a gait goes by speed over the root of size)
124
+ frames: cast => {
125
+ const walk = walkOf(c, speed / Math.sqrt(size), moments, cast);
126
+ return { rests: rests.map(rest => restOf(c, rest, cast)), walk };
127
+ },
128
+ };
129
+ }
130
+
131
+ export { canineHerd };
@@ -0,0 +1,64 @@
1
+ import * as THREE from 'three';
2
+ import { NO_ANIMAL_OPTIONS, cachePerOptions } from '../geometry/animal-options.js';
3
+ import { buildCattle } from '../rendering/animal-cattle-figure.js';
4
+ import { castBeast, horsePose } from './animal-bearing.js';
5
+ import { BONE, LEGS } from './quadruped.js';
6
+
7
+ // ════════════════════════════════════════════════════════════════════════
8
+ // Cattle and sheep as plain geometry, cast from a beast on its skeleton (rendering/animal-cattle-figure.js) after a few moments of standing or
9
+ // grazing, so that it stands as cattle stand: weight off a hind leg, ears and tail at rest. One model of each build is made
10
+ // where it is first wanted (the page, or a worker casting a land's herds), for each world's options: its near skin for the beasts close
11
+ // by, its far one for the rest. Nothing here touches the page, so a worker can do all of it.
12
+ // ════════════════════════════════════════════════════════════════════════
13
+ const modelsOf = cachePerOptions(),
14
+ // A dead beast is laid on its left side by whoever places it (rolled about its length, its right side up): its legs then go
15
+ // out level over the ground, so the ones underneath lie a little bent towards it and the ones on top sag down onto them, and
16
+ // its head is turned on its neck, so the horn beneath lies along the ground instead of through it. Radians about its length.
17
+ DEAD = { under: -0.12, over: -0.5, head: -1.05 },
18
+ LENGTH = new THREE.Vector3(0, 0, 1), // the body's length, nose-wards
19
+ _turn = new THREE.Quaternion();
20
+ const cattleModel = (build, options) => (modelsOf(options)[build] ??= buildCattle(build, [2, 0], options));
21
+
22
+ /**
23
+ * A beast of the build as one plain geometry, facing +z on y = 0, its head down at the grass or up.
24
+ * @param {boolean} grazing Its head down at the grass.
25
+ * @param {boolean} far The lighter copy.
26
+ * @param {string} build Its build's name (`buildCattle`).
27
+ * @param {boolean} [fallen] Dead, its legs loose, to be laid on its left side by whoever places it (rolled about its length).
28
+ * @param {import('../geometry/animal-options.js').AnimalKitOptions} [options]
29
+ * @returns {THREE.BufferGeometry}
30
+ */
31
+ function castCattle(grazing, far, build, fallen = false, options = NO_ANIMAL_OPTIONS) {
32
+ const H = cattleModel(build, options);
33
+ H.graze = grazing ? 1 : 0;
34
+ H.down = fallen ? 1 : 0;
35
+ H.rig.px = null;
36
+ H.rig.seed = grazing ? 3.1 : 7.3; // which leg it rests and where its ears are: the same on every visit
37
+ H.mesh.updateMatrixWorld(true);
38
+ for (let i = 0, t = grazing ? 17 : 41; i < 40; i++) horsePose(H, 0.1, (t += 0.1), 0);
39
+ if (fallen) layOnSide(H.rig.bones);
40
+ const geo = castBeast(H, far ? H.far : H.near);
41
+ H.down = 0;
42
+ return geo;
43
+ }
44
+
45
+ function layOnSide(bones) {
46
+ // each leg swung about the body's length at its top joint; the left legs (even) are the ones underneath
47
+ LEGS.forEach((bone, k) => bones[bone].quaternion.premultiply(_turn.setFromAxisAngle(LENGTH, k % 2 ? DEAD.over : DEAD.under)));
48
+ bones[BONE.head].quaternion.premultiply(_turn.setFromAxisAngle(LENGTH, DEAD.head));
49
+ }
50
+
51
+ // The engine's static builder layout, by attribute name. The page binds the compact arrays
52
+ // without loading the skeleton or retaining an extra copy of their positions after upload.
53
+ const arraysOf = geo => Object.fromEntries(Object.entries(geo.attributes).map(([name, attribute]) => [name, attribute.array]));
54
+
55
+ /**
56
+ * A worker's job: the casts of one build, each [grazing, far], as arrays by attribute name in the same order. Casts of one skin
57
+ * share its colours.
58
+ * @param {{ build: string, casts: boolean[][] }} spec
59
+ * @param {import('../geometry/animal-options.js').AnimalKitOptions} [options]
60
+ */
61
+ const castArrays = ({ build, casts }, options = NO_ANIMAL_OPTIONS) =>
62
+ casts.map(([grazing, far]) => arraysOf(castCattle(grazing, far, build, false, options)));
63
+
64
+ export { castArrays, castCattle };