zhuda-laya-engine 0.0.0-stage → 2.1.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 (740) hide show
  1. package/AGENTS.md +236 -0
  2. package/CHANGELOG.md +431 -0
  3. package/LICENSE +41 -0
  4. package/README.md +247 -2
  5. package/assets/branding/layaair-tribute-mark.svg +5 -0
  6. package/assets/branding/zhuda-layaair-mark.svg +34 -0
  7. package/assets/prefabs/CoinFountainVfx.lh +197 -0
  8. package/assets/prefabs/ConfirmActionButton.lh +87 -0
  9. package/assets/prefabs/LevelUpAuraVfx.lh +136 -0
  10. package/assets/prefabs/MineExplosionParticle.lh +352 -0
  11. package/assets/prefabs/NineSliceDialogFrame.lh +171 -0
  12. package/assets/prefabs/SwordSlashTrailVfx.lh +117 -0
  13. package/assets/prefabs/TacticalHudBar.lh +134 -0
  14. package/assets/prefabs/TelemetryDashboard.lh +87 -0
  15. package/assets/prefabs/UnityCrystalGuardian.lh +144 -0
  16. package/assets/prefabs/ZhudaSpine42Mascot.lh +183 -0
  17. package/assets/scenes/MinesweeperStage.ls +1180 -0
  18. package/dist/asset-calibration-report.json +969 -0
  19. package/dist/build-manifest.json +254 -0
  20. package/dist/sdk/zhuda-laya-csg.cjs +710 -0
  21. package/dist/sdk/zhuda-laya-csg.esm.js +683 -0
  22. package/dist/sdk/zhuda-laya-csg.min.cjs +7 -0
  23. package/dist/sdk/zhuda-laya-csg.min.esm.js +7 -0
  24. package/dist/sdk/zhuda-laya-demo.cjs +5990 -0
  25. package/dist/sdk/zhuda-laya-demo.esm.js +5956 -0
  26. package/dist/sdk/zhuda-laya-demo.min.cjs +12 -0
  27. package/dist/sdk/zhuda-laya-demo.min.esm.js +12 -0
  28. package/dist/sdk/zhuda-laya-engine.cjs +52628 -0
  29. package/dist/sdk/zhuda-laya-engine.esm.js +51848 -0
  30. package/dist/sdk/zhuda-laya-engine.min.cjs +2710 -0
  31. package/dist/sdk/zhuda-laya-engine.min.esm.js +2710 -0
  32. package/docs/3d-acceptance.md +47 -0
  33. package/docs/3d-integration.md +190 -0
  34. package/docs/README.md +112 -0
  35. package/docs/SUPPORT.md +21 -0
  36. package/docs/agent-development.md +219 -0
  37. package/docs/animation-control.md +213 -0
  38. package/docs/asset-loading.md +97 -0
  39. package/docs/assets/reference-games.jpg +0 -0
  40. package/docs/assets/solana-qr.png +0 -0
  41. package/docs/assets/sponsor-pass.svg +32 -0
  42. package/docs/audio.md +319 -0
  43. package/docs/backend-delivery.md +218 -0
  44. package/docs/basis-textures.md +94 -0
  45. package/docs/browser-sdk-releases.json +204 -0
  46. package/docs/browser-sdk.md +187 -0
  47. package/docs/cinematics.md +267 -0
  48. package/docs/cloth.md +280 -0
  49. package/docs/combat-runtime.md +82 -0
  50. package/docs/consumer-route.md +169 -0
  51. package/docs/consumer-tooling.md +518 -0
  52. package/docs/crowd-runtime.md +195 -0
  53. package/docs/developer-tooling.md +191 -0
  54. package/docs/film-scenes.md +1504 -0
  55. package/docs/filmic-rendering.md +743 -0
  56. package/docs/flythrough.md +89 -0
  57. package/docs/gpu-depth.md +207 -0
  58. package/docs/grass.md +127 -0
  59. package/docs/hdr-environment.md +76 -0
  60. package/docs/instanced-meshes.md +137 -0
  61. package/docs/layout-and-media.md +37 -0
  62. package/docs/layout-wireframe.md +80 -0
  63. package/docs/lighting-depth.md +185 -0
  64. package/docs/minigame-packaging.md +79 -0
  65. package/docs/model-editor.md +66 -0
  66. package/docs/model-lod.md +122 -0
  67. package/docs/model-pipeline.md +74 -0
  68. package/docs/model-showcase.md +365 -0
  69. package/docs/overview.md +183 -0
  70. package/docs/plans/README.md +133 -0
  71. package/docs/plans/TASK-TEMPLATE.md +64 -0
  72. package/docs/plans/TASK-spine38-isolated-topology-20261106.md +89 -0
  73. package/docs/plans/TEMPLATE.md +44 -0
  74. package/docs/plans/VERIFICATION-TEMPLATE.md +45 -0
  75. package/docs/plans/asset-packaging.md +140 -0
  76. package/docs/plans/cinematic-production/task.md +97 -0
  77. package/docs/plans/cinematic-production/verification.md +49 -0
  78. package/docs/plans/consumer-delivery-followups.md +129 -0
  79. package/docs/plans/desktop-and-agent-gates/hardening-task.md +85 -0
  80. package/docs/plans/desktop-and-agent-gates/hardening-verification.md +109 -0
  81. package/docs/plans/desktop-and-agent-gates/task.md +94 -0
  82. package/docs/plans/desktop-and-agent-gates/verification.md +60 -0
  83. package/docs/plans/prefab-toolchain.md +73 -0
  84. package/docs/plans/preview-runtime-hardening.md +68 -0
  85. package/docs/platform-adapters.md +113 -0
  86. package/docs/post-quality.md +242 -0
  87. package/docs/prefab-editor.md +194 -0
  88. package/docs/prefab-library.md +94 -0
  89. package/docs/prefab-workflow.md +75 -0
  90. package/docs/procedural-assets.md +463 -0
  91. package/docs/procedural-prefabs.md +133 -0
  92. package/docs/quality-route.md +386 -0
  93. package/docs/release-policy.md +79 -0
  94. package/docs/routes/README.md +180 -0
  95. package/docs/routes/TEMPLATE.md +54 -0
  96. package/docs/routes/action-adventure-3d-minigame.md +238 -0
  97. package/docs/routes/apocalypse-survival-3d.md +219 -0
  98. package/docs/routes/aqua-freeze-2d-minigame.md +183 -0
  99. package/docs/routes/astral-minimal-film-look.md +141 -0
  100. package/docs/routes/cascade-slot.md +93 -0
  101. package/docs/routes/clip-free-garments.md +229 -0
  102. package/docs/routes/drop-merge-2d-minigame.md +200 -0
  103. package/docs/routes/dungeon-line-slot.md +87 -0
  104. package/docs/routes/film-as-data.md +131 -0
  105. package/docs/routes/film-fight-that-lands.md +198 -0
  106. package/docs/routes/film-ink-lines.md +120 -0
  107. package/docs/routes/floating-island.md +229 -0
  108. package/docs/routes/game-2d.md +168 -0
  109. package/docs/routes/game-rules-first.md +89 -0
  110. package/docs/routes/game-to-prefabs.md +249 -0
  111. package/docs/routes/go-game-server.md +95 -0
  112. package/docs/routes/good-looking-3d-scene.md +99 -0
  113. package/docs/routes/high-quality-character.md +263 -0
  114. package/docs/routes/humanoid-from-shapes.md +97 -0
  115. package/docs/routes/hunting-action-3d.md +76 -0
  116. package/docs/routes/idle-gacha-2d.md +67 -0
  117. package/docs/routes/interactive-film-viewer.md +141 -0
  118. package/docs/routes/isometric-mystery-2d.md +217 -0
  119. package/docs/routes/key-art-to-animated-title.md +132 -0
  120. package/docs/routes/laya-ide-project-cli-web.md +125 -0
  121. package/docs/routes/layered-cloth-on-body.md +240 -0
  122. package/docs/routes/low-poly-character-from-shapes.md +475 -0
  123. package/docs/routes/match-three-2d.md +64 -0
  124. package/docs/routes/merge-2d.md +59 -0
  125. package/docs/routes/mini-game-build.md +80 -0
  126. package/docs/routes/mobile-always-landscape.md +149 -0
  127. package/docs/routes/mobile-web-fullscreen.md +255 -0
  128. package/docs/routes/model-from-dcc.md +106 -0
  129. package/docs/routes/new-game-project.md +100 -0
  130. package/docs/routes/onboarding-tutorial-2d.md +54 -0
  131. package/docs/routes/online-lockstep-match.md +473 -0
  132. package/docs/routes/outdoor-landscape.md +134 -0
  133. package/docs/routes/outfit-swap-3d.md +144 -0
  134. package/docs/routes/papercraft-diorama.md +186 -0
  135. package/docs/routes/platform-fighter-2d.md +235 -0
  136. package/docs/routes/platformer-2d.md +69 -0
  137. package/docs/routes/pole-rescue-arcade-3d.md +198 -0
  138. package/docs/routes/pose-atlas-motion.md +188 -0
  139. package/docs/routes/prototype-to-center.md +162 -0
  140. package/docs/routes/raft-brawl-3d-minigame.md +205 -0
  141. package/docs/routes/rhythm-2d.md +82 -0
  142. package/docs/routes/rigged-phone-character.md +120 -0
  143. package/docs/routes/screen-fit-game-box.md +127 -0
  144. package/docs/routes/shared-islands.md +195 -0
  145. package/docs/routes/side-view-duel.md +266 -0
  146. package/docs/routes/single-html-page.md +83 -0
  147. package/docs/routes/smooth-character-motion.md +162 -0
  148. package/docs/routes/spine-character.md +175 -0
  149. package/docs/routes/story-counting-2d.md +219 -0
  150. package/docs/routes/survivors-2d.md +60 -0
  151. package/docs/routes/third-person-town-3d.md +240 -0
  152. package/docs/routes/tower-defence-3d.md +67 -0
  153. package/docs/routes/ui-test-by-probe.md +219 -0
  154. package/docs/routes/underwater.md +138 -0
  155. package/docs/routes/visual-content-prefab.md +101 -0
  156. package/docs/runtime-hardening.md +108 -0
  157. package/docs/shader-warm-up.md +125 -0
  158. package/docs/spring-bones.md +79 -0
  159. package/docs/stylized-shading.md +171 -0
  160. package/docs/terrain-shader.md +130 -0
  161. package/docs/vrm.md +128 -0
  162. package/docs/walking.md +97 -0
  163. package/docs/webgpu.md +225 -0
  164. package/docs/white-label-themes.md +212 -0
  165. package/docs/zh-CN/README.md +130 -0
  166. package/examples/browser-sdk/2d-webgpu.html +46 -0
  167. package/examples/browser-sdk/2d.html +46 -0
  168. package/examples/browser-sdk/3d-gltf-webgpu.html +50 -0
  169. package/examples/browser-sdk/3d-gltf.html +50 -0
  170. package/examples/browser-sdk/3d-webgpu.html +46 -0
  171. package/examples/browser-sdk/3d.html +46 -0
  172. package/examples/cinematic-capture/Main.ts +294 -0
  173. package/examples/cinematic-capture/README.md +27 -0
  174. package/examples/model-inspector/README.md +15 -0
  175. package/examples/model-inspector/asset.gltf +158 -0
  176. package/examples/windows-webgpu/README.md +57 -0
  177. package/examples/windows-webgpu/bundle.mjs +122 -0
  178. package/examples/windows-webgpu/main.mjs +302 -0
  179. package/examples/windows-webgpu/package-lock.json +2353 -0
  180. package/examples/windows-webgpu/package.json +40 -0
  181. package/examples/windows-webgpu/squirrel.mjs +66 -0
  182. package/package.json +259 -4
  183. package/packages/ci-gate/export-film.mjs +347 -0
  184. package/packages/ci-gate/verify-sequence.mjs +285 -0
  185. package/packages/compiler/agent-contract.mjs +545 -0
  186. package/packages/compiler/ast-scanner.mjs +254 -0
  187. package/packages/compiler/backend-loader.mjs +62 -0
  188. package/packages/compiler/branding-assets.mjs +32 -0
  189. package/packages/compiler/branding.mjs +324 -0
  190. package/packages/compiler/browser-auto-example.mjs +31 -0
  191. package/packages/compiler/browser-model-example.mjs +53 -0
  192. package/packages/compiler/browser-process.mjs +344 -0
  193. package/packages/compiler/browser-sdk-example.mjs +50 -0
  194. package/packages/compiler/browser-sdk.mjs +342 -0
  195. package/packages/compiler/chrome-host.mjs +196 -0
  196. package/packages/compiler/cli.mjs +22 -0
  197. package/packages/compiler/compiler-runtime.mjs +41 -0
  198. package/packages/compiler/consumer-accept.mjs +89 -0
  199. package/packages/compiler/consumer-build.mjs +641 -0
  200. package/packages/compiler/consumer-guards.mjs +422 -0
  201. package/packages/compiler/consumer-publication.mjs +56 -0
  202. package/packages/compiler/consumer-scripts.mjs +134 -0
  203. package/packages/compiler/consumer-starter-2d.mjs +54 -0
  204. package/packages/compiler/consumer-starter-minigame.mjs +30 -0
  205. package/packages/compiler/editor-http.mjs +210 -0
  206. package/packages/compiler/editor-request.ts +12 -0
  207. package/packages/compiler/film-host-client.ts +249 -0
  208. package/packages/compiler/flythrough-file.mjs +144 -0
  209. package/packages/compiler/json-locate.mjs +85 -0
  210. package/packages/compiler/layout-contract.mjs +472 -0
  211. package/packages/compiler/minigame-bootstrap.mjs +24 -0
  212. package/packages/compiler/minigame-bridge.mjs +66 -0
  213. package/packages/compiler/minigame-guards.mjs +107 -0
  214. package/packages/compiler/minigame-toolchain.mjs +241 -0
  215. package/packages/compiler/model-crown.mjs +173 -0
  216. package/packages/compiler/model-editor-client.ts +809 -0
  217. package/packages/compiler/model-editor.mjs +242 -0
  218. package/packages/compiler/model-lod.mjs +547 -0
  219. package/packages/compiler/prefab-check.mjs +288 -0
  220. package/packages/compiler/prefab-checks.mjs +74 -0
  221. package/packages/compiler/prefab-dependencies.mjs +102 -0
  222. package/packages/compiler/prefab-editor-client.ts +950 -0
  223. package/packages/compiler/prefab-editor-preview.ts +89 -0
  224. package/packages/compiler/prefab-editor-server.mjs +585 -0
  225. package/packages/compiler/prefab-editor.mjs +43 -0
  226. package/packages/compiler/prefab-environment.mjs +107 -0
  227. package/packages/compiler/prefab-lifecycle.mjs +60 -0
  228. package/packages/compiler/prefab-preview.mjs +159 -0
  229. package/packages/compiler/prefab-watch.mjs +459 -0
  230. package/packages/compiler/runtime3d-types.mjs +91 -0
  231. package/packages/compiler/stage-probe.mjs +557 -0
  232. package/packages/compiler/visual-asset-audit.mjs +609 -0
  233. package/packages/compiler/visual-contract-audit.mjs +173 -0
  234. package/packages/compiler/webgpu-loader.mjs +153 -0
  235. package/packages/compiler/zhuda-build.mjs +714 -0
  236. package/packages/compiler/zhuda-doctor.mjs +186 -0
  237. package/packages/compiler/zhuda-init.mjs +353 -0
  238. package/packages/compiler/zhuda-layout.mjs +163 -0
  239. package/packages/compiler/zhuda-minigame.mjs +636 -0
  240. package/packages/core/BenchmarkEngine.ts +2 -0
  241. package/packages/core/BitmapFontContract.ts +159 -0
  242. package/packages/core/DeclarativeSDK.ts +686 -0
  243. package/packages/core/IframeSoundAdapter.ts +1824 -0
  244. package/packages/core/NoSleepAdapter.ts +302 -0
  245. package/packages/core/PixelCalibrationEngine.ts +602 -0
  246. package/packages/core/Prefab.ts +314 -0
  247. package/packages/core/RealmGuards.ts +111 -0
  248. package/packages/core/ResponsiveLayout.ts +149 -0
  249. package/packages/core/RuntimeGuards.ts +261 -0
  250. package/packages/core/SpineCharacter.ts +243 -0
  251. package/packages/core/SpineVisualContract.ts +238 -0
  252. package/packages/core/SplashSignal.ts +72 -0
  253. package/packages/core/StaticAssetPipeline.ts +3 -0
  254. package/packages/core/TopologyGraph.ts +693 -0
  255. package/packages/core/UnityBridgePipeline.ts +2 -0
  256. package/packages/core/VideoSurface.ts +75 -0
  257. package/packages/core/ViewportMatrixEngine.ts +237 -0
  258. package/packages/core/VisualFocusContract.ts +76 -0
  259. package/packages/core/VisualMigrationPipeline.ts +245 -0
  260. package/packages/core/WebViewSurface.ts +116 -0
  261. package/packages/core/audio/OfflineMix.ts +186 -0
  262. package/packages/core/audio/Spatial.ts +312 -0
  263. package/packages/core/audio/StreamVoice.ts +161 -0
  264. package/packages/core/csg/Bsp.ts +310 -0
  265. package/packages/core/csg/index.ts +589 -0
  266. package/packages/core/effects/Effect2D.ts +286 -0
  267. package/packages/core/effects/Effect3D.ts +213 -0
  268. package/packages/core/effects/EffectBudget.ts +695 -0
  269. package/packages/core/effects/EffectDirector.ts +254 -0
  270. package/packages/core/effects/EffectPresets.ts +843 -0
  271. package/packages/core/effects/EffectPresets2D.ts +1011 -0
  272. package/packages/core/effects/EffectSprites.ts +143 -0
  273. package/packages/core/effects/ParticleEventLink.ts +53 -0
  274. package/packages/core/effects/README.md +108 -0
  275. package/packages/core/effects/VfxMaterial.ts +253 -0
  276. package/packages/core/film/BakeKey.ts +21 -0
  277. package/packages/core/film/ColorValues.ts +44 -0
  278. package/packages/core/film/FilmLint.ts +353 -0
  279. package/packages/core/film/FilmPrefab.ts +82 -0
  280. package/packages/core/film/FilmReview.ts +84 -0
  281. package/packages/core/film/FilmScene.ts +3442 -0
  282. package/packages/core/film/FilmStage.ts +2148 -0
  283. package/packages/core/film/Flythrough.ts +169 -0
  284. package/packages/core/film/FlythroughReport.ts +326 -0
  285. package/packages/core/film/FrameMetrics.ts +167 -0
  286. package/packages/core/film/LiveLook.ts +242 -0
  287. package/packages/core/film/LookQuality.ts +94 -0
  288. package/packages/core/film/Projection.ts +74 -0
  289. package/packages/core/film/SceneLook.ts +363 -0
  290. package/packages/core/film/index.ts +12 -0
  291. package/packages/core/index.ts +48 -0
  292. package/packages/core/particles/EffectEnvelope.ts +52 -0
  293. package/packages/core/particles/LayaParticleRenderer.ts +182 -0
  294. package/packages/core/particles/LayaParticleRenderer3D.ts +218 -0
  295. package/packages/core/particles/ParticleExtras.ts +163 -0
  296. package/packages/core/particles/ParticleMesh3D.ts +156 -0
  297. package/packages/core/particles/ParticleSystem.ts +324 -0
  298. package/packages/core/particles/ParticleSystem3D.ts +411 -0
  299. package/packages/core/particles/ParticleTypes.ts +230 -0
  300. package/packages/core/particles/ParticleTypes3D.ts +115 -0
  301. package/packages/core/particles/README.md +181 -0
  302. package/packages/core/particles/RibbonPath3D.ts +234 -0
  303. package/packages/core/particles/RibbonTrail.ts +145 -0
  304. package/packages/core/particles/RibbonTrail3D.ts +166 -0
  305. package/packages/core/particles/index.ts +12 -0
  306. package/packages/core/prefabs/PrefabLibrary.ts +692 -0
  307. package/packages/core/prefabs/PrefabTree3D.ts +291 -0
  308. package/packages/core/prefabs/index.ts +10 -0
  309. package/packages/core/procedural/Geometry.ts +1871 -0
  310. package/packages/core/procedural/Hand.ts +1510 -0
  311. package/packages/core/procedural/Isosurface.ts +1035 -0
  312. package/packages/core/procedural/ModuleHarness.ts +180 -0
  313. package/packages/core/procedural/Noise.ts +123 -0
  314. package/packages/core/procedural/PhotoMaterial.ts +283 -0
  315. package/packages/core/procedural/ProceduralAssetProvider.ts +105 -0
  316. package/packages/core/procedural/ProceduralMaterial.ts +184 -0
  317. package/packages/core/procedural/PropFactory.ts +307 -0
  318. package/packages/core/procedural/Random.ts +70 -0
  319. package/packages/core/procedural/SynthAudio.ts +221 -0
  320. package/packages/core/procedural/TerrainMesh.ts +207 -0
  321. package/packages/core/procedural/TextureRecipe.ts +464 -0
  322. package/packages/core/procedural/TriplanarMaterial.ts +169 -0
  323. package/packages/core/procedural/Variation.ts +94 -0
  324. package/packages/core/procedural/index.ts +15 -0
  325. package/packages/core/runtime3d/ActionFrames.ts +245 -0
  326. package/packages/core/runtime3d/AnimationBlend.ts +282 -0
  327. package/packages/core/runtime3d/AnimationBlendMath.ts +98 -0
  328. package/packages/core/runtime3d/AssetProvider.ts +775 -0
  329. package/packages/core/runtime3d/AssetShowcase.ts +190 -0
  330. package/packages/core/runtime3d/Assets.ts +801 -0
  331. package/packages/core/runtime3d/AsyncDeadline.ts +53 -0
  332. package/packages/core/runtime3d/AsyncOperation.ts +39 -0
  333. package/packages/core/runtime3d/BackendChoice.ts +359 -0
  334. package/packages/core/runtime3d/BakedCrowd.ts +575 -0
  335. package/packages/core/runtime3d/BasisTexture.ts +657 -0
  336. package/packages/core/runtime3d/CameraCollision.ts +69 -0
  337. package/packages/core/runtime3d/CameraEffects.ts +752 -0
  338. package/packages/core/runtime3d/CameraRig.ts +70 -0
  339. package/packages/core/runtime3d/CharacterController.ts +272 -0
  340. package/packages/core/runtime3d/CinematicCapture.ts +457 -0
  341. package/packages/core/runtime3d/Clocks.ts +724 -0
  342. package/packages/core/runtime3d/Cloth.ts +183 -0
  343. package/packages/core/runtime3d/Clouds.ts +462 -0
  344. package/packages/core/runtime3d/ColorLut.ts +351 -0
  345. package/packages/core/runtime3d/CombatQueries.ts +240 -0
  346. package/packages/core/runtime3d/ComputePass.ts +582 -0
  347. package/packages/core/runtime3d/CrowdPresentation.ts +368 -0
  348. package/packages/core/runtime3d/DebugDraw.ts +567 -0
  349. package/packages/core/runtime3d/DebugStats.ts +35 -0
  350. package/packages/core/runtime3d/Decals.ts +309 -0
  351. package/packages/core/runtime3d/DensityVolume.ts +238 -0
  352. package/packages/core/runtime3d/DistanceBricks.ts +349 -0
  353. package/packages/core/runtime3d/Dither.ts +199 -0
  354. package/packages/core/runtime3d/DrawWarmUp.ts +217 -0
  355. package/packages/core/runtime3d/EdgeSmoothing.ts +108 -0
  356. package/packages/core/runtime3d/EnvironmentProbe.ts +656 -0
  357. package/packages/core/runtime3d/Filmic.ts +973 -0
  358. package/packages/core/runtime3d/Foliage.ts +367 -0
  359. package/packages/core/runtime3d/GltfIntake.ts +914 -0
  360. package/packages/core/runtime3d/GltfSecondUv.ts +153 -0
  361. package/packages/core/runtime3d/GraphicsGuard.ts +171 -0
  362. package/packages/core/runtime3d/Grass.ts +1080 -0
  363. package/packages/core/runtime3d/GroundTruthAO.ts +360 -0
  364. package/packages/core/runtime3d/HalfFloat.ts +44 -0
  365. package/packages/core/runtime3d/HdrEnvironment.ts +588 -0
  366. package/packages/core/runtime3d/Ik.ts +392 -0
  367. package/packages/core/runtime3d/InputBuffer.ts +165 -0
  368. package/packages/core/runtime3d/InstancedMesh.ts +460 -0
  369. package/packages/core/runtime3d/Laya342Adapters.ts +1095 -0
  370. package/packages/core/runtime3d/Laya342GltfAdapter.ts +751 -0
  371. package/packages/core/runtime3d/LensFinish.ts +153 -0
  372. package/packages/core/runtime3d/LensFlare.ts +490 -0
  373. package/packages/core/runtime3d/LightFog.ts +1008 -0
  374. package/packages/core/runtime3d/LightingDepth.ts +544 -0
  375. package/packages/core/runtime3d/Lightmap.ts +238 -0
  376. package/packages/core/runtime3d/Math3D.ts +84 -0
  377. package/packages/core/runtime3d/MeshQuery.ts +547 -0
  378. package/packages/core/runtime3d/MeshoptModelDecoder.ts +354 -0
  379. package/packages/core/runtime3d/MiniGameSplash.ts +70 -0
  380. package/packages/core/runtime3d/ModelAnimationSampler.ts +97 -0
  381. package/packages/core/runtime3d/ModelCompatibility.ts +890 -0
  382. package/packages/core/runtime3d/ModelDecoder.ts +294 -0
  383. package/packages/core/runtime3d/ModelInspector.ts +226 -0
  384. package/packages/core/runtime3d/ModelLod.ts +163 -0
  385. package/packages/core/runtime3d/ModelPlacements.ts +426 -0
  386. package/packages/core/runtime3d/ObjectMotion.ts +217 -0
  387. package/packages/core/runtime3d/PhysicalCamera.ts +190 -0
  388. package/packages/core/runtime3d/PointShadow.ts +500 -0
  389. package/packages/core/runtime3d/PointShadowSchedule.ts +201 -0
  390. package/packages/core/runtime3d/Pool.ts +120 -0
  391. package/packages/core/runtime3d/ProbeVolume.ts +695 -0
  392. package/packages/core/runtime3d/QualityGovernor.ts +385 -0
  393. package/packages/core/runtime3d/QualityMemory.ts +200 -0
  394. package/packages/core/runtime3d/RenderScale.ts +356 -0
  395. package/packages/core/runtime3d/RenderSpaces.ts +105 -0
  396. package/packages/core/runtime3d/Renderer.ts +377 -0
  397. package/packages/core/runtime3d/ResultPlayback.ts +239 -0
  398. package/packages/core/runtime3d/Runtime.ts +507 -0
  399. package/packages/core/runtime3d/RuntimeDriver.ts +127 -0
  400. package/packages/core/runtime3d/SceneLifecycle.ts +211 -0
  401. package/packages/core/runtime3d/SceneMutation.ts +107 -0
  402. package/packages/core/runtime3d/SceneQueries.ts +191 -0
  403. package/packages/core/runtime3d/ScreenReflections.ts +595 -0
  404. package/packages/core/runtime3d/SelectionOutline.ts +389 -0
  405. package/packages/core/runtime3d/ShaderErrors.ts +104 -0
  406. package/packages/core/runtime3d/ShaderRegistry.ts +34 -0
  407. package/packages/core/runtime3d/ShaderWarmUp.ts +473 -0
  408. package/packages/core/runtime3d/ShadowUpdates.ts +287 -0
  409. package/packages/core/runtime3d/SkinBinding.ts +235 -0
  410. package/packages/core/runtime3d/Smaa.ts +386 -0
  411. package/packages/core/runtime3d/SmaaTables.ts +244 -0
  412. package/packages/core/runtime3d/SpringBones.ts +184 -0
  413. package/packages/core/runtime3d/SurfaceBuffer.ts +76 -0
  414. package/packages/core/runtime3d/Surfaces.ts +1105 -0
  415. package/packages/core/runtime3d/Themes.ts +344 -0
  416. package/packages/core/runtime3d/Timeline.ts +362 -0
  417. package/packages/core/runtime3d/ToneCurves.ts +292 -0
  418. package/packages/core/runtime3d/TransformGizmo.ts +539 -0
  419. package/packages/core/runtime3d/TriangleMask.ts +250 -0
  420. package/packages/core/runtime3d/Underwater.ts +778 -0
  421. package/packages/core/runtime3d/Utf8.ts +87 -0
  422. package/packages/core/runtime3d/Vrm.ts +773 -0
  423. package/packages/core/runtime3d/VrmDocument.ts +1830 -0
  424. package/packages/core/runtime3d/WalkGrid.ts +471 -0
  425. package/packages/core/runtime3d/WebGPU342Adapters.ts +280 -0
  426. package/packages/core/runtime3d/index.ts +147 -0
  427. package/packages/core/shaders/Laya342ShaderTemplates.ts +6 -0
  428. package/packages/core/shaders/LitSurfaceMaterial.ts +1076 -0
  429. package/packages/core/shaders/LitSurfaceTemplates.ts +13 -0
  430. package/packages/core/shaders/ReflectiveSurface.ts +285 -0
  431. package/packages/core/shaders/ShaderMaterials.ts +387 -0
  432. package/packages/core/shaders/ToonMaterial.ts +559 -0
  433. package/packages/core/shaders/WaterRipples.ts +170 -0
  434. package/packages/core/shaders/WaterSurface.ts +480 -0
  435. package/packages/core/shaders/ZhudaCommon.ts +109 -0
  436. package/packages/core/shaders/index.ts +6 -0
  437. package/packages/core/simulation/Cloth.ts +1541 -0
  438. package/packages/core/simulation/ParticleCore.ts +498 -0
  439. package/packages/core/simulation/SpringBones.ts +553 -0
  440. package/packages/core/simulation/index.ts +3 -0
  441. package/packages/core/terrain/Heightfield.ts +385 -0
  442. package/packages/core/terrain/Terrain2D.ts +324 -0
  443. package/packages/core/terrain/Terrain3D.ts +452 -0
  444. package/packages/core/terrain/TerrainShell.ts +94 -0
  445. package/packages/core/terrain/index.ts +3 -0
  446. package/packages/demo/BenchmarkEngine.ts +184 -0
  447. package/packages/demo/PixelCalibrationEngine.ts +36 -0
  448. package/packages/demo/ProceduralStarter.ts +312 -0
  449. package/packages/demo/StaticAssetPipeline.ts +1631 -0
  450. package/packages/demo/UnityBridgePipeline.ts +485 -0
  451. package/packages/demo/index.ts +6 -0
  452. package/packages/mcp-server/arguments.mjs +81 -0
  453. package/packages/mcp-server/corpus.mjs +627 -0
  454. package/packages/mcp-server/film-host.mjs +627 -0
  455. package/packages/mcp-server/film-session.mjs +95 -0
  456. package/packages/mcp-server/film-tools.mjs +460 -0
  457. package/packages/mcp-server/index.mjs +931 -0
  458. package/packages/mcp-server/quality-route.mjs +332 -0
  459. package/packages/mcp-server/roots.mjs +72 -0
  460. package/packages/mcp-server/runtime.mjs +81 -0
  461. package/packages/types/BitmapFontContract.d.ts +19 -0
  462. package/packages/types/DeclarativeSDK.d.ts +137 -0
  463. package/packages/types/IframeSoundAdapter.d.ts +173 -0
  464. package/packages/types/NoSleepAdapter.d.ts +50 -0
  465. package/packages/types/PixelCalibrationEngine.d.ts +83 -0
  466. package/packages/types/Prefab.d.ts +11 -0
  467. package/packages/types/RealmGuards.d.ts +26 -0
  468. package/packages/types/ResponsiveLayout.d.ts +10 -0
  469. package/packages/types/RuntimeGuards.d.ts +55 -0
  470. package/packages/types/SpineCharacter.d.ts +94 -0
  471. package/packages/types/SpineVisualContract.d.ts +50 -0
  472. package/packages/types/SplashSignal.d.ts +27 -0
  473. package/packages/types/TopologyGraph.d.ts +76 -0
  474. package/packages/types/VideoSurface.d.ts +21 -0
  475. package/packages/types/ViewportMatrixEngine.d.ts +27 -0
  476. package/packages/types/VisualFocusContract.d.ts +32 -0
  477. package/packages/types/VisualMigrationPipeline.d.ts +53 -0
  478. package/packages/types/WebViewSurface.d.ts +26 -0
  479. package/packages/types/audio/OfflineMix.d.ts +10 -0
  480. package/packages/types/audio/Spatial.d.ts +63 -0
  481. package/packages/types/audio/StreamVoice.d.ts +31 -0
  482. package/packages/types/browser.d.ts +44 -0
  483. package/packages/types/csg/Bsp.d.ts +85 -0
  484. package/packages/types/csg/index.d.ts +81 -0
  485. package/packages/types/demo/BenchmarkEngine.d.ts +61 -0
  486. package/packages/types/demo/PixelCalibrationEngine.d.ts +13 -0
  487. package/packages/types/demo/ProceduralStarter.d.ts +11 -0
  488. package/packages/types/demo/StaticAssetPipeline.d.ts +87 -0
  489. package/packages/types/demo/UnityBridgePipeline.d.ts +49 -0
  490. package/packages/types/demo/index.d.ts +7 -0
  491. package/packages/types/editor-preview.d.ts +27 -0
  492. package/packages/types/effects/Effect2D.d.ts +65 -0
  493. package/packages/types/effects/Effect3D.d.ts +42 -0
  494. package/packages/types/effects/EffectBudget.d.ts +179 -0
  495. package/packages/types/effects/EffectDirector.d.ts +68 -0
  496. package/packages/types/effects/EffectPresets.d.ts +27 -0
  497. package/packages/types/effects/EffectPresets2D.d.ts +32 -0
  498. package/packages/types/effects/EffectSprites.d.ts +23 -0
  499. package/packages/types/effects/ParticleEventLink.d.ts +16 -0
  500. package/packages/types/effects/VfxMaterial.d.ts +52 -0
  501. package/packages/types/film/BakeKey.d.ts +9 -0
  502. package/packages/types/film/ColorValues.d.ts +25 -0
  503. package/packages/types/film/FilmLint.d.ts +40 -0
  504. package/packages/types/film/FilmPrefab.d.ts +22 -0
  505. package/packages/types/film/FilmReview.d.ts +27 -0
  506. package/packages/types/film/FilmScene.d.ts +1214 -0
  507. package/packages/types/film/FilmStage.d.ts +237 -0
  508. package/packages/types/film/Flythrough.d.ts +44 -0
  509. package/packages/types/film/FlythroughReport.d.ts +132 -0
  510. package/packages/types/film/FrameMetrics.d.ts +49 -0
  511. package/packages/types/film/LiveLook.d.ts +60 -0
  512. package/packages/types/film/LookQuality.d.ts +24 -0
  513. package/packages/types/film/Projection.d.ts +20 -0
  514. package/packages/types/film/SceneLook.d.ts +122 -0
  515. package/packages/types/film/index.d.ts +13 -0
  516. package/packages/types/index.d.ts +49 -0
  517. package/packages/types/particles/EffectEnvelope.d.ts +18 -0
  518. package/packages/types/particles/LayaParticleRenderer.d.ts +30 -0
  519. package/packages/types/particles/LayaParticleRenderer3D.d.ts +29 -0
  520. package/packages/types/particles/ParticleExtras.d.ts +50 -0
  521. package/packages/types/particles/ParticleMesh3D.d.ts +24 -0
  522. package/packages/types/particles/ParticleSystem.d.ts +52 -0
  523. package/packages/types/particles/ParticleSystem3D.d.ts +69 -0
  524. package/packages/types/particles/ParticleTypes.d.ts +89 -0
  525. package/packages/types/particles/ParticleTypes3D.d.ts +56 -0
  526. package/packages/types/particles/RibbonPath3D.d.ts +32 -0
  527. package/packages/types/particles/RibbonTrail.d.ts +38 -0
  528. package/packages/types/particles/RibbonTrail3D.d.ts +22 -0
  529. package/packages/types/particles/index.d.ts +13 -0
  530. package/packages/types/prefabs/PrefabLibrary.d.ts +176 -0
  531. package/packages/types/prefabs/PrefabTree3D.d.ts +59 -0
  532. package/packages/types/prefabs/index.d.ts +4 -0
  533. package/packages/types/procedural/Geometry.d.ts +252 -0
  534. package/packages/types/procedural/Hand.d.ts +150 -0
  535. package/packages/types/procedural/Isosurface.d.ts +181 -0
  536. package/packages/types/procedural/ModuleHarness.d.ts +90 -0
  537. package/packages/types/procedural/Noise.d.ts +15 -0
  538. package/packages/types/procedural/PhotoMaterial.d.ts +49 -0
  539. package/packages/types/procedural/ProceduralAssetProvider.d.ts +31 -0
  540. package/packages/types/procedural/ProceduralMaterial.d.ts +63 -0
  541. package/packages/types/procedural/PropFactory.d.ts +94 -0
  542. package/packages/types/procedural/Random.d.ts +26 -0
  543. package/packages/types/procedural/SynthAudio.d.ts +49 -0
  544. package/packages/types/procedural/TerrainMesh.d.ts +55 -0
  545. package/packages/types/procedural/TextureRecipe.d.ts +125 -0
  546. package/packages/types/procedural/TriplanarMaterial.d.ts +27 -0
  547. package/packages/types/procedural/Variation.d.ts +23 -0
  548. package/packages/types/procedural/index.d.ts +16 -0
  549. package/packages/types/runtime3d/ActionFrames.d.ts +62 -0
  550. package/packages/types/runtime3d/AnimationBlend.d.ts +57 -0
  551. package/packages/types/runtime3d/AnimationBlendMath.d.ts +27 -0
  552. package/packages/types/runtime3d/AssetProvider.d.ts +167 -0
  553. package/packages/types/runtime3d/AssetShowcase.d.ts +44 -0
  554. package/packages/types/runtime3d/Assets.d.ts +166 -0
  555. package/packages/types/runtime3d/AsyncDeadline.d.ts +6 -0
  556. package/packages/types/runtime3d/AsyncOperation.d.ts +3 -0
  557. package/packages/types/runtime3d/BackendChoice.d.ts +130 -0
  558. package/packages/types/runtime3d/BakedCrowd.d.ts +156 -0
  559. package/packages/types/runtime3d/BasisTexture.d.ts +169 -0
  560. package/packages/types/runtime3d/CameraCollision.d.ts +20 -0
  561. package/packages/types/runtime3d/CameraEffects.d.ts +134 -0
  562. package/packages/types/runtime3d/CameraRig.d.ts +27 -0
  563. package/packages/types/runtime3d/CharacterController.d.ts +71 -0
  564. package/packages/types/runtime3d/CinematicCapture.d.ts +103 -0
  565. package/packages/types/runtime3d/Clocks.d.ts +200 -0
  566. package/packages/types/runtime3d/Cloth.d.ts +57 -0
  567. package/packages/types/runtime3d/Clouds.d.ts +69 -0
  568. package/packages/types/runtime3d/ColorLut.d.ts +73 -0
  569. package/packages/types/runtime3d/CombatQueries.d.ts +50 -0
  570. package/packages/types/runtime3d/ComputePass.d.ts +134 -0
  571. package/packages/types/runtime3d/CrowdPresentation.d.ts +104 -0
  572. package/packages/types/runtime3d/DebugDraw.d.ts +161 -0
  573. package/packages/types/runtime3d/DebugStats.d.ts +24 -0
  574. package/packages/types/runtime3d/Decals.d.ts +65 -0
  575. package/packages/types/runtime3d/DensityVolume.d.ts +39 -0
  576. package/packages/types/runtime3d/DistanceBricks.d.ts +97 -0
  577. package/packages/types/runtime3d/Dither.d.ts +78 -0
  578. package/packages/types/runtime3d/DrawWarmUp.d.ts +93 -0
  579. package/packages/types/runtime3d/EdgeSmoothing.d.ts +10 -0
  580. package/packages/types/runtime3d/EnvironmentProbe.d.ts +139 -0
  581. package/packages/types/runtime3d/Filmic.d.ts +243 -0
  582. package/packages/types/runtime3d/Foliage.d.ts +95 -0
  583. package/packages/types/runtime3d/GltfIntake.d.ts +236 -0
  584. package/packages/types/runtime3d/GltfSecondUv.d.ts +54 -0
  585. package/packages/types/runtime3d/GraphicsGuard.d.ts +18 -0
  586. package/packages/types/runtime3d/Grass.d.ts +226 -0
  587. package/packages/types/runtime3d/GroundTruthAO.d.ts +64 -0
  588. package/packages/types/runtime3d/HalfFloat.d.ts +13 -0
  589. package/packages/types/runtime3d/HdrEnvironment.d.ts +144 -0
  590. package/packages/types/runtime3d/Ik.d.ts +123 -0
  591. package/packages/types/runtime3d/InputBuffer.d.ts +49 -0
  592. package/packages/types/runtime3d/InstancedMesh.d.ts +116 -0
  593. package/packages/types/runtime3d/Laya342Adapters.d.ts +306 -0
  594. package/packages/types/runtime3d/Laya342GltfAdapter.d.ts +105 -0
  595. package/packages/types/runtime3d/LensFinish.d.ts +38 -0
  596. package/packages/types/runtime3d/LensFlare.d.ts +114 -0
  597. package/packages/types/runtime3d/LightFog.d.ts +190 -0
  598. package/packages/types/runtime3d/LightingDepth.d.ts +128 -0
  599. package/packages/types/runtime3d/Lightmap.d.ts +55 -0
  600. package/packages/types/runtime3d/Math3D.d.ts +19 -0
  601. package/packages/types/runtime3d/MeshQuery.d.ts +107 -0
  602. package/packages/types/runtime3d/MeshoptModelDecoder.d.ts +34 -0
  603. package/packages/types/runtime3d/MiniGameSplash.d.ts +4 -0
  604. package/packages/types/runtime3d/ModelAnimationSampler.d.ts +26 -0
  605. package/packages/types/runtime3d/ModelCompatibility.d.ts +169 -0
  606. package/packages/types/runtime3d/ModelDecoder.d.ts +66 -0
  607. package/packages/types/runtime3d/ModelInspector.d.ts +77 -0
  608. package/packages/types/runtime3d/ModelLod.d.ts +61 -0
  609. package/packages/types/runtime3d/ModelPlacements.d.ts +77 -0
  610. package/packages/types/runtime3d/ObjectMotion.d.ts +43 -0
  611. package/packages/types/runtime3d/PhysicalCamera.d.ts +51 -0
  612. package/packages/types/runtime3d/PointShadow.d.ts +71 -0
  613. package/packages/types/runtime3d/PointShadowSchedule.d.ts +74 -0
  614. package/packages/types/runtime3d/Pool.d.ts +33 -0
  615. package/packages/types/runtime3d/ProbeVolume.d.ts +123 -0
  616. package/packages/types/runtime3d/QualityGovernor.d.ts +201 -0
  617. package/packages/types/runtime3d/QualityMemory.d.ts +83 -0
  618. package/packages/types/runtime3d/RenderScale.d.ts +69 -0
  619. package/packages/types/runtime3d/RenderSpaces.d.ts +44 -0
  620. package/packages/types/runtime3d/Renderer.d.ts +62 -0
  621. package/packages/types/runtime3d/ResultPlayback.d.ts +70 -0
  622. package/packages/types/runtime3d/Runtime.d.ts +136 -0
  623. package/packages/types/runtime3d/RuntimeDriver.d.ts +42 -0
  624. package/packages/types/runtime3d/SceneLifecycle.d.ts +84 -0
  625. package/packages/types/runtime3d/SceneMutation.d.ts +34 -0
  626. package/packages/types/runtime3d/SceneQueries.d.ts +71 -0
  627. package/packages/types/runtime3d/ScreenReflections.d.ts +78 -0
  628. package/packages/types/runtime3d/SelectionOutline.d.ts +68 -0
  629. package/packages/types/runtime3d/ShaderErrors.d.ts +27 -0
  630. package/packages/types/runtime3d/ShaderRegistry.d.ts +10 -0
  631. package/packages/types/runtime3d/ShaderWarmUp.d.ts +162 -0
  632. package/packages/types/runtime3d/ShadowUpdates.d.ts +125 -0
  633. package/packages/types/runtime3d/SkinBinding.d.ts +53 -0
  634. package/packages/types/runtime3d/Smaa.d.ts +60 -0
  635. package/packages/types/runtime3d/SmaaTables.d.ts +12 -0
  636. package/packages/types/runtime3d/SpringBones.d.ts +69 -0
  637. package/packages/types/runtime3d/SurfaceBuffer.d.ts +28 -0
  638. package/packages/types/runtime3d/Surfaces.d.ts +326 -0
  639. package/packages/types/runtime3d/Themes.d.ts +70 -0
  640. package/packages/types/runtime3d/Timeline.d.ts +88 -0
  641. package/packages/types/runtime3d/ToneCurves.d.ts +59 -0
  642. package/packages/types/runtime3d/TransformGizmo.d.ts +139 -0
  643. package/packages/types/runtime3d/TriangleMask.d.ts +84 -0
  644. package/packages/types/runtime3d/Underwater.d.ts +120 -0
  645. package/packages/types/runtime3d/Utf8.d.ts +12 -0
  646. package/packages/types/runtime3d/Vrm.d.ts +120 -0
  647. package/packages/types/runtime3d/VrmDocument.d.ts +381 -0
  648. package/packages/types/runtime3d/WalkGrid.d.ts +94 -0
  649. package/packages/types/runtime3d/WebGPU342Adapters.d.ts +27 -0
  650. package/packages/types/runtime3d/index.d.ts +102 -0
  651. package/packages/types/shaders/Laya342ShaderTemplates.d.ts +3 -0
  652. package/packages/types/shaders/LitSurfaceMaterial.d.ts +257 -0
  653. package/packages/types/shaders/LitSurfaceTemplates.d.ts +7 -0
  654. package/packages/types/shaders/ReflectiveSurface.d.ts +58 -0
  655. package/packages/types/shaders/ShaderMaterials.d.ts +60 -0
  656. package/packages/types/shaders/ToonMaterial.d.ts +176 -0
  657. package/packages/types/shaders/WaterRipples.d.ts +48 -0
  658. package/packages/types/shaders/WaterSurface.d.ts +110 -0
  659. package/packages/types/shaders/ZhudaCommon.d.ts +31 -0
  660. package/packages/types/shaders/index.d.ts +7 -0
  661. package/packages/types/simulation/Cloth.d.ts +381 -0
  662. package/packages/types/simulation/ParticleCore.d.ts +125 -0
  663. package/packages/types/simulation/SpringBones.d.ts +107 -0
  664. package/packages/types/simulation/index.d.ts +4 -0
  665. package/packages/types/terrain/Heightfield.d.ts +67 -0
  666. package/packages/types/terrain/Terrain2D.d.ts +81 -0
  667. package/packages/types/terrain/Terrain3D.d.ts +80 -0
  668. package/packages/types/terrain/TerrainShell.d.ts +8 -0
  669. package/packages/types/terrain/index.d.ts +4 -0
  670. package/packages/types/vendor/LayaAir.runtime.d.ts +97440 -0
  671. package/packages/types/vendor/REPAIRS.md +30 -0
  672. package/packages/types/vendor/restored-3.4.2.json +142 -0
  673. package/packages/types/vendor/spine.runtime.d.ts +1507 -0
  674. package/packages/types/vendor/wechat-media.d.ts +877 -0
  675. package/packages/types/zhuda-2d-ui.d.ts +244 -0
  676. package/packages/types/zhuda-3d-physics.d.ts +34 -0
  677. package/packages/types/zhuda-audio.d.ts +128 -0
  678. package/packages/types/zhuda-bootstrap.d.ts +100 -0
  679. package/packages/types/zhuda-branding.d.ts +6 -0
  680. package/packages/types/zhuda-core.d.ts +46 -0
  681. package/packages/types/zhuda-declarative.d.ts +81 -0
  682. package/packages/types/zhuda-effects.d.ts +302 -0
  683. package/packages/types/zhuda-layout.d.ts +96 -0
  684. package/packages/types/zhuda-particles.d.ts +477 -0
  685. package/packages/types/zhuda-spine42.d.ts +23 -0
  686. package/packages/types/zhuda-static-assets.d.ts +389 -0
  687. package/packages/types/zhuda-video.d.ts +24 -0
  688. package/packages/types/zhuda-visual-contract.d.ts +52 -0
  689. package/packages/types/zhuda-webview.d.ts +43 -0
  690. package/vendor/basis/LICENSE.txt +55 -0
  691. package/vendor/basis/README.md +25 -0
  692. package/vendor/basis/basis_transcoder.js +19 -0
  693. package/vendor/basis/basis_transcoder.wasm +0 -0
  694. package/vendor/laya-3.4.2/WEBGPU-LICENSES.txt +1259 -0
  695. package/vendor/laya-3.4.2/libs/laya.ani.js +1 -0
  696. package/vendor/laya-3.4.2/libs/laya.box2D.js +1209 -0
  697. package/vendor/laya-3.4.2/libs/laya.bridge.js +2273 -0
  698. package/vendor/laya-3.4.2/libs/laya.bullet.js +1 -0
  699. package/vendor/laya-3.4.2/libs/laya.core.js +1 -0
  700. package/vendor/laya-3.4.2/libs/laya.d3.js +1 -0
  701. package/vendor/laya-3.4.2/libs/laya.device.js +1 -0
  702. package/vendor/laya-3.4.2/libs/laya.gltf.js +1 -0
  703. package/vendor/laya-3.4.2/libs/laya.ik.js +1 -0
  704. package/vendor/laya-3.4.2/libs/laya.light2D.js +1 -0
  705. package/vendor/laya-3.4.2/libs/laya.line2D.js +1 -0
  706. package/vendor/laya-3.4.2/libs/laya.native-spine42.js +7672 -0
  707. package/vendor/laya-3.4.2/libs/laya.navMesh2d.js +1 -0
  708. package/vendor/laya-3.4.2/libs/laya.navMesh3d.js +1 -0
  709. package/vendor/laya-3.4.2/libs/laya.navMeshCommon.js +1 -0
  710. package/vendor/laya-3.4.2/libs/laya.particle.js +1 -0
  711. package/vendor/laya-3.4.2/libs/laya.particle3D.js +1 -0
  712. package/vendor/laya-3.4.2/libs/laya.particleCommon.js +1 -0
  713. package/vendor/laya-3.4.2/libs/laya.physics2D.js +3774 -0
  714. package/vendor/laya-3.4.2/libs/laya.physics3D.js +1 -0
  715. package/vendor/laya-3.4.2/libs/laya.postProcess.js +1 -0
  716. package/vendor/laya-3.4.2/libs/laya.spine.js +1 -0
  717. package/vendor/laya-3.4.2/libs/laya.spine3D.js +1 -0
  718. package/vendor/laya-3.4.2/libs/laya.tilemap.js +1 -0
  719. package/vendor/laya-3.4.2/libs/laya.trail2D.js +1 -0
  720. package/vendor/laya-3.4.2/libs/laya.trail3D.js +1 -0
  721. package/vendor/laya-3.4.2/libs/laya.trailCommon.js +1 -0
  722. package/vendor/laya-3.4.2/libs/laya.ui.js +1 -0
  723. package/vendor/laya-3.4.2/libs/laya.ui2.js +9904 -0
  724. package/vendor/laya-3.4.2/libs/laya.vfx.js +6754 -0
  725. package/vendor/laya-3.4.2/libs/laya.webgl_2D.js +1 -0
  726. package/vendor/laya-3.4.2/libs/laya.webgl_3D.js +1 -0
  727. package/vendor/laya-3.4.2/libs/laya.webgpu_2D.js +18576 -0
  728. package/vendor/laya-3.4.2/libs/laya.webgpu_3D.js +6729 -0
  729. package/vendor/laya-3.4.2/libs/nagabind.js +395 -0
  730. package/vendor/laya-3.4.2/libs/nagabind_bg.wasm +0 -0
  731. package/vendor/laya-3.4.2/libs/shader_compiler_web.js +22 -0
  732. package/vendor/laya-3.4.2/libs/shader_compiler_web.wasm +0 -0
  733. package/vendor/laya-3.4.2/libs/spine-core-3.8.js +1 -0
  734. package/vendor/laya-3.4.2/libs/spine-core-4.2.js +10216 -0
  735. package/vendor/laya-3.4.2/webgpu-provenance.json +41 -0
  736. package/vendor/meshoptimizer/LICENSE.txt +21 -0
  737. package/vendor/meshoptimizer/README.md +13 -0
  738. package/vendor/threejs-post/LICENSE.txt +53 -0
  739. package/vendor/threejs-post/README.md +54 -0
  740. package/zhuda.config.json +22 -0
