distark-render 1.3.2 → 1.3.4

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 (341) hide show
  1. package/README.md +0 -0
  2. package/assets/ElonRigValidated.json +0 -0
  3. package/assets/KidB.json +2087 -2087
  4. package/assets/TankHalfRigPaul.fixed.json +0 -0
  5. package/assets/TankHalfRigPaul.json +0 -0
  6. package/assets/fixtures/rigs/mama.json +1 -0
  7. package/assets/fixtures/rigs/tank.json +1 -0
  8. package/assets/lizard.fixed.json +0 -0
  9. package/assets/lizard.json +0 -0
  10. package/assets/pig.json +0 -0
  11. package/assets/presets/jumping-jack.json +194 -0
  12. package/assets/tank.json +0 -0
  13. package/dist/cli/animate.d.ts +0 -0
  14. package/dist/cli/animate.d.ts.map +0 -0
  15. package/dist/cli/animate.js +0 -0
  16. package/dist/cli/animate.js.map +0 -0
  17. package/dist/cli/diff.d.ts +0 -0
  18. package/dist/cli/diff.d.ts.map +0 -0
  19. package/dist/cli/diff.js +0 -0
  20. package/dist/cli/diff.js.map +0 -0
  21. package/dist/cli/distark-check.d.ts +1 -0
  22. package/dist/cli/distark-check.d.ts.map +1 -1
  23. package/dist/cli/distark-check.js +6 -0
  24. package/dist/cli/distark-check.js.map +1 -1
  25. package/dist/cli/explode.d.ts +0 -0
  26. package/dist/cli/explode.d.ts.map +0 -0
  27. package/dist/cli/explode.js +0 -0
  28. package/dist/cli/explode.js.map +0 -0
  29. package/dist/cli/fix.d.ts +0 -0
  30. package/dist/cli/fix.d.ts.map +0 -0
  31. package/dist/cli/fix.js +0 -0
  32. package/dist/cli/fix.js.map +0 -0
  33. package/dist/cli/query.d.ts +0 -0
  34. package/dist/cli/query.d.ts.map +0 -0
  35. package/dist/cli/query.js +0 -0
  36. package/dist/cli/query.js.map +0 -0
  37. package/dist/cli/record.d.ts +0 -0
  38. package/dist/cli/record.d.ts.map +0 -0
  39. package/dist/cli/record.js +0 -0
  40. package/dist/cli/record.js.map +0 -0
  41. package/dist/cli/render.d.ts +0 -0
  42. package/dist/cli/render.d.ts.map +0 -0
  43. package/dist/cli/render.js +0 -0
  44. package/dist/cli/render.js.map +0 -0
  45. package/dist/cli/scene.d.ts +0 -0
  46. package/dist/cli/scene.d.ts.map +0 -0
  47. package/dist/cli/scene.js +16 -16
  48. package/dist/cli/scene.js.map +0 -0
  49. package/dist/cli/shared.d.ts +0 -0
  50. package/dist/cli/shared.d.ts.map +0 -0
  51. package/dist/cli/shared.js +0 -0
  52. package/dist/cli/shared.js.map +0 -0
  53. package/dist/cli/test.d.ts +0 -0
  54. package/dist/cli/test.d.ts.map +0 -0
  55. package/dist/cli/test.js +0 -0
  56. package/dist/cli/test.js.map +0 -0
  57. package/dist/cli/validate-world.d.ts +10 -0
  58. package/dist/cli/validate-world.d.ts.map +1 -0
  59. package/dist/cli/validate-world.js +93 -0
  60. package/dist/cli/validate-world.js.map +1 -0
  61. package/dist/cli/validate.d.ts +0 -0
  62. package/dist/cli/validate.d.ts.map +0 -0
  63. package/dist/cli/validate.js +0 -0
  64. package/dist/cli/validate.js.map +0 -0
  65. package/dist/cli/verify.d.ts +0 -0
  66. package/dist/cli/verify.d.ts.map +0 -0
  67. package/dist/cli/verify.js +0 -0
  68. package/dist/cli/verify.js.map +0 -0
  69. package/dist/modules/adapters/p5Renderer.d.ts +0 -0
  70. package/dist/modules/adapters/p5Renderer.d.ts.map +0 -0
  71. package/dist/modules/adapters/p5Renderer.js +0 -0
  72. package/dist/modules/adapters/p5Renderer.js.map +0 -0
  73. package/dist/modules/adapters/skiaRenderer.d.ts +0 -0
  74. package/dist/modules/adapters/skiaRenderer.d.ts.map +0 -0
  75. package/dist/modules/adapters/skiaRenderer.js +0 -0
  76. package/dist/modules/adapters/skiaRenderer.js.map +0 -0
  77. package/dist/modules/animationDiff.d.ts +0 -0
  78. package/dist/modules/animationDiff.d.ts.map +0 -0
  79. package/dist/modules/animationDiff.js +0 -0
  80. package/dist/modules/animationDiff.js.map +0 -0
  81. package/dist/modules/browserSceneRenderer.d.ts +0 -0
  82. package/dist/modules/browserSceneRenderer.d.ts.map +0 -0
  83. package/dist/modules/browserSceneRenderer.js +0 -0
  84. package/dist/modules/browserSceneRenderer.js.map +0 -0
  85. package/dist/modules/characterSchema.d.ts +0 -0
  86. package/dist/modules/characterSchema.d.ts.map +0 -0
  87. package/dist/modules/characterSchema.js +0 -0
  88. package/dist/modules/characterSchema.js.map +0 -0
  89. package/dist/modules/characterValidator.d.ts +0 -0
  90. package/dist/modules/characterValidator.d.ts.map +0 -0
  91. package/dist/modules/characterValidator.js +0 -0
  92. package/dist/modules/characterValidator.js.map +0 -0
  93. package/dist/modules/eyeSystem.d.ts +0 -0
  94. package/dist/modules/eyeSystem.d.ts.map +0 -0
  95. package/dist/modules/eyeSystem.js +0 -0
  96. package/dist/modules/eyeSystem.js.map +0 -0
  97. package/dist/modules/filmsetToWorld.d.ts +0 -0
  98. package/dist/modules/filmsetToWorld.d.ts.map +0 -0
  99. package/dist/modules/filmsetToWorld.js +0 -0
  100. package/dist/modules/filmsetToWorld.js.map +0 -0
  101. package/dist/modules/imageLoad.d.ts +0 -0
  102. package/dist/modules/imageLoad.d.ts.map +0 -0
  103. package/dist/modules/imageLoad.js +0 -0
  104. package/dist/modules/imageLoad.js.map +0 -0
  105. package/dist/modules/mouthSystem.d.ts +0 -0
  106. package/dist/modules/mouthSystem.d.ts.map +0 -0
  107. package/dist/modules/mouthSystem.js +0 -0
  108. package/dist/modules/mouthSystem.js.map +0 -0
  109. package/dist/modules/perspectiveDepth.d.ts +0 -0
  110. package/dist/modules/perspectiveDepth.d.ts.map +0 -0
  111. package/dist/modules/perspectiveDepth.js +0 -0
  112. package/dist/modules/perspectiveDepth.js.map +0 -0
  113. package/dist/modules/rasterDraw.d.ts +0 -0
  114. package/dist/modules/rasterDraw.d.ts.map +0 -0
  115. package/dist/modules/rasterDraw.js +0 -0
  116. package/dist/modules/rasterDraw.js.map +0 -0
  117. package/dist/modules/renderRig.d.ts +13 -0
  118. package/dist/modules/renderRig.d.ts.map +1 -1
  119. package/dist/modules/renderRig.js +72 -16
  120. package/dist/modules/renderRig.js.map +1 -1
  121. package/dist/modules/rigAssetFix.d.ts +0 -0
  122. package/dist/modules/rigAssetFix.d.ts.map +0 -0
  123. package/dist/modules/rigAssetFix.js +0 -0
  124. package/dist/modules/rigAssetFix.js.map +0 -0
  125. package/dist/modules/sceneRenderer.d.ts +0 -0
  126. package/dist/modules/sceneRenderer.d.ts.map +0 -0
  127. package/dist/modules/sceneRenderer.js +0 -0
  128. package/dist/modules/sceneRenderer.js.map +0 -0
  129. package/dist/modules/svgAssetAnalysis.d.ts +0 -0
  130. package/dist/modules/svgAssetAnalysis.d.ts.map +0 -0
  131. package/dist/modules/svgAssetAnalysis.js +0 -0
  132. package/dist/modules/svgAssetAnalysis.js.map +0 -0
  133. package/dist/modules/svgAssetFix.d.ts +0 -0
  134. package/dist/modules/svgAssetFix.d.ts.map +0 -0
  135. package/dist/modules/svgAssetFix.js +0 -0
  136. package/dist/modules/svgAssetFix.js.map +0 -0
  137. package/dist/modules/svgRaster.d.ts +0 -0
  138. package/dist/modules/svgRaster.d.ts.map +0 -0
  139. package/dist/modules/svgRaster.js +0 -0
  140. package/dist/modules/svgRaster.js.map +0 -0
  141. package/dist/modules/svgRasterPolicy.d.ts +0 -0
  142. package/dist/modules/svgRasterPolicy.d.ts.map +0 -0
  143. package/dist/modules/svgRasterPolicy.js +0 -0
  144. package/dist/modules/svgRasterPolicy.js.map +0 -0
  145. package/dist/modules/svgShapeToPath.d.ts +0 -0
  146. package/dist/modules/svgShapeToPath.d.ts.map +0 -0
  147. package/dist/modules/svgShapeToPath.js +0 -0
  148. package/dist/modules/svgShapeToPath.js.map +0 -0
  149. package/dist/modules/svgUnits.d.ts +0 -0
  150. package/dist/modules/svgUnits.d.ts.map +0 -0
  151. package/dist/modules/svgUnits.js +0 -0
  152. package/dist/modules/svgUnits.js.map +0 -0
  153. package/dist/modules/svgViewBox.d.ts +0 -0
  154. package/dist/modules/svgViewBox.d.ts.map +0 -0
  155. package/dist/modules/svgViewBox.js +0 -0
  156. package/dist/modules/svgViewBox.js.map +0 -0
  157. package/dist/modules/worldBuilder.d.ts +0 -0
  158. package/dist/modules/worldBuilder.d.ts.map +0 -0
  159. package/dist/modules/worldBuilder.js +0 -0
  160. package/dist/modules/worldBuilder.js.map +0 -0
  161. package/dist/modules/worldOrder.d.ts +0 -0
  162. package/dist/modules/worldOrder.d.ts.map +0 -0
  163. package/dist/modules/worldOrder.js +0 -0
  164. package/dist/modules/worldOrder.js.map +0 -0
  165. package/dist/modules/worldPlacement.d.ts +0 -0
  166. package/dist/modules/worldPlacement.d.ts.map +0 -0
  167. package/dist/modules/worldPlacement.js +0 -0
  168. package/dist/modules/worldPlacement.js.map +0 -0
  169. package/dist/modules/worldValidator.d.ts +50 -0
  170. package/dist/modules/worldValidator.d.ts.map +1 -0
  171. package/dist/modules/worldValidator.js +461 -0
  172. package/dist/modules/worldValidator.js.map +1 -0
  173. package/dist/tests/helpers.d.ts +0 -0
  174. package/dist/tests/helpers.d.ts.map +0 -0
  175. package/dist/tests/helpers.js +0 -0
  176. package/dist/tests/helpers.js.map +0 -0
  177. package/dist/tests/test-angle-swap.d.ts +0 -0
  178. package/dist/tests/test-angle-swap.d.ts.map +0 -0
  179. package/dist/tests/test-angle-swap.js +2 -1
  180. package/dist/tests/test-angle-swap.js.map +1 -1
  181. package/dist/tests/test-animation-diff-rendering.d.ts +0 -0
  182. package/dist/tests/test-animation-diff-rendering.d.ts.map +0 -0
  183. package/dist/tests/test-animation-diff-rendering.js +0 -0
  184. package/dist/tests/test-animation-diff-rendering.js.map +0 -0
  185. package/dist/tests/test-animation-diff.d.ts +0 -0
  186. package/dist/tests/test-animation-diff.d.ts.map +0 -0
  187. package/dist/tests/test-animation-diff.js +0 -0
  188. package/dist/tests/test-animation-diff.js.map +0 -0
  189. package/dist/tests/test-auto-eye-movement-e2e.d.ts +0 -0
  190. package/dist/tests/test-auto-eye-movement-e2e.d.ts.map +0 -0
  191. package/dist/tests/test-auto-eye-movement-e2e.js +0 -0
  192. package/dist/tests/test-auto-eye-movement-e2e.js.map +0 -0
  193. package/dist/tests/test-autofit.d.ts +0 -0
  194. package/dist/tests/test-autofit.d.ts.map +0 -0
  195. package/dist/tests/test-autofit.js +0 -0
  196. package/dist/tests/test-autofit.js.map +0 -0
  197. package/dist/tests/test-base-autofit.d.ts +0 -0
  198. package/dist/tests/test-base-autofit.d.ts.map +0 -0
  199. package/dist/tests/test-base-autofit.js +0 -0
  200. package/dist/tests/test-base-autofit.js.map +0 -0
  201. package/dist/tests/test-browser-scene.d.ts +0 -0
  202. package/dist/tests/test-browser-scene.d.ts.map +0 -0
  203. package/dist/tests/test-browser-scene.js +0 -0
  204. package/dist/tests/test-browser-scene.js.map +0 -0
  205. package/dist/tests/test-character-schema.d.ts +0 -0
  206. package/dist/tests/test-character-schema.d.ts.map +0 -0
  207. package/dist/tests/test-character-schema.js +0 -0
  208. package/dist/tests/test-character-schema.js.map +0 -0
  209. package/dist/tests/test-character-validator.d.ts +0 -0
  210. package/dist/tests/test-character-validator.d.ts.map +0 -0
  211. package/dist/tests/test-character-validator.js +0 -0
  212. package/dist/tests/test-character-validator.js.map +0 -0
  213. package/dist/tests/test-cli.d.ts +0 -0
  214. package/dist/tests/test-cli.d.ts.map +0 -0
  215. package/dist/tests/test-cli.js +88 -1
  216. package/dist/tests/test-cli.js.map +1 -1
  217. package/dist/tests/test-custom-parts.d.ts +0 -0
  218. package/dist/tests/test-custom-parts.d.ts.map +0 -0
  219. package/dist/tests/test-custom-parts.js +52 -1
  220. package/dist/tests/test-custom-parts.js.map +1 -1
  221. package/dist/tests/test-eye-extremes-visual.d.ts +0 -0
  222. package/dist/tests/test-eye-extremes-visual.d.ts.map +0 -0
  223. package/dist/tests/test-eye-extremes-visual.js +0 -0
  224. package/dist/tests/test-eye-extremes-visual.js.map +0 -0
  225. package/dist/tests/test-eye-system-reset.d.ts +0 -0
  226. package/dist/tests/test-eye-system-reset.d.ts.map +0 -0
  227. package/dist/tests/test-eye-system-reset.js +0 -0
  228. package/dist/tests/test-eye-system-reset.js.map +0 -0
  229. package/dist/tests/test-fix-visual-parity.d.ts +0 -0
  230. package/dist/tests/test-fix-visual-parity.d.ts.map +0 -0
  231. package/dist/tests/test-fix-visual-parity.js +0 -0
  232. package/dist/tests/test-fix-visual-parity.js.map +0 -0
  233. package/dist/tests/test-image-loading.d.ts +0 -0
  234. package/dist/tests/test-image-loading.d.ts.map +0 -0
  235. package/dist/tests/test-image-loading.js +0 -0
  236. package/dist/tests/test-image-loading.js.map +0 -0
  237. package/dist/tests/test-joint-movement.d.ts +0 -0
  238. package/dist/tests/test-joint-movement.d.ts.map +0 -0
  239. package/dist/tests/test-joint-movement.js +0 -0
  240. package/dist/tests/test-joint-movement.js.map +0 -0
  241. package/dist/tests/test-p5-image-types.d.ts +0 -0
  242. package/dist/tests/test-p5-image-types.d.ts.map +0 -0
  243. package/dist/tests/test-p5-image-types.js +0 -0
  244. package/dist/tests/test-p5-image-types.js.map +0 -0
  245. package/dist/tests/test-render-cache-visual.d.ts +0 -0
  246. package/dist/tests/test-render-cache-visual.d.ts.map +0 -0
  247. package/dist/tests/test-render-cache-visual.js +0 -0
  248. package/dist/tests/test-render-cache-visual.js.map +0 -0
  249. package/dist/tests/test-render-cache.d.ts +0 -0
  250. package/dist/tests/test-render-cache.d.ts.map +0 -0
  251. package/dist/tests/test-render-cache.js +0 -0
  252. package/dist/tests/test-render-cache.js.map +0 -0
  253. package/dist/tests/test-rig-standardization.d.ts +0 -0
  254. package/dist/tests/test-rig-standardization.d.ts.map +0 -0
  255. package/dist/tests/test-rig-standardization.js +1 -1
  256. package/dist/tests/test-rig-standardization.js.map +1 -1
  257. package/dist/tests/test-scene-object-svg-rerasterization.d.ts +0 -0
  258. package/dist/tests/test-scene-object-svg-rerasterization.d.ts.map +0 -0
  259. package/dist/tests/test-scene-object-svg-rerasterization.js +0 -0
  260. package/dist/tests/test-scene-object-svg-rerasterization.js.map +0 -0
  261. package/dist/tests/test-scene.d.ts +0 -0
  262. package/dist/tests/test-scene.d.ts.map +0 -0
  263. package/dist/tests/test-scene.js +0 -0
  264. package/dist/tests/test-scene.js.map +0 -0
  265. package/dist/tests/test-skia.d.ts +0 -0
  266. package/dist/tests/test-skia.d.ts.map +0 -0
  267. package/dist/tests/test-skia.js +0 -0
  268. package/dist/tests/test-skia.js.map +0 -0
  269. package/dist/tests/test-svg-asset-fix.d.ts +0 -0
  270. package/dist/tests/test-svg-asset-fix.d.ts.map +0 -0
  271. package/dist/tests/test-svg-asset-fix.js +0 -0
  272. package/dist/tests/test-svg-asset-fix.js.map +0 -0
  273. package/dist/tests/test-svg-parallax.d.ts +0 -0
  274. package/dist/tests/test-svg-parallax.d.ts.map +0 -0
  275. package/dist/tests/test-svg-parallax.js +0 -0
  276. package/dist/tests/test-svg-parallax.js.map +0 -0
  277. package/dist/tests/test-svg-raster-policy.d.ts +0 -0
  278. package/dist/tests/test-svg-raster-policy.d.ts.map +0 -0
  279. package/dist/tests/test-svg-raster-policy.js +0 -0
  280. package/dist/tests/test-svg-raster-policy.js.map +0 -0
  281. package/dist/tests/test-svg-rerasterization.d.ts +0 -0
  282. package/dist/tests/test-svg-rerasterization.d.ts.map +0 -0
  283. package/dist/tests/test-svg-rerasterization.js +0 -0
  284. package/dist/tests/test-svg-rerasterization.js.map +0 -0
  285. package/dist/tests/test-svg-viewbox.d.ts +0 -0
  286. package/dist/tests/test-svg-viewbox.d.ts.map +0 -0
  287. package/dist/tests/test-svg-viewbox.js +0 -0
  288. package/dist/tests/test-svg-viewbox.js.map +0 -0
  289. package/dist/tests/test-tanknew-svg-edit-data.d.ts +0 -0
  290. package/dist/tests/test-tanknew-svg-edit-data.d.ts.map +0 -0
  291. package/dist/tests/test-tanknew-svg-edit-data.js +0 -0
  292. package/dist/tests/test-tanknew-svg-edit-data.js.map +0 -0
  293. package/dist/tests/test-visual-pipeline.d.ts +25 -0
  294. package/dist/tests/test-visual-pipeline.d.ts.map +1 -0
  295. package/dist/tests/test-visual-pipeline.js +742 -0
  296. package/dist/tests/test-visual-pipeline.js.map +1 -0
  297. package/dist/tests/test-visual-verification.d.ts +0 -0
  298. package/dist/tests/test-visual-verification.d.ts.map +0 -0
  299. package/dist/tests/test-visual-verification.js +0 -0
  300. package/dist/tests/test-visual-verification.js.map +0 -0
  301. package/dist/tests/test-world-builder.d.ts +0 -0
  302. package/dist/tests/test-world-builder.d.ts.map +0 -0
  303. package/dist/tests/test-world-builder.js +0 -0
  304. package/dist/tests/test-world-builder.js.map +0 -0
  305. package/dist/tests/test-world-order.d.ts +0 -0
  306. package/dist/tests/test-world-order.d.ts.map +0 -0
  307. package/dist/tests/test-world-order.js +0 -0
  308. package/dist/tests/test-world-order.js.map +0 -0
  309. package/dist/tests/test-world-validate.d.ts +18 -0
  310. package/dist/tests/test-world-validate.d.ts.map +1 -0
  311. package/dist/tests/test-world-validate.js +252 -0
  312. package/dist/tests/test-world-validate.js.map +1 -0
  313. package/dist/tests/test-world-z-order.d.ts +0 -0
  314. package/dist/tests/test-world-z-order.d.ts.map +0 -0
  315. package/dist/tests/test-world-z-order.js +0 -0
  316. package/dist/tests/test-world-z-order.js.map +0 -0
  317. package/dist/types.d.ts +28 -0
  318. package/dist/types.d.ts.map +1 -1
  319. package/dist/types.js +0 -0
  320. package/dist/types.js.map +0 -0
  321. package/package.json +5 -1
  322. package/dist/tests/test-newtank-viewport-zoom-body-path.d.ts +0 -13
  323. package/dist/tests/test-newtank-viewport-zoom-body-path.d.ts.map +0 -1
  324. package/dist/tests/test-newtank-viewport-zoom-body-path.js +0 -207
  325. package/dist/tests/test-newtank-viewport-zoom-body-path.js.map +0 -1
  326. package/dist/tests/test-newtank-viewport-zoom-diagnostic.d.ts +0 -10
  327. package/dist/tests/test-newtank-viewport-zoom-diagnostic.d.ts.map +0 -1
  328. package/dist/tests/test-newtank-viewport-zoom-diagnostic.js +0 -382
  329. package/dist/tests/test-newtank-viewport-zoom-diagnostic.js.map +0 -1
  330. package/dist/tests/test-newtank-zoom-sizes.d.ts +0 -11
  331. package/dist/tests/test-newtank-zoom-sizes.d.ts.map +0 -1
  332. package/dist/tests/test-newtank-zoom-sizes.js +0 -463
  333. package/dist/tests/test-newtank-zoom-sizes.js.map +0 -1
  334. package/dist/tests/test-teen-tank-rig.d.ts +0 -12
  335. package/dist/tests/test-teen-tank-rig.d.ts.map +0 -1
  336. package/dist/tests/test-teen-tank-rig.js +0 -122
  337. package/dist/tests/test-teen-tank-rig.js.map +0 -1
  338. package/dist/tests/test-torso-pivot.d.ts +0 -11
  339. package/dist/tests/test-torso-pivot.d.ts.map +0 -1
  340. package/dist/tests/test-torso-pivot.js +0 -265
  341. package/dist/tests/test-torso-pivot.js.map +0 -1
