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,1510 @@
1
+ /**
2
+ * A human hand from numbers: a skeleton with adult proportions, a pose given
3
+ * as joint angles, soft parts round each bone joined by fillets, and nails.
4
+ *
5
+ * Built on `Isosurface.ts`. Pure data: the result is `MeshData` for the skin
6
+ * and for the nails, and where each joint ended up. Nothing here touches Laya
7
+ * or comes from a file.
8
+ *
9
+ * The hand's own frame (a right hand; a left one is its mirror in x): the
10
+ * middle of the wrist's crease at the origin, the fingers along +y, the back
11
+ * of the hand toward +z, the thumb toward -x. Metres.
12
+ *
13
+ * The proportions are an adult's of middle size (hand length 0.185, breadth
14
+ * across the knuckles 0.082), the bones' lengths in the ratios anatomy
15
+ * tables give; `length` and `breadth` scale them.
16
+ */
17
+ import type { MeshData } from '../runtime3d/Surfaces.ts';
18
+ import type { ZhudaLitSurfaceSpec } from '../shaders/LitSurfaceMaterial.ts';
19
+ import type { ZhudaVec3 } from './Geometry.ts';
20
+ import {
21
+ createZhudaIsosurfaceMesh,
22
+ createZhudaSdfField,
23
+ createZhudaSdfUnion,
24
+ joinZhudaSdfFields,
25
+ splitZhudaMesh,
26
+ zhudaSdfDepthAlong,
27
+ zhudaSmoothMin,
28
+ type ZhudaSdfField,
29
+ type ZhudaSdfShape,
30
+ } from './Isosurface.ts';
31
+
32
+ export type ZhudaHandFinger = 'index' | 'middle' | 'ring' | 'little';
33
+ export type ZhudaHandDigit = 'thumb' | ZhudaHandFinger;
34
+ export const ZHUDA_HAND_FINGERS: readonly ZhudaHandFinger[] = ['index', 'middle', 'ring', 'little'];
35
+ export const ZHUDA_HAND_DIGITS: readonly ZhudaHandDigit[] = ['thumb', ...ZHUDA_HAND_FINGERS];
36
+
37
+ /** Joint angles in degrees. A finger's are its knuckle, middle and end joints; the thumb's its base, knuckle and end joints. */
38
+ export interface ZhudaHandPose {
39
+ /** Bend at each joint toward the palm, degrees: [knuckle, middle, end]. */
40
+ index?: [number, number, number];
41
+ middle?: [number, number, number];
42
+ ring?: [number, number, number];
43
+ little?: [number, number, number];
44
+ /** Bend at [base, knuckle, end]; the base turns the thumb across the palm. */
45
+ thumb?: [number, number, number];
46
+ /** How far the fingers fan out, degrees between neighbours on average (default 6). */
47
+ spread?: number;
48
+ /** How far the thumb stands out from the palm, degrees (default 40). */
49
+ thumbOut?: number;
50
+ }
51
+
52
+ /** A hand at rest: the fingers bend more toward the little one, as a hand left alone does. */
53
+ export const ZHUDA_HAND_RELAXED: Readonly<Required<ZhudaHandPose>> = {
54
+ index: [12, 20, 10],
55
+ middle: [16, 26, 12],
56
+ ring: [20, 32, 14],
57
+ little: [24, 38, 16],
58
+ thumb: [8, 12, 16],
59
+ spread: 4,
60
+ thumbOut: 38,
61
+ };
62
+ /** A hand held up gracefully: the fingers a little bent and apart, more toward the little one. */
63
+ export const ZHUDA_HAND_GRACEFUL: Readonly<Required<ZhudaHandPose>> = {
64
+ index: [6, 10, 6],
65
+ middle: [10, 16, 8],
66
+ ring: [16, 24, 10],
67
+ little: [24, 30, 12],
68
+ thumb: [4, 8, 12],
69
+ spread: 7,
70
+ thumbOut: 34,
71
+ };
72
+ /** A hand laid flat with the fingers a little apart. */
73
+ export const ZHUDA_HAND_FLAT: Readonly<Required<ZhudaHandPose>> = {
74
+ index: [0, 4, 2],
75
+ middle: [0, 4, 2],
76
+ ring: [0, 4, 2],
77
+ little: [0, 4, 2],
78
+ thumb: [0, 4, 6],
79
+ spread: 6,
80
+ thumbOut: 44,
81
+ };
82
+
83
+ export interface ZhudaHandOptions {
84
+ side?: 'right' | 'left';
85
+ /** From the wrist's crease to the end of the middle finger, metres (default 0.185; 0.12 to 0.25). */
86
+ length?: number;
87
+ /** Across the knuckles, metres (default 0.082; 0.06 to 0.11). */
88
+ breadth?: number;
89
+ /** Joint angles; any left out are the relaxed pose's. */
90
+ pose?: ZhudaHandPose;
91
+ /** The skin's colour as a display colour (default a light skin, 0.86, 0.66, 0.56). */
92
+ tone?: [number, number, number];
93
+ /** The skin mesh's cell, metres (default 0.0009; 0.0006 to 0.004). */
94
+ cellSize?: number;
95
+ /** How far the forearm runs below the wrist's crease, metres (default 0.05; 0.01 to 0.2). */
96
+ forearm?: number;
97
+ /** The build of the hand beyond its size: slender or strong, nails, veins. */
98
+ build?: ZhudaHandBuild;
99
+ }
100
+
101
+ /** What makes one adult's hand differ from another's beyond its length and breadth. Every value has a neutral default. */
102
+ export interface ZhudaHandBuild {
103
+ /** The fingers' thickness, a share of the default (0.8 to 1.2; default 1). */
104
+ fingerWidth?: number;
105
+ /** The tip's radius as a share of the default; the joints between follow (0.75 to 1.1; default 1). */
106
+ taper?: number;
107
+ /** The fingers' length against the palm's; `length` is kept (0.9 to 1.2; default 1). */
108
+ fingerLength?: number;
109
+ /** How much bone shows: the joints' waist and knuckles, the knuckles and tendons on the back (0 to 1.5; default 1). */
110
+ bone?: number;
111
+ /** The flesh of the palm: the ball of the thumb, the heel and the pads (0.85 to 1.15; default 1). */
112
+ flesh?: number;
113
+ /** How far the nails run past the end of the finger, metres (0 to 0.006; default 0.0008). */
114
+ nailFree?: number;
115
+ /** The nails' free edge: 0 square, 0.5 round, 1 almond (narrowing to a soft point) (default 0.5). */
116
+ nailRound?: number;
117
+ /** The nails' colour over the bed, a display colour (default 0.9, 0.66, 0.64). */
118
+ nailTone?: [number, number, number];
119
+ /** How much the veins on the back of the hand show through, as a tint (0 to 1; default 0.3). */
120
+ veins?: number;
121
+ /** How much the tendons on the back of the hand stand out (0 to 1.5; default `bone`). */
122
+ tendons?: number;
123
+ /** How pink the knuckles, the fingertips and the palm's pads are (0 to 1.5; default 0.6). */
124
+ flush?: number;
125
+ }
126
+
127
+ /** A man's hand, fine rather than rough: long, broad, with clean joints, short square-round nails. */
128
+ export const ZHUDA_HAND_MALE: Readonly<ZhudaHandOptions> = {
129
+ length: 0.192,
130
+ breadth: 0.087,
131
+ tone: [0.86, 0.68, 0.57],
132
+ build: {
133
+ fingerWidth: 1.04,
134
+ taper: 0.9,
135
+ fingerLength: 1.02,
136
+ bone: 0.9,
137
+ flesh: 1,
138
+ nailFree: 0.0005,
139
+ nailRound: 0.35,
140
+ nailTone: [0.9, 0.63, 0.6],
141
+ veins: 0.3,
142
+ },
143
+ };
144
+ /** A woman's hand with fair skin: slender, long straight fingers that taper, long almond nails, pink at the knuckles and tips. */
145
+ export const ZHUDA_HAND_FEMALE: Readonly<ZhudaHandOptions> = {
146
+ length: 0.172,
147
+ breadth: 0.071,
148
+ tone: [0.96, 0.84, 0.78],
149
+ build: {
150
+ fingerWidth: 0.96,
151
+ taper: 0.88,
152
+ fingerLength: 1.2,
153
+ bone: 0.15,
154
+ flesh: 0.93,
155
+ nailFree: 0.0058,
156
+ nailRound: 0.92,
157
+ nailTone: [0.95, 0.68, 0.68],
158
+ veins: 0.6,
159
+ tendons: 1.0,
160
+ flush: 1.15,
161
+ },
162
+ };
163
+
164
+ export interface ZhudaHandJoint {
165
+ digit: ZhudaHandDigit;
166
+ /** 0 the bone's base (the finger's knuckle, the thumb's base), up to 3 the end of the last bone. */
167
+ index: number;
168
+ position: ZhudaVec3;
169
+ }
170
+
171
+ export interface ZhudaHandMesh {
172
+ /**
173
+ * The skin, in chunks of at most 65535 vertices (one `ZhudaDynamicMesh` each). Its colour a vertex carries the tint as a display colour (a
174
+ * lit surface reads it as light in `s.vertexColor.rgb`) and, in alpha, how
175
+ * thin the hand is there (1 a sheet of nothing, about 0.4 through a finger,
176
+ * 0.25 through the palm): read it into `s.thickness` for light from behind.
177
+ */
178
+ skin: MeshData[];
179
+ /** The five nails, one mesh; their colour a vertex is the nail's tint (whiter at the free edge) and 1. */
180
+ nails: MeshData;
181
+ joints: ZhudaHandJoint[];
182
+ /** Where the tip of each digit is (the end of its flesh, not of its bone). */
183
+ tips: Record<ZhudaHandDigit, ZhudaVec3>;
184
+ side: 'right' | 'left';
185
+ }
186
+
187
+ const finite = (v: unknown) => typeof v === 'number' && Number.isFinite(v);
188
+ type V = ZhudaVec3;
189
+ const add = (a: V, b: V): V => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
190
+ const sub = (a: V, b: V): V => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
191
+ const mul = (a: V, s: number): V => [a[0] * s, a[1] * s, a[2] * s];
192
+ const dot = (a: V, b: V) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
193
+ const cross = (a: V, b: V): V => [
194
+ a[1] * b[2] - a[2] * b[1],
195
+ a[2] * b[0] - a[0] * b[2],
196
+ a[0] * b[1] - a[1] * b[0],
197
+ ];
198
+ const unit = (a: V): V => mul(a, 1 / Math.hypot(a[0], a[1], a[2]));
199
+ const mix = (a: V, b: V, t: number): V => [
200
+ a[0] + (b[0] - a[0]) * t,
201
+ a[1] + (b[1] - a[1]) * t,
202
+ a[2] + (b[2] - a[2]) * t,
203
+ ];
204
+ const rad = (deg: number) => (deg * Math.PI) / 180;
205
+ /** Turns `v` about the unit `axis` by `angle` radians (Rodrigues). */
206
+ const turn = (v: V, axis: V, angle: number): V => {
207
+ const c = Math.cos(angle),
208
+ s = Math.sin(angle);
209
+ return add(add(mul(v, c), mul(cross(axis, v), s)), mul(axis, dot(axis, v) * (1 - c)));
210
+ };
211
+ const smooth = (a: number, b: number, x: number) => {
212
+ const t = Math.min(Math.max((x - a) / (b - a), 0), 1);
213
+ return t * t * (3 - 2 * t);
214
+ };
215
+
216
+ /** What is wrong with the options; empty when a hand can be made. */
217
+ export function validateZhudaHand(options: ZhudaHandOptions = {}): string[] {
218
+ const errors: string[] = [];
219
+ if (!options || typeof options !== 'object') return ['options must be an object'];
220
+ const range = (value: unknown, label: string, lo: number, hi: number) => {
221
+ if (
222
+ value !== undefined &&
223
+ !(finite(value) && (value as number) >= lo && (value as number) <= hi)
224
+ )
225
+ errors.push(`${label} must be a number from ${lo} to ${hi}`);
226
+ };
227
+ if (options.side !== undefined && options.side !== 'right' && options.side !== 'left')
228
+ errors.push("side must be 'right' or 'left'");
229
+ range(options.length, 'length', 0.12, 0.25);
230
+ range(options.breadth, 'breadth', 0.06, 0.11);
231
+ range(options.cellSize, 'cellSize', 0.0006, 0.004);
232
+ range(options.forearm, 'forearm', 0.01, 0.2);
233
+ if (options.tone !== undefined) {
234
+ const t = options.tone;
235
+ if (!Array.isArray(t) || t.length !== 3 || !t.every((v) => finite(v) && v >= 0 && v <= 1))
236
+ errors.push('tone must be three numbers from 0 to 1');
237
+ }
238
+ const build = options.build;
239
+ if (build !== undefined) {
240
+ if (!build || typeof build !== 'object') errors.push('build must be an object');
241
+ else {
242
+ range(build.fingerWidth, 'build.fingerWidth', 0.8, 1.2);
243
+ range(build.taper, 'build.taper', 0.75, 1.1);
244
+ range(build.fingerLength, 'build.fingerLength', 0.9, 1.2);
245
+ range(build.tendons, 'build.tendons', 0, 1.5);
246
+ range(build.flush, 'build.flush', 0, 1.5);
247
+ range(build.bone, 'build.bone', 0, 1.5);
248
+ range(build.flesh, 'build.flesh', 0.85, 1.15);
249
+ range(build.nailFree, 'build.nailFree', 0, 0.006);
250
+ range(build.nailRound, 'build.nailRound', 0, 1);
251
+ range(build.veins, 'build.veins', 0, 1);
252
+ const t = build.nailTone;
253
+ if (
254
+ t !== undefined &&
255
+ (!Array.isArray(t) || t.length !== 3 || !t.every((v) => finite(v) && v >= 0 && v <= 1))
256
+ )
257
+ errors.push('build.nailTone must be three numbers from 0 to 1');
258
+ }
259
+ }
260
+ const pose = options.pose;
261
+ if (pose !== undefined) {
262
+ if (!pose || typeof pose !== 'object') errors.push('pose must be an object');
263
+ else {
264
+ for (const digit of ZHUDA_HAND_DIGITS) {
265
+ const a = pose[digit];
266
+ if (a === undefined) continue;
267
+ if (!Array.isArray(a) || a.length !== 3 || !a.every(finite))
268
+ errors.push(`pose.${digit} must be three angles in degrees`);
269
+ else {
270
+ const [lo, hi] = digit === 'thumb' ? [-20, 60] : [-25, 95];
271
+ a.forEach((v, i) => {
272
+ const top = i === 0 && digit !== 'thumb' ? 90 : i === 1 && digit !== 'thumb' ? 110 : hi;
273
+ const bottom = i === 0 ? lo : -10;
274
+ if (v < bottom || v > top)
275
+ errors.push(`pose.${digit}[${i}] must be from ${bottom} to ${top} degrees`);
276
+ });
277
+ }
278
+ }
279
+ range(pose.spread, 'pose.spread', -2, 20);
280
+ range(pose.thumbOut, 'pose.thumbOut', 0, 80);
281
+ }
282
+ }
283
+ return errors;
284
+ }
285
+
286
+ /** The base proportions, at length 0.185 and breadth 0.082: positions of the knuckles, bone lengths and radii. */
287
+ const FINGER: Record<
288
+ ZhudaHandFinger,
289
+ {
290
+ knuckle: V;
291
+ /** Where the bone of the palm starts. */
292
+ base: V;
293
+ bones: [number, number, number];
294
+ /** Radius of the flesh at the knuckle, the middle joint, the end joint and the tip. */
295
+ radii: [number, number, number, number];
296
+ /** The finger's own share of the fan, as a part of `spread` (negative toward the thumb). */
297
+ fan: number;
298
+ /** A finger's own turn about its length (degrees): the outer fingers face a little toward the middle. */
299
+ roll: number;
300
+ }
301
+ > = {
302
+ index: {
303
+ knuckle: [-0.0275, 0.0935, 0.002],
304
+ base: [-0.012, 0.03, 0.006],
305
+ bones: [0.0405, 0.0235, 0.0115],
306
+ radii: [0.0089, 0.0079, 0.0068, 0.0058],
307
+ fan: -1.0,
308
+ roll: -6,
309
+ },
310
+ middle: {
311
+ knuckle: [-0.007, 0.0965, 0.0035],
312
+ base: [-0.002, 0.03, 0.007],
313
+ bones: [0.0445, 0.0275, 0.0122],
314
+ radii: [0.0092, 0.0082, 0.007, 0.006],
315
+ fan: 0,
316
+ roll: 0,
317
+ },
318
+ ring: {
319
+ knuckle: [0.0125, 0.0915, 0.002],
320
+ base: [0.009, 0.03, 0.006],
321
+ bones: [0.0415, 0.0265, 0.0118],
322
+ radii: [0.0086, 0.0077, 0.0066, 0.0056],
323
+ fan: 0.9,
324
+ roll: 5,
325
+ },
326
+ little: {
327
+ knuckle: [0.03, 0.0845, -0.0015],
328
+ base: [0.019, 0.032, 0.004],
329
+ bones: [0.0355, 0.021, 0.011],
330
+ radii: [0.0075, 0.0067, 0.0059, 0.0051],
331
+ fan: 2.2,
332
+ roll: 12,
333
+ },
334
+ };
335
+ const THUMB = {
336
+ /** The joint at the wrist the thumb turns on. */
337
+ base: [-0.0185, 0.022, -0.006] as V,
338
+ bones: [0.0445, 0.031, 0.0185] as [number, number, number],
339
+ radii: [0.0125, 0.0099, 0.0094, 0.0076] as [number, number, number, number],
340
+ };
341
+
342
+ type Segment = { a: V; b: V; ra: number; rb: number; dorsal: V; lateral: V; dir: V };
343
+ type Resolved = Required<Omit<ZhudaHandOptions, 'build'>> & { build: Required<ZhudaHandBuild> };
344
+ const NEUTRAL_BUILD: Required<ZhudaHandBuild> = {
345
+ fingerWidth: 1,
346
+ taper: 1,
347
+ fingerLength: 1,
348
+ bone: 1,
349
+ flesh: 1,
350
+ nailFree: 0.0008,
351
+ nailRound: 0.5,
352
+ nailTone: [0.92, 0.64, 0.62],
353
+ veins: 0.3,
354
+ tendons: -1,
355
+ flush: 0.6,
356
+ };
357
+ /** The palm's scale along the hand: the middle knuckle at 0.0965 and the finger past it at 0.0885 share `length`. */
358
+ const palmScale = (o: Pick<Resolved, 'length' | 'build'>) =>
359
+ o.length / (0.0965 + 0.0885 * o.build.fingerLength);
360
+ type Digit = {
361
+ name: ZhudaHandDigit;
362
+ joints: V[];
363
+ radii: number[];
364
+ segments: Segment[];
365
+ };
366
+
367
+ function poseDigits(options: Resolved, pose: Required<ZhudaHandPose>): Digit[] {
368
+ const sx = options.breadth / 0.082,
369
+ sy = palmScale(options);
370
+ const b = options.build;
371
+ // The fingers' bones longer or shorter than the palm's; the thumb half as much.
372
+ const fy = sy * b.fingerLength,
373
+ ty = sy * (1 + (b.fingerLength - 1) * 0.5);
374
+ /** A digit's radius at joint i of 0..3: wider or narrower, and narrowing toward the tip. */
375
+ const width = (r: number, i: number, thumb = false) =>
376
+ // 1.06: the width the joined cones' fillets used to add, now that they add none.
377
+ r * 1.06 * sx * b.fingerWidth * (thumb ? Math.sqrt(b.taper) : b.taper) ** (i / 3);
378
+ const S = (p: V): V => [p[0] * sx, p[1] * sy, p[2] * sx];
379
+ const digits: Digit[] = [];
380
+ for (const name of ZHUDA_HAND_FINGERS) {
381
+ const f = FINGER[name];
382
+ const knuckle = S(f.knuckle);
383
+ // The finger leaves the knuckle along the line of its palm bone, fanned out about the back's normal.
384
+ let dir = unit(sub(knuckle, S(f.base)));
385
+ let dorsal: V = unit(sub([0, 0, 1], mul(dir, dir[2])));
386
+ dir = turn(dir, dorsal, -rad(f.fan * pose.spread) + rad(name === 'middle' ? 0 : 0));
387
+ dorsal = turn(dorsal, dir, rad(f.roll));
388
+ const angles = pose[name];
389
+ const joints: V[] = [knuckle];
390
+ const segments: Segment[] = [];
391
+ const radii = f.radii.map((r, i) => width(r, i));
392
+ let at = knuckle;
393
+ for (let i = 0; i < 3; i++) {
394
+ // Bend toward the palm about the finger's side axis.
395
+ const lateral = unit(cross(dir, dorsal));
396
+ const bend = rad(angles[i]);
397
+ dir = turn(dir, lateral, -bend);
398
+ dorsal = turn(dorsal, lateral, -bend);
399
+ const length = f.bones[i] * fy;
400
+ const next = add(at, mul(dir, length));
401
+ segments.push({ a: at, b: next, ra: radii[i], rb: radii[i + 1], dorsal, lateral, dir });
402
+ joints.push(next);
403
+ at = next;
404
+ }
405
+ digits.push({ name, joints, radii, segments });
406
+ }
407
+ // The thumb: out from the palm by thumbOut, turned across it by its base angle.
408
+ {
409
+ const base = S(THUMB.base);
410
+ const radii = THUMB.radii.map((r, i) => (i === 0 ? r * sx : width(r, i, true)));
411
+ // At thumbOut 0 the thumb lies along the side of the index's palm bone. It swings out
412
+ // toward -x in the palm's plane and, less, forward of the palm.
413
+ let dir = unit([-0.22, 1, -0.12]);
414
+ // The thumb's nail faces about 65 degrees round from the fingers' nails, toward -x.
415
+ let palmar: V = [Math.sin(rad(65)), 0, -Math.cos(rad(65))];
416
+ const radial = rad(pose.thumbOut * 0.8),
417
+ forward = rad(pose.thumbOut * 0.45);
418
+ dir = turn(turn(dir, [0, 0, 1], radial), [1, 0, 0], -forward);
419
+ palmar = turn(turn(palmar, [0, 0, 1], radial), [1, 0, 0], -forward);
420
+ const dorsal0 = mul(palmar, -1);
421
+ let dorsal = unit(sub(dorsal0, mul(dir, dot(dorsal0, dir))));
422
+ const joints: V[] = [base];
423
+ const segments: Segment[] = [];
424
+ let at = base;
425
+ for (let i = 0; i < 3; i++) {
426
+ const lateral = unit(cross(dir, dorsal));
427
+ const bend = rad(pose.thumb[i]);
428
+ dir = turn(dir, lateral, -bend);
429
+ dorsal = turn(dorsal, lateral, -bend);
430
+ const next = add(at, mul(dir, THUMB.bones[i] * ty));
431
+ segments.push({ a: at, b: next, ra: radii[i], rb: radii[i + 1], dorsal, lateral, dir });
432
+ joints.push(next);
433
+ at = next;
434
+ }
435
+ digits.unshift({ name: 'thumb', joints, radii, segments });
436
+ }
437
+ return digits;
438
+ }
439
+
440
+ /**
441
+ * The flesh of one digit: along each bone two cones that meet a little
442
+ * narrower in the bone's middle (how much, by `bone`), a low knob of bone on
443
+ * the back of the middle joint, and a pad on the palm side of each bone.
444
+ */
445
+ function digitShapes(d: Digit, bone: number): ZhudaSdfShape[] {
446
+ const shapes: ZhudaSdfShape[] = [];
447
+ const thumb = d.name === 'thumb';
448
+ d.segments.forEach((s, i) => {
449
+ const length = Math.hypot(...sub(s.b, s.a));
450
+ const last = i === 2;
451
+ // A digit is wider than it is deep; the end bone flattest, under the nail.
452
+ const squash = thumb ? (last ? 0.8 : 0.84) : last ? 0.84 : 0.9;
453
+ const flatten = { axis: s.dorsal, factor: squash };
454
+ const waist = last ? 1 : 1 - 0.035 * bone;
455
+ const middle = add(s.a, mul(s.dir, length * 0.5));
456
+ const rm = ((s.ra + s.rb) / 2) * waist;
457
+ // Two cones in a line need no fillet (a smooth union bulges where they meet, and the
458
+ // finger looks beaded); across a joint a small one.
459
+ shapes.push(
460
+ { kind: 'roundCone', a: s.a, b: middle, ra: s.ra, rb: rm, blend: 0.001, flatten },
461
+ { kind: 'roundCone', a: middle, b: s.b, ra: rm, rb: s.rb, blend: 0, flatten },
462
+ );
463
+ // The knob of bone on the back of the middle joint (a finger's) or the knuckle (the thumb's).
464
+ if (bone > 0.5 && i === 0)
465
+ shapes.push({
466
+ kind: 'ellipsoid',
467
+ center: add(s.b, mul(s.dorsal, s.rb * squash * (0.42 + 0.1 * bone))),
468
+ radii: [s.rb * 0.45, s.rb * 0.62, s.rb * 0.4],
469
+ axes: [s.lateral, s.dir, s.dorsal],
470
+ blend: 0.0035,
471
+ });
472
+ // The pad of flesh on the palm side of the bone.
473
+ const padAt = last ? 0.62 : 0.5;
474
+ const r = s.ra + (s.rb - s.ra) * padAt;
475
+ shapes.push({
476
+ kind: 'ellipsoid',
477
+ center: add(add(s.a, mul(s.dir, length * padAt)), mul(s.dorsal, -r * (last ? 0.3 : 0.36))),
478
+ radii: [r * (last ? 0.78 : 0.62), length * (last ? 0.6 : 0.5), r * (last ? 0.7 : 0.6)],
479
+ axes: [s.lateral, s.dir, s.dorsal],
480
+ blend: last ? 0.004 : 0.005,
481
+ });
482
+ });
483
+ return shapes;
484
+ }
485
+
486
+ /** The palm, the wrist and the forearm. */
487
+ function palmShapes(digits: Digit[], options: Resolved): ZhudaSdfShape[] {
488
+ const sx = options.breadth / 0.082,
489
+ sy = palmScale(options);
490
+ const S = (p: V): V => [p[0] * sx, p[1] * sy, p[2] * sx];
491
+ const { flesh, bone } = options.build;
492
+ const shapes: ZhudaSdfShape[] = [];
493
+ // Forearm into the wrist: an oval, wider than deep.
494
+ shapes.push({
495
+ kind: 'roundCone',
496
+ a: S([0.001, -options.forearm / sy, 0.001]),
497
+ // The wrist's end only a little toward the palm: further, it filled the valley between
498
+ // the two balls of the hand and left a straight step across the heel.
499
+ b: S([0.0, 0.004, -0.0008]),
500
+ // A slender build has a slimmer wrist.
501
+ ra: 0.0285 * sx * (0.9 + 0.1 * Math.min(bone, 1)),
502
+ // Less at the wrist's end: the heel of the hand would stand over it as a ledge.
503
+ rb: 0.0265 * sx * (0.96 + 0.04 * Math.min(bone, 1)),
504
+ // Deeper than it was (0.66): the heel of the hand stood over a thin wrist as a ledge.
505
+ flatten: { axis: [0, 0, 1], factor: 0.73 },
506
+ });
507
+ // The wrist's bones, a flat block.
508
+ shapes.push({
509
+ kind: 'ellipsoid',
510
+ // Narrower than the hand above it: wider, it made the little finger's edge bulge at the
511
+ // wrist and pinch in above.
512
+ center: S([0.002, 0.02, 0.0025]),
513
+ radii: [0.0255 * sx, 0.024 * sy, 0.0135 * sx],
514
+ blend: 0.012,
515
+ });
516
+ // The palm's bones with their flesh: a ray from the wrist to each knuckle, joined into a plate.
517
+ for (const name of ZHUDA_HAND_FINGERS) {
518
+ const f = FINGER[name];
519
+ const digit = digits.find((d) => d.name === name)!;
520
+ const knuckle = digit.joints[0];
521
+ shapes.push({
522
+ kind: 'roundCone',
523
+ a: S(f.base),
524
+ b: knuckle,
525
+ ra: 0.0105 * sx,
526
+ rb: digit.radii[0] * 1.02,
527
+ blend: 0.011,
528
+ flatten: { axis: [0, 0, 1], factor: 0.8 },
529
+ });
530
+ }
531
+ // The heads of the palm's bones, seen on the back as knuckles.
532
+ for (const name of ZHUDA_HAND_FINGERS) {
533
+ const d = digits.find((x) => x.name === name)!;
534
+ const head = sub(d.joints[0], mul(d.segments[0].dir, 0.004 * sy));
535
+ shapes.push({
536
+ kind: 'ellipsoid',
537
+ center: add(head, [0, 0, 0.0035 * sx * (0.75 + 0.25 * bone)]),
538
+ radii: [d.radii[0] * 0.78, 0.008 * sy, 0.0055 * sx * (0.8 + 0.2 * bone)],
539
+ axes: [d.segments[0].lateral, d.segments[0].dir, d.segments[0].dorsal],
540
+ blend: 0.007,
541
+ });
542
+ }
543
+ // The little finger's edge of the hand, one smooth line from the wrist to the knuckle:
544
+ // the heel and the palm's bone pushed it out in two plateaus.
545
+ {
546
+ const little = digits.find((d) => d.name === 'little')!;
547
+ shapes.push({
548
+ kind: 'roundCone',
549
+ a: S([0.0172, 0.006, -0.0015]),
550
+ // Ending short of the knuckle: over it, it stood on the back as a bump.
551
+ b: sub(little.joints[0], mul(little.segments[0].dir, 0.013 * sy)),
552
+ ra: 0.0094 * sx,
553
+ rb: little.radii[0] * 0.92,
554
+ blend: 0.012,
555
+ flatten: { axis: [0, 0, 1], factor: 0.74 },
556
+ });
557
+ }
558
+ // The heel as one broad rise: an ellipse through the palm's side about 21.5 mm out at
559
+ // 12 mm above the wrist, 19 at 24 and 15 at 40, so the palm turns down onto the heel
560
+ // gradually. (The heel's pads all ended along one line, and the light caught the bend.)
561
+ shapes.push({
562
+ kind: 'ellipsoid',
563
+ center: S([0.004, 0.004, 0.0058]),
564
+ radii: [0.024 * sx, 0.05 * sy, 0.0222 * sx * flesh],
565
+ // Only its palm side: set this deep, its back would stand out of the back of the hand.
566
+ keep: { normal: [0, 0, 1], offset: 0.004 * sx },
567
+ blend: 0.012,
568
+ });
569
+ // The flesh of the palm between its balls: without it the middle of the palm was 14 mm
570
+ // thinner than the heel, a pit rather than a cup.
571
+ shapes.push({
572
+ kind: 'ellipsoid',
573
+ // Down to the heel, so the palm runs onto it in a slope rather than a step.
574
+ // Deep in the hand and wide, so its face is a broad gentle curve: a thin wide one was
575
+ // flat across the middle and put all the curving into one line above the heel.
576
+ center: S([0.003, 0.052, 0.0128]),
577
+ radii: [0.03 * sx, 0.046 * sy, 0.0222 * sx * flesh],
578
+ keep: { normal: [0, 0, 1], offset: 0.0 },
579
+ blend: 0.014,
580
+ });
581
+ // The pad under the knuckles, along their curve.
582
+ shapes.push({
583
+ kind: 'ellipsoid',
584
+ center: S([0.001, 0.081, -0.0066]),
585
+ radii: [0.032 * sx, 0.015 * sy, 0.0052 * sx * flesh],
586
+ axes: [unit([1, -0.2, 0]), unit([0.2, 1, 0]), [0, 0, 1]],
587
+ blend: 0.014,
588
+ });
589
+ // The ball of the thumb and the heel of the hand on the little finger's side.
590
+ shapes.push({
591
+ kind: 'ellipsoid',
592
+ // Out far enough that the thumb's side of the hand bulges from the wrist to the thumb
593
+ // (it ran as a straight line, and the thumb seemed stuck on).
594
+ // Its inner edge stops at the life line, as the ball of the thumb's does: past it, it
595
+ // filled the valley between the two balls of the hand.
596
+ center: S([-0.0228, 0.032, -0.0112]),
597
+ radii: [0.0172 * sx * flesh, 0.031 * sy, 0.0138 * sx * flesh],
598
+ axes: [unit([0.92, 0.39, 0]), unit([-0.39, 0.92, 0]), [0, 0, 1]],
599
+ blend: 0.012,
600
+ });
601
+ shapes.push({
602
+ kind: 'ellipsoid',
603
+ // Placed so the little finger's edge widens steadily from the wrist to the knuckle.
604
+ // Inside the line of the edge below (it pushed past it as a plateau).
605
+ // A rounded pad standing toward the palm side (outward it pushed the edge past its line).
606
+ // Down to the wrist: the heel on this side is this pad, not a bar across the palm.
607
+ center: S([0.0168, 0.032, -0.0086]),
608
+ radii: [0.0098 * sx * flesh, 0.034 * sy, 0.0112 * sx * flesh],
609
+ axes: [unit([1, 0.12, 0]), unit([-0.12, 1, 0]), [0, 0, 1]],
610
+ blend: 0.012,
611
+ });
612
+ // No hollow cut into the palm: the middle pad sits lower than the pads round it, and that
613
+ // is the cup. A cut deep enough to show also reached the heel's pads, which stand further
614
+ // out, and its fillet carved a line across the palm above the heel.
615
+ return shapes;
616
+ }
617
+
618
+ /** The web of skin between the thumb and the index finger. */
619
+ function webShapes(digits: Digit[], sx: number): ZhudaSdfShape[] {
620
+ const thumb = digits[0],
621
+ index = digits[1];
622
+ // The muscle between the thumb's palm bone and the index's: a flat mass on the back, a web
623
+ // of skin at its free edge.
624
+ const t0 = mix(thumb.joints[0], thumb.joints[1], 0.35);
625
+ const t1 = mix(thumb.joints[0], thumb.joints[1], 0.85);
626
+ const i1 = mix(index.joints[0], index.joints[1], 0.06);
627
+ const i0 = add(i1, [0.004 * sx, -0.03 * sx, 0]);
628
+ const middle = mix(mix(t0, t1, 0.5), mix(i0, i1, 0.5), 0.5);
629
+ const across = unit(sub(mix(i0, i1, 0.5), mix(t0, t1, 0.5)));
630
+ const along = unit(sub(mix(t1, i1, 0.5), mix(t0, i0, 0.5)));
631
+ const normal = unit(cross(across, along));
632
+ const out = unit(sub(along, mul(across, dot(along, across))));
633
+ return [
634
+ {
635
+ kind: 'ellipsoid',
636
+ center: middle,
637
+ radii: [
638
+ Math.hypot(...sub(mix(i0, i1, 0.5), mix(t0, t1, 0.5))) * 0.5,
639
+ Math.hypot(...sub(mix(t1, i1, 0.5), mix(t0, i0, 0.5))) * 0.55,
640
+ 0.0075 * sx,
641
+ ],
642
+ axes: [across, out, unit(cross(across, out))],
643
+ blend: 0.01,
644
+ },
645
+ {
646
+ kind: 'roundCone',
647
+ a: t1,
648
+ b: i1,
649
+ ra: 0.0055 * sx,
650
+ rb: 0.006 * sx,
651
+ blend: 0.008,
652
+ flatten: { axis: normal, factor: 0.6 },
653
+ },
654
+ ];
655
+ }
656
+
657
+ /** Where the skin's surface is, going out from a point along a direction (for seating a nail). */
658
+ function surfaceAlong(field: ZhudaSdfField, from: V, dir: V, reach: number): number {
659
+ let lo = 0,
660
+ hi = reach;
661
+ for (let i = 0; i < 40; i++) {
662
+ const mid = (lo + hi) / 2;
663
+ if (field.distance(...add(from, mul(dir, mid))) < 0) lo = mid;
664
+ else hi = mid;
665
+ }
666
+ return (lo + hi) / 2;
667
+ }
668
+
669
+ /**
670
+ * A nail on the end bone of a digit, seated a little into the skin: a curved
671
+ * plate, round at the cuticle, square or oval at its free edge, running
672
+ * `nailFree` past where the flesh under it ends.
673
+ */
674
+ function nailField(field: ZhudaSdfField, d: Digit, b: Required<ZhudaHandBuild>) {
675
+ const s = d.segments[2];
676
+ const L = Math.hypot(...sub(s.b, s.a));
677
+ const r = s.rb;
678
+ const thumb = d.name === 'thumb';
679
+ // How far the flesh runs past the end of the bone, along it.
680
+ const reach = surfaceAlong(field, s.b, s.dir, r * 3);
681
+ const u0 = L * (thumb ? 0.2 : 0.1);
682
+ // Where the nail leaves the flesh: the tip curves down under it before the flesh ends.
683
+ const uFlesh = L + reach * 0.72;
684
+ const u1 = uFlesh + b.nailFree;
685
+ const halfWidth = r * (thumb ? 0.7 : 0.76);
686
+ // How curved it is across: a little more than the skin under it, so its sides tuck into the
687
+ // folds along them instead of standing up as walls.
688
+ const bend = r * (thumb ? 0.9 : 0.95);
689
+ const thick = 0.00055;
690
+ const heightAt = (u: number) => surfaceAlong(field, add(s.a, mul(s.dir, u)), s.dorsal, r * 2.5);
691
+ // The skin's height along the bone, sampled; past the flesh's end the nail runs on, curving
692
+ // down a little.
693
+ const uEnd = L + reach * 0.5;
694
+ const samples = 24;
695
+ const heights = Array.from({ length: samples + 1 }, (_, i) =>
696
+ heightAt(u0 + ((uEnd - u0) * i) / samples),
697
+ );
698
+ const endSlope = (heights[samples] - heights[samples - 2]) / ((2 * (uEnd - u0)) / samples);
699
+ const skinAt = (u: number) => {
700
+ if (u >= uEnd) {
701
+ const past = u - uEnd;
702
+ // A long nail curves on down past the tip, as the finger would (a C seen from the side).
703
+ return heights[samples] + Math.max(endSlope, -0.3) * past * 0.45 - past * past * 28;
704
+ }
705
+ const f = (Math.max(u, u0) - u0) / ((uEnd - u0) / samples);
706
+ const i = Math.min(Math.floor(f), samples - 1);
707
+ return heights[i] + (heights[i + 1] - heights[i]) * (f - i);
708
+ };
709
+ // The plate's axis: under the skin's top by its curvature, set 0.08 mm into the skin, and
710
+ // sunk under the fold at the cuticle.
711
+ const axisAt = (u: number) =>
712
+ skinAt(u) - bend + thick * 0.5 - 0.00008 - 0.0003 * (1 - smooth(u0, u0 + 0.0012, u));
713
+ const almond = Math.max(0, b.nailRound - 0.6) / 0.4;
714
+ const proximal = halfWidth * 0.95,
715
+ distal = halfWidth * Math.min(0.38 + 0.6 * b.nailRound, 0.95);
716
+ const cu = (u0 + u1) / 2,
717
+ hu = (u1 - u0) / 2;
718
+ const distance = (x: number, y: number, z: number) => {
719
+ const p = sub([x, y, z], s.a);
720
+ const u = dot(p, s.dir),
721
+ lat = dot(p, s.lateral),
722
+ up = dot(p, s.dorsal) - axisAt(u);
723
+ const radial = Math.hypot(lat, up);
724
+ // A little thicker where it runs free of the finger: seen from the side it is a nail,
725
+ // not a blade.
726
+ const t = thick + 0.0002 * smooth(uFlesh, u1, u);
727
+ const shell = Math.abs(radial - bend) - t * 0.5;
728
+ // Across the plate as an arc length; the outline a rectangle with round ends, rounder at
729
+ // the free edge for an oval nail.
730
+ const across = bend * Math.atan2(lat, up);
731
+ const corner = u > cu ? distal : proximal;
732
+ // An almond nail narrows past the flesh toward a soft point.
733
+ const narrow = almond * smooth(uFlesh - 0.002, u1, u);
734
+ const qx = Math.abs(across) / (1 - 0.45 * narrow) - (halfWidth - corner),
735
+ qy = Math.abs(u - cu) - (hu - corner);
736
+ const outline =
737
+ Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - corner;
738
+ // The plate's rim rounded over its thickness, not a knife edge.
739
+ const rr = thick * 0.45;
740
+ const a = shell + rr,
741
+ c = outline + rr;
742
+ return Math.hypot(Math.max(a, 0), Math.max(c, 0)) + Math.min(Math.max(a, c), 0) - rr;
743
+ };
744
+ /** A point on the nail's top: along the bone, and across it as a share of its half width. */
745
+ const onTop = (u: number, share: number): V => {
746
+ const angle = (share * halfWidth) / bend;
747
+ return add(
748
+ add(add(s.a, mul(s.dir, u)), mul(s.lateral, bend * Math.sin(angle))),
749
+ mul(s.dorsal, axisAt(u) + bend * Math.cos(angle)),
750
+ );
751
+ };
752
+ const corners: V[] = [];
753
+ for (const u of [u0 - 0.001, u1 + 0.001])
754
+ for (const l of [-halfWidth - 0.001, halfWidth + 0.001])
755
+ for (const h of [-0.004, 0.003]) {
756
+ const c = add(
757
+ add(add(s.a, mul(s.dir, u)), mul(s.lateral, l)),
758
+ mul(s.dorsal, axisAt(u) + bend + h),
759
+ );
760
+ corners.push(c);
761
+ }
762
+ const min = [0, 1, 2].map((k) => Math.min(...corners.map((c) => c[k])) - 0.0015) as V;
763
+ const max = [0, 1, 2].map((k) => Math.max(...corners.map((c) => c[k])) + 0.0015) as V;
764
+ return { distance, min, max, s, u0, u1, uFlesh, halfWidth, onTop };
765
+ }
766
+
767
+ /** The skin that holds a nail: a low fold along each side of it and over its root. */
768
+ function nailFolds(nail: ReturnType<typeof nailField>, sx: number): ZhudaSdfShape[] {
769
+ const shapes: ZhudaSdfShape[] = [];
770
+ const r = 0.0007 * sx;
771
+ const { s, u0, uFlesh, onTop } = nail;
772
+ const run = uFlesh - 0.0012 * sx - (u0 + 0.0008);
773
+ for (const side of [-1, 1]) {
774
+ const points: V[] = [];
775
+ for (let i = 0; i <= 6; i++) {
776
+ const u = u0 + 0.0008 + (run * i) / 6;
777
+ // Beside the nail's edge, a little lower than its top, lower toward the tip.
778
+ const p = onTop(u, side * 1.04);
779
+ const fall = i / 6;
780
+ points.push(
781
+ add(add(p, mul(s.lateral, side * r * 0.55)), mul(s.dorsal, -r * (0.75 + 0.5 * fall))),
782
+ );
783
+ }
784
+ for (let i = 0; i < 6; i++)
785
+ shapes.push({ kind: 'roundCone', a: points[i], b: points[i + 1], ra: r, rb: r * 0.8 });
786
+ }
787
+ // Over the root: an arc across, just behind where the nail shows.
788
+ const arc: V[] = [];
789
+ for (let i = 0; i <= 8; i++) {
790
+ const share = -1.05 + (2.1 * i) / 8;
791
+ arc.push(
792
+ add(
793
+ add(
794
+ onTop(u0 + 0.0006 * sx - 0.0006 * Math.abs(share) ** 2, share),
795
+ mul(s.dorsal, -r * 0.55),
796
+ ),
797
+ mul(s.dir, -r * 0.2),
798
+ ),
799
+ );
800
+ }
801
+ for (let i = 0; i < 8; i++)
802
+ shapes.push({ kind: 'roundCone', a: arc[i], b: arc[i + 1], ra: r * 1.05, rb: r * 1.05 });
803
+ return shapes;
804
+ }
805
+
806
+ /** The veins that show on the back of the hand: lines in the hand's plane, base proportions. */
807
+ const VEINS: Array<Array<[number, number]>> = [
808
+ [
809
+ [0.026, 0.07],
810
+ [0.022, 0.05],
811
+ [0.016, 0.03],
812
+ [0.012, 0.012],
813
+ [0.01, -0.012],
814
+ ],
815
+ [
816
+ [0.004, 0.074],
817
+ [0.006, 0.055],
818
+ [0.002, 0.035],
819
+ [-0.002, 0.018],
820
+ [-0.004, -0.008],
821
+ ],
822
+ [
823
+ [-0.016, 0.07],
824
+ [-0.019, 0.05],
825
+ [-0.021, 0.03],
826
+ [-0.021, 0.01],
827
+ [-0.019, -0.014],
828
+ ],
829
+ // The arch across the back joins them; it bows toward the fingers in the middle.
830
+ [
831
+ [0.02, 0.05],
832
+ [0.011, 0.056],
833
+ [0.0, 0.058],
834
+ [-0.011, 0.055],
835
+ [-0.019, 0.049],
836
+ ],
837
+ ];
838
+ /** How strongly each vein shows: the arch, thinner and deeper, least. */
839
+ const VEIN_STRENGTH = [1, 0.85, 1, 0.45];
840
+
841
+ /** A crease to cut: points on the skin, the outward direction at each, how wide and how deep, how dark. */
842
+ type Crease = { points: V[]; out: V[]; width: number; depth: number; strength: number };
843
+
844
+ /** Capsules along a crease, raised so they cut only `depth` into the skin, thinning to nothing at the ends. */
845
+ function creaseCapsules(c: Crease): ZhudaSdfShape[] {
846
+ const shapes: ZhudaSdfShape[] = [];
847
+ const n = c.points.length - 1;
848
+ const r = c.width / 2;
849
+ const at = (i: number) => {
850
+ const fade = Math.max(0, Math.sin((Math.PI * i) / n)) ** 0.6;
851
+ // The capsule's middle sits r - depth outside the skin; toward the ends it lifts clear of
852
+ // the skin and of the fillet that joins it, so a crease fades out instead of grazing.
853
+ return add(c.points[i], mul(c.out[i], r - c.depth * fade + 0.0014 * (1 - fade)));
854
+ };
855
+ for (let i = 0; i < n; i++)
856
+ shapes.push({ kind: 'roundCone', a: at(i), b: at(i + 1), ra: r, rb: r });
857
+ return shapes;
858
+ }
859
+ /** Points along straight runs between control points, `per` to a run. */
860
+ function along(control: V[], per: number): V[] {
861
+ const out: V[] = [];
862
+ for (let i = 0; i < control.length - 1; i++)
863
+ for (let k = 0; k < per; k++) out.push(mix(control[i], control[i + 1], k / per));
864
+ out.push(control[control.length - 1]);
865
+ return out;
866
+ }
867
+
868
+ /**
869
+ * The creases of the skin: across the palm side of each finger joint (two at
870
+ * the middle joint), where a finger leaves the palm, the thumb's, the three
871
+ * long lines of the palm, the wrist's, and faint wrinkles over the backs of
872
+ * the middle joints. Each is seated on the skin as it is.
873
+ */
874
+ function creases(body: ZhudaSdfField, digits: Digit[], o: Resolved): Crease[] {
875
+ const sx = o.breadth / 0.082,
876
+ sy = palmScale(o);
877
+ const list: Crease[] = [];
878
+ /** An arc round a digit at a place on its axis, from `side` (unit, square to the axis), `spread` degrees each way. */
879
+ const arc = (
880
+ centre: V,
881
+ axis: V,
882
+ side: V,
883
+ spread: number,
884
+ width: number,
885
+ depth: number,
886
+ strength: number,
887
+ samples = 12,
888
+ ) => {
889
+ const points: V[] = [],
890
+ out: V[] = [];
891
+ for (let i = 0; i <= samples; i++) {
892
+ const dir = turn(side, axis, rad(-spread + (2 * spread * i) / samples));
893
+ points.push(add(centre, mul(dir, surfaceAlong(body, centre, dir, 0.03))));
894
+ out.push(dir);
895
+ }
896
+ list.push({ points, out, width: width * sx, depth: depth * sx, strength });
897
+ };
898
+ for (const d of digits) {
899
+ const at = (segment: number, u: number) => {
900
+ const s = d.segments[segment];
901
+ return add(s.a, mul(s.dir, u));
902
+ };
903
+ const palmar = (segment: number) => mul(d.segments[segment].dorsal, -1);
904
+ const axisAt = (segment: number) => d.segments[segment].dir;
905
+ if (d.name !== 'thumb') {
906
+ const L0 = Math.hypot(...sub(d.segments[0].b, d.segments[0].a));
907
+ // Across the palm side only: wrapped further they notch the finger's outline seen from
908
+ // the back, and the finger looks beaded.
909
+ arc(at(0, L0 * 0.4), axisAt(0), palmar(0), 52, 0.0022, 0.00045, 0.55);
910
+ arc(at(1, -0.0011 * sy), axisAt(1), palmar(1), 52, 0.0018, 0.00042, 0.55);
911
+ arc(at(1, 0.0011 * sy), axisAt(1), palmar(1), 46, 0.0016, 0.00035, 0.45);
912
+ arc(at(2, 0.0005 * sy), axisAt(2), palmar(2), 50, 0.0016, 0.00035, 0.45);
913
+ // Faint wrinkles over the back of the middle joint, shorter toward the ends.
914
+ [
915
+ [-0.0024, 22],
916
+ [-0.0006, 30],
917
+ [0.0013, 26],
918
+ ].forEach(([u, spread]) =>
919
+ arc(
920
+ at(1, u * sy),
921
+ axisAt(1),
922
+ d.segments[1].dorsal,
923
+ spread,
924
+ 0.0012,
925
+ 0.00014 * (0.5 + 0.5 * Math.min(o.build.bone, 1)),
926
+ 0.22 * (0.4 + 0.6 * Math.min(o.build.bone, 1)),
927
+ 8,
928
+ ),
929
+ );
930
+ } else {
931
+ // Not round toward the web: there the arc would cut into it.
932
+ arc(at(1, 0.0012 * sy), axisAt(1), palmar(1), 42, 0.002, 0.00045, 0.55);
933
+ arc(at(1, 0.0032 * sy), axisAt(1), palmar(1), 40, 0.0016, 0.00035, 0.45);
934
+ arc(at(2, 0.0006 * sy), axisAt(2), palmar(2), 68, 0.0018, 0.0004, 0.5);
935
+ }
936
+ }
937
+ // The palm's lines, drawn on the palm from inside it.
938
+ const onPalm = (xy: Array<[number, number]>, width: number, depth: number, strength: number) => {
939
+ // Only where the line runs over the palm: a point whose start is not inside the body is
940
+ // past the palm's edge, and the line stops there.
941
+ const points = along(
942
+ xy.map(([x, y]) => [x * sx, y * sy, -0.002 * sx] as V),
943
+ 5,
944
+ )
945
+ .filter((p) => body.distance(...p) < -0.002)
946
+ .map((p) => add(p, [0, 0, -surfaceAlong(body, p, [0, 0, -1], 0.04)]));
947
+ if (points.length < 3) return;
948
+ list.push({
949
+ points,
950
+ out: points.map(() => [0, 0, -1] as V),
951
+ width: width * sx,
952
+ depth: depth * sx,
953
+ strength,
954
+ });
955
+ };
956
+ // The heart line, from the little finger's edge to between the index and middle fingers.
957
+ onPalm(
958
+ [
959
+ [0.036, 0.066],
960
+ [0.024, 0.07],
961
+ [0.009, 0.0755],
962
+ [-0.005, 0.082],
963
+ [-0.013, 0.0865],
964
+ ],
965
+ 0.0024,
966
+ 0.0005,
967
+ 0.5,
968
+ );
969
+ // The head line, from the web of the thumb across the middle of the palm.
970
+ onPalm(
971
+ [
972
+ [-0.023, 0.069],
973
+ [-0.016, 0.0655],
974
+ [-0.003, 0.06],
975
+ [0.011, 0.054],
976
+ [0.021, 0.0505],
977
+ ],
978
+ 0.0022,
979
+ 0.00045,
980
+ 0.45,
981
+ );
982
+ // The life line, round the ball of the thumb to the wrist.
983
+ onPalm(
984
+ [
985
+ [-0.0225, 0.069],
986
+ [-0.0165, 0.0615],
987
+ [-0.0105, 0.049],
988
+ [-0.0068, 0.034],
989
+ [-0.0058, 0.019],
990
+ [-0.0065, 0.008],
991
+ ],
992
+ 0.0024,
993
+ 0.0005,
994
+ 0.5,
995
+ );
996
+ // The wrist's two creases.
997
+ onPalm(
998
+ [
999
+ [-0.022, 0.0025],
1000
+ [-0.008, 0.0],
1001
+ [0.008, 0.0],
1002
+ [0.022, 0.0025],
1003
+ ],
1004
+ 0.002,
1005
+ 0.0004,
1006
+ 0.4,
1007
+ );
1008
+ onPalm(
1009
+ [
1010
+ [-0.019, -0.0075],
1011
+ [-0.006, -0.009],
1012
+ [0.008, -0.009],
1013
+ [0.019, -0.0075],
1014
+ ],
1015
+ 0.0016,
1016
+ 0.00025,
1017
+ 0.25,
1018
+ );
1019
+ return list;
1020
+ }
1021
+
1022
+ /**
1023
+ * The tendons on the back of the hand: one strand from behind each knuckle
1024
+ * toward the middle of the wrist, a little above the skin near the knuckle
1025
+ * and sinking into it toward the wrist.
1026
+ */
1027
+ function tendonShapes(trunk: ZhudaSdfField, digits: Digit[], o: Resolved): ZhudaSdfShape[][] {
1028
+ const sx = o.breadth / 0.082,
1029
+ sy = palmScale(o);
1030
+ const shapes: ZhudaSdfShape[][] = [];
1031
+ const skinAbove = (p: V): V => {
1032
+ const inside: V = [p[0], p[1], 0];
1033
+ return add(inside, [0, 0, surfaceAlong(trunk, inside, [0, 0, 1], 0.04)]);
1034
+ };
1035
+ for (const name of ZHUDA_HAND_FINGERS) {
1036
+ const d = digits.find((x) => x.name === name)!;
1037
+ if (o.build.tendons < 0.05) continue;
1038
+ const r = 0.0026 * sx * (name === 'little' ? 0.8 : 1);
1039
+ // From just behind the knuckle, sunk there, up to its highest a third of the way to the
1040
+ // wrist, and under again at the wrist: two cones joined without a fillet (a fillet
1041
+ // bulges where two pieces meet), the pair joined to the hand with one. (One long slim
1042
+ // ellipsoid broke down: the ellipsoid's distance is an estimate, poor at 13 to 1.)
1043
+ const start = sub(d.joints[0], mul(d.segments[0].dir, 0.005 * sy));
1044
+ const end: V = [start[0] * 0.35 + 0.002 * sx, 0.004 * sy, 0];
1045
+ const top = mix(start, end, 0.42);
1046
+ const raise = 0.00042 * sx * Math.min(o.build.tendons, 1.3) ** 2;
1047
+ const a = add(skinAbove(start), [0, 0, -r * 1.3]);
1048
+ const m = add(skinAbove(top), [0, 0, -r + raise]);
1049
+ const b = add(skinAbove(end), [0, 0, -r * 2.6]);
1050
+ shapes.push([
1051
+ { kind: 'roundCone', a, b: m, ra: r * 0.85, rb: r },
1052
+ { kind: 'roundCone', a: m, b, ra: r, rb: r * 0.8 },
1053
+ ]);
1054
+ }
1055
+ return shapes;
1056
+ }
1057
+
1058
+ const toLinear = (c: number) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
1059
+ const toDisplay = (c: number) => (c <= 0.0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055);
1060
+
1061
+ /** Makes the hand. Throws with every problem `validateZhudaHand` finds. */
1062
+ export function createZhudaHandMesh(options: ZhudaHandOptions = {}): ZhudaHandMesh {
1063
+ const errors = validateZhudaHand(options);
1064
+ if (errors.length) throw Error(`Invalid hand: ${errors.join('; ')}`);
1065
+ const o: Resolved = {
1066
+ build: { ...NEUTRAL_BUILD, ...options.build } as Required<ZhudaHandBuild>,
1067
+ side: options.side ?? 'right',
1068
+ length: options.length ?? 0.185,
1069
+ breadth: options.breadth ?? 0.082,
1070
+ pose: options.pose ?? {},
1071
+ tone: options.tone ?? [0.86, 0.66, 0.56],
1072
+ cellSize: options.cellSize ?? 0.0009,
1073
+ forearm: options.forearm ?? 0.05,
1074
+ };
1075
+ if (o.build.tendons < 0) o.build.tendons = o.build.bone;
1076
+ const pose = { ...ZHUDA_HAND_RELAXED, ...o.pose } as Required<ZhudaHandPose>;
1077
+ const sx = o.breadth / 0.082;
1078
+ const digits = poseDigits(o, pose);
1079
+ const plain = createZhudaSdfField([...palmShapes(digits, o), ...webShapes(digits, sx)]);
1080
+ // Each tendon a field of its own, joined to the palm with a fillet as a whole; a narrow
1081
+ // one, since a fillet itself swells the skin by up to a quarter of its width.
1082
+ const trunk = joinZhudaSdfFields(
1083
+ plain,
1084
+ tendonShapes(plain, digits, o).map((pair) => ({
1085
+ field: createZhudaSdfField(pair),
1086
+ blend: 0.004,
1087
+ })),
1088
+ );
1089
+ const limbs = digits.map((d) => ({
1090
+ field: createZhudaSdfField(digitShapes(d, o.build.bone)),
1091
+ // The little finger joins the hand's edge with a fuller fillet: no corner at its base.
1092
+ blend: d.name === 'thumb' ? 0.012 : d.name === 'little' ? 0.013 : 0.0085,
1093
+ }));
1094
+ const joined = joinZhudaSdfFields(trunk, limbs);
1095
+ // The creases are cut last, into the skin as it is; they reach no deeper than a millimetre,
1096
+ // so only a point that near the surface asks them.
1097
+ const lines = creases(joined, digits, o);
1098
+ const owner: number[] = [];
1099
+ const cuts: ZhudaSdfShape[] = [];
1100
+ lines.forEach((line, i) =>
1101
+ creaseCapsules(line).forEach((shape) => {
1102
+ cuts.push(shape);
1103
+ owner.push(i);
1104
+ }),
1105
+ );
1106
+ const creaseField = createZhudaSdfUnion(cuts, { reach: 0.003 });
1107
+ const body: ZhudaSdfField = {
1108
+ bounds: joined.bounds,
1109
+ nearest: joined.nearest,
1110
+ distance(x, y, z) {
1111
+ const d = joined.distance(x, y, z);
1112
+ if (d > 0.0025 || d < -0.0025) return d;
1113
+ return -zhudaSmoothMin(-d, creaseField.distance(x, y, z), 0.0009);
1114
+ },
1115
+ };
1116
+ // The nails, seated on the skin as it is; then the folds of skin that hold them.
1117
+ const nailFields = digits.map((d) => nailField(body, d, o.build));
1118
+ const folds = createZhudaSdfUnion(
1119
+ nailFields.flatMap((n) => nailFolds(n, sx)),
1120
+ { reach: 0.003 },
1121
+ );
1122
+ const held: ZhudaSdfField = {
1123
+ bounds: body.bounds,
1124
+ nearest: body.nearest,
1125
+ distance(x, y, z) {
1126
+ const d = body.distance(x, y, z);
1127
+ if (d > 0.003 || d < -0.003) return d;
1128
+ return zhudaSmoothMin(d, folds.distance(x, y, z), 0.0011);
1129
+ },
1130
+ };
1131
+ /** How much a crease darkens a point of the skin: its strength in its bottom, none at its edge. */
1132
+ const creaseAt = (q: V) => {
1133
+ const i = creaseField.nearest(...q);
1134
+ if (i < 0) return 0;
1135
+ const line = lines[owner[i]];
1136
+ // Inside a capsule by more than its radius less its depth is the bottom of the crease.
1137
+ const inside = -creaseField.distance(...q) - (line.width / 2 - line.depth);
1138
+ return line.strength * smooth(-0.0002 * sx, line.depth, inside);
1139
+ };
1140
+ // A left hand is the right one seen in a mirror across x: the field is read mirrored.
1141
+ const m = o.side === 'left' ? -1 : 1;
1142
+ const mirror = (p: V): V => [p[0] * m, p[1], p[2]];
1143
+ const distance = (x: number, y: number, z: number) => held.distance(x * m, y, z);
1144
+ const bmin = mirror(body.bounds.min),
1145
+ bmax = mirror(body.bounds.max);
1146
+ const min: V = [Math.min(bmin[0], bmax[0]), body.bounds.min[1], body.bounds.min[2]];
1147
+ const max: V = [Math.max(bmin[0], bmax[0]), body.bounds.max[1], body.bounds.max[2]];
1148
+ // The forearm is cut where it leaves the box: the mesh is closed at its end by a plane.
1149
+ const cut = -o.forearm + 0.004;
1150
+ const closed = (x: number, y: number, z: number) => Math.max(distance(x, y, z), cut - y);
1151
+ min[1] = Math.max(min[1], cut - 0.004);
1152
+
1153
+ const sy = palmScale(o);
1154
+ const veinLines = VEINS.map((line) => line.map(([x, y]) => [x * sx, y * sy] as [number, number]));
1155
+ const tone = o.tone.map(toLinear) as V;
1156
+ const palmTone = mix(tone, mul(tone, 1), 0).map((v, k) => v * [1.06, 1.0, 1.0][k]) as V;
1157
+ const flush: V = [0.82, 0.42, 0.36].map(toLinear) as V;
1158
+ const palmNormalDot = (n: V) => -n[2];
1159
+ const skin = createZhudaIsosurfaceMesh({
1160
+ distance: closed,
1161
+ min,
1162
+ max,
1163
+ cellSize: o.cellSize,
1164
+ project: 3,
1165
+ uv: (p) => [p[0] * m, p[1]],
1166
+ color: (p, n) => {
1167
+ const q = mirror(p);
1168
+ const nq = mirror(n);
1169
+ const part = body.nearest(...q);
1170
+ // The palm's rule: its own palm side, its knuckles.
1171
+ const palmRule = {
1172
+ side: palmNormalDot(nq),
1173
+ flush:
1174
+ smooth(0.07 * palmScale(o), 0.095 * palmScale(o), q[1]) *
1175
+ 0.35 *
1176
+ Math.max(-palmNormalDot(nq), 0),
1177
+ };
1178
+ let palmSide = palmRule.side;
1179
+ let flushAmount = palmRule.flush;
1180
+ if (part >= 0) {
1181
+ const d = digits[part];
1182
+ let best = 0,
1183
+ bestU = 0,
1184
+ bestD = Infinity;
1185
+ d.segments.forEach((s, i) => {
1186
+ const L = Math.hypot(...sub(s.b, s.a));
1187
+ const u = Math.min(Math.max(dot(sub(q, s.a), s.dir), 0), L);
1188
+ const dist = Math.hypot(...sub(q, add(s.a, mul(s.dir, u))));
1189
+ if (dist < bestD) {
1190
+ bestD = dist;
1191
+ best = i;
1192
+ bestU = u / L;
1193
+ }
1194
+ });
1195
+ const side = -dot(nq, d.segments[best].dorsal);
1196
+ // Warmer over the joints on the back (the knuckle where the finger starts too) and at
1197
+ // the tips, fading along the bone rather than in rings.
1198
+ const top = Math.max(-side, 0) ** 2;
1199
+ const atJoint =
1200
+ best === 0
1201
+ ? Math.max(1 - smooth(0, 0.35, bestU), smooth(0.7, 1, bestU))
1202
+ : best === 1
1203
+ ? Math.max(1 - smooth(0, 0.3, bestU), smooth(0.75, 1, bestU))
1204
+ : 1 - smooth(0, 0.3, bestU);
1205
+ const tip = best === 2 ? smooth(0.45, 1, bestU) * smooth(-0.4, 0.6, side) : 0;
1206
+ const digitFlush = Math.max(atJoint * 0.3 * top, tip * 0.45);
1207
+ // Where the finger meets the palm the two rules blend, so no seam shows.
1208
+ const w = smooth(-0.004, 0.004, trunk.distance(...q) - limbs[part].field.distance(...q));
1209
+ palmSide = palmRule.side + (side - palmRule.side) * w;
1210
+ flushAmount = palmRule.flush + (digitFlush - palmRule.flush) * w;
1211
+ }
1212
+ const palm = smooth(-0.1, 0.5, palmSide);
1213
+ let c = mix(tone, palmTone, palm);
1214
+ // The palm side is paler and pinker; its pads redder.
1215
+ c = mix(c, [c[0] * 1.02, c[1] * 0.9, c[2] * 0.9], palm * 0.6);
1216
+ c = mix(c, flush, Math.min(flushAmount * o.build.flush, 0.85));
1217
+ // A fine darker line where the skin meets a nail, round its root and sides.
1218
+ for (const nail of nailFields) {
1219
+ const e = nail.distance(...q);
1220
+ if (e < 0.0012 * sx)
1221
+ c = mix(c, [c[0] * 0.86, c[1] * 0.74, c[2] * 0.72], 1 - smooth(0.0002, 0.0012 * sx, e));
1222
+ }
1223
+ // Darker and a little redder in the bottom of a crease.
1224
+ const crease = creaseAt(q);
1225
+ c = mix(c, [c[0] * 0.8, c[1] * 0.68, c[2] * 0.66], crease);
1226
+ // Veins under the skin of the back, bluer where they run.
1227
+ if (o.build.veins > 0 && part < 0 && nq[2] > 0.15) {
1228
+ let vein = 0;
1229
+ veinLines.forEach((line, k) => {
1230
+ let near = Infinity,
1231
+ at = 0,
1232
+ run = 0;
1233
+ const total = line
1234
+ .slice(1)
1235
+ .reduce((n, p, i) => n + Math.hypot(p[0] - line[i][0], p[1] - line[i][1]), 0);
1236
+ for (let i = 0; i < line.length - 1; i++) {
1237
+ const a = line[i],
1238
+ b2 = line[i + 1];
1239
+ const ab = [b2[0] - a[0], b2[1] - a[1]],
1240
+ ap = [q[0] - a[0], q[1] - a[1]];
1241
+ const length = Math.hypot(ab[0], ab[1]);
1242
+ const t = Math.min(
1243
+ Math.max((ap[0] * ab[0] + ap[1] * ab[1]) / (ab[0] ** 2 + ab[1] ** 2), 0),
1244
+ 1,
1245
+ );
1246
+ const d = Math.hypot(ap[0] - ab[0] * t, ap[1] - ab[1] * t);
1247
+ if (d < near) {
1248
+ near = d;
1249
+ at = (run + t * length) / total;
1250
+ }
1251
+ run += length;
1252
+ }
1253
+ const w = 0.0016 * sx;
1254
+ // A vein comes up out of the skin and goes back under it: faint at its two ends.
1255
+ const ends = smooth(0, 0.3, at) * (1 - smooth(0.85, 1, at));
1256
+ vein = Math.max(vein, Math.exp(-((near / w) ** 2)) * VEIN_STRENGTH[k] * ends);
1257
+ });
1258
+ vein *= o.build.veins * smooth(0.15, 0.6, nq[2]);
1259
+ c = mix(c, [c[0] * 0.8, c[1] * 0.86, c[2] * 1.04], vein * 0.7);
1260
+ }
1261
+ // How thick the hand is here: along the normal, and, where the palm's skin faces the
1262
+ // front, also straight through the hand, the shorter. (Along the normal alone, a slope of the
1263
+ // heel sent the line lengthwise through the wrist: the heel read far thicker than the
1264
+ // palm above it, and the light through the palm stopped there in a straight edge.)
1265
+ let depth = zhudaSdfDepthAlong(distance, sub(p, mul(n, 0.0004)), mul(n, -1), 0.06);
1266
+ // Faded in as the skin turns to face front or back: switched on at once, it made bands
1267
+ // down the sides where it switched.
1268
+ // On the palm's side only, where the heel's slope was the trouble.
1269
+ const facing = part < 0 ? smooth(0.15, 0.6, -n[2]) : 0;
1270
+ if (facing > 0) {
1271
+ const through: V = [0, 0, 1];
1272
+ const across = zhudaSdfDepthAlong(distance, sub(p, mul(n, 0.0004)), through, 0.06);
1273
+ depth += (Math.min(depth, across) - depth) * facing;
1274
+ }
1275
+ const thin = Math.exp(-depth / 0.016);
1276
+ return [toDisplay(c[0]), toDisplay(c[1]), toDisplay(c[2]), thin];
1277
+ },
1278
+ });
1279
+
1280
+ // Nails: meshed finer than the skin.
1281
+ const parts: MeshData[] = [];
1282
+ const bed = o.build.nailTone;
1283
+ for (const nail of nailFields) {
1284
+ const nm = (p: V) => mirror(p);
1285
+ const mn = mirror(nail.min),
1286
+ mx = mirror(nail.max);
1287
+ parts.push(
1288
+ createZhudaIsosurfaceMesh({
1289
+ distance: (x, y, z) => nail.distance(x * m, y, z),
1290
+ min: [Math.min(mn[0], mx[0]), nail.min[1], nail.min[2]],
1291
+ max: [Math.max(mn[0], mx[0]), nail.max[1], nail.max[2]],
1292
+ cellSize: Math.min(o.cellSize * 0.3, 0.00026),
1293
+ project: 3,
1294
+ uv: (p) => {
1295
+ const q = nm(p);
1296
+ return [dot(sub(q, nail.s.a), nail.s.lateral), dot(sub(q, nail.s.a), nail.s.dir)];
1297
+ },
1298
+ color: (p) => {
1299
+ const q = nm(p);
1300
+ const u = dot(sub(q, nail.s.a), nail.s.dir);
1301
+ // Pink where the bed is under it, a pale half-moon at the root, white and clearer
1302
+ // where there is no skin under it.
1303
+ const gap = body.distance(...q);
1304
+ const free = smooth(0.0011, 0.0019, gap) * smooth(nail.uFlesh - 0.001, nail.uFlesh, u);
1305
+ const moon = 1 - smooth(nail.u0 + 0.0006, nail.u0 + 0.0024, u);
1306
+ // Paler toward the sides, where the plate turns down into the folds.
1307
+ const side = Math.abs(dot(sub(q, nail.s.a), nail.s.lateral)) / nail.halfWidth;
1308
+ let c = mix(bed, [0.95, 0.88, 0.86], Math.max(moon * 0.55, smooth(0.6, 1, side) * 0.35));
1309
+ c = mix(c, [0.97, 0.91, 0.87], free * 0.8);
1310
+ return [c[0], c[1], c[2], 1];
1311
+ },
1312
+ }),
1313
+ );
1314
+ }
1315
+ const nails = concat(parts);
1316
+
1317
+ const joints: ZhudaHandJoint[] = [];
1318
+ const tips = {} as Record<ZhudaHandDigit, V>;
1319
+ for (const d of digits) {
1320
+ d.joints.forEach((j, index) => joints.push({ digit: d.name, index, position: mirror(j) }));
1321
+ const last = d.segments[2];
1322
+ tips[d.name] = mirror(
1323
+ add(last.b, mul(last.dir, surfaceAlong(body, last.b, last.dir, last.rb * 2))),
1324
+ );
1325
+ }
1326
+ return { skin: splitZhudaMesh(skin), nails, joints, tips, side: o.side };
1327
+ }
1328
+
1329
+ function concat(parts: MeshData[]): MeshData {
1330
+ const count = parts.reduce((n, p) => n + p.positions.length / 3, 0);
1331
+ if (count > 65535) throw Error('The nails need more than 65535 vertices; give a larger cellSize');
1332
+ const positions = new Float32Array(count * 3),
1333
+ normals = new Float32Array(count * 3),
1334
+ uvs = new Float32Array(count * 2),
1335
+ colors = new Float32Array(count * 4);
1336
+ const indices = new Uint16Array(parts.reduce((n, p) => n + p.indices.length, 0));
1337
+ let v = 0,
1338
+ i = 0;
1339
+ for (const p of parts) {
1340
+ positions.set(p.positions, v * 3);
1341
+ normals.set(p.normals!, v * 3);
1342
+ uvs.set(p.uvs!, v * 2);
1343
+ colors.set(p.colors!, v * 4);
1344
+ for (let k = 0; k < p.indices.length; k++) indices[i + k] = p.indices[k] + v;
1345
+ v += p.positions.length / 3;
1346
+ i += p.indices.length;
1347
+ }
1348
+ return { positions, normals, uvs, colors, indices };
1349
+ }
1350
+
1351
+ export interface ZhudaHandSurfaceOptions {
1352
+ /** A prefix for the two shader names (each name is a shader contract: one per look, not per hand). */
1353
+ name: string;
1354
+ /** How much fine creasing shows close up (0 to 2; default 1). */
1355
+ detail?: number;
1356
+ /** Faint blotches of colour across the skin (0 to 2; default 1). */
1357
+ mottle?: number;
1358
+ /** The skin's roughness between its creases (0.25 to 0.8; default 0.48). */
1359
+ roughness?: number;
1360
+ /** The colour light takes through skin, as light (default 1, 0.3, 0.2). */
1361
+ subsurfaceColor?: [number, number, number];
1362
+ }
1363
+
1364
+ /**
1365
+ * The lit surfaces a `createZhudaHandMesh` hand is drawn with: skin that reads
1366
+ * the mesh's tint and thinness, light round and through it, a soft network of
1367
+ * fine creases that fades out where it would be smaller than a pixel,
1368
+ * faint blotches of colour; and glossy nails. Pass each to
1369
+ * `new ZhudaLitSurfaceMaterial(spec)`, and give the skin the hand's place
1370
+ * with `setZhudaHandSkinSpace` whenever the hand moves, turns or scales: the
1371
+ * fine pattern is in the hand's own space and stays on it.
1372
+ */
1373
+ export function createZhudaHandSurfaces(options: ZhudaHandSurfaceOptions): {
1374
+ skin: ZhudaLitSurfaceSpec;
1375
+ nail: ZhudaLitSurfaceSpec;
1376
+ } {
1377
+ const errors: string[] = [];
1378
+ if (typeof options?.name !== 'string' || !/^[A-Za-z][A-Za-z0-9_]*$/.test(options.name))
1379
+ errors.push('name must be letters, digits and _, starting with a letter');
1380
+ const num = (v: unknown, label: string, lo: number, hi: number, d: number) => {
1381
+ if (v === undefined) return d;
1382
+ if (!(finite(v) && (v as number) >= lo && (v as number) <= hi))
1383
+ errors.push(`${label} must be a number from ${lo} to ${hi}`);
1384
+ return v as number;
1385
+ };
1386
+ const detail = num(options?.detail, 'detail', 0, 2, 1);
1387
+ const mottle = num(options?.mottle, 'mottle', 0, 2, 1);
1388
+ const roughness = num(options?.roughness, 'roughness', 0.25, 0.8, 0.48);
1389
+ const sss = options?.subsurfaceColor ?? [1, 0.3, 0.2];
1390
+ if (!Array.isArray(sss) || sss.length !== 3 || !sss.every((v) => finite(v) && v >= 0 && v <= 1))
1391
+ errors.push('subsurfaceColor must be three numbers from 0 to 1');
1392
+ if (errors.length) throw Error(`Invalid hand surfaces: ${errors.join('; ')}`);
1393
+ const f = (v: number) => v.toFixed(4);
1394
+ const skin: ZhudaLitSurfaceSpec = {
1395
+ name: `${options.name}Skin`,
1396
+ common: true,
1397
+ material: { roughness, metallic: 0 },
1398
+ subsurface: {
1399
+ color: [...sss] as [number, number, number],
1400
+ wrap: 0.45,
1401
+ back: 1.6,
1402
+ power: 3,
1403
+ distortion: 0.25,
1404
+ },
1405
+ // The faint soft glow skin has where it turns from the eye.
1406
+ sheen: { color: [0.26, 0.22, 0.2], roughness: 0.55 },
1407
+ // The world-to-hand transform, a row each (`setZhudaHandSkinSpace`).
1408
+ uniforms: {
1409
+ u_ZhudaSkinX: { type: 'vec4', value: [1, 0, 0, 0] },
1410
+ u_ZhudaSkinY: { type: 'vec4', value: [0, 1, 0, 0] },
1411
+ u_ZhudaSkinZ: { type: 'vec4', value: [0, 0, 1, 0] },
1412
+ },
1413
+ surface: `float zhudaSkinRelief(vec3 q){
1414
+ // Creases: where a noise crosses its middle, a network of soft lines about half a
1415
+ // millimetre apart. (A finer layer and pores broke into dark dots: thinner than a pixel.)
1416
+ float a=1.0-abs(2.0*zhudaNoise(q*1800.0)-1.0);
1417
+ return -smoothstep(0.8,1.0,a);
1418
+ }
1419
+ vec3 zhudaSkinSpace(vec3 p){
1420
+ vec4 w=vec4(p,1.0);
1421
+ return vec3(dot(u_ZhudaSkinX,w),dot(u_ZhudaSkinY,w),dot(u_ZhudaSkinZ,w));
1422
+ }
1423
+ void zhudaSurface(inout ZhudaLitSurface s, vec2 uv, vec3 p, vec3 n) {
1424
+ s.baseColor *= s.vertexColor.rgb;
1425
+ s.thickness = s.vertexColor.a;
1426
+ vec3 q = zhudaSkinSpace(p);
1427
+ // Faint blotches: a little redder here, a little paler there.
1428
+ float m = zhudaFbm(q * 70.0) - 0.5;
1429
+ s.baseColor *= mix(vec3(1.0), vec3(1.05, 0.95, 0.94), clamp(m * 2.2 * ${f(mottle)}, -1.0, 1.0));
1430
+ // The fine relief, faded out where a pixel is wider than about a quarter millimetre.
1431
+ float footprint = max(length(dFdx(p)), length(dFdy(p)));
1432
+ float show = ${f(detail)} * (1.0 - smoothstep(0.00009, 0.00022, footprint));
1433
+ float r = ${f(roughness)};
1434
+ if (show > 0.001) {
1435
+ float e = 0.00004;
1436
+ float h0 = zhudaSkinRelief(q);
1437
+ float ht = zhudaSkinRelief(zhudaSkinSpace(p + s.tangent * e));
1438
+ float hb = zhudaSkinRelief(zhudaSkinSpace(p + s.bitangent * e));
1439
+ // The slope across the surface, a 0.05 mm relief.
1440
+ vec2 slope = vec2(ht - h0, hb - h0) / e * 0.00005 * show;
1441
+ s.normalTS = normalize(vec3(-slope, 1.0));
1442
+ r = mix(r, 0.62, clamp(-h0 * 0.6 * show, 0.0, 1.0));
1443
+ }
1444
+ s.roughness = r;
1445
+ }`,
1446
+ };
1447
+ const nail: ZhudaLitSurfaceSpec = {
1448
+ name: `${options.name}Nail`,
1449
+ material: { roughness: 0.18, metallic: 0, clearCoat: 0.5, clearCoatRoughness: 0.06 },
1450
+ // A nail is thin and clear: light wraps round it and comes through it, so seen edge on
1451
+ // it is pale, not a dark blade.
1452
+ // The light through it takes the bed's pink (a paler one washed the nail out).
1453
+ subsurface: { color: [1, 0.55, 0.5], wrap: 0.6, back: 0.9, power: 2, distortion: 0.2 },
1454
+ surface: `void zhudaSurface(inout ZhudaLitSurface s, vec2 uv, vec3 p, vec3 n) {
1455
+ s.baseColor *= s.vertexColor.rgb;
1456
+ s.thickness = 1.0;
1457
+ }`,
1458
+ };
1459
+ return { skin, nail };
1460
+ }
1461
+
1462
+ /**
1463
+ * Gives a hand's skin (a material made from `createZhudaHandSurfaces().skin`)
1464
+ * the hand's place, so its fine pattern stays on the hand: `worldMatrix` is
1465
+ * the hand node's world matrix as 16 numbers in LayaAir's order (the axes in
1466
+ * 0..2, 4..6, 8..10, the position in 12..14), e.g.
1467
+ * `node.transform.worldMatrix.elements`. Call it when the hand moves.
1468
+ */
1469
+ export function setZhudaHandSkinSpace(
1470
+ skin: { set(name: string, value: readonly number[]): void },
1471
+ worldMatrix: ArrayLike<number>,
1472
+ ): void {
1473
+ if (!worldMatrix || worldMatrix.length < 16) throw Error('worldMatrix must be 16 numbers');
1474
+ const m = Array.from({ length: 16 }, (_, i) => worldMatrix[i]);
1475
+ if (!m.every(finite)) throw Error('worldMatrix must be 16 finite numbers');
1476
+ // The 3 by 3 part, a column an axis: world = A * local + t.
1477
+ const a = [
1478
+ [m[0], m[4], m[8]],
1479
+ [m[1], m[5], m[9]],
1480
+ [m[2], m[6], m[10]],
1481
+ ];
1482
+ const t = [m[12], m[13], m[14]];
1483
+ const det =
1484
+ a[0][0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1]) -
1485
+ a[0][1] * (a[1][0] * a[2][2] - a[1][2] * a[2][0]) +
1486
+ a[0][2] * (a[1][0] * a[2][1] - a[1][1] * a[2][0]);
1487
+ if (!(Math.abs(det) > 1e-12)) throw Error('worldMatrix cannot be inverted');
1488
+ const inv = [
1489
+ [
1490
+ (a[1][1] * a[2][2] - a[1][2] * a[2][1]) / det,
1491
+ (a[0][2] * a[2][1] - a[0][1] * a[2][2]) / det,
1492
+ (a[0][1] * a[1][2] - a[0][2] * a[1][1]) / det,
1493
+ ],
1494
+ [
1495
+ (a[1][2] * a[2][0] - a[1][0] * a[2][2]) / det,
1496
+ (a[0][0] * a[2][2] - a[0][2] * a[2][0]) / det,
1497
+ (a[0][2] * a[1][0] - a[0][0] * a[1][2]) / det,
1498
+ ],
1499
+ [
1500
+ (a[1][0] * a[2][1] - a[1][1] * a[2][0]) / det,
1501
+ (a[0][1] * a[2][0] - a[0][0] * a[2][1]) / det,
1502
+ (a[0][0] * a[1][1] - a[0][1] * a[1][0]) / det,
1503
+ ],
1504
+ ];
1505
+ // local = inv * (world - t): a row each, with its offset in w.
1506
+ const rows = inv.map((r) => [r[0], r[1], r[2], -(r[0] * t[0] + r[1] * t[1] + r[2] * t[2])]);
1507
+ skin.set('u_ZhudaSkinX', rows[0]);
1508
+ skin.set('u_ZhudaSkinY', rows[1]);
1509
+ skin.set('u_ZhudaSkinZ', rows[2]);
1510
+ }