@@ -0,0 +1,1035 @@
1
+ /**
2
+ * Shapes as signed distances, joined smoothly, and turned into a mesh.
3
+ *
4
+ * A body made of soft parts (a hand, a face, a stone) is easier to write as
5
+ * distances than as faces: each part is a round cone or an ellipsoid, the
6
+ * parts are joined with a smooth minimum (the joint is a fillet, not a seam),
7
+ * and the mesher finds the surface. Pure data, as the rest of `procedural/`:
8
+ * the result is the engine's `MeshData` and nothing here touches Laya.
9
+ *
10
+ * Conventions: metres; a distance is negative inside; the triangles wind as
11
+ * the geometry kit's (cross(v1 - v0, v2 - v0) points into the body).
12
+ */
13
+ import type { MeshData } from '../runtime3d/Surfaces.ts';
14
+ import type { ZhudaVec3 } from './Geometry.ts';
15
+
16
+ /** Squeezes a shape along one direction: 1 keeps it, 0.8 makes it 0.8 as thick that way. */
17
+ export interface ZhudaSdfFlatten {
18
+ axis: ZhudaVec3;
19
+ factor: number;
20
+ }
21
+
22
+ interface ZhudaSdfShapeBase {
23
+ /** How wide the fillet is where this shape meets what came before it, in metres (0: a crease). */
24
+ blend?: number;
25
+ /** Cut this shape out of what came before it (with the same fillet) instead of adding it. */
26
+ subtract?: boolean;
27
+ flatten?: ZhudaSdfFlatten;
28
+ /**
29
+ * Keep only the part of the shape on one side of a plane: where `dot(p, normal)` is at most
30
+ * `offset`. For a large shape whose far side would stand out of the body (a pad set deep
31
+ * so its face curves gently); the cut face should lie inside the body.
32
+ */
33
+ keep?: { normal: ZhudaVec3; offset: number };
34
+ }
35
+ /** A cone between two balls: radius `ra` at `a`, `rb` at `b`. Equal radii make a capsule. */
36
+ export interface ZhudaSdfRoundCone extends ZhudaSdfShapeBase {
37
+ kind: 'roundCone';
38
+ a: ZhudaVec3;
39
+ b: ZhudaVec3;
40
+ ra: number;
41
+ rb: number;
42
+ }
43
+ /** An ellipsoid with half-axes `radii` along `axes` (default the world's x, y, z). */
44
+ export interface ZhudaSdfEllipsoid extends ZhudaSdfShapeBase {
45
+ kind: 'ellipsoid';
46
+ center: ZhudaVec3;
47
+ radii: ZhudaVec3;
48
+ /** Three unit vectors, square to each other. */
49
+ axes?: [ZhudaVec3, ZhudaVec3, ZhudaVec3];
50
+ }
51
+ export type ZhudaSdfShape = ZhudaSdfRoundCone | ZhudaSdfEllipsoid;
52
+
53
+ export interface ZhudaSdfField {
54
+ /** The distance at a point: negative inside. Never more than the true distance by much, so a mesher may step by it. */
55
+ distance(x: number, y: number, z: number): number;
56
+ /** A box that holds the whole body. */
57
+ bounds: { min: ZhudaVec3; max: ZhudaVec3 };
58
+ /** Which shape is nearest the point (the index in the list given), for colouring by part. */
59
+ nearest(x: number, y: number, z: number): number;
60
+ }
61
+
62
+ const finite = (value: unknown) => typeof value === 'number' && Number.isFinite(value);
63
+ const isVec = (value: unknown): value is ZhudaVec3 =>
64
+ Array.isArray(value) && value.length === 3 && value.every((n) => finite(n));
65
+ const vlen = (v: readonly number[]) => Math.hypot(v[0], v[1], v[2]);
66
+ const len = (x: number, y: number, z: number) => Math.sqrt(x * x + y * y + z * z);
67
+
68
+ /** What is wrong with a list of shapes; empty when it can be built. */
69
+ export function validateZhudaSdfShapes(shapes: readonly ZhudaSdfShape[]): string[] {
70
+ const errors: string[] = [];
71
+ if (!Array.isArray(shapes) || shapes.length === 0)
72
+ return ['shapes must be a list of at least one shape'];
73
+ shapes.forEach((shape, i) => {
74
+ const at = `shapes[${i}]`;
75
+ if (!shape || typeof shape !== 'object') return void errors.push(`${at} must be a shape`);
76
+ if (shape.blend !== undefined && !(finite(shape.blend) && shape.blend >= 0))
77
+ errors.push(`${at}.blend must be a number of metres, 0 or more`);
78
+ if (shape.subtract && i === 0) errors.push(`${at}.subtract cannot cut the first shape`);
79
+ if (shape.flatten !== undefined) {
80
+ const f = shape.flatten;
81
+ if (!f || !isVec(f.axis) || !(vlen(f.axis) > 1e-9))
82
+ errors.push(`${at}.flatten.axis must be three numbers, not all 0`);
83
+ if (!f || !(finite(f.factor) && f.factor > 0 && f.factor <= 1))
84
+ errors.push(`${at}.flatten.factor must be more than 0 and at most 1`);
85
+ }
86
+ if (shape.keep !== undefined) {
87
+ const k = shape.keep;
88
+ if (!k || !isVec(k.normal) || !(vlen(k.normal) > 1e-9))
89
+ errors.push(`${at}.keep.normal must be three numbers, not all 0`);
90
+ if (!k || !finite(k.offset)) errors.push(`${at}.keep.offset must be a number of metres`);
91
+ }
92
+ if (shape.kind === 'roundCone') {
93
+ if (!isVec(shape.a) || !isVec(shape.b)) errors.push(`${at}.a and .b must be three numbers`);
94
+ if (!(finite(shape.ra) && shape.ra > 0) || !(finite(shape.rb) && shape.rb > 0))
95
+ errors.push(`${at}.ra and .rb must be positive numbers`);
96
+ } else if (shape.kind === 'ellipsoid') {
97
+ if (!isVec(shape.center)) errors.push(`${at}.center must be three numbers`);
98
+ if (!isVec(shape.radii) || !shape.radii.every((r: number) => r > 0))
99
+ errors.push(`${at}.radii must be three positive numbers`);
100
+ if (shape.axes !== undefined) {
101
+ const axes = shape.axes;
102
+ if (!Array.isArray(axes) || axes.length !== 3 || !axes.every(isVec))
103
+ errors.push(`${at}.axes must be three vectors`);
104
+ else {
105
+ for (let k = 0; k < 3; k++) {
106
+ if (Math.abs(vlen(axes[k]) - 1) > 1e-3) errors.push(`${at}.axes[${k}] must be unit`);
107
+ const o = axes[(k + 1) % 3];
108
+ const d = axes[k][0] * o[0] + axes[k][1] * o[1] + axes[k][2] * o[2];
109
+ if (Math.abs(d) > 1e-3) errors.push(`${at}.axes must be square to each other`);
110
+ }
111
+ }
112
+ }
113
+ } else errors.push(`${at}.kind must be 'roundCone' or 'ellipsoid'`);
114
+ });
115
+ return [...new Set(errors)];
116
+ }
117
+
118
+ /** The polynomial smooth minimum: the two distances joined with a fillet `k` wide. */
119
+ export function zhudaSmoothMin(a: number, b: number, k: number): number {
120
+ if (!(k > 0)) return Math.min(a, b);
121
+ const h = Math.max(k - Math.abs(a - b), 0) / k;
122
+ return Math.min(a, b) - h * h * k * 0.25;
123
+ }
124
+
125
+ type Compiled = {
126
+ blend: number;
127
+ subtract: boolean;
128
+ /** The box, before the fillet. */
129
+ lo: ZhudaVec3;
130
+ hi: ZhudaVec3;
131
+ /** How much the flatten shortens a distance at most (the factor, or 1). */
132
+ shrink: number;
133
+ distance: (x: number, y: number, z: number) => number;
134
+ };
135
+
136
+ function roundCone(s: ZhudaSdfRoundCone): (x: number, y: number, z: number) => number {
137
+ // Inigo Quilez's exact round cone (MIT), written out for numbers.
138
+ const [ax, ay, az] = s.a,
139
+ bx = s.b[0] - ax,
140
+ by = s.b[1] - ay,
141
+ bz = s.b[2] - az;
142
+ const r1 = s.ra,
143
+ r2 = s.rb;
144
+ const l2 = bx * bx + by * by + bz * bz;
145
+ const rr = r1 - r2;
146
+ const a2 = l2 - rr * rr;
147
+ const il2 = l2 > 0 ? 1 / l2 : 0;
148
+ if (l2 < 1e-14 || a2 <= 1e-14) {
149
+ // One ball holds the other: the bigger ball.
150
+ const big = r1 >= r2 ? s.a : s.b,
151
+ r = Math.max(r1, r2);
152
+ return (x, y, z) => len(x - big[0], y - big[1], z - big[2]) - r;
153
+ }
154
+ return (x, y, z) => {
155
+ const px = x - ax,
156
+ py = y - ay,
157
+ pz = z - az;
158
+ const yy = px * bx + py * by + pz * bz;
159
+ const zz = yy - l2;
160
+ const qx = px * l2 - bx * yy,
161
+ qy = py * l2 - by * yy,
162
+ qz = pz * l2 - bz * yy;
163
+ const x2 = qx * qx + qy * qy + qz * qz;
164
+ const y2 = yy * yy * l2;
165
+ const z2 = zz * zz * l2;
166
+ const k = Math.sign(rr) * rr * rr * x2;
167
+ if (Math.sign(zz) * a2 * z2 > k) return Math.sqrt(x2 + z2) * il2 - r2;
168
+ if (Math.sign(yy) * a2 * y2 < k) return Math.sqrt(x2 + y2) * il2 - r1;
169
+ return (Math.sqrt(x2 * a2 * il2) + yy * rr) * il2 - r1;
170
+ };
171
+ }
172
+
173
+ function ellipsoid(s: ZhudaSdfEllipsoid): (x: number, y: number, z: number) => number {
174
+ // Inigo Quilez's bound for an ellipsoid (MIT): close to the surface, never far over.
175
+ const [cx, cy, cz] = s.center;
176
+ const [rx, ry, rz] = s.radii;
177
+ const axes = s.axes ?? [
178
+ [1, 0, 0],
179
+ [0, 1, 0],
180
+ [0, 0, 1],
181
+ ];
182
+ const [u, v, w] = axes;
183
+ return (x, y, z) => {
184
+ const px = x - cx,
185
+ py = y - cy,
186
+ pz = z - cz;
187
+ const lx = px * u[0] + py * u[1] + pz * u[2],
188
+ ly = px * v[0] + py * v[1] + pz * v[2],
189
+ lz = px * w[0] + py * w[1] + pz * w[2];
190
+ const k0 = len(lx / rx, ly / ry, lz / rz);
191
+ const k1 = len(lx / (rx * rx), ly / (ry * ry), lz / (rz * rz));
192
+ if (k1 < 1e-12) return -Math.min(rx, ry, rz);
193
+ return (k0 * (k0 - 1)) / k1;
194
+ };
195
+ }
196
+
197
+ function compile(shape: ZhudaSdfShape): Compiled {
198
+ let base: (x: number, y: number, z: number) => number;
199
+ let lo: ZhudaVec3, hi: ZhudaVec3;
200
+ if (shape.kind === 'roundCone') {
201
+ base = roundCone(shape);
202
+ lo = [0, 1, 2].map((k) => Math.min(shape.a[k] - shape.ra, shape.b[k] - shape.rb)) as ZhudaVec3;
203
+ hi = [0, 1, 2].map((k) => Math.max(shape.a[k] + shape.ra, shape.b[k] + shape.rb)) as ZhudaVec3;
204
+ } else {
205
+ base = ellipsoid(shape);
206
+ const axes = shape.axes ?? [
207
+ [1, 0, 0],
208
+ [0, 1, 0],
209
+ [0, 0, 1],
210
+ ];
211
+ // The box of an oriented ellipsoid: along each world axis, the length of the radii there.
212
+ const ext = [0, 1, 2].map((k) =>
213
+ Math.sqrt(
214
+ (axes[0][k] * shape.radii[0]) ** 2 +
215
+ (axes[1][k] * shape.radii[1]) ** 2 +
216
+ (axes[2][k] * shape.radii[2]) ** 2,
217
+ ),
218
+ );
219
+ lo = [0, 1, 2].map((k) => shape.center[k] - ext[k]) as ZhudaVec3;
220
+ hi = [0, 1, 2].map((k) => shape.center[k] + ext[k]) as ZhudaVec3;
221
+ }
222
+ let distance = base;
223
+ let shrink = 1;
224
+ if (shape.flatten && shape.flatten.factor < 1) {
225
+ // Squeezed about the shape's own middle: a point is stretched away from it, the distance scaled back.
226
+ const n = shape.flatten.axis;
227
+ const nl = len(...n);
228
+ const ax = n[0] / nl,
229
+ ay = n[1] / nl,
230
+ az = n[2] / nl;
231
+ const f = shape.flatten.factor;
232
+ const stretch = 1 / f - 1;
233
+ // About the shape's own middle: a round cone's axis, an ellipsoid's centre. (The middle of
234
+ // its box is off the axis of a cone whose two radii differ, and two such cones in a line
235
+ // were squeezed about different planes and left a pit where they met.)
236
+ const o =
237
+ shape.kind === 'roundCone'
238
+ ? [0, 1, 2].map((k) => (shape.a[k] + shape.b[k]) / 2)
239
+ : [...shape.center];
240
+ distance = (x, y, z) => {
241
+ const along = (x - o[0]) * ax + (y - o[1]) * ay + (z - o[2]) * az;
242
+ return base(x + stretch * along * ax, y + stretch * along * ay, z + stretch * along * az) * f;
243
+ };
244
+ shrink = f;
245
+ }
246
+ if (shape.keep) {
247
+ // Cut by the plane: the larger of the two distances (an intersection).
248
+ const n = shape.keep.normal;
249
+ const nl = vlen(n);
250
+ const kx = n[0] / nl,
251
+ ky = n[1] / nl,
252
+ kz = n[2] / nl,
253
+ off = shape.keep.offset;
254
+ const whole = distance;
255
+ distance = (x, y, z) => Math.max(whole(x, y, z), x * kx + y * ky + z * kz - off);
256
+ }
257
+ // Never less than the distance to the shape's box: the ellipsoid's distance is an estimate
258
+ // that can fall below it far from the shape, and a broad phase that skips by the box would
259
+ // then change the field where it starts skipping (a step in the surface).
260
+ const exact = distance;
261
+ const guarded = (x: number, y: number, z: number) => {
262
+ const e = exact(x, y, z);
263
+ if (e <= 0) return e;
264
+ const dx = Math.max(lo[0] - x, 0, x - hi[0]),
265
+ dy = Math.max(lo[1] - y, 0, y - hi[1]),
266
+ dz = Math.max(lo[2] - z, 0, z - hi[2]);
267
+ return Math.max(e, len(dx, dy, dz) * shrink);
268
+ };
269
+ return { blend: shape.blend ?? 0, subtract: !!shape.subtract, lo, hi, shrink, distance: guarded };
270
+ }
271
+
272
+ /** The shapes, in order, as one field. Throws with every problem `validateZhudaSdfShapes` finds. */
273
+ export function createZhudaSdfField(shapes: readonly ZhudaSdfShape[]): ZhudaSdfField {
274
+ const errors = validateZhudaSdfShapes(shapes);
275
+ if (errors.length) throw Error(`Invalid signed distance shapes: ${errors.join('; ')}`);
276
+ const parts = shapes.map(compile);
277
+ const boxDistance = (p: Compiled, x: number, y: number, z: number) => {
278
+ const dx = Math.max(p.lo[0] - x, 0, x - p.hi[0]),
279
+ dy = Math.max(p.lo[1] - y, 0, y - p.hi[1]),
280
+ dz = Math.max(p.lo[2] - z, 0, z - p.hi[2]);
281
+ return len(dx, dy, dz) * p.shrink;
282
+ };
283
+ const distance = (x: number, y: number, z: number) => {
284
+ let d = Infinity;
285
+ for (const p of parts) {
286
+ if (p.subtract) {
287
+ // A cut only matters where it is near: outside its box and fillet it changes nothing.
288
+ const box = boxDistance(p, x, y, z);
289
+ if (box > 0 && box >= p.blend + Math.abs(d)) continue;
290
+ d = -zhudaSmoothMin(-d, p.distance(x, y, z), p.blend);
291
+ continue;
292
+ }
293
+ // Broad phase: a shape whose box is farther than what is already here plus its fillet
294
+ // changes nothing. Only outside the box: inside it the shape's distance can be below 0,
295
+ // the box's is 0, and a shape that overlaps the body would be skipped.
296
+ if (d !== Infinity) {
297
+ const box = boxDistance(p, x, y, z);
298
+ if (box > 0 && box >= d + p.blend) continue;
299
+ }
300
+ const e = p.distance(x, y, z);
301
+ d = d === Infinity ? e : zhudaSmoothMin(d, e, p.blend);
302
+ }
303
+ return d;
304
+ };
305
+ const nearest = (x: number, y: number, z: number) => {
306
+ let best = 0,
307
+ bestD = Infinity;
308
+ parts.forEach((p, i) => {
309
+ if (p.subtract) return;
310
+ const e = p.distance(x, y, z);
311
+ if (e < bestD) {
312
+ bestD = e;
313
+ best = i;
314
+ }
315
+ });
316
+ return best;
317
+ };
318
+ const min: ZhudaVec3 = [Infinity, Infinity, Infinity],
319
+ max: ZhudaVec3 = [-Infinity, -Infinity, -Infinity];
320
+ for (const p of parts) {
321
+ if (p.subtract) continue;
322
+ for (let k = 0; k < 3; k++) {
323
+ min[k] = Math.min(min[k], p.lo[k] - p.blend);
324
+ max[k] = Math.max(max[k], p.hi[k] + p.blend);
325
+ }
326
+ }
327
+ return { distance, nearest, bounds: { min, max } };
328
+ }
329
+
330
+ /**
331
+ * Values of a field on the grid `createZhudaIsosurfaceMesh` samples
332
+ * (`zhudaIsosurfaceGrid`), negative inside: what `computeZhudaDensityVolume`
333
+ * makes on the GPU or in JavaScript.
334
+ */
335
+ export interface ZhudaDensityVolume {
336
+ /** One value a grid point, x fastest, then y, then z. */
337
+ values: Float32Array;
338
+ /** Grid points along x, y and z. */
339
+ size: [number, number, number];
340
+ /** Where the first grid point is. */
341
+ origin: ZhudaVec3;
342
+ cellSize: number;
343
+ /** Where the values were computed. */
344
+ backend: 'webgpu' | 'cpu';
345
+ }
346
+
347
+ /** Which body `removeFloating` keeps: the one on the box's floor (default), the largest, or the one at a point. */
348
+ export type ZhudaIsosurfaceAnchor = 'floor' | 'largest' | ZhudaVec3;
349
+
350
+ export interface ZhudaIsosurfaceOptions {
351
+ /**
352
+ * The distance at a point, negative inside. A `ZhudaSdfField`'s `distance`
353
+ * serves. With `volume` it may be left out: the volume, interpolated, is
354
+ * then the field.
355
+ */
356
+ distance?: (x: number, y: number, z: number) => number;
357
+ /**
358
+ * The field's values on this box's grid, computed before (on the GPU,
359
+ * `computeZhudaDensityVolume`): the mesher reads them instead of sampling
360
+ * `distance`, which only moves the vertices onto the surface and gives
361
+ * their normals.
362
+ */
363
+ volume?: ZhudaDensityVolume;
364
+ /**
365
+ * Before meshing, what is inside but not connected (through neighbouring
366
+ * grid points) to the anchor becomes outside: loose specks of rock do not
367
+ * float. `true` anchors on the box's floor: the body that comes within a
368
+ * cell of `min`'s height. `'largest'` keeps the largest body; a point keeps
369
+ * the body at it.
370
+ */
371
+ removeFloating?: boolean | { anchor?: ZhudaIsosurfaceAnchor };
372
+ /** The box to search; the surface must not touch its sides. */
373
+ min: ZhudaVec3;
374
+ max: ZhudaVec3;
375
+ /** The size of a cell, in metres: the mesh's detail, and about the distance between its vertices. */
376
+ cellSize: number;
377
+ /** Steps that move each vertex onto the surface along the field's slope (default 3; 0 leaves them where the cells put them). */
378
+ project?: number;
379
+ /** Texture coordinates at a vertex (default its x and y, in metres). */
380
+ uv?: (p: ZhudaVec3, n: ZhudaVec3) => [number, number];
381
+ /** A colour at a vertex (four numbers); left out, the mesh has none. */
382
+ color?: (p: ZhudaVec3, n: ZhudaVec3) => [number, number, number, number];
383
+ /**
384
+ * Refuse past this many vertices (default 2 000 000). Past 65535 the indices are 32-bit:
385
+ * `splitZhudaMesh` cuts such a mesh into chunks a `ZhudaDynamicMesh` takes.
386
+ */
387
+ maxVertices?: number;
388
+ }
389
+
390
+ /** What is wrong with the options; empty when they can be used. */
391
+ export function validateZhudaIsosurface(options: ZhudaIsosurfaceOptions): string[] {
392
+ const errors: string[] = [];
393
+ if (!options || typeof options !== 'object') return ['options must be an object'];
394
+ if (options.volume === undefined && typeof options.distance !== 'function')
395
+ errors.push('distance must be a function');
396
+ if (options.distance !== undefined && typeof options.distance !== 'function')
397
+ errors.push('distance must be a function');
398
+ if (!isVec(options.min) || !isVec(options.max)) errors.push('min and max must be three numbers');
399
+ else if (!options.min.every((v, k) => v < options.max[k]))
400
+ errors.push('min must be below max on every axis');
401
+ if (!(finite(options.cellSize) && options.cellSize > 0))
402
+ errors.push('cellSize must be a positive number of metres');
403
+ else if (isVec(options.min) && isVec(options.max)) {
404
+ const cells = [0, 1, 2].map((k) =>
405
+ Math.ceil((options.max[k] - options.min[k]) / options.cellSize),
406
+ );
407
+ if (cells[0] * cells[1] * cells[2] > 64e6)
408
+ errors.push(
409
+ `cellSize ${options.cellSize} makes ${cells.join(' x ')} cells; more than 64 million`,
410
+ );
411
+ }
412
+ if (
413
+ options.project !== undefined &&
414
+ !(Number.isInteger(options.project) && options.project >= 0 && options.project <= 8)
415
+ )
416
+ errors.push('project must be a whole number from 0 to 8');
417
+ if (options.uv !== undefined && typeof options.uv !== 'function')
418
+ errors.push('uv must be a function');
419
+ if (options.color !== undefined && typeof options.color !== 'function')
420
+ errors.push('color must be a function');
421
+ if (
422
+ options.maxVertices !== undefined &&
423
+ !(Number.isInteger(options.maxVertices) && options.maxVertices >= 3)
424
+ )
425
+ errors.push('maxVertices must be a whole number, 3 or more');
426
+ const floating = options.removeFloating;
427
+ if (floating !== undefined && typeof floating !== 'boolean') {
428
+ const anchor = floating && typeof floating === 'object' ? floating.anchor : null;
429
+ if (anchor !== undefined && anchor !== 'floor' && anchor !== 'largest' && !isVec(anchor))
430
+ errors.push("removeFloating: true, or { anchor: 'floor', 'largest' or a point }");
431
+ }
432
+ if (options.volume !== undefined && !errors.length) {
433
+ const v = options.volume;
434
+ const grid = zhudaIsosurfaceGrid(options.min, options.max, options.cellSize);
435
+ if (
436
+ !v ||
437
+ !(v.values instanceof Float32Array) ||
438
+ !Array.isArray(v.size) ||
439
+ v.size.some((n, k) => n !== grid.size[k]) ||
440
+ !isVec(v.origin) ||
441
+ v.origin.some((o, k) => Math.abs(o - grid.origin[k]) > options.cellSize * 1e-6) ||
442
+ v.cellSize !== options.cellSize ||
443
+ v.values.length !== grid.size[0] * grid.size[1] * grid.size[2]
444
+ )
445
+ errors.push(
446
+ `volume does not cover this box's grid (${grid.size.join(' x ')} points from ${grid.origin.map((o) => +o.toFixed(6)).join(', ')}); make it with the same min, max and cellSize`,
447
+ );
448
+ }
449
+ return errors;
450
+ }
451
+
452
+ /**
453
+ * The grid `createZhudaIsosurfaceMesh` samples for a box: the box padded by
454
+ * two cells on every side, so a closed body never meets its edge; `size`
455
+ * grid points along each axis from `origin`, `cellSize` apart.
456
+ */
457
+ export function zhudaIsosurfaceGrid(
458
+ min: ZhudaVec3,
459
+ max: ZhudaVec3,
460
+ cellSize: number,
461
+ ): { origin: ZhudaVec3; size: [number, number, number] } {
462
+ const h = cellSize;
463
+ return {
464
+ origin: [min[0] - 2 * h, min[1] - 2 * h, min[2] - 2 * h],
465
+ size: [
466
+ Math.ceil((max[0] - min[0]) / h) + 5,
467
+ Math.ceil((max[1] - min[1]) / h) + 5,
468
+ Math.ceil((max[2] - min[2]) / h) + 5,
469
+ ],
470
+ };
471
+ }
472
+
473
+ /**
474
+ * A volume as a field: its values interpolated (trilinear) between grid
475
+ * points, and the nearest edge value beyond the grid.
476
+ */
477
+ export function zhudaVolumeDistance(
478
+ volume: ZhudaDensityVolume,
479
+ ): (x: number, y: number, z: number) => number {
480
+ const { values, size, origin, cellSize: h } = volume;
481
+ const [nx, ny, nz] = size;
482
+ const clamp = (v: number, n: number) => (v < 0 ? 0 : v > n - 1 ? n - 1 : v);
483
+ return (x, y, z) => {
484
+ const fx = clamp((x - origin[0]) / h, nx),
485
+ fy = clamp((y - origin[1]) / h, ny),
486
+ fz = clamp((z - origin[2]) / h, nz);
487
+ const x0 = Math.min(Math.floor(fx), nx - 2),
488
+ y0 = Math.min(Math.floor(fy), ny - 2),
489
+ z0 = Math.min(Math.floor(fz), nz - 2);
490
+ const tx = fx - x0,
491
+ ty = fy - y0,
492
+ tz = fz - z0;
493
+ const at = (i: number, j: number, k: number) => values[i + j * nx + k * nx * ny];
494
+ const lerp = (a: number, b: number, t: number) => a + (b - a) * t;
495
+ const c00 = lerp(at(x0, y0, z0), at(x0 + 1, y0, z0), tx),
496
+ c10 = lerp(at(x0, y0 + 1, z0), at(x0 + 1, y0 + 1, z0), tx),
497
+ c01 = lerp(at(x0, y0, z0 + 1), at(x0 + 1, y0, z0 + 1), tx),
498
+ c11 = lerp(at(x0, y0 + 1, z0 + 1), at(x0 + 1, y0 + 1, z0 + 1), tx);
499
+ return lerp(lerp(c00, c10, ty), lerp(c01, c11, ty), tz);
500
+ };
501
+ }
502
+
503
+ /**
504
+ * Keeps the inside grid points (value <= 0) connected, through the six
505
+ * neighbours of each, to the anchor's; every other inside point is set to
506
+ * `outside`. Returns how many bodies were removed. Grid points at or below
507
+ * the height `floorTop` anchor `'floor'`.
508
+ */
509
+ function keepConnected(
510
+ values: Float32Array,
511
+ size: readonly [number, number, number],
512
+ origin: ZhudaVec3,
513
+ h: number,
514
+ anchor: ZhudaIsosurfaceAnchor,
515
+ floorTop: number,
516
+ outside: number,
517
+ ): number {
518
+ const [nx, ny, nz] = size;
519
+ const total = nx * ny * nz;
520
+ const label = new Int32Array(total);
521
+ const queue = new Int32Array(total);
522
+ const sizes: number[] = [0];
523
+ // Label every body: 1, 2, 3, ... in the order they are met.
524
+ for (let start = 0; start < total; start++) {
525
+ if (label[start] || values[start] > 0) continue;
526
+ const id = sizes.length;
527
+ let head = 0,
528
+ tail = 0,
529
+ count = 0;
530
+ queue[tail++] = start;
531
+ label[start] = id;
532
+ while (head < tail) {
533
+ const i = queue[head++];
534
+ count++;
535
+ const x = i % nx,
536
+ y = Math.floor(i / nx) % ny,
537
+ z = Math.floor(i / (nx * ny));
538
+ const visit = (j: number) => {
539
+ if (!label[j] && values[j] <= 0) {
540
+ label[j] = id;
541
+ queue[tail++] = j;
542
+ }
543
+ };
544
+ if (x > 0) visit(i - 1);
545
+ if (x < nx - 1) visit(i + 1);
546
+ if (y > 0) visit(i - nx);
547
+ if (y < ny - 1) visit(i + nx);
548
+ if (z > 0) visit(i - nx * ny);
549
+ if (z < nz - 1) visit(i + nx * ny);
550
+ }
551
+ sizes.push(count);
552
+ }
553
+ const keep = new Set<number>();
554
+ if (anchor === 'largest') {
555
+ let best = 0;
556
+ for (let id = 1; id < sizes.length; id++) if (sizes[id] > sizes[best]) best = id;
557
+ if (best) keep.add(best);
558
+ } else if (anchor === 'floor') {
559
+ const layers = Math.floor((floorTop - origin[1]) / h + 1e-9);
560
+ for (let z = 0; z < nz; z++)
561
+ for (let y = 0; y <= Math.min(layers, ny - 1); y++)
562
+ for (let x = 0; x < nx; x++) {
563
+ const id = label[x + y * nx + z * nx * ny];
564
+ if (id) keep.add(id);
565
+ }
566
+ if (!keep.size)
567
+ throw Error(
568
+ "removeFloating: nothing is inside within a cell of the box's floor (min's height)",
569
+ );
570
+ } else {
571
+ // The inside grid point nearest the anchor, within two cells.
572
+ let best = -1,
573
+ bestD = Infinity;
574
+ const cx = Math.round((anchor[0] - origin[0]) / h),
575
+ cy = Math.round((anchor[1] - origin[1]) / h),
576
+ cz = Math.round((anchor[2] - origin[2]) / h);
577
+ for (let z = cz - 2; z <= cz + 2; z++)
578
+ for (let y = cy - 2; y <= cy + 2; y++)
579
+ for (let x = cx - 2; x <= cx + 2; x++) {
580
+ if (x < 0 || y < 0 || z < 0 || x >= nx || y >= ny || z >= nz) continue;
581
+ const i = x + y * nx + z * nx * ny;
582
+ if (!label[i]) continue;
583
+ const d =
584
+ (origin[0] + x * h - anchor[0]) ** 2 +
585
+ (origin[1] + y * h - anchor[1]) ** 2 +
586
+ (origin[2] + z * h - anchor[2]) ** 2;
587
+ if (d < bestD) ((bestD = d), (best = i));
588
+ }
589
+ if (best < 0)
590
+ throw Error('removeFloating: the anchor point is not inside the body (within two cells)');
591
+ keep.add(label[best]);
592
+ }
593
+ for (let i = 0; i < total; i++) if (label[i] && !keep.has(label[i])) values[i] = outside;
594
+ return sizes.length - 1 - keep.size;
595
+ }
596
+
597
+ /**
598
+ * The surface where the distance is 0, as a mesh, by surface nets: one vertex
599
+ * in each cell the surface passes through, moved onto the surface, and a
600
+ * quad across each edge of the grid that the surface cuts. The normals are
601
+ * the field's slope. A closed body inside the box gives a closed mesh.
602
+ */
603
+ export function createZhudaIsosurfaceMesh(options: ZhudaIsosurfaceOptions): MeshData {
604
+ const errors = validateZhudaIsosurface(options);
605
+ if (errors.length) throw Error(`Invalid isosurface: ${errors.join('; ')}`);
606
+ const { min, max, cellSize: h } = options;
607
+ const distance = options.distance ?? zhudaVolumeDistance(options.volume!);
608
+ const project = options.project ?? 3;
609
+ const maxVertices = options.maxVertices ?? 2_000_000;
610
+ // Grid points: n per axis, the box padded by two cells so the surface never meets its side.
611
+ const grid = zhudaIsosurfaceGrid(min, max, h);
612
+ const o = grid.origin;
613
+ const [nx, ny, nz] = grid.size;
614
+ const sx = 1,
615
+ sy = nx,
616
+ sz = nx * ny;
617
+ const values = options.volume ? options.volume.values.slice() : new Float32Array(nx * ny * nz);
618
+ // Blocks of 8 cells a side: where the distance at a block's middle is more than its half
619
+ // diagonal, the surface is not in it (the distance grows no faster than the way travelled)
620
+ // and its points all take that sign without being asked.
621
+ const B = 8;
622
+ const reach = Math.sqrt(3) * (B / 2) * h * 1.05;
623
+ if (!options.volume)
624
+ for (let bz = 0; bz < nz; bz += B)
625
+ for (let by = 0; by < ny; by += B)
626
+ for (let bx = 0; bx < nx; bx += B) {
627
+ const ex = Math.min(bx + B, nx),
628
+ ey = Math.min(by + B, ny),
629
+ ez = Math.min(bz + B, nz);
630
+ const mid = distance(
631
+ o[0] + ((bx + ex - 1) / 2) * h,
632
+ o[1] + ((by + ey - 1) / 2) * h,
633
+ o[2] + ((bz + ez - 1) / 2) * h,
634
+ );
635
+ const far = Math.abs(mid) > reach;
636
+ for (let z = bz; z < ez; z++)
637
+ for (let y = by; y < ey; y++)
638
+ for (let x = bx; x < ex; x++) {
639
+ values[x * sx + y * sy + z * sz] = far
640
+ ? mid
641
+ : distance(o[0] + x * h, o[1] + y * h, o[2] + z * h);
642
+ }
643
+ }
644
+ if (options.removeFloating) {
645
+ const anchor =
646
+ (typeof options.removeFloating === 'object' && options.removeFloating.anchor) || 'floor';
647
+ keepConnected(values, grid.size, o, h, anchor, min[1] + h, h);
648
+ }
649
+ for (const k of [0, nx - 1])
650
+ for (let z = 0; z < nz; z++)
651
+ for (let y = 0; y < ny; y++)
652
+ if (values[k + y * sy + z * sz] <= 0)
653
+ throw Error('The surface reaches the side of the box; give a larger min and max');
654
+ for (const k of [0, ny - 1])
655
+ for (let z = 0; z < nz; z++)
656
+ for (let x = 0; x < nx; x++)
657
+ if (values[x + k * sy + z * sz] <= 0)
658
+ throw Error('The surface reaches the side of the box; give a larger min and max');
659
+ for (const k of [0, nz - 1])
660
+ for (let y = 0; y < ny; y++)
661
+ for (let x = 0; x < nx; x++)
662
+ if (values[x + y * sy + k * sz] <= 0)
663
+ throw Error('The surface reaches the side of the box; give a larger min and max');
664
+
665
+ // The field's slope from four samples at the corners of a tetrahedron (Inigo Quilez's,
666
+ // MIT): the same direction as six samples along the axes, two fewer.
667
+ const ge = h * 0.25;
668
+ const gradient = (x: number, y: number, z: number): ZhudaVec3 => {
669
+ const a = distance(x + ge, y - ge, z - ge),
670
+ b = distance(x - ge, y - ge, z + ge),
671
+ c = distance(x - ge, y + ge, z - ge),
672
+ d = distance(x + ge, y + ge, z + ge);
673
+ return [a - b - c + d, -a - b + c + d, -a + b - c + d];
674
+ };
675
+ // One vertex in each cell the surface crosses (the cell's corner with the lowest index names it).
676
+ const cellVertex = new Int32Array((nx - 1) * (ny - 1) * nz).fill(-1);
677
+ const cellIndex = (x: number, y: number, z: number) => x + y * (nx - 1) + z * (nx - 1) * (ny - 1);
678
+ const positions: number[] = [];
679
+ const normals: number[] = [];
680
+ const CORNERS = [
681
+ [0, 0, 0],
682
+ [1, 0, 0],
683
+ [0, 1, 0],
684
+ [1, 1, 0],
685
+ [0, 0, 1],
686
+ [1, 0, 1],
687
+ [0, 1, 1],
688
+ [1, 1, 1],
689
+ ];
690
+ const EDGES = [
691
+ [0, 1],
692
+ [2, 3],
693
+ [4, 5],
694
+ [6, 7],
695
+ [0, 2],
696
+ [1, 3],
697
+ [4, 6],
698
+ [5, 7],
699
+ [0, 4],
700
+ [1, 5],
701
+ [2, 6],
702
+ [3, 7],
703
+ ];
704
+ const corner = new Float32Array(8);
705
+ for (let z = 0; z < nz - 1; z++)
706
+ for (let y = 0; y < ny - 1; y++)
707
+ for (let x = 0; x < nx - 1; x++) {
708
+ let inside = 0;
709
+ for (let c = 0; c < 8; c++) {
710
+ const [cx, cy, cz] = CORNERS[c];
711
+ corner[c] = values[(x + cx) * sx + (y + cy) * sy + (z + cz) * sz];
712
+ if (corner[c] <= 0) inside++;
713
+ }
714
+ if (inside === 0 || inside === 8) continue;
715
+ // The mean of where the surface crosses the cell's edges.
716
+ let px = 0,
717
+ py = 0,
718
+ pz = 0,
719
+ count = 0;
720
+ for (const [a, b] of EDGES) {
721
+ const va = corner[a],
722
+ vb = corner[b];
723
+ if (va <= 0 === vb <= 0) continue;
724
+ const t = va / (va - vb);
725
+ const A = CORNERS[a],
726
+ Bc = CORNERS[b];
727
+ px += A[0] + (Bc[0] - A[0]) * t;
728
+ py += A[1] + (Bc[1] - A[1]) * t;
729
+ pz += A[2] + (Bc[2] - A[2]) * t;
730
+ count++;
731
+ }
732
+ let p: ZhudaVec3 = [
733
+ o[0] + (x + px / count) * h,
734
+ o[1] + (y + py / count) * h,
735
+ o[2] + (z + pz / count) * h,
736
+ ];
737
+ const start = p;
738
+ // The last slope taken, and where: it serves as the normal when the vertex has not
739
+ // moved since by more than a fiftieth of a cell (its direction is then off by about a
740
+ // tenth of a degree on a body ten cells round).
741
+ let last: ZhudaVec3 | null = null;
742
+ let lastAt = p;
743
+ for (let i = 0; i < project; i++) {
744
+ const d = distance(...p);
745
+ // On the surface already: no step needed.
746
+ if (Math.abs(d) < h * 1e-5) break;
747
+ const g = gradient(...p);
748
+ last = g;
749
+ lastAt = p;
750
+ const gl2 = g[0] * g[0] + g[1] * g[1] + g[2] * g[2];
751
+ if (!(gl2 > 1e-20)) break;
752
+ // The four samples sum to 4 ge times the field's gradient.
753
+ const scale = (d * 4 * ge) / gl2;
754
+ const next: ZhudaVec3 = [p[0] - g[0] * scale, p[1] - g[1] * scale, p[2] - g[2] * scale];
755
+ // Never more than a cell from where the cell put it: keeps sharp places from folding.
756
+ if (len(next[0] - start[0], next[1] - start[1], next[2] - start[2]) > h) break;
757
+ p = next;
758
+ }
759
+ const g =
760
+ last && len(p[0] - lastAt[0], p[1] - lastAt[1], p[2] - lastAt[2]) < h * 0.02
761
+ ? last
762
+ : gradient(...p);
763
+ const gl = len(...g);
764
+ const n: ZhudaVec3 = gl > 1e-20 ? [g[0] / gl, g[1] / gl, g[2] / gl] : [0, 1, 0];
765
+ const index = positions.length / 3;
766
+ if (index >= maxVertices)
767
+ throw Error(
768
+ `The surface needs more than ${maxVertices} vertices at cellSize ${h}; give a larger cellSize or split the body`,
769
+ );
770
+ cellVertex[cellIndex(x, y, z)] = index;
771
+ positions.push(p[0], p[1], p[2]);
772
+ normals.push(n[0], n[1], n[2]);
773
+ }
774
+ // A quad across every grid edge the surface cuts, made of the four cells round that edge.
775
+ const indices: number[] = [];
776
+ const P = (i: number): ZhudaVec3 => [
777
+ positions[i * 3],
778
+ positions[i * 3 + 1],
779
+ positions[i * 3 + 2],
780
+ ];
781
+ const N = (i: number): ZhudaVec3 => [normals[i * 3], normals[i * 3 + 1], normals[i * 3 + 2]];
782
+ // The four cells round an edge go round it one way; `flip` turns them the other, so that
783
+ // every triangle winds into the body (the side of the edge whose point is inside).
784
+ const quad = (a: number, b: number, c: number, d: number, flip: boolean) => {
785
+ if (a < 0 || b < 0 || c < 0 || d < 0) return;
786
+ if (flip) [b, d] = [d, b];
787
+ const tri = (i: number, j: number, k: number) => indices.push(i, j, k);
788
+ // Split along the shorter diagonal: fewer slivers.
789
+ const pa = P(a),
790
+ pb = P(b),
791
+ pc = P(c),
792
+ pd = P(d);
793
+ const ac = len(pa[0] - pc[0], pa[1] - pc[1], pa[2] - pc[2]);
794
+ const bd = len(pb[0] - pd[0], pb[1] - pd[1], pb[2] - pd[2]);
795
+ if (ac <= bd) {
796
+ tri(a, b, c);
797
+ tri(a, c, d);
798
+ } else {
799
+ tri(a, b, d);
800
+ tri(b, c, d);
801
+ }
802
+ };
803
+ const cv = (x: number, y: number, z: number) => cellVertex[cellIndex(x, y, z)];
804
+ for (let z = 1; z < nz - 1; z++)
805
+ for (let y = 1; y < ny - 1; y++)
806
+ for (let x = 1; x < nx - 1; x++) {
807
+ const here = values[x * sx + y * sy + z * sz] <= 0;
808
+ // The edge along x from this point: the four cells round it share y-1..y, z-1..z, and
809
+ // go round +x in that order (round -y for the edge along y, round +z for z). The
810
+ // outside is toward +axis when this point is inside.
811
+ if (here !== values[(x + 1) * sx + y * sy + z * sz] <= 0)
812
+ quad(cv(x, y - 1, z - 1), cv(x, y, z - 1), cv(x, y, z), cv(x, y - 1, z), here);
813
+ if (here !== values[x * sx + (y + 1) * sy + z * sz] <= 0)
814
+ quad(cv(x - 1, y, z - 1), cv(x, y, z - 1), cv(x, y, z), cv(x - 1, y, z), !here);
815
+ if (here !== values[x * sx + y * sy + (z + 1) * sz] <= 0)
816
+ quad(cv(x - 1, y - 1, z), cv(x, y - 1, z), cv(x, y, z), cv(x - 1, y, z), here);
817
+ }
818
+ const count = positions.length / 3;
819
+ if (count < 3) throw Error('The field has no surface inside the box');
820
+ const uvs = new Float32Array(count * 2);
821
+ const colors = options.color ? new Float32Array(count * 4) : undefined;
822
+ for (let i = 0; i < count; i++) {
823
+ const p = P(i),
824
+ n = N(i);
825
+ const uv = options.uv ? options.uv(p, n) : [p[0], p[1]];
826
+ uvs[i * 2] = uv[0];
827
+ uvs[i * 2 + 1] = uv[1];
828
+ if (colors && options.color) colors.set(options.color(p, n), i * 4);
829
+ }
830
+ return {
831
+ positions: new Float32Array(positions),
832
+ normals: new Float32Array(normals),
833
+ uvs,
834
+ ...(colors ? { colors } : {}),
835
+ indices: count <= 65535 ? new Uint16Array(indices) : new Uint32Array(indices),
836
+ };
837
+ }
838
+
839
+ /**
840
+ * A trunk with limbs: each limb is joined to the trunk with its own fillet,
841
+ * and the limbs meet each other with none (fingers touch without growing
842
+ * together). `distance` is the least of the trunk joined with each limb.
843
+ */
844
+ export function joinZhudaSdfFields(
845
+ trunk: ZhudaSdfField,
846
+ limbs: ReadonlyArray<{ field: ZhudaSdfField; blend: number }>,
847
+ ): ZhudaSdfField {
848
+ limbs.forEach((limb, i) => {
849
+ if (!limb || typeof limb.field?.distance !== 'function')
850
+ throw Error(`limbs[${i}].field must be a signed distance field`);
851
+ if (!(finite(limb.blend) && limb.blend >= 0))
852
+ throw Error(`limbs[${i}].blend must be a number of metres, 0 or more`);
853
+ });
854
+ const boxOf = (f: ZhudaSdfField, x: number, y: number, z: number) =>
855
+ len(
856
+ Math.max(f.bounds.min[0] - x, 0, x - f.bounds.max[0]),
857
+ Math.max(f.bounds.min[1] - y, 0, y - f.bounds.max[1]),
858
+ Math.max(f.bounds.min[2] - z, 0, z - f.bounds.max[2]),
859
+ );
860
+ const distance = (x: number, y: number, z: number) => {
861
+ const t = trunk.distance(x, y, z);
862
+ let d = t;
863
+ for (const limb of limbs) {
864
+ // A field's box already holds its own fillets; past it by more than the trunk's distance
865
+ // and this fillet, the limb leaves the trunk as it is.
866
+ const box = boxOf(limb.field, x, y, z);
867
+ if (box > 0 && box >= t + limb.blend) continue;
868
+ d = Math.min(d, zhudaSmoothMin(t, limb.field.distance(x, y, z), limb.blend));
869
+ }
870
+ return d;
871
+ };
872
+ const min = [...trunk.bounds.min] as ZhudaVec3,
873
+ max = [...trunk.bounds.max] as ZhudaVec3;
874
+ for (const limb of limbs)
875
+ for (let k = 0; k < 3; k++) {
876
+ min[k] = Math.min(min[k], limb.field.bounds.min[k] - limb.blend);
877
+ max[k] = Math.max(max[k], limb.field.bounds.max[k] + limb.blend);
878
+ }
879
+ // Which part is nearest: -1 the trunk, else the limb's index.
880
+ const nearest = (x: number, y: number, z: number) => {
881
+ let best = -1,
882
+ bestD = trunk.distance(x, y, z);
883
+ limbs.forEach((limb, i) => {
884
+ const e = limb.field.distance(x, y, z);
885
+ if (e < bestD) {
886
+ bestD = e;
887
+ best = i;
888
+ }
889
+ });
890
+ return best;
891
+ };
892
+ return { distance, nearest, bounds: { min, max } };
893
+ }
894
+
895
+ /** How far a line from a point inside the body runs before it leaves it (up to `limit`). */
896
+ export function zhudaSdfDepthAlong(
897
+ distance: (x: number, y: number, z: number) => number,
898
+ from: ZhudaVec3,
899
+ direction: ZhudaVec3,
900
+ limit: number,
901
+ ): number {
902
+ const l = len(...direction);
903
+ const dx = direction[0] / l,
904
+ dy = direction[1] / l,
905
+ dz = direction[2] / l;
906
+ let t = 0;
907
+ for (let i = 0; i < 128 && t < limit; i++) {
908
+ const d = distance(from[0] + dx * t, from[1] + dy * t, from[2] + dz * t);
909
+ if (d > 0 && t > 0) return t;
910
+ t += Math.max(Math.abs(d), limit / 400);
911
+ }
912
+ return Math.min(t, limit);
913
+ }
914
+
915
+ /**
916
+ * Cuts a mesh into chunks of at most `maxVertices` (default 65535) with 16-bit
917
+ * indices, the size a `ZhudaDynamicMesh` takes. Triangles keep their order;
918
+ * a vertex on a cut is in both chunks, with the same normal, so no seam shows.
919
+ */
920
+ export function splitZhudaMesh(data: MeshData, maxVertices = 65535): MeshData[] {
921
+ if (!(Number.isInteger(maxVertices) && maxVertices >= 3 && maxVertices <= 65535))
922
+ throw Error('maxVertices must be a whole number from 3 to 65535');
923
+ const count = data.positions.length / 3;
924
+ if (count <= maxVertices && data.indices instanceof Uint16Array) return [data];
925
+ const chunks: MeshData[] = [];
926
+ const map = new Int32Array(count).fill(-1);
927
+ let used: number[] = [];
928
+ let tris: number[] = [];
929
+ const flush = () => {
930
+ if (!tris.length) return;
931
+ const n = used.length;
932
+ const pick = (array: Float32Array | undefined, size: number) => {
933
+ if (!array) return undefined;
934
+ const result = new Float32Array(n * size);
935
+ used.forEach((v, i) => result.set(array.subarray(v * size, v * size + size), i * size));
936
+ return result;
937
+ };
938
+ const chunk: MeshData = {
939
+ positions: pick(data.positions, 3)!,
940
+ indices: new Uint16Array(tris),
941
+ };
942
+ const normals = pick(data.normals, 3),
943
+ uvs = pick(data.uvs, 2),
944
+ tangents = pick(data.tangents, 4),
945
+ colors = pick(data.colors, 4);
946
+ if (normals) chunk.normals = normals;
947
+ if (uvs) chunk.uvs = uvs;
948
+ if (tangents) chunk.tangents = tangents;
949
+ if (colors) chunk.colors = colors;
950
+ chunks.push(chunk);
951
+ for (const v of used) map[v] = -1;
952
+ used = [];
953
+ tris = [];
954
+ };
955
+ const index = data.indices;
956
+ for (let i = 0; i < index.length; i += 3) {
957
+ let fresh = 0;
958
+ for (let k = 0; k < 3; k++) if (map[index[i + k]] < 0) fresh++;
959
+ if (used.length + fresh > maxVertices) flush();
960
+ for (let k = 0; k < 3; k++) {
961
+ const v = index[i + k];
962
+ if (map[v] < 0) {
963
+ map[v] = used.length;
964
+ used.push(v);
965
+ }
966
+ tris.push(map[v]);
967
+ }
968
+ }
969
+ flush();
970
+ return chunks;
971
+ }
972
+
973
+ /**
974
+ * Many small shapes as one plain union (no fillets, no cuts: creases, rivets,
975
+ * pores), found through a grid so a point asks only the shapes near it.
976
+ * Within `reach` of a shape the distance is exact; farther it is `reach`,
977
+ * which is never more than the true distance. Use it where only what is
978
+ * near matters: a cut into a surface, a detail joined to one.
979
+ */
980
+ export function createZhudaSdfUnion(
981
+ shapes: readonly ZhudaSdfShape[],
982
+ options: { reach?: number; cell?: number } = {},
983
+ ): ZhudaSdfField {
984
+ const errors = validateZhudaSdfShapes(shapes);
985
+ shapes.forEach((s, i) => {
986
+ if (s && (s.subtract || (s.blend ?? 0) > 0))
987
+ errors.push(`shapes[${i}] must have no blend and no subtract in a plain union`);
988
+ });
989
+ const reach = options.reach ?? 0.004,
990
+ cell = options.cell ?? 0.008;
991
+ if (!(finite(reach) && reach > 0)) errors.push('reach must be a positive number of metres');
992
+ if (!(finite(cell) && cell > 0)) errors.push('cell must be a positive number of metres');
993
+ if (errors.length) throw Error(`Invalid signed distance union: ${errors.join('; ')}`);
994
+ const parts = shapes.map(compile);
995
+ const min = [0, 1, 2].map((k) => Math.min(...parts.map((p) => p.lo[k]))) as ZhudaVec3;
996
+ const max = [0, 1, 2].map((k) => Math.max(...parts.map((p) => p.hi[k]))) as ZhudaVec3;
997
+ const o = min.map((v) => v - reach) as ZhudaVec3;
998
+ const n = [0, 1, 2].map((k) => Math.max(1, Math.ceil((max[k] + reach - o[k]) / cell)));
999
+ const buckets: number[][] = Array.from({ length: n[0] * n[1] * n[2] }, () => []);
1000
+ parts.forEach((p, i) => {
1001
+ const a = [0, 1, 2].map((k) => Math.max(0, Math.floor((p.lo[k] - reach - o[k]) / cell)));
1002
+ const b = [0, 1, 2].map((k) => Math.min(n[k] - 1, Math.floor((p.hi[k] + reach - o[k]) / cell)));
1003
+ for (let z = a[2]; z <= b[2]; z++)
1004
+ for (let y = a[1]; y <= b[1]; y++)
1005
+ for (let x = a[0]; x <= b[0]; x++) buckets[x + y * n[0] + z * n[0] * n[1]].push(i);
1006
+ });
1007
+ const bucket = (x: number, y: number, z: number) => {
1008
+ const i = Math.floor((x - o[0]) / cell),
1009
+ j = Math.floor((y - o[1]) / cell),
1010
+ k = Math.floor((z - o[2]) / cell);
1011
+ if (i < 0 || j < 0 || k < 0 || i >= n[0] || j >= n[1] || k >= n[2]) return null;
1012
+ return buckets[i + j * n[0] + k * n[0] * n[1]];
1013
+ };
1014
+ const distance = (x: number, y: number, z: number) => {
1015
+ const list = bucket(x, y, z);
1016
+ let d = reach;
1017
+ if (list) for (const i of list) d = Math.min(d, parts[i].distance(x, y, z));
1018
+ return d;
1019
+ };
1020
+ const nearest = (x: number, y: number, z: number) => {
1021
+ const list = bucket(x, y, z);
1022
+ let best = -1,
1023
+ bestD = Infinity;
1024
+ if (list)
1025
+ for (const i of list) {
1026
+ const e = parts[i].distance(x, y, z);
1027
+ if (e < bestD) {
1028
+ bestD = e;
1029
+ best = i;
1030
+ }
1031
+ }
1032
+ return best;
1033
+ };
1034
+ return { distance, nearest, bounds: { min, max } };
1035
+ }