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
@@ -1,24 +1,24 @@
1
1
  import * as THREE from 'three';
2
- import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3
- import { createNoise, createRenderContext, createUnitShapes, GeometryBuilder, mulberry32 } from 'roamwright';
2
+ import { GeometryBuilder } from 'roamwright';
4
3
  import { heightfieldSampler } from 'roamwright/geometry/heightfield.js';
5
4
  import { createCameraGuard } from './viaduct-camera.js';
6
5
  import { alpineRiver, branchWhorl, valleySky } from './viaduct-landscape.js';
6
+ import { createOrbitRig, initExample } from './stage.js';
7
7
  import { C, stick, TRS } from 'roamwright/geometry/primitives.js';
8
8
 
9
- const canvas = document.querySelector('canvas');
10
- const { renderer, camera, scene, worldGroup } = createRenderContext(canvas, { fov: 41 });
11
- const seed = Number(new URL(location.href).searchParams.get('seed') ?? 42) | 0;
12
- const noise = createNoise(seed);
9
+ const { canvas, renderer, camera, scene, worldGroup, random, noise, shapes } = initExample({ fallbackSeed: 42, fov: 41 });
13
10
  const { fbm, ridged } = noise;
14
- const random = mulberry32(seed);
15
- const shapes = createUnitShapes(fbm);
16
11
  const material = new THREE.MeshStandardMaterial({ vertexColors: true, flatShading: true });
17
12
  const smoothstep = THREE.MathUtils.smoothstep;
18
13
  const peaks = [
19
14
  // x, z, summit elevation and horizontal radius
20
- [-144, -112, 61, 86], [-91, -122, 78, 87], [-42, -142, 58, 76],
21
- [12, -119, 73, 65], [54, -134, 79, 76], [105, -107, 62, 74], [152, -138, 74, 79],
15
+ [-144, -112, 61, 86],
16
+ [-91, -122, 78, 87],
17
+ [-42, -142, 58, 76],
18
+ [12, -119, 73, 65],
19
+ [54, -134, 79, 76],
20
+ [105, -107, 62, 74],
21
+ [152, -138, 74, 79],
22
22
  ];
23
23
  const channel = z => 8 * Math.sin(z * 0.067) + 5 * Math.sin(z * 0.029);
24
24
 