@@ -0,0 +1,742 @@
1
+ /**
2
+ * Visual Pipeline Tests
3
+ *
4
+ * End-to-end visual verification using real rigged characters (Tank & Mama).
5
+ * Every test renders to a real PNG and verifies output with pure CPU pixel math.
6
+ * No LLM, no golden images, no external services.
7
+ *
8
+ * Rigs: assets/fixtures/rigs/tank.json & mama.json (all images baked as data URIs)
9
+ *
10
+ * Tests:
11
+ * 1. Can load character & all parts appear
12
+ * 2. Can move character (position keyframes)
13
+ * 3. Can have an animation
14
+ * 4. Can have animation + move together
15
+ * 5. Can change emotion (variation swap)
16
+ * 6. Can pan (camera x shift)
17
+ * 7. Can zoom (camera width/height)
18
+ * 8. Can pan + zoom together
19
+ * 9. Two characters facing each other
20
+ * 10. Can have mouth moving (mouth shape swap)
21
+ * 11. Character placed at spot fitting scene (sizing)
22
+ * 12. Z-index ordering between characters
23
+ */
24
+ import { readFile, mkdir } from 'fs/promises';
25
+ import { renderScene, evaluateScene, computeRigBounds, computeRenderScale, computeGroupRenderScales, fitCameraToCharacters } from '../modules/sceneRenderer.js';
26
+ import { assert, printSummary } from './helpers.js';
27
+ const OUT_DIR = 'test-outputs/visual-pipeline';
28
+ const W = 1280;
29
+ const H = 720;
30
+ // ── Rig loading ───────────────────────────────────────────────────
31
+ let tankRig;
32
+ let mamaRig;
33
+ async function loadRigs() {
34
+ tankRig = JSON.parse(await readFile('assets/fixtures/rigs/tank.json', 'utf-8'));
35
+ mamaRig = JSON.parse(await readFile('assets/fixtures/rigs/mama.json', 'utf-8'));
36
+ }
37
+ // ── Pixel helpers ─────────────────────────────────────────────────
38
+ async function getCanvasModule() {
39
+ try {
40
+ return await import('skia-canvas');
41
+ }
42
+ catch {
43
+ // @ts-ignore optional dependency
44
+ return await import('@napi-rs/canvas');
45
+ }
46
+ }
47
+ async function getImageData(pngPath) {
48
+ const mod = await getCanvasModule();
49
+ const img = await mod.loadImage(pngPath);
50
+ const canvas = mod.Canvas ? new mod.Canvas(img.width, img.height) : mod.createCanvas(img.width, img.height);
51
+ const ctx = canvas.getContext('2d');
52
+ ctx.drawImage(img, 0, 0);
53
+ return ctx.getImageData(0, 0, img.width, img.height);
54
+ }
55
+ function countPixelsInRegion(imageData, region, predicate) {
56
+ let count = 0;
57
+ const { x: rx, y: ry, w: rw, h: rh } = region;
58
+ for (let y = Math.max(0, Math.floor(ry)); y < Math.min(imageData.height, Math.floor(ry + rh)); y++) {
59
+ for (let x = Math.max(0, Math.floor(rx)); x < Math.min(imageData.width, Math.floor(rx + rw)); x++) {
60
+ const i = (y * imageData.width + x) * 4;
61
+ if (predicate(imageData.data[i], imageData.data[i + 1], imageData.data[i + 2], imageData.data[i + 3])) {
62
+ count++;
63
+ }
64
+ }
65
+ }
66
+ return count;
67
+ }
68
+ /** Is this pixel NOT the sky-blue background? */
69
+ function isNotBackground(r, g, b, a) {
70
+ if (a < 10)
71
+ return false;
72
+ // sky blue: rgb(135,206,235)
73
+ return !(Math.abs(r - 135) < 15 && Math.abs(g - 206) < 15 && Math.abs(b - 235) < 15);
74
+ }
75
+ function countNonBgPixels(imageData) {
76
+ return countPixelsInRegion(imageData, { x: 0, y: 0, w: imageData.width, h: imageData.height }, isNotBackground);
77
+ }
78
+ function countContentInRegion(imageData, region) {
79
+ return countPixelsInRegion(imageData, region, isNotBackground);
80
+ }
81
+ function countDifferentPixels(imgA, imgB, threshold = 10) {
82
+ let diff = 0;
83
+ const len = Math.min(imgA.data.length, imgB.data.length);
84
+ for (let i = 0; i < len; i += 4) {
85
+ const dr = Math.abs(imgA.data[i] - imgB.data[i]);
86
+ const dg = Math.abs(imgA.data[i + 1] - imgB.data[i + 1]);
87
+ const db = Math.abs(imgA.data[i + 2] - imgB.data[i + 2]);
88
+ if (dr > threshold || dg > threshold || db > threshold)
89
+ diff++;
90
+ }
91
+ return diff;
92
+ }
93
+ /** Count non-bg pixels in the left half vs right half */
94
+ function leftRightBalance(imageData) {
95
+ const midX = Math.floor(imageData.width / 2);
96
+ const left = countPixelsInRegion(imageData, { x: 0, y: 0, w: midX, h: imageData.height }, isNotBackground);
97
+ const right = countPixelsInRegion(imageData, { x: midX, y: 0, w: imageData.width - midX, h: imageData.height }, isNotBackground);
98
+ return { left, right };
99
+ }
100
+ async function renderWorld(world, rigs, outPath, time = 0) {
101
+ return renderScene(world, time, outPath, rigs, { width: W, height: H });
102
+ }
103
+ // ── Test 1: Can load character & all parts appear ─────────────────
104
+ async function test01_loadCharacterPartsAppear() {
105
+ console.log('\n1. Can load character & all parts appear');
106
+ const world = {
107
+ scene: { background: null },
108
+ characters: [
109
+ { id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400 },
110
+ ],
111
+ timeline: [], animations: {}, variations: [],
112
+ };
113
+ const outPath = `${OUT_DIR}/01_load_character.png`;
114
+ const report = await renderWorld(world, { Tank: tankRig }, outPath);
115
+ assert(report.quality.total_characters === 1, 'Report shows 1 character');
116
+ assert(report.quality.visible_characters === 1, 'Character is visible');
117
+ const imgData = await getImageData(outPath);
118
+ const totalContent = countNonBgPixels(imgData);
119
+ assert(totalContent > 5000, `Real character has substantial pixels (${totalContent} non-bg pixels)`);
120
+ // Character should be roughly centered
121
+ const bounds = report.characters[0].screenBounds;
122
+ const contentInBounds = countContentInRegion(imgData, bounds);
123
+ assert(contentInBounds > 1000, `Content exists in character bounds (${contentInBounds} pixels)`);
124
+ }
125
+ // ── Test 2: Can move character (position keyframes) ───────────────
126
+ async function test02_moveCharacter() {
127
+ console.log('\n2. Can move character (position keyframes)');
128
+ const world = {
129
+ scene: { background: null },
130
+ characters: [
131
+ { id: 'Tank', xCoor: 400, yCoor: 900, width: 200, height: 400 },
132
+ ],
133
+ timeline: [{
134
+ characterId: 'Tank',
135
+ lanes: [{
136
+ property: 'position',
137
+ keyframes: [
138
+ { time: 0, value: { x: 400, y: 900 }, easing: 'easeInOut' },
139
+ { time: 4, value: { x: 2100, y: 900 }, easing: 'easeInOut' },
140
+ ],
141
+ }],
142
+ }],
143
+ animations: {}, variations: [],
144
+ };
145
+ const pathT0 = `${OUT_DIR}/02_move_t0.png`;
146
+ const pathT4 = `${OUT_DIR}/02_move_t4.png`;
147
+ const reportT0 = await renderWorld(world, { Tank: tankRig }, pathT0, 0);
148
+ const reportT4 = await renderWorld(world, { Tank: tankRig }, pathT4, 4);
149
+ const centerXT0 = reportT0.characters[0].screenBounds.x + reportT0.characters[0].screenBounds.w / 2;
150
+ const centerXT4 = reportT4.characters[0].screenBounds.x + reportT4.characters[0].screenBounds.w / 2;
151
+ assert(centerXT0 < W / 2, `t=0: character center (${Math.round(centerXT0)}) is in left half`);
152
+ assert(centerXT4 > W / 2, `t=4: character center (${Math.round(centerXT4)}) is in right half`);
153
+ // Visual: the rendered images must differ
154
+ const imgT0 = await getImageData(pathT0);
155
+ const imgT4 = await getImageData(pathT4);
156
+ const diffPixels = countDifferentPixels(imgT0, imgT4);
157
+ assert(diffPixels > 1000, `Frames visually differ by ${diffPixels} pixels`);
158
+ }
159
+ // ── Test 3: Can have an animation ─────────────────────────────────
160
+ async function test03_animation() {
161
+ console.log('\n3. Can have an animation');
162
+ const world = {
163
+ scene: { background: null },
164
+ characters: [
165
+ { id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400 },
166
+ ],
167
+ timeline: [{
168
+ characterId: 'Tank',
169
+ lanes: [{
170
+ property: 'animation',
171
+ keyframes: [{ time: 0, value: 'headbob', easing: 'instant' }],
172
+ }],
173
+ }],
174
+ animations: {
175
+ 'headbob': {
176
+ id: 'headbob', name: 'Head Bob',
177
+ frames: [
178
+ { rotationValues: { head: 0 } },
179
+ { rotationValues: { head: 0.5 } },
180
+ { rotationValues: { head: 0 } },
181
+ { rotationValues: { head: -0.5 } },
182
+ ],
183
+ },
184
+ },
185
+ variations: [],
186
+ };
187
+ // Render at two different points in the animation cycle
188
+ // 4 frames at 12fps = 0.25s cycle. t=0 and t=0.125 should be visually different.
189
+ const pathA = `${OUT_DIR}/03_anim_frameA.png`;
190
+ const pathB = `${OUT_DIR}/03_anim_frameB.png`;
191
+ await renderWorld(world, { Tank: tankRig }, pathA, 0);
192
+ await renderWorld(world, { Tank: tankRig }, pathB, 0.125);
193
+ const state = evaluateScene(world, 0);
194
+ assert(state.characters[0].animationId === 'headbob', `Animation 'headbob' is active`);
195
+ // With a real rig, the head rotation should produce different pixels
196
+ const imgA = await getImageData(pathA);
197
+ const imgB = await getImageData(pathB);
198
+ const diffPixels = countDifferentPixels(imgA, imgB);
199
+ assert(diffPixels > 100, `Animation frames visually differ (${diffPixels} pixels changed)`);
200
+ }
201
+ // ── Test 4: Animation + move together ─────────────────────────────
202
+ async function test04_animationAndMove() {
203
+ console.log('\n4. Can have animation + move together');
204
+ const world = {
205
+ scene: { background: null },
206
+ characters: [
207
+ { id: 'Tank', xCoor: 400, yCoor: 900, width: 200, height: 400 },
208
+ ],
209
+ timeline: [{
210
+ characterId: 'Tank',
211
+ lanes: [
212
+ {
213
+ property: 'position',
214
+ keyframes: [
215
+ { time: 0, value: { x: 400, y: 900 }, easing: 'easeInOut' },
216
+ { time: 4, value: { x: 2100, y: 900 }, easing: 'easeInOut' },
217
+ ],
218
+ },
219
+ {
220
+ property: 'animation',
221
+ keyframes: [{ time: 0, value: 'walk', easing: 'instant' }],
222
+ },
223
+ ],
224
+ }],
225
+ animations: {
226
+ 'walk': {
227
+ id: 'walk', name: 'Walk Cycle',
228
+ frames: [
229
+ { rotationValues: { leftThigh: 0.3, rightThigh: -0.3 } },
230
+ { rotationValues: { leftThigh: -0.3, rightThigh: 0.3 } },
231
+ ],
232
+ },
233
+ },
234
+ variations: [],
235
+ };
236
+ const pathT0 = `${OUT_DIR}/04_anim_move_t0.png`;
237
+ const pathT2 = `${OUT_DIR}/04_anim_move_t2.png`;
238
+ const pathT4 = `${OUT_DIR}/04_anim_move_t4.png`;
239
+ const rT0 = await renderWorld(world, { Tank: tankRig }, pathT0, 0);
240
+ const rT2 = await renderWorld(world, { Tank: tankRig }, pathT2, 2);
241
+ const rT4 = await renderWorld(world, { Tank: tankRig }, pathT4, 4);
242
+ // Position should progress left → center → right
243
+ const cx0 = rT0.characters[0].screenBounds.x + rT0.characters[0].screenBounds.w / 2;
244
+ const cx2 = rT2.characters[0].screenBounds.x + rT2.characters[0].screenBounds.w / 2;
245
+ const cx4 = rT4.characters[0].screenBounds.x + rT4.characters[0].screenBounds.w / 2;
246
+ assert(cx0 < cx2, `t=0 (${Math.round(cx0)}) < t=2 (${Math.round(cx2)})`);
247
+ assert(cx2 < cx4, `t=2 (${Math.round(cx2)}) < t=4 (${Math.round(cx4)})`);
248
+ // Animation should be active throughout
249
+ const state = evaluateScene(world, 2);
250
+ assert(state.characters[0].animationId === 'walk', 'Walk animation active at t=2');
251
+ // All three frames should be visually different (moved + animated)
252
+ const imgT0 = await getImageData(pathT0);
253
+ const imgT2 = await getImageData(pathT2);
254
+ const diff02 = countDifferentPixels(imgT0, imgT2);
255
+ assert(diff02 > 1000, `t=0 vs t=2 visually differ (${diff02} pixels)`);
256
+ }
257
+ // ── Test 5: Can change emotion (variation swap) ───────────────────
258
+ async function test05_emotionVariation() {
259
+ console.log('\n5. Can change emotion (variation swap)');
260
+ // Build a variation that swaps Tank's head image to a different one.
261
+ // We'll use the mouth 'f' image as a fake "angry head" — it's a different image
262
+ // baked into the rig, so the head region will look different.
263
+ const angryHeadImage = tankRig.mouth?.f || tankRig.imagePaths?.torso;
264
+ const world = {
265
+ scene: { background: null },
266
+ characters: [
267
+ { id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400 },
268
+ ],
269
+ timeline: [{
270
+ characterId: 'Tank',
271
+ lanes: [{
272
+ property: 'variation',
273
+ keyframes: [
274
+ { time: 0, value: 'default', easing: 'instant' },
275
+ { time: 3, value: 'angry', easing: 'instant' },
276
+ ],
277
+ }],
278
+ }],
279
+ animations: {},
280
+ variations: [
281
+ { id: 'angry', characterId: 'Tank', imagePaths: { head: angryHeadImage } },
282
+ ],
283
+ };
284
+ const stateT0 = evaluateScene(world, 0);
285
+ const stateT3 = evaluateScene(world, 3);
286
+ assert(stateT0.characters[0].variationName === 'default', `t=0: variation is 'default'`);
287
+ assert(stateT3.characters[0].variationName === 'angry', `t=3: variation is 'angry'`);
288
+ // Render both — the head region should look different
289
+ const pathDefault = `${OUT_DIR}/05_emotion_default.png`;
290
+ const pathAngry = `${OUT_DIR}/05_emotion_angry.png`;
291
+ await renderWorld(world, { Tank: tankRig }, pathDefault, 0);
292
+ await renderWorld(world, { Tank: tankRig }, pathAngry, 3);
293
+ const imgDefault = await getImageData(pathDefault);
294
+ const imgAngry = await getImageData(pathAngry);
295
+ const diffPixels = countDifferentPixels(imgDefault, imgAngry);
296
+ assert(diffPixels > 100, `Variation swap produces visual change (${diffPixels} pixels differ)`);
297
+ }
298
+ // ── Test 6: Can pan (camera x shift) ─────────────────────────────
299
+ async function test06_pan() {
300
+ console.log('\n6. Can pan (camera x shift)');
301
+ const world = {
302
+ scene: { background: null },
303
+ characters: [
304
+ { id: 'Tank', xCoor: 640, yCoor: 720, width: 200, height: 400 },
305
+ ],
306
+ timeline: [{
307
+ characterId: '__camera__',
308
+ lanes: [{
309
+ property: 'camera',
310
+ keyframes: [
311
+ { time: 0, value: { x: 1280, y: 720, width: 2560, height: 1440 }, easing: 'easeInOut' },
312
+ { time: 4, value: { x: 2000, y: 720, width: 2560, height: 1440 }, easing: 'easeInOut' },
313
+ ],
314
+ }],
315
+ }],
316
+ animations: {}, variations: [],
317
+ };
318
+ const pathT0 = `${OUT_DIR}/06_pan_t0.png`;
319
+ const pathT4 = `${OUT_DIR}/06_pan_t4.png`;
320
+ const rT0 = await renderWorld(world, { Tank: tankRig }, pathT0, 0);
321
+ const rT4 = await renderWorld(world, { Tank: tankRig }, pathT4, 4);
322
+ const cx0 = rT0.characters[0].screenBounds.x + rT0.characters[0].screenBounds.w / 2;
323
+ const cx4 = rT4.characters[0].screenBounds.x + rT4.characters[0].screenBounds.w / 2;
324
+ assert(cx4 < cx0, `Pan right: character moved left on screen (${Math.round(cx0)} → ${Math.round(cx4)})`);
325
+ const imgT0 = await getImageData(pathT0);
326
+ const imgT4 = await getImageData(pathT4);
327
+ const diff = countDifferentPixels(imgT0, imgT4);
328
+ assert(diff > 500, `Pan produced visual change (${diff} pixels differ)`);
329
+ }
330
+ // ── Test 7: Can zoom (camera width/height) ────────────────────────
331
+ async function test07_zoom() {
332
+ console.log('\n7. Can zoom (camera width/height)');
333
+ const world = {
334
+ scene: { background: null },
335
+ characters: [
336
+ { id: 'Tank', xCoor: 1280, yCoor: 720, width: 200, height: 400 },
337
+ ],
338
+ timeline: [{
339
+ characterId: '__camera__',
340
+ lanes: [{
341
+ property: 'camera',
342
+ keyframes: [
343
+ { time: 0, value: { x: 1280, y: 720, width: 2560, height: 1440 }, easing: 'easeInOut' },
344
+ { time: 4, value: { x: 1280, y: 720, width: 800, height: 450 }, easing: 'easeInOut' },
345
+ ],
346
+ }],
347
+ }],
348
+ animations: {}, variations: [],
349
+ };
350
+ const pathWide = `${OUT_DIR}/07_zoom_wide.png`;
351
+ const pathClose = `${OUT_DIR}/07_zoom_close.png`;
352
+ const rWide = await renderWorld(world, { Tank: tankRig }, pathWide, 0);
353
+ const rClose = await renderWorld(world, { Tank: tankRig }, pathClose, 4);
354
+ const wideW = rWide.characters[0].screenBounds.w;
355
+ const closeW = rClose.characters[0].screenBounds.w;
356
+ assert(closeW > wideW, `Zoom in: character screen width grew (${wideW} → ${closeW})`);
357
+ const imgWide = await getImageData(pathWide);
358
+ const imgClose = await getImageData(pathClose);
359
+ const contentWide = countNonBgPixels(imgWide);
360
+ const contentClose = countNonBgPixels(imgClose);
361
+ assert(contentClose > contentWide, `Zoom in: more content pixels (${contentWide} → ${contentClose})`);
362
+ }
363
+ // ── Test 8: Can pan + zoom together ───────────────────────────────
364
+ async function test08_panAndZoom() {
365
+ console.log('\n8. Can pan + zoom together');
366
+ const world = {
367
+ scene: { background: null },
368
+ characters: [
369
+ { id: 'Tank', xCoor: 1900, yCoor: 720, width: 200, height: 400 },
370
+ ],
371
+ timeline: [{
372
+ characterId: '__camera__',
373
+ lanes: [{
374
+ property: 'camera',
375
+ keyframes: [
376
+ { time: 0, value: { x: 1280, y: 720, width: 2560, height: 1440 }, easing: 'easeInOut' },
377
+ { time: 4, value: { x: 1900, y: 720, width: 1000, height: 563 }, easing: 'easeInOut' },
378
+ ],
379
+ }],
380
+ }],
381
+ animations: {}, variations: [],
382
+ };
383
+ const pathStart = `${OUT_DIR}/08_panzoom_start.png`;
384
+ const pathEnd = `${OUT_DIR}/08_panzoom_end.png`;
385
+ const rStart = await renderWorld(world, { Tank: tankRig }, pathStart, 0);
386
+ const rEnd = await renderWorld(world, { Tank: tankRig }, pathEnd, 4);
387
+ const cxStart = rStart.characters[0].screenBounds.x + rStart.characters[0].screenBounds.w / 2;
388
+ const cxEnd = rEnd.characters[0].screenBounds.x + rEnd.characters[0].screenBounds.w / 2;
389
+ const distStart = Math.abs(cxStart - W / 2);
390
+ const distEnd = Math.abs(cxEnd - W / 2);
391
+ assert(distEnd < distStart, `Pan+zoom: character closer to center (dist ${Math.round(distStart)} → ${Math.round(distEnd)})`);
392
+ const wStart = rStart.characters[0].screenBounds.w;
393
+ const wEnd = rEnd.characters[0].screenBounds.w;
394
+ assert(wEnd > wStart, `Pan+zoom: character screen width grew (${wStart} → ${wEnd})`);
395
+ }
396
+ // ── Test 9: Two characters facing each other ──────────────────────
397
+ async function test09_twoCharsFacing() {
398
+ console.log('\n9. Two characters facing each other');
399
+ const world = {
400
+ scene: { background: null },
401
+ characters: [
402
+ { id: 'Tank', xCoor: 800, yCoor: 900, width: 200, height: 400 },
403
+ { id: 'Mama', xCoor: 1760, yCoor: 900, width: 200, height: 400 },
404
+ ],
405
+ timeline: [
406
+ {
407
+ characterId: 'Tank',
408
+ lanes: [{
409
+ property: 'flip',
410
+ keyframes: [{ time: 0, value: false, easing: 'instant' }],
411
+ }],
412
+ },
413
+ {
414
+ characterId: 'Mama',
415
+ lanes: [{
416
+ property: 'flip',
417
+ keyframes: [{ time: 0, value: true, easing: 'instant' }],
418
+ }],
419
+ },
420
+ ],
421
+ animations: {}, variations: [],
422
+ };
423
+ const outPath = `${OUT_DIR}/09_facing.png`;
424
+ const report = await renderWorld(world, { Tank: tankRig, Mama: mamaRig }, outPath);
425
+ assert(report.characters.length === 2, '2 characters in report');
426
+ const tank = report.characters.find((c) => c.id === 'Tank');
427
+ const mama = report.characters.find((c) => c.id === 'Mama');
428
+ assert(tank && mama, 'Both characters found in report');
429
+ const tankCX = tank.screenBounds.x + tank.screenBounds.w / 2;
430
+ const mamaCX = mama.screenBounds.x + mama.screenBounds.w / 2;
431
+ assert(tankCX < mamaCX, `Tank (${Math.round(tankCX)}) is left of Mama (${Math.round(mamaCX)})`);
432
+ assert(tank.flipX === false, 'Tank faces right (flipX=false)');
433
+ assert(mama.flipX === true, 'Mama faces left (flipX=true)');
434
+ // Visual: both characters should have content
435
+ const imgData = await getImageData(outPath);
436
+ const tankContent = countContentInRegion(imgData, tank.screenBounds);
437
+ const mamaContent = countContentInRegion(imgData, mama.screenBounds);
438
+ assert(tankContent > 1000, `Tank has real content (${tankContent} pixels)`);
439
+ assert(mamaContent > 1000, `Mama has real content (${mamaContent} pixels)`);
440
+ // FlipX visual check: render Tank alone normal vs flipped
441
+ const worldNormal = {
442
+ scene: { background: null },
443
+ characters: [{ id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400 }],
444
+ timeline: [{ characterId: 'Tank', lanes: [{ property: 'flip', keyframes: [{ time: 0, value: false, easing: 'instant' }] }] }],
445
+ animations: {}, variations: [],
446
+ };
447
+ const worldFlipped = {
448
+ scene: { background: null },
449
+ characters: [{ id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400 }],
450
+ timeline: [{ characterId: 'Tank', lanes: [{ property: 'flip', keyframes: [{ time: 0, value: true, easing: 'instant' }] }] }],
451
+ animations: {}, variations: [],
452
+ };
453
+ const pathNormal = `${OUT_DIR}/09_flip_normal.png`;
454
+ const pathFlipped = `${OUT_DIR}/09_flip_flipped.png`;
455
+ await renderWorld(worldNormal, { Tank: tankRig }, pathNormal);
456
+ await renderWorld(worldFlipped, { Tank: tankRig }, pathFlipped);
457
+ const imgNormal = await getImageData(pathNormal);
458
+ const imgFlipped = await getImageData(pathFlipped);
459
+ // Flipped image should have its content mirrored: left/right pixel balance should swap
460
+ const balNormal = leftRightBalance(imgNormal);
461
+ const balFlipped = leftRightBalance(imgFlipped);
462
+ // Tank faces right by default → more content on right side
463
+ // When flipped → more content on left side
464
+ const normalLeanRight = balNormal.right > balNormal.left;
465
+ const flippedLeanLeft = balFlipped.left > balFlipped.right;
466
+ assert(normalLeanRight || flippedLeanLeft, `FlipX changes pixel balance (normal: L=${balNormal.left} R=${balNormal.right}, flipped: L=${balFlipped.left} R=${balFlipped.right})`);
467
+ // The two images should definitely be different
468
+ const flipDiff = countDifferentPixels(imgNormal, imgFlipped);
469
+ assert(flipDiff > 500, `FlipX produces visual change (${flipDiff} pixels differ)`);
470
+ }
471
+ // ── Test 10: Mouth moving (mouth shape swap) ──────────────────────
472
+ async function test10_mouthMoving() {
473
+ console.log('\n10. Can have mouth moving (mouth shape swap)');
474
+ // The scene renderer doesn't directly handle 'mouth' timeline lane,
475
+ // but we can test mouth shape swapping by setting currentMouthShape on the rig.
476
+ // Render Tank with closed mouth vs open mouth — they should differ visually.
477
+ const tankClosed = { ...tankRig, currentMouthShape: 'closed' };
478
+ const tankOpen = { ...tankRig, currentMouthShape: 'open' };
479
+ const worldClosed = {
480
+ scene: { background: null },
481
+ characters: [{ id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400 }],
482
+ timeline: [], animations: {}, variations: [],
483
+ };
484
+ const worldOpen = {
485
+ scene: { background: null },
486
+ characters: [{ id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400 }],
487
+ timeline: [], animations: {}, variations: [],
488
+ };
489
+ const pathClosed = `${OUT_DIR}/10_mouth_closed.png`;
490
+ const pathOpen = `${OUT_DIR}/10_mouth_open.png`;
491
+ await renderWorld(worldClosed, { Tank: tankClosed }, pathClosed);
492
+ await renderWorld(worldOpen, { Tank: tankOpen }, pathOpen);
493
+ const imgClosed = await getImageData(pathClosed);
494
+ const imgOpen = await getImageData(pathOpen);
495
+ const diffPixels = countDifferentPixels(imgClosed, imgOpen);
496
+ assert(diffPixels > 50, `Mouth shape change produces visual change (${diffPixels} pixels differ)`);
497
+ // Both should still render a full character
498
+ const contentClosed = countNonBgPixels(imgClosed);
499
+ const contentOpen = countNonBgPixels(imgOpen);
500
+ assert(contentClosed > 5000, `Closed mouth: character renders (${contentClosed} px)`);
501
+ assert(contentOpen > 5000, `Open mouth: character renders (${contentOpen} px)`);
502
+ }
503
+ // ── Test 11: Character placed at spot fitting scene (sizing) ──────
504
+ async function test11_renderScale() {
505
+ console.log('\n11. Character placed at spot fitting scene (sizing)');
506
+ // Test A: renderScale changes the visual size of a real rig
507
+ const worldSmall = {
508
+ scene: { background: null },
509
+ characters: [{ id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400, renderScale: 0.5 }],
510
+ timeline: [], animations: {}, variations: [],
511
+ };
512
+ const worldBig = {
513
+ scene: { background: null },
514
+ characters: [{ id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 400, renderScale: 1.5 }],
515
+ timeline: [], animations: {}, variations: [],
516
+ };
517
+ const pathSmall = `${OUT_DIR}/11_size_small.png`;
518
+ const pathBig = `${OUT_DIR}/11_size_big.png`;
519
+ await renderWorld(worldSmall, { Tank: tankRig }, pathSmall);
520
+ await renderWorld(worldBig, { Tank: tankRig }, pathBig);
521
+ const contentSmall = countNonBgPixels(await getImageData(pathSmall));
522
+ const contentBig = countNonBgPixels(await getImageData(pathBig));
523
+ assert(contentBig > contentSmall, `renderScale 1.5 (${contentBig} px) > renderScale 0.5 (${contentSmall} px)`);
524
+ // Test B: Adult vs child sizing — child should be shorter on screen
525
+ const worldFamily = {
526
+ scene: { background: null },
527
+ characters: [
528
+ { id: 'Mama', xCoor: 900, yCoor: 900, width: 200, height: 500 },
529
+ { id: 'Tank', xCoor: 1660, yCoor: 900, width: 136, height: 340 },
530
+ ],
531
+ timeline: [], animations: {}, variations: [],
532
+ };
533
+ const pathFamily = `${OUT_DIR}/11_family.png`;
534
+ const rFamily = await renderWorld(worldFamily, { Mama: mamaRig, Tank: tankRig }, pathFamily);
535
+ const parent = rFamily.characters.find((c) => c.id === 'Mama');
536
+ const child = rFamily.characters.find((c) => c.id === 'Tank');
537
+ assert(child.screenBounds.h < parent.screenBounds.h, `Tank (${child.screenBounds.h}px) shorter than Mama (${parent.screenBounds.h}px)`);
538
+ }
539
+ // ── Test 12: Z-index ordering between characters ──────────────────
540
+ async function test12_zIndexCharacters() {
541
+ console.log('\n12. Z-index ordering between characters');
542
+ // SceneEngine sorts by y (painter's algorithm): higher y = renders on top.
543
+ // Place Tank (y=800, behind) and Mama (y=900, in front) overlapping at same x.
544
+ const world = {
545
+ scene: { background: null },
546
+ characters: [
547
+ { id: 'Tank', xCoor: 1280, yCoor: 800, width: 200, height: 400 },
548
+ { id: 'Mama', xCoor: 1280, yCoor: 900, width: 200, height: 400 },
549
+ ],
550
+ timeline: [], animations: {}, variations: [],
551
+ };
552
+ const outPath = `${OUT_DIR}/12_zindex.png`;
553
+ const report = await renderWorld(world, { Tank: tankRig, Mama: mamaRig }, outPath);
554
+ assert(report.characters.length === 2, '2 characters in z-index test');
555
+ const tank = report.characters.find((c) => c.id === 'Tank');
556
+ const mama = report.characters.find((c) => c.id === 'Mama');
557
+ assert(!tank.hidden && !mama.hidden, 'Both characters visible');
558
+ // Mama (y=900) should be lower on screen and render on top
559
+ const tankBottom = tank.screenBounds.y + tank.screenBounds.h;
560
+ const mamaBottom = mama.screenBounds.y + mama.screenBounds.h;
561
+ assert(mamaBottom > tankBottom, `Mama extends lower (${Math.round(mamaBottom)}) than Tank (${Math.round(tankBottom)})`);
562
+ // They overlap — verify shared screen space
563
+ const overlapTop = Math.max(tank.screenBounds.y, mama.screenBounds.y);
564
+ const overlapBottom = Math.min(tankBottom, mamaBottom);
565
+ assert(overlapBottom > overlapTop, `Characters overlap vertically (${Math.round(overlapTop)} to ${Math.round(overlapBottom)})`);
566
+ // Visual: the overlap region should have content (Mama rendered on top of Tank)
567
+ const imgData = await getImageData(outPath);
568
+ const overlapRegion = {
569
+ x: Math.max(tank.screenBounds.x, mama.screenBounds.x),
570
+ y: overlapTop,
571
+ w: Math.min(tank.screenBounds.x + tank.screenBounds.w, mama.screenBounds.x + mama.screenBounds.w) -
572
+ Math.max(tank.screenBounds.x, mama.screenBounds.x),
573
+ h: overlapBottom - overlapTop,
574
+ };
575
+ const overlapContent = countContentInRegion(imgData, overlapRegion);
576
+ assert(overlapContent > 500, `Overlap region has content — front char rendered on top (${overlapContent} px)`);
577
+ }
578
+ // ── Test 13: computeRigBounds returns correct native size ─────────
579
+ async function test13_rigBounds() {
580
+ console.log('\n13. computeRigBounds returns correct native size');
581
+ const tankBounds = await computeRigBounds(tankRig);
582
+ assert(tankBounds !== null, 'Tank bounds computed');
583
+ assert(tankBounds.height > 800 && tankBounds.height < 1200, `Tank native height reasonable (${tankBounds.height})`);
584
+ assert(tankBounds.aboveRoot > tankBounds.belowRoot, `Most of Tank is above root (above=${tankBounds.aboveRoot} > below=${tankBounds.belowRoot})`);
585
+ const mamaBounds = await computeRigBounds(mamaRig);
586
+ assert(mamaBounds !== null, 'Mama bounds computed');
587
+ assert(mamaBounds.height > tankBounds.height, `Mama (${mamaBounds.height}) taller than Tank (${tankBounds.height}) natively`);
588
+ }
589
+ // ── Test 14: computeRenderScale sizes characters correctly ────────
590
+ async function test14_computeRenderScale() {
591
+ console.log('\n14. computeRenderScale sizes characters correctly');
592
+ // Tank should render at 280px height (child size)
593
+ const tankScale = await computeRenderScale(tankRig, 280);
594
+ assert(tankScale > 0.2 && tankScale < 0.5, `Tank renderScale for 280px: ${tankScale.toFixed(3)}`);
595
+ // Mama should render at 420px height (adult size)
596
+ const mamaScale = await computeRenderScale(mamaRig, 420);
597
+ assert(mamaScale > 0.2 && mamaScale < 0.6, `Mama renderScale for 420px: ${mamaScale.toFixed(3)}`);
598
+ // Actually render and verify visual size
599
+ const worldTank = {
600
+ scene: { background: null },
601
+ characters: [{ id: 'Tank', xCoor: 1280, yCoor: 900, width: 200, height: 280, renderScale: tankScale }],
602
+ timeline: [], animations: {}, variations: [],
603
+ };
604
+ const worldMama = {
605
+ scene: { background: null },
606
+ characters: [{ id: 'Mama', xCoor: 1280, yCoor: 900, width: 200, height: 420, renderScale: mamaScale }],
607
+ timeline: [], animations: {}, variations: [],
608
+ };
609
+ const pathTank = `${OUT_DIR}/14_scale_tank.png`;
610
+ const pathMama = `${OUT_DIR}/14_scale_mama.png`;
611
+ await renderWorld(worldTank, { Tank: tankRig }, pathTank);
612
+ await renderWorld(worldMama, { Mama: mamaRig }, pathMama);
613
+ const imgTank = await getImageData(pathTank);
614
+ const imgMama = await getImageData(pathMama);
615
+ const tankPx = countNonBgPixels(imgTank);
616
+ const mamaPx = countNonBgPixels(imgMama);
617
+ // Mama at 420px should have more pixels than Tank at 280px
618
+ assert(mamaPx > tankPx, `Mama (420px, ${mamaPx}px²) has more pixels than Tank (280px, ${tankPx}px²)`);
619
+ }
620
+ // ── Test 15: Same-line characters with renderScale ────────────────
621
+ async function test15_sameLineCharacters() {
622
+ console.log('\n15. Same-line characters with correct relative sizes');
623
+ // Compute renderScales for Tank (child=280) and Mama (adult=420) on same line
624
+ const group = await computeGroupRenderScales([
625
+ { id: 'Tank', rigData: tankRig, targetHeight: 280 },
626
+ { id: 'Mama', rigData: mamaRig, targetHeight: 420 },
627
+ ]);
628
+ assert(group.Tank.renderScale > 0, `Tank renderScale computed: ${group.Tank.renderScale.toFixed(3)}`);
629
+ assert(group.Mama.renderScale > 0, `Mama renderScale computed: ${group.Mama.renderScale.toFixed(3)}`);
630
+ // Place them on the same baseline, let fitCameraToCharacters frame them
631
+ const chars = [
632
+ { id: 'Tank', xCoor: 800, yCoor: 900, targetHeight: 280, ...group.Tank },
633
+ { id: 'Mama', xCoor: 1760, yCoor: 900, targetHeight: 420, ...group.Mama },
634
+ ];
635
+ const baseCamera = { x: 1280, y: 720, width: 2560, height: 1440 };
636
+ const fittedCam = fitCameraToCharacters(chars, baseCamera);
637
+ // Build world with renderScales
638
+ const world = {
639
+ scene: { background: null },
640
+ characters: [
641
+ { id: 'Tank', xCoor: 800, yCoor: 900, width: 200, height: 280, renderScale: group.Tank.renderScale },
642
+ { id: 'Mama', xCoor: 1760, yCoor: 900, width: 200, height: 420, renderScale: group.Mama.renderScale },
643
+ ],
644
+ timeline: [
645
+ { characterId: 'Tank', lanes: [{ property: 'flip', keyframes: [{ time: 0, value: 'right', easing: 'instant' }] }] },
646
+ { characterId: 'Mama', lanes: [{ property: 'flip', keyframes: [{ time: 0, value: 'left', easing: 'instant' }] }] },
647
+ { characterId: '__camera__', lanes: [{ property: 'camera', keyframes: [{ time: 0, value: fittedCam, easing: 'linear' }] }] },
648
+ ],
649
+ animations: {}, variations: [],
650
+ };
651
+ const outPath = `${OUT_DIR}/15_same_line.png`;
652
+ const report = await renderWorld(world, { Tank: tankRig, Mama: mamaRig }, outPath);
653
+ // Both should be visible
654
+ assert(report.quality.visible_characters === 2, 'Both characters visible');
655
+ const tankR = report.characters.find((c) => c.id === 'Tank');
656
+ const mamaR = report.characters.find((c) => c.id === 'Mama');
657
+ // Mama should appear taller on screen
658
+ assert(mamaR.screenBounds.h > tankR.screenBounds.h, `Mama screen height (${mamaR.screenBounds.h}) > Tank (${tankR.screenBounds.h})`);
659
+ // Both should have feet near the same y level on screen
660
+ const tankFeetY = tankR.screenBounds.y + tankR.screenBounds.h;
661
+ const mamaFeetY = mamaR.screenBounds.y + mamaR.screenBounds.h;
662
+ const feetDiff = Math.abs(tankFeetY - mamaFeetY);
663
+ assert(feetDiff < 50, `Feet on same line (Tank=${tankFeetY}, Mama=${mamaFeetY}, diff=${feetDiff})`);
664
+ // Neither should be clipped (fully within frame)
665
+ const imgData = await getImageData(outPath);
666
+ assert(tankR.screenBounds.y >= 0, `Tank head not clipped (top=${tankR.screenBounds.y})`);
667
+ assert(mamaR.screenBounds.y >= 0, `Mama head not clipped (top=${mamaR.screenBounds.y})`);
668
+ assert(tankR.screenBounds.y + tankR.screenBounds.h <= H, `Tank feet in frame`);
669
+ assert(mamaR.screenBounds.y + mamaR.screenBounds.h <= H, `Mama feet in frame`);
670
+ // Both should have real content
671
+ const tankContent = countContentInRegion(imgData, tankR.screenBounds);
672
+ const mamaContent = countContentInRegion(imgData, mamaR.screenBounds);
673
+ assert(tankContent > 500, `Tank has content (${tankContent} px)`);
674
+ assert(mamaContent > 500, `Mama has content (${mamaContent} px)`);
675
+ }
676
+ // ── Test 16: fitCameraToCharacters prevents clipping ──────────────
677
+ async function test16_fitCameraNoClip() {
678
+ console.log('\n16. fitCameraToCharacters prevents head clipping');
679
+ const group = await computeGroupRenderScales([
680
+ { id: 'Tank', rigData: tankRig, targetHeight: 400 },
681
+ { id: 'Mama', rigData: mamaRig, targetHeight: 600 },
682
+ ]);
683
+ // Use a tight "medium" camera that would clip heads without fitting
684
+ const tightCamera = { x: 1280, y: 720, width: 1600, height: 900 };
685
+ const chars = [
686
+ { id: 'Tank', xCoor: 800, yCoor: 900, targetHeight: 400, ...group.Tank },
687
+ { id: 'Mama', xCoor: 1760, yCoor: 900, targetHeight: 600, ...group.Mama },
688
+ ];
689
+ const fitted = fitCameraToCharacters(chars, tightCamera);
690
+ // Fitted camera should be at least as large as tight camera
691
+ assert(fitted.width >= tightCamera.width, `Fitted width (${fitted.width}) >= tight (${tightCamera.width})`);
692
+ // Render and verify no clipping
693
+ const world = {
694
+ scene: { background: null },
695
+ characters: [
696
+ { id: 'Tank', xCoor: 800, yCoor: 900, width: 200, height: 400, renderScale: group.Tank.renderScale },
697
+ { id: 'Mama', xCoor: 1760, yCoor: 900, width: 200, height: 600, renderScale: group.Mama.renderScale },
698
+ ],
699
+ timeline: [
700
+ { characterId: '__camera__', lanes: [{ property: 'camera', keyframes: [{ time: 0, value: fitted, easing: 'linear' }] }] },
701
+ ],
702
+ animations: {}, variations: [],
703
+ };
704
+ const outPath = `${OUT_DIR}/16_fit_camera.png`;
705
+ const report = await renderWorld(world, { Tank: tankRig, Mama: mamaRig }, outPath);
706
+ const mamaR = report.characters.find((c) => c.id === 'Mama');
707
+ const tankR = report.characters.find((c) => c.id === 'Tank');
708
+ assert(mamaR.screenBounds.y >= -10, `Mama head not clipped (top=${mamaR.screenBounds.y})`);
709
+ assert(tankR.screenBounds.y >= -10, `Tank head not clipped (top=${tankR.screenBounds.y})`);
710
+ }
711
+ // ── Runner ────────────────────────────────────────────────────────
712
+ async function main() {
713
+ console.log('Visual Pipeline Tests (Real Rigs)');
714
+ console.log('='.repeat(60));
715
+ console.log('Pure CPU pixel verification — no LLM, no golden images');
716
+ console.log('Rigs: assets/fixtures/rigs/tank.json + mama.json\n');
717
+ await mkdir(OUT_DIR, { recursive: true });
718
+ await loadRigs();
719
+ await test01_loadCharacterPartsAppear();
720
+ await test02_moveCharacter();
721
+ await test03_animation();
722
+ await test04_animationAndMove();
723
+ await test05_emotionVariation();
724
+ await test06_pan();
725
+ await test07_zoom();
726
+ await test08_panAndZoom();
727
+ await test09_twoCharsFacing();
728
+ await test10_mouthMoving();
729
+ await test11_renderScale();
730
+ await test12_zIndexCharacters();
731
+ await test13_rigBounds();
732
+ await test14_computeRenderScale();
733
+ await test15_sameLineCharacters();
734
+ await test16_fitCameraNoClip();
735
+ console.log(`\nAll output PNGs saved to ${OUT_DIR}/`);
736
+ printSummary();
737
+ }
738
+ main().catch(err => {
739
+ console.error(err);
740
+ process.exit(1);
741
+ });
742
+ //# sourceMappingURL=test-visual-pipeline.js.map