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,407 @@
1
+ // Photo-statistics look guard runner and YAML baseline comparison.
2
+ // Captures fixed cameras and scripted scene beats across a world's lands, measures in-browser photo statistics
3
+ // (roamwright/tools/look-stats.cjs), writes look.yaml and contact sheets, and checks threshold warnings and drift
4
+ // against a kept YAML baseline.
5
+ 'use strict';
6
+ const fs = require('fs'),
7
+ path = require('path');
8
+ const { parseYaml, stringifyYaml } = require('./yaml.cjs');
9
+ const { compareViewStats, evaluateThresholds, measureLookStatsSource } = require('./look-stats.cjs');
10
+ const { writeContactSheet } = require('./contact-sheet.cjs');
11
+ const { seekSceneInPage, waitSceneReady } = require('./scene-run.cjs');
12
+
13
+ /**
14
+ * Filters a world's land/scene suites by optional land, substring, lands-only, or scenes-only selectors.
15
+ *
16
+ * @param {Array<object>} suites
17
+ * @param {object} [options]
18
+ * @param {string} [options.landFilter='']
19
+ * @param {string} [options.onlyFilter='']
20
+ * @param {boolean} [options.landsOnly=false]
21
+ * @param {boolean} [options.scenesOnly=false]
22
+ * @returns {Array<object>}
23
+ */
24
+ function filterLookSuites(suites, { landFilter = '', onlyFilter = '', landsOnly = false, scenesOnly = false } = {}) {
25
+ return suites
26
+ .filter(suite => !landFilter || suite.land === landFilter)
27
+ .map(suite => ({
28
+ ...suite,
29
+ views: scenesOnly ? [] : (suite.views || []).filter(v => !onlyFilter || v.id.includes(onlyFilter)),
30
+ scenes: landsOnly
31
+ ? []
32
+ : (suite.scenes || [])
33
+ .map(sc => ({
34
+ ...sc,
35
+ beats: (sc.beats || []).filter(b => !onlyFilter || b.id.includes(onlyFilter) || sc.eventId.includes(onlyFilter)),
36
+ }))
37
+ .filter(sc => sc.beats.length > 0),
38
+ }))
39
+ .filter(suite => suite.views.length > 0 || suite.scenes.length > 0);
40
+ }
41
+
42
+ /**
43
+ * Formats the single-line photo-statistics caption drawn under a look-guard contact sheet tile.
44
+ *
45
+ * @param {string} id
46
+ * @param {object} stats
47
+ * @param {string[]} warnings
48
+ * @returns {string}
49
+ */
50
+ function formatLookCaption(id, stats, warnings) {
51
+ const clipPct = (stats.clipped * 100).toFixed(1),
52
+ crushPct = (stats.crushed * 100).toFixed(1),
53
+ warnTag = warnings.length ? ` [WARN: ${warnings.join('; ')}]` : '';
54
+ return `${id} L:${stats.brightness.toFixed(2)} C:${stats.contrast.toFixed(2)} S:${stats.saturation.toFixed(2)} clip:${clipPct}% crush:${crushPct}% flat:${stats.bottomFlatness.toFixed(2)}${warnTag}`;
55
+ }
56
+
57
+ async function measureCanvasStats(page, canvasSelector) {
58
+ const pngBuffer = await page.locator(canvasSelector).screenshot({ type: 'png' });
59
+ const pngBase64 = pngBuffer.toString('base64');
60
+ const stats = await page.evaluate(
61
+ async ([b64, fnSrc]) => {
62
+ const measure = (0, eval)('(' + fnSrc + ')');
63
+ const bmp = await createImageBitmap(await (await fetch('data:image/png;base64,' + b64)).blob());
64
+ const canvas = new OffscreenCanvas(bmp.width, bmp.height),
65
+ ctx = canvas.getContext('2d');
66
+ ctx.drawImage(bmp, 0, 0);
67
+ const { data } = ctx.getImageData(0, 0, bmp.width, bmp.height);
68
+ return measure(data, bmp.width, bmp.height);
69
+ },
70
+ [pngBase64, measureLookStatsSource],
71
+ );
72
+ return { pngBase64, stats };
73
+ }
74
+
75
+ function recordMeasuredView(results, images, id, meta, pngBase64, stats) {
76
+ const warnings = evaluateThresholds(stats);
77
+ results[id] = { ...meta, ...stats };
78
+ images[id] = {
79
+ land: meta.land,
80
+ dataUrl: 'data:image/png;base64,' + pngBase64,
81
+ caption: formatLookCaption(id, stats, warnings),
82
+ warned: warnings.length > 0,
83
+ };
84
+ console.log(
85
+ (warnings.length ? 'WARN ' : 'OK ') +
86
+ id.padEnd(24) +
87
+ ` L=${stats.brightness.toFixed(3)} C=${stats.contrast.toFixed(3)} S=${stats.saturation.toFixed(3)} clip=${(stats.clipped * 100).toFixed(1)}% crush=${(stats.crushed * 100).toFixed(1)}% grn=${stats.greenHueSpread.toFixed(1)}d/${stats.greenLightSpread.toFixed(3)} tb=${stats.topBottomDelta.toFixed(3)} flat=${stats.bottomFlatness.toFixed(3)}` +
88
+ (warnings.length ? ` [${warnings.join(', ')}]` : ''),
89
+ );
90
+ }
91
+
92
+ async function captureSuiteOnBase(driver, browser, baseUrl, suites, { routePrefix = 'location/' } = {}) {
93
+ const results = {},
94
+ images = {},
95
+ canvasId = driver.canvasSelector.replace(/^#/, '');
96
+ let gpuName = '';
97
+
98
+ for (const suite of suites) {
99
+ const context = await browser.newContext({ viewport: { width: 1280, height: 720 }, deviceScaleFactor: 1 });
100
+ await driver.applyStorage(context, { quality: 'high', 'quality-fit': 'high', muted: '1' });
101
+ const page = await context.newPage();
102
+ page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 220)));
103
+
104
+ const url = driver.routeUrl(routePrefix + suite.address, { base: baseUrl });
105
+ await driver.enter(page, url, { titledMs: 180000 });
106
+ await page.waitForTimeout(1800);
107
+
108
+ if (!gpuName) {
109
+ gpuName = await page.evaluate(d => {
110
+ const gl = window[d].renderer.getContext(),
111
+ ext = gl.getExtension('WEBGL_debug_renderer_info');
112
+ return ext ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL) : '';
113
+ }, driver.debug);
114
+ }
115
+
116
+ await page.evaluate(
117
+ ([d, cId]) => {
118
+ for (const el of document.body.children) if (el.id !== cId) el.style.visibility = 'hidden';
119
+ window[d].holdQuality(true);
120
+ window[d].env.flow = false;
121
+ },
122
+ [driver.debug, canvasId],
123
+ );
124
+
125
+ for (const view of suite.views) {
126
+ await page.evaluate(
127
+ ({ d, setupCode, hour }) => {
128
+ const app = window[d],
129
+ P = app.P,
130
+ W = app.CONFIG.world,
131
+ g = (x, z) => app.space.ground(x, z);
132
+ void P;
133
+ void W;
134
+ void g;
135
+ const spec = eval(setupCode);
136
+ app.state.mode = 'play';
137
+ app.placePlayer(spec.pos[0], spec.pos[2], 0);
138
+ app.env.time = hour;
139
+ app.state.mode = 'inspect';
140
+ app.camera.position.set(spec.pos[0], spec.pos[1], spec.pos[2]);
141
+ app.camera.lookAt(spec.look[0], spec.look[1], spec.look[2]);
142
+ },
143
+ { d: driver.debug, setupCode: view.setup, hour: view.hour },
144
+ );
145
+
146
+ await page.evaluate(async d => {
147
+ const app = window[d],
148
+ wait = ms => new Promise(r => setTimeout(r, ms));
149
+ for (let i = 0; i < 24; i++) {
150
+ await app.bench(3);
151
+ await wait(75);
152
+ if (i >= 8 && (!app.quarters || app.quarters.every(q => !q.job))) break;
153
+ }
154
+ }, driver.debug);
155
+ if (await driver.clearView(page)) {
156
+ await page.evaluate(d => window[d].bench(4), driver.debug);
157
+ }
158
+ await page.evaluate(d => {
159
+ const app = window[d];
160
+ app.state.measuring = true;
161
+ app.draw();
162
+ app.draw();
163
+ app.state.measuring = false;
164
+ }, driver.debug);
165
+
166
+ const { pngBase64, stats } = await measureCanvasStats(page, driver.canvasSelector);
167
+ recordMeasuredView(results, images, view.id, { kind: 'land', land: suite.land, hour: view.hour }, pngBase64, stats);
168
+ }
169
+
170
+ for (const sceneSpec of suite.scenes) {
171
+ await page.evaluate(
172
+ ([d, sceneId]) => {
173
+ const app = window[d];
174
+ app.state.mode = 'play';
175
+ app.env.flow = true;
176
+ const ev = app.CONFIG.events.find(e => e.id === sceneId);
177
+ app.startScene(ev, true);
178
+ },
179
+ [driver.debug, sceneSpec.eventId],
180
+ );
181
+
182
+ const started = await waitSceneReady(page, driver.debug, 120000);
183
+ if (!started) {
184
+ console.error(`look-guard: scene '${sceneSpec.eventId}' failed to start`);
185
+ continue;
186
+ }
187
+ await page.evaluate(cId => {
188
+ for (const el of document.body.children) if (el.id !== cId) el.style.visibility = 'hidden';
189
+ }, canvasId);
190
+
191
+ for (const beat of sceneSpec.beats) {
192
+ await page.evaluate(seekSceneInPage, {
193
+ debug: driver.debug,
194
+ targetSeconds: beat.t,
195
+ settleSeconds: 1.1,
196
+ clearAllLog: true,
197
+ });
198
+
199
+ await page.waitForFunction(
200
+ ([d, s]) => {
201
+ const dir = window[d].director;
202
+ return !dir.ev || dir.ending || dir.t >= s;
203
+ },
204
+ [driver.debug, beat.t],
205
+ { timeout: 180000 },
206
+ );
207
+ await page.evaluate(d => {
208
+ window[d].state.measuring = true;
209
+ }, driver.debug);
210
+ const { pngBase64, stats } = await measureCanvasStats(page, driver.canvasSelector);
211
+ await page.evaluate(
212
+ d =>
213
+ new Promise(resolve =>
214
+ requestAnimationFrame(() =>
215
+ setTimeout(() => {
216
+ window[d].state.measuring = false;
217
+ resolve();
218
+ }, 120),
219
+ ),
220
+ ),
221
+ driver.debug,
222
+ );
223
+ const sceneHour = await page.evaluate(d => +window[d].env.time.toFixed(3), driver.debug);
224
+ recordMeasuredView(
225
+ results,
226
+ images,
227
+ beat.id,
228
+ { kind: 'scene', land: suite.land, scene: sceneSpec.eventId, beat: beat.t, hour: sceneHour },
229
+ pngBase64,
230
+ stats,
231
+ );
232
+ }
233
+
234
+ await page.evaluate(d => {
235
+ if (window[d].director.ev) window[d].endScene();
236
+ }, driver.debug);
237
+ await page.waitForFunction(d => window[d].state.mode === 'play' && !window[d].director.ev, driver.debug, { timeout: 60000 });
238
+ await page.waitForTimeout(250);
239
+ }
240
+
241
+ await context.close();
242
+ }
243
+
244
+ return { gpu: gpuName, views: results, images };
245
+ }
246
+
247
+ /**
248
+ * Runs the full look guard over a world's suites, writing `look.yaml` and contact sheets into `driver.OUT`.
249
+ *
250
+ * @param {object} driver Page driver from `createPageDriver`.
251
+ * @param {object} options
252
+ * @param {Array<object>} options.suites Land/scene camera suites.
253
+ * @param {string} [options.commit='']
254
+ * @param {string} [options.landFilter='']
255
+ * @param {string} [options.onlyFilter='']
256
+ * @param {boolean} [options.landsOnly=false]
257
+ * @param {boolean} [options.scenesOnly=false]
258
+ * @param {string} [options.base2=''] Optional comparison build URL for side-by-side contact sheet.
259
+ * @param {string} [options.routePrefix='location/']
260
+ */
261
+ async function runLookGuard(
262
+ driver,
263
+ {
264
+ suites: allSuites,
265
+ commit = '',
266
+ landFilter = '',
267
+ onlyFilter = '',
268
+ landsOnly = false,
269
+ scenesOnly = false,
270
+ base2 = '',
271
+ routePrefix = 'location/',
272
+ },
273
+ ) {
274
+ const suites = filterLookSuites(allSuites, { landFilter, onlyFilter, landsOnly, scenesOnly });
275
+ if (!suites.length) {
276
+ console.error('look-guard: no views or scenes matched filter');
277
+ process.exit(2);
278
+ }
279
+
280
+ const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
281
+ fs.mkdirSync(driver.OUT, { recursive: true });
282
+
283
+ const current = await captureSuiteOnBase(driver, browser, driver.BASE, suites, { routePrefix });
284
+ const record = {
285
+ when: new Date().toISOString(),
286
+ commit,
287
+ gpu: current.gpu,
288
+ views: current.views,
289
+ };
290
+ fs.writeFileSync(path.join(driver.OUT, 'look.yaml'), stringifyYaml(record));
291
+
292
+ if (base2) {
293
+ console.log('look-guard: capturing comparison build at', base2);
294
+ const reference = await captureSuiteOnBase(driver, browser, base2, suites, { routePrefix });
295
+ fs.writeFileSync(
296
+ path.join(driver.OUT, 'look-ref.yaml'),
297
+ stringifyYaml({ when: new Date().toISOString(), base: base2, gpu: reference.gpu, views: reference.views }),
298
+ );
299
+ const sideBySide = [];
300
+ for (const id of Object.keys(current.images)) {
301
+ if (reference.images[id]) {
302
+ sideBySide.push({ ...reference.images[id], caption: 'REF ' + reference.images[id].caption });
303
+ }
304
+ sideBySide.push({ ...current.images[id], caption: 'NOW ' + current.images[id].caption });
305
+ }
306
+ const comparePath = path.join(driver.OUT, 'look-compare.jpg');
307
+ await writeContactSheet(browser, sideBySide, comparePath, { columns: 2 });
308
+ console.log('look-guard: wrote side-by-side A/B contact sheet', comparePath);
309
+ }
310
+
311
+ const allCells = Object.values(current.images);
312
+ const sheetPath = path.join(driver.OUT, 'look-sheet.jpg');
313
+ await writeContactSheet(browser, allCells, sheetPath, { columns: 2 });
314
+ for (const suite of suites) {
315
+ const ids = [...suite.views.map(v => v.id), ...suite.scenes.flatMap(sc => sc.beats.map(b => b.id))];
316
+ const landCells = ids.map(id => current.images[id]).filter(Boolean);
317
+ if (landCells.length) {
318
+ await writeContactSheet(browser, landCells, path.join(driver.OUT, `look-${suite.land}.jpg`), { columns: 2 });
319
+ }
320
+ }
321
+ console.log(`look-guard: measured ${allCells.length} views/scenes across ${suites.length} land(s); contact sheet: ${sheetPath}`);
322
+ await driver.closeBrowser(browser);
323
+ }
324
+
325
+ /**
326
+ * Compares a measured look YAML file against a baseline YAML file (or keeps it when `mode === 'keep'`).
327
+ *
328
+ * @param {object} options
329
+ * @param {string} options.measuredPath
330
+ * @param {string} options.baselinePath
331
+ * @param {string} [options.mode=''] `''`, `'keep'`, or `'--strict'`.
332
+ * @param {string} [options.updateCmd='look-guard.sh keep'] Command printed in baseline header and drift hint.
333
+ * @returns {{ exitCode: number, thresholdWarnCount: number, driftCount: number, lines: string[] }}
334
+ */
335
+ function compareLookFiles({ measuredPath, baselinePath, mode = '', updateCmd = 'look-guard.sh keep' }) {
336
+ const now = parseYaml(fs.readFileSync(measuredPath, 'utf8'));
337
+ const views = now.views || {};
338
+ const viewIds = Object.keys(views);
339
+ const lines = [];
340
+
341
+ let thresholdWarnCount = 0;
342
+ for (const id of viewIds) {
343
+ const warnings = evaluateThresholds(views[id]);
344
+ if (warnings.length) {
345
+ thresholdWarnCount++;
346
+ lines.push(`WARN threshold ${id.padEnd(24)} ${warnings.join(', ')}`);
347
+ }
348
+ }
349
+
350
+ if (mode === 'keep' || !fs.existsSync(baselinePath)) {
351
+ const existing = fs.existsSync(baselinePath) ? parseYaml(fs.readFileSync(baselinePath, 'utf8')) : { views: {} };
352
+ const mergedViews = { ...(existing.views || {}), ...views };
353
+ const saved = {
354
+ when: now.when,
355
+ commit: now.commit || existing.commit || '',
356
+ gpu: now.gpu || existing.gpu || '',
357
+ views: mergedViews,
358
+ };
359
+ fs.writeFileSync(
360
+ baselinePath,
361
+ `# Photo-statistics look baseline (updated via \`${updateCmd}\`; no reference photos committed)\n` + stringifyYaml(saved),
362
+ );
363
+ lines.push(
364
+ `look-guard: baseline kept (${saved.commit || 'working tree'}, ${saved.when}): ${Object.keys(mergedViews).length} views (${thresholdWarnCount} threshold warning(s))`,
365
+ );
366
+ return { exitCode: 0, thresholdWarnCount, driftCount: 0, lines };
367
+ }
368
+
369
+ const base = parseYaml(fs.readFileSync(baselinePath, 'utf8'));
370
+ const baseViews = base.views || {};
371
+ let driftCount = 0;
372
+
373
+ lines.push(`look-guard: ${now.commit || 'this build'} (${now.when}) vs baseline ${base.commit || '?'} (${base.when})`);
374
+ for (const id of viewIds) {
375
+ const cur = views[id],
376
+ was = baseViews[id];
377
+ if (!was) {
378
+ lines.push(`NEW ${id.padEnd(24)} L=${cur.brightness.toFixed(3)} C=${cur.contrast.toFixed(3)} S=${cur.saturation.toFixed(3)}`);
379
+ continue;
380
+ }
381
+ const drifts = compareViewStats(cur, was);
382
+ if (drifts.length) {
383
+ driftCount++;
384
+ const summary = drifts.map(d => `${d.metric} ${d.was}->${d.is} (${d.delta >= 0 ? '+' : ''}${d.delta})`).join('; ');
385
+ lines.push(`DRIFT ${id.padEnd(24)} ${summary}`);
386
+ } else {
387
+ lines.push(
388
+ ` ${id.padEnd(24)} L ${was.brightness.toFixed(3)}->${cur.brightness.toFixed(3)} C ${was.contrast.toFixed(3)}->${cur.contrast.toFixed(3)} S ${was.saturation.toFixed(3)}->${cur.saturation.toFixed(3)} flat ${was.bottomFlatness.toFixed(3)}->${cur.bottomFlatness.toFixed(3)}`,
389
+ );
390
+ }
391
+ }
392
+
393
+ lines.push(
394
+ `look-guard: ${viewIds.length} views checked, ${thresholdWarnCount} threshold warning(s), ${driftCount} baseline drift(s)` +
395
+ (driftCount ? ` (update with \`${updateCmd}\` when intentional)` : ''),
396
+ );
397
+ const exitCode = mode === '--strict' && (thresholdWarnCount > 0 || driftCount > 0) ? 1 : 0;
398
+ return { exitCode, thresholdWarnCount, driftCount, lines };
399
+ }
400
+
401
+ module.exports = {
402
+ captureSuiteOnBase,
403
+ compareLookFiles,
404
+ filterLookSuites,
405
+ formatLookCaption,
406
+ runLookGuard,
407
+ };
@@ -0,0 +1,93 @@
1
+ 'use strict';
2
+ const test = require('node:test');
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('fs'),
5
+ os = require('os'),
6
+ path = require('path');
7
+ const { stringifyYaml } = require('./yaml.cjs');
8
+ const { compareLookFiles, filterLookSuites, formatLookCaption } = require('./look-guard.cjs');
9
+ const { diffRgbaFrames, measureFrameSteadiness } = require('./look-compare.cjs');
10
+
11
+ test('filterLookSuites narrows by land, substring, lands-only, and scenes-only', () => {
12
+ const suites = [
13
+ {
14
+ land: 'north',
15
+ address: 'harbour',
16
+ views: [{ id: 'north-harbour-noon' }, { id: 'north-forest-dawn' }],
17
+ scenes: [{ eventId: 'arrival', beats: [{ id: 'scene-arrival-wide', t: 10 }] }],
18
+ },
19
+ {
20
+ land: 'south',
21
+ address: 'oasis',
22
+ views: [{ id: 'south-oasis-dusk' }],
23
+ scenes: [],
24
+ },
25
+ ];
26
+ assert.equal(filterLookSuites(suites, { landFilter: 'south' }).length, 1);
27
+ assert.equal(filterLookSuites(suites, { onlyFilter: 'harbour' })[0].views.length, 1);
28
+ assert.equal(filterLookSuites(suites, { landsOnly: true })[0].scenes.length, 0);
29
+ const scenesOnly = filterLookSuites(suites, { scenesOnly: true });
30
+ assert.equal(scenesOnly.length, 1);
31
+ assert.equal(scenesOnly[0].views.length, 0);
32
+ assert.equal(scenesOnly[0].scenes[0].beats.length, 1);
33
+ });
34
+
35
+ test('formatLookCaption and compareLookFiles report OK, drift, strict failure, and keep mode', () => {
36
+ const sample = {
37
+ brightness: 0.42,
38
+ contrast: 0.18,
39
+ saturation: 0.31,
40
+ clipped: 0.01,
41
+ crushed: 0.02,
42
+ greenHueSpread: 12,
43
+ greenLightSpread: 0.06,
44
+ topBottomDelta: 0.12,
45
+ bottomFlatness: 0.25,
46
+ };
47
+ assert.match(formatLookCaption('harbour-noon', sample, []), /harbour-noon L:0\.42/);
48
+ assert.match(formatLookCaption('harbour-noon', sample, ['clipped 8%']), /\[WARN: clipped 8%\]/);
49
+
50
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'look-guard-test-'));
51
+ try {
52
+ const measured = path.join(dir, 'look.yaml'),
53
+ baseline = path.join(dir, 'baseline.yaml');
54
+ fs.writeFileSync(
55
+ measured,
56
+ stringifyYaml({ when: '2026-12-01T00:00:00Z', commit: 'abc123', gpu: 'TestGPU', views: { 'harbour-noon': sample } }),
57
+ );
58
+ const kept = compareLookFiles({ measuredPath: measured, baselinePath: baseline, mode: 'keep' });
59
+ assert.equal(kept.exitCode, 0);
60
+ assert.ok(fs.existsSync(baseline));
61
+
62
+ const clean = compareLookFiles({ measuredPath: measured, baselinePath: baseline, mode: '--strict' });
63
+ assert.equal(clean.exitCode, 0);
64
+ assert.equal(clean.driftCount, 0);
65
+
66
+ const driftedSample = { ...sample, brightness: 0.65 };
67
+ fs.writeFileSync(
68
+ measured,
69
+ stringifyYaml({ when: '2026-12-01T00:01:00Z', commit: 'def456', gpu: 'TestGPU', views: { 'harbour-noon': driftedSample } }),
70
+ );
71
+ const drifted = compareLookFiles({ measuredPath: measured, baselinePath: baseline, mode: '--strict' });
72
+ assert.equal(drifted.exitCode, 1);
73
+ assert.equal(drifted.driftCount, 1);
74
+ } finally {
75
+ fs.rmSync(dir, { recursive: true, force: true });
76
+ }
77
+ });
78
+
79
+ test('diffRgbaFrames and measureFrameSteadiness compute exact pixel deltas', () => {
80
+ const a = new Uint8Array(4 * 4 * 4).fill(100);
81
+ const b = new Uint8Array(a);
82
+ b[(2 * 4 + 1) * 4] = 120; // pixel (1, 2) differs by 20 in red
83
+ const diff = diffRgbaFrames(a, b, 4, 4, 2);
84
+ assert.deepEqual(diff, { pixels: 16, width: 4, differ: 1, most: 20, box: [1, 2, 1, 2] });
85
+
86
+ const c = new Uint8Array(a);
87
+ c[(2 * 4 + 1) * 4] = 190; // channel R +90 => luma average +30 (> 24)
88
+ const steady = measureFrameSteadiness([a, b, c], 4, 4, [0, 0, 1, 1]);
89
+ assert.equal(steady.pixels, 16);
90
+ assert.equal(steady.over8, 1);
91
+ assert.equal(steady.over24, 1);
92
+ assert.equal(steady.most, 30);
93
+ });
@@ -0,0 +1,185 @@
1
+ // Photo statistics of a rendered frame and checks against thresholds and a kept baseline, for a guard of a world's look.
2
+ // Pure RGBA8 pixel analyzer that runs both inside Chromium (via Function/eval) and in Node tests.
3
+ 'use strict';
4
+
5
+ const LOOK_THRESHOLDS = {
6
+ clippedMax: 0.06, // L > 0.985 share above 6% warns of blown highlights
7
+ crushedMax: 0.12, // L < 0.02 share above 12% warns of crushed shadows
8
+ saturationMax: 0.68, // mean saturation above 0.68 warns of oversaturated/garish colour
9
+ contrastMin: 0.09, // luminance std-dev below 0.09 warns of washed-out / fogged-flat frames
10
+ };
11
+
12
+ const LOOK_DRIFT_SLACK = {
13
+ brightness: 0.08,
14
+ contrast: 0.04,
15
+ saturation: 0.1,
16
+ clipped: 0.03,
17
+ crushed: 0.05,
18
+ greenHueSpread: 5.0,
19
+ greenLightSpread: 0.04,
20
+ topBottomDelta: 0.1,
21
+ bottomFlatness: 0.15,
22
+ };
23
+
24
+ // Measures photographic statistics from an sRGB RGBA8 Uint8Array / Uint8ClampedArray of size width * height * 4.
25
+ function measureLookStats(rgba, width, height) {
26
+ const totalPixels = width * height;
27
+ if (!totalPixels || rgba.length < totalPixels * 4) {
28
+ throw new Error(`measureLookStats: invalid buffer (${rgba.length} bytes for ${width}x${height})`);
29
+ }
30
+
31
+ let sumL = 0,
32
+ sumL2 = 0,
33
+ sumSat = 0,
34
+ clippedCount = 0,
35
+ crushedCount = 0,
36
+ greenCount = 0,
37
+ greenSumHue = 0,
38
+ greenSumHue2 = 0,
39
+ greenSumL = 0,
40
+ greenSumL2 = 0,
41
+ topSumL = 0,
42
+ topCount = 0,
43
+ botSumL = 0,
44
+ botCount = 0,
45
+ botFlatCount = 0,
46
+ botPairCount = 0;
47
+
48
+ const topEnd = Math.floor(height / 3),
49
+ botStart = Math.floor((2 * height) / 3),
50
+ prevRowL = new Float32Array(width);
51
+
52
+ let idx = 0;
53
+ for (let y = 0; y < height; y++) {
54
+ let prevL = 0;
55
+ const inTop = y < topEnd,
56
+ inBot = y >= botStart;
57
+ for (let x = 0; x < width; x++, idx += 4) {
58
+ const sr = rgba[idx] / 255,
59
+ sg = rgba[idx + 1] / 255,
60
+ sb = rgba[idx + 2] / 255;
61
+ // Rec. 709 perceptual luma over display sRGB channels in [0, 1].
62
+ const lum = 0.2126 * sr + 0.7152 * sg + 0.0722 * sb;
63
+ sumL += lum;
64
+ sumL2 += lum * lum;
65
+ if (lum > 0.985) clippedCount++;
66
+ if (lum < 0.02) crushedCount++;
67
+
68
+ const maxC = sr > sg ? (sr > sb ? sr : sb) : sg > sb ? sg : sb,
69
+ minC = sr < sg ? (sr < sb ? sr : sb) : sg < sb ? sg : sb,
70
+ chroma = maxC - minC,
71
+ // Floor denominator at 0.04 so near-black 8-bit quantization noise does not read as 100% saturated.
72
+ sat = chroma / (maxC > 0.04 ? maxC : 0.04);
73
+ sumSat += sat;
74
+
75
+ // Green vegetation/turf pixels (yellow-green crop through cool pine, [55 deg, 165 deg]).
76
+ if (chroma > 0.035 && sat > 0.12 && lum > 0.025 && lum < 0.96) {
77
+ let hue;
78
+ if (maxC === sr) hue = ((((sg - sb) / chroma) % 6) + 6) % 6;
79
+ else if (maxC === sg) hue = (sb - sr) / chroma + 2;
80
+ else hue = (sr - sg) / chroma + 4;
81
+ const hueDeg = hue * 60;
82
+ if (hueDeg >= 55 && hueDeg <= 165) {
83
+ greenCount++;
84
+ greenSumHue += hueDeg;
85
+ greenSumHue2 += hueDeg * hueDeg;
86
+ greenSumL += lum;
87
+ greenSumL2 += lum * lum;
88
+ }
89
+ }
90
+
91
+ if (inTop) {
92
+ topSumL += lum;
93
+ topCount++;
94
+ } else if (inBot) {
95
+ botSumL += lum;
96
+ botCount++;
97
+ if (x > 0 && y > botStart) {
98
+ const dx = Math.abs(lum - prevL),
99
+ dy = Math.abs(lum - prevRowL[x]);
100
+ if ((dx > dy ? dx : dy) < 0.004) botFlatCount++;
101
+ botPairCount++;
102
+ }
103
+ prevRowL[x] = lum;
104
+ prevL = lum;
105
+ }
106
+ }
107
+ }
108
+
109
+ const brightness = sumL / totalPixels,
110
+ contrast = Math.sqrt(Math.max(0, sumL2 / totalPixels - brightness * brightness)),
111
+ saturation = sumSat / totalPixels,
112
+ clipped = clippedCount / totalPixels,
113
+ crushed = crushedCount / totalPixels,
114
+ greenShare = greenCount / totalPixels,
115
+ greenMeanHue = greenCount >= 32 ? greenSumHue / greenCount : 0,
116
+ greenHueSpread = greenCount >= 32 ? Math.sqrt(Math.max(0, greenSumHue2 / greenCount - greenMeanHue * greenMeanHue)) : 0,
117
+ greenMeanL = greenCount >= 32 ? greenSumL / greenCount : 0,
118
+ greenLightSpread = greenCount >= 32 ? Math.sqrt(Math.max(0, greenSumL2 / greenCount - greenMeanL * greenMeanL)) : 0,
119
+ topThirdLum = topCount ? topSumL / topCount : 0,
120
+ bottomThirdLum = botCount ? botSumL / botCount : 0,
121
+ topBottomDelta = topThirdLum - bottomThirdLum,
122
+ bottomFlatness = botPairCount ? botFlatCount / botPairCount : 0;
123
+
124
+ const round4 = v => +v.toFixed(4);
125
+ return {
126
+ brightness: round4(brightness),
127
+ contrast: round4(contrast),
128
+ saturation: round4(saturation),
129
+ clipped: round4(clipped),
130
+ crushed: round4(crushed),
131
+ greenShare: round4(greenShare),
132
+ greenHueSpread: +greenHueSpread.toFixed(2),
133
+ greenLightSpread: round4(greenLightSpread),
134
+ topThirdLum: round4(topThirdLum),
135
+ bottomThirdLum: round4(bottomThirdLum),
136
+ topBottomDelta: round4(topBottomDelta),
137
+ bottomFlatness: round4(bottomFlatness),
138
+ };
139
+ }
140
+
141
+ function evaluateThresholds(stats, thresholds = LOOK_THRESHOLDS) {
142
+ const warnings = [];
143
+ if (stats.clipped > thresholds.clippedMax) {
144
+ warnings.push(`clipped ${(stats.clipped * 100).toFixed(1)}% > ${(thresholds.clippedMax * 100).toFixed(0)}%`);
145
+ }
146
+ if (stats.crushed > thresholds.crushedMax) {
147
+ warnings.push(`crushed ${(stats.crushed * 100).toFixed(1)}% > ${(thresholds.crushedMax * 100).toFixed(0)}%`);
148
+ }
149
+ if (stats.saturation > thresholds.saturationMax) {
150
+ warnings.push(`saturation ${stats.saturation.toFixed(3)} > ${thresholds.saturationMax}`);
151
+ }
152
+ if (stats.contrast < thresholds.contrastMin) {
153
+ warnings.push(`contrast ${stats.contrast.toFixed(3)} < ${thresholds.contrastMin}`);
154
+ }
155
+ return warnings;
156
+ }
157
+
158
+ function compareViewStats(nowStats, baseStats, slack = LOOK_DRIFT_SLACK) {
159
+ const drifts = [];
160
+ if (!baseStats) return drifts;
161
+ for (const [metric, limit] of Object.entries(slack)) {
162
+ const isVal = nowStats[metric],
163
+ wasVal = baseStats[metric];
164
+ if (typeof isVal !== 'number' || typeof wasVal !== 'number') continue;
165
+ const delta = isVal - wasVal;
166
+ if (Math.abs(delta) > limit) {
167
+ drifts.push({
168
+ metric,
169
+ was: wasVal,
170
+ is: isVal,
171
+ delta: +delta.toFixed(4),
172
+ });
173
+ }
174
+ }
175
+ return drifts;
176
+ }
177
+
178
+ module.exports = {
179
+ LOOK_DRIFT_SLACK,
180
+ LOOK_THRESHOLDS,
181
+ compareViewStats,
182
+ evaluateThresholds,
183
+ measureLookStats,
184
+ measureLookStatsSource: measureLookStats.toString(),
185
+ };