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,446 @@
1
+ import * as THREE from 'three';
2
+ import { lerp, sstep } from '../math/scalar.js';
3
+ import { C } from './primitives.js';
4
+ import { GB, geometryOf } from './builder.js';
5
+ import { indexParts } from './index-parts.js';
6
+ import { NO_ANIMAL_OPTIONS, animalNoise, presetOf } from './animal-options.js';
7
+ import { tube } from './animal-skin.js';
8
+ import { ear, eyeWithLids } from './animal-horse-face.js';
9
+ import { MEALY, SLEEK, coatOf, codedCoat, skinOf } from './animal-horse-coat.js';
10
+ import { forelock, hair } from './animal-horse-hair.js';
11
+ import { tackUp } from './animal-horse-tack.js';
12
+ import { EYE, MOUTH, boneUnder, headSkin, headStations } from './animal-horse-head.js';
13
+ import { BONE, LEGS } from '../motion/quadruped.js';
14
+
15
+ // ════════════════════════════════════════════════════════════════════════
16
+ // A horse, built on the four-legged skeleton (motion/quadruped.js): nose to +z, hooves at y 0. The body is laid out in
17
+ // withers heights (the withers at 1) and scaled to its size: a riding horse stands 1.5 m at the withers, a noble's taller and
18
+ // finer, a draught horse heavy, with feathered heels, a mule smaller with long ears; a world adds builds of its own (a hardy
19
+ // pony of the steppe, say) as rows of the same numbers. Its coat's colours are worked out in animal-horse-coat.js, its mane and
20
+ // tail in animal-horse-hair.js. Arithmetic only, so a pool's workers can build a rider's horse ahead of need;
21
+ // rendering/animal-horse-figure.js puts it on its bones.
22
+ // ════════════════════════════════════════════════════════════════════════
23
+ const WITHERS = 1.5, // a riding horse's withers, metres
24
+ SEAT = 1.02, // the saddle's seat, in withers heights
25
+ HORN = [0.05, 0.045, 0.04],
26
+ NOSTRIL = [0.025, 0.006, 0.376], // a nostril's middle in the head, in head lengths: to the side, up, forward
27
+ DARK = [0.03, 0.026, 0.024],
28
+ SMOOTH = 1,
29
+ zF = 0.36, // where the fore hooves stand along the body,
30
+ zH = -0.42; // and the hind ones
31
+
32
+ // Lengths in withers heights. size: against a riding horse; girth, bone: the barrel's and the legs' thickness; neck: [length,
33
+ // thickness, carriage 0 level to 1 upright]; head, ear: their size; mane, tail: the hair's length; feather: hair at the heels; a mule
34
+ // also has chest: the breast's width against a horse's; upright: a short mane standing up off the crest; tuft: a thin tail with its
35
+ // long hair only below; mealy: pale points (muzzle, eyes, belly).
36
+ /** The horse builds the kit knows, by name: `riding`, `fine`, `draught` and `mule`; a world passes rows of its own in
37
+ * `horseBuilds` (geometry/animal-options.js), each the same numbers. */
38
+ export const HORSE_BUILDS = {
39
+ riding: { size: 1, girth: 1, bone: 1, neck: [1, 1, 0.52], head: 1.1, ear: 1.15, mane: 1, tail: 1, feather: 0 },
40
+ fine: { size: 1.05, girth: 0.94, bone: 0.9, neck: [1.08, 0.9, 0.72], head: 1.02, ear: 1.1, mane: 0.9, tail: 1.1, feather: 0 },
41
+ draught: { size: 1.08, girth: 1.22, bone: 1.4, neck: [0.95, 1.32, 0.48], head: 1.24, ear: 1.1, mane: 1.25, tail: 1, feather: 1.3 },
42
+ mule: {
43
+ ...{ size: 0.9, girth: 0.94, bone: 0.92, neck: [0.95, 0.92, 0.42], head: 1.22, ear: 2.1, mane: 1, tail: 0.85, feather: 0 },
44
+ ...{ chest: 0.84, upright: 1, tuft: 1, mealy: 1 },
45
+ },
46
+ };
47
+
48
+ // How a horse's legs go, and its gaits: [speed against leg length, stance travel, duty, footfalls (fore left, fore right, hind left,
49
+ // hind right), rise, lift, flex] (motion/quadruped.js): a walk of four beats, a trot on the diagonals, a canter of three beats on the right
50
+ // lead, a gallop of four with one flight.
51
+ const HABITS = {
52
+ fore: { follow: 1, heel3: 0.12, fold3: 1.2, heel4: 0.85, fold4: 0.7, sink: 0.2, glide: 0.12 },
53
+ // paired: the stifle and hock bend together, the cannon kept about parallel to the thigh, which swings at most thigh radians
54
+ // forward of its rest (motion/quadruped.js pairedLeg)
55
+ hind: { follow: 0.62, heel3: 0.3, fold3: 0.2, heel4: 0.8, fold4: 0.6, sink: 0.18, glide: 0, paired: true, thigh: 0.55 },
56
+ crouch: 0.03,
57
+ gaits: [
58
+ [0.08, 0.55, 0.68, [0.25, 0.75, 0, 0.5], 0.015, 0.06, 0.02],
59
+ [0.5, 0.78, 0.62, [0.25, 0.75, 0, 0.5], 0.02, 0.09, 0.02],
60
+ [0.7, 0.78, 0.46, [0.5, 0, 0, 0.5], 0.07, 0.12, 0.02],
61
+ [1.15, 0.88, 0.38, [0.5, 0, 0, 0.5], 0.09, 0.16, 0.03],
62
+ [1.4, 0.88, 0.36, [0.28, 0.56, 0, 0.28], 0.1, 0.17, 0.12],
63
+ [2.1, 0.95, 0.32, [0.28, 0.56, 0, 0.28], 0.11, 0.2, 0.18],
64
+ [2.6, 0.93, 0.27, [0.38, 0.52, 0, 0.12], 0.1, 0.22, 0.24],
65
+ [3.8, 0.97, 0.22, [0.38, 0.52, 0, 0.12], 0.1, 0.24, 0.3],
66
+ ],
67
+ };
68
+
69
+ // Where the joints are, in withers heights: [y, z] in the body's upright plane.
70
+ function anatomy(p) {
71
+ const carriage = lerp(0.35, 1.05, p.neck[2]),
72
+ reach = 0.5 * p.neck[0],
73
+ neck = [0.86, zF + 0.14];
74
+ return {
75
+ sx: 0.105 * p.girth * (p.chest ?? 1),
76
+ hx: 0.11 * p.girth,
77
+ shoulder: [0.67, zF + 0.13],
78
+ elbow: [0.57, zF - 0.02],
79
+ knee: [0.31, zF],
80
+ fetlock: [0.105, zF],
81
+ hoof: [0, zF + 0.048],
82
+ // the stifle high against the flank, a little ahead of the hoof; the gaskin sloping back from it to a hock under the
83
+ // buttock at about the front knee's height; the cannon near upright and the pastern sloping forward to the hoof
84
+ hip: [0.8, zH + 0.02],
85
+ stifle: [0.63, zH + 0.13],
86
+ hock: [0.37, zH - 0.1],
87
+ hindFetlock: [0.105, zH - 0.065],
88
+ hindHoof: [0, zH - 0.02],
89
+ neck,
90
+ poll: [neck[0] + reach * Math.sin(carriage), neck[1] + reach * Math.cos(carriage)],
91
+ dock: [0.95, zH - 0.19],
92
+ hands: [1.09, zF - 0.05], // where a rider's hands hold the reins, over the withers
93
+ };
94
+ }
95
+
96
+ // The bones' joints and the hooves, in metres.
97
+ function jointsAt(A, p, K, headAt) {
98
+ const at = (x, q) => [x * K, q[0] * K, q[1] * K],
99
+ k = p.head,
100
+ joints = [];
101
+ joints[BONE.root] = at(0, [0.88, -0.04]);
102
+ joints[BONE.hips] = at(0, [0.9, -0.14]);
103
+ joints[BONE.chest] = at(0, [0.9, 0.02]);
104
+ joints[BONE.neck] = at(0, A.neck);
105
+ joints[BONE.neck2] = at(0, [(A.neck[0] + A.poll[0]) / 2, (A.neck[1] + A.poll[1]) / 2]);
106
+ joints[BONE.head] = at(0, A.poll);
107
+ joints[BONE.jaw] = headAt(0, -0.05 * k, 0.1 * k);
108
+ joints[BONE.earL] = headAt(-0.04 * k, 0.045 * k, 0.012 * k);
109
+ joints[BONE.earR] = headAt(0.04 * k, 0.045 * k, 0.012 * k);
110
+ joints[BONE.lip] = headAt(0, -0.02 * k, 0.37 * k);
111
+ [-1, 1].forEach((s, i) => {
112
+ const f = LEGS[i],
113
+ h = LEGS[i + 2];
114
+ joints[f] = at(s * A.sx, A.shoulder);
115
+ joints[f + 1] = at(s * A.sx, A.elbow);
116
+ joints[f + 2] = at(s * A.sx, A.knee);
117
+ joints[f + 3] = at(s * A.sx, A.fetlock);
118
+ joints[h] = at(s * A.hx, A.hip);
119
+ joints[h + 1] = at(s * A.hx, A.stifle);
120
+ joints[h + 2] = at(s * A.hx, A.hock);
121
+ joints[h + 3] = at(s * A.hx, A.hindFetlock);
122
+ });
123
+ joints[BONE.tail] = at(0, A.dock);
124
+ joints[BONE.tail + 1] = at(0, [A.dock[0] - 0.1, A.dock[1] - 0.07]);
125
+ joints[BONE.tail + 2] = at(0, [A.dock[0] - 0.34, A.dock[1] - 0.1]);
126
+ joints[BONE.crest] = at(0, A.hands); // the horse has no crest to raise: this bone carries the reins' ends, in the rider's hands
127
+ return { joints, feet: [at(-A.sx, A.hoof), at(A.sx, A.hoof), at(-A.hx, A.hindHoof), at(A.hx, A.hindHoof)] };
128
+ }
129
+
130
+ // The trunk's stations, from the buttocks over the croup, the loin and the barrel to the withers, then up the neck to the poll.
131
+ function trunkStations(A, p) {
132
+ const g = p.girth,
133
+ nt = p.neck[1],
134
+ breast = z => lerp(1, p.chest ?? 1, sstep(zF - 0.3, zF, z)), // a mule narrow at the breast
135
+ ring = (z, top, bottom, w, bone, sq = 2.25) => [
136
+ (top + bottom) / 2,
137
+ z,
138
+ w * g * breast(z),
139
+ (top - bottom) / 2,
140
+ (top - bottom) / 2,
141
+ bone,
142
+ sq,
143
+ ],
144
+ mid = [(A.neck[0] + A.poll[0]) / 2 + 0.01, (A.neck[1] + A.poll[1]) / 2 - 0.01];
145
+ return [
146
+ [0.86, zH - 0.215, 0, 0, 0, 0],
147
+ ring(zH - 0.185, 0.955, 0.7, 0.09, 0, 2.4),
148
+ ring(zH - 0.08, 0.988, 0.615, 0.158, 0, 2.5),
149
+ ring(zH + 0.06, 0.992, 0.598, 0.168, 0, 2.4),
150
+ ring(zH + 0.22, 0.958, 0.582, 0.164, 0.5),
151
+ ring(zH + 0.4, 0.938, 0.548, 0.174, 0.9),
152
+ ring(zF - 0.2, 0.945, 0.54, 0.17, 1),
153
+ ring(zF - 0.09, 0.985, 0.548, 0.158, 1),
154
+ ring(zF, 1, 0.585, 0.136, 1),
155
+ ring(zF + 0.1, 0.985, 0.645, 0.11, 1.3, 2),
156
+ [A.neck[0] + 0.01, A.neck[1] + 0.03, 0.1 * nt, 0.17 * nt, 0.19 * nt, 2],
157
+ [mid[0], mid[1], 0.074 * nt, 0.13 * nt, 0.13 * nt, 3],
158
+ [lerp(mid[0], A.poll[0], 0.72), lerp(mid[1], A.poll[1], 0.72), 0.056 * nt ** 0.6, 0.094 * nt ** 0.6, 0.092 * nt ** 0.6, 3.7],
159
+ [A.poll[0] - 0.01, A.poll[1] - 0.012, 0.046, 0.06, 0.068, 4],
160
+ [A.poll[0] - 0.012, A.poll[1] + 0.03, 0, 0, 0, 4],
161
+ ];
162
+ }
163
+
164
+ // A leg from the shoulder blade or the quarter down to the fetlock, then the pastern and the hoof.
165
+ function leg(b, A, p, coat, q, s, hind) {
166
+ const t = p.bone,
167
+ i = (hind ? 2 : 0) + (s > 0 ? 1 : 0),
168
+ f = LEGS[i],
169
+ skin = skinOf(coat, i),
170
+ mix = (P, Q, k, dz = 0) => [P[0] + (Q[0] - P[0]) * k, P[1] + (Q[1] - P[1]) * k + dz],
171
+ at = (P, w, front, back, bone, lean = 0) => [P[0], P[1], w * t, front * t, back * t, bone, 2.2, lean];
172
+ const S = hind
173
+ ? [
174
+ [0.955, A.hip[1] - 0.02, 0, 0, 0, 0],
175
+ [0.88, A.hip[1] - 0.03, 0.05, 0.12, 0.2, 0.2, 2, -0.045 * p.girth],
176
+ // the quarter's back line, the hamstring, runs down unbroken from the buttock behind the stifle to the point of the hock
177
+ at(mix(A.hip, A.stifle, 0.2, -0.02), 0.075, 0.11, 0.19, 1, -0.015),
178
+ at(mix(A.hip, A.stifle, 0.7, -0.03), 0.068, 0.09, 0.18, 1),
179
+ at(A.stifle, 0.055, 0.065, 0.15, 1.5),
180
+ at(mix(A.stifle, A.hock, 0.45), 0.044, 0.05, 0.1, 2),
181
+ at(mix(A.stifle, A.hock, 0.8), 0.03, 0.032, 0.05, 2),
182
+ at(A.hock, 0.03, 0.036, 0.05, 2.5),
183
+ at(mix(A.hock, A.hindFetlock, 0.25), 0.023, 0.025, 0.03, 3),
184
+ at(mix(A.hock, A.hindFetlock, 0.8), 0.02, 0.022, 0.029, 3),
185
+ at(A.hindFetlock, 0.027, 0.03, 0.036, 3),
186
+ [A.hindFetlock[0] - 0.03, A.hindFetlock[1] + 0.01, 0, 0, 0, 3],
187
+ ]
188
+ : [
189
+ [0.985, zF - 0.06, 0, 0, 0, 0],
190
+ [0.9, zF - 0.03, 0.03, 0.11, 0.1, 0, 2, -0.05 * p.girth],
191
+ at(mix(A.shoulder, A.elbow, -0.1), 0.056, 0.07, 0.12, 0.5, -0.012),
192
+ at(mix(A.shoulder, A.elbow, 0.55), 0.058, 0.07, 0.12, 1),
193
+ at(A.elbow, 0.045, 0.066, 0.085, 1.5),
194
+ at(mix(A.elbow, A.knee, 0.28), 0.042, 0.056, 0.056, 2),
195
+ at(mix(A.elbow, A.knee, 0.78), 0.028, 0.03, 0.032, 2),
196
+ at(A.knee, 0.033, 0.037, 0.034, 2.5),
197
+ at(mix(A.knee, A.fetlock, 0.25), 0.022, 0.024, 0.028, 3),
198
+ at(mix(A.knee, A.fetlock, 0.8), 0.02, 0.022, 0.028, 3),
199
+ at(A.fetlock, 0.027, 0.03, 0.036, 3),
200
+ [A.fetlock[0] - 0.03, A.fetlock[1] + 0.01, 0, 0, 0, 3],
201
+ ];
202
+ const x = s * (hind ? A.hx : A.sx),
203
+ F = hind ? A.hindFetlock : A.fetlock,
204
+ H = hind ? A.hindHoof : A.hoof;
205
+ tube(b, S, {
206
+ x,
207
+ side: s,
208
+ chain: [hind ? BONE.hips : BONE.chest, f, f + 1, f + 2],
209
+ around: [6, 8, 10][q],
210
+ sub: [1, 2, 3][q],
211
+ coat: skin,
212
+ lay: 1,
213
+ });
214
+ // the pastern slopes down to the coronet, and the hoof stands under it
215
+ const pale = coat.socks[i] > 0,
216
+ horn = pale ? [0.3, 0.26, 0.2] : HORN,
217
+ foot = (col, px, py, pz, nx, ny) => {
218
+ skin(col, px, py, pz, nx, ny);
219
+ const hard = sstep(0.058, 0.05, py);
220
+ for (let k = 0; k < 3; k++) col[k] += (horn[k] - col[k]) * hard;
221
+ col[3] = lerp(SLEEK, SMOOTH + 0.2, hard);
222
+ };
223
+ tube(
224
+ b,
225
+ [
226
+ [F[0] + 0.02, F[1] - 0.006, 0, 0, 0, 0],
227
+ [F[0], F[1], 0.025 * t, 0.028 * t, 0.03 * t, 0.4],
228
+ [0.078, lerp(F[1], H[1], 0.45), 0.023 * t, 0.025 * t, 0.025 * t, 1],
229
+ [0.054, lerp(F[1], H[1], 0.8), 0.034 * t, 0.037 * t, 0.035 * t, 1, 2.3],
230
+ [0.028, H[1] - 0.004, 0.04 * t, 0.048 * t, 0.038 * t, 1, 2.6],
231
+ [0.003, H[1], 0.046 * t, 0.056 * t, 0.042 * t, 1, 2.6],
232
+ [0, H[1], 0, 0, 0, 1],
233
+ ],
234
+ {
235
+ x,
236
+ side: s,
237
+ chain: [f + 2, f + 3],
238
+ around: [6, 8, 10][q],
239
+ sub: [1, 1, 2][q],
240
+ coat: foot,
241
+ lay: 1,
242
+ // feather: long hair at the heels of a heavy horse
243
+ fur:
244
+ q > 0 &&
245
+ p.feather > 0 &&
246
+ ((out, px, py, pz, nx, ny, nz, a) => {
247
+ const len = 0.05 * p.feather * sstep(0.05, 0.075, py) * (0.5 + 0.5 * sstep(0.2, -0.6, Math.sin(a)));
248
+ if (len < 0.015) return false;
249
+ out[0] = len;
250
+ out[1] = 0.25;
251
+ out[2] = len * 0.3;
252
+ out[3] = 3;
253
+ return true;
254
+ }),
255
+ },
256
+ );
257
+ }
258
+
259
+ // The head: a long skull from the poll to the muzzle, deep at the jaw, with eyes, nostrils and ears; the lower lip and chin
260
+ // follow the jaw's bone.
261
+ function head(b, p, coat, q) {
262
+ const k = p.head,
263
+ skin = skinOf(coat),
264
+ eye = EYE.map(v => v * k),
265
+ // the mouth's line runs from its corner, low on the muzzle's side, forward and a little up to the front, where the upper lip
266
+ // overhangs the lower
267
+ lipLine = z => (MOUTH[0] + (MOUTH[1] - MOUTH[0]) * sstep(MOUTH[2], 0.405, z / k)) * k,
268
+ lipAt = (y, z) => {
269
+ const reach = sstep(MOUTH[2] - 0.02, MOUTH[2] + 0.01, z / k),
270
+ d = (y - lipLine(z)) / k;
271
+ return {
272
+ groove: reach * sstep(0.008, 0.0015, Math.abs(d)),
273
+ over: reach * sstep(0.35, 0.4, z / k) * sstep(0.016, 0.002, Math.abs(d - 0.01)),
274
+ };
275
+ },
276
+ // a nostril: an opening longer than it is wide, slanting up and back from the front of the muzzle, its outer wing raised
277
+ nostrilAt = (x, y, z) => {
278
+ const dx = (Math.abs(x) - NOSTRIL[0] * k) / k,
279
+ dy = (y - NOSTRIL[1] * k) / k,
280
+ dz = (z - NOSTRIL[2] * k) / k,
281
+ along = dy * 0.6 - dz * 0.8, // up and back
282
+ across = dy * 0.8 + dz * 0.6,
283
+ e = Math.hypot(along / 0.021, across / 0.0095, dx / 0.024);
284
+ return { hole: sstep(1.05, 0.55, e), wing: sstep(0.9, 1.25, e) * sstep(2.1, 1.35, e) * sstep(-0.004, 0.004, across) };
285
+ },
286
+ face = (col, x, y, z, nx, ny) => {
287
+ skin(col, x, y, z, nx, ny);
288
+ // a dark, bare muzzle, dark round the eyes and in the nostrils; a blaze down the face
289
+ const bare = Math.max(
290
+ sstep(0.3 * k, 0.37 * k, z) * 0.75,
291
+ sstep(0.022 * k, 0.011 * k, Math.hypot(Math.abs(x) - eye[0], y - eye[1], z - eye[2])),
292
+ ),
293
+ hole = Math.max(nostrilAt(x, y, z).hole, 0.85 * lipAt(y, z).groove),
294
+ white =
295
+ coat.blaze *
296
+ sstep(0.02 * k * (0.5 + coat.blaze), 0.008 * k, Math.abs(x)) *
297
+ sstep(0.3, 0.7, ny) *
298
+ sstep(0.03 * k, 0.07 * k, z) *
299
+ sstep(0.36 * k, 0.3 * k * coat.blaze, z);
300
+ // a mule's muzzle and the rings round its eyes pale instead
301
+ const mealy = coat.mealy
302
+ ? Math.max(
303
+ sstep(0.25 * k, 0.32 * k, z),
304
+ sstep(0.045 * k, 0.03 * k, Math.hypot(Math.abs(x) - eye[0], y - eye[1], z - eye[2])) *
305
+ sstep(0.012 * k, 0.02 * k, Math.hypot(Math.abs(x) - eye[0], y - eye[1], z - eye[2])),
306
+ )
307
+ : 0;
308
+ for (let i = 0; i < 3; i++) {
309
+ col[i] += (coat.white[i] - col[i]) * white;
310
+ col[i] += (DARK[i] * 2 - col[i]) * bare * (1 - white) * (1 - mealy);
311
+ col[i] += (MEALY[i] - col[i]) * mealy * 0.85;
312
+ col[i] += (DARK[i] * 0.15 - col[i]) * hole;
313
+ }
314
+ col[3] = lerp(col[3], SMOOTH, Math.max(bare * 0.6, hole));
315
+ };
316
+ tube(b, headStations(k), {
317
+ chain: [BONE.head, BONE.jaw],
318
+ around: [8, 10, 20][q],
319
+ sub: [2, 2, 4][q],
320
+ coat: face,
321
+ // sockets for the eyes under a bony brow, and the hollows of the nostrils
322
+ warp: (Q, q) => {
323
+ const x = Q[q],
324
+ y = Q[q + 1],
325
+ z = Q[q + 2],
326
+ { hole, wing } = nostrilAt(x, y, z),
327
+ lip = lipAt(y, z),
328
+ chin =
329
+ sstep(0.022 * k, 0.006 * k, Math.hypot(y - MOUTH[3] * k, z - MOUTH[4] * k)) * sstep(MOUTH[0] * k, MOUTH[0] * k - 0.01 * k, y);
330
+ Q[q] += Math.sign(x) * (boneUnder(x, y, z, k) + 0.006 * k * wing - 0.012 * k * hole - 0.0045 * k * lip.groove);
331
+ Q[q + 1] -= 0.004 * k * chin;
332
+ Q[q + 2] += 0.004 * k * wing - 0.011 * k * hole - 0.0045 * k * lip.groove + 0.005 * k * lip.over + 0.003 * k * chin;
333
+ },
334
+ // the lower lip and the chin are the jaw's, below the line of the mouth
335
+ bind: (bw, x, y, z) => {
336
+ bw[0] = BONE.head;
337
+ bw[1] = BONE.jaw;
338
+ bw[2] = 1 - sstep(0.22 * k, 0.29 * k, z) * sstep(lipLine(z) + 0.003 * k, lipLine(z) - 0.004 * k, y);
339
+ },
340
+ });
341
+ // the eyes under their lids, and the ears, on the skin
342
+ const shape = headSkin(k),
343
+ root = [0, 0, 0, 0],
344
+ brow = [0, 0, 0, 0];
345
+ skin(root, 0.04 * k, 0.04 * k, 0.012 * k, 0, 1);
346
+ skin(brow, eye[0], eye[1] + 0.03 * k, eye[2], 1, 0);
347
+ const lid = [0, 1, 2].map(i => lerp(brow[i], DARK[i] * 2, 0.85)); // the lids' edges are bare and dark
348
+ for (const s of [-1, 1]) {
349
+ eyeWithLids(b, shape, k, s, lid, SMOOTH, BONE.head, q);
350
+ ear(b, shape, k, s, p.ear, root, DARK, SLEEK, s < 0 ? BONE.earL : BONE.earR, q);
351
+ }
352
+ if (!p.upright) forelock(b, shape, k, p, coat.hair, q); // a mule's brush has none
353
+ }
354
+
355
+ /**
356
+ * The arrays of one version of a horse's skinned mesh, as `GeometryBuilder.parts` gives them (positions, normals, colours, tags,
357
+ * bone indices and weights), standing at the origin with its nose to +z.
358
+ * @param {number | number[] | null} hex Its coat's colour (sRGB hex, or linear [r, g, b]); null for a coded coat (`codedCoat`),
359
+ * to be coloured after it is cast.
360
+ * @param {number} cloth The saddle cloth's colour (sRGB hex).
361
+ * @param {boolean} tack Saddled and bridled.
362
+ * @param {object} p Its build (`buildOf`).
363
+ * @param {number} q Its detail: 0 far, 1 between, 2 near.
364
+ * @param {boolean | number} marked With the white socks and blaze its colour gives it; a number picks which.
365
+ * @param {import('./animal-options.js').AnimalKitOptions} [options] The world's noise for a grey's dapples.
366
+ */
367
+ function horseParts(hex, cloth, tack, p, q, marked, options = NO_ANIMAL_OPTIONS) {
368
+ const b = new GB(),
369
+ K = WITHERS * p.size,
370
+ A = anatomy(p),
371
+ coat = { ...(hex === null ? codedCoat(marked) : coatOf(hex, marked)), mealy: p.mealy, fbm: animalNoise(options).fbm },
372
+ S = trunkStations(A, p),
373
+ HM = headMatrix(A, K);
374
+ b.sk = [];
375
+ b.sk2 = [];
376
+ b.skw = [];
377
+ b.tg = [];
378
+ b.M = new THREE.Matrix4().makeScale(K, K, K);
379
+ tube(b, S, {
380
+ chain: [BONE.hips, BONE.chest, BONE.neck, BONE.neck2, BONE.head],
381
+ around: [10, 14, 20][q],
382
+ sub: [2, 2, 3][q],
383
+ coat: skinOf(coat),
384
+ // the muscle under the hide: a hollow in the flank before the stifle, the two rounds of the croup with the spine's channel
385
+ // between them, the breast's two pillars
386
+ warp: (Q, q) => {
387
+ const x = Q[q],
388
+ y = Q[q + 1],
389
+ z = Q[q + 2],
390
+ flank = sstep(0.11, 0.02, Math.hypot(y - 0.72, (z - zH - 0.32) * 0.8)),
391
+ channel = sstep(0.05, 0, Math.abs(x)) * sstep(0.9, 0.96, y) * sstep(zH + 0.36, zH + 0.2, z) * sstep(zH - 0.2, zH - 0.08, z),
392
+ breast = sstep(0.03, 0, Math.abs(x)) * sstep(zF + 0.02, zF + 0.1, z) * sstep(0.86, 0.72, y) * sstep(0.56, 0.66, y);
393
+ Q[q] -= Math.sign(x) * 0.014 * flank * p.girth;
394
+ Q[q + 1] -= 0.012 * channel;
395
+ Q[q + 2] -= 0.014 * breast;
396
+ },
397
+ });
398
+ for (const s of [-1, 1]) {
399
+ leg(b, A, p, coat, q, s, false);
400
+ leg(b, A, p, coat, q, s, true);
401
+ }
402
+ hair(b, A, p, coat, q);
403
+ if (tack) tackUp(b, S, A, p, C(cloth), q, HM, K);
404
+ b.M = HM;
405
+ head(b, p, coat, q);
406
+ b.M = null;
407
+ return b.parts(true);
408
+ }
409
+
410
+ // The head hangs from the poll, its face sloping down.
411
+ function headMatrix(A, K) {
412
+ return new THREE.Matrix4()
413
+ .makeTranslation(0, A.poll[0] * K, A.poll[1] * K)
414
+ .multiply(new THREE.Matrix4().makeRotationX(0.92))
415
+ .multiply(new THREE.Matrix4().makeScale(K, K, K));
416
+ }
417
+
418
+ /**
419
+ * The numbers of a horse build by name: the world's own (`options.horseBuilds`), else the kit's (`HORSE_BUILDS`), else a riding horse.
420
+ * @param {string} build
421
+ * @param {import('./animal-options.js').AnimalKitOptions} [options]
422
+ */
423
+ const buildOf = (build, options = NO_ANIMAL_OPTIONS) => presetOf(build, options.horseBuilds, HORSE_BUILDS, 'riding');
424
+ /**
425
+ * A rider's horse, near and far, as a figure's look gives it: the arrays of both skins (`horseParts` at detail 2 and 0), saddled.
426
+ * @param {{ horse: number | number[], saddle: number, steed?: string }} L The coat's colour, the saddle cloth's, and the build.
427
+ * @param {import('./animal-options.js').AnimalKitOptions} [options]
428
+ */
429
+ const riderHorseParts = (L, options = NO_ANIMAL_OPTIONS) =>
430
+ [2, 0].map(q => horseParts(L.horse, L.saddle, true, buildOf(L.steed, options), q, true, options));
431
+
432
+ /**
433
+ * A horse standing, as one plain indexed geometry with no markings of its own: for a picket line or a team in harness, which a
434
+ * crowd draws many times over.
435
+ * @param {number | number[]} hex Its coat's colour.
436
+ * @param {number} [cloth] The saddle cloth's colour (sRGB hex).
437
+ * @param {boolean} [tack] Saddled and bridled.
438
+ * @param {string} [build] Its build's name (`buildOf`).
439
+ * @param {boolean} [far] The lightest version, for a herd of hundreds.
440
+ * @param {import('./animal-options.js').AnimalKitOptions} [options]
441
+ */
442
+ function horseGeometry(hex, cloth = 0x6a2a26, tack = true, build = 'riding', far = false, options = NO_ANIMAL_OPTIONS) {
443
+ return geometryOf(indexParts(horseParts(hex, cloth, tack, buildOf(build, options), far ? 0 : 1, false, options)));
444
+ }
445
+
446
+ export { HABITS, SEAT, WITHERS, anatomy, buildOf, headMatrix, horseGeometry, horseParts, jointsAt, riderHorseParts };
@@ -0,0 +1,171 @@
1
+ import { sstep } from '../math/scalar.js';
2
+ import { facet } from './animal-skin.js';
3
+ import { MOUTH, headSkin } from './animal-horse-head.js';
4
+ import { BONE } from '../motion/quadruped.js';
5
+
6
+ // ════════════════════════════════════════════════════════════════════════
7
+ // A horse's bridle, laid on the skin of its head (animal-horse-head.js): one strap from the bit's ring up the cheek, over the
8
+ // poll behind the ears and down the other cheek to the other ring; a browband across the forehead in front of the ears; a
9
+ // noseband round the face below the cheekbones; and the bit's two rings at the corners of the mouth, where the reins are buckled.
10
+ // Lengths in head lengths, times the head's size k.
11
+ // ════════════════════════════════════════════════════════════════════════
12
+ const LEATHER = [0.16, 0.09, 0.05],
13
+ STEEL = [0.34, 0.33, 0.32],
14
+ EDGE = 0.72, // a strap's cut edges, darker than its face
15
+ POLISHED = 0.9, // tags (as a figure material reads them): oiled leather, and metal
16
+ METAL = 1.6,
17
+ HALF = 0.008, // half a strap's width
18
+ NOSE_HALF = 0.011, // and the noseband's
19
+ THICK = 0.003, // a strap's thickness
20
+ GAP = 0.0008, // between the skin and a strap
21
+ CROWN_Z = -0.012, // the headpiece, just behind the ears
22
+ CROWN_FROM = 0.25, // the angle on the side of the head where the headpiece turns down into a cheekpiece
23
+ BROW_TOP = 0.058, // the browband on the middle of the forehead
24
+ NOSE_Z = 0.215, // the noseband over the face; under the jaw it lies NOSE_DROP further forward
25
+ NOSE_DROP = 0.012,
26
+ RING = 0.019, // a ring of the bit, and the round of its iron
27
+ WIRE = 0.0028,
28
+ // the cheekpiece, below the headpiece: down behind the eye, then forward along the cheek to the ring (z forward, y up)
29
+ CHEEK = [
30
+ [0.02, 0.012],
31
+ [0.05, 0],
32
+ [0.09, -0.014],
33
+ [0.14, -0.024],
34
+ [0.19, -0.031],
35
+ [0.24, -0.036],
36
+ [0.272, -0.037],
37
+ ];
38
+
39
+ // Each level of detail (0 far, 1 between, 2 near): points to a span of a strap, whether its edges are drawn, the points round a
40
+ // ring and round its iron
41
+ const SPANS = [1, 2, 3],
42
+ EDGES = [false, false, true],
43
+ ROUND = [6, 10, 16],
44
+ IRON = [3, 4, 4];
45
+
46
+ const scale = (v, c) => [v[0] * c, v[1] * c, v[2] * c],
47
+ unit = v => scale(v, 1 / (Math.hypot(v[0], v[1], v[2]) || 1)),
48
+ cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]],
49
+ // v with its part along n taken out, made unit: a direction lying in the surface n is the normal of
50
+ flat = (v, n) => {
51
+ const d = v[0] * n[0] + v[1] * n[1] + v[2] * n[2];
52
+ return unit([v[0] - n[0] * d, v[1] - n[1] * d, v[2] - n[2] * d]);
53
+ };
54
+
55
+ // A strap through the points of its middle line ([x, y, z, nx, ny, nz] each, the normal its face's), `half` wide: its face and,
56
+ // when `edges`, its two cut edges down to the skin. closed: the last point runs on to the first.
57
+ function strap(b, pts, half, k, edges, closed = false) {
58
+ const n = pts.length,
59
+ rows = pts.map((P, i) => {
60
+ const A = pts[closed ? (i + n - 1) % n : Math.max(0, i - 1)],
61
+ B = pts[closed ? (i + 1) % n : Math.min(n - 1, i + 1)],
62
+ nrm = [P[3], P[4], P[5]],
63
+ across = unit(cross([B[0] - A[0], B[1] - A[1], B[2] - A[2]], nrm)),
64
+ corner = (w, h) => [P[0] + across[0] * w + nrm[0] * h, P[1] + across[1] * w + nrm[1] * h, P[2] + across[2] * w + nrm[2] * h],
65
+ top = THICK * k * 0.5,
66
+ w = half * k;
67
+ return { nrm, across, L: corner(w, top), R: corner(-w, top), l: corner(w, -top), r: corner(-w, -top) };
68
+ }),
69
+ v = (p, nrm, c) => [p[0], p[1], p[2], nrm[0], nrm[1], nrm[2], LEATHER[0] * c, LEATHER[1] * c, LEATHER[2] * c];
70
+ for (let i = 0; i < (closed ? n : n - 1); i++) {
71
+ const a = rows[i],
72
+ c = rows[(i + 1) % n];
73
+ facet(b, v(a.L, a.nrm, 1), v(a.R, a.nrm, 1), v(c.R, c.nrm, 1), v(c.L, c.nrm, 1), BONE.head);
74
+ if (!edges) continue;
75
+ facet(b, v(a.L, a.across, EDGE), v(a.l, a.across, EDGE), v(c.l, c.across, EDGE), v(c.L, c.across, EDGE), BONE.head);
76
+ const ia = scale(a.across, -1),
77
+ ic = scale(c.across, -1);
78
+ facet(b, v(a.R, ia, EDGE), v(c.R, ic, EDGE), v(c.r, ic, EDGE), v(a.r, ia, EDGE), BONE.head);
79
+ }
80
+ }
81
+
82
+ // A ring of iron round `at`, in the plane across `axis`, `up` one of its directions
83
+ function ring(b, at, axis, up, k, q) {
84
+ const side = cross(axis, up),
85
+ M = ROUND[q],
86
+ N = IRON[q],
87
+ point = (i, j) => {
88
+ const f = (i / M) * Math.PI * 2,
89
+ g = (j / N) * Math.PI * 2,
90
+ u = [0, 1, 2].map(c => up[c] * Math.cos(f) + side[c] * Math.sin(f)),
91
+ d = [0, 1, 2].map(c => u[c] * Math.cos(g) + axis[c] * Math.sin(g));
92
+ return [0, 1, 2].map(c => at[c] + (u[c] * RING + d[c] * WIRE) * k).concat(d, STEEL);
93
+ };
94
+ for (let i = 0; i < M; i++)
95
+ for (let j = 0; j < N; j++) facet(b, point(i, j), point(i + 1, j), point(i + 1, j + 1), point(i, j + 1), BONE.head);
96
+ }
97
+
98
+ // Bridles the head being built (b.M its place). k: the head's size; q: the detail. Returns where each rein is buckled to its
99
+ // ring, in the head's own frame: { 1: [x, y, z], -1: [x, y, z] }.
100
+ function bridle(b, k, q) {
101
+ const H = headSkin(k),
102
+ spans = SPANS[q],
103
+ lift = GAP + THICK * 0.5,
104
+ bits = {},
105
+ // the points of a line drawn through `marks` ([z, a] each, z in head lengths), `spans` to each step between them
106
+ line = (marks, out) => {
107
+ const pts = [];
108
+ for (let i = 0; i < marks.length - 1; i++)
109
+ for (let j = 0; j < spans; j++) {
110
+ const t = j / spans,
111
+ z = marks[i][0] + (marks[i + 1][0] - marks[i][0]) * t,
112
+ a = marks[i][1] + (marks[i + 1][1] - marks[i][1]) * t;
113
+ pts.push(H.at(z * k, a, (lift + out(z, a)) * k));
114
+ }
115
+ const [z, a] = marks.at(-1);
116
+ pts.push(H.at(z * k, a, (lift + out(z, a)) * k));
117
+ return pts;
118
+ },
119
+ // a cheekpiece rides over the noseband where they cross
120
+ overNose = z => THICK * sstep(0.022, 0.008, Math.abs(z - NOSE_Z - NOSE_DROP * 0.3)),
121
+ // the headpiece over the poll and both cheekpieces, as one strap from the right ring to the left
122
+ cheekMarks = s => {
123
+ const a = (z, y) => (s > 0 ? H.angleOf(z * k, y * k) : Math.PI - H.angleOf(z * k, y * k));
124
+ return [[CROWN_Z, s > 0 ? CROWN_FROM : Math.PI - CROWN_FROM], ...CHEEK.map(([z, y]) => [z, a(z, y)])];
125
+ },
126
+ crown = [];
127
+ for (let i = 0; i <= 6; i++) crown.push([CROWN_Z, CROWN_FROM + ((Math.PI - 2 * CROWN_FROM) * i) / 6]);
128
+ const ends = {};
129
+ for (const s of [1, -1]) {
130
+ // the ring at the corner of the mouth, standing just off the lips
131
+ const corner = H.side(MOUTH[2] * k, MOUTH[0] * k, s, 0),
132
+ axis = [corner[3], corner[4], corner[5]],
133
+ up = flat([0, 1, 0], axis),
134
+ forward = flat([0, 0, 1], axis),
135
+ at = [0, 1, 2].map(c => corner[c] + axis[c] * (WIRE + 0.002) * k);
136
+ b.tv = METAL;
137
+ ring(b, at, axis, up, k, q);
138
+ bits[s] = [0, 1, 2].map(c => at[c] - forward[c] * RING * k);
139
+ // the cheekpiece's end is buckled round the top of the ring
140
+ ends[s] = [0, 1, 2].map(c => at[c] + up[c] * RING * k).concat(axis);
141
+ }
142
+ b.tv = POLISHED;
143
+ const right = line(cheekMarks(1), overNose),
144
+ left = line(cheekMarks(-1), overNose),
145
+ over = line(crown, () => 0);
146
+ strap(b, [ends[1], ...right.reverse(), ...over.slice(1, -1), ...left, ends[-1]], HALF, k, EDGES[q]);
147
+ // the browband: from where each cheekpiece leaves the headpiece, forward over the forehead in front of the ears
148
+ const brow = [];
149
+ for (let i = 0; i <= 8; i++) {
150
+ const a = CROWN_FROM + ((Math.PI - 2 * CROWN_FROM) * i) / 8;
151
+ brow.push([CROWN_Z + (BROW_TOP - CROWN_Z) * Math.sin(a) ** 1.5, a]);
152
+ }
153
+ strap(
154
+ b,
155
+ line(brow, (z, a) => THICK * (1 - Math.sin(a))),
156
+ HALF,
157
+ k,
158
+ EDGES[q],
159
+ );
160
+ // the noseband, all the way round
161
+ const nose = [];
162
+ for (let i = 0; i < 16; i++) {
163
+ const a = (i / 16) * Math.PI * 2;
164
+ nose.push([NOSE_Z + NOSE_DROP * 0.5 * (1 - Math.sin(a)), a]);
165
+ }
166
+ nose.push([NOSE_Z + NOSE_DROP * 0.5, Math.PI * 2]);
167
+ strap(b, line(nose, () => 0).slice(0, -1), NOSE_HALF, k, EDGES[q], true);
168
+ return bits;
169
+ }
170
+
171
+ export { bridle };