@@ -28,7 +28,8 @@ function elevation(x, z) {
28
28
  const foothills = smoothstep(bank, 5, 66) * (15 + 15 * roughness);
29
29
  let summit = 0;
30
30
  for (const [cx, cz, top, radius] of peaks) {
31
- const dx = x - cx, dz = z - cz;
31
+ const dx = x - cx,
32
+ dz = z - cz;
32
33
  const angle = Math.atan2(dz, dx);
33
34
  const spine = 1 + 0.19 * Math.cos(angle * 3 + cx) + 0.12 * Math.sin(angle * 5 + cz);
34
35
  summit = Math.max(summit, top * (1 - Math.hypot(dx, dz) / (radius * spine)));
@@ -51,11 +52,15 @@ const positions = ground.attributes.position;
51
52
  for (let i = 0; i < positions.count; i++) positions.setY(i, elevation(positions.getX(i), positions.getZ(i)));
52
53
  ground.computeVertexNormals();
53
54
  const colors = new Float32Array(positions.count * 3);
54
- const grass = new THREE.Color(0x839062), gravel = new THREE.Color(0xc6b690);
55
- const rock = new THREE.Color(0x6d7377), snow = new THREE.Color(0xf3efe4);
55
+ const grass = new THREE.Color(0x839062),
56
+ gravel = new THREE.Color(0xc6b690);
57
+ const rock = new THREE.Color(0x6d7377),
58
+ snow = new THREE.Color(0xf3efe4);
56
59
  const tint = new THREE.Color();
57
60
  for (let i = 0; i < positions.count; i++) {
58
- const x = positions.getX(i), y = positions.getY(i), z = positions.getZ(i);
61
+ const x = positions.getX(i),
62
+ y = positions.getY(i),
63
+ z = positions.getZ(i);
59
64
  const grain = fbm(x * 0.16, z * 0.16, 3, 91);
60
65
  const bedding = Math.cos(y * 1.8 + x * 0.44 + 5 * grain);
61
66
  const up = ground.attributes.normal.getY(i);
@@ -73,7 +78,10 @@ worldGroup.add(hillside);
73
78
  worldGroup.add(alpineRiver(channel, elevation, noise));
74
79
 
75
80
  const structures = new GeometryBuilder();
76
- const deck = 18, span = 12, radius = 4.7, spring = 10;
81
+ const deck = 18,
82
+ span = 12,
83
+ radius = 4.7,
84
+ spring = 10;
77
85
  function extrude(shape, depth) {
78
86
  return new THREE.ExtrudeGeometry(shape, { depth, bevelEnabled: false, curveSegments: 12 }).translate(0, 0, -depth / 2);
79
87
  }
@@ -102,7 +110,8 @@ function facing(x, row, left, right) {
102
110
  const bottom = row * 0.83;
103
111
  const offset = row % 2 === 0 ? 0 : 1.1;
104
112
  for (let joint = -span / 2 - offset; joint < right; joint += 2.2) {
105
- const a = Math.max(left, joint), b = Math.min(right, joint + 2.2);
113
+ const a = Math.max(left, joint),
114
+ b = Math.min(right, joint + 2.2);
106
115
  if (b - a < 0.12) continue;
107
116
  structures.box(x + (a + b) / 2, bottom, 0, b - a - 0.035, 0.79, 4.04, C(0xbca68b, 0.07, random));
108
117
  }
@@ -134,16 +143,17 @@ const tunnelInterior = extrude(tunnel, 0.25);
134
143
  const portalBase = deck - 4.5;
135
144
  // Scale a copy of the stone arch around each tunnel entrance, perpendicular to the bridge.
136
145
  for (const side of [-1, 1]) {
137
- structures.add(tunnelInterior, C(0x252a27), TRS(side * 55, portalBase, 0, 0.59, 0.77, 1, side * Math.PI / 2));
138
- structures.add(archShape, C(0x917d67), TRS(side * 53, portalBase, 0, 0.59, 0.77, 1, side * Math.PI / 2));
146
+ structures.add(tunnelInterior, C(0x252a27), TRS(side * 55, portalBase, 0, 0.59, 0.77, 1, (side * Math.PI) / 2));
147
+ structures.add(archShape, C(0x917d67), TRS(side * 53, portalBase, 0, 0.59, 0.77, 1, (side * Math.PI) / 2));
139
148
  for (let i = 0; i < 15; i++) {
140
- const matrix = TRS(side * 53, portalBase + spring * 0.77, 0, 0.59, 0.77, 1, side * Math.PI / 2).clone();
149
+ const matrix = TRS(side * 53, portalBase + spring * 0.77, 0, 0.59, 0.77, 1, (side * Math.PI) / 2).clone();
141
150
  matrix.multiply(new THREE.Matrix4().makeRotationZ(i * angle));
142
151
  structures.add(wedgeShape, C(0xbda884), matrix);
143
152
  }
144
153
  }
145
154
  // Cantilevers keep the contact wire above the track. Only the upper cable sags.
146
- const iron = C(0x475550), copper = C(0x554634);
155
+ const iron = C(0x475550),
156
+ copper = C(0x554634);
147
157
  for (let x = -48; x <= 48; x += 16) {
148
158
  const foot = deck + 1;
149
159
  structures.box(x, foot, -2, 0.19, 6.4, 0.19, iron);
@@ -172,7 +182,7 @@ for (const x of [-14, -5, 4, 13]) {
172
182
  carriages.box(x, deck + 2.22, 0, 8.62, 1.22, 2.82, C(0xf4d9a5));
173
183
  for (let offset = -3; offset <= 3; offset += 1.5) {
174
184
  carriages.box(x + offset, deck + 2.36, 0, 1.1, 0.85, 2.86, C(0x344e54));
175
- carriages.box(x + offset, deck + 2.96, 0, 1.10, 0.22, 2.865, C(0x6c878b));
185
+ carriages.box(x + offset, deck + 2.96, 0, 1.1, 0.22, 2.865, C(0x6c878b));
176
186
  }
177
187
  carriages.add(roof, C(0x646b68), TRS(x, deck + 3.83, 0));
178
188
  for (const end of [-3, 3]) {
@@ -189,8 +199,8 @@ carriages.box(17.32, deck + 2.42, 0, 0.12, 0.92, 2.1, C(0x34494c));
189
199
  for (const z of [-1, 1]) carriages.box(17.34, deck + 1.66, z, 0.15, 0.32, 0.32, C(0xffda89));
190
200
  // A sprung pickup connects the leading car to the contact wire.
191
201
  for (const z of [-0.32, 0.32]) {
192
- stick(carriages, [10.9, deck + 4.24, z], [12.25, deck + 5.28, z], 0.10, iron);
193
- stick(carriages, [12.25, deck + 5.28, z], [11.4, deck + 6.30, z], 0.085, iron);
202
+ stick(carriages, [10.9, deck + 4.24, z], [12.25, deck + 5.28, z], 0.1, iron);
203
+ stick(carriages, [12.25, deck + 5.28, z], [11.4, deck + 6.3, z], 0.085, iron);
194
204
  }
195
205
  carriages.box(11.4, deck + 6.28, 0, 0.22, 0.07, 1.45, C(0x383c39));
196
206
  const train = carriages.mesh(material, worldGroup, false);
@@ -201,16 +211,23 @@ const groundAt = heightfieldSampler(ground);
201
211
  const treeCrowns = [];
202
212
  const whorl = branchWhorl();
203
213
  for (let i = 0; i < 3300; i++) {
204
- const x = random() * 220 - 110, z = random() * 162 - 111;
214
+ const x = random() * 220 - 110,
215
+ z = random() * 162 - 111;
205
216
  const y = groundAt(x, z);
206
217
  if (y < 2 || y > 35 || (Math.abs(z) < 4 && Math.abs(x) < 58)) continue;
207
218
  const size = 2.2 + random() * 4.2;
208
219
  const yaw = random() * Math.PI;
209
- const larch = noise.vnoise(x * 0.09, z * 0.09, 93) + random() * 0.30 > 0.92;
220
+ const larch = noise.vnoise(x * 0.09, z * 0.09, 93) + random() * 0.3 > 0.92;
210
221
  const needles = larch ? 0xa88938 : 0x325b4b;
211
- const halfTrunk = size * 0.065 / 2;
212
- const root = Math.min(groundAt(x - halfTrunk, z - halfTrunk), groundAt(x - halfTrunk, z + halfTrunk),
213
- groundAt(x + halfTrunk, z - halfTrunk), groundAt(x + halfTrunk, z + halfTrunk), y) - 0.25;
222
+ const halfTrunk = (size * 0.065) / 2;
223
+ const root =
224
+ Math.min(
225
+ groundAt(x - halfTrunk, z - halfTrunk),
226
+ groundAt(x - halfTrunk, z + halfTrunk),
227
+ groundAt(x + halfTrunk, z - halfTrunk),
228
+ groundAt(x + halfTrunk, z + halfTrunk),
229
+ y,
230
+ ) - 0.25;
214
231
  woodland.box(x, root, z, halfTrunk * 2, y + size * 0.7 - root, halfTrunk * 2, C(0x5b4738));
215
232
  treeCrowns.push({ x, z, top: y + size * 1.09, radius: size * 0.28 });
216
233
  for (let tier = 0; tier < 3; tier++) {
@@ -219,7 +236,8 @@ for (let i = 0; i < 3300; i++) {
219
236
  }
220
237
  }
221
238
  for (let i = 0; i < 520; i++) {
222
- const z = random() * 155 - 100, x = channel(z) + (random() - 0.5) * 29;
239
+ const z = random() * 155 - 100,
240
+ x = channel(z) + (random() - 0.5) * 29;
223
241
  const bed = groundAt(x, z);
224
242
  if (bed > 5) continue;
225
243
  const size = 0.4 + random() * 2.05;
@@ -242,67 +260,38 @@ renderer.shadowMap.autoUpdate = false;
242
260
  renderer.shadowMap.needsUpdate = true;
243
261
  scene.add(sun);
244
262
 
245
- const controls = new OrbitControls(camera, canvas);
246
- controls.enablePan = false;
247
- controls.maxPolarAngle = Math.PI * 0.49;
248
- controls.minDistance = 6;
249
- controls.maxDistance = 135;
250
-
251
263
  const viewpoints = {
252
- valley: { eye: [31, 29, 82], target: [0, 17, -9] },
264
+ valley: { eye: [31, 29, 82], target: [0, 17, -9] },
253
265
  trackside: { eye: [29, 25, 14], target: [1, 20.5, 0] },
254
266
  riverbank: { eye: [13, 5.3, 38], target: [-2, 11.8, -6] },
255
267
  };
256
- const viewButtons = document.querySelectorAll('[data-view]');
257
- function draw() {
258
- renderer.render(scene, camera);
259
- }
260
- const guardCamera = createCameraGuard(ground, treeCrowns);
261
- function drawCamera() {
262
- guardCamera(camera);
263
- camera.lookAt(controls.target);
264
- draw();
265
- }
266
- controls.addEventListener('change', drawCamera);
267
- function selectView(name) {
268
- const { eye, target } = viewpoints[name];
269
- controls.target.fromArray(target);
270
- camera.position.fromArray(eye);
271
- controls.update();
272
- viewButtons.forEach(button => button.setAttribute('aria-pressed', String(button.dataset.view === name)));
273
- draw();
274
- }
275
- viewButtons.forEach(button => button.addEventListener('click', () => selectView(button.dataset.view)));
276
- document.querySelector('#seed').value = seed;
277
-
278
- // Give keyboard explorers the same orbit and zoom gestures as pointer users.
279
- canvas.addEventListener('keydown', event => {
280
- const offset = camera.position.clone().sub(controls.target);
281
- const orbit = new THREE.Spherical().setFromVector3(offset);
282
- switch (event.key) {
283
- case 'ArrowLeft': orbit.theta -= 0.10; break;
284
- case 'ArrowRight': orbit.theta += 0.10; break;
285
- case 'ArrowUp': orbit.phi -= 0.08; break;
286
- case 'ArrowDown': orbit.phi += 0.08; break;
287
- case '+': case '=': orbit.radius *= 0.88; break;
288
- case '-': orbit.radius /= 0.88; break;
289
- default: return;
290
- }
291
- event.preventDefault();
292
- camera.position.setFromSpherical(orbit.makeSafe()).add(controls.target);
293
- controls.update();
268
+ createOrbitRig({
269
+ camera,
270
+ canvas,
271
+ renderer,
272
+ scene,
273
+ views: viewpoints,
274
+ initialView: 'valley',
275
+ guardCamera: createCameraGuard(ground, treeCrowns),
276
+ minDistance: 6,
277
+ maxDistance: 135,
278
+ baseFov: 41,
279
+ maxFov: 69,
280
+ maxPolarAngle: Math.PI * 0.49,
281
+ far: 7000,
294
282
  });
295
283
 
296
284
  const trainButton = document.querySelector('#train');
297
- const trainLabel = document.querySelector('#train-label');
298
- let running = false, frame = 0, lastTime = 0;
285
+ let running = false,
286
+ frame = 0,
287
+ lastTime = 0;
299
288
  function moveTrain(time) {
300
289
  const elapsed = lastTime ? Math.min((time - lastTime) / 1000, 0.1) : 0;
301
290
  lastTime = time;
302
291
  train.position.x += elapsed * 6;
303
292
  if (train.position.x >= 80) train.position.x -= 160;
304
293
  train.updateMatrix();
305
- draw();
294
+ renderer.render(scene, camera);
306
295
  frame = requestAnimationFrame(moveTrain);
307
296
  }
308
297
  function scheduleTrain() {
@@ -312,21 +301,8 @@ function scheduleTrain() {
312
301
  }
313
302
  trainButton.addEventListener('click', () => {
314
303
  running = !running;
315
- trainLabel.textContent = running ? 'Pause train' : 'Run train';
316
- trainButton.firstElementChild.textContent = running ? 'Ⅱ' : '▶';
304
+ trainButton.textContent = running ? 'Pause train' : 'Run train';
305
+ trainButton.setAttribute('aria-pressed', String(running));
317
306
  scheduleTrain();
318
307
  });
319
308
  document.addEventListener('visibilitychange', scheduleTrain);
320
-
321
- function resize() {
322
- renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
323
- renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
324
- camera.aspect = canvas.clientWidth / canvas.clientHeight;
325
- // Keep the train and several arches in frame on a narrow screen.
326
- camera.fov = THREE.MathUtils.clamp(41 / Math.min(camera.aspect, 1), 41, 69);
327
- camera.updateProjectionMatrix();
328
- drawCamera();
329
- }
330
- window.addEventListener('resize', resize);
331
- selectView('valley');
332
- resize();
@@ -0,0 +1,410 @@
1
+ import * as THREE from 'three';
2
+ import { lerp, sstep } from '../math/scalar.js';
3
+ import { GB } from './builder.js';
4
+ import { TRS } from './primitives.js';
5
+ import { SHAPES } from './animal-shapes.js';
6
+ import { tube } from './animal-skin.js';
7
+ import { CALLUS, HIDE_TAG, PAD, PAD_TAG, camelHead } from './animal-camel-head.js';
8
+ import { BONE, LEGS } from '../motion/quadruped.js';
9
+
10
+ // ════════════════════════════════════════════════════════════════════════
11
+ // A camel, a dromedary, built on the four-legged skeleton (motion/quadruped.js) as cattle are (animal-cattle-body.js): nose to
12
+ // +z, feet at y 0, laid out in withers heights. A short deep body carried high on long thin legs, one hump of fat on the middle
13
+ // of the back, the rump falling away to a thin tufted tail; a long neck that leaves the chest low, runs forward and dips, then
14
+ // rises steeply to a long head carried level (animal-camel-head.js); hind legs whose thighs hang free of the body; calloused pads
15
+ // where it kneels (the brisket, elbows, knees, stifles); broad soft two-toed feet. Its coat is near white, so that an instance's
16
+ // colour gives it its sand, tawny or dark brown; the hair is longer on the hump, the shoulders and under the neck.
17
+ // ════════════════════════════════════════════════════════════════════════
18
+ const WITHERS = 1.85, // metres at the shoulder; the hump stands about 30 cm higher
19
+ COAT = [0.88, 0.84, 0.77], // near white: the herd's tint gives the colour
20
+ zF = 0.33, // where the fore feet stand along the body,
21
+ zH = -0.4, // and the hind ones
22
+ GRAZE_BEND = [0.85, 0.75, -0.95], // the neck lowered from its base, its upper half and the head bent to the scrub (motion/animal-bearing.js)
23
+ GIRTH = 1, // the body's width against the camel modelled
24
+ BONE_W = 1; // and the legs'
25
+
26
+ // How a camel's legs go, and its gaits (motion/quadruped.js): it walks with the two legs of one side nearly together, and at speed paces,
27
+ // each side's pair swinging as one. [speed against leg length, stance travel, duty, footfalls (fore left, fore right, hind left,
28
+ // hind right), rise, lift, flex].
29
+ const HABITS = {
30
+ fore: { follow: 0.9, heel3: 0.08, fold3: 1.2, heel4: 0.6, fold4: 0.7, sink: 0.08, glide: 0.12 },
31
+ hind: { follow: 0.65, heel3: 0.2, fold3: 0.35, heel4: 0.6, fold4: 0.55, sink: 0.08, glide: 0 },
32
+ crouch: 0.015,
33
+ gaits: [
34
+ [0.1, 0.6, 0.72, [0.12, 0.62, 0, 0.5], 0.008, 0.06, 0.015],
35
+ [1.0, 0.85, 0.62, [0.12, 0.62, 0, 0.5], 0.012, 0.1, 0.02],
36
+ [1.4, 0.9, 0.46, [0.03, 0.53, 0, 0.5], 0.03, 0.12, 0.02],
37
+ [2.2, 0.95, 0.38, [0, 0.5, 0, 0.5], 0.05, 0.15, 0.03],
38
+ ],
39
+ };
40
+
41
+ // Where the joints are, in withers heights: [y, z] in the body's upright plane.
42
+ const A = {
43
+ sx: 0.11 * GIRTH,
44
+ hx: 0.1 * GIRTH,
45
+ shoulder: [0.92, zF - 0.02],
46
+ elbow: [0.62, zF - 0.06],
47
+ knee: [0.34, zF - 0.01],
48
+ fetlock: [0.085, zF],
49
+ hoof: [0, zF + 0.04],
50
+ hip: [0.86, zH + 0.06],
51
+ stifle: [0.6, zH + 0.2],
52
+ hock: [0.38, zH - 0.06],
53
+ hindFetlock: [0.085, zH - 0.01],
54
+ hindHoof: [0, zH + 0.03],
55
+ neck: [0.84, zF + 0.12], // the neck's root, on the front of the chest
56
+ bow: [0.8, zF + 0.33], // the low point of its dip
57
+ poll: [1.14, zF + 0.56],
58
+ dock: [0.88, zH - 0.12],
59
+ };
60
+
61
+ // The bones' joints and the feet, in metres (as cattle's, animal-cattle-body.js).
62
+ function jointsAt(K, headAt) {
63
+ const at = (x, q) => [x * K, q[0] * K, q[1] * K],
64
+ joints = [];
65
+ joints[BONE.root] = at(0, [0.9, -0.04]);
66
+ joints[BONE.hips] = at(0, [0.92, -0.2]);
67
+ joints[BONE.chest] = at(0, [0.95, 0.12]);
68
+ joints[BONE.neck] = at(0, A.neck);
69
+ joints[BONE.neck2] = at(0, A.bow);
70
+ joints[BONE.head] = at(0, A.poll);
71
+ joints[BONE.jaw] = headAt(0, -0.03, 0.08);
72
+ joints[BONE.earL] = headAt(-0.045, 0.03, -0.01);
73
+ joints[BONE.earR] = headAt(0.045, 0.03, -0.01);
74
+ joints[BONE.lip] = headAt(0, -0.03, 0.29);
75
+ [-1, 1].forEach((s, i) => {
76
+ const f = LEGS[i],
77
+ h = LEGS[i + 2];
78
+ joints[f] = at(s * A.sx, A.shoulder);
79
+ joints[f + 1] = at(s * A.sx, A.elbow);
80
+ joints[f + 2] = at(s * A.sx, A.knee);
81
+ joints[f + 3] = at(s * A.sx, A.fetlock);
82
+ joints[h] = at(s * A.hx, A.hip);
83
+ joints[h + 1] = at(s * A.hx, A.stifle);
84
+ joints[h + 2] = at(s * A.hx, A.hock);
85
+ joints[h + 3] = at(s * A.hx, A.hindFetlock);
86
+ });
87
+ joints[BONE.tail] = at(0, A.dock);
88
+ joints[BONE.tail + 1] = at(0, [A.dock[0] - 0.2, A.dock[1] - 0.02]);
89
+ joints[BONE.tail + 2] = at(0, [A.dock[0] - 0.38, A.dock[1] - 0.025]);
90
+ joints[BONE.crest] = at(0, [1.15, 0.02]);
91
+ return { joints, feet: [at(-A.sx, A.hoof), at(A.sx, A.hoof), at(-A.hx, A.hindHoof), at(A.hx, A.hindHoof)] };
92
+ }
93
+
94
+ // The coat at a point of the body: paler under the belly and inside the legs, dusty low down, darker and rough where it kneels;
95
+ // mottled with the world's value noise.
96
+ const hideWith = vnoise => (col, x, y, z, nx, ny) => {
97
+ const under = 0.07 * sstep(-0.3, -0.9, ny),
98
+ dust = 0.1 * sstep(0.3, 0.06, y),
99
+ mottle = 0.06 * (vnoise(x * 19 + z * 7, y * 23, 391) - 0.5),
100
+ // the pads it kneels on: the brisket under the chest, and where an elbow lies against it
101
+ brisket = sstep(0.07, 0.02, Math.hypot(x * 0.8, y - 0.55, (z - 0.24) * 0.6)),
102
+ elbow = sstep(0.04, 0.012, Math.hypot(Math.abs(x) - A.sx - 0.03, y - A.elbow[0], z - A.elbow[1] + 0.03)),
103
+ pad = Math.max(brisket, elbow);
104
+ for (let i = 0; i < 3; i++) col[i] = lerp(COAT[i] * (1 + under - dust + mottle), CALLUS[i], pad);
105
+ col[3] = lerp(HIDE_TAG, PAD_TAG, pad);
106
+ };
107
+
108
+ // The hump: a mound of fat narrower than the back it sits on, highest a little behind the middle of the body; how far it lifts a
109
+ // point of the trunk's upper half at (x, y, z), in withers heights. pad: how far out from the hide (the blanket over it).
110
+ const HUMP = { rise: 0.2, z: -0.03, long: 0.19, half: 0.165 };
111
+ function humpLift(x, y, z, pad = 0) {
112
+ const across = Math.max(0, 1 - (Math.abs(x) / (HUMP.half + pad)) ** 2),
113
+ along = (z - HUMP.z) / HUMP.long;
114
+ return HUMP.rise * Math.exp(-(along * along) * (0.6 + along * along)) * across ** 0.7 * sstep(0.78, 0.92, y);
115
+ }
116
+
117
+ // The trunk's stations, from the buttocks over the rump, the back and the deep chest, then along the neck's dip and rise to the poll:
118
+ // [y, z, half width, rise, fall, bone, squareness]. The hump is raised on the back by the warp.
119
+ function trunkStations() {
120
+ const ring = (z, top, bottom, w, bone, sq = 2.4) => [(top + bottom) / 2, z, w * GIRTH, (top - bottom) / 2, (top - bottom) / 2, bone, sq],
121
+ neck = (y, z, w, h, bone, low = h) => [y, z, w, h, low, bone, 2.1];
122
+ return [
123
+ [0.8, zH - 0.135, 0, 0, 0, 0],
124
+ ring(zH - 0.12, 0.87, 0.68, 0.06, 0, 2.4),
125
+ ring(zH - 0.08, 0.92, 0.62, 0.11, 0, 2.6),
126
+ ring(zH + 0.02, 0.965, 0.6, 0.145, 0.1, 2.7),
127
+ ring(zH + 0.16, 0.985, 0.585, 0.165, 0.35, 2.6),
128
+ ring(-0.12, 0.995, 0.57, 0.178, 0.55, 2.5),
129
+ ring(0.0, 1.0, 0.56, 0.188, 0.75, 2.4),
130
+ ring(0.1, 1.0, 0.55, 0.19, 0.92, 2.4),
131
+ ring(0.2, 1.0, 0.53, 0.182, 1, 2.4),
132
+ ring(0.29, 0.99, 0.54, 0.165, 1, 2.4),
133
+ ring(zF + 0.05, 0.96, 0.6, 0.14, 1.3, 2.3),
134
+ neck(0.83, zF + 0.12, 0.1, 0.13, 2, 0.15),
135
+ neck(0.81, zF + 0.21, 0.078, 0.1, 2.3),
136
+ neck(0.795, zF + 0.3, 0.066, 0.08, 2.8),
137
+ neck(0.82, zF + 0.39, 0.06, 0.07, 3.2),
138
+ neck(0.9, zF + 0.47, 0.056, 0.064, 3.5),
139
+ neck(1.01, zF + 0.525, 0.052, 0.06, 3.8),
140
+ neck(1.1, zF + 0.55, 0.052, 0.06, 4),
141
+ [A.poll[0] + 0.025, A.poll[1], 0.04, 0.035, 0.045, 4],
142
+ [A.poll[0] + 0.05, A.poll[1] + 0.005, 0, 0, 0, 4],
143
+ ];
144
+ }
145
+
146
+ // Under the hide: the hump, the ridge of the spine before and behind it, the shoulder blades, the hollow of the flank, the hip
147
+ // bones at the corners of the rump.
148
+ function bodyWarp(Q, q) {
149
+ const x = Q[q],
150
+ y = Q[q + 1],
151
+ z = Q[q + 2],
152
+ ax = Math.abs(x),
153
+ blade = sstep(0.09, 0.0, Math.hypot(ax - 0.14, y - 0.88, (z - zF + 0.02) * 0.6)),
154
+ hook = sstep(0.06, 0.0, Math.hypot(ax - 0.14, y - 0.93, z - zH - 0.02)),
155
+ flank = sstep(0.12, 0.02, Math.hypot(y - 0.75, (z - zH - 0.22) * 0.7)) * sstep(0.1, 0.18, ax),
156
+ spine =
157
+ sstep(0.03, 0, ax) *
158
+ sstep(0.95, 1.0, y) *
159
+ (sstep(-0.42, -0.3, z) * sstep(-0.18, -0.26, z) + sstep(0.18, 0.24, z) * sstep(0.36, 0.3, z));
160
+ Q[q] += Math.sign(x) * (0.018 * blade + 0.02 * hook - 0.02 * flank);
161
+ Q[q + 1] += 0.01 * blade + 0.015 * hook + 0.01 * spine + (z < 0.4 ? humpLift(x, y, z) : 0);
162
+ }
163
+
164
+ // The longer hair of a dromedary's coat, as a tube's fur (animal-skin.js): on the hump's crown, over the shoulders and down the
165
+ // front and underside of the neck; out: [length, lift, width, locks at the point, the tips' shade].
166
+ const shagWith = vnoise => (out, x, y, z, nx, ny) => {
167
+ const hump = sstep(1.05, 1.15, y) * sstep(-0.2, -0.08, z) * sstep(0.18, 0.08, z),
168
+ throat = sstep(-0.3, -0.8, ny) * sstep(zF + 0.14, zF + 0.24, z) * sstep(zF + 0.45, zF + 0.36, z),
169
+ shoulder = sstep(0.93, 1.0, y) * sstep(0.18, 0.28, z) * sstep(0.38, 0.32, z),
170
+ grow = Math.max(hump, throat, shoulder * 0.6);
171
+ if (grow < 0.2) return false;
172
+ out[0] = grow * (0.025 + 0.015 * throat) * (0.8 + 0.4 * vnoise(x * 50, z * 50, 393));
173
+ out[1] = 0.25 + 0.2 * hump;
174
+ out[2] = 0.025;
175
+ out[3] = 2;
176
+ out[4] = 0.8;
177
+ return true;
178
+ };
179
+
180
+ // A leg from the shoulder blade or the thigh to the fetlock, then the pastern lying low and the broad soft foot: two toes with a
181
+ // nail each, on one spreading pad. Calloused at the knee (fore) and the stifle (hind), where the camel kneels.
182
+ function leg(b, q, s, hind, hide) {
183
+ const t = BONE_W,
184
+ i = (hind ? 2 : 0) + (s > 0 ? 1 : 0),
185
+ f = LEGS[i],
186
+ mix = (P, R, k, dz = 0) => [P[0] + (R[0] - P[0]) * k, P[1] + (R[1] - P[1]) * k + dz],
187
+ at = (P, w, front, back, bone, lean = 0) => [P[0], P[1], w * t, front * t, back * t, bone, 2.2, lean],
188
+ pad = hind ? A.stifle : A.knee,
189
+ coat = (col, x, y, z, nx, ny) => {
190
+ hide(col, x, y, z, nx, ny);
191
+ const callus = sstep(0.05, 0.02, Math.hypot(y - pad[0], z - pad[1] - (hind ? 0.02 : 0.03)));
192
+ for (let k = 0; k < 3; k++) col[k] = lerp(col[k], CALLUS[k], callus);
193
+ col[3] = lerp(col[3], PAD_TAG, callus);
194
+ };
195
+ const S = hind
196
+ ? [
197
+ [0.9, A.hip[1] + 0.03, 0, 0, 0, 0],
198
+ [0.86, A.hip[1] + 0.01, 0.05, 0.12, 0.14, 0.2, 2, -0.08],
199
+ at(mix(A.hip, A.stifle, 0.25, -0.01), 0.07, 0.13, 0.15, 1, -0.06),
200
+ at(mix(A.hip, A.stifle, 0.65, -0.01), 0.058, 0.1, 0.12, 1, -0.03),
201
+ at(A.stifle, 0.046, 0.06, 0.1, 1.5),
202
+ at(mix(A.stifle, A.hock, 0.4), 0.036, 0.04, 0.06, 2),
203
+ at(mix(A.stifle, A.hock, 0.85), 0.024, 0.024, 0.032, 2),
204
+ at(A.hock, 0.026, 0.026, 0.04, 2.5),
205
+ at(mix(A.hock, A.hindFetlock, 0.3), 0.018, 0.02, 0.022, 3),
206
+ at(mix(A.hock, A.hindFetlock, 0.85), 0.017, 0.019, 0.022, 3),
207
+ at(A.hindFetlock, 0.023, 0.024, 0.028, 3),
208
+ [A.hindFetlock[0] - 0.02, A.hindFetlock[1] + 0.012, 0, 0, 0, 3],
209
+ ]
210
+ : [
211
+ [0.84, zF - 0.04, 0, 0, 0, 0],
212
+ [0.8, zF - 0.03, 0.03, 0.07, 0.08, 0, 2, -0.1],
213
+ at(mix(A.shoulder, A.elbow, 0.25), 0.05, 0.075, 0.09, 0.5, -0.05),
214
+ at(mix(A.shoulder, A.elbow, 0.6), 0.046, 0.065, 0.08, 1, -0.02),
215
+ at(A.elbow, 0.04, 0.05, 0.07, 1.5, 0.01),
216
+ at(mix(A.elbow, A.knee, 0.3), 0.034, 0.042, 0.042, 2),
217
+ at(mix(A.elbow, A.knee, 0.82), 0.022, 0.024, 0.024, 2),
218
+ at(A.knee, 0.027, 0.032, 0.026, 2.5),
219
+ at(mix(A.knee, A.fetlock, 0.3), 0.018, 0.019, 0.019, 3),
220
+ at(mix(A.knee, A.fetlock, 0.85), 0.017, 0.018, 0.02, 3),
221
+ at(A.fetlock, 0.023, 0.024, 0.028, 3),
222
+ [A.fetlock[0] - 0.02, A.fetlock[1] + 0.012, 0, 0, 0, 3],
223
+ ];
224
+ const x = s * (hind ? A.hx : A.sx),
225
+ F = hind ? A.hindFetlock : A.fetlock,
226
+ H = hind ? A.hindHoof : A.hoof;
227
+ tube(b, S, {
228
+ x,
229
+ side: s,
230
+ chain: [hind ? BONE.hips : BONE.chest, f, f + 1, f + 2],
231
+ around: [6, 8, 10][q],
232
+ sub: [1, 2, 3][q],
233
+ coat,
234
+ droop: 0.6,
235
+ });
236
+ // the pastern runs forward low to the foot; the foot is a flat oval pad wider than the leg, cleft in front into two toes
237
+ const foot = (col, px, py, pz, nx, ny) => {
238
+ hide(col, px, py, pz, nx, ny);
239
+ const sole = sstep(0.03, 0.012, py),
240
+ nail = sstep(H[1] + 0.035, H[1] + 0.055, pz) * sstep(0.012, 0.03, py) * sstep(0.05, 0.035, py);
241
+ for (let k = 0; k < 3; k++) col[k] = lerp(lerp(col[k], PAD[k], sole), PAD[k] * 0.5, nail);
242
+ col[3] = lerp(col[3], PAD_TAG, Math.max(sole, nail));
243
+ };
244
+ tube(
245
+ b,
246
+ [
247
+ [F[0] + 0.015, F[1] - 0.008, 0, 0, 0, 0],
248
+ [F[0], F[1], 0.024 * t, 0.025 * t, 0.028 * t, 0.4],
249
+ [0.058, lerp(F[1], H[1], 0.35), 0.027 * t, 0.026 * t, 0.026 * t, 1],
250
+ [0.04, lerp(F[1], H[1], 0.7), 0.042 * t, 0.034 * t, 0.04 * t, 1, 2.6],
251
+ [0.022, H[1] - 0.005, 0.056 * t, 0.06 * t, 0.06 * t, 1, 3.2],
252
+ [0.006, H[1] + 0.008, 0.058 * t, 0.066 * t, 0.062 * t, 1, 3.6],
253
+ [0, H[1] + 0.01, 0, 0, 0, 1],
254
+ ],
255
+ {
256
+ x,
257
+ side: s,
258
+ chain: [f + 2, f + 3],
259
+ around: [6, 8, 12][q],
260
+ sub: [1, 1, 2][q],
261
+ coat: foot,
262
+ // the cleft between the toes, from the front of the pad back along its middle
263
+ warp: (Q, k) => {
264
+ const cleft = sstep(0.008, 0, Math.abs(Q[k] - x)) * sstep(H[1] + 0.03, H[1] + 0.06, Q[k + 2]) * sstep(0.04, 0.015, Q[k + 1]);
265
+ Q[k + 2] -= 0.012 * cleft;
266
+ },
267
+ },
268
+ );
269
+ }
270
+
271
+ // The tail: thin, hung from a dock below the top of the rump to about the hocks, ending in a tuft of dark hair.
272
+ function tail(b, q, hide) {
273
+ const D = A.dock,
274
+ hair = (col, x, y, z, nx, ny) => {
275
+ hide(col, x, y, z, nx, ny);
276
+ const tuft = sstep(0.62, 0.55, y);
277
+ for (let i = 0; i < 3; i++) col[i] = lerp(col[i], COAT[i] * 0.45, tuft);
278
+ col[3] = lerp(col[3], 0.3, tuft);
279
+ };
280
+ tube(
281
+ b,
282
+ [
283
+ [D[0] + 0.03, D[1] + 0.03, 0, 0, 0, 0],
284
+ [D[0] - 0.005, D[1] + 0.005, 0.018, 0.02, 0.02, 0.5],
285
+ [D[0] - 0.08, D[1] - 0.03, 0.014, 0.014, 0.014, 1],
286
+ [D[0] - 0.2, D[1] - 0.04, 0.011, 0.011, 0.011, 1.4],
287
+ [D[0] - 0.32, D[1] - 0.04, 0.012, 0.016, 0.016, 2.2],
288
+ [D[0] - 0.42, D[1] - 0.035, 0.016, 0.02, 0.02, 3],
289
+ [D[0] - 0.47, D[1] - 0.03, 0, 0, 0, 3],
290
+ ],
291
+ { chain: [BONE.hips, BONE.tail, BONE.tail + 1, BONE.tail + 2], around: [4, 6, 8][q], sub: [1, 2, 2][q], coat: hair, lay: 1 },
292
+ );
293
+ }
294
+
295
+ // A pack camel's load, set on the chest's bone: a striped blanket over the hump, a wooden pack saddle of two arches tied over it,
296
+ // a pair of stuffed sacks hung on each side under a rolled rug, and the ropes that bind them. The blanket and the rugs are of
297
+ // undyed wool unless a world dyes them (`camelPack` of geometry/animal-options.js).
298
+ const BLANKET = [0.46, 0.4, 0.32], // undyed wool, its stripes dark and pale
299
+ SACK = [0.62, 0.55, 0.44],
300
+ RUGS = [
301
+ [0.36, 0.3, 0.24],
302
+ [0.56, 0.5, 0.41],
303
+ ], // a dark fleece's and a pale one's
304
+ WOOD = [0.32, 0.22, 0.13],
305
+ ROPE = [0.5, 0.42, 0.3];
306
+ function pack(b, q, { blanket = BLANKET, rugs = RUGS } = {}) {
307
+ // the blanket follows the body's own sections a little out from the hide, over the top and down to the sacks
308
+ const drape = (z, top, bottom, w) => [(top + bottom) / 2, z, w + 0.02, (top - bottom) / 2 + 0.02, (top - bottom) / 2 + 0.02, 0, 2.4];
309
+ b.tv = 0.8; // cloth
310
+ tube(
311
+ b,
312
+ [
313
+ drape(-0.24, 0.99, 0.58, 0.168),
314
+ drape(-0.12, 0.995, 0.57, 0.178),
315
+ drape(0.0, 1.0, 0.56, 0.188),
316
+ drape(0.1, 1.0, 0.55, 0.19),
317
+ drape(0.2, 1.0, 0.53, 0.182),
318
+ ],
319
+ {
320
+ chain: [BONE.chest],
321
+ around: [8, 12, 16][q],
322
+ sub: [1, 2, 2][q],
323
+ arc: [0.15, Math.PI - 0.15],
324
+ warp: (Q, k) => {
325
+ Q[k + 1] += humpLift(Q[k], Q[k + 1], Q[k + 2], 0.03) * 1.05;
326
+ },
327
+ coat: (col, x, y, z) => {
328
+ const stripe = Math.sin((z + 0.22) * 70) > 0.75 ? 0.45 : 1,
329
+ hem = sstep(0.97, 0.93, y);
330
+ for (let i = 0; i < 3; i++) col[i] = lerp(blanket[i] * stripe, 0.7, hem * 0.5);
331
+ col[3] = 0.8;
332
+ },
333
+ },
334
+ );
335
+ b.bone = BONE.chest;
336
+ const put = (shape, col, x, y, z, sx, sy, sz, ry = 0, rx = 0, rz = 0) => b.add(shape, col, TRS(x, y, z, sx, sy, sz, ry, rx, rz));
337
+ b.tv = 0.3; // wood: each arch two legs crossed over the hump, and the side bars that join the arches
338
+ for (const z of [-0.22, 0.17]) for (const s of [-1, 1]) put(SHAPES.cyl6, WOOD, s * 0.15, 0.97, z, 0.025, 0.27, 0.025, 0, 0, s * 0.95);
339
+ for (const s of [-1, 1]) put(SHAPES.cyl6, WOOD, s * 0.18, 0.94, -0.25, 0.022, 0.47, 0.022, 0, Math.PI / 2);
340
+ b.tv = 0.75;
341
+ for (const s of [-1, 1]) {
342
+ // two sacks a side, stuffed full and slumped against the flank, a rolled rug on them, and the ropes down their outer faces
343
+ put(SHAPES.sph, SACK, s * 0.29, 0.86, 0.0, 0.17, 0.25, 0.36, 0, 0, s * 0.1);
344
+ put(
345
+ SHAPES.sph,
346
+ SACK.map(v => v * 0.92),
347
+ s * 0.28,
348
+ 0.93,
349
+ 0.18,
350
+ 0.15,
351
+ 0.2,
352
+ 0.2,
353
+ 0,
354
+ 0,
355
+ s * 0.12,
356
+ );
357
+ put(SHAPES.cyl, rugs[s > 0 ? 0 : 1], s * 0.27, 1.0, -0.17, 0.11, 0.42, 0.11, 0, Math.PI / 2);
358
+ for (const z of [-0.08, 0.08]) put(SHAPES.cyl6, ROPE, s * 0.37, 0.74, z, 0.012, 0.26, 0.012, 0, 0, s * 0.08);
359
+ }
360
+ put(SHAPES.cyl6, ROPE, 0.2, 0.545, 0.2, 0.014, 0.4, 0.014, 0, 0, Math.PI / 2); // the girth under the belly, holding it all down
361
+ }
362
+
363
+ const HEAD_DIP = 0.3; // radians the face slopes down from level
364
+ /** Where the head hangs from the poll, carried near level: a matrix from the head's own frame to the body's, in metres. */
365
+ function headMatrix(K) {
366
+ return new THREE.Matrix4()
367
+ .makeTranslation(0, A.poll[0] * K, A.poll[1] * K)
368
+ .multiply(new THREE.Matrix4().makeRotationX(HEAD_DIP))
369
+ .multiply(new THREE.Matrix4().makeScale(K, K, K));
370
+ }
371
+
372
+ /**
373
+ * The arrays of one version of a camel's skinned mesh, as `GeometryBuilder.build(true)` gives them, standing at the origin with
374
+ * its nose to +z. Its coat is near white, for an instance's colour to tint.
375
+ * @param {number} q Its detail: 0 far, 1 between, 2 near.
376
+ * @param {boolean} packed With a pack camel's load.
377
+ * @param {(x: number, y: number, seed: number) => number} vnoise Value noise for its coat's mottling and long hair (math/noise.js).
378
+ * @param {{ blanket?: number[], rugs?: number[][] }} [colours] The load's blanket and rugs, linear [r, g, b].
379
+ */
380
+ function camelMesh(q, packed, vnoise, colours) {
381
+ const b = new GB(),
382
+ K = WITHERS,
383
+ hide = hideWith(vnoise);
384
+ b.sk = [];
385
+ b.sk2 = [];
386
+ b.skw = [];
387
+ b.tg = [];
388
+ b.M = new THREE.Matrix4().makeScale(K, K, K);
389
+ tube(b, trunkStations(), {
390
+ chain: [BONE.hips, BONE.chest, BONE.neck, BONE.neck2, BONE.head],
391
+ around: [12, 16, 22][q],
392
+ sub: [2, 3, 3][q],
393
+ coat: hide,
394
+ warp: bodyWarp,
395
+ fur: q > 0 && shagWith(vnoise),
396
+ droop: 0.5,
397
+ });
398
+ for (const s of [-1, 1]) {
399
+ leg(b, q, s, false, hide);
400
+ leg(b, q, s, true, hide);
401
+ }
402
+ tail(b, q, hide);
403
+ if (packed) pack(b, q, colours);
404
+ b.M = headMatrix(K);
405
+ camelHead(b, q, hide);
406
+ b.M = null;
407
+ return b.build(true);
408
+ }
409
+
410
+ export { GRAZE_BEND, HABITS, WITHERS, camelMesh, headMatrix, jointsAt };