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,68 @@
1
+ import { sstep } from '../math/scalar.js';
2
+ import { C } from './primitives.js';
3
+
4
+ // ════════════════════════════════════════════════════════════════════════
5
+ // A horse's coat (animal-horse-body.js builds the horse): its colours from the body's colour, and the skin's colour at each point.
6
+ // ════════════════════════════════════════════════════════════════════════
7
+ const SLEEK = 0.55, // a groomed coat: smoother than fur, with a sheen
8
+ COAT_GAIN = 1.6, // a coat's colour is given as it looks; in the sun's exposure a dark bay needs this much to keep its form
9
+ MEALY = [0.5, 0.42, 0.33]; // the pale points of a mule's coat: its muzzle, round its eyes, its belly
10
+
11
+ // The colours of a coat from its body colour (a hex, or linear [r, g, b]): black points on a bay or a dun, a chestnut's mane of
12
+ // its own red, a grey's dapples; here and there a white sock or a blaze (marked; a number picks which, where the colour does not).
13
+ function coatOf(colour, marked) {
14
+ const body = (Array.isArray(colour) ? colour : C(colour)).map(v => v * COAT_GAIN),
15
+ max = Math.max(...body),
16
+ min = Math.min(...body),
17
+ grey = max - min < 0.08 * (max + 0.05) + 0.012,
18
+ black = max < 0.03,
19
+ seed = typeof marked === 'number' ? marked : Array.isArray(colour) ? Math.round(colour[0] * 977 + colour[1] * 613) % 89 : colour % 89,
20
+ luck = n => {
21
+ const v = Math.sin(seed * 12.9898 + n * 78.233) * 43758.5453;
22
+ return v - Math.floor(v);
23
+ },
24
+ chestnut = !grey && !black && luck(7) < 0.4, // of the browns, some are red all over, the rest bay or dun with black points
25
+ points = grey || chestnut || black ? body.map(v => v * (grey ? 0.55 : 0.8)) : [0.03, 0.026, 0.024],
26
+ socks = [0, 1, 2, 3].map(i => (marked !== false && luck(i) < 0.22 ? 0.16 + 0.1 * luck(i + 9) : 0)), // how high each leg is white
27
+ blaze = marked !== false && luck(5) < 0.4 ? 0.3 + 0.7 * luck(6) : 0;
28
+ return {
29
+ body,
30
+ points,
31
+ grey,
32
+ socks,
33
+ blaze,
34
+ hair: grey ? points : chestnut ? body.map(v => v * 1.1) : points,
35
+ white: [0.62, 0.6, 0.56],
36
+ seed,
37
+ };
38
+ }
39
+ // A coat whose colours are not colours yet but shares: red of the body's colour, green of the points', blue of white. A horse cast
40
+ // from it takes its real colours afterwards (motion/animal-horse-still.js), so one model serves a whole picket line.
41
+ function codedCoat(marks) {
42
+ const coat = coatOf([0.5, 0.5, 0.5], marks);
43
+ return { ...coat, body: [1, 0, 0], points: [0, 1, 0], hair: [0, 1, 0], white: [0, 0, 1], grey: false };
44
+ }
45
+
46
+ // The body's skin colour at a point: the coat, darkening down the legs to the points, dappled if grey, lighter under the belly.
47
+ // The coat carries the noise its dapples are drawn with (`fbm`, as animal-horse-body.js gives it).
48
+ function skinOf(coat, legIndex = -1) {
49
+ return (col, x, y, z, nx, ny) => {
50
+ const down = legIndex < 0 ? 0 : sstep(0.42, 0.22, y),
51
+ sock = legIndex < 0 ? 0 : sstep(coat.socks[legIndex] + 0.02, coat.socks[legIndex] - 0.02, y) * (coat.socks[legIndex] ? 1 : 0),
52
+ dapple = coat.grey ? 0.16 * sstep(0.45, 0.65, coat.fbm(z * 14 + x * 5, y * 14, 2, coat.seed)) : 0,
53
+ under = 0.1 * sstep(-0.3, -0.9, ny),
54
+ streak = 0.94 + 0.12 * (Math.sin(x * 190 + y * 311 + z * 127) * 0.5 + 0.5),
55
+ // a mule's belly, flanks underneath and the insides of its legs pale
56
+ pale = coat.mealy ? sstep(-0.2, -0.75, ny) * (legIndex < 0 ? 1 : sstep(0.35, 0.5, y)) : 0;
57
+ for (let i = 0; i < 3; i++) {
58
+ let v = coat.body[i] * (1 + under * (1 - pale) + dapple);
59
+ v += (MEALY[i] - v) * pale * 0.75;
60
+ v += (coat.points[i] - v) * down * (coat.grey ? 0.5 : 1);
61
+ v += (coat.white[i] - v) * sock;
62
+ col[i] = v * streak;
63
+ }
64
+ col[3] = SLEEK;
65
+ };
66
+ }
67
+
68
+ export { MEALY, SLEEK, coatOf, codedCoat, skinOf };
@@ -0,0 +1,162 @@
1
+ import * as THREE from 'three';
2
+ import { sstep } from '../math/scalar.js';
3
+ import { SHAPES } from './animal-shapes.js';
4
+ import { EYE_TAG, facet } from './animal-skin.js';
5
+ import { EYE } from './animal-horse-head.js';
6
+
7
+ // ════════════════════════════════════════════════════════════════════════
8
+ // A horse's ears and eyes, on the skin of its head (animal-horse-head.js). An ear is a funnel of skin rolled from a closed root
9
+ // and opening forwards to a point, its outside the coat, its inside dark skin with pale hair; an eye is a dark, glossy ball set
10
+ // in the face under lids that make it an almond. Lengths in head lengths, times the head's size k.
11
+ // ════════════════════════════════════════════════════════════════════════
12
+ const EAR_ROWS = [3, 5, 7], // each level of detail (0 far, 1 between, 2 near): rows up an ear, points round it,
13
+ EAR_ROUND = [4, 6, 8],
14
+ LID_ROUND = [0, 10, 18], // points round an eye's lids (none far: from there the eye is a dark spot) and round a lid's edge
15
+ LID_EDGE = [0, 3, 4],
16
+ EAR_ROOT = [0.82, 0.012], // where an ear rises: its angle round the head (a right ear's) and its place forward
17
+ EAR_SUNK = 0.008, // how far the root is set into the head
18
+ EAR_WIDE = 0.021, // the ear's half width at its broadest, for an ear of size 1
19
+ IRIS = [0.05, 0.03, 0.018], // a horse's eye: dark brown, almost all iris
20
+ EYE_OUT = 0.009, // how far it bulges out of the face
21
+ EYE_FILL = 1.12, // and how far past the lids' line its rim reaches, under them
22
+ BALL = 2, // SHAPES.sph is a ball half a unit across
23
+ LID = [0.019, 0.0105], // the opening between the lids: half its length, half its height,
24
+ LID_TILT = 0.0025, // and how much higher its back corner is than its front
25
+ HAIR = [0.42, 0.38, 0.33]; // the pale hair inside an ear
26
+
27
+ const mix = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
28
+ const unit = v => {
29
+ const l = Math.hypot(v[0], v[1], v[2]) || 1;
30
+ return [v[0] / l, v[1] / l, v[2] / l];
31
+ };
32
+
33
+ // An ear on the side s of the head (skin: headSkin), of size `size` (1 a riding horse's), on its bone, tagged `tag`. coat: the
34
+ // colour of the head at its root; dark: the bare skin's. Its outside and inside are both drawn, so it shows on a one-sided
35
+ // material.
36
+ function ear(b, skin, k, s, size, coat, dark, tag, bone, q) {
37
+ const root = skin.at(EAR_ROOT[1] * k, s > 0 ? EAR_ROOT[0] : Math.PI - EAR_ROOT[0], -EAR_SUNK * k),
38
+ up = unit([s * 0.2, 0.95, -0.2]),
39
+ // the way the opening faces: forwards and a little out, square to `up`
40
+ front = (() => {
41
+ const f = [s * 0.45, 0.1, 0.88],
42
+ d = f[0] * up[0] + f[1] * up[1] + f[2] * up[2];
43
+ return unit([f[0] - up[0] * d, f[1] - up[1] * d, f[2] - up[2] * d]);
44
+ })(),
45
+ across = [up[1] * front[2] - up[2] * front[1], up[2] * front[0] - up[0] * front[2], up[0] * front[1] - up[1] * front[0]],
46
+ len = (0.09 * size + EAR_SUNK) * k,
47
+ wide = EAR_WIDE * Math.sqrt(size) * k,
48
+ rows = EAR_ROWS[q],
49
+ round = EAR_ROUND[q],
50
+ // the point of row i, j of the way round, on the outside (side 1) or the inside (-1), with its normal and colour
51
+ point = (i, j, side) => {
52
+ const t = i / rows,
53
+ r = wide * Math.sin(Math.PI * (0.35 + 0.65 * t)) ** 0.7 * (1 - t * t * t),
54
+ open = Math.PI - (0.35 + 0.9 * sstep(0.12, 0.45, t) - 0.15 * sstep(0.6, 1, t)), // half the shell's arc, from its back
55
+ th = (j / round) * 2 * open - open,
56
+ thick = side > 0 ? 0 : wide * (0.16 * (1 - t) + 0.03) * (1 - t),
57
+ // the tip leans a little forwards and in
58
+ lean = len * t * t,
59
+ c = [0, 1, 2].map(n => root[n] + up[n] * len * t + front[n] * lean * 0.08 - (n === 0 ? s * lean * 0.05 : 0)),
60
+ out = [0, 1, 2].map(n => -front[n] * Math.cos(th) + across[n] * Math.sin(th)),
61
+ colour =
62
+ side > 0
63
+ ? mix(coat, dark, 0.35 * sstep(0.7, 1, t))
64
+ : mix(mix(dark, HAIR, 0.6 * sstep(0.2, 0.55, t)), dark, sstep(0.75, 1, Math.abs(th) / open) * 0.5);
65
+ return [0, 1, 2]
66
+ .map(n => c[n] + out[n] * (r - thick))
67
+ .concat(
68
+ out.map(v => v * side),
69
+ colour,
70
+ );
71
+ },
72
+ // where the outside meets the inside along an edge of the shell: its normal faces along the edge, outwards
73
+ rim = (i, j) => {
74
+ const P = point(i, j, 1),
75
+ Q = point(i + 1, j, 1),
76
+ A = point(i, j === 0 ? 1 : round - 1, 1),
77
+ n = unit([P[0] - A[0], P[1] - A[1], P[2] - A[2]]),
78
+ dim = v => [v[0], v[1], v[2], n[0], n[1], n[2], coat[0] * 0.8, coat[1] * 0.8, coat[2] * 0.8];
79
+ return [dim(P), dim(point(i, j, -1)), dim(point(i + 1, j, -1)), dim(Q)];
80
+ };
81
+ b.tv = tag;
82
+ for (let i = 0; i < rows; i++) {
83
+ for (let j = 0; j < round; j++) {
84
+ facet(b, point(i, j, 1), point(i + 1, j, 1), point(i + 1, j + 1, 1), point(i, j + 1, 1), bone);
85
+ facet(b, point(i, j, -1), point(i, j + 1, -1), point(i + 1, j + 1, -1), point(i + 1, j, -1), bone);
86
+ }
87
+ for (const j of [0, round]) {
88
+ const [A, B, C, D] = rim(i, j);
89
+ facet(b, A, B, C, D, bone);
90
+ }
91
+ }
92
+ }
93
+
94
+ // An eye on the side s of the head (skin: headSkin), on the head's bone: the ball, and, near enough to be seen, lids round it in
95
+ // the colour `lid`, tagged `tag`.
96
+ function eyeWithLids(b, skin, k, s, lid, tag, bone, q) {
97
+ const E = EYE.map(v => v * k),
98
+ M = LID_ROUND[q],
99
+ N = LID_EDGE[q],
100
+ // the skin round the opening, a quarter turn at a time from its front corner: front, top, back, bottom
101
+ lidAt = f => skin.side(E[2] + LID[0] * k * Math.cos(f), E[1] + LID[1] * k * Math.sin(f) - LID_TILT * k * Math.cos(f), s, 0),
102
+ [F, T, B, D] = [0, 1, 2, 3].map(i => lidAt((i * Math.PI) / 2)),
103
+ middle = [0, 1, 2].map(c => (F[c] + T[c] + B[c] + D[c]) / 4),
104
+ along = [0, 1, 2].map(c => (F[c] - B[c]) / 2),
105
+ upward = (() => {
106
+ const v = [0, 1, 2].map(c => (T[c] - D[c]) / 2),
107
+ a = unit(along),
108
+ d = v[0] * a[0] + v[1] * a[1] + v[2] * a[2];
109
+ return [0, 1, 2].map(c => v[c] - a[c] * d);
110
+ })(),
111
+ outward = (() => {
112
+ const c = unit([
113
+ along[1] * upward[2] - along[2] * upward[1],
114
+ along[2] * upward[0] - along[0] * upward[2],
115
+ along[0] * upward[1] - along[1] * upward[0],
116
+ ]),
117
+ // turned the way the skin faces
118
+ way = c[0] * (F[3] + B[3]) + c[1] * (F[4] + B[4]) + c[2] * (F[5] + B[5]) < 0 ? -1 : 1;
119
+ return c.map(v => v * way * EYE_OUT * k);
120
+ })();
121
+ // the ball: its rim lies on the skin under the lids, its middle bulges out of the face
122
+ b.bone = bone;
123
+ b.tv = EYE_TAG;
124
+ b.add(
125
+ SHAPES.sph,
126
+ IRIS,
127
+ new THREE.Matrix4()
128
+ .makeBasis(
129
+ new THREE.Vector3(...along).multiplyScalar(EYE_FILL * BALL),
130
+ new THREE.Vector3(...upward).multiplyScalar(EYE_FILL * BALL),
131
+ new THREE.Vector3(...outward).multiplyScalar(BALL),
132
+ )
133
+ .setPosition(...middle),
134
+ );
135
+ if (!M) return;
136
+ // the lids: a soft rim round the opening, fuller above, lying on the skin
137
+ const ring = [];
138
+ for (let i = 0; i <= M; i++) {
139
+ const P = lidAt((i / M) * Math.PI * 2),
140
+ n = [P[3], P[4], P[5]],
141
+ v = [P[0] - middle[0], P[1] - middle[1], P[2] - middle[2]],
142
+ d = v[0] * n[0] + v[1] * n[1] + v[2] * n[2];
143
+ ring.push({
144
+ P,
145
+ n,
146
+ away: unit([v[0] - n[0] * d, v[1] - n[1] * d, v[2] - n[2] * d]), // outwards from the eye, along the skin
147
+ thick: (0.0013 + 0.0013 * Math.max(0, Math.sin((i / M) * Math.PI * 2))) * k,
148
+ });
149
+ }
150
+ b.tv = tag;
151
+ // a point of the lid's edge: half round it, from over the ball (j = 0) across its top to the skin outside it (j = N)
152
+ const point = (i, j) => {
153
+ const { P, n, away, thick } = ring[i],
154
+ g = (j / N) * Math.PI,
155
+ d = [0, 1, 2].map(c => -away[c] * Math.cos(g) + n[c] * Math.sin(g));
156
+ return [0, 1, 2].map(c => P[c] + d[c] * thick + away[c] * thick * 0.6).concat(d, lid);
157
+ };
158
+ for (let i = 0; i < M; i++)
159
+ 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);
160
+ }
161
+
162
+ export { ear, eyeWithLids };
@@ -0,0 +1,304 @@
1
+ import { TAU, sstep } from '../math/scalar.js';
2
+ import { ribbon, scatter, tube } from './animal-skin.js';
3
+ import { BONE } from '../motion/quadruped.js';
4
+
5
+ // ════════════════════════════════════════════════════════════════════════
6
+ // A horse's hair (animal-horse-body.js builds the horse): the mane or a mule's brush, the forelock, and the tail's dock and fall, each
7
+ // lock following the bones it grows on.
8
+ // ════════════════════════════════════════════════════════════════════════
9
+ // The mane along the crest of the neck, falling to one side; the forelock between the ears; the tail's dock and its fall of hair.
10
+ function hair(b, A, p, coat, q) {
11
+ const zF = A.fetlock[1], // where the fore hooves stand along the body (animal-horse-body.js)
12
+ lock = coat.hair,
13
+ side = coat.seed % 2 ? 1 : -1,
14
+ strand = (col, x, y, z) => {
15
+ const v = 0.8 + 0.4 * (Math.sin(x * 211 + y * 157 + z * 97) * 0.5 + 0.5);
16
+ col[0] = lock[0] * v;
17
+ col[1] = lock[1] * v;
18
+ col[2] = lock[2] * v;
19
+ col[3] = 0.35;
20
+ },
21
+ mid = [(A.neck[0] + A.poll[0]) / 2, (A.neck[1] + A.poll[1]) / 2],
22
+ nt = p.neck[1];
23
+ // the mane: a thin ridge of skin along the crest, from which the hair falls
24
+ tube(
25
+ b,
26
+ [
27
+ [1.0, zF + 0.02, 0, 0, 0, 0],
28
+ [1.0, zF + 0.05, 0.012, 0.02, 0.02, 0],
29
+ [A.neck[0] + 0.135 * nt + 0.012, A.neck[1] - 0.075 * nt, 0.016, 0.022, 0.03, 1],
30
+ [mid[0] + 0.1 * nt, mid[1] - 0.088 * nt, 0.016, 0.022, 0.03, 2],
31
+ [A.poll[0] + 0.045, A.poll[1] - 0.055, 0.014, 0.018, 0.03, 2.8],
32
+ [A.poll[0] + 0.045, A.poll[1] - 0.01, 0, 0, 0, 3],
33
+ ],
34
+ {
35
+ chain: [BONE.chest, BONE.neck, BONE.neck2, BONE.head],
36
+ around: [4, 5, 6][q],
37
+ sub: [2, 3, 4][q],
38
+ coat: strand,
39
+ fur: (out, x, y, z, nx, ny, nz, a) => {
40
+ if (q > 0) return false; // nearer, the mane is its locks (mane())
41
+ if (p.upright) {
42
+ out[0] = 0.05 * p.mane;
43
+ out[1] = 0.9;
44
+ out[2] = 0.024;
45
+ out[3] = 2;
46
+ out[4] = 0.8;
47
+ return true;
48
+ }
49
+ const over = Math.cos(a) * side;
50
+ if (Math.abs(over) < 0.2) return false;
51
+ out[0] = (over > 0 ? 0.15 : 0.06) * p.mane * (0.8 + 0.4 * Math.sin(z * 37) ** 2);
52
+ out[1] = 0.12;
53
+ out[2] = 0.024;
54
+ out[3] = [2, 3, 5][q];
55
+ out[4] = 0.8;
56
+ return true;
57
+ },
58
+ lay: -1,
59
+ droop: 1.6,
60
+ },
61
+ );
62
+ if (q > 0) (p.upright ? brush : mane)(b, A, p, lock, side, q);
63
+ // the tail: the dock, then the long hair
64
+ const D = A.dock,
65
+ len = 0.62 * p.tail,
66
+ thin = p.tuft ? 0.55 : 1; // a mule's tail: a thin dock with short hair, its long hair only below
67
+ tube(
68
+ b,
69
+ [
70
+ [D[0] + 0.01, D[1] + 0.05, 0, 0, 0, 0],
71
+ [D[0], D[1], 0.03, 0.03, 0.03, 0.6],
72
+ [D[0] - 0.06, D[1] - 0.055, 0.034 * thin, 0.03 * thin, 0.032 * thin, 1],
73
+ [D[0] - 0.2, D[1] - 0.09, 0.045 * thin * thin, 0.03 * thin, 0.036 * thin, 1.6],
74
+ [D[0] - len * 0.6, D[1] - 0.1, 0.05 * thin * thin, 0.026 * thin, 0.034 * thin, 2.6],
75
+ [D[0] - len * 0.9, D[1] - 0.085, 0.036 * thin, 0.016 * thin, 0.02 * thin, 3],
76
+ [D[0] - len, D[1] - 0.08, 0, 0, 0, 3],
77
+ ],
78
+ {
79
+ chain: [BONE.hips, BONE.tail, BONE.tail + 1, BONE.tail + 2],
80
+ around: [5, 6, 8][q],
81
+ sub: [1, 2, 3][q],
82
+ coat: strand,
83
+ lay: 1,
84
+ },
85
+ );
86
+ if (q > 0) tailHair(b, D, len, p, lock, q);
87
+ }
88
+
89
+ const MANE_LOCKS = [0, 60, 120], // locks of the mane at each detail, of the forelock and of the tail's fall
90
+ FORELOCK = [0, 5, 9],
91
+ TAIL_LOCKS = [0, 26, 48],
92
+ MANE_ROUND = 1.45, // radians round the neck's section that a mane lies to before it hangs
93
+ LOCK_TAPER = 0.88, // how much narrower a lock of the mane or forelock is at its tip than at its root: nearly to a point, so
94
+ // the ends read as wisps of hair and not as cut tabs
95
+ LOCK_ROUND = 0.2, // how far a lock's edges turn away: little, so the locks of a mane lie together as one fall of hair
96
+ _lockPts = [],
97
+ _lockOuts = [];
98
+
99
+ // A point along a path of [y, z, bone] points, u from 0 at its first to 1 at its last, straight between them.
100
+ function along(path, u) {
101
+ const f = Math.min(path.length - 1.001, u * (path.length - 1)),
102
+ i = Math.floor(f),
103
+ t = f - i;
104
+ return path[i].map((v, k) => v + (path[i + 1][k] - v) * t);
105
+ }
106
+
107
+ // The mane's locks: rooted along the crest from the withers to the poll, each lying over the side it falls to and down the neck,
108
+ // across it (in its section), combed a little back, standing a finger off the hide at the roots and lying closer lower down;
109
+ // a few at the withers fall to the other side. Each follows the bones of the neck where it grows.
110
+ function mane(b, A, p, lock, side, q) {
111
+ const zF = A.fetlock[1],
112
+ nt = p.neck[1],
113
+ mid = [(A.neck[0] + A.poll[0]) / 2, (A.neck[1] + A.poll[1]) / 2],
114
+ // the crest: [y, z, bone along the chest, neck, neck2, head], with the neck's half-width and its half-depth below the crest there
115
+ crest = [
116
+ [1.0, zF + 0.05, 0, 0.11 * p.girth, 0.2],
117
+ [A.neck[0] + 0.135 * nt + 0.012, A.neck[1] - 0.075 * nt, 1, 0.1 * nt, 0.17 * nt],
118
+ [mid[0] + 0.1 * nt, mid[1] - 0.088 * nt, 2, 0.074 * nt, 0.13 * nt],
119
+ [A.poll[0] + 0.045, A.poll[1] - 0.055, 2.8, 0.052 * nt, 0.09 * nt],
120
+ ],
121
+ n = MANE_LOCKS[q],
122
+ segs = q > 1 ? 9 : 5,
123
+ chain = [BONE.chest, BONE.neck, BONE.neck2, BONE.head],
124
+ root = lock.map(v => v * 0.7),
125
+ tip = lock.map(v => v * 1.15);
126
+ b.tv = 0.35;
127
+ for (let i = 0; i < n; i++) {
128
+ const u = (i + scatter(i * 3.1)) / n,
129
+ [y, z, bone, w, h] = along(crest, u),
130
+ [y2, z2] = along(crest, Math.min(1, u + 0.02)),
131
+ [y1, z1] = along(crest, Math.max(0, u - 0.02)),
132
+ tl = Math.hypot(y2 - y1, z2 - z1) || 1,
133
+ upY = (z2 - z1) / tl, // from the neck's middle out to the crest, across the neck (the crest runs up and forward)
134
+ upZ = -(y2 - y1) / tl,
135
+ k = Math.min(chain.length - 2, Math.floor(bone)),
136
+ bw = [chain[k], chain[k + 1], 1 - (bone - k)],
137
+ s = u < 0.12 && scatter(i * 7.7) < 0.3 ? -side : side, // at the withers a few fall the other way
138
+ len = (0.15 + 0.05 * scatter(i * 5.3)) * p.mane * (1 - 0.4 * sstep(0.75, 1, u)),
139
+ quarter = 0.785 * (w + h), // about the length of a quarter of the neck's section, from the crest to its widest
140
+ reach = Math.min(len, quarter), // how far round the neck's side the lock lies; the rest hangs down the side
141
+ half = (0.018 + 0.008 * scatter(i * 1.9)) * (q > 1 ? 1 : 1.4), // broad enough that each lies over the next
142
+ back = 0.02 + 0.03 * scatter(i * 9.1); // how far it is combed back towards the withers by its tip
143
+ for (let j = 0; j <= segs; j++) {
144
+ const t = j / segs,
145
+ arc = Math.min(len * t, reach),
146
+ a = (arc / quarter) * MANE_ROUND, // the angle round the section from the crest
147
+ off = 0.006 + 0.008 * (1 - t), // off the hide: fuller at the roots
148
+ ex = s * Math.sin(a) * (w + off),
149
+ ey = Math.cos(a) * (h + off) - h,
150
+ // what is left hangs down the side of the neck: straight down would take it into a neck that leans forward
151
+ hang = len * t - arc;
152
+ _lockPts[j] = [ex, y + upY * (ey - hang), z + upZ * (ey - hang) - back * t * t];
153
+ const ox = s * Math.sin(a) * h,
154
+ oy = Math.cos(a) * w,
155
+ ol = Math.hypot(ox, oy) || 1;
156
+ _lockOuts[j] = [ox / ol, (oy / ol) * upY, (oy / ol) * upZ];
157
+ }
158
+ _lockPts.length = _lockOuts.length = segs + 1;
159
+ const tone = 0.88 + 0.22 * scatter(i * 2.3); // strands of a lighter and a darker cast, close enough to read as one mane
160
+ ribbon(
161
+ b,
162
+ _lockPts,
163
+ _lockOuts,
164
+ half,
165
+ root.map(v => v * tone),
166
+ tip.map(v => v * tone),
167
+ () => bw,
168
+ LOCK_TAPER,
169
+ LOCK_ROUND,
170
+ );
171
+ }
172
+ }
173
+
174
+ // The forelock: locks rooted on the poll between the ears, falling forwards over the browband onto the forehead, fanning a little
175
+ // to either side of the middle, on the skin of the head (skin: headSkin, k its size) and on its bone.
176
+ function forelock(b, skin, k, p, lock, q) {
177
+ const n = FORELOCK[q],
178
+ segs = q > 1 ? 6 : 3,
179
+ root = lock.map(v => v * 0.7),
180
+ tip = lock.map(v => v * 1.12),
181
+ bw = [BONE.head, BONE.head, 1];
182
+ b.tv = 0.35;
183
+ for (let i = 0; i < n; i++) {
184
+ const fan = (i / Math.max(1, n - 1) - 0.5) * 0.55 + (scatter(i * 3.7) - 0.5) * 0.12, // its angle off the middle of the poll
185
+ from = -0.008 + 0.01 * scatter(i * 2.2),
186
+ len = (0.09 + 0.045 * scatter(i * 5.1)) * p.mane, // in head lengths, forwards down the face
187
+ tone = 0.88 + 0.22 * scatter(i * 6.7);
188
+ for (let j = 0; j <= segs; j++) {
189
+ const t = j / segs,
190
+ z = from + len * t,
191
+ // off the skin: full at the root, then lying on the forehead, lifted over the browband where it crosses it
192
+ out = 0.002 + 0.004 * (1 - t) + 0.0045 * sstep(0.025, 0.012, Math.abs(z - 0.055)),
193
+ P = skin.at(z * k, Math.PI / 2 + fan * (1 + 0.7 * t), out * k);
194
+ _lockPts[j] = [P[0], P[1], P[2]];
195
+ _lockOuts[j] = [P[3], P[4], P[5]];
196
+ }
197
+ _lockPts.length = _lockOuts.length = segs + 1;
198
+ ribbon(
199
+ b,
200
+ _lockPts,
201
+ _lockOuts,
202
+ (0.009 + 0.004 * scatter(i * 8.9)) * k * (q > 1 ? 1 : 1.4),
203
+ root.map(v => v * tone),
204
+ tip.map(v => v * tone),
205
+ () => bw,
206
+ LOCK_TAPER,
207
+ LOCK_ROUND,
208
+ );
209
+ }
210
+ }
211
+
212
+ // A mule's mane: a short brush of hair standing up off the crest from the withers to the poll, each lock rising across the neck
213
+ // and combed a little back, shortest at the withers, its tips darker; it moves with the bones of the neck where it grows.
214
+ function brush(b, A, p, lock, side, q) {
215
+ const zF = A.fetlock[1],
216
+ nt = p.neck[1],
217
+ mid = [(A.neck[0] + A.poll[0]) / 2, (A.neck[1] + A.poll[1]) / 2],
218
+ crest = [
219
+ [0.99, zF + 0.04, 0],
220
+ [A.neck[0] + 0.135 * nt + 0.008, A.neck[1] - 0.075 * nt, 1],
221
+ [mid[0] + 0.1 * nt - 0.004, mid[1] - 0.088 * nt, 2],
222
+ [A.poll[0] + 0.04, A.poll[1] - 0.055, 2.8],
223
+ ],
224
+ n = MANE_LOCKS[q],
225
+ segs = q > 1 ? 4 : 2,
226
+ chain = [BONE.chest, BONE.neck, BONE.neck2, BONE.head],
227
+ root = lock.map(v => v * 0.8),
228
+ tip = lock.map(v => v * 0.55),
229
+ out = [1, 0, 0];
230
+ b.tv = 0.35;
231
+ for (let i = 0; i < n; i++) {
232
+ const u = (i + scatter(i * 3.1)) / n,
233
+ [y, z, bone] = along(crest, u),
234
+ [y2, z2] = along(crest, Math.min(1, u + 0.02)),
235
+ [y1, z1] = along(crest, Math.max(0, u - 0.02)),
236
+ tl = Math.hypot(y2 - y1, z2 - z1) || 1,
237
+ upY = (z2 - z1) / tl,
238
+ upZ = -(y2 - y1) / tl,
239
+ k = Math.min(chain.length - 2, Math.floor(bone)),
240
+ bw = [chain[k], chain[k + 1], 1 - (bone - k)],
241
+ len = (0.045 + 0.02 * scatter(i * 5.3)) * p.mane * sstep(-0.1, 0.25, u),
242
+ x = (scatter(i * 7.7) - 0.5) * 0.012,
243
+ back = 0.012 + 0.012 * scatter(i * 9.1), // combed back towards the withers by its tip
244
+ lean = (scatter(i * 1.3) - 0.5) * 0.02; // and a little to one side or the other
245
+ for (let j = 0; j <= segs; j++) {
246
+ const t = j / segs;
247
+ _lockPts[j] = [x + lean * t * t, y + upY * len * t + back * t * t * upZ, z + upZ * len * t - back * t * t * upY];
248
+ _lockOuts[j] = out;
249
+ }
250
+ _lockPts.length = _lockOuts.length = segs + 1;
251
+ const tone = 0.8 + 0.35 * scatter(i * 2.3);
252
+ ribbon(
253
+ b,
254
+ _lockPts,
255
+ _lockOuts,
256
+ 0.007 * (q > 1 ? 1 : 1.5),
257
+ root.map(v => v * tone),
258
+ tip.map(v => v * tone),
259
+ () => bw,
260
+ );
261
+ }
262
+ }
263
+
264
+ // The tail's fall of hair from the dock: locks rooted round the dock's last part, each going back off it and falling, the long
265
+ // hair following the tail's lower bones so it swings and streams with them.
266
+ function tailHair(b, D, len, p, lock, q) {
267
+ const n = TAIL_LOCKS[q],
268
+ segs = q > 1 ? 8 : 5,
269
+ root = lock.map(v => v * 0.8),
270
+ tip = lock.map(v => v * 1.12);
271
+ b.tv = 0.35;
272
+ for (let i = 0; i < n; i++) {
273
+ const a = (i / n) * TAU + scatter(i * 4.3), // round the dock
274
+ v = scatter(i * 2.9), // along it
275
+ tuft = p.tuft ? 1 : 0, // a mule's hair grows from the lower half of its tail, and is shorter
276
+ ry = D[0] - 0.03 - 0.1 * v - tuft * (0.12 + 0.14 * v),
277
+ rz = D[1] - 0.03 - 0.05 * v - tuft * 0.05,
278
+ r = 0.026 * (1 - 0.3 * v) * (1 - 0.4 * tuft),
279
+ cx = Math.cos(a),
280
+ cy = Math.sin(a),
281
+ long = (len * (0.75 + 0.3 * scatter(i * 6.1)) - 0.1 * v) * (1 - 0.45 * tuft),
282
+ half = (0.012 + 0.006 * scatter(i * 8.3)) * (q > 1 ? 1 : 1.5);
283
+ for (let j = 0; j <= segs; j++) {
284
+ const t = j / segs,
285
+ spread = r + (0.025 * Math.sin(Math.min(1, t * 2.2) * Math.PI * 0.5) + 0.01 * t) * (1 - 0.5 * tuft), // fuller below the dock
286
+ back = 0.07 * Math.sin(Math.min(1, t * 2) * Math.PI * 0.5);
287
+ _lockPts[j] = [cx * spread, ry - long * t + cy * r * (1 - t), rz - back + cy * spread * 0.6];
288
+ _lockOuts[j] = [cx, 0, cy];
289
+ }
290
+ _lockPts.length = _lockOuts.length = segs + 1;
291
+ const tone = 0.75 + 0.45 * scatter(i * 2.3);
292
+ ribbon(
293
+ b,
294
+ _lockPts,
295
+ _lockOuts,
296
+ half,
297
+ root.map(v => v * tone),
298
+ tip.map(v => v * tone),
299
+ t => [BONE.tail + 1, BONE.tail + 2, (1 - sstep(0.05, 0.6, t)) * (1 - tuft)],
300
+ );
301
+ }
302
+ }
303
+
304
+ export { forelock, hair };
@@ -0,0 +1,133 @@
1
+ import { sstep } from '../math/scalar.js';
2
+ import { spline } from './animal-skin.js';
3
+
4
+ // ════════════════════════════════════════════════════════════════════════
5
+ // A horse's head as a shape, in head lengths times k (z from the poll forward to the muzzle, y up the face, x to the side):
6
+ // the stations its skin is lofted through (animal-horse-body.js) and points on that skin, so that what lies on the face, the bridle's
7
+ // straps (animal-horse-bridle.js), lies on it and does not stand off it. Plain arithmetic, for a pool's workers.
8
+ // ════════════════════════════════════════════════════════════════════════
9
+
10
+ // The head's stations (animal-skin.js tube: [y, z, half-width, rise, fall, bone, squareness]): a broad jowl behind, the face
11
+ // narrowing to the muzzle, which swells a little round the nostrils and closes at the lips.
12
+ function headStations(k) {
13
+ return [
14
+ [0.002 * k, -0.028 * k, 0, 0, 0, 0],
15
+ [0, -0.005 * k, 0.05 * k, 0.046 * k, 0.062 * k, 0],
16
+ [-0.006 * k, 0.05 * k, 0.068 * k, 0.052 * k, 0.09 * k, 0, 2.2],
17
+ [-0.012 * k, 0.115 * k, 0.073 * k, 0.054 * k, 0.094 * k, 0, 2.3],
18
+ [-0.014 * k, 0.185 * k, 0.058 * k, 0.046 * k, 0.074 * k, 0.4, 2.5],
19
+ [-0.016 * k, 0.255 * k, 0.045 * k, 0.04 * k, 0.052 * k, 0.5, 2.7],
20
+ [-0.016 * k, 0.315 * k, 0.04 * k, 0.038 * k, 0.043 * k, 0.5, 2.7],
21
+ [-0.0145 * k, 0.34 * k, 0.042 * k, 0.039 * k, 0.044 * k, 0.5, 2.65],
22
+ [-0.013 * k, 0.362 * k, 0.044 * k, 0.04 * k, 0.043 * k, 0.5, 2.6],
23
+ [-0.013 * k, 0.378 * k, 0.041 * k, 0.037 * k, 0.04 * k, 0.5, 2.5],
24
+ [-0.014 * k, 0.39 * k, 0.034 * k, 0.03 * k, 0.034 * k, 0.5],
25
+ [-0.015 * k, 0.399 * k, 0.024 * k, 0.022 * k, 0.026 * k, 0.5],
26
+ [-0.016 * k, 0.404 * k, 0, 0, 0, 0.5],
27
+ ];
28
+ }
29
+
30
+ // The right eye's middle, in head lengths: to the side, up, forward
31
+ const EYE = [0.064, 0.012, 0.118],
32
+ // the mouth's line: its height at the corner and at the front, the corner's place forward; the chin's height and place
33
+ MOUTH = [-0.034, -0.026, 0.3, -0.052, 0.352];
34
+
35
+ // How far the skin at (x, y, z) is pushed out to the side by the bone under it: the brow over the eye, the eye's socket under it,
36
+ // the round plate of the jaw. The head's own warp adds the nostrils and the lips, which nothing lies on.
37
+ function boneUnder(x, y, z, k) {
38
+ const ex = Math.abs(x) - EYE[0] * k,
39
+ ey = y - EYE[1] * k,
40
+ ez = z - EYE[2] * k,
41
+ sink = sstep(0.021 * k, 0.007 * k, Math.hypot(ex, ey * 1.7, ez)) * 0.008 * k, // inside the lids, for the ball
42
+ brow = sstep(0.032 * k, 0.01 * k, Math.hypot(ex, ey - 0.02 * k, ez)) * 0.008 * k,
43
+ cheek = sstep(0.055 * k, 0.02 * k, Math.hypot(y + 0.04 * k, z - 0.085 * k)) * 0.007 * k;
44
+ return brow - sink + cheek;
45
+ }
46
+
47
+ const DA = 0.02, // radians, and head lengths along it: the steps over which the skin's slope is found
48
+ DZ = 0.004,
49
+ FIND = 24; // halvings that find where along the stations a z lies
50
+
51
+ // Points on the skin of a head of size k, as the tube lofts it through the stations. at(z, a, out): the point at z whose section
52
+ // angle is a (0 the right side, a quarter turn the top), lifted `out` off the skin along its outward normal, as
53
+ // [x, y, z, nx, ny, nz]. side(z, y, s, out): the same for the point at height y on the side s (1 right, -1 left).
54
+ function headSkin(k) {
55
+ const S = headStations(k),
56
+ n = S.length,
57
+ station = (j, i, t) => spline(S[Math.max(0, i - 1)][j], S[i][j], S[Math.min(n - 1, i + 1)][j], S[Math.min(n - 1, i + 2)][j], t),
58
+ // the section at a place along the stations, u (from 0 to n - 1): as tube() makes its rings
59
+ section = u => {
60
+ const i = Math.min(n - 2, Math.floor(u)),
61
+ t = u - i,
62
+ ty0 = station(0, i, t + 0.02) - station(0, i, t - 0.02),
63
+ tz0 = station(1, i, t + 0.02) - station(1, i, t - 0.02),
64
+ l = Math.hypot(ty0, tz0) || 1;
65
+ return {
66
+ y: station(0, i, t),
67
+ z: station(1, i, t),
68
+ ty: ty0 / l,
69
+ tz: tz0 / l,
70
+ w: Math.max(0, station(2, i, t)),
71
+ u: Math.max(0, station(3, i, t)),
72
+ d: Math.max(0, station(4, i, t)),
73
+ e: 2 / ((S[i][6] ?? 2) + ((S[i + 1][6] ?? 2) - (S[i][6] ?? 2)) * t),
74
+ };
75
+ },
76
+ // where along the stations the middle of the section lies at z
77
+ along = z => {
78
+ let lo = 0,
79
+ hi = n - 1;
80
+ for (let i = 0; i < FIND; i++) {
81
+ const mid = (lo + hi) / 2;
82
+ if (section(mid).z < z) lo = mid;
83
+ else hi = mid;
84
+ }
85
+ return (lo + hi) / 2;
86
+ },
87
+ bare = (z, a) => {
88
+ const s = section(along(z)),
89
+ c = Math.cos(a),
90
+ sn = Math.sin(a),
91
+ sy = Math.sign(sn) * Math.abs(sn) ** s.e * (sn > 0 ? s.u : s.d),
92
+ x = Math.sign(c) * Math.abs(c) ** s.e * s.w,
93
+ y = s.y + s.tz * sy,
94
+ zz = s.z - s.ty * sy;
95
+ return [x + Math.sign(c) * boneUnder(x, y, zz, k), y, zz, s.y];
96
+ },
97
+ at = (z, a, out = 0) => {
98
+ const P = bare(z, a),
99
+ A0 = bare(z, a - DA),
100
+ A1 = bare(z, a + DA),
101
+ Z0 = bare(z - DZ * k, a),
102
+ Z1 = bare(z + DZ * k, a),
103
+ ux = A1[0] - A0[0],
104
+ uy = A1[1] - A0[1],
105
+ uz = A1[2] - A0[2],
106
+ vx = Z1[0] - Z0[0],
107
+ vy = Z1[1] - Z0[1],
108
+ vz = Z1[2] - Z0[2];
109
+ let nx = uy * vz - uz * vy,
110
+ ny = uz * vx - ux * vz,
111
+ nz = ux * vy - uy * vx;
112
+ const l = Math.hypot(nx, ny, nz) || 1,
113
+ outward = nx * P[0] + ny * (P[1] - P[3]) < 0 ? -1 / l : 1 / l; // away from the section's middle
114
+ nx *= outward;
115
+ ny *= outward;
116
+ nz *= outward;
117
+ return [P[0] + nx * out, P[1] + ny * out, P[2] + nz * out, nx, ny, nz];
118
+ },
119
+ // the angle on the right side of the section at z whose height is y
120
+ angleOf = (z, y) => {
121
+ const sec = section(along(z)),
122
+ h = y - sec.y,
123
+ reach = Math.min(1, Math.abs(h) / Math.max(1e-6, h > 0 ? sec.u : sec.d)) ** (1 / sec.e); // |sin| of the angle
124
+ return Math.sign(h) * Math.asin(reach);
125
+ },
126
+ side = (z, y, s, out = 0) => {
127
+ const a = angleOf(z, y);
128
+ return at(z, s > 0 ? a : Math.PI - a, out);
129
+ };
130
+ return { angleOf, at, side };
131
+ }
132
+
133
+ export { EYE, MOUTH, boneUnder, headSkin, headStations };