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,157 @@
1
+ import * as THREE from 'three';
2
+ import { TRS } from './primitives.js';
3
+ import { SHAPES } from './animal-shapes.js';
4
+ import { tube } from './animal-skin.js';
5
+ import { bridle } from './animal-horse-bridle.js';
6
+ import { BONE } from '../motion/quadruped.js';
7
+
8
+ // ════════════════════════════════════════════════════════════════════════
9
+ // A horse's tack, fitted to its own body (animal-horse-body.js): the saddle cloth and the saddle lie on the trunk's sections, the
10
+ // girth goes round the barrel behind the elbows, the stirrups hang from their leathers, the bridle is strapped to
11
+ // the head, and the reins run from the bit back to the rider's hands.
12
+ // ════════════════════════════════════════════════════════════════════════
13
+ const LEATHER = [0.16, 0.09, 0.05],
14
+ WORN = [0.24, 0.15, 0.09],
15
+ IRON = [0.32, 0.31, 0.3],
16
+ TRUNK = [BONE.hips, BONE.chest, BONE.neck, BONE.neck2, BONE.head],
17
+ POLISHED = 0.9, // tags: leather that has been sat on,
18
+ WOVEN = 0.1, // cloth,
19
+ METAL = 1.6,
20
+ BARREL = 10, // how many of the trunk's stations are the body (the rest are the neck)
21
+ REINS_APART = 0.06; // half the width between the rider's hands, where the reins end, in withers heights
22
+
23
+ // The trunk's section at z along the body, between the stations either side of it.
24
+ function sectionAt(S, z) {
25
+ let i = 1;
26
+ while (i < BARREL - 2 && S[i + 1][1] < z) i++;
27
+ const t = (z - S[i][1]) / (S[i + 1][1] - S[i][1]);
28
+ return S[i].map((v, k) => v + (S[i + 1][k] - v) * t);
29
+ }
30
+ // That section, standing off the body by `grow`, its top raised by `lift` more.
31
+ function over(S, z, grow, lift = 0) {
32
+ const s = sectionAt(S, z);
33
+ s[2] += grow;
34
+ s[3] += grow + lift;
35
+ s[4] += grow;
36
+ return s;
37
+ }
38
+
39
+ // Saddles and bridles a horse. b: the mesh being built, in withers heights; S: the trunk's stations; A: its joints; cloth: the
40
+ // saddle cloth's colour; q: the detail (0 far, 1 between, 2 near); HM: the head's place; K: the horse's size.
41
+ function tackUp(b, S, A, p, cloth, q, HM, K) {
42
+ const fine = q > 0,
43
+ zF = A.fetlock[1],
44
+ around = fine ? 16 : 8,
45
+ plain = c => col => {
46
+ col[0] = c[0];
47
+ col[1] = c[1];
48
+ col[2] = c[2];
49
+ col[3] = c === cloth ? WOVEN : POLISHED;
50
+ },
51
+ // the cloth: over the back and well down each flank, with a darker border
52
+ woven = (col, x, y, z, nx, ny, nz, a, v) => {
53
+ const edge = Math.min(v, 1 - v) < 0.12 || Math.abs(a - Math.PI / 2) > 1.95 ? 0.6 : 1,
54
+ weave = 0.92 + 0.16 * (Math.sin(z * 260) * Math.sin(y * 260) > 0 ? 1 : 0);
55
+ col[0] = cloth[0] * edge * weave;
56
+ col[1] = cloth[1] * edge * weave;
57
+ col[2] = cloth[2] * edge * weave;
58
+ col[3] = WOVEN;
59
+ };
60
+ tube(
61
+ b,
62
+ [zF - 0.44, zF - 0.34, zF - 0.2, zF - 0.06, zF + 0.0].map(z => over(S, z, 0.008)),
63
+ {
64
+ chain: TRUNK,
65
+ arc: [-0.62, Math.PI + 0.62],
66
+ around,
67
+ sub: fine ? 2 : 1,
68
+ coat: woven,
69
+ },
70
+ );
71
+ // the saddle: a seat between a pommel and a cantle, and a flap down each side
72
+ tube(
73
+ b,
74
+ [
75
+ over(S, zF - 0.37, 0.02, 0.07),
76
+ over(S, zF - 0.33, 0.022, 0.035),
77
+ over(S, zF - 0.22, 0.022, 0.012),
78
+ over(S, zF - 0.1, 0.022, 0.03),
79
+ over(S, zF - 0.06, 0.02, 0.075),
80
+ over(S, zF - 0.035, 0.012, 0.03),
81
+ ],
82
+ {
83
+ chain: TRUNK,
84
+ arc: [0.5, Math.PI - 0.5],
85
+ around: fine ? 12 : 6,
86
+ sub: fine ? 2 : 1,
87
+ coat: plain(LEATHER),
88
+ },
89
+ );
90
+ for (const [a0, a1] of [
91
+ [-0.42, 0.62],
92
+ [Math.PI - 0.62, Math.PI + 0.42],
93
+ ])
94
+ tube(
95
+ b,
96
+ [zF - 0.3, zF - 0.2, zF - 0.1].map(z => over(S, z, 0.017)),
97
+ { chain: TRUNK, arc: [a0, a1], around: fine ? 6 : 4, sub: 1, coat: plain(WORN) },
98
+ );
99
+ // the girth, behind the elbows
100
+ tube(
101
+ b,
102
+ [zF - 0.135, zF - 0.1].map(z => over(S, z, 0.012)),
103
+ { chain: TRUNK, around, sub: 1, coat: plain(LEATHER) },
104
+ );
105
+ // stirrups on their leathers
106
+ const side = sectionAt(S, zF - 0.19),
107
+ out = side[2] - 0.012;
108
+ b.bone = BONE.chest;
109
+ for (const s of [-1, 1]) {
110
+ b.tv = POLISHED;
111
+ b.add(SHAPES.box, LEATHER, TRS(s * out, 0.52, zF - 0.19, 0.008, 0.33, 0.022));
112
+ b.tv = METAL;
113
+ b.add(SHAPES.box, IRON, TRS(s * out, 0.46, zF - 0.19, 0.06, 0.008, 0.04));
114
+ for (const e of [-1, 1]) b.add(SHAPES.box, IRON, TRS(s * out + e * 0.028, 0.46, zF - 0.19, 0.007, 0.065, 0.026, 0, 0, -e * 0.22));
115
+ }
116
+ // the bridle, on the head, and where the reins are buckled to its bit
117
+ const M0 = b.M;
118
+ b.M = HM;
119
+ const bit = bridle(b, p.head, q);
120
+ b.M = M0;
121
+ // the reins: from each ring of the bit back along the neck to the rider's hands over the withers, slack in the middle. Their
122
+ // far ends follow the crest bone, which a rider's hands carry
123
+ const hand = [REINS_APART, A.hands[0], A.hands[1]],
124
+ SPANS = fine ? 8 : 3,
125
+ v = new THREE.Vector3();
126
+ b.tv = POLISHED;
127
+ for (const s of [-1, 1]) {
128
+ const from = v
129
+ .set(bit[s][0], bit[s][1], bit[s][2])
130
+ .applyMatrix4(HM)
131
+ .toArray()
132
+ .map(c => c / K),
133
+ at = i => {
134
+ const t = i / SPANS,
135
+ sag = 0.05 * Math.sin(Math.PI * t);
136
+ return [
137
+ from[0] + (s * hand[0] - from[0]) * t + s * 0.03 * Math.sin(Math.PI * t),
138
+ from[1] + (hand[1] - from[1]) * t - sag,
139
+ from[2] + (hand[2] - from[2]) * t,
140
+ 1 - t,
141
+ ];
142
+ },
143
+ put = (q, dy) => b.raw(q[0], q[1] + dy, q[2], s, 0.2, 0, LEATHER[0], LEATHER[1], LEATHER[2], BONE.head, BONE.crest, q[3]);
144
+ for (let i = 0; i < SPANS; i++) {
145
+ const P = at(i),
146
+ Q = at(i + 1);
147
+ put(P, 0);
148
+ put(Q, 0);
149
+ put(Q, 0.014);
150
+ put(P, 0);
151
+ put(Q, 0.014);
152
+ put(P, 0.014);
153
+ }
154
+ }
155
+ }
156
+
157
+ export { tackUp };
@@ -0,0 +1,59 @@
1
+ import { createNoise } from '../math/noise.js';
2
+
3
+ /**
4
+ * What a world tells the animal kit about itself, passed as the last argument of the kit's builders, casts and poses. Every
5
+ * field is optional: with none the kit draws its own generic animals.
6
+ * @typedef {object} AnimalKitOptions
7
+ * @property {{ fbm: Function, vnoise: Function }} [noise] Seeded noise (`createNoise` of math/noise.js) for dappled, mottled and
8
+ * woolly coats; pass the world's own to repeat its look. Defaults to `createNoise()` (seed 0).
9
+ * @property {Object<string, object>} [horseBuilds] Horse builds of the world's own by name, beside `HORSE_BUILDS`.
10
+ * @property {Object<string, object>} [cattleBuilds] Cattle builds of the world's own by name, beside `CATTLE_BUILDS`; a row may
11
+ * carry its own coat, fur and grazing bend (see `CATTLE_BUILDS`).
12
+ * @property {Object<string, object>} [canineBreeds] Canine breeds of the world's own by name, beside `CANINE_BREEDS`.
13
+ * @property {string} [canineFallback] The breed a look whose breed is unknown takes. Defaults to `'cur'`.
14
+ * @property {number} [canineGirth] How much a canine figure is scaled up beyond its look's height. Defaults to 1.
15
+ * @property {{ blanket?: number[], rugs?: number[][] }} [camelPack] The colours of a pack camel's blanket and of its rugs, linear
16
+ * [r, g, b]. Defaults to undyed wool.
17
+ * @property {{ saddleCloth?: number, coat?: number }} [troop] A column's horses: their saddle cloth and their coat (sRGB hex),
18
+ * which each instance's colour tints. Defaults to a brown cloth on a pale coat.
19
+ */
20
+
21
+ /** The options of the kit's generic animals: nothing of any world. */
22
+ export const NO_ANIMAL_OPTIONS = Object.freeze({});
23
+
24
+ let generic = null; // the default noise, made the first time an animal without a world's noise needs it
25
+
26
+ /**
27
+ * The noise an animal's coat is shaded with: the world's, or the generic default.
28
+ * @param {AnimalKitOptions} options
29
+ * @returns {{ fbm: Function, vnoise: Function }}
30
+ */
31
+ export function animalNoise(options) {
32
+ return options.noise ?? (generic ??= createNoise());
33
+ }
34
+
35
+ /**
36
+ * A row of a table of presets by name: the world's own row if it has one, else the kit's; for a name neither knows, the
37
+ * `fallback` row, again the world's before the kit's.
38
+ * @param {string} name The preset asked for.
39
+ * @param {Object<string, object> | undefined} own The world's own rows.
40
+ * @param {Object<string, object>} kit The kit's rows.
41
+ * @param {string} fallback The row for a name neither knows.
42
+ */
43
+ export function presetOf(name, own, kit, fallback) {
44
+ return own?.[name] || kit[name] || own?.[fallback] || kit[fallback];
45
+ }
46
+
47
+ /**
48
+ * A cache of things the kit makes once for each world's options (a model posed for casting, say), so that two worlds on one
49
+ * page never share one: a map from the options to the world's own entries by key.
50
+ * @returns {(options: AnimalKitOptions) => Object<string, any>}
51
+ */
52
+ export function cachePerOptions() {
53
+ const caches = new WeakMap();
54
+ return options => {
55
+ let cache = caches.get(options);
56
+ if (!cache) caches.set(options, (cache = {}));
57
+ return cache;
58
+ };
59
+ }
@@ -0,0 +1,21 @@
1
+ import * as THREE from 'three';
2
+ import { box } from './primitives.js';
3
+
4
+ /**
5
+ * The unit shapes the animal kit lays its small parts with (eyes, teeth, hooves, horn tips, buckles, a hen's comb), the same
6
+ * geometries `createUnitShapes` makes for them, made once here so that the kit needs no noise to build them. Each is a metre
7
+ * across (or tall) about its own origin; an animal's builder scales and places it with a matrix.
8
+ * - `sph`: a ball 1 m across (80 faces); `head`: a finer ball 1 m across (320 faces).
9
+ * - `cone`, `cone6`: a cone 1 m across its foot and 1 m tall, standing on y = 0, round in 10 and in 6 sides.
10
+ * - `box`: a cube 1 m on a side, standing on y = 0.
11
+ * - `cyl`, `cyl6`: a cylinder 1 m across and 1 m tall, standing on y = 0, round in 10 and in 6 sides.
12
+ */
13
+ export const SHAPES = {
14
+ sph: new THREE.IcosahedronGeometry(0.5, 1),
15
+ head: new THREE.IcosahedronGeometry(0.5, 2),
16
+ cone: new THREE.ConeGeometry(0.5, 1, 10).translate(0, 0.5, 0),
17
+ cone6: new THREE.ConeGeometry(0.5, 1, 6).translate(0, 0.5, 0),
18
+ box,
19
+ cyl: new THREE.CylinderGeometry(0.5, 0.5, 1, 10).translate(0, 0.5, 0),
20
+ cyl6: new THREE.CylinderGeometry(0.5, 0.5, 1, 6).translate(0, 0.5, 0),
21
+ };
@@ -0,0 +1,390 @@
1
+ import { TAU } from '../math/scalar.js';
2
+ import { TRS } from './primitives.js';
3
+ import { SHAPES } from './animal-shapes.js';
4
+
5
+ // ════════════════════════════════════════════════════════════════════════
6
+ // The skin of a beast (a dog, a horse): tubes lofted along a path in the body's upright plane, each ring with its own
7
+ // width, rise and fall, so a ribcage, a tucked belly, a thigh or a muzzle is a list of stations; and the locks of a coat.
8
+ // Everything goes into a GB as weighted vertices (GB.raw): x is the beast's side, y up, z its nose.
9
+ // ════════════════════════════════════════════════════════════════════════
10
+ const _p = [], // ring points of the tube being built
11
+ _n = [], // and their normals
12
+ _c = [], // the centre and tangent of each ring: y, z, ty, tz, radius
13
+ _x = [], // and each ring's place to the side
14
+ _col = [0, 0, 0, 0], // a vertex's colour and tag, as a coat function fills it
15
+ _fur = [0, 0, 0, 1, 0, -1], // a lock as a fur function fills it: length, lift, width, how many at the point, the tips' shade, the tips' bone
16
+ _bw = [0, 0, 1], // a vertex's two bones and the first one's weight, as a bind function fills it
17
+ EYE_TAG = 2, // the tag of an eye's surface: wet and glossy, so it catches the light (as a figure material reads its tags)
18
+ DARK_EYE = [0.02, 0.016, 0.014];
19
+
20
+ // A number between 0 and 1 from any number, the same every time.
21
+ const scatter = v => {
22
+ const s = Math.sin(v * 12.9898) * 43758.5453;
23
+ return s - Math.floor(s);
24
+ };
25
+ // A uniform Catmull-Rom spline through four values: b at t = 0, c at t = 1, a and d steering the ends.
26
+ const spline = (a, b, c, d, t) => 0.5 * (2 * b + (c - a) * t + (2 * a - 5 * b + 4 * c - d) * t * t + (3 * b - a - 3 * c + d) * t * t * t);
27
+
28
+ // A lock of the coat: two crossed blades rooted at p, lying along d (a unit vector), shaded as the skin they grow from.
29
+ // The roots follow the skin's bones; the tips may follow another (tip: a bone), which is how hackles and a mane rise.
30
+ function lock(gb, p, d, n, len, wide, root, end, b1, b2, w, tip = -1) {
31
+ const ax = d[1] * n[2] - d[2] * n[1],
32
+ ay = d[2] * n[0] - d[0] * n[2],
33
+ az = d[0] * n[1] - d[1] * n[0],
34
+ al = Math.hypot(ax, ay, az) || 1,
35
+ h = wide / 2,
36
+ tx = p[0] + d[0] * len,
37
+ ty = p[1] + d[1] * len,
38
+ tz = p[2] + d[2] * len,
39
+ tb = tip < 0 ? b1 : tip,
40
+ tb2 = tip < 0 ? b2 : tip,
41
+ tw = tip < 0 ? w : 1;
42
+ // one blade lying in the coat, one standing on it
43
+ for (const [sx, sy, sz] of [
44
+ [(ax / al) * h, (ay / al) * h, (az / al) * h],
45
+ [n[0] * h, n[1] * h, n[2] * h],
46
+ ]) {
47
+ gb.raw(p[0] - sx, p[1] - sy, p[2] - sz, n[0], n[1], n[2], root[0], root[1], root[2], b1, b2, w);
48
+ gb.raw(p[0] + sx, p[1] + sy, p[2] + sz, n[0], n[1], n[2], root[0], root[1], root[2], b1, b2, w);
49
+ gb.raw(tx, ty, tz, n[0], n[1], n[2], end[0], end[1], end[2], tb, tb2, tw);
50
+ }
51
+ }
52
+
53
+ // A skin lofted through stations along a path. A station is [y, z, half-width, rise, fall, bone, squareness, lean]: the section
54
+ // stands across the path, `rise` on the side that is up when the path runs forward (the front, when it runs down a leg) and
55
+ // `fall` on the other; `bone` is a place along o.chain (1.5: halfway between its second and third bones); squareness 2 is an
56
+ // ellipse, more is boxier; lean moves the station outwards (inwards when negative) from the path's own side. The stations are
57
+ // joined by a spline, o.sub rings to a span, o.around points to a ring.
58
+ // o.x, o.side the path's place to the side, and -1 to mirror the section for a left limb
59
+ // o.coat(col, x, y, z, nx, ny, nz, a, v) fills col with the colour and the tag (how smooth) at a point
60
+ // o.warp(p, q, a, v) moves the point p[q..q+2] before the normals are found (a socket, a muscle, a toe)
61
+ // o.bind(bw, x, y, z) fills bw with a point's own two bones and the first one's weight, instead of the chain's
62
+ // o.fur(out, x, y, z, nx, ny, nz, a, v) fills out with a lock's length, lift (0 lying to 1 standing) and width, then optionally how
63
+ // many locks stand at the point, the shade of their tips, and the bone the tips follow; or returns false
64
+ // o.lay which way the coat lies along the path: -1 back towards the first station, 1 on towards the last
65
+ // o.droop how heavily the locks hang (a mane hangs straight down)
66
+ // o.arc [from, to]: only that part of each ring, as an open sheet (angles from the side, a quarter turn is the top)
67
+ function tube(gb, S, o) {
68
+ const n = S.length,
69
+ sub = o.sub ?? 3,
70
+ seg = o.around ?? 12,
71
+ rings = (n - 1) * sub + 1,
72
+ side = o.side ?? 1,
73
+ x0 = o.x ?? 0,
74
+ chain = o.chain,
75
+ arc = o.arc,
76
+ angle = j => (arc ? arc[0] + ((arc[1] - arc[0]) * j) / (seg - 1) : (j / seg) * TAU),
77
+ P = _p,
78
+ N = _n,
79
+ R = _c,
80
+ X = _x;
81
+ const at = (k, i, t) => spline(S[Math.max(0, i - 1)][k], S[i][k], S[Math.min(n - 1, i + 1)][k], S[Math.min(n - 1, i + 2)][k], t);
82
+ for (let r = 0; r < rings; r++) {
83
+ const i = Math.min(n - 2, (r / sub) | 0),
84
+ t = r / sub - i,
85
+ y = at(0, i, t),
86
+ z = at(1, i, t),
87
+ w = Math.max(0, at(2, i, t)),
88
+ u = Math.max(0, at(3, i, t)),
89
+ d = Math.max(0, at(4, i, t)),
90
+ e = 2 / ((S[i][6] ?? 2) + ((S[i + 1][6] ?? 2) - (S[i][6] ?? 2)) * t),
91
+ xc = x0 + side * ((S[i][7] ?? 0) + ((S[i + 1][7] ?? 0) - (S[i][7] ?? 0)) * t);
92
+ let ty = at(0, i, t + 0.02) - at(0, i, t - 0.02),
93
+ tz = at(1, i, t + 0.02) - at(1, i, t - 0.02);
94
+ const tl = Math.hypot(ty, tz) || 1;
95
+ ty /= tl;
96
+ tz /= tl;
97
+ R[r * 5] = y;
98
+ R[r * 5 + 1] = z;
99
+ R[r * 5 + 2] = ty;
100
+ R[r * 5 + 3] = tz;
101
+ R[r * 5 + 4] = Math.max(w, u, d);
102
+ X[r] = xc;
103
+ for (let j = 0; j < seg; j++) {
104
+ const a = angle(j),
105
+ c = Math.cos(a),
106
+ s = Math.sin(a),
107
+ cx = Math.sign(c) * Math.abs(c) ** e,
108
+ sy = Math.sign(s) * Math.abs(s) ** e * (s > 0 ? u : d),
109
+ q = (r * seg + j) * 3;
110
+ P[q] = xc + side * cx * w;
111
+ P[q + 1] = y + tz * sy;
112
+ P[q + 2] = z - ty * sy;
113
+ if (o.warp) o.warp(P, q, a, r / (rings - 1));
114
+ }
115
+ }
116
+ // normals from the neighbours in the grid, turned outwards; a ring closed to a point looks along the path
117
+ for (let r = 0; r < rings; r++)
118
+ for (let j = 0; j < seg; j++) {
119
+ const q = (r * seg + j) * 3,
120
+ A = (r * seg + (arc ? Math.max(0, j - 1) : (j + seg - 1) % seg)) * 3,
121
+ B = (r * seg + (arc ? Math.min(seg - 1, j + 1) : (j + 1) % seg)) * 3,
122
+ C = (Math.max(0, r - 1) * seg + j) * 3,
123
+ D = (Math.min(rings - 1, r + 1) * seg + j) * 3,
124
+ ax = P[B] - P[A],
125
+ ay = P[B + 1] - P[A + 1],
126
+ az = P[B + 2] - P[A + 2],
127
+ bx = P[D] - P[C],
128
+ by = P[D + 1] - P[C + 1],
129
+ bz = P[D + 2] - P[C + 2];
130
+ let nx = ay * bz - az * by,
131
+ ny = az * bx - ax * bz,
132
+ nz = ax * by - ay * bx;
133
+ const l = Math.hypot(nx, ny, nz);
134
+ if (l < 1e-9 || R[r * 5 + 4] < 1e-5) {
135
+ const end = r < rings / 2 ? -1 : 1;
136
+ nx = 0;
137
+ ny = R[r * 5 + 2] * end;
138
+ nz = R[r * 5 + 3] * end;
139
+ } else {
140
+ const out = nx * (P[q] - X[r]) + ny * (P[q + 1] - R[r * 5]) + nz * (P[q + 2] - R[r * 5 + 1]) < 0 ? -1 / l : 1 / l;
141
+ nx *= out;
142
+ ny *= out;
143
+ nz *= out;
144
+ }
145
+ N[q] = nx;
146
+ N[q + 1] = ny;
147
+ N[q + 2] = nz;
148
+ }
149
+ const col = _col,
150
+ bones = r => {
151
+ const i = Math.min(n - 2, (r / sub) | 0),
152
+ f = S[i][5] + (S[i + 1][5] - S[i][5]) * (r / sub - i),
153
+ k = Math.min(chain.length - 1, f | 0);
154
+ return [chain[k], chain[Math.min(chain.length - 1, k + 1)], 1 - (f - k)];
155
+ },
156
+ put = (r, j, bw) => {
157
+ const q = (r * seg + (j % seg)) * 3,
158
+ a = angle(j % seg);
159
+ o.coat(col, P[q], P[q + 1], P[q + 2], N[q], N[q + 1], N[q + 2], a, r / (rings - 1));
160
+ gb.tv = col[3];
161
+ if (o.bind) o.bind((bw = _bw), P[q], P[q + 1], P[q + 2]);
162
+ gb.raw(P[q], P[q + 1], P[q + 2], N[q], N[q + 1], N[q + 2], col[0], col[1], col[2], bw[0], bw[1], bw[2]);
163
+ };
164
+ // the grid's triangles wound to face where the normals face (a mirrored side or a path run backwards turns them), so that a
165
+ // single-sided material shows the outside
166
+ const cols = arc ? seg - 1 : seg,
167
+ turn = facing(P, N, rings, seg, cols) < 0 ? 1 : 0;
168
+ for (let r = 0; r < rings - 1; r++) {
169
+ const b0 = bones(r),
170
+ b1 = bones(r + 1),
171
+ shut0 = R[r * 5 + 4] < 1e-5,
172
+ shut1 = R[(r + 1) * 5 + 4] < 1e-5;
173
+ for (let j = 0; j < cols; j++) {
174
+ if (!shut1) {
175
+ put(r, j, b0);
176
+ put(r + 1, j + turn, b1);
177
+ put(r + 1, j + 1 - turn, b1);
178
+ }
179
+ if (!shut0) {
180
+ put(r, j, b0);
181
+ put(r + 1 - turn, j + 1, turn ? b0 : b1);
182
+ put(r + turn, j + 1, turn ? b1 : b0);
183
+ }
184
+ }
185
+ }
186
+ if (!o.fur) return;
187
+ // the coat's locks, rooted at the grid's points and scattered between them, lying along the path and falling a little under their weight
188
+ const lay = o.lay ?? -1,
189
+ droop = o.droop ?? 0.25,
190
+ fur = _fur,
191
+ p = [0, 0, 0],
192
+ d = [0, 0, 0],
193
+ nn = [0, 0, 0],
194
+ end = [0, 0, 0];
195
+ for (let r = 1; r < rings - 1; r++) {
196
+ const bw = bones(r);
197
+ for (let j = 0; j < seg; j++) {
198
+ const q = (r * seg + j) * 3,
199
+ qa = (r * seg + ((j + 1) % seg)) * 3, // the next point round the ring, and the next along the path: locks stand between
200
+ qv = ((r + 1) * seg + j) * 3,
201
+ a = angle(j),
202
+ v = r / (rings - 1);
203
+ fur[3] = 1;
204
+ fur[4] = 0;
205
+ fur[5] = -1;
206
+ if (o.fur(fur, P[q], P[q + 1], P[q + 2], N[q], N[q + 1], N[q + 2], a, v) === false || fur[0] <= 0) continue;
207
+ const lift = fur[1];
208
+ d[0] = N[q] * lift;
209
+ d[1] = R[r * 5 + 2] * lay * (1 - lift) + N[q + 1] * lift - droop * (1 - lift);
210
+ d[2] = R[r * 5 + 3] * lay * (1 - lift) + N[q + 2] * lift;
211
+ const dl = Math.hypot(d[0], d[1], d[2]) || 1;
212
+ d[0] /= dl;
213
+ d[1] /= dl;
214
+ d[2] /= dl;
215
+ nn[0] = N[q];
216
+ nn[1] = N[q + 1];
217
+ nn[2] = N[q + 2];
218
+ for (let k = 0; k < (fur[3] || 1); k++) {
219
+ const ta = scatter(q + k),
220
+ tv = scatter(q + k + 0.5);
221
+ for (let i = 0; i < 3; i++) p[i] = P[q + i] + (P[qa + i] - P[q + i]) * ta + (P[qv + i] - P[q + i]) * tv;
222
+ o.coat(col, p[0], p[1], p[2], nn[0], nn[1], nn[2], a, v);
223
+ gb.tv = col[3];
224
+ const shade = fur[4] || 1.1; // tips paler than the roots, or darker where the guard hairs are tipped
225
+ end[0] = col[0] * shade;
226
+ end[1] = col[1] * shade;
227
+ end[2] = col[2] * shade;
228
+ lock(gb, p, d, nn, fur[0] * (0.8 + 0.4 * scatter(q + k + 0.25)), fur[2], col, end, bw[0], bw[1], bw[2], fur[5]);
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ // Which way a tube's grid is wound against its normals: the sum over its quads of the first triangle's turn along the normal at its
235
+ // corner (positive: the triangles (r, j), (r + 1, j), (r + 1, j + 1) face outwards).
236
+ function facing(P, N, rings, seg, cols) {
237
+ let sum = 0;
238
+ for (let r = 0; r < rings - 1; r++)
239
+ for (let j = 0; j < cols; j++) {
240
+ const q = (r * seg + j) * 3,
241
+ b = ((r + 1) * seg + j) * 3,
242
+ c = ((r + 1) * seg + ((j + 1) % seg)) * 3,
243
+ ux = P[b] - P[q],
244
+ uy = P[b + 1] - P[q + 1],
245
+ uz = P[b + 2] - P[q + 2],
246
+ vx = P[c] - P[q],
247
+ vy = P[c + 1] - P[q + 1],
248
+ vz = P[c + 2] - P[q + 2];
249
+ sum += (uy * vz - uz * vy) * N[q] + (uz * vx - ux * vz) * N[q + 1] + (ux * vy - uy * vx) * N[q + 2];
250
+ }
251
+ return sum;
252
+ }
253
+
254
+ // A leaf of skin standing on a base: an ear. It runs `len` along `up` from `base`, `wide` across `across` at its broadest, cupped
255
+ // towards `front`; past `fold` of its length (1: no fold) the rest tips over forwards. All its points follow one bone. point: 0 a
256
+ // leaf rounded at its root, 1 a triangle broadest at its root (a cat's ear). both: drawn on both faces, for a material that shows
257
+ // only the side a triangle faces (a herd's): its inside facing `front`, the back of it in the outer colour facing away.
258
+ function leaf(gb, base, up, across, front, len, wide, cup, fold, col, inner, bone, point = 0, both = false) {
259
+ const ROWS = 6,
260
+ pt = (i, s) => {
261
+ const t = i / ROWS,
262
+ round = Math.sin(Math.PI * (0.22 + 0.78 * t)) ** 0.8 * (1 - t * t * t),
263
+ half = wide * 0.5 * (point ? round + ((1 - t) ** 0.9 - round) * point : round),
264
+ over = Math.max(0, t - fold), // how far past the fold: from there the leaf goes forwards and down
265
+ along = len * Math.min(t, fold),
266
+ fwd = cup * half * (1 - s * s) * 2 - cup * wide * 0.3 + len * over * 0.9,
267
+ drop = len * over * over * 1.6 - len * over * 0.2;
268
+ return [
269
+ base[0] + up[0] * (along - drop) + across[0] * half * s + front[0] * fwd,
270
+ base[1] + up[1] * (along - drop) + across[1] * half * s + front[1] * fwd,
271
+ base[2] + up[2] * (along - drop) + across[2] * half * s + front[2] * fwd,
272
+ ];
273
+ },
274
+ put = (i, s, face = 1) => {
275
+ const q = pt(i, s),
276
+ c = s === 0 && face > 0 ? inner : col;
277
+ gb.raw(
278
+ q[0],
279
+ q[1],
280
+ q[2],
281
+ face * (front[0] * 0.6 + across[0] * s * 0.5),
282
+ face * (front[1] * 0.6 + up[1] * 0.4),
283
+ face * (front[2] * 0.6 + across[2] * s * 0.5),
284
+ c[0],
285
+ c[1],
286
+ c[2],
287
+ bone,
288
+ bone,
289
+ 1,
290
+ );
291
+ },
292
+ // the triangles of a row as wound below face `front` (true) or away from it, found on one of them
293
+ [a, b, c] = [pt(2, -1), pt(3, -1), pt(3, 0)],
294
+ u = [b[0] - a[0], b[1] - a[1], b[2] - a[2]],
295
+ v = [c[0] - a[0], c[1] - a[1], c[2] - a[2]],
296
+ forward = (u[1] * v[2] - u[2] * v[1]) * front[0] + (u[2] * v[0] - u[0] * v[2]) * front[1] + (u[0] * v[1] - u[1] * v[0]) * front[2] > 0,
297
+ // the two triangles of a cell of the grid, wound the rows' own way or (reversed) the other
298
+ quad = (i, s, face, reversed) => {
299
+ const k = reversed ? 1 : 0;
300
+ put(i, s, face);
301
+ put(i + 1, s + k, face);
302
+ put(i + 1, s + 1 - k, face);
303
+ put(i, s, face);
304
+ put(i + 1 - k, s + 1, face);
305
+ put(i + k, s + 1, face);
306
+ };
307
+ for (let i = 0; i < ROWS; i++)
308
+ for (const s of [-1, 0])
309
+ if (!both) quad(i, s, 1, false);
310
+ else {
311
+ quad(i, s, 1, !forward);
312
+ quad(i, s, -1, forward);
313
+ }
314
+ }
315
+
316
+ // A lock of long hair (a mane's, a tail's): a ribbon through pts ([x, y, z] each), its face turned to outs (unit vectors, one a
317
+ // point), `half` wide at the root and narrowing to the tip, shaded from col at the root to tip at the end; bind(u) gives the bones
318
+ // [b1, b2, weight of b1] of the point u of the way along; taper: how much narrower it is at its tip. Its edges are rounded by
319
+ // their normals (round: how far they turn), so a few strands read as a lock.
320
+ function ribbon(gb, pts, outs, half, col, tip, bind, taper = 0.8, round = 0.6) {
321
+ const last = pts.length - 1,
322
+ rows = [];
323
+ for (let i = 0; i <= last; i++) {
324
+ const p = pts[i],
325
+ a = pts[Math.max(0, i - 1)],
326
+ b = pts[Math.min(last, i + 1)],
327
+ n = outs[i],
328
+ u = i / last,
329
+ dx = b[0] - a[0],
330
+ dy = b[1] - a[1],
331
+ dz = b[2] - a[2];
332
+ let sx = dy * n[2] - dz * n[1],
333
+ sy = dz * n[0] - dx * n[2],
334
+ sz = dx * n[1] - dy * n[0];
335
+ const sl = Math.hypot(sx, sy, sz) || 1,
336
+ wide = half * (1 - taper * u * u),
337
+ bw = bind(u),
338
+ c = [0, 1, 2].map(k => col[k] + (tip[k] - col[k]) * u);
339
+ sx /= sl;
340
+ sy /= sl;
341
+ sz /= sl;
342
+ rows.push(
343
+ [-1, 1].map(k => [
344
+ p[0] + sx * wide * k,
345
+ p[1] + sy * wide * k,
346
+ p[2] + sz * wide * k,
347
+ n[0] * 0.8 + sx * round * k,
348
+ n[1] * 0.8 + sy * round * k,
349
+ n[2] * 0.8 + sz * round * k,
350
+ k < 0 ? c.map(v => v * (1 - round / 3)) : c, // darker down one edge, as strands lie over one another
351
+ bw,
352
+ ]),
353
+ );
354
+ }
355
+ const put = v => gb.raw(v[0], v[1], v[2], v[3], v[4], v[5], v[6][0], v[6][1], v[6][2], v[7][0], v[7][1], v[7][2]);
356
+ for (let i = 0; i < last; i++) {
357
+ const [a, b] = rows[i],
358
+ [c, d] = rows[i + 1];
359
+ put(a);
360
+ put(b);
361
+ put(d);
362
+ put(a);
363
+ put(d);
364
+ put(c);
365
+ }
366
+ }
367
+
368
+ // A quad of four vertices ([x, y, z, nx, ny, nz, r, g, b] each) in order round it, wound to face the way its first vertex's
369
+ // normal points, on bones b1 and b2 (b1's share w).
370
+ function facet(gb, A, B, C, D, b1, b2 = b1, w = 1) {
371
+ const ux = B[0] - A[0],
372
+ uy = B[1] - A[1],
373
+ uz = B[2] - A[2],
374
+ vx = C[0] - A[0],
375
+ vy = C[1] - A[1],
376
+ vz = C[2] - A[2],
377
+ facing = (uy * vz - uz * vy) * A[3] + (uz * vx - ux * vz) * A[4] + (ux * vy - uy * vx) * A[5] >= 0,
378
+ order = facing ? [A, B, C, A, C, D] : [A, C, B, A, D, C];
379
+ for (const V of order) gb.raw(V[0], V[1], V[2], V[3], V[4], V[5], V[6], V[7], V[8], b1, b2, w);
380
+ }
381
+
382
+ // An eye: a glossy ball at (x, y, z) with half-sizes (rx, ry, rz), turned `turn` about y. The builder keeps tags (gb.tg = []).
383
+ function eye(gb, x, y, z, rx, ry, rz, col = DARK_EYE, turn = 0) {
384
+ const tag = gb.tv;
385
+ gb.tv = EYE_TAG;
386
+ gb.add(SHAPES.sph, col, TRS(x, y, z, rx, ry, rz, turn));
387
+ gb.tv = tag;
388
+ }
389
+
390
+ export { EYE_TAG, eye, facet, leaf, ribbon, scatter, spline, tube };
@@ -15,9 +15,17 @@ export function cutBuilderCells(builder, cellSize, smallSize = 0) {
15
15
  end = partIndex + 1 < starts.length ? starts[partIndex + 1] : builder.count;
16
16
  if (end <= start) continue;
17
17
  const boundsOffset = partIndex * 6,
18
- small = Math.max(bounds[boundsOffset + 1] - bounds[boundsOffset], bounds[boundsOffset + 3] - bounds[boundsOffset + 2], bounds[boundsOffset + 5] - bounds[boundsOffset + 4]) < smallSize,
18
+ small =
19
+ Math.max(
20
+ bounds[boundsOffset + 1] - bounds[boundsOffset],
21
+ bounds[boundsOffset + 3] - bounds[boundsOffset + 2],
22
+ bounds[boundsOffset + 5] - bounds[boundsOffset + 4],
23
+ ) < smallSize,
19
24
  key =
20
- Math.floor((bounds[boundsOffset] + bounds[boundsOffset + 1]) / 2 / cellSize) + ':' + Math.floor((bounds[boundsOffset + 4] + bounds[boundsOffset + 5]) / 2 / cellSize) + (small ? 's' : '');
25
+ Math.floor((bounds[boundsOffset] + bounds[boundsOffset + 1]) / 2 / cellSize) +
26
+ ':' +
27
+ Math.floor((bounds[boundsOffset + 4] + bounds[boundsOffset + 5]) / 2 / cellSize) +
28
+ (small ? 's' : '');
21
29
  let cell = cells.get(key);
22
30
  if (!cell) cells.set(key, (cell = { small, runs: [], numbers: 0 }));
23
31
  cell.runs.push(start, end);
@@ -3,7 +3,8 @@ import { TRS } from './primitives.js';
3
3
 
4
4
  // Builders can share the stable matrix reference. Stack entries are reused on subsequent pushes.
5
5
  export function createBuilderFrame() {
6
- const matrix = new Matrix4(), stack = [];
6
+ const matrix = new Matrix4(),
7
+ stack = [];
7
8
  let depth = 0;
8
9
  function push(local) {
9
10
  (stack[depth] ??= new Matrix4()).copy(matrix);