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 @@
1
+ !function(t,e){"use strict";class i extends e.EventDispatcher{static get instance(){return i._instance=i._instance||new i,i._instance}constructor(){super()}onStartListeningToType(t){return t===e.Event.CHANGE&&e.PAL.device.on("devicemotion",this,this.onDeviceMotionChange),this}onDeviceMotionChange(t,i,a,n){this.event(e.Event.CHANGE,[t,i,n,a])}static getTransformedAcceleration(t){i.transformedAcceleration=i.transformedAcceleration||{x:0,y:0,z:0},i.transformedAcceleration.z=t.z;let a,n=e.PAL.browser.getScreenOrientation();return"landscape-primary"===n?(i.transformedAcceleration.x=t.y,i.transformedAcceleration.y=-t.x):"landscape-secondary"===n?(i.transformedAcceleration.x=-t.y,i.transformedAcceleration.y=t.x):"portrait-primary"===n?(i.transformedAcceleration.x=t.x,i.transformedAcceleration.y=t.y):"portrait-secondary"===n&&(i.transformedAcceleration.x=-t.x,i.transformedAcceleration.y=-t.y),-90==e.ILaya.stage.canvasDegree?(a=i.transformedAcceleration.x,i.transformedAcceleration.x=-i.transformedAcceleration.y,i.transformedAcceleration.y=a):90==e.ILaya.stage.canvasDegree&&(a=i.transformedAcceleration.x,i.transformedAcceleration.x=i.transformedAcceleration.y,i.transformedAcceleration.y=-a),i.transformedAcceleration}}class a extends e.EventDispatcher{static get instance(){return a._instance=a._instance||new a,a._instance}start(t,a){this.threshold=t,this.shakeInterval=a,this.lastX=this.lastY=this.lastZ=NaN,i.instance.on(e.Event.CHANGE,this,this.onShake)}stop(){i.instance.off(e.Event.CHANGE,this,this.onShake)}onShake(t,i,a,n){if(isNaN(this.lastX))return this.lastX=i.x,this.lastY=i.y,this.lastZ=i.z,void(this.lastMillSecond=performance.now());let o=Math.abs(this.lastX-i.x),s=Math.abs(this.lastY-i.y),c=Math.abs(this.lastZ-i.z);if(this.isShaked(o,s,c)){performance.now()-this.lastMillSecond>this.shakeInterval&&(this.event(e.Event.CHANGE),this.lastMillSecond=performance.now())}this.lastX=i.x,this.lastY=i.y,this.lastZ=i.z}isShaked(t,e,i){const a=(t>this.threshold?1:0)|(e>this.threshold?2:0)|(i>this.threshold?4:0);return!!(a&a-1)}}class n extends e.DeviceAdapter{constructor(){var t;super(),this._locInfo={timestamp:0,accuracy:0,altitude:0,altitudeAccuracy:0,heading:0,latitude:0,longitude:0,speed:0},this._accInfo={x:0,y:0,z:0},this._accInfo2=Object.assign({},this._accInfo),this._rotInfo={alpha:0,beta:0,gamma:0,absolute:!1,compassAccuracy:0},this._rotInfo2=Object.assign({},this._rotInfo);let i=e.Browser.window.navigator;i&&(this._loc=i.geolocation,this._getUserMedia=(null===(t=i.mediaDevices)||void 0===t?void 0:t.getUserMedia)||i.getUserMedia)}get supportedLocation(){return!!this._loc}get supportedGetUserMedia(){return!!this._getUserMedia}getCurrentPosition(t,e,i){this._loc?this._loc.getCurrentPosition(e=>{Object.assign(this._locInfo,e.coords),this._locInfo.timestamp=e.timestamp,t(this._locInfo)},t=>null==e?void 0:e(t),i):e&&e(o)}watchPosition(t,e,i){return this._loc?this._loc.watchPosition(e=>{Object.assign(this._locInfo,e.coords),this._locInfo.timestamp=e.timestamp,t(this._locInfo)},t=>null==e?void 0:e(t),i):e?(e(o),-1):-1}clearWatchPosition(t){this._loc&&this._loc.clearWatch(t)}getUserMedia(t,e,i){this._getUserMedia?this._getUserMedia(t).then(t=>e(t)).catch(t=>null==i?void 0:i(t)):null==i||i(new Error("getUserMedia is not supported."))}startListeningDeviceMotion(){e.Browser.window.addEventListener("devicemotion",t=>this.onDeviceMotion(t))}startListeningDeviceOrientation(){e.Browser.window.addEventListener("deviceorientation",t=>this.onDeviceOrientation(t))}onDeviceMotion(t){this._accInfo.x=t.acceleration.x,this._accInfo.y=t.acceleration.y,this._accInfo.z=t.acceleration.z,this._accInfo2.x=t.accelerationIncludingGravity.x,this._accInfo2.y=t.accelerationIncludingGravity.y,this._accInfo2.z=t.accelerationIncludingGravity.z,this._rotInfo.alpha=-1*t.rotationRate.gamma,this._rotInfo.beta=-1*t.rotationRate.alpha,this._rotInfo.gamma=t.rotationRate.beta,t.interval,e.Browser.onAndroid?(e.Browser.userAgent.indexOf("Chrome")>-1&&(this._rotInfo.alpha*=180/Math.PI,this._rotInfo.beta*=180/Math.PI,this._rotInfo.gamma*=180/Math.PI),this._accInfo.x*=-1,this._accInfo2.x*=-1):e.Browser.onIOS&&(this._accInfo.y*=-1,this._accInfo.z*=-1,this._accInfo2.y*=-1,this._accInfo2.z*=-1),this.event("devicemotion",[this._accInfo,this._accInfo2,this._rotInfo,t.interval])}onDeviceOrientation(t){this._rotInfo2.alpha=t.alpha,this._rotInfo2.beta=t.beta,this._rotInfo2.gamma=t.gamma,t.webkitCompassHeading&&(this._rotInfo2.alpha=-1*t.webkitCompassHeading,this._rotInfo2.compassAccuracy=t.webkitCompassAccuracy),this.event("deviceorientation",[t.absolute,this._rotInfo2])}}const o={code:9,message:"Geolocation is not supported."};e.PAL.register("device",n);class s{static getCurrentPosition(t,i){e.PAL.device.getCurrentPosition(i=>{t instanceof e.Handler?t.runWith(i):t(i)},t=>{i instanceof e.Handler?i.runWith(t):i&&i(t)},{enableHighAccuracy:s.enableHighAccuracy,timeout:s.timeout,maximumAge:s.maximumAge})}static watchPosition(t,i){return e.PAL.device.watchPosition(i=>{t instanceof e.Handler?t.runWith(i):t(i)},t=>{i instanceof e.Handler?i.runWith(t):i&&i(t)},{enableHighAccuracy:s.enableHighAccuracy,timeout:s.timeout,maximumAge:s.maximumAge})}static clearWatch(t){e.PAL.device.clearWatchPosition(t)}}s.PERMISSION_DENIED=1,s.POSITION_UNAVAILABLE=2,s.TIMEOUT=3,s.enableHighAccuracy=!1,s.timeout=1e10,s.maximumAge=0;class c extends e.EventDispatcher{static get instance(){return c._instance=c._instance||new c,c._instance}onStartListeningToType(t){return t===e.Event.CHANGE&&e.PAL.device.on("deviceorientation",this,this.onDeviceOrientation),this}onDeviceOrientation(t,i){this.event(e.Event.CHANGE,[t,i])}}t.Accelerator=i,t.Geolocation=s,t.Gyroscope=c,t.Media=class{static supported(){return e.PAL.device.supportedGetUserMedia}static getMedia(t,i,a){e.PAL.device.getUserMedia(t,t=>{i instanceof e.Handler?i.runWith(t):i(t)},t=>{a instanceof e.Handler?a.runWith(t):a&&a(t)})}},t.Shake=a,t.WebDeviceAdapter=n}(window.Laya=window.Laya||{},Laya);
@@ -0,0 +1 @@
1
+ !function(e,r){"use strict";class t{static init(){this.Define_BaseColorMap=r.Shader3D.getDefineByName("BASECOLORMAP"),this.Define_BaseColorMapTransform=r.Shader3D.getDefineByName("BASECOLORMAP_TRANSFORM"),this.Define_MetallicRoughnessMap=r.Shader3D.getDefineByName("METALLICROUGHNESSMAP"),this.Define_MetallicRoughnessMapTransform=r.Shader3D.getDefineByName("METALLICROUGHNESSMAP_TRANSFORM"),this.Define_NormalMap=r.Shader3D.getDefineByName("NORMALMAP"),this.Define_NormalMapTransform=r.Shader3D.getDefineByName("NORMALMAP_TRANSFORM"),this.Define_OcclusionMap=r.Shader3D.getDefineByName("OCCLUSIONMAP"),this.Define_OcclusionMapTransform=r.Shader3D.getDefineByName("OCCLUSIONMAP_TRANSFORM"),this.Define_EmissionMap=r.Shader3D.getDefineByName("EMISSIONMAP"),this.Define_EmissionMapTransform=r.Shader3D.getDefineByName("EMISSIONMAP_TRANSFORM"),this.Define_ClearCoatMap=r.Shader3D.getDefineByName("CLEARCOATMAP"),this.Define_ClearCoatMapTransform=r.Shader3D.getDefineByName("CLEARCOATMAP_TRANSFORM"),this.Define_ClearCoatRoughnessMap=r.Shader3D.getDefineByName("CLEARCOAT_ROUGHNESSMAP"),this.Define_ClearCoatRoughnessMapTransform=r.Shader3D.getDefineByName("CLEARCOAT_ROUGHNESSMAP_TRANSFORM"),this.Define_ClearCoatNormalMapTransform=r.Shader3D.getDefineByName("CLEARCOAT_NORMALMAP_TRANSFORM"),this.Define_AnisotropyMap=r.Shader3D.getDefineByName("ANISOTROPYMAP"),this.Define_AnisotropyMapTransform=r.Shader3D.getDefineByName("ANISOTROPYMAP_TRANSFORM"),this.Define_IridescenceMap=r.Shader3D.getDefineByName("IRIDESCENCEMAP"),this.Define_IridescenceMapTransform=r.Shader3D.getDefineByName("IRIDESCENCEMAP_TRANSFORM"),this.Define_IridescenceThicknessMap=r.Shader3D.getDefineByName("IRIDESCENCE_THICKNESSMAP"),this.Define_IridescenceThicknessMapTransform=r.Shader3D.getDefineByName("IRIDESCENCE_THICKNESSMAP_TRANSFORM"),this.Define_SheenColorMap=r.Shader3D.getDefineByName("SHEENCOLORMAP"),this.Define_SheenColorMapTransform=r.Shader3D.getDefineByName("SHEENCOLORMAP_TRANSFORM"),this.Define_SheenRoughnessMap=r.Shader3D.getDefineByName("SHEEN_ROUGHNESSMAP"),this.Define_SheenRoughnessMapTransform=r.Shader3D.getDefineByName("SHEEN_ROUGHNESSMAP_TRANSFORM"),this.Define_TransmissionMap=r.Shader3D.getDefineByName("TRANSMISSIONMAP"),this.Define_TransmissionMapTransform=r.Shader3D.getDefineByName("TRANSMISSIONMAP_TRANSFORM"),this.Define_VolumeThicknessMap=r.Shader3D.getDefineByName("THICKNESSMAP"),this.Define_VolumeThicknessMapTransform=r.Shader3D.getDefineByName("THICKNESSMAP_TRANSFORM"),this.Define_SpecularFactorMap=r.Shader3D.getDefineByName("SPECULARFACTORMAP"),this.Define_SpecularFactorMapTransform=r.Shader3D.getDefineByName("SPECULARFACTORMAP_TRANSFORM"),this.Define_SpecularColorMap=r.Shader3D.getDefineByName("SPECULARCOLORMAP"),this.Define_SpecularColorMapTransform=r.Shader3D.getDefineByName("SPECULARCOLORMAP_TRANSFORM");let e=r.Shader3D.find(t.name);if(e)return;r.Shader3D.addInclude("glTFMetallicRoughness.glsl",'#if !defined(glTFMetallicRoughness_lib)\n#define glTFMetallicRoughness_lib\n#include "ShadingFrag.glsl";\n#include "PBRFrag.glsl";\nstruct SurfaceInputs{vec3 diffuseColor;float alpha;float alphaTest;float metallic;float roughness;float occlusion;vec3 emissionColor;vec3 normalTS;float specular;float specularFactor;vec3 specularColor;\n#ifdef CLEARCOAT\nfloat clearCoat;float clearCoatRoughness;\n#ifdef CLEARCOAT_NORMAL\nvec3 clearCoatNormalTS;\n#endif\n#endif\n#ifdef ANISOTROPIC\nfloat anisotropy;vec2 anisotropyDirection;\n#endif\n#ifdef IOR\nfloat ior;\n#endif\n#ifdef IRIDESCENCE\nfloat iridescence;float iridescenceIor;float iridescenceThickness;\n#endif\n#ifdef SHEEN\nvec3 sheenColor;float sheenRoughness;\n#endif\n#ifdef TRANSMISSION\nfloat transmission;\n#endif\n#ifdef THICKNESS\nfloat thickness;vec3 attenuationColor;float attenuationDistance;\n#endif\n};void initSurface(inout Surface surface,const in SurfaceInputs inputs,const in PixelParams pixel){surface.alpha=inputs.alpha;surface.normalTS=inputs.normalTS;vec3 baseColor=inputs.diffuseColor;float metallic=inputs.metallic;float perceptualRoughness=inputs.roughness;\n#ifdef IOR\nfloat ior=inputs.ior;surface.ior=ior;vec3 f0=vec3(dielectricIorToF0(ior));\n#else\nvec3 f0=vec3(dielectricSpecularToF0(inputs.specular));surface.ior=dielectricF0ToIor(f0.x);\n#endif\nf0*=inputs.specularFactor*inputs.specularColor;surface.perceptualRoughness=max(perceptualRoughness,MIN_PERCEPTUAL_ROUGHNESS);surface.roughness=surface.perceptualRoughness*surface.perceptualRoughness;surface.diffuseColor=computeDiffuse(baseColor,metallic);surface.f0=computeF0(f0,baseColor,metallic);surface.f90=computeF90(surface.f0);surface.occlusion=inputs.occlusion;\n#ifdef EMISSION\nsurface.emissionColor=inputs.emissionColor;\n#endif\n#ifdef IRIDESCENCE\nsurface.iridescence=inputs.iridescence;surface.iridescenceIor=inputs.iridescenceIor;surface.iridescenceThickness=inputs.iridescenceThickness;\n#endif\n#ifdef SHEEN\nsurface.sheenColor=inputs.sheenColor;surface.sheenPerceptualRoughness=max(inputs.sheenRoughness,MIN_PERCEPTUAL_ROUGHNESS);surface.sheenRoughness=pow2(surface.sheenPerceptualRoughness);\n#endif\n#ifdef CLEARCOAT\nsurface.clearCoat=inputs.clearCoat;surface.clearCoatPerceptualRoughness=clamp(inputs.clearCoatRoughness,MIN_PERCEPTUAL_ROUGHNESS,1.0);surface.clearCoatRoughness=surface.clearCoatPerceptualRoughness*surface.clearCoatPerceptualRoughness;\n#ifdef CLEARCOAT_NORMAL\nsurface.clearCoatNormalTS=inputs.clearCoatNormalTS;\n#endif\n#endif\n#ifdef ANISOTROPIC\nsurface.anisotropy=inputs.anisotropy;surface.anisotropyDirection=inputs.anisotropyDirection;\n#endif\n#ifdef TRANSMISSION\nsurface.transmission=inputs.transmission;\n#endif\n#ifdef THICKNESS\nsurface.thickness=inputs.thickness;surface.attenuationColor=inputs.attenuationColor;surface.attenuationDistance=inputs.attenuationDistance;\n#endif\n}vec4 glTFMetallicRoughness(const in SurfaceInputs inputs,in PixelParams pixel){\n#ifdef ALPHATEST\nif(inputs.alpha<inputs.alphaTest){discard;}\n#endif\nSurface surface;initSurface(surface,inputs,pixel);PixelInfo info;getPixelInfo(info,pixel,surface);vec3 surfaceColor=vec3(0.0);surfaceColor+=PBRLighting(surface,info);return vec4(surfaceColor,surface.alpha);}\n#endif\n');let a={u_AlphaTestValue:r.ShaderDataType.Float,u_BaseColorFactor:r.ShaderDataType.Vector4,u_BaseColorTexture:r.ShaderDataType.Texture2D,u_BaseColorMapTransform:r.ShaderDataType.Matrix3x3,u_Specular:r.ShaderDataType.Float,u_MetallicFactor:r.ShaderDataType.Float,u_RoughnessFactor:r.ShaderDataType.Float,u_MetallicRoughnessTexture:r.ShaderDataType.Texture2D,u_MetallicRoughnessMapTransform:r.ShaderDataType.Matrix3x3,u_NormalTexture:r.ShaderDataType.Texture2D,u_NormalMapTransform:r.ShaderDataType.Matrix3x3,u_NormalScale:r.ShaderDataType.Float,u_OcclusionTexture:r.ShaderDataType.Texture2D,u_OcclusionMapTransform:r.ShaderDataType.Matrix3x3,u_OcclusionStrength:r.ShaderDataType.Float,u_EmissionFactor:r.ShaderDataType.Vector3,u_EmissionTexture:r.ShaderDataType.Texture2D,u_EmissionMapTransform:r.ShaderDataType.Matrix3x3,u_EmissionStrength:r.ShaderDataType.Float,u_ClearCoatFactor:r.ShaderDataType.Float,u_ClearCoatTexture:r.ShaderDataType.Texture2D,u_ClearCoatMapTransform:r.ShaderDataType.Matrix3x3,u_ClearCoatRoughness:r.ShaderDataType.Float,u_ClearCoatRoughnessTexture:r.ShaderDataType.Texture2D,u_ClearCoatRoughnessMapTransform:r.ShaderDataType.Matrix3x3,u_ClearCoatNormalTexture:r.ShaderDataType.Texture2D,u_ClearCoatNormalMapTransform:r.ShaderDataType.Matrix3x3,u_ClearCoatNormalScale:r.ShaderDataType.Float,u_AnisotropyStrength:r.ShaderDataType.Float,u_AnisotropyRotation:r.ShaderDataType.Float,u_AnisotropyTexture:r.ShaderDataType.Texture2D,u_AnisotropyMapTransform:r.ShaderDataType.Matrix3x3,u_Ior:r.ShaderDataType.Float,u_IridescenceFactor:r.ShaderDataType.Float,u_IridescenceTexture:r.ShaderDataType.Texture2D,u_IridescenceMapTransform:r.ShaderDataType.Matrix3x3,u_IridescenceIor:r.ShaderDataType.Float,u_IridescenceThicknessMinimum:r.ShaderDataType.Float,u_IridescenceThicknessMaximum:r.ShaderDataType.Float,u_IridescenceThicknessTexture:r.ShaderDataType.Texture2D,u_IridescenceThicknessMapTransform:r.ShaderDataType.Matrix3x3,u_SheenColorFactor:r.ShaderDataType.Vector3,u_SheenColorTexture:r.ShaderDataType.Texture2D,u_SheenColorMapTransform:r.ShaderDataType.Matrix3x3,u_SheenRoughness:r.ShaderDataType.Float,u_SheenRoughnessTexture:r.ShaderDataType.Texture2D,u_SheenRoughnessMapTransform:r.ShaderDataType.Matrix3x3,u_TransmissionFactor:r.ShaderDataType.Float,u_TransmissionTexture:r.ShaderDataType.Texture2D,u_TransmissionMapTransform:r.ShaderDataType.Matrix3x3,u_VolumeThicknessFactor:r.ShaderDataType.Float,u_VolumeThicknessTexture:r.ShaderDataType.Texture2D,u_VoluemThicknessMapTransform:r.ShaderDataType.Matrix3x3,u_VolumeAttenuationDistance:r.ShaderDataType.Float,u_VolumeAttenuationColor:r.ShaderDataType.Vector3,u_SpecularFactor:r.ShaderDataType.Float,u_SpecularFactorTexture:r.ShaderDataType.Texture2D,u_SpecularFactorMapTransfrom:r.ShaderDataType.Matrix3x3,u_SpecularColorFactor:r.ShaderDataType.Vector3,u_SpecularColorTexture:r.ShaderDataType.Texture2D,u_SpecularColorMapTransform:r.ShaderDataType.Matrix3x3},n={u_AlphaTestValue:.5,u_BaseColorFactor:r.Vector4.ONE,u_BaseColorMapTransform:r.Matrix3x3.DEFAULT,u_Specular:.5,u_MetallicFactor:1,u_RoughnessFactor:1,u_MetallicRoughnessMapTransform:r.Matrix3x3.DEFAULT,u_NormalMapTransform:r.Matrix3x3.DEFAULT,u_NormalScale:1,u_OcclusionMapTransform:r.Matrix3x3.DEFAULT,u_OcclusionStrength:1,u_EmissionFactor:r.Vector3.ZERO,u_EmissionMapTransform:r.Matrix3x3.DEFAULT,u_EmissionStrength:1,u_SpecularFactor:1,u_SpecularFactorMapTransfrom:r.Matrix3x3.DEFAULT,u_SpecularColorFactor:r.Vector3.ONE,u_SpecularColorMapTransform:r.Matrix3x3.DEFAULT,u_Ior:1.5,u_ClearCoatFactor:0,u_ClearCoatMapTransform:r.Matrix3x3.DEFAULT,u_ClearCoatRoughness:0,u_ClearCoatRoughnessMapTransform:r.Matrix3x3.DEFAULT,u_ClearCoatNormalMapTransform:r.Matrix3x3.DEFAULT,u_ClearCoatNormalScale:1,u_AnisotropyStrength:0,u_AnisotropyRotation:0,u_AnisotropyMapTransform:r.Matrix3x3.DEFAULT,u_IridescenceFactor:0,u_IridescenceMapTransform:r.Matrix3x3.DEFAULT,u_IridescenceIor:1.33,u_IridescenceThicknessMinimum:100,u_IridescenceThicknessMaximum:400,u_IridescenceThicknessMapTransform:r.Matrix3x3.DEFAULT,u_SheenColorFactor:r.Vector3.ZERO,u_SheenColorMapTransform:r.Matrix3x3.DEFAULT,u_SheenRoughness:0,u_SheenRoughnessMapTransform:r.Matrix3x3.DEFAULT,u_TransmissionFactor:0,u_TransmissionMapTransform:r.Matrix3x3.DEFAULT};e=r.Shader3D.add("glTFPBR",!0,!0),e.shaderType=r.ShaderFeatureType.D3;let s=new r.SubShader(r.SubShader.DefaultAttributeMap,a,n);e.addSubShader(s),s.addShaderPass('#define SHADER_NAME glTFPBRVS\n#include "Math.glsl";\n#include "Scene.glsl";\n#include "SceneFogInput.glsl";\n#include "Camera.glsl";\n#include "Sprite3DVertex.glsl";\n#include "VertexCommon.glsl";\n#include "PBRVertex.glsl";\nvoid main(){Vertex vertex;getVertexParams(vertex);PixelParams pixel;initPixelParams(pixel,vertex);gl_Position=getPositionCS(pixel.positionWS);gl_Position=remapPositionZ(gl_Position);\n#ifdef FOG\nFogHandle(gl_Position.z);\n#endif\n}','#define SHADER_NAME glTFPBRFS\n#include "Color.glsl";\n#include "Scene.glsl";\n#include "SceneFog.glsl";\n#include "Camera.glsl";\n#include "Sprite3DFrag.glsl";\n#include "glTFMetallicRoughness.glsl";\nvoid initSurfaceInputs(inout SurfaceInputs inputs,const in PixelParams pixel){vec2 uv=vec2(0.0);\n#ifdef UV\nuv=pixel.uv0;\n#endif\ninputs.alphaTest=u_AlphaTestValue;inputs.diffuseColor=u_BaseColorFactor.xyz;inputs.alpha=u_BaseColorFactor.w;\n#ifdef COLOR\n#ifdef ENABLEVERTEXCOLOR\ninputs.diffuseColor*=pixel.vertexColor.xyz;inputs.alpha*=pixel.vertexColor.a;\n#endif\n#endif\n#ifdef BASECOLORMAP\nvec2 baseColorUV=uv;\n#ifdef BASECOLORMAP_TRANSFORM\nbaseColorUV=(u_BaseColorMapTransform*vec3(baseColorUV,1.0)).xy;\n#endif\nvec4 baseColorSampler=texture2D(u_BaseColorTexture,baseColorUV);\n#ifdef Gamma_u_BaseColorTexture\nbaseColorSampler=gammaToLinear(baseColorSampler);\n#endif\ninputs.diffuseColor*=baseColorSampler.rgb;inputs.alpha*=baseColorSampler.a;\n#endif\ninputs.specular=u_Specular;inputs.specularFactor=1.0;inputs.specularColor=vec3(1.0);inputs.specularFactor=u_SpecularFactor;\n#ifdef SPECULARFACTORMAP\nvec2 specularFactorUV=uv;\n#ifdef SPECULARFACTORMAP_TRANSFORM\nspecularFactorUV=(u_SpecularFactorMapTransfrom*specularFactorUV).xy;\n#endif\nvec4 specularFactorSampler=texture2D(u_SpecularFactorTexture,specularFactorUV);inputs.specularFactor*=specularFactorSampler.a;\n#endif\ninputs.specularColor=u_SpecularColorFactor;\n#ifdef SPECULARCOLORMAP\nvec2 specularColorUV=uv;\n#ifdef SPECULARFACTORMAP_TRANSFORM\nspecularColorUV=(u_SpecularColorMapTransform*specularColorUV).xy;\n#endif\nvec4 specularColorSampler=texture2D(u_SpecularColorTexture,specularColorUV);\n#ifdef Gamma_u_SpecularColorTexture\nspecularColorSampler=gammaToLinear(specularColorSampler);\n#endif\ninputs.specularColor*=specularColorSampler.rgb;\n#endif\ninputs.metallic=u_MetallicFactor;float roughness=u_RoughnessFactor;\n#ifdef METALLICROUGHNESSMAP\nvec2 metallicUV=uv;\n#ifdef METALLICROUGHNESSMAP_TRANSFORM\nmetallicUV=(u_MetallicRoughnessMapTransform*vec3(metallicUV,1.0)).xy;\n#endif METALLICROUGHNESSMAP_TRANSFORM\nvec4 metallicRoughnessSampler=texture2D(u_MetallicRoughnessTexture,metallicUV);inputs.metallic*=metallicRoughnessSampler.b;roughness*=metallicRoughnessSampler.g;\n#endif\ninputs.roughness=roughness;float occlusion=1.0;\n#ifdef OCCLUSIONMAP\nvec2 occlusionUV=uv;\n#ifdef OCCLUSIONMAP_TRANSFORM\nocclusionUV=(u_OcclusionMapTransform*vec3(occlusionUV,1.0)).xy;\n#endif\nvec4 occlusionSampler=texture2D(u_OcclusionTexture,occlusionUV);\n#ifdef Gamma_u_OcclusionTexture\nocclusionSampler=gammaToLinear(occlusionSampler);\n#endif\nocclusion=occlusionSampler.r;\n#endif\ninputs.occlusion=(1.0-u_OcclusionStrength)+occlusion*u_OcclusionStrength;inputs.emissionColor=u_EmissionFactor*u_EmissionStrength;\n#ifdef EMISSIONMAP\nvec2 emissionUV=uv;\n#ifdef EMISSIONMAP_TRANSFORM\nemissionUV=(u_EmissionMapTransform*vec3(emissionUV,1.0)).xy;\n#endif\nvec4 emissionSampler=texture2D(u_EmissionTexture,emissionUV);\n#ifdef Gamma_u_EmissionTexture\nemissionSampler=gammaToLinear(emissionSampler);\n#endif\ninputs.emissionColor*=emissionSampler.rgb;\n#endif\ninputs.normalTS=vec3(0.0,0.0,1.0);\n#ifdef NORMALMAP\nvec2 normalUV=uv;\n#ifdef NORMALMAP_TRANSFORM\nnormalUV=(u_NormalMapTransform*vec3(normalUV,1.0)).xy;\n#endif\nvec3 normalSampler=texture2D(u_NormalTexture,normalUV).xyz;normalSampler=normalize(normalSampler*2.0-1.0);normalSampler.y*=-1.0;inputs.normalTS=normalScale(normalSampler,u_NormalScale);\n#endif\n#ifdef IOR\ninputs.ior=u_Ior;\n#endif\n#ifdef IRIDESCENCE\nfloat iridescenceFactor=u_IridescenceFactor;\n#ifdef IRIDESCENCEMAP\nvec2 iridescenceUV=uv;\n#ifdef IRIDESCENCEMAP_TRANSFORM\niridescenceUV=(u_IridescenceMapTransform*vec3(iridescenceUV,1.0)).xy;\n#endif\nvec4 iridescenceSampler=texture2D(u_IridescenceTexture,iridescenceUV);iridescenceFactor*=iridescenceSampler.r;\n#endif\nfloat iridescenceThickness=u_IridescenceThicknessMaximum;\n#ifdef IRIDESCENCE_THICKNESSMAP\nvec2 iridescenceThicknessUV=uv;\n#ifdef IRIDESCENCE_THICKNESSMAP_TRANSFORM\niridescenceThicknessUV=(u_IridescenceThicknessMapTransform,vec3(iridescenceThicknessUV,1.0)).xy;\n#endif\nvec4 iridescenceThicknessSampler=texture2D(u_IridescenceThicknessTexture,iridescenceThicknessUV);iridescenceThickness=mix(u_IridescenceThicknessMinimum,u_IridescenceThicknessMaximum,iridescenceThicknessSampler.g);\n#endif\ninputs.iridescence=iridescenceFactor;inputs.iridescenceIor=u_IridescenceIor;inputs.iridescenceThickness=iridescenceThickness;\n#endif\n#ifdef SHEEN\nvec3 sheenColor=u_SheenColorFactor;\n#ifdef SHEENCOLORMAP\nvec2 sheenColorUV=uv;\n#ifdef SHEENCOLORMAP_TRANSFORM\nsheenColorUV=(u_SheenColorMapTransform*vec3(sheenColorUV,1.0)).xy;\n#endif\nvec4 sheenColorSampler=texture2D(u_SheenColorTexture,sheenColorUV);\n#ifdef Gamma_u_SheenColorFactor\nsheenColorSampler=gammaToLinear(sheenColorSampler);\n#endif\nsheenColor*=sheenColorSampler.rgb;\n#endif\nfloat sheenRoughness=u_SheenRoughness;\n#ifdef SHEEN_ROUGHNESSMAP\nvec2 sheenRoughnessUV=uv;\n#ifdef SHEEN_ROUGHNESSMAP_TRANSFORM\nsheenRoughnessUV=(u_SheenRoughnessMapTransform*vec3(sheenRoughnessUV,1.0)).xy;\n#endif\nvec4 sheenRoughnessSampler=texture2D(u_SheenRoughnessTexture,sheenRoughnessUV);sheenRoughness*=sheenRoughnessSampler.a;\n#endif\ninputs.sheenColor=sheenColor;inputs.sheenRoughness=sheenRoughness;\n#endif\n#ifdef CLEARCOAT\ninputs.clearCoat=u_ClearCoatFactor;inputs.clearCoatRoughness=u_ClearCoatRoughness;\n#ifdef CLEARCOATMAP\nvec2 clearCoatUV=uv;\n#ifdef CLEARCOATMAP_TRANSFORM\nclearCoatUV=(u_ClearCoatMapTransform*vec3(clearCoatUV,1.0)).xy;\n#endif\nvec4 clearCoatSampler=texture2D(u_ClearCoatTexture,clearCoatUV);inputs.clearCoat*=clearCoatSampler.r;\n#endif\n#ifdef CLEARCOAT_ROUGHNESSMAP\nvec2 clearCoatRoughnessUV=uv;\n#ifdef CLEARCOAT_ROUGHNESSMAP_TRANSFORM\nclearCoatRoughnessUV=(u_ClearCoatRoughnessMapTransform*vec3(uv,1.0)).xy;\n#endif\nvec4 clearcoatSampleRoughness=texture2D(u_ClearCoatRoughnessTexture,clearCoatRoughnessUV);inputs.clearCoatRoughness*=clearcoatSampleRoughness.g;\n#endif\n#ifdef CLEARCOAT_NORMAL\nvec2 clearCoatNormalUV=uv;\n#ifdef CLEARCOAT_NORMALMAP_TRANSFORM\nclearCoatNormalUV=(u_ClearCoatNormalMapTransform*vec3(clearCoatNormalUV,1.0)).xy;\n#endif\nvec3 clearCoatNormalSampler=texture2D(u_ClearCoatNormalTexture,clearCoatNormalUV).rgb;clearCoatNormalSampler=normalize(clearCoatNormalSampler*2.0-1.0);clearCoatNormalSampler.y*=-1.0;inputs.clearCoatNormalTS=normalScale(clearCoatNormalSampler,u_ClearCoatNormalScale);\n#endif\n#endif\n#ifdef ANISOTROPIC\ninputs.anisotropy=u_AnisotropyStrength;vec2 direction=vec2(1.0,0.0);\n#ifdef ANISOTROPYMAP\nvec2 anisotropyUV=uv;\n#ifdef ANISOTROPYMAP_TRANSFORM\nanisotropyUV=(u_AnisotropyMapTransform*vec3(anisotropyUV,1.0)).xy;\n#endif\nvec3 anisotropySampler=texture2D(u_AnisotropyTexture,anisotropyUV).rgb;inputs.anisotropy*=anisotropySampler.b;direction=anisotropySampler.xy*2.0-1.0;\n#endif\nvec2 anisotropyRotation=vec2(cos(u_AnisotropyRotation),sin(u_AnisotropyRotation));mat2 rotationMatrix=mat2(anisotropyRotation.x,anisotropyRotation.y,-anisotropyRotation.y,anisotropyRotation.x);inputs.anisotropyDirection=rotationMatrix*direction;\n#endif\n#ifdef TRANSMISSION\nfloat transmission=u_TransmissionFactor;\n#ifdef TRANSMISSIONMAP\nvec2 transmissionUV=uv;\n#ifdef TRANSMISSIONMAP_TRANSFORM\ntransmissionUV=(u_TransmissionMapTransform*vec3(transmissionUV,1.0)).xy;\n#endif\nvec4 transmissionSampler=texture2D(u_TransmissionTexture,transmissionUV);transmission*=transmissionSampler.r;\n#endif\ninputs.transmission=transmission;\n#endif\n#ifdef THICKNESS\nfloat thicknessFactor=u_VolumeThicknessFactor;float attenuationDistance=u_VolumeAttenuationDistance;vec3 attenuationColor=u_VolumeAttenuationColor.xyz;\n#ifdef THICKNESSMAP\nvec2 thicknessUV=uv;\n#ifdef THICKNESSMAP_TRANSFORM\nthicknessUV=(u_VoluemThicknessMapTransform*vec3(thicknessUV,1.0)).xy;\n#endif\nvec4 thicknessSampler=texture2D(u_VolumeThicknessTexture,thicknessUV);thicknessFactor*=thicknessSampler.g;\n#endif\ninputs.thickness=thicknessFactor;inputs.attenuationColor=attenuationColor;inputs.attenuationDistance=attenuationDistance;\n#endif\n}void main(){\n#ifndef DEBUG\nPixelParams pixel;getPixelParams(pixel);SurfaceInputs inputs;initSurfaceInputs(inputs,pixel);vec4 surfaceColor=glTFMetallicRoughness(inputs,pixel);\n#ifdef FOG\nsurfaceColor.rgb=sceneLitFog(surfaceColor.rgb);\n#endif\ngl_FragColor=surfaceColor;\n#else DEBUG\nPixelParams pixel;getPixelParams(pixel);SurfaceInputs inputs;initSurfaceInputs(inputs,pixel);Surface surface;initSurface(surface,inputs,pixel);PixelInfo info;getPixelInfo(info,pixel,surface);vec3 debug=vec3(0.0);\n#ifdef Debug_ShadingNormal\ndebug=vec3(info.normalWS*0.5+0.5);\n#endif\n#ifdef Debug_GeometryNormal\ndebug=vec3(info.vertexNormalWS*0.5+0.5);\n#endif\n#ifdef Debug_GeometryTangent\ndebug=vec3(pixel.tangentWS*0.5+0.5);\n#endif\n#ifdef Debug_GeometryBiTangent\ndebug=vec3(pixel.biNormalWS*0.5+0.5);\n#endif\n#ifdef Debug_Roughness\ndebug=vec3(surface.perceptualRoughness);\n#endif\n#ifdef Debug_Alpha\ndebug=vec3(surface.alpha);\n#endif\n#ifdef Debug_Occlusion\ndebug=vec3(surface.occlusion);\n#endif\n#ifdef Debug_BaseColor\ndebug=surface.diffuseColor;\n#endif\n#ifdef Debug_Metallic\ndebug=vec3(inputs.metallic);\n#endif\n#ifdef THICKNESS\n#ifdef Debug_VolumeThickness\ndebug=vec3(surface.thickness);\n#endif\n#ifdef Debug_Attenuation\n{vec3 scaleLength=vec3(0.0);scaleLength.x=length(vec3(u_WorldMat[0].xyz));scaleLength.y=length(vec3(u_WorldMat[1].xyz));scaleLength.z=length(vec3(u_WorldMat[2].xyz));vec3 n=info.normalWS;vec3 r=-info.viewDir;float airIor=1.0;float ior=surface.ior;float etaIR=airIor/ior;float etaRI=ior/airIor;vec3 refractionVector=normalize(refract(r,n,etaIR))*surface.thickness*scaleLength;vec3 absorption=-log((surface.attenuationColor))/(surface.attenuationDistance);debug=exp(-absorption);}\n#endif\n#endif\n#ifdef TRANSMISSION\n#ifdef Debug_Transmission\nvec3 E=getE(surface,info);debug=transmissionIBL(surface,info,E);\n#endif\n#endif\n#ifdef Debug_IOR\ndebug=vec3(surface.ior-1.0);\n#endif\n#ifdef Debug_SpecularFactor\ndebug=vec3(inputs.specularFactor);\n#endif\n#ifdef Debug_SpecularColor\ndebug=vec3(inputs.specularColor);\n#endif\n#ifdef Debug_f0\ndebug=vec3(surface.f0);\n#endif\n#ifdef Debug_f90\ndebug=vec3(surface.f90);\n#endif\n#ifdef Debug_FrontFace\nif(gl_FrontFacing){debug=vec3(1.0,0.0,0.0);}else{debug=vec3(0.0,1.0,0.0);}\n#endif\n#ifdef Debug_SpecularAO\nfloat specularAO=saturate(pow(info.NoV+surface.occlusion,exp2(-16.0*surface.roughness-1.0))-1.0+surface.occlusion);float diffAO=specularAO-surface.occlusion;debug=vec3(abs(diffAO));if(diffAO<0.0){debug*=vec3(1.0,0.0,0.0);}else{debug*=vec3(0.0,1.0,0.0);}\n#endif\ndebug=gammaToLinear(debug);gl_FragColor=vec4(debug,1.0);\n#endif\n}'),s.addShaderPass('#define SHADER_NAME glTFDepthVS\n#include "DepthVertex.glsl";\n#ifdef ALPHATEST\nvarying vec2 v_AlphaTestUV;varying float v_AlphaTestVertexAlpha;\n#endif\nvoid main(){Vertex vertex;getVertexParams(vertex);\n#ifdef ALPHATEST\n#ifdef UV\nv_AlphaTestUV=vertex.texCoord0;\n#else\nv_AlphaTestUV=vec2(0.0);\n#endif\n#if defined(COLOR) && defined(ENABLEVERTEXCOLOR)\nv_AlphaTestVertexAlpha=vertex.vertexColor.a;\n#else\nv_AlphaTestVertexAlpha=1.0;\n#endif\n#endif\nmat4 worldMat=getWorldMatrix();vec4 pos=(worldMat*vec4(vertex.positionOS,1.0));vec3 positionWS=pos.xyz/pos.w;mat4 normalMat=transpose(inverse(worldMat));vec3 normalWS=normalize((normalMat*vec4(vertex.normalOS,0.0)).xyz);vec4 positionCS=DepthPositionCS(positionWS,normalWS);gl_Position=remapPositionZ(positionCS);}','#define SHADER_NAME glTFDepthFS\n#include "DepthFrag.glsl";\n#ifdef ALPHATEST\nvarying vec2 v_AlphaTestUV;varying float v_AlphaTestVertexAlpha;\n#endif\nvoid main(){\n#ifdef ALPHATEST\nfloat alpha=u_BaseColorFactor.w*v_AlphaTestVertexAlpha;\n#ifdef BASECOLORMAP\nvec2 baseColorUV=v_AlphaTestUV;\n#ifdef BASECOLORMAP_TRANSFORM\nbaseColorUV=(u_BaseColorMapTransform*vec3(baseColorUV,1.0)).xy;\n#endif\nalpha*=texture2D(u_BaseColorTexture,baseColorUV).a;\n#endif\nif(alpha<u_AlphaTestValue)discard;\n#endif\ngl_FragColor=getDepthColor();}',"ShadowCaster"),s.addShaderPass('#define SHADER_NAME glTFPBRDepthNormalVS\n#include "Math.glsl";\n#include "Camera.glsl";\n#include "Sprite3DVertex.glsl";\n#include "VertexCommon.glsl";\n#include "PBRVertex.glsl";\nvarying vec4 v_PositionCS;void main(){Vertex vertex;getVertexParams(vertex);PixelParams pixel;initPixelParams(pixel,vertex);sharePixelParams(pixel);vec4 positionCS=getPositionCS(pixel.positionWS);v_PositionCS=positionCS;gl_Position=positionCS;gl_Position=remapPositionZ(gl_Position);}','#define SHADER_NAME glTFPBRDepthNormalFS\n#include "Color.glsl";\n#include "Scene.glsl";\n#include "SceneFog.glsl";\n#include "Camera.glsl";\n#include "Sprite3DFrag.glsl";\n#include "ShadingFrag.glsl";\n#include "DepthNormalFrag.glsl";\nvarying vec4 v_PositionCS;void main(){PixelParams pixel;getPixelParams(pixel);\n#ifdef ALPHATEST\nfloat alpha=u_BaseColorFactor.w;\n#if defined(COLOR) && defined(ENABLEVERTEXCOLOR)\nalpha*=pixel.vertexColor.a;\n#endif\n#ifdef BASECOLORMAP\nvec2 baseColorUV=vec2(0.0);\n#ifdef UV\nbaseColorUV=pixel.uv0;\n#endif\n#ifdef BASECOLORMAP_TRANSFORM\nbaseColorUV=(u_BaseColorMapTransform*vec3(baseColorUV,1.0)).xy;\n#endif\nalpha*=texture2D(u_BaseColorTexture,baseColorUV).a;\n#endif\nif(alpha<u_AlphaTestValue)discard;\n#endif\nvec3 normalWS=pixel.normalWS;\n#ifdef NORMALMAP\n#ifdef UV\nvec2 uv=pixel.uv0;vec3 normalSampler=texture2D(u_NormalTexture,uv).xyz;normalSampler=normalize(normalSampler*2.0-1.0);normalSampler.y*=-1.0;vec3 normalTS=normalScale(normalSampler,u_NormalScale);normalWS=normalize(pixel.TBN*normalTS);\n#endif UV\n#endif\nvec4 positionCS=v_PositionCS;vec4 dephtNormal=encodeDepthNormal(positionCS,normalWS);gl_FragColor=dephtNormal;}',"DepthNormal")}}t.ShaderName="glTFPBR";class a extends r.Prefab{static registerExtension(e,r){this._Extensions[e]=r}get data(){return this._data}constructor(){super(),this._buffers={},this._textures=[],this._materials=[],this._meshes={},this._extensions=new Map,this._pendingOps=[],this._scenes=[],this._nodes=[]}loadBinary(e,t){let a=this._data;if(a.buffers){let n=[];return a.buffers.forEach((a,s)=>{if(r.Base64Tool.isBase64String(a.uri)){let e=r.Base64Tool.decode(a.uri.replace(r.Base64Tool.reghead,""));this._buffers[s]=e}else{let o=s;n.push(r.ILaya.loader.fetch(r.URL.join(e,a.uri),"arraybuffer",null==t?void 0:t.createCallback(.2)).then(e=>{this._buffers[o]=e}))}}),Promise.all(n)}return Promise.resolve()}loadTextureFromInfo(e,t,a,n){let s=this._data,o=e.index,i=s.textures[o],l=i.source,u=s.images[l],c=i.sampler,f=s.samplers?s.samplers[c]:void 0,h=this.getTextureConstructParams(u,f,t),d=this.getTexturePropertyParams(f);if(null!=u.bufferView){let e=s.bufferViews[u.bufferView],r=this._buffers[e.buffer],t=e.byteOffset||0,a=e.byteLength,i=r.slice(t,t+a);return this.loadTextureFromBuffer(i,u.mimeType,h,d,n).then(e=>(this._textures[o]=e,this.addDep(e),e))}return this.loadTexture(r.URL.join(a,u.uri),h,d,n).then(e=>(this._textures[o]=e,this.addDep(e),e))}loadTextures(e,r){let t=this._data,a=t.materials,n=t.textures,s=[];if(a&&n)for(let a of t.materials){let t=a.pbrMetallicRoughness;if(t){if(t.baseColorTexture){let a=!0,n=this.loadTextureFromInfo(t.baseColorTexture,a,e,r);s.push(n)}if(t.metallicRoughnessTexture){let a=!1,n=this.loadTextureFromInfo(t.metallicRoughnessTexture,a,e,r);s.push(n)}}if(a.normalTexture){let t=!1,n=this.loadTextureFromInfo(a.normalTexture,t,e,r);s.push(n)}if(a.occlusionTexture){let t=!1,n=this.loadTextureFromInfo(a.occlusionTexture,t,e,r);s.push(n)}if(a.emissiveTexture){let t=!0,n=this.loadTextureFromInfo(a.emissiveTexture,t,e,r);s.push(n)}}return this._extensions.forEach(t=>{if(t.loadAdditionTextures){let a=t.loadAdditionTextures(e,r);s.push(a)}}),Promise.all(s)}importMaterials(){return Promise.resolve().then(()=>{let e=this._data;e.materials&&e.materials.forEach((e,r)=>{let t=this.createMaterial(e);this._materials[r++]=t,this.addDep(t)})})}importMeshes(){return Promise.resolve().then(()=>{let e=this._data;e.meshes&&e.nodes&&e.nodes.forEach(e=>{var r;if(null!=e.mesh){let t=this._data.meshes[e.mesh],a=null===(r=this._data.skins)||void 0===r?void 0:r[e.skin],n=e.mesh+(null!=e.skin?"_"+e.skin:""),s=this._meshes[n];s||(s=this.createMesh(t,a),this._meshes[n]=s,this.addDep(s))}})})}_parse(e,t,n){var s,o,i;if(!e.asset||"2.0"!==e.asset.version)throw new Error("glTF version wrong!");this._data=e;let l=r.URL.getPath(t);this._idCounter={},null===(s=e.extensionsUsed)||void 0===s||s.forEach(e=>{let r=a._Extensions[e];r?this._extensions.set(e,r(this)):console.warn(`glTF: unsupported used extension: ${e}`)}),null===(o=e.extensionsRequired)||void 0===o||o.forEach(e=>{a._Extensions[e]||console.warn(`glTF: unsupported required extension: ${e}`)}),null===(i=e.nodes)||void 0===i||i.forEach(e=>{if(!e.name){let r=this.generateId("glTFNode");e.name=`node_${r}`}});let u=this.loadBinary(l,n);return u=u.then(()=>this.loadTextures(l,n)),u=u.then(()=>this.importMeshes()),u=u.then(()=>this.importMaterials()),u.then(()=>this._pendingOps.length>0?Promise.all(this._pendingOps).then(()=>{this._idCounter=null}):(this._idCounter=null,Promise.resolve()))}_parseglb(e,t,n){var s,o,i;let l=r.URL.getPath(t);this._idCounter={};let u=new r.Byte(e);if(1179937895!=u.readUint32())throw new Error("glb fromat wrong!");if(2!=u.readUint32())throw new Error("glb version wrong!");u.readUint32();let c=u.readUint32();if(1313821514!=u.readUint32())throw new Error("glb json chunk data wrong!");let f=u.readArrayBuffer(c),h=(new TextDecoder).decode(f),d=JSON.parse(h);this._data=d;let p=u.readUint32();if(5130562!=u.readUint32())throw new Error("glb bin chunk data wrong!");let m=null===(s=d.buffers)||void 0===s?void 0:s[0];m.byteLength=m.byteLength?Math.min(m.byteLength,p):p,this._buffers[0]=u.readArrayBuffer(m.byteLength),null===(o=d.extensionsUsed)||void 0===o||o.forEach(e=>{let r=a._Extensions[e];r?this._extensions.set(e,r(this)):console.warn(`glTF: unsupported used extension: ${e}`)}),null===(i=d.extensionsRequired)||void 0===i||i.forEach(e=>{a._Extensions[e]||console.warn(`glTF: unsupported required extension: ${e}`)});let _=this.loadTextures(l,n);return _=_.then(()=>this.importMeshes()),_=_.then(()=>this.importMaterials()),_.then(()=>this._pendingOps.length>0?Promise.all(this._pendingOps).then(()=>{this._idCounter=null}):(this._idCounter=null,Promise.resolve()))}create(){let e=this._data;this._scenes.length=0,this._nodes.length=0,this._idCounter={},this.loadNodes(e.nodes),this.buildHierarchy(e.nodes),this.loadScenes(e.scenes),this.loadAnimations(e.animations);let r=null!=e.scene?e.scene:0,t=this._scenes[r];return this._scenes.length=0,this._nodes.length=0,this._idCounter=null,t}loadTextureFromBuffer(e,t,a,n,s){let o=`data:${t};base64,${r.Base64Tool.encode(e)}`;return r.ILaya.loader.load({url:o,constructParams:a,propertyParams:n},r.Loader.TEXTURE2D,null==s?void 0:s.createCallback())}loadTexture(e,t,a,n){return r.ILaya.loader.load({url:e,constructParams:t,propertyParams:a},r.Loader.TEXTURE2D,null==n?void 0:n.createCallback())}generateId(e){let r=this._idCounter[e];return null==r?r=0:r++,this._idCounter[e]=r,r.toString()}getAccessorComponentsNum(e){switch(e){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 0}}getAttributeNum(e){switch(e){case"POSITION":case"NORMAL":return 3;case"COLOR":case"BLENDWEIGHT":case"BLENDINDICES":case"TANGENT":return 4;case"UV":case"UV1":return 2;default:return 0}}_getTypedArrayConstructor(e){switch(e){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5125:return Uint32Array;case 5126:return Float32Array}}_getAccessorDateByteStride(e){switch(e){case 5120:case 5121:return 1;case 5122:case 5123:return 2;case 5125:case 5126:return 4}}getBufferFormBufferView(e,r,t,a,n){let s=this._buffers[e.buffer];const o=this._getTypedArrayConstructor(a);let i,l=this.getAccessorComponentsNum(t);if(e.byteStride){let t=e.byteStride,u=this._getAccessorDateByteStride(a),c=t/u,f=(r||0)/u,h=new o(s,e.byteOffset||0,e.byteLength/u);i=new o(n);let d=0;for(let e=0;e<n;e++){let r=e*c;for(let e=0;e<l;e++)i[d++]=h[r+f+e]}}else{i=new o(s,(e.byteOffset||0)+(r||0),n)}return i}getBufferwithAccessorIndex(e){let r=this._data.accessors[e];if(!r)return null;let t,a=r.count,n=this.getAccessorComponentsNum(r.type),s=a*n,o=this._data.bufferViews[r.bufferView];if(o)t=this.getBufferFormBufferView(o,r.byteOffset,r.type,r.componentType,s);else{t=new(this._getTypedArrayConstructor(r.componentType))(s).fill(0)}if(r.sparse){let e=r.sparse.count,a=r.sparse.indices,s=this._data.bufferViews[a.bufferView],o=this.getBufferFormBufferView(s,a.byteOffset,r.type,a.componentType,e),i=r.sparse.values,l=this._data.bufferViews[i.bufferView],u=this.getBufferFormBufferView(l,i.byteOffset,r.type,r.componentType,e*n);for(let r=0;r<e;r++){let e=o[r];for(let a=0;a<n;a++)t[e*n+a]=u[r*n+a]}}return t}getTextureMipmap(e){return!e||9729!=e.minFilter&&9728!=e.minFilter}getTextureFormat(e){return"image/jpeg"===e.mimeType?0:1}getTextureFilterMode(e){return e?9728===e.magFilter?0:this.getTextureMipmap(e)&&9987===e.minFilter?2:1:1}getTextureWrapMode(e){switch(e=null!=e?e:10497){case 10497:default:return r.WrapMode.Repeat;case 33071:return r.WrapMode.Clamp;case 33648:return r.WrapMode.Mirrored}}getTextureConstructParams(e,r,t){return[0,0,this.getTextureFormat(e),this.getTextureMipmap(r),!1,t]}getTexturePropertyParams(e){if(!e)return null;return{filterMode:this.getTextureFilterMode(e),wrapModeU:this.getTextureWrapMode(e.wrapS),wrapModeV:this.getTextureWrapMode(e.wrapT),anisoLevel:1,hdrEncodeFormat:r.HDREncodeFormat.NONE}}getTextureWithInfo(e){return e.texCoord&&console.warn("glTF Loader: non 0 uv channel unsupported."),this._textures[e.index]}getExtensionTextureInfo(e,r){let t=this._extensions.get(r);return e.extensions&&e.extensions[r]&&t?t.loadExtensionTextureInfo?t.loadExtensionTextureInfo(e):void 0:null}applyMaterialRenderState(e,t){var a;switch(e.alphaMode||"OPAQUE"){case"OPAQUE":t.materialRenderMode=r.MaterialRenderMode.RENDERMODE_OPAQUE;break;case"BLEND":t.materialRenderMode=r.MaterialRenderMode.RENDERMODE_TRANSPARENT;break;case"MASK":t.materialRenderMode=r.MaterialRenderMode.RENDERMODE_CUTOUT}t.alphaTestValue=null!==(a=e.alphaCutoff)&&void 0!==a?a:.5,e.doubleSided&&(t.cull=r.RenderState.CULL_NONE)}setMaterialTextureProperty(e,r,t,a,n,s){let o=this.getTextureWithInfo(r);if(e.setTexture(t,o),a&&e.setDefine(a,!0),s){let t=this.getExtensionTextureInfo(r,"KHR_texture_transform");t&&(e.setDefine(s,!0),e.setMatrix3x3(n,t.transform))}}applyDefaultMaterialProperties(e,a){var n,s,o,i;let l=e.pbrMetallicRoughness;if(l){if(l.baseColorFactor){let e=a.getVector4("u_BaseColorFactor");e.fromArray(l.baseColorFactor),a.setVector4("u_BaseColorFactor",e)}l.baseColorTexture&&this.setMaterialTextureProperty(a,l.baseColorTexture,"u_BaseColorTexture",t.Define_BaseColorMap,"u_BaseColorMapTransform",t.Define_BaseColorMapTransform);let e=null!==(n=l.metallicFactor)&&void 0!==n?n:1;a.setFloat("u_MetallicFactor",e);let r=null!==(s=l.roughnessFactor)&&void 0!==s?s:1;a.setFloat("u_RoughnessFactor",r),l.metallicRoughnessTexture&&this.setMaterialTextureProperty(a,l.metallicRoughnessTexture,"u_MetallicRoughnessTexture",t.Define_MetallicRoughnessMap,"u_MetallicRoughnessMapTransform",t.Define_MetallicRoughnessMapTransform)}if(e.normalTexture){this.setMaterialTextureProperty(a,e.normalTexture,"u_NormalTexture",t.Define_NormalMap,"u_NormalMapTransform",t.Define_NormalMapTransform);let r=null!==(o=e.normalTexture.scale)&&void 0!==o?o:1;a.setFloat("u_NormalScale",r)}if(e.occlusionTexture){this.setMaterialTextureProperty(a,e.occlusionTexture,"u_OcclusionTexture",t.Define_OcclusionMap,"u_OcclusionMapTransform",t.Define_OcclusionMapTransform);let r=null!==(i=e.occlusionTexture.strength)&&void 0!==i?i:1;a.setFloat("u_OcclusionStrength",r)}if(e.emissiveFactor){let t=a.getVector3("u_EmissionFactor");t.fromArray(e.emissiveFactor),a.setVector3("u_EmissionFactor",t),a.setDefine(r.PBRShaderLib.DEFINE_EMISSION,!0)}e.emissiveTexture&&(a.setDefine(r.PBRShaderLib.DEFINE_EMISSION,!0),this.setMaterialTextureProperty(a,e.emissiveTexture,"u_EmissionTexture",t.Define_EmissionMap,"u_EmissionMapTransform",t.Define_EmissionMapTransform)),this.applyMaterialRenderState(e,a)}createDefaultMaterial(e){let a=new r.Material;return a.setShaderName(t.ShaderName),a.name=e.name?e.name:"",this.applyDefaultMaterialProperties(e,a),a}createMaterial(e){let r=null,t=[];for(const a in e.extensions){let n=this._extensions.get(a);n&&(n.createMaterial&&(r=n.createMaterial(e)),n.additionMaterialProperties&&t.push(n))}return r||(r=this.createDefaultMaterial(e)),t.forEach(t=>{t.additionMaterialProperties(e,r)}),r}pickMeshMaterials(e){let t=[];return e.primitives.forEach(e=>{if(null!=e.material){let r=this._materials[e.material];t.push(r)}else{let a=new r.PBRStandardMaterial;t.push(a),this._materials.push(a),e.material=this._materials.indexOf(a)}}),t}loadScenes(e){e&&e.forEach((e,r)=>{this._scenes[r]=this._loadScene(e)})}_loadScene(e){return this._createSceneNode(e)}_createSceneNode(e){let t=new r.Sprite3D(e.name||"Scene");return e.nodes.forEach(e=>{let r=this._nodes[e];t.addChild(r)}),t}applyTransform(e,r){if(e.matrix){let t=r.transform.localMatrix;t.elements.set(e.matrix),r.transform.localMatrix=t}else{let t=r.transform.localPosition,a=r.transform.localRotation,n=r.transform.localScale;e.translation&&t.fromArray(e.translation),e.rotation&&a.fromArray(e.rotation),e.scale&&n.fromArray(e.scale),r.transform.localPosition=t,r.transform.localRotation=a,r.transform.localScale=n}}buildHierarchy(e){e.forEach((e,r)=>{let t=this._nodes[r];e.children&&e.children.forEach(e=>{let r=this._nodes[e];t.addChild(r)})}),e.forEach((e,r)=>{let t=this._nodes[r];null!=e.skin&&this.fixSkinnedSprite(e,t)})}loadNodes(e){e&&e.forEach((e,r)=>{this._nodes[r]=this.loadNode(e)})}loadNode(e){return this.createSprite3D(e)}createSprite3D(e){let t;null!=e.skin?(t=this.createSkinnedMeshSprite3D(e),this.applyTransform(e,t)):null!=e.mesh?(t=this.createMeshSprite3D(e),this.applyTransform(e,t)):(t=new r.Sprite3D(e.name),this.applyTransform(e,t));let a=this.generateId("node");return t.name=e.name||`node_${a}`,t._extra.storeId="#"+a,t}createMeshSprite3D(e){let t=this._data.meshes[e.mesh],a=this._meshes[e.mesh],n=this.pickMeshMaterials(t),s=new r.Sprite3D(e.name),o=s.addComponent(r.MeshFilter),i=s.addComponent(r.MeshRenderer);return o.sharedMesh=a,i.sharedMaterials=n,i.receiveShadow=!0,i.castShadow=!0,t.weights&&t.weights.forEach((e,r)=>{let t=a.morphTargetData.getMorphChannelbyIndex(r);i.setMorphChannelWeight(t.name,e)}),s}createSkinnedMeshSprite3D(e){let t=this._data.meshes[e.mesh],a=this._meshes[e.mesh+"_"+e.skin],n=this.pickMeshMaterials(t),s=new r.Sprite3D(e.name),o=s.addComponent(r.MeshFilter),i=s.addComponent(r.SkinnedMeshRenderer);return o.sharedMesh=a,i.sharedMaterials=n,i.receiveShadow=!0,i.castShadow=!0,t.weights&&t.weights.forEach((e,r)=>{let t=a.morphTargetData.getMorphChannelbyIndex(r);i.setMorphChannelWeight(t.name,e)}),s}getArrributeBuffer(e,r,t,a){let n=this.getBufferwithAccessorIndex(e);if(!n)return null;a.push(r);let s=n;return t.set(r,s),s}getIndexBuffer(e,r){let t=this.getBufferwithAccessorIndex(e);if(t)return new Uint32Array(t).reverse();{let e=new Uint32Array(r);for(let t=0;t<r;t++)e[t]=r-1-t;return e}}calculateFlatNormal(e,r){let t=new Float32Array(e.length);for(let a=0;a<r.length;a+=3){let n=r[a],s=r[a+1],o=r[a+2],i=e[3*n],l=e[3*n+1],u=e[3*n+2],c=e[3*s]-i,f=e[3*s+1]-l,h=e[3*s+2]-u,d=e[3*o]-i,p=e[3*o+1]-l,m=e[3*o+2]-u,_=f*m-h*p,T=h*d-c*m,x=c*p-f*d,S=-1/Math.sqrt(_*_+T*T+x*x),g=_*S,M=T*S,A=x*S;t[3*n]=g,t[3*s]=g,t[3*o]=g,t[3*n+1]=M,t[3*s+1]=M,t[3*o+1]=M,t[3*n+2]=A,t[3*s+2]=A,t[3*o+2]=A}return t}parseMeshwithSubMeshData(e,t){let a,n=0,s=0;e.forEach(e=>{n+=e.vertexCount,s+=e.indices.length,a=a||e.vertexDecler});let o,i=r.VertexMesh.getVertexDeclaration(a,!1),l=i.vertexStride/4,u=new Float32Array(l*n),c=r.IndexFormat.UInt32;n<65536?(o=new Uint16Array(s),c=r.IndexFormat.UInt16):o=new Uint32Array(s),this.fillMeshBuffers(e,u,o,l),this.generateMesh(u,o,i,c,e,t)}fillMeshBuffers(e,r,t,a){let n=0,s=0,o=0;e.forEach(e=>{let i=n,l=e.vertexCount,u=e.indices;for(let e=0;e<u.length;e++)t[i+e]=u[e]+s;n+=u.length,s+=l;const c=(e,t,n=0)=>{let s=o+t;for(let t=0;t<l;t++)for(let o=0;o<n;o++)r[s+t*a+o]=e[t*n+o]};let f=0,h=e.attributeMap,d=h.get("POSITION");d&&(c(d,f,3),f+=3);let p=h.get("NORMAL");p&&(c(p,f,3),f+=3);let m=h.get("COLOR");m&&(c(m,f,4),f+=4);let _=h.get("UV");_&&(c(_,f,2),f+=2);let T=h.get("UV1");T&&(c(T,f,2),f+=2);let x=h.get("BLENDWEIGHT");x&&(c(x,f,4),f+=4);let S=h.get("BLENDINDICES");if(S){let e=new Uint8Array(S);c(new Float32Array(e.buffer),f,1),f+=1}let g=h.get("TANGENT");g&&(c(g,f,4),f+=4),o+=l*a})}splitSubMeshByBonesCount(e,r,t,a,n,s){let o=0,i=new Set,l=e.get("BLENDINDICES"),u=l.length/4,c=new Float32Array(l.length),f=new Array(u).fill(!1);for(let e=0,r=t.length;e<r;e+=3){let u=new Set;for(let r=e;r<e+3;r++){let e=4*t[r];for(let r=0;r<4;r++)u.add(l[e+r])}let c=new Set([...i,...u]);if(c.size>24){let r=e-o;n.push(o),s.push(r);let t=Array.from(i);a.push(new Uint16Array(t)),o=e,i=new Set(u)}else i=c;if(e==r-3){let r=e-o+3;n.push(o),s.push(r),o=e;let t=Array.from(i);a.push(new Uint16Array(t))}}let h=a.length,d=new Map;e.forEach((e,r)=>{let t=new Array;d.set(r,t)});let p={};for(const e in r.targets){let t=p[e]=new Map;r.targets[e].forEach((e,r)=>{t.set(r,new Array)})}let m=u-1;for(let o=0;o<h;o++){let i=n[o],h=s[o],_=a[o],T=new Array(u).fill(!1),x=new Map;for(let a=0;a<h;a++){let n=t[a+i],s=4*n;for(let e=s;e<s+4;e++){let r=l[e],t=_.indexOf(r);t=-1==t?0:t,f[n]&&!T[n]?d.get("BLENDINDICES").push(t):f[n]&&T[n]||(c[e]=t)}if(f[n]||T[n])if(!f[n]&&T[n])t[a+i]=x.get(n);else if(f[n]&&!T[n]){T[n]=!0,m++,x.set(n,m),t[a+i]=m,d.forEach((r,t)=>{let a=this.getAttributeNum(t),s=e.get(t);if("BLENDINDICES"!==t)for(let e=0;e<a;e++)r.push(s[e+n*a])});for(const e in p){let t=p[e],a=r.targets[e];t.forEach((e,r)=>{let t=this.getAttributeNum(r),s=a.get(r);for(let r=0;r<t;r++)e.push(s[r+n*t])})}}else f[n]&&T[n]&&(t[a+i]=x.get(n));else T[n]=!0,x.set(n,n)}T.forEach((e,r)=>{f[r]=e||f[r]})}d.forEach((r,t)=>{let a=e.get(t);"BLENDINDICES"==t&&(a=c);let n=a.length+r.length,s=new Float32Array(n);s.set(a,0),s.set(r,a.length),e.set(t,s)});for(const e in p){let t=p[e],a=r.targets[e];t.forEach((e,r)=>{let t=a.get(r),n=e.length+t.length,s=new Float32Array(n);s.set(t,0),s.set(e,t.length),a.set(r,s)})}l=null}generateMesh(e,t,a,n,s,o){let i=r.Laya3DRender.renderOBJCreate.createVertexBuffer3D(e.byteLength,r.BufferUsage.Static,!0);i.vertexDeclaration=a,i.setData(e.buffer);let l=r.Laya3DRender.renderOBJCreate.createIndexBuffer3D(n,t.length,r.BufferUsage.Static,!0);l.setData(t),o._indexFormat=n,o._indexBuffer=l,o._vertexBuffer=i,o._setBuffer(i,l),o._vertexCount=i._byteLength/a.vertexStride;let u=!1,c=new r.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),f=new r.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),h=0,d=s.length,p=new Array(d);for(let e=0;e<d;e++){let t=s[e],a=new r.SubMesh(o);p[e]=a,a._vertexBuffer=i,a._indexBuffer=l;let d=h;h+=t.indices.length;let m=t.indices.length;a._setIndexRange(d,m,n),a._boneIndicesList=t.boneIndicesList,a._subIndexBufferStart=t.subIndexStartArray,a._subIndexBufferCount=t.subIndexCountArray;for(let e=0;e<a._subIndexBufferStart.length;e++)a._subIndexBufferStart[e]+=d;t.boundMax&&t.boundMin?(c.x=Math.min(t.boundMin[0],c.x),c.y=Math.min(t.boundMin[1],c.y),c.z=Math.min(t.boundMin[2],c.z),f.x=Math.max(t.boundMax[0],f.x),f.y=Math.max(t.boundMax[1],f.y),f.z=Math.max(t.boundMax[2],f.z)):u=!0}o._setSubMeshes(p),u?o.calculateBounds():(o.bounds.setMin(c),o.bounds.setMax(f));let m=i._byteLength+l._byteLength;o._setCPUMemory(m),o._setGPUMemory(m)}applyglTFSkinData(e,t,a){if(!a)return;let n=a.joints,s=new Float32Array(this.getBufferwithAccessorIndex(a.inverseBindMatrices)),o=n.length,i=e._boneNames=[];n.forEach(e=>{let r=this._data.nodes[e];i.push(r.name)}),e._inverseBindPoses=[],e._inverseBindPosesBuffer=s.buffer;for(let t=0;t<o;t++){let a=16*t,n=s.slice(a,a+16);e._inverseBindPoses[t]=new r.Matrix4x4(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11],n[12],n[13],n[14],n[15],n)}let l=t.length,u=e._skinnedMatrixCaches;u.length=e._inverseBindPoses.length;for(let t=0;t<l;t++){let a=e.getSubMesh(t),n=a._subIndexBufferStart.length;for(let e=0;e<n;e++){let n=a._boneIndicesList[e];for(let a=0;a<n.length;a++){let s=n[a];u[s]||(u[s]=new r.skinnedMatrixCache(t,e,a))}}}for(let e=0;e<u.length;e++)u[e]||(u[e]=new r.skinnedMatrixCache(0,0,0))}applyMorphTarget(e,t){let a=!1,n=!1,s=!1;if(t.forEach(e=>{a=e.morphtargets.position||a,n=e.morphtargets.normal||n,s=e.morphtargets.tangent||s}),!(a||s||s))return;let o=e.vertexCount,i=new r.MorphTargetData;i.vertexCount=o;let l=[];a&&l.push("POSITION"),n&&l.push("NORMAL"),s&&l.push("TANGENT");let u=r.VertexMesh.getVertexDeclaration(l.toLocaleString()),c=u.vertexStride/4;i.vertexDec=u;let f=i.bounds,h=f.getMin(),d=f.getMax();h.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),d.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);let p=0;for(let e=0;e<t.length;e++){let a=t[e];h.x=Math.min(h.x,a.morphtargets.boundMin[0]),h.y=Math.min(h.y,a.morphtargets.boundMin[1]),h.z=Math.min(h.z,a.morphtargets.boundMin[2]),d.x=Math.max(d.x,a.morphtargets.boundMax[0]),d.y=Math.max(d.y,a.morphtargets.boundMax[1]),d.z=Math.max(d.z,a.morphtargets.boundMax[2]);let n=a.morphtargets.targets;for(const e in n){let t=i.getMorphChannel(e);if(!t){t=new r.MorphTargetChannel,t.name=e;let a=new r.MorphTarget;a.name=e,a.data=new Float32Array(o*c).fill(0),t.addTarget(a),i.addMorphChannel(t)}let s=t.getTargetByIndex(0),l=n[e];for(let e=0;e<a.vertexCount;e++){let t=l.get("POSITION");if(t){let a=u.getVertexElementByUsage(r.VertexMesh.MESH_POSITION0).offset/4;s.data[(e+p)*c+a]=t[3*e],s.data[(e+p)*c+a+1]=t[3*e+1],s.data[(e+p)*c+a+2]=t[3*e+2]}let n=l.get("NORMAL");if(n){let t=u.getVertexElementByUsage(r.VertexMesh.MESH_NORMAL0).offset/4;s.data[(e+p)*c+t]=n[3*e],s.data[(e+p)*c+t+1]=n[3*e+1],s.data[(e+p)*c+t+2]=n[3*e+2]}let o=l.get("TANGENT");if(o){let t=u.getVertexElementByUsage(r.VertexMesh.MESH_TANGENT0).offset/4;s.data[(e+p)*c+t]=o[3*e],s.data[(e+p)*c+t+1]=o[3*e+1],s.data[(e+p)*c+t+2]=o[3*e+2],s.data[(e+p)*c+t+3]=a.attributeMap.get("TANGENT")[4*e+3]}}}p+=a.vertexCount}f.setMin(h),f.setMax(d),e.morphTargetData=i,i.initData()}createMesh(e,t){let a=new r.Mesh;e.name&&(a.name=e.name);let s=e.primitives,o=e.weights,i=t?t.joints.length:0,l=[];return s.forEach(r=>{var a;let s=r.mode;null==s&&(s=4),4!=s&&console.warn("glTF Loader: only support gl.TRIANGLES.");let u,c=[],f=new Map,h=r.attributes,d=this.getArrributeBuffer(h.POSITION,"POSITION",f,c),p=d.length/3,m=this.getIndexBuffer(r.indices,p),_=this._data.accessors[h.POSITION],T=this.getArrributeBuffer(h.NORMAL,"NORMAL",f,c);if(T||(T=this.calculateFlatNormal(d,m),c.push("NORMAL"),f.set("NORMAL",T)),this.getArrributeBuffer(h.COLOR_0,"COLOR",f,c),this.getArrributeBuffer(h.TEXCOORD_0,"UV",f,c),this.getArrributeBuffer(h.TEXCOORD_1,"UV1",f,c),this.getArrributeBuffer(h.WEIGHTS_0,"BLENDWEIGHT",f,c),this.getArrributeBuffer(h.JOINTS_0,"BLENDINDICES",f,c),u=this.getArrributeBuffer(h.TANGENT,"TANGENT",f,c),u)for(let e=0;e<u.length;e+=4)u[e+3]*=-1;let x=r.targets,S={weights:o,position:!1,normal:!1,tangent:!1,targets:{},boundMin:[Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE],boundMax:[-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE]};if(x){let r,t=(null===(a=e.extras)||void 0===a?void 0:a.targetNames)||[];r=S.targets,x.forEach((e,a)=>{let n=t[a]||`target_${a}`,s=new Map;r[n]=s;let o=this.getBufferwithAccessorIndex(e.POSITION),i=this.getBufferwithAccessorIndex(e.NORMAL),l=this.getBufferwithAccessorIndex(e.TANGENT);if(o&&(s.set("POSITION",o),S.position=!0,d)){let e=d.length/3;for(let r=0;r<e;r++){let e=3*r,t=d[e]+o[e],a=d[e+1]+o[e+1],n=d[e+2]+o[e+2];S.boundMin[0]=Math.min(t,S.boundMin[0]),S.boundMin[1]=Math.min(a,S.boundMin[1]),S.boundMin[2]=Math.min(n,S.boundMin[2]),S.boundMax[0]=Math.max(t,S.boundMax[0]),S.boundMax[1]=Math.max(a,S.boundMax[1]),S.boundMax[2]=Math.max(n,S.boundMax[2])}}i&&(s.set("NORMAL",i),S.normal=!0),l&&(s.set("TANGENT",l),S.tangent=!0)})}let g=new Array,M=[],A=[];if(t)if(i>24)this.splitSubMeshByBonesCount(f,S,m,g,M,A),p=f.get("POSITION").length/3;else{M[0]=0,A[0]=m.length,g[0]=new Uint16Array(i);for(let e=0;e<i;e++)g[0][e]=e}else M[0]=0,A[0]=m.length;let C=c.toString(),y=new n;l.push(y),y.attributeMap=f,y.boundMax=_.max,y.boundMin=_.min,y.morphtargets=S,y.indices=m,y.vertexCount=p,y.vertexDecler=C,y.boneIndicesList=g,y.subIndexStartArray=M,y.subIndexCountArray=A}),this.parseMeshwithSubMeshData(l,a),this.applyglTFSkinData(a,l,t),this.applyMorphTarget(a,l),a}calSkinnedSpriteLocalBounds(e){let t=e.getComponent(r.SkinnedMeshRenderer),a=e.getComponent(r.MeshFilter).sharedMesh,n=t.rootBone.transform.worldMatrix,s=new r.Matrix4x4;n.invert(s);let o=a.getIndices(),i=[],l=[],u=[];a.getPositions(i),a.getBoneIndices(l),a.getBoneWeights(u);let c=[];a._subMeshes.forEach((e,t)=>{e._boneIndicesList.forEach((t,a)=>{let n=e._subIndexBufferStart[a],s=e._subIndexBufferCount[a]+n;for(let e=n;e<s;e++){let a=o[e],n=l[a],s=t[n.x],i=t[n.y],u=t[n.z],f=t[n.w];c[a]=new r.Vector4(s,i,u,f)}})});let f=a._inverseBindPoses,h=t.bones,d=[],p=new r.Matrix4x4;h.forEach((e,t)=>{d[t]=new r.Matrix4x4,r.Matrix4x4.multiply(s,e.transform.worldMatrix,p),r.Matrix4x4.multiply(p,f[t],d[t])});let m=new r.Matrix4x4,_=new r.Vector3,T=new r.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),x=new r.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(let e=0;e<i.length;e++){let t=i[e],a=c[e],n=u[e];if(a&&n){for(let e=0;e<16;e++)m.elements[e]=d[a.x].elements[e]*n.x,m.elements[e]+=d[a.y].elements[e]*n.y,m.elements[e]+=d[a.z].elements[e]*n.z,m.elements[e]+=d[a.w].elements[e]*n.w;r.Vector3.transformV3ToV3(t,m,_),r.Vector3.min(T,_,T),r.Vector3.max(x,_,x)}}i=null,l=u=c=null,o=null,d=null,t.localBounds.setMin(T),t.localBounds.setMax(x),t.localBounds=t.localBounds}fixSkinnedSprite(e,t){let a=this._data.skins[e.skin],n=t.getComponent(r.SkinnedMeshRenderer);a.joints.forEach(e=>{let r=this._nodes[e];n.bones.push(r)}),null==a.skeleton&&(a.skeleton=a.joints[0]),n.rootBone=this._nodes[a.skeleton],n.bones=n.bones,this.calSkinnedSpriteLocalBounds(t)}getAnimationRoot(e){const r=(e,t)=>{if(!e)return!1;if(-1==e.indexOf(t))for(let a=0;a<e.length;a++){let n=this._data.nodes[e[a]];if(r(n.children,t))return!0}return!0};let t=e[0].target.node;for(let e=0;e<this._data.scenes.length;e++){let a=this._data.scenes[e];if(r(a.nodes,t))return this._scenes[e]}return null}getAnimationPath(e,r){let t=[];if(e==r)return t;let a=r;for(;a.parent!=e;)a=a.parent,t.push(a.name);return t=t.reverse(),t.push(r.name),t}loadAnimations(e){e&&e.forEach((e,r)=>{this.loadAnimation(e)})}loadAnimation(e){return this.createAnimator(e)}createAnimator(e){let t=e.channels;e.samplers;let a=this.getAnimationRoot(t);if(!a)return null;let n=a.getComponent(r.Animator);if(!n){n=a.addComponent(r.Animator);let e=new r.AnimatorControllerLayer("AnimatorLayer");n.addControllerLayer(e),e.defaultWeight=1}let s=this.createAnimatorClip(e,a),o=n.getControllerLayer(),i=s.name;o.getAnimatorState(i)&&(i=s.name=`${i}_${this.generateId(i)}`);let l=new r.AnimatorState;return l.name=i,l.clip=s,o.addState(l),o.defaultState=l,o.playOnWake=!0,n}createAnimatorClip(e,t){let a=new r.AnimationClip,n=0,s=e.channels,o=e.samplers,i=[];s.forEach((e,a)=>{var s;let l=e.target,u=o[e.sampler],c=l.path,f=this.getBufferwithAccessorIndex(u.input),h=this.getBufferwithAccessorIndex(u.output),d=new Float32Array(f),p=new Float32Array(h),m=this._nodes[l.node],_=this.getAnimationPath(t,m);if("weights"==c){let e=null===(s=m.getComponent(r.MeshFilter))||void 0===s?void 0:s.sharedMesh;if(e&&e.morphTargetData){let t=m.getComponent(r.SkinnedMeshRenderer)?"SkinnedMeshRenderer":"MeshRenderer",a=e.morphTargetData,s=a.channelCount;if(p.length/d.length==s)for(let e=0;e<s;e++){let r=a.getMorphChannelbyIndex(e).name,o={};i.push(o),o.paths=_,o.interpolation=u.interpolation,o.timeArray=d,o.valueArray=new Float32Array(d.length);for(let r=0;r<d.length;r++)o.valueArray[r]=p[r*s+e];o.propertyOwner=t,o.propertise=[],o.propertise.push("morphTargetValues"),o.propertise.push(r),o.propertyLength=o.propertise.length,o.type=0,o.callbackFunc="_changeMorphTargetValue",o.callbackParams=[r],o.propertyChangePath="morphTargetValues",o.duration=o.timeArray[o.timeArray.length-1],n=Math.max(n,o.duration)}}}else{let e={};i.push(e),e.timeArray=d,e.valueArray=p;let r=u.interpolation;switch(e.interpolation=r,e.paths=_,c){case"translation":e.propertyOwner="transform",e.propertyLength=1,e.propertise=[],e.propertise.push("localPosition"),e.type=1;break;case"rotation":e.propertyOwner="transform",e.propertyLength=1,e.propertise=[],e.propertise.push("localRotation"),e.type=2;break;case"scale":e.propertyOwner="transform",e.propertyLength=1,e.propertise=[],e.propertise.push("localScale"),e.type=3}e.duration=e.timeArray[e.timeArray.length-1],n=Math.max(n,e.duration)}}),a.name=e.name?e.name:`Animation_${this.generateId("Animation")}`,a._duration=n,a.islooping=!0,a._frameRate=30;let l=i.length,u=a._nodes;u.count=l;let c=a._nodesMap={},f=a._nodesDic={};for(let e=0;e<l;e++){let t=new r.KeyframeNode,a=i[e];u.setNodeByIndex(e,t),t._indexInList=e;let n=t.type=a.type,s=a.paths.length;t._setOwnerPathCount(s);let o=a.paths;for(let e=0;e<s;e++)t._setOwnerPathByIndex(e,o[e]);let l=t._joinOwnerPath("/"),h=c[l];h||(c[l]=h=[]),h.push(t),t.propertyOwner=a.propertyOwner;let d=a.propertyLength;t._setPropertyCount(d);for(let e=0;e<d;e++)t._setPropertyByIndex(e,a.propertise[e]);let p=l+"."+t.propertyOwner+"."+t._joinProperty(".");f[p]=p,t.fullPath=p,t.callbackFunData=a.callbackFunc,t.callParams=a.callbackParams,t.propertyChangePath=a.propertyChangePath;let m=a.timeArray.length;for(let e=0;e<m;e++)switch(n){case 0:let n=new r.FloatKeyframe;switch(t._setKeyframeByIndex(e,n),n.time=a.timeArray[e],a.interpolation){case"CUBICSPLINE":n.value=a.valueArray[3*e+1],n.inTangent=a.valueArray[3*e+0],n.outTangent=a.valueArray[3*e+2];break;case"STEP":n.value=a.valueArray[e],n.inTangent=1/0,n.outTangent=1/0;break;default:{n.value=a.valueArray[e];let r=0==e?e:e-1,t=a.timeArray[r],s=a.valueArray[r],o=r==e?1:n.time-t;n.inTangent=(n.value-s)/o;let i=e==m-1?e:e+1,l=a.timeArray[i],u=a.valueArray[i],c=i==e?1:l-n.time;n.outTangent=(u-n.value)/c,r==e&&(n.inTangent=n.outTangent),i==e&&(n.outTangent=n.inTangent)}}break;case 1:case 3:case 4:let s=new r.Vector3Keyframe;t._setKeyframeByIndex(e,s);let o=s.time=a.timeArray[e],i=s.inTangent,l=s.outTangent,u=s.value;switch(a.interpolation){case"CUBICSPLINE":u.setValue(a.valueArray[9*e+3],a.valueArray[9*e+4],a.valueArray[9*e+5]),i.setValue(a.valueArray[9*e+0],a.valueArray[9*e+1],a.valueArray[9*e+2]),l.setValue(a.valueArray[9*e+6],a.valueArray[9*e+7],a.valueArray[9*e+8]);break;case"STEP":u.setValue(a.valueArray[3*e],a.valueArray[3*e+1],a.valueArray[3*e+2]),i.setValue(1/0,1/0,1/0),l.setValue(1/0,1/0,1/0);break;default:{u.setValue(a.valueArray[3*e],a.valueArray[3*e+1],a.valueArray[3*e+2]);let r=0==e?e:e-1,t=a.timeArray[r],n=a.valueArray[3*r],s=a.valueArray[3*r+1],c=a.valueArray[3*r+2],f=r==e?1:o-t;i.x=(u.x-n)/f,i.y=(u.y-s)/f,i.z=(u.z-c)/f;let h=e==m-1?e:e+1,d=a.timeArray[h],p=a.valueArray[3*h],_=a.valueArray[3*h+1],T=a.valueArray[3*h+2],x=h==e?1:d-o;l.x=(p-u.x)/x,l.y=(_-u.y)/x,l.z=(T-u.z)/x,r==e&&l.cloneTo(i),h==e&&i.cloneTo(l)}}break;case 2:let c=new r.QuaternionKeyframe;t._setKeyframeByIndex(e,c);let f=c.time=a.timeArray[e],h=c.inTangent,d=c.outTangent,p=c.value;switch(a.interpolation){case"CUBICSPLINE":p.set(a.valueArray[12*e+4],a.valueArray[12*e+5],a.valueArray[12*e+6],a.valueArray[12*e+7]),h.setValue(a.valueArray[12*e+0],a.valueArray[12*e+1],a.valueArray[12*e+2],a.valueArray[12*e+3]),d.setValue(a.valueArray[12*e+8],a.valueArray[12*e+9],a.valueArray[12*e+10],a.valueArray[12*e+11]);break;case"STEP":p.set(a.valueArray[4*e+0],a.valueArray[4*e+1],a.valueArray[4*e+2],a.valueArray[4*e+3]),h.setValue(1/0,1/0,1/0,1/0),d.setValue(1/0,1/0,1/0,1/0);break;default:{p.set(a.valueArray[4*e+0],a.valueArray[4*e+1],a.valueArray[4*e+2],a.valueArray[4*e+3]);let r=0==e?e:e-1,t=a.timeArray[r],n=a.valueArray[4*r],s=a.valueArray[4*r+1],o=a.valueArray[4*r+2],i=a.valueArray[4*r+3],l=r==e?1:f-t;h.x=(p.x-n)/l,h.y=(p.y-s)/l,h.z=(p.z-o)/l,h.w=(p.w-i)/l;let u=e==m-1?e:e+1,c=a.timeArray[u],_=a.valueArray[4*u],T=a.valueArray[4*u+1],x=a.valueArray[4*u+2],S=a.valueArray[4*u+3];p.x*_+p.y*T+p.z*x+p.w*S<0&&(_*=-1,T*=-1,x*=-1,S*=-1,a.valueArray[4*u]=_,a.valueArray[4*u+1]=T,a.valueArray[4*u+2]=x,a.valueArray[4*u+3]=S);let g=u==e?1:c-f;d.x=(_-p.x)/g,d.y=(T-p.y)/g,d.z=(x-p.z)/g,d.w=(S-p.w)/g,r==e&&d.cloneTo(h),u==e&&h.cloneTo(d)}}}}return i=null,a}}a._Extensions={};class n{constructor(){}}r.Laya.addInitCallback(()=>t.init());const s="KHR_materials_anisotropy";class o{constructor(e){this.name=s,this._resource=e}loadAdditionTextures(e,r){let t=this._resource.data.materials,a=this._resource.data.textures;if(t&&a){let a=[];return t.forEach(t=>{var n;let s=null===(n=t.extensions)||void 0===n?void 0:n.KHR_materials_anisotropy;if(s&&s.anisotropyTexture){let t=this._resource.loadTextureFromInfo(s.anisotropyTexture,!1,e,r);a.push(t)}}),Promise.all(a)}return Promise.resolve()}additionMaterialProperties(e,a){var n,s;let o=e.extensions.KHR_materials_anisotropy,i=null!==(n=o.anisotropyStrength)&&void 0!==n?n:0,l=null!==(s=o.anisotropyRotation)&&void 0!==s?s:0;if(a.setDefine(r.PBRShaderLib.DEFINE_ANISOTROPY,!0),a.setFloat("u_AnisotropyStrength",i),a.setFloat("u_AnisotropyRotation",l),o.anisotropyTexture){let e=this._resource.getTextureWithInfo(o.anisotropyTexture);a.setTexture("u_AnisotropyTexture",e),a.setDefine(t.Define_AnisotropyMap,!0)}}}a.registerExtension(s,e=>new o(e));const i="KHR_materials_clearcoat";class l{constructor(e){this.name=i,this._resource=e}loadAdditionTextures(e,r){let t=this._resource.data.materials,a=this._resource.data.textures;if(t&&a){let a=[];return t.forEach(t=>{var n;let s=null===(n=t.extensions)||void 0===n?void 0:n.KHR_materials_clearcoat;if(s){if(s.clearcoatTexture){let t=this._resource.loadTextureFromInfo(s.clearcoatTexture,!1,e,r);a.push(t)}if(s.clearcoatRoughnessTexture){let t=this._resource.loadTextureFromInfo(s.clearcoatRoughnessTexture,!1,e,r);a.push(t)}if(s.clearcoatNormalTexture){let t=this._resource.loadTextureFromInfo(s.clearcoatNormalTexture,!1,e,r);a.push(t)}}}),Promise.all(a)}return Promise.resolve()}additionMaterialProperties(e,a){var n,s,o;let i=e.extensions.KHR_materials_clearcoat,l=null!==(n=i.clearcoatFactor)&&void 0!==n?n:0,u=null!==(s=i.clearcoatRoughnessFactor)&&void 0!==s?s:0;if(a.setDefine(r.PBRShaderLib.DEFINE_CLEARCOAT,!0),a.setFloat("u_ClearCoatFactor",l),i.clearcoatTexture&&this._resource.setMaterialTextureProperty(a,i.clearcoatTexture,"u_ClearCoatTexture",t.Define_ClearCoatMap,"u_ClearCoatMapTransform",t.Define_ClearCoatMapTransform),a.setFloat("u_ClearCoatRoughness",u),i.clearcoatRoughnessTexture&&this._resource.setMaterialTextureProperty(a,i.clearcoatRoughnessTexture,"u_ClearCoatRoughnessTexture",t.Define_ClearCoatRoughnessMap,"u_ClearCoatRoughnessMapTransform",t.Define_ClearCoatRoughnessMapTransform),i.clearcoatNormalTexture){a.setDefine(r.PBRShaderLib.DEFINE_CLEARCOAT_NORMAL,!0),this._resource.setMaterialTextureProperty(a,i.clearcoatNormalTexture,"u_ClearCoatNormalTexture",null,"u_ClearCoatNormalMapTransform",t.Define_ClearCoatNormalMapTransform);let e=null!==(o=i.clearcoatNormalTexture.scale)&&void 0!==o?o:1;a.setFloat("u_ClearCoatNormalScale",e)}}}a.registerExtension(i,e=>new l(e));const u="KHR_materials_emissive_strength";class c{constructor(e){this.name=u,this._resource=e}additionMaterialProperties(e,r){var t;let a=null!==(t=e.extensions.KHR_materials_emissive_strength.emissiveStrength)&&void 0!==t?t:1;r.setFloat("u_EmissionStrength",a)}}a.registerExtension(u,e=>new c(e));const f="KHR_materials_ior";class h{constructor(e){this.name=f,this._resource=e}additionMaterialProperties(e,t){var a;let n=null!==(a=e.extensions.KHR_materials_ior.ior)&&void 0!==a?a:1.5;t.setDefine(r.PBRShaderLib.DEFINE_IOR,!0),t.setFloat("u_Ior",n)}}a.registerExtension(f,e=>new h(e));const d="KHR_materials_iridescence";class p{constructor(e){this.name=d,this._resource=e}loadAdditionTextures(e,r){let t=this._resource.data.materials,a=this._resource.data.textures;if(t&&a){let a=[];return t.forEach(t=>{var n;let s=null===(n=t.extensions)||void 0===n?void 0:n.KHR_materials_iridescence;if(s){if(s.iridescenceTexture){let t=this._resource.loadTextureFromInfo(s.iridescenceTexture,!1,e,r);a.push(t)}if(s.iridescenceThicknessTexture){let t=this._resource.loadTextureFromInfo(s.iridescenceThicknessTexture,!1,e,r);a.push(t)}}}),Promise.all(a)}return Promise.resolve()}additionMaterialProperties(e,a){var n,s,o,i;let l=e.extensions.KHR_materials_iridescence,u=null!==(n=l.iridescenceFactor)&&void 0!==n?n:0,c=null!==(s=l.iridescenceIor)&&void 0!==s?s:1.3,f=null!==(o=l.iridescenceThicknessMinimum)&&void 0!==o?o:100,h=null!==(i=l.iridescenceThicknessMaximum)&&void 0!==i?i:400;a.setDefine(r.PBRShaderLib.DEFINE_IRIDESCENCE,!0),a.setFloat("u_IridescenceFactor",u),a.setFloat("u_IridescenceIor",c),a.setFloat("u_IridescenceThicknessMinimum",f),a.setFloat("u_IridescenceThicknessMaximum",h),l.iridescenceTexture&&this._resource.setMaterialTextureProperty(a,l.iridescenceTexture,"u_IridescenceTexture",t.Define_IridescenceMap,"u_IridescenceMapTransform",t.Define_IridescenceMapTransform),l.iridescenceThicknessTexture&&this._resource.setMaterialTextureProperty(a,l.iridescenceThicknessTexture,"u_IridescenceThicknessTexture",t.Define_IridescenceThicknessMap,"u_IridescenceThicknessMapTransform",t.Define_IridescenceThicknessMapTransform)}}a.registerExtension(d,e=>new p(e));const m="KHR_materials_sheen";class _{constructor(e){this.name=m,this._resource=e}loadAdditionTextures(e,r){let t=this._resource.data.materials,a=this._resource.data.textures;if(t&&a){let a=[];return t.forEach(t=>{var n;let s=null===(n=t.extensions)||void 0===n?void 0:n.KHR_materials_sheen;if(s){if(s.sheenColorTexture){let t=!1,n=this._resource.loadTextureFromInfo(s.sheenColorTexture,t,e,r);a.push(n)}if(s.sheenRoughnessTexture){let t=!1,n=this._resource.loadTextureFromInfo(s.sheenRoughnessTexture,t,e,r);a.push(n)}}}),Promise.all(a)}return Promise.resolve()}additionMaterialProperties(e,a){var n;let s=e.extensions.KHR_materials_sheen;a.setDefine(r.PBRShaderLib.DEFINE_SHEEN,!0);let o=new r.Vector3(0,0,0);s.sheenColorFactor&&o.fromArray(s.sheenColorFactor);let i=null!==(n=s.sheenRoughnessFactor)&&void 0!==n?n:0;a.setVector3("u_SheenColorFactor",o),a.setFloat("u_SheenRoughness",i),s.sheenColorTexture&&this._resource.setMaterialTextureProperty(a,s.sheenColorTexture,"u_SheenColorTexture",t.Define_SheenColorMap,"u_SheenColorMapTransform",t.Define_SheenColorMapTransform),s.sheenRoughnessTexture&&this._resource.setMaterialTextureProperty(a,s.sheenRoughnessTexture,"u_SheenRoughnessTexture",t.Define_SheenRoughnessMap,"u_SheenRoughnessMapTransform",t.Define_SheenRoughnessMapTransform)}}a.registerExtension(m,e=>new _(e));const T="KHR_materials_specular";class x{constructor(e){this.name=T,this._resource=e}loadAdditionTextures(e,r){let t=[],a=this._resource.data.materials,n=this._resource.data.textures;return a&&n&&a.forEach(a=>{var n;let s=null===(n=a.extensions)||void 0===n?void 0:n.KHR_materials_specular;if(s){if(s.specularTexture){let a=!1,n=this._resource.loadTextureFromInfo(s.specularTexture,a,e,r);t.push(n)}if(s.specularColorTexture){let a=!0,n=this._resource.loadTextureFromInfo(s.specularColorTexture,a,e,r);t.push(n)}}}),Promise.all(t)}additionMaterialProperties(e,a){var n;let s=e.extensions.KHR_materials_specular,o=null!==(n=s.specularFactor)&&void 0!==n?n:1,i=new r.Vector3(1,1,1);s.specularColorFactor&&i.fromArray(s.specularColorFactor),a.setDefine(r.Shader3D.getDefineByName("SPECULAR"),!0),a.setFloat("u_SpecularFactor",o),a.setVector3("u_SpecularColorFactor",i),s.specularTexture&&this._resource.setMaterialTextureProperty(a,s.specularTexture,"u_SpecularFactorTexture",t.Define_SpecularFactorMap,"u_SpecularFactorMapTransfrom",t.Define_SpecularFactorMapTransform),s.specularColorTexture&&this._resource.setMaterialTextureProperty(a,s.specularColorTexture,"u_SpecularColorTexture",t.Define_SpecularColorMap,"u_SpecularColorMapTransform",t.Define_SpecularColorMapTransform)}}a.registerExtension(T,e=>new x(e));const S="KHR_materials_transmission";class g{constructor(e){this.name=S,this._resource=e}loadAdditionTextures(e,r){let t=this._resource.data.materials,a=this._resource.data.textures;if(t&&a){let a=[];return t.forEach(t=>{var n;let s=null===(n=t.extensions)||void 0===n?void 0:n.KHR_materials_transmission;if(s&&s.transmissionTexture){let t=!1,n=this._resource.loadTextureFromInfo(s.transmissionTexture,t,e,r);a.push(n)}}),Promise.all(a)}return Promise.resolve()}additionMaterialProperties(e,a){var n;let s=e.extensions.KHR_materials_transmission,o=null!==(n=s.transmissionFactor)&&void 0!==n?n:0;a.materialRenderMode=r.MaterialRenderMode.RENDERMODE_CUSTOME,a.renderQueue=3e3,a.setDefine(r.PBRShaderLib.DEFINE_TRANSMISSION,!0),a.setFloat("u_TransmissionFactor",o),s.transmissionTexture&&this._resource.setMaterialTextureProperty(a,s.transmissionTexture,"u_TransmissionTexture",t.Define_TransmissionMap,"u_TransmissionMapTransform",t.Define_TransmissionMapTransform)}}a.registerExtension(S,e=>new g(e));const M="KHR_materials_unlit";class A{constructor(e){this.name=M,this._resource=e}createMaterial(e){let t=new r.UnlitMaterial,a=e.pbrMetallicRoughness;if(a){if(a.baseColorFactor){let e=t.albedoColor;e.fromArray(a.baseColorFactor),e.toGamma(e),t.albedoColor=e}a.baseColorTexture&&(t.albedoTexture=this._resource.getTextureWithInfo(a.baseColorTexture))}return this._resource.applyMaterialRenderState(e,t),t}}a.registerExtension(M,e=>new A(e));const C="KHR_materials_volume";class y{constructor(e){this.name=C,this._resource=e}loadAdditionTextures(e,r){let t=this._resource.data.materials,a=this._resource.data.textures;if(t&&a){let a=[];return t.forEach(t=>{var n;let s=null===(n=t.extensions)||void 0===n?void 0:n.KHR_materials_volume;if(s&&s.thicknessTexture){let t=!1,n=this._resource.loadTextureFromInfo(s.thicknessTexture,t,e,r);a.push(n)}}),Promise.all(a)}return Promise.resolve()}additionMaterialProperties(e,a){var n,s;let o=e.extensions.KHR_materials_volume;a.setDefine(r.PBRShaderLib.DEFINE_THICKNESS,!0);let i=null!==(n=o.thicknessFactor)&&void 0!==n?n:0,l=null!==(s=o.attenuationDistance)&&void 0!==s?s:65504;a.setFloat("u_VolumeThicknessFactor",i),a.setFloat("u_VolumeAttenuationDistance",l);let u=new r.Vector3(1,1,1);o.attenuationColor&&u.fromArray(o.attenuationColor),a.setVector3("u_VolumeAttenuationColor",u),o.thicknessTexture&&this._resource.setMaterialTextureProperty(a,o.thicknessTexture,"u_VolumeThicknessTexture",t.Define_VolumeThicknessMap,"u_VoluemThicknessMapTransform",t.Define_VolumeThicknessMapTransform)}}a.registerExtension(C,e=>new y(e));const R="KHR_texture_transform",D=new r.Matrix3x3,v=new r.Matrix3x3,E=new r.Vector2,N=new r.Vector2;class F{constructor(e){this.name=R,this._resource=e}createTransform(e){var t;E.setValue(0,0),e.offset&&E.fromArray(e.offset),r.Matrix3x3.createFromTranslation(E,D);let a=null!==(t=e.rotation)&&void 0!==t?t:0;r.Matrix3x3.createFromRotation(-a,v),N.setValue(1,1),e.scale&&N.fromArray(e.scale);let n=new r.Matrix3x3;return r.Matrix3x3.multiply(D,v,n),n.scale(N,n),n}loadExtensionTextureInfo(e){var r;let t=null===(r=e.extensions)||void 0===r?void 0:r.KHR_texture_transform;return{transform:this.createTransform(t),texCoord:t.texCoord}}}a.registerExtension(R,e=>new F(e));r.Loader.registerLoader(["gltf"],class{load(e){return e.loader.fetch(e.url,"json",e.progress.createCallback(.5),e.options).then(r=>{let t=new a;return t._parse(r,e.url,e.progress).then(()=>t.onLoad())})}});r.Loader.registerLoader(["glb"],class{load(e){return e.loader.fetch(e.url,"arraybuffer",e.progress.createCallback(.5),e.options).then(r=>{let t=new a;return t._parseglb(r,e.url,e.progress).then(()=>t.onLoad())})}}),e.KHR_materials_anisotropy=o,e.KHR_materials_clearcoat=l,e.KHR_materials_emissive_strength=c,e.KHR_materials_ior=h,e.KHR_materials_iridescence=p,e.KHR_materials_sheen=_,e.KHR_materials_specular=x,e.KHR_materials_transmission=g,e.KHR_materials_unlit=A,e.KHR_materials_volume=y,e.KHR_texture_transform=F,e.glTFResource=a,e.glTFShader=t}(window.Laya=window.Laya||{},Laya);
@@ -0,0 +1 @@
1
+ !function(t,e){"use strict";let n,i,o;function s(t,s,r){n||(n=new e.Vector3(1,0,0),i=new e.Vector3(0,1,0),o=new e.Vector3);var a=e.Vector3.dot(t,s);return a<-.99999999?(e.Vector3.cross(n,t,o),e.Vector3.scalarLength(o)<1e-6&&e.Vector3.cross(i,t,o),e.Vector3.normalize(o,o),e.Quaternion.createFromAxisAngle(o,Math.PI,r),!0):a>.99999999?(r.x=0,r.y=0,r.z=0,r.w=1,!1):(e.Vector3.cross(t,s,o),r.x=o.x,r.y=o.y,r.z=o.z,r.w=1+a,r.normalize(r),!0)}let r=new e.Vector3,a=new e.Vector3;function l(t,e,n,i=1e-6){const o=e.vsub(t,r).normalize(),s=n.vsub(t,a).normalize(),l=Math.abs(o.dot(s));return Math.abs(l-1)<i}function h(t,n,i){const o=1e-8,s=e.Vector3.dot(n,n),r=2*e.Vector3.dot(t,n),a=e.Vector3.dot(t,t)-e.Vector3.dot(i,i);if(Math.abs(s)<o){if(Math.abs(r)<o)return Math.abs(a)<o?0:NaN;const t=-a/r;return t>=-o?t<0?0:t:NaN}const l=r*r-4*s*a;if(l<-o)return NaN;if(Math.abs(l)<=o){const t=-r/(2*s);return t>=-o?t<0?0:t:NaN}const h=Math.sqrt(l),c=(-r+h)/(2*s),u=(-r-h)/(2*s);let d=!1,m=!1,g=0,p=0;return c>=-o&&(d=!0,g=c<0?0:c),u>=-o&&(m=!0,p=u<0?0:u),d||m?d&&!m?g:!d&&m?p:Math.abs(g)<=Math.abs(p)?g:p:NaN}function c(t,n,i){let o=n.elements,r=new e.Vector3(o[12],o[13],o[14]),a=new e.Vector3(o[8],o[9],o[10]);a.normalize();let l=h(r,a,t);if(isNaN(l))return!1;let c=new e.Vector3;return e.Vector3.scale(a,l,c),e.Vector3.add(r,c,c),c.normalize(),s(c,t.clone().normalize(),i),!0}function u(t){let e=t.elements,n=Math.sqrt(e[0]**2+e[1]**2+e[2]**2);return e[0]/=n,e[1]/=n,e[2]/=n,n=Math.sqrt(e[4]**2+e[5]**2+e[6]**2),e[4]/=n,e[5]/=n,e[6]/=n,n=Math.sqrt(e[8]**2+e[9]**2+e[10]**2),e[8]/=n,e[9]/=n,e[10]/=n,t}class d{constructor(t=.5){this.k=t,this.lastv=0}in(t){let e=this.k,n=1-e;return this.lastv=t*e+this.lastv*n,this.lastv}}new e.Vector3,new e.Quaternion,new e.Vector3,new e.Vector3,new e.Vector3,new e.Vector3,new e.Vector3,new e.Vector3,new e.Quaternion,new e.Quaternion,new e.Quaternion;class m{constructor(t=1){this.dampingFactor=.1,this.poleTarget=null,this._targetPos=new e.Vector3,this._currentEndPos=new e.Vector3,this._jointToEndVec=new e.Vector3,this._jointToTargetVec=new e.Vector3,this._pivotPos=new e.Vector3,this._rotationDelta=new e.Quaternion,this._calcVecA=new e.Vector3,this._calcVecB=new e.Vector3,this._calcVecC=new e.Vector3,this._calcQuat=new e.Quaternion,this.maxIterations=t}solve(t,n,i,o){const s=n.joints;if(s.length<2)return!1;const r=o?s.length-2:s.length-1,a=s[r],l=s[0].position;i.cloneTo(this._targetPos);const h=this.calculateTotalLength(s,r);if(e.Vector3.distance(l,this._targetPos)>h){const t=this._calcVecA;this._targetPos.vsub(l,t),t.normalize();const n=.9999*h;t.scale(n,t),e.Vector3.add(l,t,this._targetPos)}this.poleTarget&&s.length>2&&this.preRotateToPole(s,r,l);let c=0,u=!1;const d=n.maxError*n.maxError;for(a.position.cloneTo(this._currentEndPos);c<this.maxIterations&&(u=this.solveOneIteration(s,r,this._targetPos,d),!u);)c++,c<this.maxIterations&&(this.updateAllJointPositions(s,r),a.position.cloneTo(this._currentEndPos));return this.updateAllJointPositions(s,r),this.poleTarget&&s.length>2&&this.solvePoleVector(t,n,s,r,l),t.current_iteration=c,t.current_error=Math.sqrt(e.Vector3.distanceSquared(a.position,this._targetPos)),u}preRotateToPole(t,n,i){const o=this.poleTarget.pos,r=t[1],a=t[n],l=this._calcVecA;if(a.position.vsub(i,l),l.lengthSquared()<1e-6)return;l.normalize();const h=this._calcVecB;r.position.vsub(i,h);const c=this._jointToEndVec,u=e.Vector3.dot(h,l),d=this._calcVecC;l.scale(u,d),h.vsub(d,c);const m=this._jointToTargetVec;o.vsub(i,m);const g=this._pivotPos,p=e.Vector3.dot(m,l);if(l.scale(p,d),m.vsub(d,g),c.lengthSquared()>1e-4&&g.lengthSquared()>1e-4){c.normalize(),g.normalize();const i=this._calcQuat;s(c,g,i);const o=t[0];e.Quaternion.multiply(i,o.rotationQuat,o.rotationQuat),this.updateAllJointPositions(t,n)}}solveOneIteration(t,n,i,o){const r=this._currentEndPos,a=this._jointToEndVec,l=this._jointToTargetVec,h=this._rotationDelta,c=this._pivotPos;for(let u=n-1;u>=0;u--){const n=t[u];if(n.fixed)continue;if(n.position.cloneTo(c),e.Vector3.distanceSquared(r,i)<o)return!0;if(r.vsub(c,a),i.vsub(c,l),a.lengthSquared()<1e-6||l.lengthSquared()<1e-6)continue;a.normalize(),l.normalize(),s(a,l,h),this.dampingFactor<1&&this.dampingFactor>0&&e.Quaternion.slerp(e.Quaternion.DEFAULT,h,this.dampingFactor,h);const d=n.rotationQuat;e.Quaternion.multiply(h,d,d),d.normalize(d),n.rotationQuat=d,n.constraint&&n.constraint.enable&&n.constraint.doConsraint(n),r.vsub(c,a),e.Vector3.transformQuat(a,h,a),e.Vector3.add(c,a,r)}return!1}updateAllJointPositions(t,n){for(let i=0;i<n;i++){const n=t[i],o=t[i+1];if(o){const t=this._calcVecA;e.Vector3.transformQuat(o.relPos,n.rotationQuat,t);const i=o.position;i.x=n.position.x+t.x,i.y=n.position.y+t.y,i.z=n.position.z+t.z,o.position=i}}}calculateTotalLength(t,e){let n=0;for(let i=0;i<e;i++)n+=t[i].length;return n}solvePoleVector(t,n,i,o,s){const r=this._calcVecA,a=this._calcVecB,l=this._calcVecC,h=this._jointToEndVec,c=this._jointToTargetVec,u=this._pivotPos,d=i[o].position,m=this.poleTarget.pos,g=n.joints[1].position;d.vsub(s,r),m.vsub(s,a),g.vsub(s,l);const p=r.lengthSquared();if(p<1e-6)return;const f=Math.sqrt(p);r.scale(1/f,r);const x=e.Vector3.dot(l,r),w=h;r.scale(x,w),l.vsub(w,h);const _=e.Vector3.dot(a,r),y=c;r.scale(_,y),a.vsub(y,c);const V=h.length(),z=c.length();if(V>.001&&z>.001){h.scale(1/V,h),c.scale(1/z,c);const i=Math.max(-1,Math.min(1,e.Vector3.dot(h,c)));e.Vector3.cross(h,c,u);const o=e.Vector3.dot(u,r);let s=Math.atan2(o,i);if(Math.abs(s)>1e-4){t.pole_rot=s;const i=this._rotationDelta;e.Quaternion.createFromAxisAngle(r,s,i),n.rotateJoint(0,i)}}}}var g=new e.Vector3;class p{constructor(t=0){this.roations=[],this.positions=[],this.length=t}set length(t){if(this.roations.length!=t){this.roations.length=t,this.positions.length=t;for(let n=0;n<t;n++)this.roations[n]=new e.Quaternion,this.positions[n]=new e.Vector3}}get length(){return this.roations.length}captureBonePose(t){let n=t.length;this.roations.length=n;for(let i=0;i<n;i++){let n=t[i].bone.transform,o=this.roations[i]||new e.Quaternion,s=this.positions[i]||new e.Vector3;this.roations[i]=o,this.positions[i]=s,n.rotation.cloneTo(o),n.position.cloneTo(s)}return this}captureIKResult(t){let n=t.length;this.roations.length=n;for(let i=0;i<n;i++){let n=t[i],o=this.roations[i]||new e.Quaternion;n.rotationQuat.cloneTo(o),this.roations[i]=o;let s=this.positions[i]||new e.Vector3;n.position.cloneTo(s),this.positions[i]=s}return this}copy(t){this.length=t.length;for(let n=0,i=t.length;n<i;n++)this.roations[n]||(this.roations[n]=new e.Quaternion),this.positions[n]||(this.positions[n]=new e.Vector3),t.roations[n].cloneTo(this.roations[n]),t.positions[n].cloneTo(this.positions[n])}blend(t,n,i,o=null){let s=this.roations.length;if(o||(o=new p(s)),o.length=s,!t||0==t.roations.length)return void o.copy(this);if(0==this.roations.length)return void o.copy(t);n<0&&(n=0),n>1&&(n=1);let r=o.roations,a=o.positions,l=new e.Vector3;this.positions[0].scale(1-n,l);let h=new e.Vector3;t.positions[0].scale(n,h),l.vadd(h,l),l.cloneTo(a[0]);for(let o=0;o<s;o++){let l=r[o],h=this.roations[o],c=t.roations[o];if(c?e.Quaternion.slerp(h,c,n,l):h.cloneTo(l),o<s-1){const t=i[o+1];e.Vector3.transformQuat(t.relPos,l,g),a[o].vadd(g,t.position)}}}applyToBone(t){let n=t.length;for(let i=0;i<n-1;i++){let n=t[i];if(!n.bone)continue;if(n.fixed)continue;if(!this.roations[i])return;let o=n.bone.transform,s=this.roations[i],r=n.position;const a=t[i+1];e.Vector3.transformQuat(a.relPos,s,g),r.vadd(g,a.position),a.position=a.position,o.position=r,o.rotation=s}}}class f{constructor(){this.finalLayer=new p,this.lastSet=new p,this.fadeSrc=null,this.fadeTarget=null,this.fadeStart=0,this.fadeTm=0}getCurrent(){return this.finalLayer}set(t){t&&(this.finalLayer.copy(t),this.lastSet.copy(t))}fadeTo(t,e){this.fadeStart=Date.now(),this.fadeTm=e,this.fadeSrc=new p,this.fadeSrc.copy(this.finalLayer),this.fadeTarget=new p,this.fadeTarget.copy(t)}stopFade(){this.fadeStart=0}isFading(){return 0!==this.fadeStart}apply(t){if(this.fadeStart>0){let e=Date.now()-this.fadeStart;if(e>this.fadeTm)this.fadeStart=0;else{let n=e/this.fadeTm;n=Math.pow(n,.5),this.fadeSrc.blend(this.fadeTarget,n,t,this.finalLayer)}}this.finalLayer.applyToBone(t)}}var x=new Map;function w(t){let e=x.get(t);return e||(e=new _),x.set(t,e),e}class _{constructor(){this._mapBoneJoint={}}getJoint(t){return this._mapBoneJoint[t]}addJoint(t,e){this._mapBoneJoint[t]=e}}let y=new e.Quaternion,V=new e.Vector3,z=new e.Quaternion;class b{constructor(t){this.name="",this._target=null,this.layerMgr=new f,this.staticLayer=new p,this.animLayer=new p,this.ik_result=new p,this._isRunning=!1,this.enable=!0,this._jointMgr=null,this.totalLength=0,this.blendWeight=1,this.maxError=.01,this._weightSmooth=1,this._jointMgr=w(t.owner),this._weightSmooth&&(this.wSmoother=new d(.1))}get weightSmooth(){return this._weightSmooth}set weightSmooth(t){this._weightSmooth=t,this.wSmoother=t<1&&t>0?new d(t):null}set isRunning(t){this._isRunning!=t&&(t?this.layerMgr.stopFade():this.fadeToAnim()),this._isRunning=t}get isRunning(){return this._isRunning}set target(t){this._target=t}get target(){return this._target}set endFixed(t){let e=this.joints.length;e>2&&(this.joints[e-2].fixed=t)}get endFixed(){let t=this.joints.length;return t>2&&this.joints[t-2].fixed}visualize(t){}get end_effector(){return this._end_effector}addJoint(t){if(this.end_effector)throw"已经结束了";let n=t.bone;if(!n)return void console.log("没有对应的Sprite3D对象就没有ik的必要");this._jointMgr&&(this._jointMgr.getJoint(t.name)||this._jointMgr.addJoint(t.name,t));let i,o=this.joints,s=o[o.length-1];if(o.push(t),s){if(t.parent=s,i=s.bone,!i)throw"no parentnode";let o=i.transform.rotation,r=i.transform.position,a=n.transform.position.clone();a.vsub(r,a),s.length=a.length(),this.totalLength+=s.length,e.Quaternion.invert(o,y),e.Vector3.transformQuat(a,y,t.relPos)}else i=n.parent instanceof e.Sprite3D?n.parent:null,n.parent&&this._jointMgr&&(t.parent=this._jointMgr.getJoint(n.parent.name))}getJoint(t){return this.joints.find(e=>e.name==t)}rotateJoint(t,n){let i=this.joints;for(let o=t;o<i.length;o++){const s=i[o];let r=s.rotationQuat;if(o==t&&s.constraint&&r.cloneTo(z),e.Quaternion.multiply(n,r,r),r.normalize(r),s.rotationQuat=r,o==t&&s.constraint&&s.constraint.enable){s.constraint.doConsraint(s);let t=y;z.invert(t),e.Quaternion.multiply(s.rotationQuat,t,n),n.normalize(n)}const a=i[o+1];a&&(e.Vector3.transformQuat(a.relPos,r,V),a.position.setValue(s.position.x+V.x,s.position.y+V.y,s.position.z+V.z))}}copyCurPoseAsInitPose(){let t=this.joints;for(let e of t)e.copyTransform()}copyInitPose(){let t=this.joints,e=this.animLayer;for(let n=0,i=t.length;n<i;n++){let i=t[n],o=e;o.roations[n].cloneTo(i.transform.rotation),o.positions[n].cloneTo(i.transform.position),i.transform.position=i.transform.position,i.transform.rotation=i.transform.rotation}}captureStaticPose(){this.staticLayer.captureBonePose(this.joints)}resetStaticPose(){if(this.staticLayer.roations.length==this.joints.length)for(let t=0,e=this.joints.length;t<e;t++){let e=this.joints[t].bone.transform;e.position=this.staticLayer.positions[t],e.rotation=this.staticLayer.roations[t]}}captureAnimPose(){this.animLayer.captureBonePose(this.joints)}fadeToAnim(){this.layerMgr.isFading()||this.layerMgr.fadeTo(this.animLayer,200)}isFading(){return this.layerMgr.isFading()}applyResult(){this.layerMgr.apply(this.joints)}solve(t){}applyIKResult(t){if(!this.enable)return;let e=this.wSmoother?this.wSmoother.in(this.blendWeight):this.blendWeight;t.blendW=e;for(let t=0,n=this.joints.length;t<n;t++){let n=this.joints[t];n.fixed||e>0&&n.applyTransform(e)}}onLinkEnd(){let t=this.joints;this._end_effector=t[t.length-1];let n=new e.Quaternion;for(let i=0,o=t.length-1;i<o;i++){let o=t[i],r=t[i+1],a=new e.Vector3;r.bone.transform.localPosition.cloneTo(a),a.normalize(),s(new e.Vector3(0,0,1),a,n);let l=new e.Matrix4x4;e.Matrix4x4.createFromQuaternion(n,l),o.childDirOff=l}this.captureStaticPose()}}new e.Vector3(0,0,1),new e.Vector3,new e.Quaternion;let M=new e.Vector3;new e.Quaternion;var v=new e.Matrix4x4;function T(t){const n=new e.Vector3;return t.cloneTo(n),n}function Q(t){const n=new e.Quaternion;return t.cloneTo(n),n}class I extends b{constructor(t,e){super(e),this._showDbg=!1,this.solver=null,this.poleTarget=null,this._endAlign="no",this._isEndAlign=!1,this._parentInEnd=null,this.lastBoneDir=[],this.lastQuat=[],this._firstGetParentInEnd=!0,this.name=t,this.joints=[]}isCollinear(t,n=.001){let i=this.joints;if(i.length<2)return!1;const o=i[0].position,s=i[i.length-1].position;let r=new e.Vector3;if(t.vsub(o,r),this.totalLength<r.length())return!1;let a=i.length-1;this._endAlign&&"no"!==this._endAlign&&(a-=1);for(let t=1;t<a;t++)if(!l(o,i[t].position,s,n))return!1;return l(o,s,t,n)}visualize(t){if(this.target){let n=this.target.pos;this.target.getPose(v),u(v);let i=v.elements,o=.1,s=new e.Vector3(n.x+i[0]*o,n.y+i[1]*o,n.z+i[2]*o),r=new e.Vector3(n.x-i[0]*o,n.y-i[1]*o,n.z-i[2]*o),a=new e.Vector3(n.x+i[4]*o,n.y+i[5]*o,n.z+i[6]*o),l=new e.Vector3(n.x-i[4]*o,n.y-i[5]*o,n.z-i[6]*o),h=new e.Vector3(n.x+i[8]*o,n.y+i[9]*o,n.z+i[10]*o),c=new e.Vector3(n.x-i[8]*o,n.y-i[9]*o,n.z-i[10]*o);t.addLine(n,s,e.Color.RED,e.Color.RED),t.addLine(n,r,e.Color.RED,e.Color.RED),t.addLine(n,a,e.Color.GREEN,e.Color.GREEN),t.addLine(n,l,e.Color.GREEN,e.Color.GREEN),t.addLine(n,h,e.Color.BLUE,e.Color.BLUE),t.addLine(n,c,e.Color.BLUE,e.Color.BLUE)}this.endAlign;let n=this.joints;for(let i=0,o=n.length;i<o;i++){let o=n[i];o.visualize(t);let s=n[i+1];s&&t.addLine(o.position,s.position,new e.Color(1,0,0,1),new e.Color(0,1,0,1))}}set showDbg(t){this._showDbg=t}get showDbg(){return this._showDbg}set endAlign(t){this._endAlign=t,t&&"no"!=t?this._isEndAlign=!0:(this._isEndAlign=!1,this._parentInEnd=null)}get endAlign(){return this._endAlign}solve(t){if(!this._target)return;let n=this.solver;n.poleTarget=this.poleTarget;let i=this.joints,o=this.target.pos.clone(),r=null;if(this._isEndAlign){i[i.length-1].fixed=!0;{this._firstGetParentInEnd=!1;let t=this.joints[this.joints.length-1],n=t.bone.transform.worldMatrix.clone(),i=t.parent.bone.transform.worldMatrix.clone();u(n),u(i);let o=new e.Matrix4x4;n.invert(o);let s=this._parentInEnd=new e.Matrix4x4;e.Matrix4x4.multiply(o,i,s)}let t=this.target;r=new e.Quaternion;let n=this._parentInEnd;switch(this._endAlign){case"y":{let a=new e.Vector3;if(t.targetSprite){let e=t.targetSprite.transform.worldMatrix.elements;a.setValue(e[4],e[5],e[6])}else t.dir.cloneTo(a);a.normalize();let l=i[i.length-1].transform.worldMatrix;u(l);let h=new e.Vector3(l.elements[4],l.elements[5],l.elements[6]),c=new e.Quaternion;s(h,a,c);let d=new e.Matrix4x4;e.Matrix4x4.createFromQuaternion(c,d);let m=new e.Matrix4x4;e.Matrix4x4.multiply(d,l,m),m.elements[12]=o.x,m.elements[13]=o.y,m.elements[14]=o.z;let g=d;e.Matrix4x4.multiply(m,n,g);let p=g.elements;o.setValue(p[12],p[13],p[14]),e.Quaternion.createFromMatrix4x4(g,r)}break;case"all":{let i=new e.Matrix4x4;t.getPose(i),u(i);let s=new e.Matrix4x4;e.Matrix4x4.multiply(i,n,s);let a=s.elements;o.setValue(a[12],a[13],a[14]),u(s),e.Quaternion.createFromMatrix4x4(s,r);break}}}for(let t=0,n=i.length;t<n-1;t++){let n=i[t];if(n.fixed)continue;let o,s=i[t+1];o=this.lastBoneDir[t]?this.lastBoneDir[t]:this.lastBoneDir[t]=new e.Vector3,s.position.vsub(n.position,o),o.normalize(),this.lastQuat[t]=i[t].rotationQuat.clone()}n.solve(t,this,o,this._isEndAlign);for(let t=0,n=i.length;t<n-1;t++){let n=i[t];if(n.fixed)continue;let o=i[t+1],r=new e.Vector3;o.position.vsub(n.position,r),r.normalize();let a=this.lastBoneDir[t],l=n.rotationQuat,h=new e.Quaternion;s(a,r,h),e.Quaternion.multiply(h,this.lastQuat[t],l),n.rotationQuat=l}if(this._isEndAlign&&r){let t=i[i.length-2].rotationQuat,n=new e.Quaternion;t.invert(n);let o=new e.Quaternion;e.Quaternion.multiply(r,n,o),this.rotateJoint(i.length-2,o)}}updateRotations(){const t=this.joints,n=t.length;if(n<2)return;const i=new e.Quaternion,o=new e.Vector3,r=M;for(let e=0;e<n-1;e++){const a=t[e],l=t[e+1];l.position.vsub(a.position,r).normalize(),a===t[n-1]?o.setValue(0,0,1):l.relPos.cloneTo(o);const h=o.length();h<1e-6||(o.scale(1/h,o),s(o,r,i),i.cloneTo(a.rotationQuat))}t[n-2].rotationQuat.cloneTo(t[n-1].rotationQuat)}getDebugSnapshot(){const t=this.joints.map(t=>({name:t.name,pos:T(t.position),rot:Q(t.rotationQuat)})),e={chainName:this.name,joints:t};return this.target&&(e.targetPos=T(this.target.pos)),this.poleTarget&&e.poleTargetPos&&(this.poleTarget.pos=e.poleTargetPos),this.poleTarget&&e.poleTargetDir&&(this.poleTarget.dir=e.poleTargetDir),e}applyDebugSnapshot(t){if(!t)return;const e=Math.min(t.joints.length,this.joints.length);for(let n=0;n<e;n++){const e=this.joints[n],i=t.joints[n];i.pos.cloneTo(e.transform.position),i.rot.cloneTo(e.rotationQuat),e.applyTransform(1)}t.targetPos&&this.target&&(this.target.pos=t.targetPos),this.poleTarget&&t.poleTargetPos&&(this.poleTarget.pos=t.poleTargetPos),this.poleTarget&&t.poleTargetDir&&(this.poleTarget.dir=t.poleTargetDir)}}class C{constructor(t){this.transform=new e.Transform3D(null),this.length=1,this._parent=null,this.name="",this.childDirOff=null,this.relPos=new e.Vector3,this.fixed=!1,t&&(this.name=t.name,this.bone=t,this.copyTransform())}copyTransform(){let t=this.bone;t&&(this.transform.position=t.transform.position,this.transform.rotation=t.transform.rotation)}applyTransform(t){if(!this.bone)return;if(t<0&&(t=0),0==t)return;t>1&&(t=1);let n=this.bone.transform;n.position;let i=this.transform.position,o=n.rotation,s=this.transform.rotation;1==t?(n.position=i,n.rotation=s):(e.Quaternion.slerp(o,s,t,o),n.rotation=o)}set rotationQuat(t){t.normalize(t),this.transform.rotation=t}get rotationQuat(){return this.transform.rotation}set position(t){this.transform.position=t}get position(){return this.transform.position}get worldMatrix(){return this.transform.worldMatrix}set parent(t){var n,i;this._parent=t,t?this.transform._parent=t.transform:(null===(n=this.bone)||void 0===n?void 0:n.parent)instanceof e.Sprite3D?this.transform._parent=null===(i=this.bone.parent)||void 0===i?void 0:i.transform:this.transform._parent=null}get parent(){return this._parent}visualize(t){this.constraint&&this.constraint.enable&&this.constraint.visualize(this,t)}random(t,n,i){let o=new e.Quaternion;return e.Quaternion.createFromAxisAngle(t,178*Math.PI/180,o),e.Vector3.transformQuat(n,o,i),i}perturbJoint(){if(!this.parent)return!1;let t=new e.Vector3;if(this.position.vsub(this.parent.position,t),t.normalize(),"revolute"===this.type){let n=new e.Vector3;e.Vector3.cross(t,new e.Vector3(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1),n),n.normalize();const i=(10*Math.random()-5)*Math.PI/180;let o=new e.Quaternion;e.Quaternion.createFromAxisAngle(n,i,o);let s=new e.Quaternion;return e.Quaternion.multiply(this.transform.rotation,o,s),this.transform.rotation=s,!0}if("prismatic"===this.type)return!1;{let t=new e.Vector3(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1);t.normalize();const n=(10*Math.random()-5)*Math.PI/180;let i=new e.Quaternion;e.Quaternion.createFromAxisAngle(t,n,i);let o=this.transform.rotation;return e.Quaternion.multiply(o,i,o),this.transform.rotation=o,!0}}}let S=new e.Quaternion;new e.Matrix4x4;class L extends b{constructor(t,e){super(e),this._chainLength=0,this._end=null,this._hasOff=!1,this.alignWithTarget=!1,this._chainLength=t.length;let n=!0;if(t.length>1&&(t[0].bone.parent==t[1].bone?n=!1:t[1].bone.parent==t[0].bone?n=!0:console.warn("无法确定lookat的ik链的顺序")),this.joints=new Array(0),n)for(let e=0,n=t.length;e<n;e++)this.addJoint(t[e]);else for(let e=t.length-1;e>=0;e--)this.addJoint(t[e]);this._end=this.joints[this.joints.length-1],this._end.bone._isRenderNode||(this._hasOff=!0,this._end.fixed=!0),this.onLinkEnd()}visualize(t){for(let e of this.joints)e.constraint&&e.constraint.visualize(e,t);if(this._target){let n=this._end.bone.transform.worldMatrix.elements,i=new e.Vector3(n[12],n[13],n[14]),o=new e.Vector3(n[8],n[9],n[10]);o.normalize();let s=new e.Vector3;this._target.pos.vsub(i,s);let r=s.length();s.setValue(i.x+r*o.x,i.y+r*o.y,i.z+r*o.z),t.addLine(i,s,e.Color.RED,e.Color.RED)}}solve(){if(!this.enable)return;if(!this._chainLength||!this._target)return;let t=new e.Quaternion,n=new e.Matrix4x4,i=this._target.pos.clone(),o=new e.Vector3,r=this._end;if(this.alignWithTarget,1==this._chainLength){let n=r.worldMatrix,o=new e.Vector3(i.x-n.elements[12],i.y-n.elements[13],i.z-n.elements[14]);o.normalize();let a=new e.Vector3(n.elements[8],n.elements[9],n.elements[10]);a.normalize(),s(a,o,t);let l=r.rotationQuat,h=new e.Quaternion;e.Quaternion.multiply(t,l,h),r.rotationQuat=h;let c=this.joints[0];c.constraint&&c.constraint.enable&&c.constraint.doConsraint(c)}else{let s=this._chainLength;this._hasOff&&(s-=1);let a=1/s,l=L.dirIt,h=!1;for(;l--&&!h;)for(let l=s-1;l>=0;l--){let s=this.joints[l];s.worldMatrix.invert(n),e.Vector3.transformCoordinate(i,n,o);let h=r.worldMatrix;{let t=h.elements,n=new e.Vector3(t[12],t[13],t[14]),o=new e.Vector3(t[8],t[9],t[10]),s=new e.Vector3;i.vsub(n,s),s.normalize(),o.normalize(),o.dot(s)}let u=new e.Matrix4x4;if(e.Matrix4x4.multiply(n,h,u),!c(o,u,t))return void console.log("无法解决lookat问题");e.Quaternion.slerp(S,t,a,t);let d=new e.Quaternion,m=s.rotationQuat;e.Quaternion.multiply(m,t,d);let g=new e.Quaternion;m.invert(g),e.Quaternion.multiply(d,g,t),this.rotateJoint(l,t)}}}}L.dirIt=1;class P{constructor(){this.maxFrames=120,this.enabled=!1,this._frames=[],this._replayIndex=-1}canRecordFrame(){return this.enabled&&!this.isReplaying()}recordFrame(t){if(!this.enabled||this.isReplaying()||!(null==t?void 0:t.length))return;const n={frameId:e.timer?e.timer.currFrame:0,timestamp:Date.now(),chainStates:t};this._frames.push(n),this._frames.length>this.maxFrames&&this._frames.shift()}clear(){this._frames.length=0,this._replayIndex=-1}isReplaying(){return this._replayIndex>=0&&this._replayIndex<this._frames.length}startReplay(t=0){if(!this._frames.length)return!1;const e=this._frames.length-1-t;return this._replayIndex=Math.max(0,Math.min(e,this._frames.length-1)),!0}stopReplay(){this._replayIndex=-1}step(t){this.isReplaying()&&(this._replayIndex=Math.max(0,Math.min(this._replayIndex+t,this._frames.length-1)))}getReplayFrame(){var t;return this.isReplaying()&&null!==(t=this._frames[this._replayIndex])&&void 0!==t?t:null}get replayInfo(){var t,e;if(!this.isReplaying())return null;const n=this._frames[this._replayIndex];return{index:this._replayIndex,total:this._frames.length,frameId:null!==(t=null==n?void 0:n.frameId)&&void 0!==t?t:0,timestamp:null!==(e=null==n?void 0:n.timestamp)&&void 0!==e?e:0}}}class A{static none(){return A.showdbg=0,A}static all(){return A.showdbg=A.ALL,A}static add(t){return A.showdbg|=t,A}static sub(t){return A.showdbg&=~t,A}static has(t){return 0!==(A.showdbg&t)}}A.CONSTRAINT=1,A.CONSTRAINT_AXIS=4,A.BONE=8,A.BONE_AXIS=16,A.ALL=255,A.showdbg=A.ALL;class D{constructor(t){this.chains=[],this.lookats=[],this.rootSprite=null,this._showDbg=!1,this.enableSolver=!0,this.ikcomp=null,this.useAnimLayer=!1,this._debugRecorder=new P,this.ikcomp=t,this.solver=new m}setRoot(t){this.rootSprite=t}setMaxIterations(t){this.solver.maxIterations=t}setDampingFactor(t){this.solver.dampingFactor=t}getDampingFactor(){return this.solver.dampingFactor}set showDbg(t){this._showDbg=t;for(let e of this.chains)e.showDbg=t}get showDbg(){return this._showDbg}visualize(t){if(this._showDbg){for(let e of this.chains)e.visualize(t);for(let e of this.lookats)e.visualize(t)}}addChain(t){this.chains.push(t),t.solver=this.solver}clear(){this.chains.length=0,this.lookats.length=0,this._debugRecorder.clear()}_getChildByName(t,e){if(t.name===e)return t;const n=t.numChildren;for(let i=0;i<n;i++){const n=t.getChildAt(i),o=this._getChildByName(n,e);if(null!==o)return o}return null}getBoneChain(t,e){let n=this._getChildByName(this.rootSprite,t);return this.getBoneChainBySprite(n,e)}getBoneChainBySprite(t,n){if(!t)return null;let i=[t],o=t;for(let t=0;t<n-1&&(o=o.parent,o)&&o instanceof e.Sprite3D;t++)i.push(o);return i}chreateChainByBoneName(t,n){let i,o,s=this.ikcomp;if("string"==typeof t?(o=t,i=this.getBoneChain(t,n)):t instanceof e.Sprite3D&&(o=t.name,i=this.getBoneChainBySprite(t,n)),!i||i.length!=n)return console.error(`没有找到骨骼:${o}或者长度不足${n}`),null;let r=new I("",s);for(let t=n-1;t>=0;t--){const e=i[t],n=new C(e);if(this.constraintsMap){let t=this.constraintsMap.get(e);n.constraint=t}r.addJoint(n)}return r.onLinkEnd(),r}chreateLookatByEndSprite(t,e){let n,i=this.ikcomp,o=t.name;if(n=this.getBoneChainBySprite(t,e),!n||n.length!=e)return console.error(`没有找到骨骼:${o}或者长度不足${e}`),null;let s=[];for(let t of n){let e=new C(t);this.constraintsMap&&(e.constraint=this.constraintsMap.get(t)),s.push(e)}return new L(s,i)}_findChainByName(t){for(let e of this.chains)if(e.name==t)return e;return null}setTarget(t,e){let n=null;n=t instanceof I?t:this._findChainByName(t),n&&(n.target=e)}resetPose(){for(let t of this.chains)t.captureStaticPose();for(let t of this.lookats)t.captureStaticPose()}async onUpdate(){this._debugRecorder.isReplaying();const t=this._debugRecorder.getReplayFrame(),e=this._debugRecorder.canRecordFrame()?[]:null;for(let n of this.chains){let i=this.enableSolver&&n.enable;n.isRunning=i;const o=null==t?void 0:t.chainStates.find(t=>t.chainName===n.name);this.useAnimLayer?(i&&(n.captureAnimPose(),n.copyInitPose(),n.solve(this.ikcomp),n.ik_result.captureIKResult(n.joints),n.layerMgr.set(n.ik_result),n.applyResult()),n.isFading()&&n.applyResult()):i&&(o?n.applyDebugSnapshot(o):n.copyCurPoseAsInitPose(),e&&!o&&e.push(n.getDebugSnapshot()),n.solve(this.ikcomp),n.applyIKResult(this.ikcomp))}for(let t of this.lookats){let e=this.enableSolver&&t.enable;t.isRunning=e,this.useAnimLayer?(e&&(t.captureAnimPose(),t.copyInitPose(),t.solve(),t.ik_result.captureIKResult(t.joints),t.layerMgr.set(t.ik_result),t.applyResult()),t.isFading()&&t.applyResult()):e&&(t.captureAnimPose(),t.copyInitPose(),t.solve(),t.applyIKResult(this.ikcomp))}(null==e?void 0:e.length)&&this._debugRecorder.recordFrame(e)}setFrameRecorderEnabled(t){this._debugRecorder.enabled=t,t||this._debugRecorder.stopReplay()}setFrameRecorderDepth(t){this._debugRecorder.maxFrames=Math.max(1,Math.floor(t))}startFrameDebugReplay(t=0){this._debugRecorder.startReplay(t)}stopFrameDebugReplay(){this._debugRecorder.stopReplay()}stepFrameDebugReplay(t){this._debugRecorder.step(t)}getFrameReplayInfo(){return this._debugRecorder.replayInfo}}D.version="0.1.0";var R=new e.Vector3,E=new e.Vector3,k=new e.Vector3,F=new e.Vector3,B=new e.Vector3;new e.Vector3,new e.Vector3,new e.Vector3;var j=new e.Vector3,N=new e.Vector3,J=new e.Vector3,K=new e.Vector3,O=new e.Vector3,W=new e.Vector3,q=new e.Vector3,G=new e.Vector3;function H(t,n,i,o=[e.Color.RED,e.Color.GREEN,e.Color.BLUE]){let s=n.elements;B.set(s[12],s[13],s[14]),R.set(s[0],s[1],s[2]).normalize(),E.set(s[4],s[5],s[6]).normalize(),k.set(s[8],s[9],s[10]).normalize();let r=Math.min(.1,i/2),a=r/4,l=o[0],h=o[1],c=o[2];R.scale(i,F),B.vadd(F,F),t.addLine(B,F,l,l),K.set(a,a,a),J.set(r,r,r),N.set(F.x-J.x*R.x+E.x*K.x,F.y-J.y*R.y+E.y*K.y,F.z-J.z*R.z+E.z*K.z).cloneTo(O),t.addLine(F,N,l,l),N.set(F.x-J.x*R.x-E.x*K.x,F.y-J.y*R.y-E.y*K.y,F.z-J.z*R.z-E.z*K.z).cloneTo(W),t.addLine(F,N,l,l),N.set(F.x-J.x*R.x+k.x*K.x,F.y-J.y*R.y+k.y*K.y,F.z-J.z*R.z+k.z*K.z).cloneTo(q),t.addLine(F,N,l,l),N.set(F.x-J.x*R.x-k.x*K.x,F.y-J.y*R.y-k.y*K.y,F.z-J.z*R.z-k.z*K.z).cloneTo(G),t.addLine(F,N,l,l),t.addLine(O,q,l,l),t.addLine(q,W,l,l),t.addLine(W,G,l,l),t.addLine(G,O,l,l),E.scale(i,F),B.vadd(F,F),t.addLine(B,F,h,h),N.set(F.x-J.x*E.x+R.x*K.x,F.y-J.y*E.y+R.y*K.y,F.z-J.z*E.z+R.z*K.z).cloneTo(O),t.addLine(F,N,h,h),N.set(F.x-J.x*E.x-R.x*K.x,F.y-J.y*E.y-R.y*K.y,F.z-J.z*E.z-R.z*K.z).cloneTo(W),t.addLine(F,N,h,h),N.set(F.x-J.x*E.x+k.x*K.x,F.y-J.y*E.y+k.y*K.y,F.z-J.z*E.z+k.z*K.z).cloneTo(q),t.addLine(F,N,h,h),N.set(F.x-J.x*E.x-k.x*K.x,F.y-J.y*E.y-k.y*K.y,F.z-J.z*E.z-k.z*K.z).cloneTo(G),t.addLine(F,N,h,h),t.addLine(F,N,h,h),t.addLine(O,q,h,h),t.addLine(q,W,h,h),t.addLine(W,G,h,h),t.addLine(G,O,h,h),k.scale(i,F),B.vadd(F,F),t.addLine(B,F,c,c),N.set(F.x-J.x*k.x+E.x*K.x,F.y-J.y*k.y+E.y*K.y,F.z-J.z*k.z+E.z*K.z).cloneTo(O),t.addLine(F,N,c,c),N.set(F.x-J.x*k.x-E.x*K.x,F.y-J.y*k.y-E.y*K.y,F.z-J.z*k.z-E.z*K.z).cloneTo(W),t.addLine(F,N,c,c),N.set(F.x-J.x*k.x+R.x*K.x,F.y-J.y*k.y+R.y*K.y,F.z-J.z*k.z+R.z*K.z).cloneTo(q),t.addLine(F,N,c,c),N.set(F.x-J.x*k.x-R.x*K.x,F.y-J.y*k.y-R.y*K.y,F.z-J.z*k.z-R.z*K.z).cloneTo(G),t.addLine(F,N,c,c),t.addLine(F,N,c,c),t.addLine(F,N,c,c),t.addLine(O,q,c,c),t.addLine(q,W,c,c),t.addLine(W,G,c,c),t.addLine(G,O,c,c)}var U=new e.Color(.9,.5,.5),X=new e.Color(.5,.9,.5),Y=new e.Color(.5,.5,.9);let $=new e.Quaternion,Z=new e.Vector3;function tt(t,n,i,o,s,r,a){let l=new e.Vector3;(i=i.clone()).scale(.4,i);let h=(r-s)/20;e.Quaternion.createFromAxisAngle(o,s,$),e.Vector3.transformQuat(i,$,l),t.addLine(n,n.vadd(l,l),a,a),l.cloneTo(Z);for(let c=s;c<r;c+=h)e.Quaternion.createFromAxisAngle(o,c,$),e.Vector3.transformQuat(i,$,l),n.vadd(l,l),t.addLine(Z,l,a,a),l.cloneTo(Z);e.Quaternion.createFromAxisAngle(o,r,$),e.Vector3.transformQuat(i,$,l),t.addLine(n,n.vadd(l,l),a,a),t.addLine(Z,l,a,a)}let et=new e.Vector3,nt=new e.Vector3,it=new e.Vector3,ot=new e.Vector3;function st(t,n,i,o,s,r,a,l){let h=n.elements,c=new e.Vector3(h[12],h[13],h[14]),u=new e.Vector3(h[0],h[1],h[2]),d=new e.Vector3(h[4],h[5],h[6]),m=new e.Vector3(h[8],h[9],h[10]);u.normalize(),d.normalize(),m.normalize();let g=new e.Matrix4x4(u.x,u.y,u.z,0,d.x,d.y,d.z,0,m.x,m.y,m.z,0,0,0,0,1),p=new e.Vector3(0,0,1),f=new e.Vector3,x=new e.Vector3,w=new e.Vector3,_=new e.Vector3,y=new e.Vector3(1,0,0),V=new e.Vector3,z=new e.Vector3,b=new e.Quaternion(0,Math.sin(s/2),0,Math.cos(s/2));e.Vector3.transformQuat(p,b,z),e.Vector3.transformQuat(y,b,V);let M=new e.Quaternion;e.Quaternion.createFromAxisAngle(V,i,M),e.Vector3.transformQuat(z,M,f),e.Quaternion.createFromAxisAngle(V,o,M),e.Vector3.transformQuat(z,M,x),b.setValue(0,Math.sin(r/2),0,Math.cos(r/2)),e.Vector3.transformQuat(p,b,z),e.Vector3.transformQuat(y,b,V),e.Quaternion.createFromAxisAngle(V,i,M),e.Vector3.transformQuat(z,M,w),e.Quaternion.createFromAxisAngle(V,o,M),e.Vector3.transformQuat(z,M,_);let v=[];for(let t=0;t<=8;t++){let n=[],a=s+t/8*(r-s);for(let t=0;t<=8;t++){let s=i+t/8*(o-i),r=new e.Quaternion(0,Math.sin(a/2),0,Math.cos(a/2)),l=new e.Vector3;e.Vector3.transformQuat(p,r,l);let h=new e.Vector3;e.Vector3.transformQuat(y,r,h);let c=new e.Quaternion;e.Quaternion.createFromAxisAngle(h,s,c);let u=new e.Vector3;e.Vector3.transformQuat(l,c,u),e.Vector3.TransformNormal(u,g,u),u.scale(.3,u),n.push(u)}v.push(n)}for(let n=0;n<=8;n++)for(let i=0;i<=8;i++){let o=new e.Vector3;if(c.vadd(v[n][i],o),i>0){let s=new e.Vector3;c.vadd(v[n][i-1],s),t.addLine(s,o,e.Color.RED,e.Color.RED)}if(n>0){let s=new e.Vector3;c.vadd(v[n-1][i],s),t.addLine(s,o,e.Color.RED,e.Color.RED)}}}function rt(t,n,i,o,s,r,a){if(o<=0||s<=0)return;if(0===i.x&&0===i.y&&0===i.z)return;if(et.set(i.x,i.y,i.z),et.normalize(),!a||0===a.x&&0===a.y&&0===a.z)Math.abs(et.y)<.999?nt.set(0,1,0):nt.set(1,0,0),e.Vector3.cross(nt,et,it);else{const t=a.x*et.x+a.y*et.y+a.z*et.z;it.set(a.x-t*et.x,a.y-t*et.y,a.z-t*et.z),0===it.x&&0===it.y&&0===it.z&&(Math.abs(et.y)<.999?nt.set(0,1,0):nt.set(1,0,0),e.Vector3.cross(nt,et,it))}it.normalize(),e.Vector3.cross(et,it,ot),ot.normalize();const l=2*Math.PI/48;for(let e=0;e<48;e++){const i=e*l,a=(e+1)*l;let h=Math.cos(i),c=Math.sin(i);j.set(o*it.x*h+s*ot.x*c,o*it.y*h+s*ot.y*c,o*it.z*h+s*ot.z*c),n.vadd(j,W),h=Math.cos(a),c=Math.sin(a),j.set(o*it.x*h+s*ot.x*c,o*it.y*h+s*ot.y*c,o*it.z*h+s*ot.z*c),n.vadd(j,q),t.addLine(W,q,r,r)}}var at=new e.Matrix4x4,lt=new e.Matrix4x4,ht=new e.Matrix4x4;let ct=new e.Matrix4x4,ut=new e.Matrix4x4,dt=new e.Vector3,mt=new e.Quaternion;class gt{constructor(t,n,i){this.constraint=t,this.constraintBone=i,this.inParent=new e.Matrix4x4,this.inChild=null,this.enable=!0,this.data=null,n.cloneTo(this.inParent)}doConsraint(t){if(!this.enable)return;t.parent?e.Matrix4x4.multiply(t.parent.transform.worldMatrix,this.inParent,at):t.bone.parent&&t.bone.parent instanceof e.Sprite3D?e.Matrix4x4.multiply(t.bone.parent.transform.worldMatrix,this.inParent,at):this.inParent.cloneTo(at),at.invert(lt);let n=t.worldMatrix;this.constraintBone&&t.childDirOff&&(n=n.clone(),e.Matrix4x4.multiply(n,t.childDirOff,n)),e.Matrix4x4.multiply(lt,n,ht);let i=this.constraint.constraintMat(u(ht),mt);if(e.Matrix4x4.createFromQuaternion(i,ut),this.constraintBone&&t.childDirOff){let n=t.childDirOff.clone();n.transpose(),e.Matrix4x4.multiply(ut,n,ut)}e.Matrix4x4.multiply(at,ut,ct),u(ct).decomposeYawPitchRoll(dt),e.Quaternion.createFromYawPitchRoll(dt.x,dt.y,dt.z,t.rotationQuat),t.rotationQuat=t.rotationQuat}visualize(t,n){if(!A.has(A.CONSTRAINT))return;if(!this.enable)return;let i;t.bone.parent&&t.bone.parent instanceof e.Sprite3D&&(i=t.bone.parent.transform.worldMatrix);let o=new e.Matrix4x4;i&&e.Matrix4x4.multiply(i,this.inParent,o);A.has(A.CONSTRAINT_AXIS)&&H(n,o,.6,[new e.Color(1,.3,.3),new e.Color(.3,1,.3),new e.Color(.3,.3,1)]),this.constraint.visualize(n,o);let s=t.bone.transform.worldMatrix.elements,r=new e.Vector3(s[12],s[13],s[14]),a=new e.Vector3(s[8],s[9],s[10]);a.normalize(),a.scale(.7,a).vadd(r,a),n.addLine(r,a,e.Color.RED,e.Color.RED)}}new e.Vector3(0,0,1);let pt=new e.Vector3;class ft{constructor(t=-Math.PI/2,n=Math.PI/2,i=-Math.PI,o=Math.PI,s=-Math.PI,r=Math.PI){this.xmin=t,this.xmax=n,this.ymin=i,this.ymax=o,this.zmin=s,this.zmax=r,this.rotation=new e.Quaternion,this.cur=0}constraintMat(t,n){t.decomposeYawPitchRoll(pt);let i=pt.x,o=pt.y,s=pt.z;o>this.xmax&&(o=this.xmax),o<this.xmin&&(o=this.xmin),i>this.ymax&&(i=this.ymax),i<this.ymin&&(i=this.ymin),s<this.zmin&&(s=this.zmin),s>this.zmax&&(s=this.zmax);let r=n||new e.Quaternion;return e.Quaternion.createFromYawPitchRoll(i,o,s,r),r}constraintQ(t){return null}visualize(t,e){st(t,e,this.xmin,this.xmax,this.ymin,this.ymax,this.zmin,this.zmax)}}var xt=new e.Vector3(0,0,1);let wt=new e.Quaternion,_t=new e.Vector3,yt=new e.Quaternion,Vt=new e.Quaternion,zt=new e.Vector3,bt=new e.Quaternion,Mt=new e.Quaternion,vt=new e.Quaternion;class Tt{constructor(t=Math.PI/4,n=Math.PI/4,i=-Math.PI,o=Math.PI){this.xmax=t,this.ymax=n,this.zmin=i,this.zmax=o,this.rotation=new e.Quaternion,this.cur=0,this.visual_height=.5,this.visual_zheight=.5}constraintMat(t,n){u(t);let i=t.elements;const o=1e-6;e.Quaternion.createFromMatrix4x4(t,wt),wt.normalize(wt),_t.setValue(i[8],i[9],i[10]),_t.normalize(),s(xt,_t,yt);const r=Math.sqrt(yt.x*yt.x+yt.y*yt.y+yt.z*yt.z),a=yt.w;let l=2*Math.atan2(r,a);const h=1/Math.max(r,o),c=r<o?1:yt.x*h,d=r<o?0:yt.y*h,m=t=>Math.min(Math.max(t,o),Math.PI/2-.001),g=Math.max(Math.tan(m(this.xmax)),o),p=Math.max(Math.tan(m(this.ymax)),o),f=Math.atan2(d,c),x=Math.cos(f),w=Math.sin(f),_=Math.sqrt(x/g*(x/g)+w/p*(w/p)),y=_<o?Math.PI/2-.001:Math.atan(1/_),V=Math.min(l,y);V<o?(Vt.x=0,Vt.y=0,Vt.z=0,Vt.w=1):(zt.setValue(c,d,0),zt.normalize(),e.Quaternion.createFromAxisAngle(zt,V,Vt)),yt.invert(bt),e.Quaternion.multiply(bt,wt,vt),vt.normalize(vt);let z=2*Math.atan2(vt.z,vt.w);for(;z>Math.PI;)z-=2*Math.PI;for(;z<-Math.PI;)z+=2*Math.PI;z=Math.max(this.zmin,Math.min(this.zmax,z)),e.Quaternion.createFromAxisAngle(xt,z,Mt);let b=n||new e.Quaternion;return e.Quaternion.multiply(Vt,Mt,b),b}constraintQ(t){return null}visualize(t,n){let i=80*Math.PI/180;if(this.xmax>i||this.ymax>i)return;let o=this.visual_height,s=Math.tan(this.xmax)*o,r=Math.tan(this.ymax)*o;this.visual_zheight;let a=n.elements,l=new e.Vector3(a[12],a[13],a[14]),h=new e.Vector3(a[8],a[9],a[10]),c=new e.Vector3(a[4],a[5],a[6]);c.normalize(),h.normalize(),rt(t,new e.Vector3(l.x+h.x*o,l.y+h.y*o,l.z+h.z*o),h,s,r,e.Color.CYAN,c)}}class Qt{constructor(t,n){this.targetSprite=null,this._pos=new e.Vector3,this._dir=new e.Vector3(0,1,0),t instanceof e.Sprite3D?this.targetSprite=t:(t&&t.cloneTo(this._pos),n&&n.cloneTo(this._dir))}getPose(t){return this.targetSprite?(this.targetSprite.transform.worldMatrix.cloneTo(t),t):null}get pos(){return this.targetSprite?this.targetSprite.transform.position:this._pos}set pos(t){this.targetSprite&&(this.targetSprite=null),t.cloneTo(this._pos)}get dir(){if(this.targetSprite){let t=this.targetSprite.transform.worldMatrix.elements;this._dir.setValue(t[4],t[5],t[6]),this._dir.normalize()}return this._dir}set dir(t){this.targetSprite&&(this.targetSprite=null),t.cloneTo(this._dir)}}class It extends e.Script{set chainDatas(t){this._chainDatas=t,this._needRebuild=!0}get chainDatas(){return this._chainDatas}set solverIteration(t){this._solverIteration=t,this._ik_sys.setMaxIterations(t)}get solverIteration(){return this._solverIteration}set dirSolverIteration(t){this._dirsolverIteration=t,L.dirIt=t}get dirSolverIteration(){return this._dirsolverIteration}set dampingFactor(t){this._ik_sys.setDampingFactor(t)}get dampingFactor(){return this._ik_sys.getDampingFactor()}set constraints(t){this._constraintDatas=t,this._needRebuild=!0}get constraints(){return this._constraintDatas}onConstraintDataChange(t){let e=this.owner.getComponent(Ct);this.constraints=e.constraints}set showGizmos(t){this._showDbg=t,this._ik_sys&&(this._ik_sys.showDbg=t)}get showGizmos(){return this._showDbg}set"显示约束"(t){t?A.add(A.CONSTRAINT):A.sub(A.CONSTRAINT)}get"显示约束"(){return A.has(A.CONSTRAINT)}set"显约束轴"(t){t?A.add(A.CONSTRAINT_AXIS):A.sub(A.CONSTRAINT_AXIS)}get"显约束轴"(){return A.has(A.CONSTRAINT_AXIS)}get RunInEditor(){return this._runInEditor}set RunInEditor(t){this._runInEditor=t}set useAnimLayer(t){this._ik_sys.useAnimLayer=t}get useAnimLayer(){return this._ik_sys.useAnimLayer}constructor(){super(),this._needRebuild=!0,this._constraintsMap=new Map,this._showDbg=!1,this._visualSp=null,this._visualInPlay=!0,this._chainDatas=[],this.current_iteration=0,this.current_error=0,this.pole_rot=0,this.targetChange=0,this.blendW=0,this._recordIkFrames=!1,this._frameRecordDepth=60,this._frameReplayOffset=0,this._solverIteration=10,this._dirsolverIteration=10,this._runInEditor=!0}_onAdded(){let t=this._ik_sys=new D(this);t.setRoot(this.owner),t.showDbg=this._showDbg,t.setFrameRecorderEnabled(this._recordIkFrames),t.setFrameRecorderDepth(this._frameRecordDepth)}onAfterDeserialize(){this._needRebuild=!0}onChainDataChange(t,e,n,i){this._needRebuild=!0}setTarget(t,e){this._ik_sys.setTarget(t,e)}get chains(){return this._ik_sys.chains}getChain(t){for(let e of this.chains)if(e.name==t)return e;return null}beforeOwnerAnim(){if(this._runInEditor||!window.EditorEnv){for(let t of this._ik_sys.chains)t.resetStaticPose();for(let t of this._ik_sys.lookats)t.resetStaticPose()}}onAwake(){super.onAwake();let t=this.owner.getComponent(Ct);t&&(this.constraints=t.constraints,this.owner.on(Ct.DATACHANGE,this,this.onConstraintDataChange))}onDestroy(){this.showGizmos=!1,this._ik_sys.showDbg=!1,super.onDestroy(),this.owner.off(Ct.DATACHANGE,this,this.onConstraintDataChange)}onUpdate(){if(!window.EditorEnv||this._runInEditor){if(this._needRebuild){let t=new Set;this._constraintsMap.clear(),this._constraintDatas&&(this._constraintDatas.forEach(e=>{if(!e.bone)return;this._constraintsMap.get(e.bone)&&console.error("一个骨骼只能设置一个约束:",e.bone,name,e.bone);let n=null,i=Math.PI/180;switch(e.type){case"hinge":e.ymin=0,e.ymax=0,e.zmin=0,e.zmax=0;case"euler":{let t=new ft(e.xmin*i,e.xmax*i,e.ymin*i,e.ymax*i,e.zmin*i,e.zmax*i);n=this._createConstraintInstanceFromData(e,t)}break;case"swingtwist":{let t=new Tt(e.xmax*i,e.ymax*i,e.zmin*i,e.zmax*i);t.visual_height=e.visualHeight,t.visual_zheight=t.visual_height+.1,n=this._createConstraintInstanceFromData(e,t)}break;case"fixed":t.add(e.bone)}n&&this._constraintsMap.set(e.bone,n)}),this._ik_sys.constraintsMap=this._constraintsMap),this._ik_sys.clear(),this.chainDatas.forEach(e=>{var n;let i=(null===(n=e.bones)||void 0===n?void 0:n.length)||e.jointCount;if(!i||!e.end||!e.enable)return;let o=e.name;o||(o=e.end.name);let s=null;if("position"==e.type){let t=this._ik_sys.chreateChainByBoneName(e.end,i);t.name=o,t.enable=e.enable,t.blendWeight=e.blendWeight,t.poleTarget=e.PoleTarget?new Qt(e.PoleTarget):null,e.smoothBlendWeight&&(t.weightSmooth=e.smoothBlendWeight),e.maxError&&(t.maxError=e.maxError),e.enablePoleTarget||(t.poleTarget=null),this._ik_sys.addChain(t),e.target&&this._ik_sys.setTarget(t,new Qt(e.target)),e.fixedEnd&&(t.endFixed=!0),e.alignTarget&&"no"!=e.alignTarget&&(t.endAlign=e.alignTarget),s=t.joints}else if("lookat"==e.type){let t=this._ik_sys.chreateLookatByEndSprite(e.end,i);t&&(t.name=o,t.enable=e.enable,this._ik_sys.lookats.push(t),e.target&&(t.target=new Qt(e.target)),s=t.joints)}if(e.bones){let t=s;e.bones.forEach(e=>{if(e.disabled)for(let n=0,o=i;n<o;n++)if(t[n].bone==e.data){t[n].fixed=!0;break}})}t.size&&s.forEach(e=>{t.has(e.bone)&&(e.fixed=!0)})}),this._needRebuild=!1}else this._updateConstraintSpace();if(this._ik_sys.onUpdate(),e.LayaEnv.isPlaying&&this._visualInPlay){if(!this._visualSp){let t=this._visualSp=new e.PixelLineSprite3D;t.name="ik visual",t.maxLineCount=1e3;let n=t._render.material;n.renderQueue=4001,n.depthTest=e.RenderState.DEPTHTEST_ALWAYS,this.owner._scene.addChild(t)}this._visualSp.clear(),this.visualize(this._visualSp)}}}_createConstraintInstanceFromData(t,n){if(!t||!t.bone)return null;let i,o=new e.Matrix4x4;if(t.bone.parent&&(i=t.bone.parent.transform.worldMatrix),t.space){t.space.parent==t.bone&&alert(`约束调整对象${t.space.name}不要放到当前关节下,建议放到当前关节的父下,否则初始化的时候会与当前关节的姿态有关`);let n=t.space.transform.worldMatrix,s=new e.Matrix4x4;i?(i.invert(s),e.Matrix4x4.multiply(s,n,o)):n.cloneTo(o),e.LayaEnv.isPlaying&&t.space.name.startsWith("_ik")}else{let e=t.bone.transform.localPosition;o.elements[12]=e.x,o.elements[13]=e.y,o.elements[14]=e.z}let s=new gt(n,o,t.constraintBone);return s.data=t,s.enable=t.enable,s}_updateConstraintSpace(){for(let[t,n]of this._constraintsMap){let t=n.inParent,i=n.data;if(i.space&&!i.space.destroyed){let n;i.bone.parent&&(n=i.bone.parent.transform.worldMatrix);let o=i.space.transform.worldMatrix,s=new e.Matrix4x4;n?(n.invert(s),e.Matrix4x4.multiply(s,o,t)):o.cloneTo(t)}}}visualize(t){this._ik_sys.visualize(t)}}class Ct extends e.Script{set constraints(t){this._constraintDatas=t}get constraints(){return this._constraintDatas}onConstraintDataChange(t){this.owner.event(Ct.DATACHANGE,t)}onAwake(){let t=this.owner.getComponent(It);t&&(t.constraints=this.constraints)}onDestroy(){let t=this.owner.getComponent(It);t&&(t.constraints=null)}}Ct.DATACHANGE="constraint_data_change";let St=new e.Vector3,Lt=new e.Vector3,Pt=new e.Vector3;new e.Vector3(0,0,1);class At{}class Dt{constructor(){this.type="position",this.end=null,this.root=null,this.fixedEnd=!1,this.alignTarget="no",this.target=null,this.enablePoleTarget=!1,this.PoleTarget=null,this.jointCount=2,this.blendWeight=1,this.smoothBlendWeight=1,this.enable=!0,this.maxError=.001}}class Rt{constructor(){this._xmin=-45,this._xmax=45,this._ymin=-45,this._ymax=45,this._zmin=0,this._zmax=0,this.enable=!0,this.type="hinge",this.space=null,this.constraintBone=!1,this.visualHeight=.5}set xmin(t){this._xmin=t,this._xmax<t&&(this.xmax=t)}get xmin(){return this._xmin}set xmax(t){this._xmax=t,this._xmin>t&&(this.xmin=t)}get xmax(){return this._xmax}set ymin(t){this._ymin=t,this._ymax<t&&(this.ymax=t)}get ymin(){return this._ymin}set ymax(t){this._ymax=t,this._ymin>t&&(this.ymin=t)}get ymax(){return this._ymax}set zmin(t){this._zmin=t,this._zmax<t&&(this.zmax=t)}get zmin(){return this._zmin}set zmax(t){this._zmax=t,this._zmin>t&&(this.zmin=t)}get zmax(){return this._zmax}}let Et=new e.Quaternion;class kt extends b{constructor(t,e){super(e),this._chainLength=0,this._end=null,this._hasOff=!1,this.alignWithTarget=!1,this._chainLength=t.length;let n=!0;if(t.length>1&&(t[0].bone.parent==t[1].bone?n=!1:t[1].bone.parent==t[0].bone?n=!0:console.warn("无法确定lookat的ik链的顺序")),n)for(let e=0,n=t.length;e<n;e++)this.addJoint(t[e]);else{this.joints=new Array(0);for(let e=t.length-1;e>=0;e--)this.addJoint(t[e])}this._end=this.joints[this.joints.length-1],this._end.bone._isRenderNode||(this._hasOff=!0,this._end.fixed=!0),this.onLinkEnd()}visualize(t){for(let e of this.joints)e.constraint&&e.constraint.visualize(e,t);if(this._target){let n=this._end.bone.transform.worldMatrix.elements,i=new e.Vector3(n[12],n[13],n[14]),o=new e.Vector3(n[8],n[9],n[10]);o.normalize();let s=new e.Vector3;this._target.pos.vsub(i,s);let r=s.length();s.setValue(i.x+r*o.x,i.y+r*o.y,i.z+r*o.z),t.addLine(i,s,e.Color.RED,e.Color.RED)}}solve(){if(!this.enable)return;if(!this._chainLength||!this._target)return;let t=new e.Quaternion,n=this._target.pos.clone(),i=this._end;if(1==this._chainLength){let o=i.worldMatrix,r=new e.Vector3(n.x-o.elements[12],n.y-o.elements[13],n.z-o.elements[14]);r.normalize();let a=new e.Vector3(o.elements[8],o.elements[9],o.elements[10]);a.normalize(),s(a,r,t);let l=i.rotationQuat,h=new e.Quaternion;e.Quaternion.multiply(t,l,h),i.rotationQuat=h;let c=this.joints[0];c.constraint&&c.constraint.enable&&c.constraint.doConsraint(c)}else{let o=this._chainLength;this._hasOff&&(o-=1);let r=1/o,a=kt.dirIt,l=!1;for(;a--&&!l;){for(let a=o-1;a>=0;a--){let o=this.joints[a],l=i.worldMatrix.elements,h=new e.Vector3(l[12],l[13],l[14]),c=new e.Vector3(l[8],l[9],l[10]);c.normalize();let u=new e.Vector3(n.x-h.x,n.y-h.y,n.z-h.z),d=e.Vector3.dot(u,c),m=new e.Vector3(h.x+c.x*d,h.y+c.y*d,h.z+c.z*d),g=o.worldMatrix.elements,p=new e.Vector3(g[12],g[13],g[14]),f=new e.Vector3(m.x-p.x,m.y-p.y,m.z-p.z),x=new e.Vector3(n.x-p.x,n.y-p.y,n.z-p.z);f.normalize(),x.normalize(),s(f,x,t),e.Quaternion.slerp(Et,t,r,t),this.rotateJoint(a,t)}let a=i.worldMatrix.elements,h=new e.Vector3(a[12],a[13],a[14]),c=new e.Vector3(a[8],a[9],a[10]);c.normalize();let u=new e.Vector3(n.x-h.x,n.y-h.y,n.z-h.z),d=e.Vector3.dot(u,c);new e.Vector3(u.x-d*c.x,u.y-d*c.y,u.z-d*c.z).length()<.001&&(l=!0)}}}}kt.dirIt=1;let Ft=e.ClassUtils.regClass;Ft("IK_Comp",It),Ft("IK_ChainData",Dt),Ft("IK_ConstraintData",Rt),Ft("BoneConstraints",Ct),Ft("BoneData",At);var Bt=new e.Vector3;class jt{constructor(t,e,n){this.name=t,this.parent=e,this.child=n,this.boneLength=0,this.pickDist=0,e.transform.position.vsub(n.transform.position,Bt),this.boneLength=Bt.length()}}new e.Vector3,new e.Vector3;t.Bone3D=jt,t.BoneConstraints=Ct,t.BoneData=At,t.IK_AnimLayer=p,t.IK_CCDSolver=m,t.IK_Chain=I,t.IK_ChainBase=b,t.IK_ChainData=Dt,t.IK_Comp=It,t.IK_ConstraintData=Rt,t.IK_ConstraintInstance=gt,t.IK_Constraint_Euler=ft,t.IK_Constraint_SwingTwist=Tt,t.IK_DebugRecorder=P,t.IK_FABRIK_Solver=class{constructor(t=10,e=.01){this.debugProc=!1,this.poleTarget=null,this.maxIterations=t,this.tolerance=e}solve(t,n,i,o){const s=n.joints,r=n.totalLength,a=s[0].position.clone();if(i.vsub(a,St),St.length()>r)return this.stretchToTarget(n,i),!1;for(let t=0;t<this.maxIterations;t++){if(n.isCollinear(i)){let t=1,i=new e.Vector3(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1);i.normalize();const o=(10*Math.random()-5)*Math.PI/180;let s=new e.Quaternion;e.Quaternion.createFromAxisAngle(i,o,s),n.rotateJoint(t,s)}i.cloneTo(s[s.length-1].position);for(let t=s.length-2;t>=0;t--)this.forwardStep(s[t],s[t+1]);a.cloneTo(s[0].position);for(let t=1;t<s.length;t++)this.backwardStep(s[t-1],s[t]);if(n.updateRotations(),this.applyConstraints(n),s[s.length-1].position.vsub(i,Lt).length()<this.tolerance)break}if(this.poleTarget&&s.length>2){let t=St;i.vsub(a,t);let o=this.poleTarget.pos,s=new e.Vector3;o.vsub(a,s);let r=new e.Vector3;n.joints[1].position.vsub(a,r);const l=1e-6;if(t.length()>l&&s.length()>l&&r.length()>l){t.normalize();const i=new e.Vector3,o=new e.Vector3,a=new e.Vector3;t.scale(e.Vector3.dot(r,t),a),r.vsub(a,i),t.scale(e.Vector3.dot(s,t),a),s.vsub(a,o);const l=i.length(),h=o.length(),c=.1;if(l>c&&h>c){i.scale(1/l,i),o.scale(1/h,o);const s=Math.max(-1,Math.min(1,e.Vector3.dot(i,o))),r=new e.Vector3;e.Vector3.cross(i,o,r);const a=e.Vector3.dot(r,t);let c=Math.atan2(a,s);if(isFinite(c)){const i=(t,e,n)=>Math.max(e,Math.min(n,t)),o=.5,s=this.dampingFactor>0?i(this.dampingFactor,.05,.5):.1;if(c=i(c,-o,o)*s,Math.abs(c)>1e-5){const i=new e.Quaternion;e.Quaternion.createFromAxisAngle(t,c,i),n.rotateJoint(0,i)}}}}}return n.updateRotations(),!0}applyConstraints(t){const n=t.joints;if(n.length<2)return;const i=new e.Quaternion;for(let e=0;e<n.length-1;e++)t.rotateJoint(e,i)}stretchToTarget(t,e){const n=t.joints,i=e.vsub(n[0].position,Lt).normalize();for(let t=1;t<n.length;t++){const e=n[t],o=n[t-1];o.position.vadd(i.scale(o.length,Pt),e.position)}t.updateRotations(),this.applyConstraints(t)}forwardStep(t,e){const n=e.position.vsub(t.position,Lt).normalize();e.position.vsub(n.scale(t.length,Pt),t.position)}backwardStep(t,e){const n=e.position.vsub(t.position,Lt).normalize();t.position.vadd(n.scale(t.length,Pt),e.position)}},t.IK_Joint=C,t.IK_JointManager=_,t.IK_LayerMgr=f,t.IK_Lookat=L,t.IK_Lookat1=kt,t.IK_System=D,t.IK_Target=Qt,t.IK_TwoBoneChain=class{constructor(){this.root=null,this.kee=null,this.end=null}solve(t,e){this.root.bone.transform.worldMatrix,this.kee.bone.transform.worldMatrix,this.kee.bone.transform.worldMatrix}},t.NumberSmooth=d,t.SHOW_DBG=A,t.Skeleton3D=class{constructor(){this.showBone=!0,this._bones=[],this._bounds=new e.BoundBox(new e.Vector3,new e.Vector3),this._editorCamera=null,this.enablePick=!1,this._curPickedBone=null,this._lastMouseX=0,this._lastMouseY=0,this._useGizmo=!0,this.showAxis=!1,this.axisLength=.3}get pickedParent(){var t;return null===(t=this._curPickedBone)||void 0===t?void 0:t.parent}get pickedChild(){var t;return null===(t=this._curPickedBone)||void 0===t?void 0:t.child}get pickdName(){var t;return null===(t=this._curPickedBone)||void 0===t?void 0:t.name}onAwake(t){this.owner=t,this._bones.length=0,this.traverseChildren(t,(t,e)=>{t&&e&&this._bones.push(new jt(t.name+"->"+e.name,t,e))})}visualize(t){if(this.showBone){this._visualSp=t;let e=this.owner;this.traverseChildren(e,this._addLine.bind(this))}}_addLine(t,n){if(!n)return;let i=e.Color.RED,o=e.Color.GREEN,s=this._visualSp;this._curPickedBone&&this._curPickedBone.parent==t&&this._curPickedBone.child==n&&(i=e.Color.WHITE,o=e.Color.WHITE,this.showAxis&&H(s,t.transform.worldMatrix,this.axisLength)),s.addLine(t.transform.position,n.transform.position,i,o)}traverseChildren(t,n){"joints"!=t.name&&(t.children&&0!=t.children.length||n(t,null),t.children.forEach(i=>{if(i instanceof e.Sprite3D){let e=i;n(t,e),this.traverseChildren(e,n)}}))}},t.Vec3Smooth=class{constructor(t=.5){this.k=t,this.lastV=null}in(t){let e=this.k,n=1-e;this.lastV||(this.lastV=t.clone());let i=this.lastV,o=t;return this.lastV.setValue(o.x*e+i.x*n,o.y*e+i.y*n,o.z*e+i.z*n),this.lastV}},t.delay=function(t){return new Promise(function(e){setTimeout(e,t)})},t.drawAxis=H,t.drawCircle=function(t,n,i,o,s){if(o<=0)return;if(0===i.x&&0===i.y&&0===i.z)return;et.set(i.x,i.y,i.z),et.normalize(),Math.abs(et.y)<.999?nt.set(0,1,0):nt.set(1,0,0),e.Vector3.cross(nt,et,it),it.normalize(),e.Vector3.cross(et,it,ot),ot.normalize();const r=2*Math.PI/48;for(let e=0;e<48;e++){const i=e*r,a=(e+1)*r;let l=Math.cos(i),h=Math.sin(i);j.set(o*(it.x*l+ot.x*h),o*(it.y*l+ot.y*h),o*(it.z*l+ot.z*h)),n.vadd(j,W),l=Math.cos(a),h=Math.sin(a),j.set(o*(it.x*l+ot.x*h),o*(it.y*l+ot.y*h),o*(it.z*l+ot.z*h)),n.vadd(j,q),t.addLine(W,q,s,s)}},t.drawEllipse=rt,t.drawEulerRange=st,t.drawEulerRange1=function(t,n,i,o,s,r,a,l){let h=n.elements,c=new e.Vector3(h[12],h[13],h[14]),u=new e.Vector3(h[0],h[1],h[2]),d=new e.Vector3(h[4],h[5],h[6]),m=new e.Vector3(h[8],h[9],h[10]);u.normalize(),d.normalize(),m.normalize(),tt(t,c,d,u,i,o,U),tt(t,c,u,d,s,r,X),tt(t,c,u,m,a,l,Y)},t.getJointMgr=w,t.getVecAngInPlane=function(t,n,i,o){let s=new e.Vector3;o.vsub(t,s);let r=e.Vector3.dot(s,n),a=new e.Vector3(s.x-r*n.x,s.y-r*n.y,s.z-r*n.z),l=e.Vector3.dot(i,n),h=new e.Vector3(i.x-l*n.x,i.y-l*n.y,i.z-l*n.z),c=function(t,e){let n=t.length(),i=e.length(),o=t.dot(e)/n/i;return o>1&&(o=1),Math.acos(o)}(h,a),u=new e.Vector3;return e.Vector3.cross(h,a,u),e.Vector3.dot(u,n)<0&&(c=-c),c},t.isCollinear=l,t.quaternionFromTo=s,t.ripMatScale=u,t.solveLambdaForNormEquality=h,t.solveLookat=c}(window.Laya=window.Laya||{},Laya);
@@ -0,0 +1 @@
1
+ !function(e,t){"use strict";class i{constructor(){this.changeCount=0,this._lightDirection=new t.Vector3(-1,0,1),this._ambientColor=new t.Color(.2,.2,.2,0),this._ambientLayerMask=-1,this._multiSamples=4}notifyChange(){this.changeCount++}get lightDirection(){return this._lightDirection}set lightDirection(e){this._lightDirection!==e&&(this._lightDirection=e,this.notifyChange())}get ambientColor(){return this._ambientColor}set ambientColor(e){this._ambientColor!==e&&(this._ambientColor=e),this.notifyChange()}get ambientLayerMask(){return this._ambientLayerMask}set ambientLayerMask(e){this._ambientLayerMask!==e&&(this._ambientLayerMask=e,this.notifyChange())}get multiSamples(){return this._multiSamples}set multiSamples(e){this._multiSamples!==e&&(this._multiSamples=e,this.notifyChange())}}class s{constructor(e,i,s){this.lights=[],this.textures=[],this.material=[],this.materialShadow=[],this.lightMeshs=[],this.shadowMeshs=[],this.needShadowMesh=[],this.sceneModeNum=[],this.sceneModeList=[],this._layer=0,this._invertY=!1,this._cmdLightMeshs=[],this._cmdShadowMeshs=[],this._cmdBuffer=new t.CommandBuffer2D("Light2DRender"),this._layer=i,this._invertY=s}_initMaterial(e,i){i?(e.setShaderName("ShadowGen2D"),e.setFloat("u_Shadow2DStrength",.5),e.setColor("u_ShadowColor",new t.Color(0,0,0,1))):e.setShaderName("LightAndShadowGen2D"),e.setColor("u_LightColor",new t.Color(1,1,1,1)),e.setFloat("u_LightRotation",0),e.setFloat("u_LightIntensity",1),e.setFloat("u_PCFIntensity",1),e.setVector2("u_LightTextureSize",new t.Vector2(1,1)),e.setVector2("u_LightScale",new t.Vector2(1,1)),e.setBoolByIndex(t.Shader3D.DEPTH_WRITE,!1),e.setIntByIndex(t.Shader3D.DEPTH_TEST,t.RenderState.DEPTHTEST_OFF),e.setIntByIndex(t.Shader3D.BLEND,t.RenderState.BLEND_ENABLE_SEPERATE),e.setIntByIndex(t.Shader3D.BLEND_EQUATION_RGB,t.RenderState.BLENDEQUATION_ADD),e.setIntByIndex(t.Shader3D.BLEND_SRC_RGB,t.RenderState.BLENDPARAM_ONE),e.setIntByIndex(t.Shader3D.BLEND_DST_RGB,t.RenderState.BLENDPARAM_ONE),e.setIntByIndex(t.Shader3D.BLEND_EQUATION_ALPHA,t.RenderState.BLENDEQUATION_ADD),e.setIntByIndex(t.Shader3D.BLEND_SRC_ALPHA,t.RenderState.BLENDPARAM_ONE),e.setIntByIndex(t.Shader3D.BLEND_DST_ALPHA,t.RenderState.BLENDPARAM_ONE),e.setIntByIndex(t.Shader3D.CULL,t.RenderState.CULL_NONE)}setMaterialData(i,s,h){const n=i._pcfIntensity();if(h&&(s.setColor("u_ShadowColor",i.shadowColor),s.setFloat("u_Shadow2DStrength",i.shadowStrength)),s.setColor("u_LightColor",i.color),s.setFloat("u_LightIntensity",i.intensity),s.setFloat("u_LightRotation",i.lightRotation),s.setVector2("u_LightScale",i.lightScale),s.setVector2("u_LightTextureSize",i._getTextureSize()),s.setFloat("u_PCFIntensity",n),L.SUPPORT_LIGHT_BLEND_MODE)switch(i.lightMode){default:case e.Light2DMode.Add:s.setIntByIndex(t.Shader3D.BLEND_EQUATION_RGB,t.RenderState.BLENDEQUATION_ADD),s.setIntByIndex(t.Shader3D.BLEND_SRC_RGB,t.RenderState.BLENDPARAM_ONE),s.setIntByIndex(t.Shader3D.BLEND_DST_RGB,t.RenderState.BLENDPARAM_ONE);break;case e.Light2DMode.Sub:s.setIntByIndex(t.Shader3D.BLEND_EQUATION_RGB,t.RenderState.BLENDEQUATION_REVERSE_SUBTRACT),s.setIntByIndex(t.Shader3D.BLEND_SRC_RGB,t.RenderState.BLENDPARAM_ONE),s.setIntByIndex(t.Shader3D.BLEND_DST_RGB,t.RenderState.BLENDPARAM_ONE);break;case e.Light2DMode.Mix:s.setIntByIndex(t.Shader3D.BLEND_EQUATION_RGB,t.RenderState.BLENDEQUATION_ADD),s.setIntByIndex(t.Shader3D.BLEND_SRC_RGB,t.RenderState.BLENDPARAM_ONE),s.setIntByIndex(t.Shader3D.BLEND_DST_RGB,t.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA)}}addLights(e,i){const s=e.length;!L.REUSE_MESH&&i&&this._needRecoverMesh(i,s),this.lights=e,this.textures.length=s,this.lightMeshs.length=s,this.shadowMeshs.length=s,this.needShadowMesh.length=s,this.sceneModeList.length=s;for(let e=0;e<3;e++)this.sceneModeNum[e]=0;for(let i=0;i<s;i++){const s=e[i],h=1/s._pcfIntensity()|0;this.lightMeshs[i]||(this.lightMeshs[i]=[]),this.lightMeshs[i].length=h,this.material[i]?this.setMaterialData(s,this.material[i],!1):(this.material[i]=new t.Material,this.material[i]._addReference(),this._initMaterial(this.material[i],!1)),this.textures[i]=s._texLight,this.sceneModeNum[s.sceneMode]++,this.sceneModeList[i]=s.sceneMode}for(let i=0;i<s;i++){const s=e[i];s._isNeedShadowMesh()?(this.materialShadow[i]?this.setMaterialData(s,this.materialShadow[i],!0):(this.materialShadow[i]=new t.Material,this.materialShadow[i]._addReference(),this._initMaterial(this.materialShadow[i],!0)),this.needShadowMesh[i]=!0):this.needShadowMesh[i]=!1}}updateLightPCF(e){for(let t=this.lights.length-1;t>-1;t--)if(this.lights[t]===e){const i=1/e._pcfIntensity()|0;this.lightMeshs[t]||(this.lightMeshs[t]=[]),this.lightMeshs[t].length=i}}_needRecoverMesh(e,t){for(let i=this.lightMeshs.length-1;i>=t;i--)if(this.lightMeshs[i]){const t=this.lightMeshs[i];if(t[i])for(let i=t.length-1;i>-1;i--)e.push(t[i]),t[i]=null}for(let i=this.shadowMeshs.length-1;i>=t;i--)this.shadowMeshs[i]&&(e.push(this.shadowMeshs[i]),this.shadowMeshs[i]=null)}setRenderTargetCMD(e,i,s){this._cmdRT?this._cmdRT.renderTexture=e:this._cmdRT=t.Set2DRTCMD.create(e,!0,t.Color.CLEAR,this._invertY),L.SUPPORT_LIGHT_SCENE_MODE&&(this._cmdRTAdd?this._cmdRTAdd.renderTexture=i:i&&(this._cmdRTAdd=t.Set2DRTCMD.create(i,!0,t.Color.CLEAR,this._invertY)),this._cmdRTSub?this._cmdRTSub.renderTexture=s:s&&(this._cmdRTSub=t.Set2DRTCMD.create(s,!0,t.Color.CLEAR,this._invertY)))}buildRenderMeshCMD(){for(let e=this._cmdLightMeshs.length-1;e>-1;e--){const t=this._cmdLightMeshs[e];for(let e=t.length-1;e>-1;e--)t[e].recover();t.length=0}this._cmdLightMeshs.length=0;for(let e=this._cmdShadowMeshs.length-1;e>-1;e--)this._cmdShadowMeshs[e]&&this._cmdShadowMeshs[e].recover();this._cmdShadowMeshs.length=0;const e=t.Matrix.EMPTY;for(let i=0,s=this.lightMeshs.length;i<s;i++){const s=this.lightMeshs[i],h=this._cmdLightMeshs[i]=[];for(let n=s.length-1;n>-1;n--)h.push(t.DrawMesh2DCMD.create(s[n],e,this.textures[i],t.Color.WHITE,this.material[i]))}for(let i=0,s=this.shadowMeshs.length;i<s;i++)this.needShadowMesh[i]?this._cmdShadowMeshs.push(t.DrawMesh2DCMD.create(this.shadowMeshs[i],e,this.textures[i],t.Color.WHITE,this.materialShadow[i])):this._cmdShadowMeshs.push(null)}updateMaterial(){for(let e=0,t=this._cmdLightMeshs.length;e<t;e++){const t=this._cmdLightMeshs[e];for(let i=0,s=t.length;i<s;i++)t[i].texture=this.textures[e],t[i].material=this.material[e]}for(let e=0,t=this._cmdShadowMeshs.length;e<t;e++)this._cmdShadowMeshs[e]&&(this._cmdShadowMeshs[e].texture=this.textures[e],this._cmdShadowMeshs[e].material=this.materialShadow[e])}updateLightMesh(e,t,i){this.lightMeshs[t][i]=e,L.REUSE_CMD&&this._cmdLightMeshs[t]&&this._cmdLightMeshs[t][i]&&(this._cmdLightMeshs[t][i].mesh=e)}updateShadowMesh(e,t){this.shadowMeshs[t]=e,L.REUSE_CMD&&this._cmdShadowMeshs[t]&&(this._cmdShadowMeshs[t].mesh=e)}enableShadow(e,i){const s=this._layer;for(let h=this.lights.length-1;h>-1;h--)if(this.lights[h]===e)return this.needShadowMesh[h]=!1,void(e.shadowEnable&&e._isNeedShadowMesh()&&e.shadowLayerMask&1<<s?(L.REUSE_CMD&&(this._cmdShadowMeshs[h]||(this._cmdShadowMeshs[h]=t.DrawMesh2DCMD.create(this.shadowMeshs[h],t.Matrix.EMPTY,this.textures[h],t.Color.WHITE,this.materialShadow[h]))),this.materialShadow[h]||(this.materialShadow[h]=new t.Material,this.materialShadow[h]._addReference(),this._initMaterial(this.materialShadow[h],!0)),this.needShadowMesh[h]=!0):(!L.REUSE_MESH&&i&&this.shadowMeshs[h]&&i.push(this.shadowMeshs[h]),this.shadowMeshs[h]=null,L.REUSE_CMD&&this._cmdShadowMeshs[h]&&(this._cmdShadowMeshs[h].recover(),this._cmdShadowMeshs[h]=null)))}destroy(){for(let e=this.material.length-1;e>-1;e--)this.material[e]&&(this.material[e]._removeReference(),this.material[e]=null);for(let e=this.materialShadow.length-1;e>-1;e--)this.materialShadow[e]&&(this.materialShadow[e]._removeReference(),this.materialShadow[e]=null);this.material.length=0,this.materialShadow.length=0}render(i,s,h){const n=this.lights.length;if(L.REUSE_CMD){const t=(e,t)=>{this._cmdBuffer.addCacheCommand(e);for(let e=0;e<n;e++)if(!L.SUPPORT_LIGHT_SCENE_MODE||this.sceneModeList[e]===t){const t=this._cmdLightMeshs[e];for(let e=0,i=t.length;e<i;e++){const i=t[e];i.mesh&&i.material&&this._cmdBuffer.addCacheCommand(i)}const i=this._cmdShadowMeshs[e];i&&i.mesh&&i.material&&this._cmdBuffer.addCacheCommand(i)}this._cmdBuffer.apply(!0),this._cmdBuffer.clear(!1)};this._cmdRT&&t(this._cmdRT,e.Light2DMode.Mul),L.SUPPORT_LIGHT_SCENE_MODE&&(this._cmdRTAdd&&this.sceneModeNum[e.Light2DMode.Add]>0&&t(this._cmdRTAdd,e.Light2DMode.Add),this._cmdRTSub&&this.sceneModeNum[e.Light2DMode.Sub]>0&&t(this._cmdRTSub,e.Light2DMode.Sub))}else{const r=(e,i)=>{this._cmdBuffer.setRenderTarget(e,!0,t.Color.CLEAR,this._invertY);for(let e=0;e<n;e++)if(!L.SUPPORT_LIGHT_SCENE_MODE||this.sceneModeList[e]===i){const i=this.lightMeshs[e];for(let s=0,h=i.length;s<h;s++)i[s]&&this.material[e]&&this._cmdBuffer.drawMesh(i[s],a,this.textures[e],t.Color.WHITE,this.material[e]);const s=this.shadowMeshs[e];s&&this.materialShadow[e]&&this._cmdBuffer.drawMesh(s,a,this.textures[e],t.Color.WHITE,this.materialShadow[e])}this._cmdBuffer.apply(!0),this._cmdBuffer.clear(!0)},a=t.Matrix.EMPTY;r(i,e.Light2DMode.Mul),L.SUPPORT_LIGHT_SCENE_MODE&&(this.sceneModeNum[e.Light2DMode.Add]>0&&r(s,e.Light2DMode.Add),this.sceneModeNum[e.Light2DMode.Sub]>0&&r(h,e.Light2DMode.Sub))}}}class h{constructor(){this.useNormal=!1}create(e,i,s,h,n=!1){if(this.a?this.a.setValue(e,i):this.a=new t.Vector2(e,i),this.b?this.b.setValue(s,h):this.b=new t.Vector2(s,h),n){let n=this.n;n?n.setValue(h-i,e-s):n=this.n=new t.Vector2(h-i,e-s),t.Vector2.normalize(n,n)}return this.useNormal=n,this}}class n{constructor(e){this._points=[],e&&this._points.push(...e)}get points(){return this._points}set points(e){this._points=e}addPoint(e,t,i=-1){if(i<0)this._points.push(e,t);else{for(let e=this._points.length;e>i;e--)this._points[e]=this._points[e-1];this._points[2*i+0]=e,this._points[2*i+1]=t}}updatePoint(e,t,i){i<(this._points.length/2|0)&&i>=0&&(this._points[2*i+0]=e,this._points[2*i+1]=t)}removePoint(e){e<this._points.length&&e>=0&&this._points.splice(e,1)}clear(){this._points.length=0}clone(){const e=new n;return e._points.push(...this._points),e}cloneTo(e){return e._points.length=0,e._points.push(...this._points),e}}class r{set owner(e){this._owner=e}set manager(e){this._manager=e}get layerMask(){return this._layerMask}set layerMask(e){if(e!==this._layerMask){this._layerMaskChange(this._layerMask,e),this._layerMask=e,this._layers.length=0;for(let t=0;t<L.MAX_LAYER;t++)e&1<<t&&this._layers.push(t)}}get layers(){return this._layers}get canInLight(){return this._canInLight}set canInLight(e){e!==this._canInLight&&(this._canInLight=e,this._needUpdate=!0)}get outside(){return this._outside}set outside(e){e!==this._outside&&(this._outside=e,this._needUpdate=!0,this._clearCache())}get needUpdate(){return this._needUpdate}set needUpdate(e){this._needUpdate=e}constructor(e){this._layerMask=1,this._layers=[0],this._x=0,this._y=0,this._scaleX=1,this._scaleY=2,this._skewX=0,this._skewY=0,this._rotation=0,this._tfChanged=!0,this._sceneMatrix=new t.Matrix,this._canInLight=!0,this._outside=!0,this._occluderId=0,this._localRange=new t.Rectangle,this._worldRange=new t.Rectangle,this._needUpdate=!1,this._needTransformPoly=!1,this._needUpdateLightLocalRange=!1,this._needUpdateLightWorldRange=!1,this._select=!1,this._outsideSegment=[],this._segments=[],this._segLight=new t.Vector2,this._tempVec2=new t.Vector2,this._manager=e,this._occluderId=r._idCounter++}_onEnable(){var e;null===(e=this._manager)||void 0===e||e.addOccluder(this)}_onDisable(){var e;null===(e=this._manager)||void 0===e||e.removeOccluder(this)}pos(e,t){return this._x==e&&this._y==t||(this._x=e,this._y=t,this._tfChanged=!0,this._transformChange()),this}scale(e,t){return this._scaleX===e&&this._scaleY===t||(this._scaleX=e,this._scaleY=t,this._tfChanged=!0,this._transformChange()),this}skew(e,t){return this._skewX===e&&this._skewY===t||(this._skewX=e,this._skewY=t,this._tfChanged=!0,this._transformChange()),this}get x(){return this._x}set x(e){this.pos(e,this._y)}get y(){return this._y}set y(e){this.pos(this._x,e)}get scaleX(){return this._scaleX}set scaleX(e){this.scale(e,this._scaleY)}get scaleY(){return this._scaleY}set scaleY(e){this.scale(this._scaleX,e)}get skewX(){return this._skewX}set skewX(e){this.skew(e,this._skewX)}get skewY(){return this._skewY}set skewY(e){this.skew(this._skewX,e)}get rotation(){return this._rotation}set rotation(e){this._rotation!==e&&(this._rotation=e,this._tfChanged=!0,this._transformChange())}get transform(){if(!this._tfChanged)return this._transform;this._tfChanged=!1;const e=this._transform||(this._transform=new t.Matrix),i=this._scaleX,s=this._scaleY,h=this._skewX,n=this._skewY,r=this._rotation;if(r||1!==i||1!==s||0!==h||0!==n){e._bTransform=!0;const t=.0174532922222222*(r-h),a=.0174532922222222*(r+n),o=Math.cos(a),l=Math.sin(a),d=Math.sin(t),_=Math.cos(t);e.a=i*o,e.b=i*l,e.c=-s*d,e.d=s*_,e.tx=e.ty=0}else e.identity();return e}set transform(e){this._tfChanged=!1;const i=this._transform||(this._transform=new t.Matrix);e!==i&&e.copyTo(i),e&&(this._x=i.tx,this._y=i.ty,i.tx=i.ty=0)}_layerMaskChange(e,t){var i;null===(i=this._manager)||void 0===i||i.occluderLayerMaskChange(this,e,t)}_transformChange(){var e;this._needUpdate=!0,this._needTransformPoly=!0,this._needUpdateLightWorldRange=!0,null===(e=this._manager)||void 0===e||e.needCollectOccluderInLight(this.layerMask)}set polygonPoint(e){var t,i,s;e?(this._occluderPolygon=e,this._globalPolygon=e.clone(),this._cutPolygon?this._cutPolygon.clear():this._cutPolygon=new n,this._needUpdate=!0,this._needTransformPoly=!0,this._needUpdateLightLocalRange=!0,this._needUpdateLightWorldRange=!0,null===(t=this._manager)||void 0===t||t.addOccluder(this)):(this._occluderPolygon=null,this._globalPolygon=null,this._cutPolygon&&this._cutPolygon.clear(),null===(i=this._manager)||void 0===i||i.removeOccluder(this)),null===(s=this._manager)||void 0===s||s.needCollectOccluderInLight(this.layerMask)}get polygonPoint(){return this._occluderPolygon}_clearCache(){const e=this._segments;for(let i=e.length-1;i>-1;i--)t.Pool.recover("LightLine2D",e[i]);e.length=0,this._segLight.x=Number.POSITIVE_INFINITY,this._segLight.y=Number.POSITIVE_INFINITY}getSegment(e,i){if(this._needTransformPoly&&(this._needTransformPoly=!1,this._transformPoly()),e|=0,i|=0,this._segLight.x===e&&this._segLight.y===i)return L.DEBUG&&console.log("get segments cache",e,i),this._segments;if(this._globalPolygon){const s=this._outsideSegment,n=this._globalPolygon.points,r=this._cutPolygon.points,a=n.length/2|0;this._segLight.x=e,this._segLight.y=i;const o=this._segments;for(let e=o.length-1;e>-1;e--)t.Pool.recover("LightLine2D",o[e]);if(o.length=0,this.outside){let e=0;if(s.length>0)for(let i=0,l=s.length;i<l;i++)if(e=s[i],e>=0){const i=2*e,s=(e+1)%a*2;o.push(t.Pool.getItemByClass("LightLine2D",h).create(n[i],n[i+1],n[s],n[s+1]))}else{e=2*(-e-1);const i=2*e,s=(e+1)%a*2;o.push(t.Pool.getItemByClass("LightLine2D",h).create(r[i],r[i+1],r[s],r[s+1]))}}else if(a>1)for(let e=0;e<a;e++){const i=2*e,s=(e+1)%a*2;o.push(t.Pool.getItemByClass("LightLine2D",h).create(n[i],n[i+1],n[s],n[s+1]))}}return L.DEBUG&&console.log("calc occluder segments",e,i),this._segments}_calcLocalRange(){if(this._occluderPolygon){const e=this._occluderPolygon.points;let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY;for(let n=e.length-2;n>-1;n-=2){const r=e[n+0],a=e[n+1];t>r&&(t=r),s<r&&(s=r),i>a&&(i=a),h<a&&(h=a)}this._localRange.x=t,this._localRange.y=i,this._localRange.width=s-t,this._localRange.height=h-i}this._needUpdateLightLocalRange=!1}_calcWorldRange(){if(this._needTransformPoly&&(this._needTransformPoly=!1,this._transformPoly()),this._globalPolygon){let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;const h=this._globalPolygon.points;for(let n=h.length-2;n>-1;n-=2){const r=h[n+0],a=h[n+1];e>r&&(e=r),i<r&&(i=r),t>a&&(t=a),s<a&&(s=a)}this._worldRange.x=e,this._worldRange.y=t,this._worldRange.width=i-e,this._worldRange.height=s-t}this._needUpdateLightWorldRange=!1}_getRange(){return this._needUpdateLightLocalRange&&this._calcLocalRange(),this._needUpdateLightWorldRange&&this._calcWorldRange(),this._worldRange}isInLightRange(e){return this._getRange().intersects(e)}selectByLight(e,t){if(this._occluderPolygon){if(this.canInLight)this._select=!0;else{this._needTransformPoly&&(this._needTransformPoly=!1,this._transformPoly());let i=0;const s=this._globalPolygon.points,h=s.length/2|0;for(let n=0;n<h;n++){const r=s[2*n+0],a=s[2*n+1],o=s[(n+1)%h*2+0],l=s[(n+1)%h*2+1];if(a>t!=l>t){e<(o-r)*(t-a)/(l-a)+r&&i++}}this._select=i%2!=1}this._select&&this.outside&&this._selectOutside(this._globalPolygon.points,e,t,this._outsideSegment)}return this._select}_transformPoly(){if(this._globalPolygon){let e=this._x,i=this._y,s=this._scaleX,h=this._scaleY;if(this._owner){let n=this._owner.globalTrans;const r=n.getPos(t.Point.TEMP);e=r.x,i=r.y,s=n.scaleX,h=n.scaleY}const n=this._globalPolygon.points,r=this._occluderPolygon.points,a=r.length/2|0;let o=this._owner?this._owner.globalTrans.getMatrix():this.transform;if(o)for(let t=0;t<a;t++){const s=r[2*t+0],h=r[2*t+1];n[2*t+0]=o.a*s+o.c*h+e,n[2*t+1]=o.b*s+o.d*h+i}else for(let t=0;t<a;t++){const a=r[2*t+0],o=r[2*t+1];n[2*t+0]=a*s+e,n[2*t+1]=o*h+i}this._clearCache()}}_selectOutside(e,t,i,s){let h=0,n=0,r=0,a=0,o=0,l=0,d=0,_=0,c=0;const g=(e,t,i,s,g,u,L,y,S)=>(h=i-e,n=s-t,r=g-L,a=u-y,d=h*a-n*r,!(Math.abs(d)<Number.EPSILON)&&(o=g-e,l=u-t,_=(o*a-l*r)/d,c=(o*n-l*h)/d,_>=0&&_<=1&&c>0&&(S.x=e+_*h,S.y=t+_*n,Math.abs(S.x-g)>Number.EPSILON||Math.abs(S.y-u)>Number.EPSILON))),u=(e,t,i,s,h,n)=>(i-e)*(n-t)-(s-t)*(h-e)>0;s.length=0;const L=this._cutPolygon.points;L.length=0;const y=e.length/2|0,S=this._tempVec2;let R=0,D=0,m=0,p=0,f=!1,M=!1;for(let h=0;h<y;h++){if(R=e[2*h+0],D=e[2*h+1],m=e[(h+1)%y*2+0],p=e[(h+1)%y*2+1],f=!1,M=!1,u(R,D,m,p,t,i)){for(let s=0;s<y;s++)if(h!==s&&g(e[2*s],e[2*s+1],e[(s+1)%y*2],e[(s+1)%y*2+1],R,D,t,i,S)){f=!0;break}for(let s=0;s<y;s++)if(h!==s&&g(e[2*s],e[2*s+1],e[(s+1)%y*2],e[(s+1)%y*2+1],m,p,t,i,S)){M=!0;break}}else f=!0,M=!0;if(f||M||s.push(h),!f&&M){const h=this._findNearestIntersection(R,D,m,p,t,i,e);h&&(L.push(R,D,h.x,h.y),s.push(-L.length/4))}if(f&&!M){const h=this._findNearestIntersection(m,p,R,D,t,i,e);h&&(L.push(h.x,h.y,m,p),s.push(-L.length/4))}}}_findNearestIntersection(e,i,s,h,n,r,a){const o=(e,t,i,s)=>{const h=e-i,n=t-s;return Math.sqrt(h*h+n*n)},l=(e,t,i,s,h,n,r,a,o)=>{const l=e,d=t,_=i,c=s,g=(a-n)*(_-l)-(r-h)*(c-d);if(0===g)return!1;const u=((r-h)*(d-n)-(a-n)*(l-h))/g,L=((_-l)*(d-n)-(c-d)*(l-h))/g;return!(u<=0||u>=1||L<=0||L>=1)&&(o.x=l+u*(_-l),o.y=d+u*(c-d),!0)};let d=null,_=1/0,c=new t.Vector2,g=0;for(let t=a.length-2;t>-1;t-=2)l(e,i,s,h,n,r,a[t],a[t+1],c)&&(g=o(c.x,c.y,e,i),g<_&&(_=g,d=c));return d}destroy(){this._onDisable(),this.owner=null,this.manager=null}}r._idCounter=0;class a{constructor(e){this._occluderMap=new Map,this._manager=e}addOccluder(e,t){var i,s,h,a,o,l;let d,_=this._occluderMap.get(e);const c=t.poly,g=null!==(i=t.layerMask)&&void 0!==i?i:1,u=null!==(s=t.px)&&void 0!==s?s:0,L=null!==(h=t.py)&&void 0!==h?h:0,y=null!==(a=t.sx)&&void 0!==a?a:1,S=null!==(o=t.sy)&&void 0!==o?o:1,R=null!==(l=t.rot)&&void 0!==l?l:0;if(c instanceof Array){d=new n;for(let e=0,t=c.length;e<t;e+=2)d.addPoint(c[e],c[e+1])}else d=c;return _||(_=new r,_.manager=this._manager,_._onEnable(),this._occluderMap.set(e,_)),_.pos(u,L),_.scale(y,S),_.rotation=R,_.polygonPoint=d,_.layerMask=g,_}getOccluder(e){return this._occluderMap.get(e)}setPos(e,t,i){const s=this._occluderMap.get(e);return s&&s.pos(t,i),s}setRot(e,t){const i=this._occluderMap.get(e);return i&&(i.rotation=t),i}setScale(e,t,i){const s=this._occluderMap.get(e);return s&&s.scale(t,i),s}removeOccluder(e){const t=this._occluderMap.get(e);return t&&t.destroy(),this._occluderMap.delete(e)}clearOccluder(){this._occluderMap.forEach(e=>e.destroy()),this._occluderMap.clear()}}class o{static __init__(){this.renderShader=t.Shader3D.add("LightGen2D",!1,!1),this.renderShader.shaderType=t.ShaderFeatureType.D2_BaseRenderNode2D;const e=new t.SubShader(this.RenderAttribute,{},{});this.renderShader.addSubShader(e),e.addShaderPass('#define SHADER_NAME FreeformLight_VS\n#include "Sprite2DVertex.glsl";\nvoid main(){v_texcoord=a_uv;gl_Position=vec4((a_position.x/u_size.x-0.5)*2.0,(a_position.y/u_size.y-0.5)*2.0,0.0,1.0);\n#ifdef INVERTY\ngl_Position.y=-gl_Position.y;\n#endif\n}','#define SHADER_NAME FreeformLight_PS\n#if defined(GL_FRAGMENT_PRECISION_HIGH)\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#include "Sprite2DFrag.glsl";\nvoid main(){gl_FragColor=vec4(v_texcoord.x);}')}}o.RenderAttribute={a_position:[0,t.ShaderDataType.Vector4],a_uv:[2,t.ShaderDataType.Vector2]};class l{static __init__(){this.renderShader=t.Shader3D.add("ShadowGen2D",!1,!1),this.renderShader.shaderType=t.ShaderFeatureType.D2_BaseRenderNode2D;const e=new t.SubShader(this.RenderAttribute,this.RenderUniform,{});this.renderShader.addSubShader(e),e.addShaderPass('#define SHADER_NAME ShadowGen2D_VS\n#include "Sprite2DVertex.glsl";\nvec2 rotateAndScaleUV(vec2 uv,float rotation,vec2 scale){vec2 mid=vec2(0.5);float c=cos(rotation);float s=sin(rotation);vec2 ret=vec2(c*(uv.x-mid.x)+s*(uv.y-mid.y)+mid.x,c*(uv.y-mid.y)-s*(uv.x-mid.x)+mid.y);return(ret-mid)*scale+mid;}void main(){v_texcoord=rotateAndScaleUV(a_uv,u_LightRotation,u_LightScale);v_color=min(vec4(1.0),u_LightColor*min(1.0,u_LightIntensity)*(1.0-u_Shadow2DStrength)+u_ShadowColor);gl_Position=vec4((a_position.x/u_size.x-0.5)*2.0,(0.5-a_position.y/u_size.y)*2.0,0.0,1.0);\n#ifdef INVERTY\ngl_Position.y=-gl_Position.y;\n#endif\n}','#define SHADER_NAME ShadowGen2D_PS\n#if defined(GL_FRAGMENT_PRECISION_HIGH)\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#include "Sprite2DFrag.glsl";\nvoid main(){vec2 t=step(vec2(0.0),v_texcoord)*step(v_texcoord,vec2(1.0));gl_FragColor=texture2D(u_baseRender2DTexture,v_texcoord)*v_color*t.x*t.y;}')}}l.RenderUniform={u_LightColor:t.ShaderDataType.Color,u_ShadowColor:t.ShaderDataType.Color,u_LightRotation:t.ShaderDataType.Float,u_LightIntensity:t.ShaderDataType.Float,u_Shadow2DStrength:t.ShaderDataType.Float,u_LightScale:t.ShaderDataType.Vector2,u_PCFIntensity:t.ShaderDataType.Float},l.RenderAttribute={a_position:[0,t.ShaderDataType.Vector4],a_uv:[2,t.ShaderDataType.Vector2]};var d,_,c;class g{static __init__(){this.renderShader=t.Shader3D.add("LightAndShadowGen2D",!1,!1),this.renderShader.shaderType=t.ShaderFeatureType.D2_BaseRenderNode2D;const e=new t.SubShader(this.RenderAttribute,this.RenderUniform,{});this.renderShader.addSubShader(e),e.addShaderPass('#define SHADER_NAME LightAndShadowGen2D_VS\n#include "Sprite2DVertex.glsl";\nvec2 rotateAndScaleUV(vec2 uv,float rotation,vec2 scale){vec2 mid=vec2(0.5);float c=cos(rotation);float s=sin(rotation);vec2 ret=vec2(c*(uv.x-mid.x)+s*(uv.y-mid.y)+mid.x,c*(uv.y-mid.y)-s*(uv.x-mid.x)+mid.y);return(ret-mid)*scale+mid;}void main(){v_texcoord=rotateAndScaleUV(a_uv,u_LightRotation,u_LightScale);v_color=u_LightColor*u_LightIntensity*u_PCFIntensity;gl_Position=vec4((a_position.x/u_size.x-0.5)*2.0,(0.5-a_position.y/u_size.y)*2.0,0.0,1.0);\n#ifdef INVERTY\ngl_Position.y=-gl_Position.y;\n#endif\n}','#define SHADER_NAME LightAndShadowGen2D_PS\n#if defined(GL_FRAGMENT_PRECISION_HIGH)\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#include "Sprite2DFrag.glsl";\nvoid main(){vec2 t=step(vec2(0.0),v_texcoord)*step(v_texcoord,vec2(1.0));gl_FragColor=texture2D(u_baseRender2DTexture,v_texcoord)*v_color*t.x*t.y;}')}}g.RenderUniform={u_LightColor:t.ShaderDataType.Color,u_LightRotation:t.ShaderDataType.Float,u_LightIntensity:t.ShaderDataType.Float,u_LightScale:t.ShaderDataType.Vector2,u_LightTextureSize:t.ShaderDataType.Vector2,u_PCFIntensity:t.ShaderDataType.Float},g.RenderAttribute={a_position:[0,t.ShaderDataType.Vector4],a_uv:[2,t.ShaderDataType.Vector2]};class u{static __init__(){o.__init__(),l.__init__(),g.__init__(),y.__init__(),L.__init__()}}class L{static clampRTSize(e){const i=t.LayaGL.renderEngine.getParams(t.RenderParams.MAX_Texture_Size);return i>0&&e>i?(console.warn(`[Light2D] RT size ${e} exceeds device MAX_TEXTURE_SIZE (${i}), clamped. Reduce light outerRadius/range to avoid visual truncation on low-end devices.`),i):e}get config(){return L._config}set config(e){L._config=e;for(let e=this._updateMark.length-1;e>-1;e--)this._updateMark[e]++}static __init__(){t.Scene.scene2DUniformMap||(t.Scene.scene2DUniformMap=t.LayaGL.renderDeviceFactory.createGlobalUniformMap("Sprite2DGlobal"))}constructor(e){if(this.lsTarget=[],this.lsTargetAdd=[],this.lsTargetSub=[],this._PCF=[],this._segments=[],this._points=[],this._param=[],this._lights=[],this._occluders=[],this._works=0,this._updateMark=new Array(L.MAX_LAYER).fill(1),this._updateLayerLight=new Array(L.MAX_LAYER).fill(!1),this._configChangeCount=0,this._spriteLayer=[],this._spriteNumInLayer=new Array(L.MAX_LAYER).fill(0),this._lightLayer=[],this._lightLayerAll=[],this._lightSceneModeNum=new Array(L.MAX_LAYER).fill(0).map(()=>[0,0,0]),this._lightsInLayer=[],this._lightsInLayerAll=[],this._occluderLayer=[],this._occludersInLayer=[],this._occludersInLight=[],this._lightRenderRes=[],this._sceneInv0=new t.Vector3,this._sceneInv1=new t.Vector3,this._stageMat0=new t.Vector3,this._stageMat1=new t.Vector3,this._lightScenePos=new t.Point,this._recoverFC=0,this._needToRecover=[],this._needUpdateLightRes=0,this._needCollectLightInLayer=0,this._needCollectOccluderInLight=0,this._lightsNeedCheckRange=[],t.PlayerConfig.light2D){let e=t.PlayerConfig.light2D;L._config=new i,L._config.ambientColor=new t.Color(e.ambientColor.r,e.ambientColor.g,e.ambientColor.b,e.ambientColor.a),L._config.ambientLayerMask=e.ambientLayerMask,e.lightDirection?L._config.lightDirection=new t.Vector3(e.lightDirection.x,e.lightDirection.y,e.lightDirection.z):L._config.lightDirection=new t.Vector3(-1,0,1),L._config.multiSamples=e.multiSamples}this._scene=e,this._scene._light2DManager=this,this._screen=new t.Rectangle,this._screenPrev=new t.Vector2,this._screenSchmitt=new t.Rectangle,this._screenSchmittChange=!1,this.occluderAgent=new a(this),this._configChangeCount=this.config.changeCount,t.ILaya.stage.on(t.Event.RESIZE,this,this._onScreenResize),this._PCF=[new t.Vector2(0,0),new t.Vector2(-1,0),new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(0,1),new t.Vector2(-1,-1),new t.Vector2(1,-1),new t.Vector2(-1,1),new t.Vector2(1,1),new t.Vector2(-2,-2),new t.Vector2(2,-2),new t.Vector2(-2,2),new t.Vector2(2,2)]}destroy(){for(let e=this._lightRenderRes.length-1;e>-1;e--)this._lightRenderRes[e]&&this._lightRenderRes[e].destroy();this._lightRenderRes.length=0}_onScreenResize(){this._lights.forEach(e=>e._transformChange()),this._occluders.forEach(e=>e._transformChange())}_sceneTransformChange(){}addRender(e){const t=e.layer;this._spriteNumInLayer[t]++,1===this._spriteNumInLayer[t]&&this._spriteLayer.push(t)}removeRender(e){const t=e.layer;this._spriteNumInLayer[t]--,0===this._spriteNumInLayer[t]&&this._spriteLayer.splice(this._spriteLayer.indexOf(t),1)}Init(e){}update(e){}_printTextureToConsoleAsBase64(e){t.Utils.uint8ArrayToArrayBufferAsync(e).then(e=>console.log(e))}_lightTransformChange(e){this.needCheckLightRange(e),L.DEBUG&&console.log("light transform change",e)}_checkLightRange(e){const t=e.layers;for(let i=t.length-1;i>-1;i--){const s=t[i];if(!e._isInRange(this._screenSchmitt)){const e=1<<s;this.needCollectLightInLayer(e),this._updateLayerLight[s]=!0}}}needCheckLightRange(e){this._lightsNeedCheckRange.indexOf(e)<0&&this._lightsNeedCheckRange.push(e)}needCollectLightInLayer(e){this._needCollectLightInLayer|=e}needCollectOccluderInLight(e){this._needCollectOccluderInLight|=e}lightLayerMaskChange(e,t,i){var s;if(-1!==this._lights.indexOf(e)){for(let h=0;h<L.MAX_LAYER;h++){const n=1<<h,r=null===(s=this._lightsInLayerAll[h])||void 0===s?void 0:s.indexOf(e);i&n?void 0!==r&&-1!==r||(this._lightsInLayerAll[h]||(this._lightsInLayerAll[h]=[]),this._lightsInLayerAll[h].push(e),-1===this._lightLayerAll.indexOf(h)&&this._lightLayerAll.push(h),this._collectLightInScreenByLayer(h),this._updateLayerLight[h]=!0):t&n&&r>=0&&(this._lightsInLayerAll[h].splice(r,1),0===this._lightsInLayerAll[h].length&&this._lightLayerAll.splice(this._lightLayerAll.indexOf(h),1),this._collectLightInScreenByLayer(h),this._updateLayerLight[h]=!0)}L.DEBUG&&console.log("light layer mask change",e,t,i)}}lightShadowLayerMaskChange(e,t,i){this.needCollectOccluderInLight(t|i),L.DEBUG&&console.log("light shadow layer mask change",e,t,i)}lightShadowPCFChange(e){this._updateLightPCF(e),L.DEBUG&&console.log("light shadow pcf change",e)}lightShadowEnableChange(e){const t=e.layers;for(let i=t.length-1;i>-1;i--)this._lightRenderRes[t[i]]&&this._lightRenderRes[t[i]].enableShadow(e,this._needToRecover)}lightRenderOrderChange(e){const t=e.layers;for(let e=t.length-1;e>-1;e--)this._collectLightInScreenByLayer(t[e])}clearLight(){this._lights.length=0,this._lightLayerAll.length=0,this._lightsInLayerAll.length=0,this._lightsNeedCheckRange.length=0}addLight(e){if(-1===this._lights.indexOf(e)){this._lights.push(e);const t=e.layers;for(let i=t.length-1;i>-1;i--){const s=t[i];this._lightsInLayerAll[s]||(this._lightsInLayerAll[s]=[]),this._lightsInLayerAll[s].push(e),-1===this._lightLayerAll.indexOf(s)&&this._lightLayerAll.push(s),this._collectLightInScreenByLayer(s)}L.DEBUG&&console.log("add light",e)}}removeLight(e){const t=this._lights.indexOf(e);if(t>=0){this._lights.splice(t,1);const i=e.layers;for(let t=i.length-1;t>-1;t--){const s=i[t],h=this._lightsInLayerAll[s].indexOf(e);h>=0&&(this._lightsInLayerAll[s].splice(h,1),0===this._lightsInLayerAll[s].length&&this._lightLayerAll.splice(this._lightLayerAll.indexOf(s),1),this._collectLightInScreenByLayer(s),this.lsTarget[s]&&(this._updateLayerLight[s]=!0))}this._lightsNeedCheckRange.splice(this._lightsNeedCheckRange.indexOf(e),1),L.DEBUG&&console.log("remove light",e)}}clearOccluder(){for(let e=this._occluders.length-1;e>-1;e--)this._needCollectOccluderInLight|=this._occluders[e].layerMask;this._occluders.length=0;for(let e=this._occluderLayer.length-1;e>-1;e--)this._occludersInLayer[this._occluderLayer[e]].length=0;this._occluderLayer.length=0}addOccluder(e){if(-1===this._occluders.indexOf(e)){this._occluders.push(e);const t=e.layers;for(let i=t.length-1;i>-1;i--){const s=t[i];this._occludersInLayer[s]||(this._occludersInLayer[s]=[]),this._occludersInLayer[s].push(e),-1===this._occluderLayer.indexOf(s)&&this._occluderLayer.push(s)}this._needCollectOccluderInLight|=e.layerMask,L.DEBUG&&console.log("add occluder",e)}}removeOccluder(e){const t=this._occluders.indexOf(e);if(t>=0){this._occluders.splice(t,1);const i=e.layers;for(let t=i.length-1;t>-1;t--){const s=i[t],h=this._occludersInLayer[s].indexOf(e);h>=0&&(this._occludersInLayer[s].splice(h,1),0===this._occludersInLayer[s].length&&this._occluderLayer.splice(this._occluderLayer.indexOf(s),1))}this._needCollectOccluderInLight|=e.layerMask,L.DEBUG&&console.log("remove occluder",e)}}occluderLayerMaskChange(e,t,i){var s;if(-1!==this._occluders.indexOf(e)){for(let h=0;h<L.MAX_LAYER;h++){const n=1<<h,r=null===(s=this._occludersInLayer[h])||void 0===s?void 0:s.indexOf(e);i&n?void 0!==r&&-1!==r||(this._occludersInLayer[h]||(this._occludersInLayer[h]=[]),this._occludersInLayer[h].push(e),-1===this._occluderLayer.indexOf(h)&&this._occluderLayer.push(h)):t&n&&r>=0&&(this._occludersInLayer[h].splice(r,1),0===this._occludersInLayer[h].length&&this._occluderLayer.splice(this._occluderLayer.indexOf(h),1))}this._needCollectOccluderInLight|=t,this._needCollectOccluderInLight|=i,L.DEBUG&&console.log("occluder layer change",e,t,i)}}_buildRenderTexture(e,i){e=L.clampRTSize(e),i=L.clampRTSize(i);const s=new t.RenderTexture(e,i,t.RenderTargetFormat.R8G8B8A8,null,!1,this.config.multiSamples);return s.wrapModeU=s.wrapModeV=t.WrapMode.Clamp,s.lock=!0,s}_collectLightInScreenByLayer(i){let s=this._lightsInLayer[i];const h=this._lightsInLayerAll[i],n=this._lightSceneModeNum[i];if(s?s.length=0:s=this._lightsInLayer[i]=[],!h||0===h.length){const e=this._lightLayer.indexOf(i);return e>=0&&this._lightLayer.splice(e,1),void this._updateLayerRenderRes(i)}if(0===this._screenSchmitt.width||0===this._screenSchmitt.height)return;for(let e=h.length-1;e>-1;e--)h[e]._isInScreen(this._screenSchmitt)&&(s.push(h[e]),-1===this._lightLayer.indexOf(i)&&this._lightLayer.push(i));if(0===s.length){const e=this._lightLayer.indexOf(i);return e>=0&&this._lightLayer.splice(e,1),void this._updateLayerRenderRes(i)}if(L.SUPPORT_LIGHT_SCENE_MODE){for(let e=0;e<3;e++)n[e]=0;for(let e=s.length-1;e>-1;e--)n[s[e].sceneMode]++}L.SUPPORT_LIGHT_BLEND_MODE&&s.sort((e,t)=>e.order-t.order);const r=this._param[i],a=this.lsTarget[i],o=this._screenSchmitt.x,l=this._screenSchmitt.y,d=this._screenSchmitt.width,_=this._screenSchmitt.height;if(a?r.z!=d||r.w!=_?(this._needToRecover.push(a),r.setValue(o,l,d,_),this.lsTarget[i]=this._buildRenderTexture(d,_),L.DEBUG&&console.log("update light layer texture",o,l,d,_,i)):(r.x=o,r.y=l):(this._param[i]=new t.Vector4(o,l,d,_),this.lsTarget[i]=this._buildRenderTexture(d,_),L.DEBUG&&console.log("create light layer texture",o,l,d,_,i)),L.SUPPORT_LIGHT_SCENE_MODE){const t=this.lsTargetAdd[i],s=this.lsTargetSub[i];n[e.Light2DMode.Add]>0&&(t?t.width==d&&t.height==_||this._needToRecover.push(t):this.lsTargetAdd[i]=this._buildRenderTexture(d,_),this.lsTargetAdd[i]=this._buildRenderTexture(d,_)),n[e.Light2DMode.Sub]>0&&(s?s.width==d&&s.height==_||this._needToRecover.push(s):this.lsTargetSub[i]=this._buildRenderTexture(d,_),this.lsTargetSub[i]=this._buildRenderTexture(d,_))}for(let e=s.length-1;e>-1;e--)this._collectOccludersInLight(i,s[e],e);this._needCollectOccluderInLight&=~(1<<i),this._updateLayerRenderRes(i),this._updateMark[i]++,L.DEBUG&&console.log("collect light in screen by layer",i)}_updateLayerRenderRes(e){this._lightRenderRes[e]||(this._lightRenderRes[e]=new s(this._scene,e,!1)),this._lightRenderRes[e].addLights(this._lightsInLayer[e],this._needToRecover),this._needUpdateLightRes|=1<<e,L.REUSE_CMD&&(this._lightRenderRes[e].setRenderTargetCMD(this.lsTarget[e],this.lsTargetAdd[e],this.lsTargetSub[e]),this._lightRenderRes[e].buildRenderMeshCMD()),L.DEBUG&&console.log("update layer render res",e)}_updateLightPCF(e){const t=e.layers;for(let i=t.length-1;i>-1;i--){const s=t[i];this._lightRenderRes[s]&&this._lightRenderRes[s].updateLightPCF(e)}}_getOccluderSegment(e,i,s,n,r,a){const o=r.x,l=r.y,d=r.width,_=r.height,c=this._segments;if(c.length>=4)for(let e=0;e<4;e++)t.Pool.recover("LightLine2D",c[e]);if(c.length=0,c.push(t.Pool.getItemByClass("LightLine2D",h).create(o,l,o+d,l)),c.push(t.Pool.getItemByClass("LightLine2D",h).create(o+d,l,o+d,l+_)),c.push(t.Pool.getItemByClass("LightLine2D",h).create(o+d,l+_,o,l+_)),c.push(t.Pool.getItemByClass("LightLine2D",h).create(o,l+_,o,l)),a&&this._occludersInLight[e]){const t=this._occludersInLight[e][i];if(t)for(let e=t.length-1;e>-1;e--){const i=t[e];i.selectByLight(s,n)&&c.push(...i.getSegment(s,n))}}return L.DEBUG&&console.log("get occluder segment",e),c}_collectOccludersInLight(t,i,s){const h=this._occludersInLayer[t];if(h){this._occludersInLight[t]||(this._occludersInLight[t]=[]),this._occludersInLight[t][s]||(this._occludersInLight[t][s]=[]);const n=this._occludersInLight[t][s];if(n.length=0,i.shadowLayerMask&1<<t){const t=i.getLightType()==e.Light2DType.Direction?i._getShadowRange(this._screenSchmitt):i._getWorldRange(this._screenSchmitt);for(let e=h.length-1;e>-1;e--)h[e].isInLightRange(t)&&n.push(h[e])}}}_recoverResource(){if(t.ILaya.timer.currFrame>this._recoverFC){if(this._needToRecover.length>0){for(let e=this._needToRecover.length-1;e>-1;e--)this._needToRecover[e].destroy();this._needToRecover.length=0}this._recoverFC=t.ILaya.timer.currFrame+10}}preRenderUpdate(){const e=this.config.changeCount;if(this._configChangeCount!==e){this._configChangeCount=e;for(let e=this._updateMark.length-1;e>-1;e--)this._updateMark[e]++}this._sceneTransformChange();const t=e=>e._needUpdateLightAndShadow,i=(e,t)=>{if(this._occludersInLight[e]&&this._occludersInLight[e][t]){const i=this._occludersInLight[e][t];for(let e=i.length-1;e>-1;e--)if(i[e].needUpdate)return!0}return!1};if(this._recoverResource(),!this._updateScreen())return;if(this._screenSchmittChange)for(let e=this._lightLayerAll.length-1;e>-1;e--){const t=this._lightLayerAll[e];this._collectLightInScreenByLayer(t)}else if(0!==this._needCollectLightInLayer)for(let e=this._lightLayerAll.length-1;e>-1;e--){const t=this._lightLayerAll[e];this._needCollectLightInLayer&1<<t&&this._collectLightInScreenByLayer(t)}if(0!==this._needCollectOccluderInLight)for(let e=this._lightLayerAll.length-1;e>-1;e--){const t=this._lightLayerAll[e];if(this._needCollectOccluderInLight&1<<t){const e=this._lightsInLayer[t];for(let i=e.length-1;i>-1;i--)this._collectOccludersInLight(t,e[i],i)}}for(let e=this._lightsNeedCheckRange.length-1;e>-1;e--)this._checkLightRange(this._lightsNeedCheckRange[e]);this._lightsNeedCheckRange.length=0;let s=0,h=0;for(let e=this._lightLayer.length-1;e>-1;e--){let n=!1;const r=this._lightLayer[e],a=this._lightRenderRes[r],o=this._occludersInLayer[r],l=1<<r,d=this._screenSchmitt.x,_=this._screenSchmitt.y;if(0===this._spriteNumInLayer[r])continue;if(h|=l,o)for(let e=o.length-1;e>-1;e--)o[e]._getRange();let c=!1,g=!1,u=!1;(this._screenSchmittChange||(this._needCollectLightInLayer&l)>0||(this._needCollectOccluderInLight&l)>0||(this._needUpdateLightRes&l)>0)&&(g=!0),this._updateLayerLight[r]&&(this._updateLayerLight[r]=!1,g=!0);const y=this._lightsInLayer[r];for(let e=0,h=y.length;e<h;e++){const h=y[e],o=a.lightMeshs[e],S=a.shadowMeshs[e],R=a.material[e],D=a.materialShadow[e];if(h.getGlobalPos(this._lightScenePos),h.renderLightTexture(),g||(c=t(h),u=i(r,e)),g||u||c){for(let t=o.length-1;t>-1;t--)a.updateLightMesh(this._update(r,d,_,h,o[t],t,e),e,t),s++;a.setMaterialData(h,R,!1),a.textures[e]=h._texLight,h.shadowLayerMask&l?h._isNeedShadowMesh()?D&&(a.setMaterialData(h,D,!0),a.updateShadowMesh(this._updateShadow(r,d,_,h,S,e),e),s++):a.updateShadowMesh(null,e):S&&(L.REUSE_MESH||this._needToRecover.push(S),a.shadowMeshs[e]=null),n=!0}c=!1,u=!1}n&&(L.REUSE_CMD&&a.updateMaterial(),a.render(this.lsTarget[r],this.lsTargetAdd[r],this.lsTargetSub[r]))}let n=0;for(let e=0;e<L.MAX_LAYER;e++)if(this._updateLayerLight[e]&&-1===this._lightLayer.indexOf(e)){const t=this._lightRenderRes[e];t&&((this._needUpdateLightRes&1<<e||t.lights.length>0)&&(t.addLights([],this._needToRecover),L.REUSE_CMD&&(t.setRenderTargetCMD(this.lsTarget[e],this.lsTargetAdd[e],this.lsTargetSub[e]),t.buildRenderMeshCMD())),t.render(this.lsTarget[e],this.lsTargetAdd[e],this.lsTargetSub[e]),this._updateMark[e]++,n|=1<<e),this._updateLayerLight[e]=!1}for(let e=this._lightLayer.length-1;e>-1;e--){const t=this._lightLayer[e];if(h&1<<t){const e=this._lightsInLayer[t];for(let t=0,i=e.length;t<i;t++)e[t]._needUpdateLightAndShadow=!1}}for(let e=0,t=this._occluders.length;e<t;e++){const t=this._occluders[e];t.layerMask&h&&(t.needUpdate=!1)}this._screenSchmittChange=!1,this._needUpdateLightRes&=~(h|n),this._needCollectLightInLayer&=~(h|n),this._needCollectOccluderInLight&=~(h|n),L.DEBUG&&this._works!==s&&(this._works=s,console.log("works =",s))}_getLayerUpdateMark(e){return this._updateMark[e]}_updateShaderDataByLayer(e,i){i.setVector3(y.LIGHTANDSHADOW_LIGHT_DIRECTION,this.config.lightDirection),this.config.ambientLayerMask&1<<e?i.setColor(y.LIGHTANDSHADOW_AMBIENT,this.config.ambientColor):i.setColor(y.LIGHTANDSHADOW_AMBIENT,t.Color.CLEAR),this.lsTarget[e]?(i.removeDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_EMPTY),i.setTexture(y.LIGHTANDSHADOW,this.lsTarget[e])):(i.addDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_EMPTY),i.setTexture(y.LIGHTANDSHADOW,null)),this._param[e]&&i.setVector(y.LIGHTANDSHADOW_PARAM,this._param[e]),L.SUPPORT_LIGHT_SCENE_MODE&&(this.lsTargetAdd[e]?(i.hasDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_EMPTY)&&i.removeDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_EMPTY),i.addDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_ADDMODE),i.setTexture(y.LIGHTANDSHADOW_ADDMODE,this.lsTargetAdd[e])):(i.removeDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_ADDMODE),i.setTexture(y.LIGHTANDSHADOW_ADDMODE,null)),this.lsTargetSub[e]?(i.hasDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_EMPTY)&&i.removeDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_EMPTY),i.addDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_SUBMODE),i.setTexture(y.LIGHTANDSHADOW_SUBMODE,this.lsTargetSub[e])):(i.removeDefine(t.BaseRenderNode2D.SHADERDEFINE_LIGHT2D_SUBMODE),i.setTexture(y.LIGHTANDSHADOW_SUBMODE,null)))}_updateScreen(){let i=null;if(this._scene&&this._scene._area2Ds&&this._scene._area2Ds.size>0)for(const e of this._scene._area2Ds){const t=e.mainCamera;if(t){const e=t._rect;if(e&&e.y>e.x&&e.w>e.z){i=e;break}}}if(i?(this._screen.x=0|i.x,this._screen.y=0|i.z,this._screen.width=i.y-i.x|0,this._screen.height=i.w-i.z|0):(this._screen.x=0,this._screen.y=0,this._screen.width=0|t.RenderState2D.width,this._screen.height=0|t.RenderState2D.height),this._screen.width<=0||this._screen.height<=0)return!1;if(this._screen.x<this._screenSchmitt.x||this._screen.y<this._screenSchmitt.y||this._screen.x+this._screen.width>this._screenSchmitt.x+this._screenSchmitt.width||this._screen.y+this._screen.height>this._screenSchmitt.y+this._screenSchmitt.height||this._screenPrev.x!==this._screen.width||this._screenPrev.y!==this._screen.height){this._screenPrev.x=this._screen.width,this._screenPrev.y=this._screen.height,this._screenSchmitt.x=this._screen.x-L.SCREEN_SCHMITT_SIZE|0,this._screenSchmitt.y=this._screen.y-L.SCREEN_SCHMITT_SIZE|0,this._screenSchmitt.width=this._screen.width+2*L.SCREEN_SCHMITT_SIZE|0,this._screenSchmitt.height=this._screen.height+2*L.SCREEN_SCHMITT_SIZE|0,this._screenSchmittChange=!0;for(let t=this._lights.length-1;t>-1;t--)this._lights[t].getLightType()===e.Light2DType.Direction&&(this._lights[t]._needUpdateLightWorldRange=!0);L.DEBUG&&console.log("screen schmitt change")}return!0}_update(i,s,h,n,r,a,o){let l=r;const d=((t,i)=>t.getLightType()===e.Light2DType.Direction?this._screen.x+this._screen.width/2-(t.directionVector.x+this._PCF[i].x*t.shadowFilterSmooth*.01)*L.DIRECTION_LIGHT_SIZE/4:this._lightScenePos.x+this._PCF[i].x*t.shadowFilterSmooth)(n,a),_=((t,i)=>t.getLightType()===e.Light2DType.Direction?this._screen.y+this._screen.height/2-(t.directionVector.y+this._PCF[i].y*t.shadowFilterSmooth*.01)*L.DIRECTION_LIGHT_SIZE/4:this._lightScenePos.y+this._PCF[i].y*t.shadowFilterSmooth)(n,a),c=n._getLightRange(),g=n._getWorldRange(this._screenSchmitt),u=c.x,y=c.y,S=c.width,R=c.height,D=this._getOccluderSegment(i,o,d,_,g,n.shadowEnable),m=this._getLightPolygon(d,_,D),p=m.length;if(p>2){let e=0;this._points.length=2*p;for(let t=0;t<p;t++)this._points[e++]=m[t].x,this._points[e++]=m[t].y;l=this._genLightMesh(d,_,S,R,u,y,s,h,this._points,r)}for(let e=0;e<p;e++)t.Pool.recover("Vector4",m[e]);return l}_updateShadow(i,s,h,n,r,a){let o=r;const l=(t=>t.getLightType()==e.Light2DType.Direction?this._screen.x+this._screen.width/2-t.directionVector.x*L.DIRECTION_LIGHT_SIZE/4:this._lightScenePos.x)(n),d=(t=>t.getLightType()==e.Light2DType.Direction?this._screen.y+this._screen.height/2-t.directionVector.y*L.DIRECTION_LIGHT_SIZE/4:this._lightScenePos.y)(n),_=n._getLightRange(),c=n._getWorldRange(this._screenSchmitt),g=_.x,u=_.y,y=_.width,S=_.height,R=this._getOccluderSegment(i,a,l,d,c,n.shadowEnable),D=this._getLightPolygon(l,d,R),m=D.length;if(m>2){let e=0;this._points.length=2*m;for(let t=0;t<m;t++)this._points[e++]=D[t].x,this._points[e++]=D[t].y;const t=Math.sqrt(c.width**2+c.height**2)+10;o=this._genShadowMesh(l,d,y,S,g,u,s,h,this._points,t,r)}for(let e=0;e<m;e++)t.Pool.recover("Vector4",D[e]);return o}_makeOrUpdateMesh(e,i,s){if(s){const t=s.getIndices(),h=s.getVertices()[0];if(L.REUSE_MESH&&t.length>=i.length&&h.byteLength>=e.byteLength)return s.setIndices(i),s.setVertexByIndex(e.buffer,0),s.getSubMesh(0).clearRenderParams(),s.getSubMesh(0).setDrawElemenParams(i.length,0),s;this._needToRecover.push(s)}const h=t.VertexMesh2D.getVertexDeclaration(["POSITION,UV"],!1)[0];return t.Mesh2D.createMesh2DByPrimitive([e],[h],i,t.IndexFormat.UInt16,[{length:i.length,start:0}],!0)}_genLightMesh(e,t,i,s,h,n,r,a,o,l){const d=new Float32Array(5*(o.length/2+1)),_=new Uint16Array(o.length/2*3),c=h+i/2,g=n+s/2;d[0]=e-r,d[1]=t-a,d[2]=0,d[3]=.5-(c-e)/i,d[4]=.5-(g-t)/s;let u=5;for(let e=0;e<o.length;e+=2)d[u++]=o[e+0]-r,d[u++]=o[e+1]-a,d[u++]=0,d[u++]=.5+(o[e+0]-c)/i,d[u++]=.5+(o[e+1]-g)/s;u=0;for(let e=0;e<o.length-2;e+=2)_[u++]=0,_[u++]=e/2+1,_[u++]=e/2+2;return _[u++]=0,_[u++]=1,_[u++]=o.length/2,this._makeOrUpdateMesh(d,_,l)}_genShadowMesh(e,t,i,s,h,n,r,a,o,l,d){const _=[],c=[],g=o.length,u=h+i/2,L=n+s/2;let y=0,S=0,R=0,D=0,m=0,p=0,f=0;const M=()=>{m=y-e,p=S-t,f=Math.sqrt(m*m+p*p),R=e+m/f*l,D=t+p/f*l};for(let e=0;e<g;e+=2)y=o[e],S=o[e+1],M(),_.push(y,S,R,D);let w=0,I=0;const T=g/2;for(let e=0;e<T;e++)w=2*e,I=(e+1)%T*2,c.push(w,w+1,I),c.push(w+1,I+1,I);const E=new Float32Array(_.length/2*5),x=new Uint16Array(c.length);x.set(c);let A=0;for(let e=0,t=_.length;e<t;e+=2)E[A++]=_[e+0]-r,E[A++]=_[e+1]-a,E[A++]=0,E[A++]=.5+(_[e+0]-u)/i,E[A++]=.5+(_[e+1]-L)/s;return this._makeOrUpdateMesh(E,x,d)}_getIntersection(e,t,i){const s=e.a.x,h=e.a.y,n=e.b.x-e.a.x,r=e.b.y-e.a.y,a=t.a.x,o=t.a.y,l=t.b.x-t.a.x,d=t.b.y-t.a.y,_=Math.sqrt(n*n+r*r),c=Math.sqrt(l*l+d*d);if(n/_===l/c&&r/_===d/c)return!1;const g=(n*(o-h)+r*(s-a))/(l*r-d*n),u=(a+l*g-s)/n;return!(u<0)&&(!(g<0||g>1)&&(i.x=s+n*u,i.y=h+r*u,i.z=u,i.w=0,!0))}_getLightPolygon(e,i,s){const n=[];for(let e=0,t=s.length;e<t;e++)n.push(s[e].a,s[e].b);const r=(e=>{const t={};return e.filter(e=>{const i=e.x+","+e.y;return!(i in t)&&(t[i]=!0,!0)})})(n),a=[];for(let t=0,s=r.length;t<s;t++){const s=r[t],h=Math.atan2(s.y-i,s.x-e);a.push(h-1e-4,h,h+1e-4)}const o=t.Pool.getItemByClass("LightLine2D",h).create(0,0,0,0),l=t.Pool.getItemByClass("Vector4",t.Vector4);let d=[];for(let h=0,n=a.length;h<n;h++){const n=a[h],r=Math.cos(n),_=Math.sin(n);let c;o.a.x=e,o.a.y=i,o.b.x=e+r,o.b.y=i+_;for(let e=0,i=s.length;e<i;e++)this._getIntersection(o,s[e],l)&&(c?l.z<c.z&&c.setValue(l.x,l.y,l.z,l.w):(c=t.Pool.getItemByClass("Vector4",t.Vector4),l.cloneTo(c)));c&&(c.w=n,d.push(c))}return t.Pool.recover("LightLine2D",o),t.Pool.recover("Vector4",l),d=d.sort((e,t)=>e.w-t.w),d}}L._managerName="Light2DManager",L.MAX_LAYER=32,L.SCREEN_SCHMITT_SIZE=200,L.DIRECTION_LIGHT_SIZE=2e4,L.REUSE_CMD=!0,L.REUSE_MESH=!0,L.DEBUG=!1,L.SUPPORT_LIGHT_BLEND_MODE=!0,L.SUPPORT_LIGHT_SCENE_MODE=!0,L._config=new i,t.Scene.regManager(L._managerName,L),t.Laya.addInitCallback(u.__init__),e.Light2DType=void 0,(d=e.Light2DType||(e.Light2DType={}))[d.Base=0]="Base",d[d.Spot=1]="Spot",d[d.Sprite=2]="Sprite",d[d.Freeform=3]="Freeform",d[d.Direction=4]="Direction",e.Light2DMode=void 0,(_=e.Light2DMode||(e.Light2DMode={}))[_.Add=0]="Add",_[_.Sub=1]="Sub",_[_.Mul=2]="Mul",_[_.Mix=3]="Mix",e.ShadowFilterType=void 0,(c=e.ShadowFilterType||(e.ShadowFilterType={}))[c.None=0]="None",c[c.PCF5=1]="PCF5",c[c.PCF9=2]="PCF9",c[c.PCF13=3]="PCF13";class y extends t.Component{static __init__(){y.LIGHTANDSHADOW=t.Shader3D.propertyNameToID("u_LightAndShadow2D"),y.LIGHTANDSHADOW_ADDMODE=t.Shader3D.propertyNameToID("u_LightAndShadow2D_AddMode"),y.LIGHTANDSHADOW_SUBMODE=t.Shader3D.propertyNameToID("u_LightAndShadow2D_SubMode"),y.LIGHTANDSHADOW_LIGHT_DIRECTION=t.Shader3D.propertyNameToID("u_LightDirection"),y.LIGHTANDSHADOW_PARAM=t.Shader3D.propertyNameToID("u_LightAndShadow2DParam"),y.LIGHTANDSHADOW_AMBIENT=t.Shader3D.propertyNameToID("u_LightAndShadow2DAmbient");const e=t.LayaGL.renderDeviceFactory.createGlobalUniformMap("BaseRender2D");e.addShaderUniform(y.LIGHTANDSHADOW,"u_LightAndShadow2D",t.ShaderDataType.Texture2D),e.addShaderUniform(y.LIGHTANDSHADOW_ADDMODE,"u_LightAndShadow2D_AddMode",t.ShaderDataType.Texture2D),e.addShaderUniform(y.LIGHTANDSHADOW_SUBMODE,"u_LightAndShadow2D_SubMode",t.ShaderDataType.Texture2D),e.addShaderUniform(y.LIGHTANDSHADOW_LIGHT_DIRECTION,"u_LightDirection",t.ShaderDataType.Vector3),e.addShaderUniform(y.LIGHTANDSHADOW_PARAM,"u_LightAndShadow2DParam",t.ShaderDataType.Vector4),e.addShaderUniform(y.LIGHTANDSHADOW_AMBIENT,"u_LightAndShadow2DAmbient",t.ShaderDataType.Color)}get order(){return this._order}set order(e){this._order!==e&&(this._order=e,this._needUpdateLightAndShadow=!0,this._notifyLightOrderChange())}get lightMode(){return this._lightMode}set lightMode(e){this._lightMode!==e&&(this._lightMode=e,this._needUpdateLightAndShadow=!0)}get sceneMode(){return this._sceneMode}set sceneMode(e){this._sceneMode!==e&&(this._sceneMode=e,this._needUpdateLightAndShadow=!0)}get color(){return this._color}set color(e){e!==this._color&&e.equal(this._color)||(e.cloneTo(this._color),this._needUpdateLightAndShadow=!0)}get intensity(){return this._intensity}set intensity(e){e!==this._intensity&&(this._intensity=e,this._needUpdateLightAndShadow=!0)}get antiAlias(){return this._antiAlias}set antiAlias(e){e!==this._antiAlias&&(this._antiAlias=e,this._notifyAntiAliasChange())}get lightRotation(){return this._lightRotation}set lightRotation(e){e!==this._lightRotation&&(this._lightRotation=e,this._needUpdateLightAndShadow=!0)}get lightScale(){return this._lightScale}set lightScale(e){e!==this._lightScale&&t.Vector2.equals(e,this._lightScale)||(e.cloneTo(this._lightScale),this._needUpdateLightAndShadow=!0)}get shadowEnable(){return this._shadowEnable}set shadowEnable(e){e!==this._shadowEnable&&(this._shadowEnable=e,this._needUpdateLightAndShadow=!0,this._notifyShadowEnableChange())}get shadowColor(){return this._shadowColor}set shadowColor(e){e!==this._shadowColor&&e.equal(this._shadowColor)||(e.cloneTo(this._shadowColor),this._needUpdateLightAndShadow=!0)}get shadowStrength(){return this._shadowStrength}set shadowStrength(e){e!==this._shadowStrength&&(this._shadowStrength=e,this._needUpdateLightAndShadow=!0)}get shadowFilterType(){return this._shadowFilterType}set shadowFilterType(e){e!==this._shadowFilterType&&(this._shadowFilterType=e,this._needUpdateLightAndShadow=!0,this._notifyShadowPCFChange())}get shadowFilterSmooth(){return this._shadowFilterSmooth}set shadowFilterSmooth(e){e!==this._shadowFilterSmooth&&(this._shadowFilterSmooth=e,this._needUpdateLightAndShadow=!0,this._needUpdateLightWorldRange=!0)}get layerMask(){return this._layerMask}set layerMask(e){if(e!==this._layerMask){this._needUpdateLightAndShadow=!0,this._notifyLightLayerMaskChange(this._layerMask,e),this._layerMask=e,this._layers.length=0;for(let t=0;t<L.MAX_LAYER;t++)e&1<<t&&this._layers.push(t)}}get layers(){return this._layers}get shadowLayerMask(){return this._shadowLayerMask}set shadowLayerMask(e){e!==this._shadowLayerMask&&(this._needUpdateLightAndShadow=!0,this._notifyShadowCastLayerMaskChange(this._shadowLayerMask,e),this._shadowLayerMask=e,this._notifyShadowEnableChange())}constructor(){super(),this._type=e.Light2DType.Base,this._lightMode=e.Light2DMode.Add,this._sceneMode=e.Light2DMode.Mul,this._order=0,this._color=new t.Color(1,1,1,1),this._intensity=1,this._antiAlias=!1,this._lightRotation=0,this._lightScale=new t.Vector2(1,1),this._layerMask=1,this._layers=[0],this._shadowEnable=!1,this._shadowColor=new t.Color(0,0,0,1),this._shadowStrength=.5,this._shadowFilterSmooth=1,this._shadowLayerMask=1,this._shadowFilterType=e.ShadowFilterType.None,this._localRange=new t.Rectangle,this._worldRange=new t.Rectangle,this._lightRange=new t.Rectangle,this._recoverFC=0,this._needToRecover=[],this._inScreen=!1,this._screenCache=new t.Rectangle,this._texSize=new t.Vector2(1,1),this.showLightTexture=!1,this._needUpdateLight=!1,this._needUpdateLightAndShadow=!1,this._needUpdateLightLocalRange=!1,this._needUpdateLightWorldRange=!1,this._lightId=y.idCounter++}_notifyLightLayerMaskChange(e,t){var i,s;const h=null===(s=null===(i=this.owner)||void 0===i?void 0:i.scene)||void 0===s?void 0:s._light2DManager;h&&(h.lightLayerMaskChange(this,e,t),h.needCollectLightInLayer(t))}_notifyShadowCastLayerMaskChange(e,t){var i,s,h;null===(h=null===(s=null===(i=this.owner)||void 0===i?void 0:i.scene)||void 0===s?void 0:s._light2DManager)||void 0===h||h.lightShadowLayerMaskChange(this,e,t)}_notifyShadowPCFChange(){var e,t;const i=null===(t=null===(e=this.owner)||void 0===e?void 0:e.scene)||void 0===t?void 0:t._light2DManager;i&&(i.lightShadowPCFChange(this),i.needCollectLightInLayer(this.layerMask))}_notifyShadowEnableChange(){var e,t,i;null===(i=null===(t=null===(e=this.owner)||void 0===e?void 0:e.scene)||void 0===t?void 0:t._light2DManager)||void 0===i||i.lightShadowEnableChange(this)}_notifyLightOrderChange(){var e,t,i;L.SUPPORT_LIGHT_BLEND_MODE&&(null===(i=null===(t=null===(e=this.owner)||void 0===e?void 0:e.scene)||void 0===t?void 0:t._light2DManager)||void 0===i||i.lightRenderOrderChange(this))}_notifyAntiAliasChange(){}_onEnable(){var e,i;super._onEnable(),this.owner.on(t.Event.TRANSFORM_CHANGED,this,this._transformChange),null===(i=null===(e=this.owner.scene)||void 0===e?void 0:e._light2DManager)||void 0===i||i.addLight(this)}_onDisable(){var e,i;super._onDisable(),this._clearScreenCache(),this.owner.off(t.Event.TRANSFORM_CHANGED,this,this._transformChange),null===(i=null===(e=this.owner.scene)||void 0===e?void 0:e._light2DManager)||void 0===i||i.removeLight(this)}_onDestroy(){}_transformChange(){var e,t,i;this._clearScreenCache(),this._needUpdateLightAndShadow=!0,this._needUpdateLightWorldRange=!0,null===(i=null===(t=null===(e=this.owner)||void 0===e?void 0:e.scene)||void 0===t?void 0:t._light2DManager)||void 0===i||i._lightTransformChange(this)}_clearScreenCache(){this._screenCache.width=0,this._screenCache.height=0}_pcfIntensity(){switch(this.shadowFilterType){default:case e.ShadowFilterType.None:return 1;case e.ShadowFilterType.PCF5:return.2;case e.ShadowFilterType.PCF9:return 1/9;case e.ShadowFilterType.PCF13:return 1/13}}_getLocalRange(){return this._needUpdateLightLocalRange&&this._calcLocalRange(),this._localRange}_getWorldRange(e){return this._needUpdateLightLocalRange&&this._calcLocalRange(),this._needUpdateLightWorldRange&&this._calcWorldRange(e),this._worldRange}_getLightRange(e){return this._needUpdateLightLocalRange&&this._calcLocalRange(),this._needUpdateLightWorldRange&&this._calcWorldRange(e),this._lightRange}_getTextureSize(){return this._texLight&&(this._texSize.x=this._texLight.width,this._texSize.y=this._texLight.height),this._texSize}_isNeedShadowMesh(){return(!this._shadowColor.equal(t.Color.BLACK)||this._shadowStrength<1)&&this.shadowEnable}_rectContain(e,t){return t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height}getLightType(){return this._type}getGlobalPosX(){return this.owner.globalTrans.x}getGlobalPosY(){return this.owner.globalTrans.y}getGlobalPos(e){return this.owner.globalTrans.getPos(e),e}setLayerMaskByList(e){let t=0;for(let i=e.length-1;i>-1;i--)t|=1<<e[i];this.layerMask=t}isLayerEnable(e){return this.layerMask&1<<e}setShadowLayerMaskByList(e){let t=0;for(let i=e.length-1;i>-1;i--)t|=1<<e[i];this.shadowLayerMask=t}isShadowLayerEnable(e){return this.shadowLayerMask&1<<e}_printTextureToConsoleAsBase64(){this._texLight&&t.Utils.uint8ArrayToArrayBufferAsync(this._texLight).then(e=>console.log(e))}_calcLocalRange(){this._needUpdateLightLocalRange=!1}_calcWorldRange(e){var t,i,s;this._needUpdateLightWorldRange=!1,null===(s=null===(i=null===(t=this.owner)||void 0===t?void 0:t.scene)||void 0===i?void 0:i._light2DManager)||void 0===s||s.needCheckLightRange(this)}_lightScaleAndRotation(){const e=this.owner.globalTrans.scaleX,i=this.owner.globalTrans.scaleY;t.Vector2.TEMP.x=1/e,t.Vector2.TEMP.y=1/i,this.lightScale=t.Vector2.TEMP,this.lightRotation=this.owner.globalTrans.getSceneRotation()*Math.PI/180}renderLightTexture(){if(t.ILaya.timer.currFrame>this._recoverFC){if(this._needToRecover.length>0){for(let e=this._needToRecover.length-1;e>-1;e--)this._needToRecover[e].destroy();this._needToRecover.length=0}this._recoverFC=t.ILaya.timer.currFrame+10}}_isInRange(e){return e&&this._rectContain(e,this._getWorldRange())}_isInScreen(e){const t=this._screenCache;return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.right===e.height||(this._inScreen=this._getWorldRange().intersects(e),e.cloneTo(t)),this._inScreen}_makeOrUpdateMesh(e,i,s,h){const n=new Float32Array(5*e.length),r=new Uint16Array(i);let a,o=0;for(let t=0,i=e.length;t<i;t++)a=e[t],n[o++]=a.x,n[o++]=a.y,n[o++]=0,n[o++]=a.z,n[o++]=0;if(s){const e=s.getIndices(),t=s.getVertices()[0];if(L.REUSE_MESH&&e.length>=r.length&&t.byteLength>=n.byteLength)return s.setIndices(r),s.setVertexByIndex(n.buffer,0),s.getSubMesh(0).clearRenderParams(),s.getSubMesh(0).setDrawElemenParams(r.length,0),s;h&&h.push(s)}const l=t.VertexMesh2D.getVertexDeclaration(["POSITION,UV"],!1)[0];return t.Mesh2D.createMesh2DByPrimitive([n],[l],r,t.IndexFormat.UInt16,[{length:r.length,start:0}],!0)}}y.idCounter=0;class S extends y{constructor(i=0){super(),this._directionAngle=0,this._directionVector=new t.Vector2(1,0),this._shadowDistance=500,this._shadowRange=new t.Rectangle,this._type=e.Light2DType.Direction,this.directionAngle=i,this._calcLocalRange()}get directionAngle(){return this._directionAngle}set directionAngle(e){e%=360,this._directionAngle!==e&&(this._directionAngle=e,this._directionVector.x=Math.cos(this._directionAngle*Math.PI/180),this._directionVector.y=Math.sin(this._directionAngle*Math.PI/180),this._needUpdateLightAndShadow=!0)}get directionVector(){return this._directionVector}set directionVector(e){const i=t.Vector2.scalarLength(e);if(i>0){const t=e.x/i,s=e.y/i;e!==this._directionVector&&this._directionVector.x===t&&this._directionVector.y===s||(this._directionAngle=180*Math.atan2(s,t)/Math.PI,this._directionVector.x=t,this._directionVector.y=s,this._needUpdateLightAndShadow=!0)}}get shadowDistance(){return this._shadowDistance}set shadowDistance(e){var t,i,s;this._shadowDistance!==e&&(this._shadowDistance=e,this._needUpdateLightAndShadow=!0,null===(s=null===(i=null===(t=this.owner)||void 0===t?void 0:t.scene)||void 0===i?void 0:i._light2DManager)||void 0===s||s.needCollectOccluderInLight(this.layerMask))}_getWorldRange(e){return e&&!this._screenCache.equals(e)&&(e.cloneTo(this._screenCache),this._calcWorldRange(e)),this._worldRange}_calcLocalRange(){super._calcLocalRange(),this._localRange.x=-L.DIRECTION_LIGHT_SIZE/2,this._localRange.y=-L.DIRECTION_LIGHT_SIZE/2,this._localRange.width=L.DIRECTION_LIGHT_SIZE,this._localRange.height=L.DIRECTION_LIGHT_SIZE}_calcWorldRange(e){super._calcWorldRange(e),this._worldRange.x=this._localRange.x+(e?0|e.x:0),this._worldRange.y=this._localRange.y+(e?0|e.y:0),this._worldRange.width=this._localRange.width,this._worldRange.height=this._localRange.height,this._lightRange.x=this._worldRange.x,this._lightRange.y=this._worldRange.x,this._lightRange.width=this._worldRange.width,this._lightRange.height=this._worldRange.height}_getShadowRange(e){return this._shadowRange.x=-this._shadowDistance/2+(e?0|e.x:0),this._shadowRange.y=-this._shadowDistance/2+(e?0|e.y:0),this._shadowRange.width=L.DIRECTION_LIGHT_SIZE,this._shadowRange.height=L.DIRECTION_LIGHT_SIZE,this._shadowRange}_isInRange(e){return!0}_isInScreen(e){return!0}}class R extends y{constructor(){super(),this._falloffRange=1,this._localCenter=new t.Vector2,this._type=e.Light2DType.Freeform,this._material=new t.Material,this._material.setShaderName("LightGen2D"),this._material.setBoolByIndex(t.Shader3D.DEPTH_WRITE,!1),this._material.setIntByIndex(t.Shader3D.DEPTH_TEST,t.RenderState.DEPTHTEST_OFF),this._material.setIntByIndex(t.Shader3D.BLEND,t.RenderState.BLEND_ENABLE_ALL),this._material.setIntByIndex(t.Shader3D.BLEND_EQUATION,t.RenderState.BLENDEQUATION_ADD),this._material.setIntByIndex(t.Shader3D.BLEND_SRC,t.RenderState.BLENDPARAM_SRC_ALPHA),this._material.setIntByIndex(t.Shader3D.BLEND_DST,t.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA),this._material.setIntByIndex(t.Shader3D.CULL,t.RenderState.CULL_NONE),this._cmdBuffer=new t.CommandBuffer2D("Light2DRender_Freeform"),this._defaultPoly()}get falloffRange(){return this._falloffRange}set falloffRange(e){this._falloffRange!==e&&(this._falloffRange=e,this._needUpdateLight=!0,this._needUpdateLightLocalRange=!0,this._needUpdateLightWorldRange=!0,this._clearScreenCache(),this._limitParam())}_defaultPoly(){if(!this._lightPolygon){const e=new n;e.addPoint(-100,-100),e.addPoint(100,-100),e.addPoint(100,100),e.addPoint(-100,100),this.polygonPoint=e}}set polygonPoint(e){var t,i,s;const h=null===(i=null===(t=this.owner)||void 0===t?void 0:t.scene)||void 0===i?void 0:i._light2DManager;e?(this._lightPolygon=e,this._globalPolygon=e.clone(),this._needUpdateLight=!0,this._needUpdateLightLocalRange=!0,this._needUpdateLightWorldRange=!0,this._clearScreenCache(),this.enabled&&(null===(s=this.owner)||void 0===s?void 0:s.activeInHierarchy)&&(null==h||h.addLight(this))):(this._lightPolygon=null,this._globalPolygon=null,null==h||h.removeLight(this)),null==h||h.needCollectLightInLayer(this.layerMask)}get polygonPoint(){return this._lightPolygon}getGlobalPosX(){return super.getGlobalPosX()+this._localCenter.x}getGlobalPosY(){return super.getGlobalPosY()+this._localCenter.y}_transformChange(){var e,t,i;this._lightPolygon&&(this._clearScreenCache(),this._needUpdateLightAndShadow=!0,this._needUpdateLightWorldRange=!0,null===(i=null===(t=null===(e=this.owner)||void 0===e?void 0:e.scene)||void 0===t?void 0:t._light2DManager)||void 0===i||i._lightTransformChange(this))}_calcLocalRange(){super._calcLocalRange();let e=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;const h=this._lightPolygon.points;for(let n=h.length-2;n>-1;n-=2){const r=h[n+0],a=h[n+1];e>r&&(e=r),i<r&&(i=r),t>a&&(t=a),s<a&&(s=a)}let n=i-e,r=s-t;const a=this._falloffRange*R.FALLOF_WIDTH,o=n+2+2*a|0,l=r+2+2*a|0;this._localCenter.x=(i+e)/2,this._localCenter.y=(s+t)/2,this._localRange.x=-o/2,this._localRange.y=-l/2,this._localRange.width=o,this._localRange.height=l}_calcWorldRange(e){super._calcWorldRange(e),this._lightScaleAndRotation();let i=this.owner.globalTrans;const s=i.getPos(t.Point.TEMP),h=s.x,n=s.y,r=i.scaleX,a=i.scaleY,o=this._localRange.x,l=this._localRange.y,d=this._localRange.width,_=this._localRange.height,c=1.2*Math.sqrt((d*r)**2+(_*a)**2)|0;this._worldRange.x=h-c/2+this._localCenter.x|0,this._worldRange.y=n-c/2+this._localCenter.y|0,this._worldRange.width=c,this._worldRange.height=c,this._lightRange.x=h+o+this._localCenter.x|0,this._lightRange.y=n+l+this._localCenter.y|0,this._lightRange.width=d,this._lightRange.height=_;const g=this._globalPolygon.points;this._lightPolygon.cloneTo(this._globalPolygon);for(let e=g.length-2;e>-1;e-=2)g[e+0]-=o+this._localCenter.x,g[e+1]-=l+this._localCenter.y}_notifyAntiAliasChange(){const e=this._getLocalRange();this._buildRenderTexture(e.width,e.height),this._needUpdateLight=!0}_buildRenderTexture(e,i){e=L.clampRTSize(e),i=L.clampRTSize(i),this._texLight&&this._texLight.destroy();const s=this._texLight=new t.RenderTexture(e,i,t.RenderTargetFormat.R8G8B8A8,null,!1,this.antiAlias?4:1);s.wrapModeU=s.wrapModeV=t.WrapMode.Clamp,this._cmdRT?this._cmdRT.renderTexture=s:this._cmdRT=t.Set2DRTCMD.create(s,!0,t.Color.CLEAR,!1),s.lock=!0}renderLightTexture(){var e;if(super.renderLightTexture(),this._needUpdateLight){this._needUpdateLight=!1;const i=this._getLocalRange(),s=L.clampRTSize(i.width),h=L.clampRTSize(i.height);if(0===s||0===h)return;this._texLight&&this._texLight instanceof t.RenderTexture?this._texLight.width===s&&this._texLight.height===h||(this._buildRenderTexture(s,h),L.DEBUG&&console.log("update freeform light texture size",s,h)):(this._buildRenderTexture(s,h),L.DEBUG&&console.log("create freeform light texture",s,h)),this._getWorldRange();const n=this._createMesh(this._falloffRange*R.FALLOF_WIDTH,8,null===(e=this._cmdMesh)||void 0===e?void 0:e.mesh,this._needToRecover);n.lock=!0,this._cmdMesh?this._cmdMesh.mesh=n:this._cmdMesh=t.DrawMesh2DCMD.create(n,t.Matrix.EMPTY,t.Texture2D.whiteTexture,t.Color.WHITE,this._material),this._cmdBuffer.addCacheCommand(this._cmdRT),this._cmdBuffer.addCacheCommand(this._cmdMesh),this._cmdBuffer.apply(!0),this._cmdBuffer.clear(!1),this._needUpdateLightAndShadow=!0,L.DEBUG&&(this.showLightTexture&&this._printTextureToConsoleAsBase64(),console.log("update freeform light texture contain"))}}_limitParam(){this._falloffRange=Math.max(Math.min(this._falloffRange,10),0)}_createMesh(e,i=8,s,h){const n=[],r=[],a=this._globalPolygon.points,o=a.length/2|0,l=new t.Vector2,d=new t.Vector2,_=(e,t,i,s,h,n)=>(i-e)*(n-t)-(s-t)*(h-e)>0,c=(e,t,i,s,h)=>{const n=i-e,r=s-t,a=Math.sqrt(n*n+r*r);h.x=r/a,h.y=-n/a},g=(e,i,s,h)=>{const n=i.x-e.x,r=i.y-e.y,a=h.x-s.x,o=h.y-s.y,l=n*o-r*a;if(Math.abs(l)<Number.EPSILON)return null;const d=((s.x-e.x)*o-(s.y-e.y)*a)/l,_=((s.x-e.x)*r-(s.y-e.y)*n)/l;return d>=0&&d<=1&&_>=0&&_<=1?new t.Vector3(e.x+d*n,e.y+d*r,e.z):null};for(let e=0;e<o;e++)n.push(new t.Vector3(a[2*e],a[2*e+1],1));for(let s=0;s<o;s++){const h=s-1>=0?s-1:o-1,u=(s+1)%o,L=(s+2)%o;c(a[2*s],a[2*s+1],a[2*u],a[2*u+1],l),c(a[2*u],a[2*u+1],a[2*L],a[2*L+1],d);const y=n.length,S=new t.Vector3(a[2*s]+e*l.x,a[2*s+1]+e*l.y,0),R=new t.Vector3(a[2*u]+e*l.x,a[2*u+1]+e*l.y,0);if(_(a[2*s],a[2*s+1],a[2*u],a[2*u+1],a[2*L],a[2*L+1])){const o=Math.atan2(l.y,l.x);let L=Math.atan2(d.y,d.x)-o;if(L<0&&(L+=2*Math.PI),_(a[2*h],a[2*h+1],a[2*s],a[2*s+1],a[2*u],a[2*u+1]))n.push(S,R);else{c(a[2*h],a[2*h+1],a[2*s],a[2*s+1],l);let i=g(S,R,new t.Vector3(a[2*h]+e*l.x,a[2*h+1]+e*l.y,0),new t.Vector3(a[2*s]+e*l.x,a[2*s+1]+e*l.y,0));i||(i=S),n.push(i,R)}r.push(s,y,y+1),r.push(s,y+1,u);for(let s=1;s<=i;s++){const h=o+L*s/i;n.push(new t.Vector3(a[2*u+0]+e*Math.cos(h),a[2*u+1]+e*Math.sin(h),0)),r.push(u,y+s,y+s+1)}}else{const i=new t.Vector3(a[2*u]+e*d.x,a[2*u+1]+e*d.y,0),h=new t.Vector3(a[2*L]+e*d.x,a[2*L+1]+e*d.y,0);let o=g(S,R,i,h);o||(o=R),n.push(S,o,h),r.push(s,y,y+1),r.push(s,y+1,u)}}return r.push(...this._earCut(a)),this._makeOrUpdateMesh(n,r,s,h)}_earCut(e){const t=[];let i=e.length/2|0;for(let s=0;s<i;s++)t.push({x:e[2*s],y:e[2*s+1],index:s});const s=[];if(i=t.length,i<3)return s;const h=t.map((e,t)=>t);let n=i,r=0,a=n;for(;n>2;){a--,r>=n&&(r=0);const e=h[r],i=h[(r+1)%n],o=h[(r+2)%n];if(this._isEarTip(t,h,n,e,i,o)?(s.push(t[e].index,t[i].index,t[o].index),h.splice((r+1)%n,1),n--,a=n):r++,a<=0)break}return s}_isEarTip(e,t,i,s,h,n){return((e,t,i)=>(t.x-e.x)*(i.y-e.y)-(t.y-e.y)*(i.x-e.x)>=0)(e[s],e[h],e[n])&&!this._containsAnyPoint(e,t,i,e[s],e[h],e[n],[s,h,n])}_containsAnyPoint(e,t,i,s,h,n,r){const a=(e,t,i,s)=>{const h=(e,t,i)=>((t.x-e.x)*(i.y-e.y)-(t.y-e.y)*(i.x-e.x))/2,n=h(t,i,s),r=h(e,i,s),a=h(t,e,s),o=h(t,i,e);if(Math.abs(n)<Number.EPSILON)return!1;const l=r/n,d=a/n,_=o/n;return l>=0&&d>=0&&_>=0&&Math.abs(l+d+_-1)<Number.EPSILON};for(let o=0;o<i;o++){const i=t[o];if(!r.includes(i)&&a(e[i],s,h,n))return!0}return!1}_onDestroy(){super._onDestroy(),this._texLight&&(this._texLight.destroy(),this._texLight=null)}}R.FALLOF_WIDTH=100;class D extends t.Component{get layerMask(){return this._core.layerMask}set layerMask(e){this._core.layerMask=e}get canInLight(){return this._core.canInLight}set canInLight(e){this._core.canInLight=e}get outside(){return this._core.outside}set outside(e){this._core.outside=e}get polygonPoint(){return this._core.polygonPoint}set polygonPoint(e){this._core.polygonPoint=e}constructor(){super(),this._core=new r}_onEnable(){var e;super._onEnable(),this.owner.on(t.Event.TRANSFORM_CHANGED,this._core,this._core._transformChange),this._core.owner=this.owner,this._core.manager=null===(e=this.owner.scene)||void 0===e?void 0:e._light2DManager,this._core._onEnable()}_onDisable(){super._onDisable(),this.owner.off(t.Event.TRANSFORM_CHANGED,this._core,this._core._transformChange),this._core._onDisable()}}class m extends y{constructor(i=100,s=200,h=90,n=120,r=1){super(),this._falloffIntensity=1,this._type=e.Light2DType.Spot,this._innerAngle=h,this._outerAngle=n,this._innerRadius=i,this._outerRadius=s,this._falloffIntensity=r,this._needUpdateLight=!0,this._needUpdateLightLocalRange=!0,this._needUpdateLightWorldRange=!0,this._limitParam(),this._material=new t.Material,this._material.setShaderName("LightGen2D"),this._material.setBoolByIndex(t.Shader3D.DEPTH_WRITE,!1),this._material.setIntByIndex(t.Shader3D.DEPTH_TEST,t.RenderState.DEPTHTEST_OFF),this._material.setIntByIndex(t.Shader3D.BLEND,t.RenderState.BLEND_ENABLE_ALL),this._material.setIntByIndex(t.Shader3D.BLEND_EQUATION,t.RenderState.BLENDEQUATION_ADD),this._material.setIntByIndex(t.Shader3D.BLEND_SRC,t.RenderState.BLENDPARAM_ONE),this._material.setIntByIndex(t.Shader3D.BLEND_DST,t.RenderState.BLENDPARAM_ONE),this._material.setIntByIndex(t.Shader3D.CULL,t.RenderState.CULL_NONE),this._cmdBuffer=new t.CommandBuffer2D("Light2DRender_Spot")}get innerRadius(){return this._innerRadius}set innerRadius(e){this._innerRadius!==e&&(this._innerRadius=e,this._needUpdateLight=!0,this._needUpdateLightLocalRange=!0,this._needUpdateLightWorldRange=!0,super._clearScreenCache(),this._limitParam())}get outerRadius(){return this._outerRadius}set outerRadius(e){this._outerRadius!==e&&(this._outerRadius=e,this._needUpdateLight=!0,this._needUpdateLightLocalRange=!0,this._needUpdateLightWorldRange=!0,super._clearScreenCache(),this._limitParam())}get innerAngle(){return this._innerAngle}set innerAngle(e){this._innerAngle!==e&&(this._innerAngle=e,this._needUpdateLight=!0,this._limitParam())}get outerAngle(){return this._outerAngle}set outerAngle(e){this._outerAngle!==e&&(this._outerAngle=e,this._needUpdateLight=!0,this._limitParam())}get falloffIntensity(){return this._falloffIntensity}set falloffIntensity(e){this._falloffIntensity!==e&&(this._falloffIntensity=e,this._needUpdateLight=!0,this._limitParam())}_calcLocalRange(){super._calcLocalRange();const e=2.1*this._outerRadius|0,t=2.1*this._outerRadius|0;this._localRange.x=-e/2,this._localRange.y=-t/2,this._localRange.width=e,this._localRange.height=t}_calcWorldRange(e){super._calcWorldRange(e),this._lightScaleAndRotation();let i=this.owner.globalTrans;const s=i.getPos(t.Point.TEMP),h=s.x,n=s.y,r=i.scaleX,a=i.scaleY,o=this._localRange.x,l=this._localRange.y,d=this._localRange.width,_=this._localRange.height,c=0|Math.max(d*r,_*a);this._worldRange.x=h-c/2|0,this._worldRange.y=n-c/2|0,this._worldRange.width=c,this._worldRange.height=c,this._lightRange.x=h+o|0,this._lightRange.y=n+l|0,this._lightRange.width=d,this._lightRange.height=_}_notifyAntiAliasChange(){const e=this._getLocalRange();this._buildRenderTexture(e.width,e.height),this._needUpdateLight=!0}_buildRenderTexture(e,i){e=L.clampRTSize(e),i=L.clampRTSize(i),this._texLight&&this._texLight.destroy();const s=this._texLight=new t.RenderTexture(e,i,t.RenderTargetFormat.R8G8B8A8,null,!1,this.antiAlias?4:1);s.wrapModeU=s.wrapModeV=t.WrapMode.Clamp,this._cmdRT?this._cmdRT.renderTexture=s:this._cmdRT=t.Set2DRTCMD.create(s,!0,t.Color.CLEAR,!1),s.lock=!0}renderLightTexture(){var e;if(super.renderLightTexture(),this._needUpdateLight){this._needUpdateLight=!1;const i=this._getLocalRange(),s=L.clampRTSize(i.width),h=L.clampRTSize(i.height);if(0===s||0===h)return;this._texLight&&this._texLight instanceof t.RenderTexture?this._texLight.width===s&&this._texLight.height===h||(this._buildRenderTexture(s,h),L.DEBUG&&console.log("update spot light texture",s,h)):(this._buildRenderTexture(s,h),L.DEBUG&&console.log("create spot light texture",s,h));const n=this._createMesh(null===(e=this._cmdMesh)||void 0===e?void 0:e.mesh,this._needToRecover);this._cmdMesh?this._cmdMesh.mesh=n:this._cmdMesh=t.DrawMesh2DCMD.create(n,t.Matrix.EMPTY,t.Texture2D.whiteTexture,t.Color.WHITE,this._material),n.lock=!0,this._cmdBuffer.addCacheCommand(this._cmdRT),this._cmdBuffer.addCacheCommand(this._cmdMesh),this._cmdBuffer.apply(!0),this._cmdBuffer.clear(!1),this._needUpdateLightAndShadow=!0,L.DEBUG&&(this.showLightTexture&&this._printTextureToConsoleAsBase64(),console.log("update spot light texture contain"))}}_limitParam(){this._innerAngle=Math.max(Math.min(this._innerAngle,360),0),this._outerAngle=Math.max(Math.min(this._outerAngle,360),0),this._innerRadius=Math.max(Math.min(this._innerRadius,1e4),1),this._outerRadius=Math.max(Math.min(this._outerRadius,1e4),1),this._falloffIntensity=Math.max(Math.min(this._falloffIntensity,10),0),this._outerRadius<this._innerRadius&&(this._outerRadius=this._innerRadius),this._outerAngle<this._innerAngle&&(this._outerAngle=this._innerAngle)}_createMesh(e,i){const s=Math.max(4,Math.min(64,this._innerAngle/5|0)),h=Math.max(2,Math.min(64,(this._outerAngle-this._innerAngle)/10|0)),n=10,r=[],a=[],o=this._getLightRange(),l=o.width/2,d=o.height/2,_=this._innerAngle*Math.PI/180,c=this._outerAngle*Math.PI/180,g=-Math.PI/2,u=(e,i,s,h,o)=>{let _=r.length;r.push(new t.Vector3(l,d,1));let c=o+1,g=(h-s)/o,u=(i-e)/o,L=(this._outerRadius-this._innerRadius)/n,y=this._innerRadius/n;for(let i=0;i<n;i++)for(let h=0;h<=o;h++){const n=e+u*h,o=0===i?1:y*(i+1),L=l+o*Math.cos(n),S=d+o*Math.sin(n),R=Math.pow(s+g*h,this._falloffIntensity);if(r.push(new t.Vector3(L,S,R)),h>0)if(0===i)a.push(_,_+h,_+h+1);else{const e=c*(i-1);a.push(_+h+e,_+h+c+e,_+h+c+e+1),a.push(_+h+e,_+h+c+e+1,_+h+e+1)}}_+=9*c;for(let i=0;i<n;i++)for(let h=0;h<=o;h++){const o=e+u*h,y=l+(this._innerRadius+L*(i+1))*Math.cos(o),S=d+(this._innerRadius+L*(i+1))*Math.sin(o),R=Math.pow(s+g*h,this._falloffIntensity)*Math.pow(1-(i+1)/n,this._falloffIntensity);if(r.push(new t.Vector3(y,S,R)),h>0){const e=c*i;a.push(_+h+e,_+h+c+e,_+h+c+e+1),a.push(_+h+e,_+h+c+e+1,_+h+e+1)}}};return u(-c/2+g,-_/2+g,0,1,h),u(-_/2+g,_/2+g,1,1,s),u(_/2+g,c/2+g,1,0,h),this._makeOrUpdateMesh(r,a,e,i)}_onDestroy(){super._onDestroy(),this._texLight&&(this._texLight.destroy(),this._texLight=null)}}class p extends y{constructor(){super(),this._type=e.Light2DType.Sprite}set spriteTexture(e){this._texLight!==e&&(this._texLight&&this._texLight._removeReference(1),this._texLight=e,e&&this._texLight._addReference(1),this._needUpdateLight=!0,this._needUpdateLightLocalRange=!0,this._needUpdateLightWorldRange=!0,super._clearScreenCache())}get spriteTexture(){return this._texLight}_calcLocalRange(){super._calcLocalRange();const e=0|(this._texLight?this._texLight.width:100),t=0|(this._texLight?this._texLight.height:100);this._localRange.x=-e/2,this._localRange.y=-t/2,this._localRange.width=e,this._localRange.height=t}_calcWorldRange(e){super._calcWorldRange(e),this._lightScaleAndRotation();let i=this.owner.globalTrans;const s=i.getPos(t.Point.TEMP),h=s.x,n=s.y,r=i.scaleX,a=i.scaleY,o=this._localRange.x,l=this._localRange.y,d=this._localRange.width,_=this._localRange.height,c=0|Math.max(d*r,_*a);this._worldRange.x=h-c/2|0,this._worldRange.y=n-c/2|0,this._worldRange.width=c,this._worldRange.height=c,this._lightRange.x=h+o|0,this._lightRange.y=n+l|0,this._lightRange.width=d,this._lightRange.height=_}renderLightTexture(){super.renderLightTexture(),this._needUpdateLight&&(this._needUpdateLight=!1,this._needUpdateLightAndShadow=!0,L.DEBUG&&console.log("update sprite light texture"))}_onDestroy(){super._onDestroy(),this._texLight&&(this._texLight._removeReference(1),this._texLight=null)}}let f=t.ClassUtils.regClass;f("BaseLight2D",y),f("DirectionLight2D",S),f("SpriteLight2D",p),f("FreeformLight2D",R),f("SpotLight2D",m),f("LightOccluder2D",D),f("PolygonPoint2D",n);e.BaseLight2D=y,e.DirectionLight2D=S,e.FreeformLight2D=R,e.Light2DConfig=i,e.Light2DManager=L,e.Light2DRenderRes=s,e.LightAndShadow=u,e.LightAndShadowGenShader2D=g,e.LightGenShader2D=o,e.LightLine2D=h,e.LightOccluder2D=D,e.LightOccluder2DCore=r,e.Occluder2DAgent=a,e.PolygonPoint2D=n,e.ShadowGenShader2D=l,e.ShowRenderTarget=class{constructor(e,i,s,h,n,r){this._sprite=e.addChild(new t.Sprite),this._render=this._sprite.addComponent(t.Mesh2DRender),this._render.lightReceive=!1,i&&(this._render.texture=i),this._render.sharedMesh=this._genMesh(s,h,n,r)}setRenderTarget(e){this._render.texture=e}_genMesh(e,i,s,h){const n=new Float32Array(20),r=new Uint16Array(6);let a=0;n[a++]=e,n[a++]=i,n[a++]=0,n[a++]=0,n[a++]=1,n[a++]=e+s,n[a++]=i,n[a++]=0,n[a++]=1,n[a++]=1,n[a++]=e+s,n[a++]=i+h,n[a++]=0,n[a++]=1,n[a++]=0,n[a++]=e,n[a++]=i+h,n[a++]=0,n[a++]=0,n[a++]=0,a=0,r[a++]=0,r[a++]=1,r[a++]=3,r[a++]=1,r[a++]=2,r[a++]=3;const o=t.VertexMesh2D.getVertexDeclaration(["POSITION,UV"],!1)[0];return t.Mesh2D.createMesh2DByPrimitive([n],[o],r,t.IndexFormat.UInt16,[{length:r.length,start:0}])}},e.SpotLight2D=m,e.SpriteLight2D=p}(window.Laya=window.Laya||{},Laya);
@@ -0,0 +1 @@
1
+ !function(e,t){"use strict";class a{static __init__(){if(a._isInit)return;a._isInit=!0;let e={a_position:[0,t.ShaderDataType.Vector3],a_linePos:[2,t.ShaderDataType.Vector4],a_linelength:[3,t.ShaderDataType.Float]},i=t.Shader3D.add("LineShader",!0,!1);i.shaderType=t.ShaderFeatureType.D2_BaseRenderNode2D;let r=new t.SubShader(e,{},{});i.addSubShader(r),r.addShaderPass('#define SHADER_NAME 2DLineVS\n#include "Sprite2DVertex.glsl"\nvarying vec2 v_position;varying vec4 v_linePionts;varying float v_lineLength;varying vec2 v_linedir;varying vec3 v_dashed;varying float v_lineWidth;uniform vec3 u_dashed;uniform float u_lineWidth;uniform float u_screenSpaceWidth;void lineMat(in vec2 left,in vec2 right,inout vec3 xDir,inout vec3 yDir,float LineWidth){vec2 dir=right-left;float lineLength=length(dir)+LineWidth+2.0;dir=normalize(dir);xDir.x=dir.x*lineLength;yDir.x=dir.y*lineLength;float lineWidth=LineWidth+2.0;xDir.y=-dir.y*LineWidth;yDir.y=dir.x*LineWidth;xDir.z=(left.x+right.x)*0.5;yDir.z=(left.y+right.y)*0.5;}void main(){vec2 oriUV=(a_position.xy+vec2(0.5,0.5));oriUV.x=(oriUV.x*length(a_linePos.xy-a_linePos.zw)+a_linelength)/50.0;v_texcoord=oriUV;vec2 left,right;getGlobalPos(a_linePos.xy,left);getGlobalPos(a_linePos.zw,right);float lengthScale=length(right-left)/length(a_linePos.zw-a_linePos.xy);v_lineLength=a_linelength*lengthScale;v_dashed=vec3(u_dashed.x*lengthScale,u_dashed.y,u_dashed.z*lengthScale);v_linePionts=vec4(left,right);float lineWidth=u_lineWidth*mix(lengthScale,1.0,u_screenSpaceWidth);v_lineWidth=lineWidth;v_linedir=normalize(right-left)*v_lineWidth*0.5;vec3 xDir;vec3 yDir;lineMat(left,right,xDir,yDir,v_lineWidth);vec2 globalPos;transfrom(a_position.xy,xDir,yDir,globalPos);v_position=globalPos;clip(globalPos);vec2 viewPos;getViewPos(globalPos,viewPos);vec4 pos;getProjectPos(viewPos,pos);gl_Position=pos;}','#define SHADER_NAME 2DLineFS\n#include "Sprite2DFrag.glsl"\nvarying vec2 v_position;varying vec4 v_linePionts;varying float v_lineLength;varying vec2 v_linedir;varying vec3 v_dashed;varying float v_lineWidth;uniform vec4 u_TilingOffset;vec2 dotToline(in vec2 a,vec2 b,in vec2 p){vec2 pa=p-a,ba=b-a;float h=clamp(dot(pa,ba)/dot(ba,ba),0.0,1.0);return ba*h+a;}void main(){clip();vec2 p=dotToline(v_linePionts.xy,v_linePionts.zw,v_position);float d=v_lineWidth*0.5-length(p-v_position);vec2 left=v_linePionts.xy-v_linedir;vec2 p1=dotToline(left,v_linePionts.zw+v_linedir,v_position);float t=v_lineLength+length(left-p1)-v_dashed.z;d*=step(fract(t/v_dashed.x),v_dashed.y);vec2 uv=transformUV(v_texcoord.xy,u_TilingOffset);vec4 textureColor=texture2D(u_baseRender2DTexture,fract(uv));textureColor=transspaceColor(textureColor);vec4 renderColor=u_baseRenderColor;\n#ifdef GAMMASPACE\nrenderColor=linearToGamma(renderColor);\n#endif\nrenderColor.rgb*=renderColor.a;textureColor*=renderColor;float aa=min(v_lineWidth*0.5,2.0);gl_FragColor=vec4(textureColor.rgb,textureColor.a*smoothstep(0.0,aa,d));}'),a.LINEWIDTH=t.Shader3D.propertyNameToID("u_lineWidth"),a.DASHED=t.Shader3D.propertyNameToID("u_dashed"),a.TILINGOFFSET=t.Shader3D.propertyNameToID("u_TilingOffset"),a.SCREENSPACEWIDTH=t.Shader3D.propertyNameToID("u_screenSpaceWidth");const n=t.LayaGL.renderDeviceFactory.createGlobalUniformMap("Line2DRender");n.addShaderUniform(a.LINEWIDTH,"u_lineWidth",t.ShaderDataType.Float),n.addShaderUniform(a.DASHED,"u_dashed",t.ShaderDataType.Vector3),n.addShaderUniform(a.TILINGOFFSET,"u_TilingOffset",t.ShaderDataType.Vector4),n.addShaderUniform(a.SCREENSPACEWIDTH,"u_screenSpaceWidth",t.ShaderDataType.Float);let s=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),h=new Uint16Array([0,1,2,0,2,3]);var l=new t.VertexDeclaration(12,[new t.VertexElement(0,t.VertexElementFormat.Vector3,0)]);let d=a._vbs=t.LayaGL.renderDeviceFactory.createVertexBuffer(t.BufferUsage.Dynamic);d.vertexDeclaration=l,d.instanceBuffer=!1,d.setDataLength(s.byteLength),d.setData(s.buffer,0,0,s.byteLength);let o=a._ibs=t.LayaGL.renderDeviceFactory.createIndexBuffer(t.BufferUsage.Dynamic);o._setIndexDataLength(h.buffer.byteLength),o._setIndexData(h,0),a.linePoisitionDesc=new t.VertexDeclaration(16,[new t.VertexElement(0,t.VertexElementFormat.Vector4,2)]),a.lineLengthDesc=new t.VertexDeclaration(4,[new t.VertexElement(0,t.VertexElementFormat.Single,3)])}}a._isInit=!1;const i=new t.Vector3(20,1,0);class r extends t.BaseRenderNode2D{static _createDefaultLineMaterial(){if(r.defaultLine2DMaterial)return;a.__init__();let e=r.defaultLine2DMaterial=new t.Material;e.lock=!0,e.setShaderName("LineShader"),e.alphaTest=!1,e.depthTest=t.RenderState.DEPTHTEST_OFF,e.cull=t.RenderState.CULL_NONE,e.blend=t.RenderState.BLEND_ENABLE_ALL,e.setIntByIndex(t.Shader3D.BLEND_SRC,t.RenderState.BLENDPARAM_SRC_ALPHA),e.setIntByIndex(t.Shader3D.BLEND_DST,t.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA)}get positions(){return this._positions}set positions(e){e.length/4==(e.length/4|0)&&(this._positions=e,this._needUpdate=!0)}get lineWidth(){return this._lineWidth}set lineWidth(e){this._lineWidth=e,this._spriteShaderData.setNumber(a.LINEWIDTH,this._lineWidth)}get screenSpaceWidth(){return this._screenSpaceWidth}set screenSpaceWidth(e){this._screenSpaceWidth=e,this._spriteShaderData.setNumber(a.SCREENSPACEWIDTH,e?1:0)}set color(e){(e=e||t.Color.BLACK).cloneTo(this._color),this._spriteShaderData.setColor(t.BaseRenderNode2D.BASERENDER2DCOLOR,this._color)}get color(){return this._color}set enableDashedMode(e){this._isdashed=e,this._updateDashValue()}get enableDashedMode(){return this._isdashed}set dashedLength(e){null!=e&&(e=Math.max(.01,e),this._dashedValue.x=e,this._updateDashValue())}get dashedLength(){return this._dashedValue.x}set dashedPercent(e){e=Math.max(Math.min(1,e),0),this._dashedValue.y=e,this._updateDashValue()}get dashedPercent(){return this._dashedValue.y}set dashedOffset(e){this._dashedValue.z=e,this._updateDashValue()}get dashedOffset(){return this._dashedValue.z}set texture(e){e||(e=t.Texture2D.whiteTexture),e!=this._baseRender2DTexture&&(this._baseRender2DTexture&&this._baseRender2DTexture._removeReference(1),e._addReference(),this._baseRender2DTexture=e,this._spriteShaderData.setTexture(t.BaseRenderNode2D.BASERENDER2DTEXTURE,e),1!=e.gammaCorrection?this._spriteShaderData.addDefine(t.ShaderDefines2D.GAMMATEXTURE):this._spriteShaderData.removeDefine(t.ShaderDefines2D.GAMMATEXTURE))}get texture(){return this._baseRender2DTexture}set tillOffset(e){null==e?this._tillOffset=new t.Vector4(0,0,1,1):e.cloneTo(this._tillOffset),this._spriteShaderData.setVector(a.TILINGOFFSET,this._tillOffset)}get tillOffset(){return this._tillOffset}get sharedMaterial(){return this._materials[0]}set sharedMaterial(e){super.sharedMaterial=e,t.BaseRenderNode2D._setRenderElement2DMaterial(this._renderElements[0],this._getElementMaterial(0))}_getElementMaterial(e){return this._materials[e]||r.defaultLine2DMaterial}_updateDashValue(){this._isdashed?this._spriteShaderData.setVector3(a.DASHED,this._dashedValue):this._spriteShaderData.setVector3(a.DASHED,i)}_isMaterialVaild(e){return e.checkType(t.ShaderFeatureType.D2_BaseRenderNode2D)}_getcommonUniformMap(){return["BaseRender2D","Line2DRender"]}_initDefaultRenderData(){this._initRender(),this._spriteShaderData.setColor(t.BaseRenderNode2D.BASERENDER2DCOLOR,this._color),this._updateDashValue(),this._spriteShaderData.setNumber(a.SCREENSPACEWIDTH,0),this.tillOffset=null,this.texture=null}_changeGeometry(){let e=this._positions.length/4;e>this._maxLineNumer&&(this._maxLineNumer=(1+(e/this._enLarge|0))*this._enLarge,this._positionInstansBufferData=new Float32Array(4*this._maxLineNumer),this._positionVertexBuffer.setDataLength(16*this._maxLineNumer),this._lineLengthBufferData=new Float32Array(1*this._maxLineNumer),this._lineLengthVertexBuffer.setDataLength(4*this._maxLineNumer),this._renderGeometry.bufferState.applyState([a._vbs,this._positionVertexBuffer,this._lineLengthVertexBuffer],a._ibs),this._renderElements[0].geometry=this._renderGeometry),this._positionInstansBufferData.set(this._positions,0),this._positionVertexBuffer.setData(this._positionInstansBufferData.buffer,0,0,this._positionInstansBufferData.byteLength);{let a=0;for(var t=0;t<e;t++){const e=4*t;this._lineLengthBufferData[t]=a,a+=Math.hypot(this._positions[e+2]-this._positions[e],this._positions[e+3]-this._positions[e+1])}this._lineLengthVertexBuffer.setData(this._lineLengthBufferData.buffer,0,0,this._lineLengthBufferData.byteLength)}this._renderGeometry.instanceCount=e}addPoint(e,t,a,i){this._positions.push(e,t,a,i),this._needUpdate=!0}clear(){this._positions.length=0,this._needUpdate=!0}onPreRender(){this._needUpdate&&(this._needUpdate=!1,this._changeGeometry())}_initRender(){let e=this._maxLineNumer,i=this._positionVertexBuffer=t.LayaGL.renderDeviceFactory.createVertexBuffer(t.BufferUsage.Dynamic);i.instanceBuffer=!0,i.vertexDeclaration=a.linePoisitionDesc,i.setDataLength(16*e),this._positionInstansBufferData=new Float32Array(4*e),i.setData(this._positionInstansBufferData.buffer,0,0,this._positionInstansBufferData.byteLength);let r=this._lineLengthVertexBuffer=t.LayaGL.renderDeviceFactory.createVertexBuffer(t.BufferUsage.Dynamic);r.instanceBuffer=!0,r.vertexDeclaration=a.lineLengthDesc,r.setDataLength(4*e),this._lineLengthBufferData=new Float32Array(1*e),r.setData(this._lineLengthBufferData.buffer,0,0,this._lineLengthBufferData.byteLength);let n=this._renderGeometry=t.LayaGL.renderDeviceFactory.createRenderGeometryElement(t.MeshTopology.Triangles,t.DrawType.DrawElementInstance);n.bufferState=t.LayaGL.renderDeviceFactory.createBufferState(),n.setDrawElemenParams(6,0),n.indexFormat=t.IndexFormat.UInt16,n.instanceCount=0;let s=[];s.push(a._vbs),s.push(this._positionVertexBuffer),s.push(this._lineLengthVertexBuffer),n.bufferState.applyState(s,a._ibs);let h=t.LayaGL.render2DRenderPassFactory.createRenderElement2D();h.geometry=this._renderGeometry,h.value2DShaderData=this._spriteShaderData,h.renderStateIsBySprite=!1,h.nodeCommonMap=this._getcommonUniformMap(),h.owner=this._struct,t.BaseRenderNode2D._setRenderElement2DMaterial(h,this._getElementMaterial(0)),this._renderElements[0]=h,this._struct.renderElements=this._renderElements}constructor(){super(),this._color=new t.Color,this._positions=[],this._isdashed=!1,this._tillOffset=new t.Vector4(0,0,1,1),this._dashedValue=new t.Vector3(20,.5,0),this._needUpdate=!1,this._maxLineNumer=200,this._enLarge=100,this._lineWidth=1,this._screenSpaceWidth=!1,r._createDefaultLineMaterial(),this._renderElements=[],this._materials=[]}}t.Laya.addInitCallback(()=>r._createDefaultLineMaterial());class n extends t.Command2D{static create(e,a,i=t.Color.WHITE,r=3,s=!1){var h=n._pool.take();return h._line2DRender.color=i,h._line2DRender.positions=e,h._line2DRender.lineWidth=r,h._line2DRender.screenSpaceWidth=s,h._needUpdateElement=!0,h._setMatrix(a),h}constructor(){super(),this._drawElementData=t.LayaGL.render2DRenderPassFactory.createDraw2DElementCMDData(),this._shaderData=t.LayaGL.renderDeviceFactory.createShaderData(),this._shaderData.addDefine(t.BaseRenderNode2D.SHADERDEFINE_BASERENDER2D),this._struct=t.LayaGL.render2DRenderPassFactory.createRenderStruct2D(),this._line2DRender=new r,this._line2DRender._struct=this._struct,this._line2DRender._spriteShaderData=this._shaderData,this._line2DRender._initRender(),this._line2DRender.tillOffset=null,this._line2DRender.texture=null,this._matrix=new t.Matrix,this._line2DRender.enableDashedMode=!1,this._drawElementData.setRenderelements(this._line2DRender._renderElements)}_setMatrix(e){e?e.copyTo(this._matrix):t.Matrix.EMPTY.copyTo(this._matrix);let a=this._matrix,i=t.Vector3.TEMP;i.x=a.a,i.y=a.c,i.z=a.tx,this._shaderData.setVector3(t.ShaderDefines2D.UNIFORM_NMATRIX_0,i),i.x=a.b,i.y=a.d,i.z=a.ty,this._shaderData.setVector3(t.ShaderDefines2D.UNIFORM_NMATRIX_1,i)}getRenderCMD(){return this._drawElementData}run(){this._line2DRender.onPreRender(),this._needUpdateElement&&(this._drawElementData.setRenderelements(this._line2DRender._renderElements),this._needUpdateElement=!1)}recover(){n._pool.recover(this),super.recover()}}n._pool=t.Pool.createPool(n),(0,t.ClassUtils.regClass)("Line2DRender",r),e.Draw2DLineCMD=n,e.Line2DRender=r,e.LineShader=a}(window.Laya=window.Laya||{},Laya);