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,3774 @@
1
+ (function (exports, Laya) {
2
+ 'use strict';
3
+
4
+ class Physics2DOption {
5
+ }
6
+ Physics2DOption.allowSleeping = false;
7
+ Physics2DOption.gravity = { x: 0, y: 9.8 };
8
+ Physics2DOption.customUpdate = false;
9
+ Physics2DOption.velocityIterations = 8;
10
+ Physics2DOption.positionIterations = 3;
11
+ Physics2DOption.pixelRatio = 50;
12
+ Physics2DOption.debugDraw = true;
13
+ Physics2DOption.drawShape = true;
14
+ Physics2DOption.drawJoint = true;
15
+ Physics2DOption.drawAABB = false;
16
+ Physics2DOption.drawCenterOfMass = false;
17
+ Physics2DOption.subStep = 1;
18
+
19
+ var PhysicsLineFs = "#define SHADER_NAME PhysicsLineFS\n#include \"Sprite2DFrag.glsl\"\nvarying vec2 v_position;varying vec4 v_linePionts;varying float v_lineLength;varying vec2 v_linedir;varying float v_lineWidth;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(){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);vec2 uv=transformUV(v_texcoord.xy,u_TilingOffset);vec4 textureColor=texture2D(u_baseRender2DTexture,fract(uv));textureColor=transspaceColor(textureColor*u_baseRenderColor);gl_FragColor=vec4(u_baseRenderColor.rgb,textureColor.a*smoothstep(0.0,2.0,d));}";
20
+
21
+ var PhysicsLineVs = "#define SHADER_NAME PhysicsLineVS\n#include \"Sprite2DVertex.glsl\"\nvarying vec2 v_position;varying vec4 v_linePionts;varying float v_lineLength;varying vec2 v_linedir;varying float v_lineWidth;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_linePionts=vec4(left,right);float lineWidth=u_lineWidth*lengthScale;v_lineWidth=lineWidth;v_linedir=normalize(right-left)*v_lineWidth*0.5;vec3 xDir;vec3 yDir;lineMat(left,right,xDir,yDir,v_lineWidth);transfrom(a_position.xy,xDir,yDir,v_position);vec2 viewPos;getViewPos(v_position,viewPos);clip(viewPos);vec4 pos;getProjectPos(viewPos,pos);gl_Position=pos;}";
22
+
23
+ class PhysicsLineShader {
24
+ static __init__() {
25
+ if (PhysicsLineShader._isInit)
26
+ return;
27
+ PhysicsLineShader._isInit = true;
28
+ let attributeMap = {
29
+ 'a_position': [0, Laya.ShaderDataType.Vector3],
30
+ 'a_linePos': [2, Laya.ShaderDataType.Vector4],
31
+ "a_linelength": [3, Laya.ShaderDataType.Float],
32
+ };
33
+ let uniformMap = {
34
+ u_lineWidth: Laya.ShaderDataType.Float,
35
+ u_TilingOffset: Laya.ShaderDataType.Vector4,
36
+ };
37
+ let shader = Laya.Shader3D.add("PhysicsLineShader", true, false);
38
+ shader.shaderType = Laya.ShaderFeatureType.D2_BaseRenderNode2D;
39
+ let subShader = new Laya.SubShader(attributeMap, uniformMap, {});
40
+ shader.addSubShader(subShader);
41
+ subShader.addShaderPass(PhysicsLineVs, PhysicsLineFs);
42
+ PhysicsLineShader.LINEWIDTH = Laya.Shader3D.propertyNameToID("u_lineWidth");
43
+ PhysicsLineShader.TILINGOFFSET = Laya.Shader3D.propertyNameToID("u_TilingOffset");
44
+ let vertexs = new Float32Array([
45
+ -0.5, -0.5, 0,
46
+ 0.5, -0.5, 0,
47
+ 0.5, 0.5, 0,
48
+ -0.5, 0.5, 0
49
+ ]);
50
+ let index = new Uint16Array([0, 1, 2, 0, 2, 3]);
51
+ var declaration = new Laya.VertexDeclaration(12, [
52
+ new Laya.VertexElement(0, Laya.VertexElementFormat.Vector3, 0),
53
+ ]);
54
+ let vertex = PhysicsLineShader._vbs = Laya.LayaGL.renderDeviceFactory.createVertexBuffer(Laya.BufferUsage.Dynamic);
55
+ vertex.vertexDeclaration = declaration;
56
+ vertex.instanceBuffer = false;
57
+ vertex.setDataLength(vertexs.byteLength);
58
+ vertex.setData(vertexs.buffer, 0, 0, vertexs.byteLength);
59
+ let ibs = PhysicsLineShader._ibs = Laya.LayaGL.renderDeviceFactory.createIndexBuffer(Laya.BufferUsage.Dynamic);
60
+ ibs._setIndexDataLength(index.buffer.byteLength);
61
+ ibs._setIndexData(index, 0);
62
+ PhysicsLineShader.linePoisitionDesc = new Laya.VertexDeclaration(16, [
63
+ new Laya.VertexElement(0, Laya.VertexElementFormat.Vector4, 2),
64
+ ]);
65
+ PhysicsLineShader.lineLengthDesc = new Laya.VertexDeclaration(4, [
66
+ new Laya.VertexElement(0, Laya.VertexElementFormat.Single, 3),
67
+ ]);
68
+ }
69
+ }
70
+ PhysicsLineShader._isInit = false;
71
+
72
+ class Physics2D extends Laya.EventDispatcher {
73
+ static get I() {
74
+ return Physics2D._I || (Physics2D._I = new Physics2D());
75
+ }
76
+ _addRigidBody(body) {
77
+ this._rigiBodyList.add(body);
78
+ }
79
+ _removeRigidBody(body) {
80
+ this._rigiBodyList.remove(body);
81
+ }
82
+ _update() {
83
+ const deltaMs = Laya.ILaya.timer.delta;
84
+ if (!Number.isFinite(deltaMs))
85
+ return;
86
+ this.update(Math.min(deltaMs / 1000, 0.033));
87
+ }
88
+ update(deltaTime) {
89
+ if (!Number.isFinite(deltaTime))
90
+ throw new Error("Physics2D.update: deltaTime must be a finite number.");
91
+ if (!this._factory || !this._rigiBodyList)
92
+ return;
93
+ this._factory.update(deltaTime);
94
+ this._updatePhysicsTransformToRender();
95
+ }
96
+ _updatePhysicsTransformToRender() {
97
+ for (var i = 0, n = this._rigiBodyList.length; i < n; i++) {
98
+ this._rigiBodyList.elements[i]._updatePhysicsTransformToRender();
99
+ }
100
+ }
101
+ enable() {
102
+ if (this._factory) {
103
+ PhysicsLineShader.__init__();
104
+ if (Laya.PlayerConfig.physics2D != null && Laya.PlayerConfig.physics2D.defaultConfig != null)
105
+ Object.assign(Physics2DOption, Laya.PlayerConfig.physics2D.defaultConfig);
106
+ return this._factory.initialize().then(() => {
107
+ this.start();
108
+ return Promise.resolve();
109
+ });
110
+ }
111
+ else
112
+ return Promise.resolve();
113
+ }
114
+ start() {
115
+ if (!this._enabled) {
116
+ this._enabled = true;
117
+ }
118
+ if (!this._rigiBodyList)
119
+ this._rigiBodyList = new Laya.SingletonList();
120
+ if (!Physics2DOption.customUpdate && Laya.LayaEnv.isPlaying)
121
+ Laya.ILaya.physicsTimer.frameLoop(1, this, this._update);
122
+ }
123
+ destroyWorld() {
124
+ this._enabled = false;
125
+ Laya.ILaya.physicsTimer.clear(this, this._update);
126
+ }
127
+ stop() {
128
+ Laya.ILaya.physicsTimer.clear(this, this._update);
129
+ }
130
+ static toPhysicsX(v) { return v / Laya.ILaya.stage.clientScaleX; }
131
+ static toPhysicsY(v) { return v / Laya.ILaya.stage.clientScaleY; }
132
+ static toRenderX(v) { return v * Laya.ILaya.stage.clientScaleX; }
133
+ static toRenderY(v) { return v * Laya.ILaya.stage.clientScaleY; }
134
+ static getDesignScaleX(sprite) {
135
+ let scale = 1;
136
+ let node = sprite;
137
+ while (node && node !== Laya.ILaya.stage) {
138
+ scale *= node.scaleX;
139
+ node = node.parent instanceof Laya.Sprite ? node.parent : null;
140
+ }
141
+ return scale;
142
+ }
143
+ static getDesignScaleY(sprite) {
144
+ let scale = 1;
145
+ let node = sprite;
146
+ while (node && node !== Laya.ILaya.stage) {
147
+ scale *= node.scaleY;
148
+ node = node.parent instanceof Laya.Sprite ? node.parent : null;
149
+ }
150
+ return scale;
151
+ }
152
+ static getDesignRotation(sprite) {
153
+ let rotation = 0;
154
+ let node = sprite;
155
+ while (node && node !== Laya.ILaya.stage) {
156
+ rotation += node.rotation;
157
+ node = node.parent instanceof Laya.Sprite ? node.parent : null;
158
+ }
159
+ return rotation;
160
+ }
161
+ static setDesignRotation(sprite, rotation) {
162
+ let parentRotation = 0;
163
+ let node = sprite.parent instanceof Laya.Sprite ? sprite.parent : null;
164
+ while (node && node !== Laya.ILaya.stage) {
165
+ parentRotation += node.rotation;
166
+ node = node.parent instanceof Laya.Sprite ? node.parent : null;
167
+ }
168
+ sprite.rotation = rotation - parentRotation;
169
+ }
170
+ static getDesignPosition(sprite, out) {
171
+ out.setTo(sprite.pivotX, sprite.pivotY);
172
+ return sprite.localToGlobal(out);
173
+ }
174
+ static setDesignPosition(sprite, x, y, out) {
175
+ out.setTo(x, y);
176
+ const parent = sprite.parent;
177
+ if (parent instanceof Laya.Sprite)
178
+ parent.globalToLocal(out);
179
+ sprite.pos(out.x, out.y);
180
+ }
181
+ static localToDesignPoint(sprite, x, y, out) {
182
+ out.setTo(sprite.pivotX + x, sprite.pivotY + y);
183
+ return sprite.localToGlobal(out);
184
+ }
185
+ static designToLocalPoint(sprite, x, y, out) {
186
+ out.setTo(x, y);
187
+ sprite.globalToLocal(out);
188
+ out.x -= sprite.pivotX;
189
+ out.y -= sprite.pivotY;
190
+ return out;
191
+ }
192
+ }
193
+ Laya.Laya.addInitCallback(() => Physics2D.I.enable());
194
+
195
+ exports.EPhycis2DBlit = void 0;
196
+ (function (EPhycis2DBlit) {
197
+ EPhycis2DBlit[EPhycis2DBlit["None"] = 0] = "None";
198
+ EPhycis2DBlit[EPhycis2DBlit["Shape"] = 1] = "Shape";
199
+ EPhycis2DBlit[EPhycis2DBlit["Joint"] = 2] = "Joint";
200
+ EPhycis2DBlit[EPhycis2DBlit["AABB"] = 4] = "AABB";
201
+ EPhycis2DBlit[EPhycis2DBlit["Pair"] = 8] = "Pair";
202
+ EPhycis2DBlit[EPhycis2DBlit["CenterOfMass"] = 16] = "CenterOfMass";
203
+ EPhycis2DBlit[EPhycis2DBlit["All"] = 31] = "All";
204
+ })(exports.EPhycis2DBlit || (exports.EPhycis2DBlit = {}));
205
+ exports.EPhysics2DJoint = void 0;
206
+ (function (EPhysics2DJoint) {
207
+ EPhysics2DJoint[EPhysics2DJoint["DistanceJoint"] = 0] = "DistanceJoint";
208
+ EPhysics2DJoint[EPhysics2DJoint["RevoluteJoint"] = 1] = "RevoluteJoint";
209
+ EPhysics2DJoint[EPhysics2DJoint["GearJoint"] = 2] = "GearJoint";
210
+ EPhysics2DJoint[EPhysics2DJoint["PulleyJoint"] = 3] = "PulleyJoint";
211
+ EPhysics2DJoint[EPhysics2DJoint["WheelJoint"] = 4] = "WheelJoint";
212
+ EPhysics2DJoint[EPhysics2DJoint["WeldJoint"] = 5] = "WeldJoint";
213
+ EPhysics2DJoint[EPhysics2DJoint["MouseJoint"] = 6] = "MouseJoint";
214
+ EPhysics2DJoint[EPhysics2DJoint["MotorJoint"] = 7] = "MotorJoint";
215
+ EPhysics2DJoint[EPhysics2DJoint["PrismaticJoint"] = 8] = "PrismaticJoint";
216
+ })(exports.EPhysics2DJoint || (exports.EPhysics2DJoint = {}));
217
+ exports.EPhysics2DShape = void 0;
218
+ (function (EPhysics2DShape) {
219
+ EPhysics2DShape[EPhysics2DShape["BoxShape"] = 0] = "BoxShape";
220
+ EPhysics2DShape[EPhysics2DShape["CircleShape"] = 1] = "CircleShape";
221
+ EPhysics2DShape[EPhysics2DShape["PolygonShape"] = 2] = "PolygonShape";
222
+ EPhysics2DShape[EPhysics2DShape["ChainShape"] = 3] = "ChainShape";
223
+ EPhysics2DShape[EPhysics2DShape["EdgeShape"] = 4] = "EdgeShape";
224
+ })(exports.EPhysics2DShape || (exports.EPhysics2DShape = {}));
225
+ class Physics2DContactHitResult {
226
+ constructor() {
227
+ this.normal = { x: 0, y: 0 };
228
+ this.points = [];
229
+ this.separations = [];
230
+ }
231
+ }
232
+ class Physics2DHitResult {
233
+ constructor() {
234
+ this.hitPoint = new Laya.Vector2();
235
+ this.hitNormal = new Laya.Vector2();
236
+ this.fraction = 0;
237
+ }
238
+ }
239
+ class FilterData {
240
+ constructor() {
241
+ this.group = 0;
242
+ this.category = 1;
243
+ this.mask = -1;
244
+ }
245
+ }
246
+ class Box2DShapeDef {
247
+ constructor() {
248
+ this.density = 1;
249
+ this.friction = 0.2;
250
+ this.isSensor = false;
251
+ this.restitution = 0;
252
+ this.restitutionThreshold = 1.0;
253
+ this.filter = new FilterData();
254
+ }
255
+ }
256
+ class RigidBody2DInfo {
257
+ constructor() {
258
+ this.position = new Laya.Vector2();
259
+ this.linearVelocity = new Laya.Vector2();
260
+ this.type = "static";
261
+ }
262
+ }
263
+ class physics2D_BaseJointDef {
264
+ }
265
+ class physics2D_DistancJointDef extends physics2D_BaseJointDef {
266
+ constructor() {
267
+ super(...arguments);
268
+ this.localAnchorA = new Laya.Vector2();
269
+ this.localAnchorB = new Laya.Vector2();
270
+ }
271
+ }
272
+ class physics2D_GearJointDef extends physics2D_BaseJointDef {
273
+ }
274
+ class physics2D_MotorJointDef extends physics2D_BaseJointDef {
275
+ constructor() {
276
+ super(...arguments);
277
+ this.linearOffset = new Laya.Vector2();
278
+ }
279
+ }
280
+ class physics2D_MouseJointJointDef extends physics2D_BaseJointDef {
281
+ constructor() {
282
+ super(...arguments);
283
+ this.target = new Laya.Vector2();
284
+ }
285
+ }
286
+ class physics2D_PrismaticJointDef extends physics2D_BaseJointDef {
287
+ constructor() {
288
+ super(...arguments);
289
+ this.anchor = new Laya.Vector2();
290
+ this.axis = new Laya.Vector2();
291
+ }
292
+ }
293
+ class physics2D_PulleyJointDef extends physics2D_BaseJointDef {
294
+ constructor() {
295
+ super(...arguments);
296
+ this.groundAnchorA = new Laya.Vector2();
297
+ this.groundAnchorB = new Laya.Vector2();
298
+ this.localAnchorA = new Laya.Vector2();
299
+ this.localAnchorB = new Laya.Vector2();
300
+ }
301
+ }
302
+ class physics2D_RevoluteJointDef extends physics2D_BaseJointDef {
303
+ constructor() {
304
+ super(...arguments);
305
+ this.anchor = new Laya.Vector2();
306
+ }
307
+ }
308
+ class physics2D_WeldJointDef extends physics2D_BaseJointDef {
309
+ constructor() {
310
+ super(...arguments);
311
+ this.anchor = new Laya.Vector2();
312
+ }
313
+ }
314
+ class physics2D_WheelJointDef extends physics2D_BaseJointDef {
315
+ constructor() {
316
+ super(...arguments);
317
+ this.anchor = new Laya.Vector2();
318
+ this.axis = new Laya.Vector2();
319
+ }
320
+ }
321
+ class box2DWorldDef {
322
+ constructor() {
323
+ this.gravity = new Laya.Vector2(0, -9.8);
324
+ this.pixelRatio = 50;
325
+ this.subStep = 1;
326
+ this.velocityIterations = 8;
327
+ this.positionIterations = 3;
328
+ }
329
+ }
330
+ exports.Ebox2DType = void 0;
331
+ (function (Ebox2DType) {
332
+ Ebox2DType[Ebox2DType["b2Color"] = 0] = "b2Color";
333
+ Ebox2DType[Ebox2DType["b2Vec2"] = 1] = "b2Vec2";
334
+ Ebox2DType[Ebox2DType["b2Transform"] = 2] = "b2Transform";
335
+ Ebox2DType[Ebox2DType["b2Contact"] = 3] = "b2Contact";
336
+ Ebox2DType[Ebox2DType["b2Joint"] = 4] = "b2Joint";
337
+ Ebox2DType[Ebox2DType["b2Fixture"] = 5] = "b2Fixture";
338
+ Ebox2DType[Ebox2DType["b2Filter"] = 6] = "b2Filter";
339
+ Ebox2DType[Ebox2DType["b2QueryCallback"] = 7] = "b2QueryCallback";
340
+ Ebox2DType[Ebox2DType["b2RayCastCallback"] = 8] = "b2RayCastCallback";
341
+ })(exports.Ebox2DType || (exports.Ebox2DType = {}));
342
+
343
+ class PhysicsLineGemetry {
344
+ get positions() {
345
+ return this._positions;
346
+ }
347
+ set positions(value) {
348
+ if ((value.length / 4) != ((value.length / 4) | 0))
349
+ return;
350
+ this._positions = value;
351
+ this._needUpdate = true;
352
+ }
353
+ get renderGeometry() {
354
+ return this._renderGeometry;
355
+ }
356
+ clear() {
357
+ this._positions.length = 0;
358
+ this._needUpdate = true;
359
+ }
360
+ updateGeometry() {
361
+ if (!this._needUpdate)
362
+ return;
363
+ this._needUpdate = false;
364
+ this._changeGeometry();
365
+ }
366
+ initRender() {
367
+ let lineNums = this._maxLineNumer;
368
+ let positionBuffer = this._positionVertexBuffer = Laya.LayaGL.renderDeviceFactory.createVertexBuffer(Laya.BufferUsage.Dynamic);
369
+ positionBuffer.instanceBuffer = true;
370
+ positionBuffer.vertexDeclaration = PhysicsLineShader.linePoisitionDesc;
371
+ positionBuffer.setDataLength(lineNums * 16);
372
+ this._positionInstansBufferData = new Float32Array(lineNums * 4);
373
+ positionBuffer.setData(this._positionInstansBufferData.buffer, 0, 0, this._positionInstansBufferData.byteLength);
374
+ let lineLengthBuffer = this._lineLengthVertexBuffer = Laya.LayaGL.renderDeviceFactory.createVertexBuffer(Laya.BufferUsage.Dynamic);
375
+ lineLengthBuffer.instanceBuffer = true;
376
+ lineLengthBuffer.vertexDeclaration = PhysicsLineShader.lineLengthDesc;
377
+ lineLengthBuffer.setDataLength(lineNums * 4);
378
+ this._lineLengthBufferData = new Float32Array(lineNums * 1);
379
+ lineLengthBuffer.setData(this._lineLengthBufferData.buffer, 0, 0, this._lineLengthBufferData.byteLength);
380
+ let geometry = this._renderGeometry = Laya.LayaGL.renderDeviceFactory.createRenderGeometryElement(Laya.MeshTopology.Triangles, Laya.DrawType.DrawElementInstance);
381
+ geometry.bufferState = Laya.LayaGL.renderDeviceFactory.createBufferState();
382
+ geometry.setDrawElemenParams(6, 0);
383
+ geometry.indexFormat = Laya.IndexFormat.UInt16;
384
+ geometry.instanceCount = 0;
385
+ let buffers = [];
386
+ buffers.push(PhysicsLineShader._vbs);
387
+ buffers.push(this._positionVertexBuffer);
388
+ buffers.push(this._lineLengthVertexBuffer);
389
+ geometry.bufferState.applyState(buffers, PhysicsLineShader._ibs);
390
+ }
391
+ _changeGeometry() {
392
+ let lineLength = this._positions.length / 4;
393
+ if (lineLength > this._maxLineNumer) {
394
+ this._maxLineNumer = (((lineLength / this._enLarge) | 0) + 1) * this._enLarge;
395
+ this._positionInstansBufferData = new Float32Array(this._maxLineNumer * 4);
396
+ this._positionVertexBuffer.setDataLength(this._maxLineNumer * 16);
397
+ this._lineLengthBufferData = new Float32Array(this._maxLineNumer * 1);
398
+ this._lineLengthVertexBuffer.setDataLength(this._maxLineNumer * 4);
399
+ this._renderGeometry.bufferState.applyState([PhysicsLineShader._vbs, this._positionVertexBuffer, this._lineLengthVertexBuffer], PhysicsLineShader._ibs);
400
+ }
401
+ this._positionInstansBufferData.set(this._positions, 0);
402
+ this._positionVertexBuffer.setData(this._positionInstansBufferData.buffer, 0, 0, this._positionInstansBufferData.byteLength);
403
+ {
404
+ let totalLength = 0;
405
+ for (var i = 0; i < lineLength; i++) {
406
+ const dataIndex = i * 4;
407
+ this._lineLengthBufferData[i] = totalLength;
408
+ totalLength += Math.hypot(this._positions[dataIndex + 2] - this._positions[dataIndex], this._positions[dataIndex + 3] - this._positions[dataIndex + 1]);
409
+ }
410
+ this._lineLengthVertexBuffer.setData(this._lineLengthBufferData.buffer, 0, 0, this._lineLengthBufferData.byteLength);
411
+ }
412
+ this._renderGeometry.instanceCount = lineLength;
413
+ }
414
+ constructor() {
415
+ this._positions = [];
416
+ this._needUpdate = true;
417
+ this._maxLineNumer = 200;
418
+ this._enLarge = 100;
419
+ this.initRender();
420
+ }
421
+ }
422
+
423
+ class PhysicsDrawLine2DCMD extends Laya.Command2D {
424
+ get physicsGeometry() {
425
+ return this._physicsGeometry;
426
+ }
427
+ static create(pointArray, mat, color = Laya.Color.WHITE, lineWidth = 3) {
428
+ var cmd = PhysicsDrawLine2DCMD._pool.take();
429
+ cmd.physicsGeometry.positions = pointArray;
430
+ cmd.lineWidth = lineWidth;
431
+ cmd.color = color;
432
+ cmd._needUpdateElement = true;
433
+ cmd._setMatrix(mat);
434
+ return cmd;
435
+ }
436
+ constructor() {
437
+ super();
438
+ this._renderElements = [];
439
+ this._material = new Laya.Material();
440
+ this._material._addReference();
441
+ this._material.setShaderName("PhysicsLineShader");
442
+ this._material.cull = Laya.CullMode.Off;
443
+ this._material.setBoolByIndex(Laya.Shader3D.DEPTH_WRITE, false);
444
+ this._material.setIntByIndex(Laya.Shader3D.DEPTH_TEST, Laya.RenderState.DEPTHTEST_OFF);
445
+ this._material.setIntByIndex(Laya.Shader3D.BLEND, Laya.RenderState.BLEND_ENABLE_ALL);
446
+ this._material.setIntByIndex(Laya.Shader3D.BLEND_EQUATION, Laya.RenderState.BLENDEQUATION_ADD);
447
+ this._material.setIntByIndex(Laya.Shader3D.BLEND_SRC, Laya.RenderState.BLENDPARAM_ONE);
448
+ this._material.setIntByIndex(Laya.Shader3D.BLEND_DST, Laya.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA);
449
+ this._material.setFloatByIndex(Laya.ShaderDefines2D.UNIFORM_VERTALPHA, 1.0);
450
+ this._material.setIntByIndex(Laya.Shader3D.CULL, Laya.RenderState.CULL_NONE);
451
+ this._drawElementData = Laya.LayaGL.render2DRenderPassFactory.createDraw2DElementCMDData();
452
+ this._shaderData = Laya.LayaGL.renderDeviceFactory.createShaderData();
453
+ this._shaderData.addDefine(Laya.BaseRenderNode2D.SHADERDEFINE_BASERENDER2D);
454
+ this._struct = Laya.LayaGL.render2DRenderPassFactory.createRenderStruct2D();
455
+ this._renderElements[0] = Laya.LayaGL.render2DRenderPassFactory.createRenderElement2D();
456
+ this._physicsGeometry = new PhysicsLineGemetry();
457
+ this._physicsGeometry.updateGeometry();
458
+ this._renderElements[0].nodeCommonMap = ["BaseRender2D"];
459
+ Laya.BaseRenderNode2D._setRenderElement2DMaterial(this._renderElements[0], this._material);
460
+ this._matrix = new Laya.Matrix();
461
+ }
462
+ set lineWidth(value) {
463
+ this._material.shaderData.setNumber(PhysicsLineShader.LINEWIDTH, value);
464
+ }
465
+ set color(value) {
466
+ this._shaderData.setColor(Laya.BaseRenderNode2D.BASERENDER2DCOLOR, value);
467
+ }
468
+ _setMatrix(value) {
469
+ value ? value.copyTo(this._matrix) : Laya.Matrix.EMPTY.copyTo(this._matrix);
470
+ let mat = this._matrix;
471
+ let vec3 = Laya.Vector3.TEMP;
472
+ vec3.x = mat.a;
473
+ vec3.y = mat.c;
474
+ vec3.z = mat.tx;
475
+ this._shaderData.setVector3(Laya.ShaderDefines2D.UNIFORM_NMATRIX_0, vec3);
476
+ vec3.x = mat.b;
477
+ vec3.y = mat.d;
478
+ vec3.z = mat.ty;
479
+ this._shaderData.setVector3(Laya.ShaderDefines2D.UNIFORM_NMATRIX_1, vec3);
480
+ }
481
+ getRenderCMD() {
482
+ return this._drawElementData;
483
+ }
484
+ run() {
485
+ if (this._needUpdateElement) {
486
+ this.physicsGeometry.updateGeometry();
487
+ this._renderElements[0].geometry = this._renderGeometry = this._physicsGeometry.renderGeometry;
488
+ this._renderElements[0].renderStateIsBySprite = false;
489
+ this._renderElements[0].value2DShaderData = this._shaderData;
490
+ this._renderElements[0].materialShaderData = this._material.shaderData;
491
+ this._renderElements[0].subShader = this._material._shader.getSubShaderAt(0);
492
+ this._drawElementData.setRenderelements(this._renderElements);
493
+ this._needUpdateElement = false;
494
+ }
495
+ }
496
+ recover() {
497
+ PhysicsDrawLine2DCMD._pool.recover(this);
498
+ super.recover();
499
+ }
500
+ }
501
+ PhysicsDrawLine2DCMD._pool = Laya.Pool.createPool(PhysicsDrawLine2DCMD);
502
+
503
+ class Physics2DDebugDraw {
504
+ constructor() {
505
+ this._lineWidth = 3;
506
+ this._matrix = new Laya.Matrix();
507
+ this._meshAccums = new Map();
508
+ this._lineAccums = new Map();
509
+ this._cmdDrawLineList = [];
510
+ this._linePointsList = [];
511
+ this._cmdDrawMeshList = [];
512
+ this._meshList = [];
513
+ this._pendingMeshCmdRing = [];
514
+ this._pendingMeshRing = [];
515
+ this._pendingLineCmdRing = [];
516
+ this._camera = {};
517
+ this._camera.m_center = new Laya.Vector2(0, 0);
518
+ this._camera.m_extent = 25;
519
+ this._camera.m_zoom = 1;
520
+ this._camera.m_width = 1280;
521
+ this._camera.m_height = 800;
522
+ this._cmdBuffer = new Laya.CommandBuffer2D("Physics2DDebugDraw");
523
+ }
524
+ _colorToKey(color) {
525
+ return ((color.r * 255 + 0.5) | 0) * 16777216 +
526
+ ((color.g * 255 + 0.5) | 0) * 65536 +
527
+ ((color.b * 255 + 0.5) | 0) * 256 +
528
+ ((color.a * 255 + 0.5) | 0);
529
+ }
530
+ _getMeshAccum(color) {
531
+ let key = this._colorToKey(color);
532
+ let accum = this._meshAccums.get(key);
533
+ if (!accum) {
534
+ accum = { vertices: [], indices: [], vertexCount: 0, color: color.clone() };
535
+ this._meshAccums.set(key, accum);
536
+ }
537
+ return accum;
538
+ }
539
+ _getLineAccum(color) {
540
+ let key = this._colorToKey(color);
541
+ let accum = this._lineAccums.get(key);
542
+ if (!accum) {
543
+ accum = { points: [], color: color.clone() };
544
+ this._lineAccums.set(key, accum);
545
+ }
546
+ return accum;
547
+ }
548
+ setActive(value) {
549
+ if (value) {
550
+ Laya.Laya.timer.frameLoop(1, this, this.render);
551
+ }
552
+ else {
553
+ Laya.Laya.timer.clear(this, this.render);
554
+ }
555
+ }
556
+ appendCircle(cx, cy, radius, color, numSegments = 24) {
557
+ if (radius <= 0 || numSegments < 3)
558
+ return;
559
+ let accum = this._getMeshAccum(color);
560
+ let base = accum.vertexCount;
561
+ const twoPi = Math.PI * 2;
562
+ const verts = accum.vertices;
563
+ const idxs = accum.indices;
564
+ for (let i = 0; i < numSegments; i++) {
565
+ const angle = twoPi * i / numSegments;
566
+ const cos = Math.cos(angle);
567
+ const sin = Math.sin(angle);
568
+ verts.push(cx + radius * cos, cy + radius * sin, 0, 0.5 + 0.5 * cos, 0.5 + 0.5 * sin);
569
+ }
570
+ verts.push(cx, cy, 0, 0.5, 0.5);
571
+ const centerIdx = base + numSegments;
572
+ for (let i = 0; i < numSegments; i++) {
573
+ idxs.push(centerIdx, base + i, base + ((i + 1) % numSegments));
574
+ }
575
+ accum.vertexCount += numSegments + 1;
576
+ }
577
+ appendPolygon(points, pointCount, color) {
578
+ if (pointCount < 3)
579
+ return;
580
+ let accum = this._getMeshAccum(color);
581
+ let base = accum.vertexCount;
582
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
583
+ for (let i = 0; i < pointCount; i++) {
584
+ const x = points[i * 2], y = points[i * 2 + 1];
585
+ if (x < minX)
586
+ minX = x;
587
+ if (x > maxX)
588
+ maxX = x;
589
+ if (y < minY)
590
+ minY = y;
591
+ if (y > maxY)
592
+ maxY = y;
593
+ }
594
+ const w = maxX - minX || 1;
595
+ const h = maxY - minY || 1;
596
+ const verts = accum.vertices;
597
+ const idxs = accum.indices;
598
+ for (let i = 0; i < pointCount; i++) {
599
+ const x = points[i * 2];
600
+ const y = points[i * 2 + 1];
601
+ verts.push(x, y, 0, (x - minX) / w, (y - minY) / h);
602
+ }
603
+ for (let i = 1; i < pointCount - 1; i++) {
604
+ idxs.push(base, base + i, base + i + 1);
605
+ }
606
+ accum.vertexCount += pointCount;
607
+ }
608
+ appendLineSegment(x1, y1, x2, y2, color) {
609
+ let accum = this._getLineAccum(color);
610
+ accum.points.push(x1, y1, x2, y2);
611
+ }
612
+ appendLinePoints(points, color) {
613
+ if (points.length < 4)
614
+ return;
615
+ let accum = this._getLineAccum(color);
616
+ let arr = accum.points;
617
+ for (let i = 0, len = points.length; i < len; i++) {
618
+ arr.push(points[i]);
619
+ }
620
+ }
621
+ render() {
622
+ this._matrix.identity();
623
+ this._matrix.scale(Physics2D.toRenderX(1), Physics2D.toRenderY(1));
624
+ if (this._pendingMeshCmdRing.length >= Physics2DDebugDraw._RETAIN_FRAMES) {
625
+ const oldestMeshCmds = this._pendingMeshCmdRing.shift();
626
+ for (let i = 0; i < oldestMeshCmds.length; i++)
627
+ oldestMeshCmds[i].recover();
628
+ const oldestMeshes = this._pendingMeshRing.shift();
629
+ for (let i = 0; i < oldestMeshes.length; i++)
630
+ oldestMeshes[i].destroy();
631
+ const oldestLineCmds = this._pendingLineCmdRing.shift();
632
+ for (let i = 0; i < oldestLineCmds.length; i++)
633
+ oldestLineCmds[i].recover();
634
+ }
635
+ let area2D = this._scene._area2Ds.size > 0 ? this._scene._area2Ds.values().next().value._struct : null;
636
+ let frameMeshCmds = [];
637
+ let frameMeshes = [];
638
+ let frameLineCmds = [];
639
+ const declaration = Laya.VertexMesh2D.getVertexDeclaration(["POSITION,UV"], false)[0];
640
+ this._meshAccums.forEach(accum => {
641
+ if (accum.vertexCount === 0)
642
+ return;
643
+ const verts = new Float32Array(accum.vertices);
644
+ const useUint32 = accum.vertexCount > 65535;
645
+ const indices = useUint32 ? new Uint32Array(accum.indices) : new Uint16Array(accum.indices);
646
+ const mesh = Laya.Mesh2D.createMesh2DByPrimitive([verts], [declaration], indices, useUint32 ? Laya.IndexFormat.UInt32 : Laya.IndexFormat.UInt16, [{ length: indices.length, start: 0 }]);
647
+ const cmd = Laya.DrawMesh2DCMD.create(mesh, this._matrix, Laya.Texture2D.whiteTexture, accum.color, this._material);
648
+ if (cmd)
649
+ frameMeshCmds.push(cmd);
650
+ frameMeshes.push(mesh);
651
+ accum.vertices.length = 0;
652
+ accum.indices.length = 0;
653
+ accum.vertexCount = 0;
654
+ });
655
+ this._lineAccums.forEach(accum => {
656
+ if (accum.points.length < 4)
657
+ return;
658
+ const cmd = PhysicsDrawLine2DCMD.create(accum.points, this._matrix, accum.color, this._lineWidth);
659
+ if (cmd)
660
+ frameLineCmds.push(cmd);
661
+ });
662
+ this._cmdBuffer.setRenderTarget(null, false);
663
+ for (let i = 0; i < this._cmdDrawMeshList.length; i++) {
664
+ let cmd = this._cmdDrawMeshList[i];
665
+ if (area2D)
666
+ cmd._renderElements[0] && (cmd._renderElements[0].owner = area2D);
667
+ this._cmdBuffer.addCacheCommand(cmd);
668
+ }
669
+ for (let i = 0; i < frameMeshCmds.length; i++) {
670
+ let cmd = frameMeshCmds[i];
671
+ if (area2D)
672
+ cmd._renderElements[0] && (cmd._renderElements[0].owner = area2D);
673
+ this._cmdBuffer.addCacheCommand(cmd);
674
+ }
675
+ for (let i = 0; i < this._cmdDrawLineList.length; i++) {
676
+ let cmd = this._cmdDrawLineList[i];
677
+ if (area2D)
678
+ cmd._renderElements[0] && (cmd._renderElements[0].owner = area2D);
679
+ this._cmdBuffer.addCacheCommand(cmd);
680
+ }
681
+ for (let i = 0; i < frameLineCmds.length; i++) {
682
+ let cmd = frameLineCmds[i];
683
+ if (area2D)
684
+ cmd._renderElements[0] && (cmd._renderElements[0].owner = area2D);
685
+ this._cmdBuffer.addCacheCommand(cmd);
686
+ }
687
+ this._cmdBuffer.apply(true);
688
+ this._cmdBuffer.clear(false);
689
+ this._pendingMeshCmdRing.push(this._cmdDrawMeshList.slice().concat(frameMeshCmds));
690
+ this._pendingMeshRing.push(this._meshList.slice().concat(frameMeshes));
691
+ this._pendingLineCmdRing.push(this._cmdDrawLineList.slice().concat(frameLineCmds));
692
+ for (let i = 0; i < this._linePointsList.length; i++) {
693
+ this._linePointsList[i] = null;
694
+ }
695
+ this._cmdDrawLineList.length = 0;
696
+ this._cmdDrawMeshList.length = 0;
697
+ this._meshList.length = 0;
698
+ this._linePointsList.length = 0;
699
+ this._lineAccums.forEach(accum => { accum.points.length = 0; });
700
+ }
701
+ createMesh2DByVertices(vertices) {
702
+ const pointCount = vertices.length / 2;
703
+ if (pointCount < 3)
704
+ return null;
705
+ let vertexs = new Float32Array(pointCount * 5);
706
+ let minX = Number.MAX_VALUE, minY = Number.MAX_VALUE;
707
+ let maxX = Number.MIN_VALUE, maxY = Number.MIN_VALUE;
708
+ for (let i = 0; i < vertices.length; i += 2) {
709
+ minX = Math.min(minX, vertices[i]);
710
+ maxX = Math.max(maxX, vertices[i]);
711
+ minY = Math.min(minY, vertices[i + 1]);
712
+ maxY = Math.max(maxY, vertices[i + 1]);
713
+ }
714
+ const width = maxX - minX;
715
+ const height = maxY - minY;
716
+ let pos = 0;
717
+ for (let i = 0; i < pointCount; i++, pos += 5) {
718
+ const x = vertices[i * 2];
719
+ const y = vertices[i * 2 + 1];
720
+ vertexs[pos + 0] = x;
721
+ vertexs[pos + 1] = y;
722
+ vertexs[pos + 2] = 0;
723
+ vertexs[pos + 3] = (x - minX) / width;
724
+ vertexs[pos + 4] = (y - minY) / height;
725
+ }
726
+ let index = new Uint16Array((pointCount - 2) * 3);
727
+ let ibIndex = 0;
728
+ for (let i = 1; i < pointCount - 1; i++) {
729
+ index[ibIndex++] = 0;
730
+ index[ibIndex++] = i;
731
+ index[ibIndex++] = i + 1;
732
+ }
733
+ const declaration = Laya.VertexMesh2D.getVertexDeclaration(["POSITION,UV"], false)[0];
734
+ let mesh2D = Laya.Mesh2D.createMesh2DByPrimitive([vertexs], [declaration], index, Laya.IndexFormat.UInt16, [{ length: index.length, start: 0 }]);
735
+ return mesh2D;
736
+ }
737
+ createCircleMeshByVertices(center, radius, numSegments) {
738
+ if (numSegments < 3)
739
+ numSegments = 3;
740
+ if (radius <= 0)
741
+ return null;
742
+ const twoPi = Math.PI * 2;
743
+ let vertices = new Float32Array((numSegments + 1) * 5);
744
+ let indices = new Uint16Array(numSegments * 3);
745
+ let pos = 0;
746
+ for (let i = 0; i < numSegments; i++, pos += 5) {
747
+ const angle = twoPi * i / numSegments;
748
+ const x = center.x + radius * Math.cos(angle);
749
+ const y = center.y + radius * Math.sin(angle);
750
+ vertices[pos] = x;
751
+ vertices[pos + 1] = y;
752
+ vertices[pos + 2] = 0;
753
+ vertices[pos + 3] = 0.5 + 0.5 * Math.cos(angle);
754
+ vertices[pos + 4] = 0.5 + 0.5 * Math.sin(angle);
755
+ }
756
+ vertices[pos] = center.x;
757
+ vertices[pos + 1] = center.y;
758
+ vertices[pos + 2] = 0;
759
+ vertices[pos + 3] = 0.5;
760
+ vertices[pos + 4] = 0.5;
761
+ let ibIndex = 0;
762
+ for (let i = 0; i < numSegments; i++, ibIndex += 3) {
763
+ const nextIndex = (i + 1) % numSegments;
764
+ indices[ibIndex] = numSegments;
765
+ indices[ibIndex + 1] = i;
766
+ indices[ibIndex + 2] = nextIndex;
767
+ }
768
+ var declaration = Laya.VertexMesh2D.getVertexDeclaration(["POSITION,UV"], false)[0];
769
+ let mesh2D = Laya.Mesh2D.createMesh2DByPrimitive([vertices], [declaration], indices, Laya.IndexFormat.UInt16, [{ length: indices.length, start: 0 }]);
770
+ return mesh2D;
771
+ }
772
+ addMeshDebugDrawCMD(mesh2D, color, matrix) {
773
+ if (!mesh2D)
774
+ return;
775
+ if (!matrix)
776
+ matrix = this._matrix;
777
+ let cmd = Laya.DrawMesh2DCMD.create(mesh2D, matrix, Laya.Texture2D.whiteTexture, color, this._material);
778
+ cmd && this._cmdDrawMeshList.push(cmd);
779
+ this._meshList.push(mesh2D);
780
+ }
781
+ addLineDebugDrawCMD(points, color, lineWidth, matrix) {
782
+ if (!matrix)
783
+ matrix = this._matrix;
784
+ if (!lineWidth)
785
+ lineWidth = this._lineWidth;
786
+ let cmd = PhysicsDrawLine2DCMD.create(points, matrix, color, lineWidth);
787
+ cmd && this._cmdDrawLineList.push(cmd);
788
+ this._linePointsList.push(points);
789
+ }
790
+ destroy() {
791
+ Laya.Laya.timer.clear(this, this.render);
792
+ this._cmdBuffer && this._cmdBuffer.clear(false);
793
+ this._material && this._material.destroy();
794
+ this._material = null;
795
+ this._cmdBuffer = null;
796
+ if (this._cmdDrawMeshList) {
797
+ for (let i = 0; i < this._cmdDrawMeshList.length; i++) {
798
+ this._cmdDrawMeshList[i].recover();
799
+ }
800
+ this._cmdDrawMeshList.length = 0;
801
+ }
802
+ if (this._meshList) {
803
+ for (let i = 0; i < this._meshList.length; i++) {
804
+ this._meshList[i].destroy();
805
+ }
806
+ this._meshList.length = 0;
807
+ }
808
+ if (this._cmdDrawLineList) {
809
+ for (let i = 0; i < this._cmdDrawLineList.length; i++) {
810
+ this._cmdDrawLineList[i].recover();
811
+ }
812
+ this._cmdDrawLineList.length = 0;
813
+ }
814
+ this._linePointsList && (this._linePointsList.length = 0);
815
+ this._meshAccums.clear();
816
+ this._lineAccums.clear();
817
+ for (let i = 0; i < this._pendingMeshCmdRing.length; i++) {
818
+ const cmds = this._pendingMeshCmdRing[i];
819
+ for (let j = 0; j < cmds.length; j++)
820
+ cmds[j].recover();
821
+ }
822
+ for (let i = 0; i < this._pendingLineCmdRing.length; i++) {
823
+ const cmds = this._pendingLineCmdRing[i];
824
+ for (let j = 0; j < cmds.length; j++)
825
+ cmds[j].recover();
826
+ }
827
+ for (let i = 0; i < this._pendingMeshRing.length; i++) {
828
+ const meshes = this._pendingMeshRing[i];
829
+ for (let j = 0; j < meshes.length; j++)
830
+ meshes[j].destroy();
831
+ }
832
+ this._pendingMeshCmdRing.length = 0;
833
+ this._pendingLineCmdRing.length = 0;
834
+ this._pendingMeshRing.length = 0;
835
+ }
836
+ }
837
+ Physics2DDebugDraw._RETAIN_FRAMES = 6;
838
+
839
+ class Physics2DWorldManager {
840
+ getEmptyBody() {
841
+ return this._emptyBody || (this._emptyBody = Physics2D.I._factory.createBody(this._box2DWorld, null));
842
+ }
843
+ get box2DWorld() {
844
+ return this._box2DWorld;
845
+ }
846
+ get gravity() {
847
+ return this._gravity;
848
+ }
849
+ constructor(scene) {
850
+ var _a, _b, _c, _d, _e, _f, _g, _h;
851
+ this._subStepCount = 1;
852
+ this._pixelRatio = 50;
853
+ this._RePixelRatio = 1 / this._pixelRatio;
854
+ this._subStep = 1;
855
+ this._velocityIterations = 8;
856
+ this._positionIterations = 8;
857
+ this._gravity = new Laya.Vector2(0, -9.8);
858
+ this._worldDef = new box2DWorldDef();
859
+ this._eventList = [];
860
+ this._allowWorldSleep = false;
861
+ this._tempColor = new Laya.Color();
862
+ this._tempPoints = [];
863
+ const configlayer = (_a = Laya.PlayerConfig.physics2D) === null || _a === void 0 ? void 0 : _a.defaultConfig;
864
+ this._worldDef.pixelRatio = this._pixelRatio = (_b = configlayer === null || configlayer === void 0 ? void 0 : configlayer.pixelRatio) !== null && _b !== void 0 ? _b : Physics2DOption.pixelRatio;
865
+ this._RePixelRatio = 1 / this._pixelRatio;
866
+ this._worldDef.subStep = this._subStep = (_c = configlayer === null || configlayer === void 0 ? void 0 : configlayer.subStep) !== null && _c !== void 0 ? _c : Physics2DOption.subStep;
867
+ this._worldDef.velocityIterations = this._velocityIterations = (_d = configlayer === null || configlayer === void 0 ? void 0 : configlayer.velocityIterations) !== null && _d !== void 0 ? _d : Physics2DOption.velocityIterations;
868
+ this._worldDef.positionIterations = this._positionIterations = (_e = configlayer === null || configlayer === void 0 ? void 0 : configlayer.positionIterations) !== null && _e !== void 0 ? _e : Physics2DOption.positionIterations;
869
+ this._worldDef.gravity = this._gravity.setValue((_f = configlayer === null || configlayer === void 0 ? void 0 : configlayer.gravity.x) !== null && _f !== void 0 ? _f : Physics2DOption.gravity.x, (_g = configlayer === null || configlayer === void 0 ? void 0 : configlayer.gravity.y) !== null && _g !== void 0 ? _g : Physics2DOption.gravity.y);
870
+ this._allowWorldSleep = (_h = configlayer === null || configlayer === void 0 ? void 0 : configlayer.allowSleeping) !== null && _h !== void 0 ? _h : Physics2DOption.allowSleeping;
871
+ this._scene = scene;
872
+ scene.on(Laya.Event.DISPLAY, () => { var _a; return (_a = this._debugDraw) === null || _a === void 0 ? void 0 : _a.setActive(true); });
873
+ scene.on(Laya.Event.UNDISPLAY, () => { var _a; return (_a = this._debugDraw) === null || _a === void 0 ? void 0 : _a.setActive(false); });
874
+ this.setRootSprite(this._scene);
875
+ }
876
+ Init(data) {
877
+ var _a, _b;
878
+ let configlayer = (_a = Laya.PlayerConfig.physics2D) === null || _a === void 0 ? void 0 : _a.addConfig[data];
879
+ if (!configlayer) {
880
+ configlayer = (_b = Laya.PlayerConfig.physics2D) === null || _b === void 0 ? void 0 : _b.defaultConfig;
881
+ }
882
+ if (!configlayer)
883
+ return;
884
+ this._worldDef.pixelRatio = this._pixelRatio = configlayer.pixelRatio ? configlayer.pixelRatio : Physics2DOption.pixelRatio;
885
+ this._RePixelRatio = 1 / this._pixelRatio;
886
+ this._worldDef.subStep = this._subStep = configlayer.subStep ? configlayer.subStep : Physics2DOption.subStep;
887
+ this._worldDef.velocityIterations = this._velocityIterations = configlayer.velocityIterations ? configlayer.velocityIterations : Physics2DOption.velocityIterations;
888
+ this._worldDef.positionIterations = this._positionIterations = configlayer.positionIterations ? configlayer.positionIterations : Physics2DOption.positionIterations;
889
+ this._worldDef.gravity = this._gravity.setValue(configlayer.gravity.x ? configlayer.gravity.x : Physics2DOption.gravity.x, configlayer.gravity.y ? configlayer.gravity.y : Physics2DOption.gravity.x);
890
+ this._allowWorldSleep = configlayer.allowSleeping;
891
+ if (this._box2DWorld) {
892
+ this.destroy();
893
+ this._eventList = [];
894
+ }
895
+ this.setRootSprite(this._scene);
896
+ if (configlayer.debugDraw && Laya.LayaEnv.isPlaying) {
897
+ this.enableDebugDraw(configlayer.drawShape, exports.EPhycis2DBlit.Shape);
898
+ this.enableDebugDraw(configlayer.drawJoint, exports.EPhycis2DBlit.Joint);
899
+ this.enableDebugDraw(configlayer.drawAABB, exports.EPhycis2DBlit.AABB);
900
+ this.enableDebugDraw(configlayer.drawCenterOfMass, exports.EPhycis2DBlit.CenterOfMass);
901
+ }
902
+ }
903
+ update(dt) {
904
+ }
905
+ setRootSprite(scene) {
906
+ var _a;
907
+ this._scene = scene;
908
+ this._box2DWorld = Physics2D.I._factory.createWorld(this._worldDef);
909
+ Physics2D.I._factory.allowWorldSleep(this._box2DWorld, this._allowWorldSleep);
910
+ this._box2DWorld._pixelRatio = this._pixelRatio;
911
+ this._box2DWorld._indexInMap = Physics2D.I._factory.worldCount;
912
+ Physics2D.I._factory.worldMap.set(Physics2D.I._factory.worldCount, this);
913
+ Physics2D.I._factory.worldCount++;
914
+ this._contactListener = Physics2D.I._factory.createContactListener();
915
+ this._contactListener = this._worldContactCallback(this._contactListener);
916
+ Physics2D.I._factory.setContactListener(this._box2DWorld, this._contactListener);
917
+ this._JSRayCastcallback = Physics2D.I._factory.createJSRayCastCallback();
918
+ this._JSQuerycallback = Physics2D.I._factory.createJSQueryCallback();
919
+ const configlayer = (_a = Laya.PlayerConfig.physics2D) === null || _a === void 0 ? void 0 : _a.defaultConfig;
920
+ if (configlayer && configlayer.debugDraw && Laya.LayaEnv.isPlaying) {
921
+ this.enableDebugDraw(configlayer.drawShape, exports.EPhycis2DBlit.Shape);
922
+ this.enableDebugDraw(configlayer.drawJoint, exports.EPhycis2DBlit.Joint);
923
+ this.enableDebugDraw(configlayer.drawAABB, exports.EPhycis2DBlit.AABB);
924
+ this.enableDebugDraw(configlayer.drawCenterOfMass, exports.EPhycis2DBlit.CenterOfMass);
925
+ }
926
+ }
927
+ setGravity(gravity) {
928
+ this._gravity.setValue(gravity.x, gravity.y);
929
+ if (this._box2DWorld) {
930
+ const factory = Physics2D.I._factory;
931
+ const value = factory.createPhyVec2(gravity.x, gravity.y);
932
+ this._box2DWorld.SetGravity(value);
933
+ factory.destroyData(value);
934
+ }
935
+ }
936
+ getRootSprite() {
937
+ return this._scene;
938
+ }
939
+ shiftOrigin(newOrigin) {
940
+ Physics2D.I._factory.shiftOrigin(this._box2DWorld, newOrigin);
941
+ }
942
+ enableDebugDraw(enable, bli) {
943
+ if (!this._debugDraw) {
944
+ this._debugDraw = new Physics2DDebugDraw();
945
+ this._debugDraw._scene = this._scene;
946
+ if (this._scene.activeInHierarchy)
947
+ this._debugDraw.setActive(true);
948
+ }
949
+ this._enableBox2DDraw(enable, bli);
950
+ }
951
+ setPixel_Ratio(pixelRatio) {
952
+ if (!Number.isFinite(pixelRatio) || pixelRatio <= 0)
953
+ throw new Error("Physics2D pixel ratio must be a finite positive number.");
954
+ this._pixelRatio = pixelRatio;
955
+ this._RePixelRatio = 1 / pixelRatio;
956
+ if (this._box2DWorld)
957
+ this._box2DWorld._pixelRatio = pixelRatio;
958
+ }
959
+ getPixel_Ratio() {
960
+ return this._pixelRatio;
961
+ }
962
+ setSubStep(subStep) {
963
+ if (!Number.isSafeInteger(subStep) || subStep < 1)
964
+ throw new Error("Physics2D substeps must be a positive integer.");
965
+ this._subStep = this._subStepCount = subStep;
966
+ }
967
+ getSubStep() {
968
+ return this._subStep;
969
+ }
970
+ sendEvent() {
971
+ var _a;
972
+ const events = this._eventList;
973
+ if (!events)
974
+ return;
975
+ (_a = this._subStepStayEvents) === null || _a === void 0 ? void 0 : _a.clear();
976
+ let length = events.length;
977
+ if (length > 0) {
978
+ for (let i = 0; i < length && this._box2DWorld; i += 2) {
979
+ this._dispatchEvent(events[i], events[i + 1]);
980
+ }
981
+ let factory = Physics2D.I._factory;
982
+ for (let i = 1; i < length; i += 2) {
983
+ if (!events[i]._eventSnapshot && !events[i]._endSnapshot)
984
+ factory._cleanCache(events[i]);
985
+ }
986
+ if (events.length === length)
987
+ events.length = 0;
988
+ else
989
+ events.splice(0, length);
990
+ }
991
+ }
992
+ setVelocityIterations(velocityIterations) {
993
+ this._velocityIterations = velocityIterations;
994
+ }
995
+ getVelocityIterations() {
996
+ return this._velocityIterations;
997
+ }
998
+ setPositionIterations(positionIterations) {
999
+ this._positionIterations = positionIterations;
1000
+ }
1001
+ getPositionIterations() {
1002
+ return this._positionIterations;
1003
+ }
1004
+ getBodyCount() {
1005
+ return Physics2D.I._factory.getBodyCount(this._box2DWorld);
1006
+ }
1007
+ getJointCount() {
1008
+ return Physics2D.I._factory.getJointCount(this._box2DWorld);
1009
+ }
1010
+ getContactCount() {
1011
+ return Physics2D.I._factory.getContactCount(this._box2DWorld);
1012
+ }
1013
+ layaToPhysics2D(value) {
1014
+ return value * this._RePixelRatio;
1015
+ }
1016
+ physics2DToLaya(value) {
1017
+ return value * this._pixelRatio;
1018
+ }
1019
+ clearAllForces() {
1020
+ this._box2DWorld && Physics2D.I._factory.clearForces(this._box2DWorld);
1021
+ }
1022
+ QueryAABB(res, bounds) {
1023
+ this._JSQuerycallback.ReportFixture = function _callback(warp) {
1024
+ let fixture = Physics2D.I._factory.warpPoint(warp, exports.Ebox2DType.b2Fixture);
1025
+ if (fixture) {
1026
+ let collider = fixture.collider;
1027
+ collider && res.push(collider);
1028
+ return true;
1029
+ }
1030
+ else {
1031
+ return false;
1032
+ }
1033
+ };
1034
+ Physics2D.I._factory.QueryAABB(this._box2DWorld, this._JSQuerycallback, bounds);
1035
+ }
1036
+ RayCast(res, startPos, endPos) {
1037
+ let callback = (warp, point, normal, fraction) => {
1038
+ let fixture = Physics2D.I._factory.warpPoint(warp, exports.Ebox2DType.b2Fixture);
1039
+ if (!fixture)
1040
+ return 1;
1041
+ let v = Physics2D.I._factory.warpPoint(point, exports.Ebox2DType.b2Vec2);
1042
+ let px = v.x, py = v.y;
1043
+ v = Physics2D.I._factory.warpPoint(normal, exports.Ebox2DType.b2Vec2);
1044
+ let nx = v.x, ny = v.y;
1045
+ let hitRes = new Physics2DHitResult();
1046
+ let collider = fixture.collider;
1047
+ hitRes.collider = collider;
1048
+ hitRes.hitPoint.x = this.physics2DToLaya(px);
1049
+ hitRes.hitPoint.y = this.physics2DToLaya(py);
1050
+ hitRes.hitNormal.x = nx;
1051
+ hitRes.hitNormal.y = ny;
1052
+ hitRes.fraction = fraction;
1053
+ res.push(hitRes);
1054
+ if (collider) {
1055
+ return 1;
1056
+ }
1057
+ else {
1058
+ return 0;
1059
+ }
1060
+ };
1061
+ this._JSRayCastcallback.ReportFixture = callback.bind(this);
1062
+ Physics2D.I._factory.RayCast(this._box2DWorld, this._JSRayCastcallback, startPos, endPos);
1063
+ }
1064
+ destroy() {
1065
+ var _a;
1066
+ if (!this._box2DWorld)
1067
+ return;
1068
+ if (this._emptyBody) {
1069
+ Physics2D.I._factory.removeBody(this._box2DWorld, this._emptyBody);
1070
+ this._emptyBody = null;
1071
+ }
1072
+ if (this._debugDraw) {
1073
+ this._debugDraw.destroy();
1074
+ this._debugDraw = null;
1075
+ this._jsDraw = null;
1076
+ }
1077
+ Physics2D.I._factory.worldMap.delete(this._box2DWorld._indexInMap);
1078
+ Physics2D.I._factory.destroyWorld(this._box2DWorld);
1079
+ this._box2DWorld = null;
1080
+ this._eventList = null;
1081
+ (_a = this._subStepStayEvents) === null || _a === void 0 ? void 0 : _a.clear();
1082
+ }
1083
+ _queueContactEvent(type, pointer) {
1084
+ const factory = Physics2D.I._factory;
1085
+ const contact = factory.warpPoint(pointer, exports.Ebox2DType.b2Contact);
1086
+ const substeps = this._subStepCount > 1;
1087
+ if (!substeps && type !== "triggerexit") {
1088
+ this._eventList.push(type, contact);
1089
+ return;
1090
+ }
1091
+ const a = factory.getContactShapeA(contact);
1092
+ const b = factory.getContactShapeB(contact);
1093
+ const hit = new Physics2DContactHitResult();
1094
+ const count = factory.getContactWorldManifold(contact, hit);
1095
+ for (let i = 0; i < count; i++) {
1096
+ hit.points[i].x = this.physics2DToLaya(hit.points[i].x);
1097
+ hit.points[i].y = this.physics2DToLaya(hit.points[i].y);
1098
+ hit.separations[i] = this.physics2DToLaya(hit.separations[i]);
1099
+ }
1100
+ const snapshot = {
1101
+ _eventSnapshot: true,
1102
+ GetFixtureA: () => a,
1103
+ GetFixtureB: () => b,
1104
+ getHitInfo: () => hit
1105
+ };
1106
+ factory._cleanCache(contact);
1107
+ if (!substeps) {
1108
+ contact._endSnapshot = snapshot;
1109
+ contact.getHitInfo = snapshot.getHitInfo;
1110
+ this._eventList.push(type, snapshot);
1111
+ return;
1112
+ }
1113
+ const stays = this._subStepStayEvents || (this._subStepStayEvents = new Map());
1114
+ if (type === "triggerstay") {
1115
+ const index = stays.get(pointer);
1116
+ if (index !== undefined) {
1117
+ this._eventList[index] = snapshot;
1118
+ return;
1119
+ }
1120
+ stays.set(pointer, this._eventList.length + 1);
1121
+ }
1122
+ else {
1123
+ stays.delete(pointer);
1124
+ }
1125
+ this._eventList.push(type, snapshot);
1126
+ }
1127
+ _worldBeginContactCallback(contact) {
1128
+ this._queueContactEvent("triggerenter", contact);
1129
+ }
1130
+ _worldEndContactCallback(contact) {
1131
+ this._queueContactEvent("triggerexit", contact);
1132
+ }
1133
+ _worldPreSolveCallback(contact, oldManifold) {
1134
+ this._queueContactEvent("triggerstay", contact);
1135
+ }
1136
+ _worldPostSolveCallback(contact, impulse) {
1137
+ }
1138
+ _worldBeginTriggerCallback(contact) {
1139
+ }
1140
+ _worldEndTriggerCallback(contact) {
1141
+ }
1142
+ _worldPreTriggerCallback(contact, oldManifold) {
1143
+ }
1144
+ _worldPostTriggerCallback(contact, impulse) {
1145
+ }
1146
+ _worldContactCallback(contactListener) {
1147
+ contactListener.BeginContact = this._worldBeginContactCallback.bind(this);
1148
+ contactListener.EndContact = this._worldEndContactCallback.bind(this);
1149
+ contactListener.PreSolve = this._worldPreSolveCallback.bind(this);
1150
+ contactListener.PostSolve = this._worldPostSolveCallback.bind(this);
1151
+ return contactListener;
1152
+ }
1153
+ _makeStyleString(color, alpha = -1) {
1154
+ let colorData = Physics2D.I._factory.warpPoint(color, exports.Ebox2DType.b2Color);
1155
+ let outColor = this._tempColor;
1156
+ outColor.r = colorData.r;
1157
+ outColor.g = colorData.g;
1158
+ outColor.b = colorData.b;
1159
+ outColor.a = alpha;
1160
+ return outColor;
1161
+ }
1162
+ _enableBox2DDraw(enable, flag) {
1163
+ if (!this._jsDraw) {
1164
+ this._jsDraw = Physics2D.I._factory.createBox2DDraw(this._box2DWorld, flag);
1165
+ this._jsDraw.DrawSegment = this._debugDrawSegment.bind(this);
1166
+ this._jsDraw.DrawPolygon = this._debugDrawPolygon.bind(this);
1167
+ this._jsDraw.DrawSolidPolygon = this._debugDrawSolidPolygon.bind(this);
1168
+ this._jsDraw.DrawCircle = this._debugDrawCircle.bind(this);
1169
+ this._jsDraw.DrawSolidCircle = this._debugDrawSolidCircle.bind(this);
1170
+ this._jsDraw.DrawTransform = this._debugDrawTransform.bind(this);
1171
+ this._jsDraw.DrawPoint = this._debugDrawPoint.bind(this);
1172
+ this._jsDraw.DrawAABB = this._debugDrawAABB.bind(this);
1173
+ }
1174
+ if (enable) {
1175
+ Physics2D.I._factory.appendFlags(this._jsDraw, flag);
1176
+ }
1177
+ else {
1178
+ Physics2D.I._factory.clearFlags(this._jsDraw, flag);
1179
+ }
1180
+ }
1181
+ _debugDrawSegment(p1, p2, color) {
1182
+ let v = Physics2D.I._factory.warpPoint(p1, exports.Ebox2DType.b2Vec2);
1183
+ let p1x = this.physics2DToLaya(v.x);
1184
+ let p1y = this.physics2DToLaya(v.y);
1185
+ v = Physics2D.I._factory.warpPoint(p2, exports.Ebox2DType.b2Vec2);
1186
+ let p2x = this.physics2DToLaya(v.x);
1187
+ let p2y = this.physics2DToLaya(v.y);
1188
+ let outColor = this._makeStyleString(color, 1);
1189
+ this._debugDraw.appendLineSegment(p1x, p1y, p2x, p2y, outColor);
1190
+ }
1191
+ _debugDrawPolygon(vertices, vertexCount, color) {
1192
+ let points = this._tempPoints;
1193
+ points.length = 0;
1194
+ for (let i = 0; i < vertexCount; i++) {
1195
+ let vert = Physics2D.I._factory.warpPoint(vertices + (i * 8), exports.Ebox2DType.b2Vec2);
1196
+ points.push(this.physics2DToLaya(vert.x), this.physics2DToLaya(vert.y));
1197
+ }
1198
+ let outColor = this._makeStyleString(color, 1);
1199
+ this._debugDraw.appendPolygon(points, vertexCount, outColor);
1200
+ }
1201
+ _debugDrawSolidPolygon(vertices, vertexCount, color) {
1202
+ let points = this._tempPoints;
1203
+ points.length = 0;
1204
+ for (let i = 0; i < vertexCount; i++) {
1205
+ let vert = Physics2D.I._factory.warpPoint(vertices + (i * 8), exports.Ebox2DType.b2Vec2);
1206
+ points.push(this.physics2DToLaya(vert.x), this.physics2DToLaya(vert.y));
1207
+ }
1208
+ let outColor = this._makeStyleString(color, 0.5);
1209
+ this._debugDraw.appendPolygon(points, vertexCount, outColor);
1210
+ }
1211
+ _debugDrawCircle(center, radius, color) {
1212
+ let centerV = Physics2D.I._factory.warpPoint(center, exports.Ebox2DType.b2Vec2);
1213
+ let x = this.physics2DToLaya(centerV.x);
1214
+ let y = this.physics2DToLaya(centerV.y);
1215
+ radius = this.physics2DToLaya(radius);
1216
+ let outColor = this._makeStyleString(color, 1);
1217
+ this._debugDraw.appendCircle(x, y, radius, outColor);
1218
+ }
1219
+ _debugDrawSolidCircle(center, radius, axis, color) {
1220
+ let v = Physics2D.I._factory.warpPoint(center, exports.Ebox2DType.b2Vec2);
1221
+ let cx = this.physics2DToLaya(v.x);
1222
+ let cy = this.physics2DToLaya(v.y);
1223
+ radius = this.physics2DToLaya(radius);
1224
+ let outColor = this._makeStyleString(color, 0.5);
1225
+ this._debugDraw.appendCircle(cx, cy, radius, outColor);
1226
+ }
1227
+ _debugDrawTransform(xf) {
1228
+ xf = Physics2D.I._factory.warpPoint(xf, exports.Ebox2DType.b2Transform);
1229
+ const length = 1 / Laya.Browser.pixelRatio;
1230
+ let x = this.physics2DToLaya(xf.x);
1231
+ let y = this.physics2DToLaya(xf.y);
1232
+ let cosAngle = Math.cos(xf.angle);
1233
+ let sinAngle = Math.sin(xf.angle);
1234
+ let xAxisEndX = x + this.physics2DToLaya(length * cosAngle);
1235
+ let xAxisEndY = y + this.physics2DToLaya(length * sinAngle);
1236
+ let yAxisEndX = x + this.physics2DToLaya(length * (-sinAngle));
1237
+ let yAxisEndY = y + this.physics2DToLaya(length * cosAngle);
1238
+ this._debugDraw.appendLineSegment(x, y, xAxisEndX, xAxisEndY, Laya.Color.RED);
1239
+ this._debugDraw.appendLineSegment(x, y, yAxisEndX, yAxisEndY, Laya.Color.GREEN);
1240
+ }
1241
+ _debugDrawPoint(p, size, color) {
1242
+ p = Physics2D.I._factory.warpPoint(p, exports.Ebox2DType.b2Vec2);
1243
+ size *= this._debugDraw._camera.m_zoom;
1244
+ size /= this._debugDraw._camera.m_extent;
1245
+ var hsize = size / 2;
1246
+ let outColor = this._makeStyleString(color, 1);
1247
+ let lx = this.physics2DToLaya(p.x - hsize);
1248
+ let rx = this.physics2DToLaya(p.x + hsize);
1249
+ let ty = this.physics2DToLaya(p.y - hsize);
1250
+ let by = this.physics2DToLaya(p.y + hsize);
1251
+ this._debugDraw.appendLineSegment(lx, ty, rx, ty, outColor);
1252
+ this._debugDraw.appendLineSegment(rx, ty, rx, by, outColor);
1253
+ this._debugDraw.appendLineSegment(rx, by, lx, by, outColor);
1254
+ this._debugDraw.appendLineSegment(lx, by, lx, ty, outColor);
1255
+ }
1256
+ _debugDrawAABB(min, max, color) {
1257
+ let v = Physics2D.I._factory.warpPoint(min, exports.Ebox2DType.b2Vec2);
1258
+ let minX = v.x, minY = v.y;
1259
+ v = Physics2D.I._factory.warpPoint(max, exports.Ebox2DType.b2Vec2);
1260
+ let maxX = v.x, maxY = v.y;
1261
+ var cx = (maxX + minX) * 0.5;
1262
+ var cy = (maxY + minY) * 0.5;
1263
+ var hw = (maxX - minX) * 0.5;
1264
+ var hh = (maxY - minY) * 0.5;
1265
+ let outColor = this._makeStyleString(color, 1);
1266
+ let lx = this.physics2DToLaya(cx - hw);
1267
+ let rx = this.physics2DToLaya(cx + hw);
1268
+ let ty = this.physics2DToLaya(cy - hh);
1269
+ let by = this.physics2DToLaya(cy + hh);
1270
+ this._debugDraw.appendLineSegment(lx, ty, rx, ty, outColor);
1271
+ this._debugDraw.appendLineSegment(lx, by, rx, by, outColor);
1272
+ this._debugDraw.appendLineSegment(lx, ty, lx, by, outColor);
1273
+ this._debugDraw.appendLineSegment(rx, ty, rx, by, outColor);
1274
+ }
1275
+ _dispatchEvent(type, contact) {
1276
+ contact = contact._endSnapshot || contact;
1277
+ let contactShapeA = Physics2D.I._factory.getContactShapeA(contact);
1278
+ let contactShapeB = Physics2D.I._factory.getContactShapeB(contact);
1279
+ if (contactShapeA == null || contactShapeB == null) {
1280
+ return;
1281
+ }
1282
+ if (type !== "triggerexit" && (contactShapeA.destroyed || contactShapeB.destroyed))
1283
+ return;
1284
+ let colliderA = contactShapeA.collider;
1285
+ let colliderB = contactShapeB.collider;
1286
+ if (colliderA == null || colliderB == null) {
1287
+ return;
1288
+ }
1289
+ if (colliderA.destroyed || colliderB.destroyed) {
1290
+ return;
1291
+ }
1292
+ let ownerA = colliderA.owner;
1293
+ let ownerB = colliderB.owner;
1294
+ let __this = this;
1295
+ let _hitResult;
1296
+ if (!contact._eventSnapshot)
1297
+ contact.getHitInfo = function () {
1298
+ if (contact._endSnapshot)
1299
+ return contact._endSnapshot.getHitInfo();
1300
+ if (!_hitResult)
1301
+ _hitResult = new Physics2DContactHitResult();
1302
+ let pointCount = Physics2D.I._factory.getContactWorldManifold(contact, _hitResult);
1303
+ for (let i = 0; i < pointCount; i++) {
1304
+ _hitResult.points[i].x = __this.physics2DToLaya(_hitResult.points[i].x);
1305
+ _hitResult.points[i].y = __this.physics2DToLaya(_hitResult.points[i].y);
1306
+ _hitResult.separations[i] = __this.physics2DToLaya(_hitResult.separations[i]);
1307
+ }
1308
+ return _hitResult;
1309
+ };
1310
+ if (ownerA) {
1311
+ var args = [colliderB, colliderA, contact];
1312
+ ownerA.event(type, args);
1313
+ }
1314
+ if (ownerB && this._box2DWorld && !colliderA.destroyed && !colliderB.destroyed) {
1315
+ args = [colliderA, colliderB, contact];
1316
+ ownerB.event(type, args);
1317
+ }
1318
+ }
1319
+ }
1320
+ Physics2DWorldManager.__managerName = "Physics2DWorldManager";
1321
+ Laya.Scene.regManager(Physics2DWorldManager.__managerName, Physics2DWorldManager);
1322
+
1323
+ const _tempWorldPoint = new Laya.Point();
1324
+ const _tempBodyPosition = new Laya.Vector2();
1325
+ class ColliderBase extends Laya.Component {
1326
+ get isConnectedJoint() {
1327
+ return this._isConnectedJoint;
1328
+ }
1329
+ set isConnectedJoint(value) {
1330
+ this._isConnectedJoint = value;
1331
+ }
1332
+ get inertia() {
1333
+ let inertia;
1334
+ if (this._useAutoMass) {
1335
+ inertia = this.getInertia();
1336
+ }
1337
+ else {
1338
+ inertia = this._inertia;
1339
+ }
1340
+ return inertia;
1341
+ }
1342
+ set inertia(value) {
1343
+ this._inertia = value;
1344
+ if (!this._useAutoMass) {
1345
+ this._box2DBody && Physics2D.I._factory.set_rigidBody_Mass(this._box2DBody, this._mass, this._centerOfMass, this._inertia, this._massData);
1346
+ }
1347
+ }
1348
+ get centerOfMass() {
1349
+ let center;
1350
+ if (this._useAutoMass && this._box2DBody) {
1351
+ center = Physics2D.I._factory.get_rigidBody_Center(this._box2DBody);
1352
+ this._centerOfMass.x = center.x;
1353
+ this._centerOfMass.y = center.y;
1354
+ }
1355
+ else {
1356
+ center = this._centerOfMass;
1357
+ }
1358
+ return center;
1359
+ }
1360
+ set centerOfMass(value) {
1361
+ if (value instanceof Laya.Vector2) {
1362
+ this._centerOfMass = value;
1363
+ }
1364
+ else {
1365
+ this._centerOfMass.x = value.x;
1366
+ this._centerOfMass.y = value.y;
1367
+ }
1368
+ if (!this._useAutoMass) {
1369
+ this._box2DBody && Physics2D.I._factory.set_rigidBody_Mass(this._box2DBody, this._mass, this._centerOfMass, this._inertia, this._massData);
1370
+ }
1371
+ }
1372
+ get mass() {
1373
+ let mass;
1374
+ if (this._useAutoMass && this._box2DBody) {
1375
+ mass = Physics2D.I._factory.get_rigidBody_Mass(this._box2DBody);
1376
+ }
1377
+ else {
1378
+ mass = this._mass;
1379
+ }
1380
+ return mass;
1381
+ }
1382
+ set mass(value) {
1383
+ this._mass = value;
1384
+ if (!this._useAutoMass) {
1385
+ this._box2DBody && Physics2D.I._factory.set_rigidBody_Mass(this._box2DBody, this._mass, this._centerOfMass, this._inertia, this._massData);
1386
+ }
1387
+ }
1388
+ get useAutoMass() {
1389
+ return this._useAutoMass;
1390
+ }
1391
+ set useAutoMass(value) {
1392
+ if (this._useAutoMass === value)
1393
+ return;
1394
+ this._useAutoMass = value;
1395
+ this._resetMassData();
1396
+ }
1397
+ _resetMassData() {
1398
+ if (!this._box2DBody || this._box2DBody.destroyed)
1399
+ return;
1400
+ const factory = Physics2D.I._factory;
1401
+ if (this._useAutoMass)
1402
+ factory.retSet_rigidBody_MassData(this._box2DBody);
1403
+ else if (this._massData)
1404
+ factory.set_rigidBody_Mass(this._box2DBody, this._mass, this._centerOfMass, this._inertia, this._massData);
1405
+ }
1406
+ get isAwake() {
1407
+ if (this._box2DBody) {
1408
+ this._isAwake = Physics2D.I._factory.get_rigidBody_IsAwake(this._box2DBody);
1409
+ }
1410
+ return this._isAwake;
1411
+ }
1412
+ set isAwake(value) {
1413
+ this._isAwake = value;
1414
+ this._box2DBody && Physics2D.I._factory.set_rigidBody_Awake(this._box2DBody, value);
1415
+ }
1416
+ get scaleX() {
1417
+ return Physics2D.getDesignScaleX(this.owner);
1418
+ }
1419
+ get scaleY() {
1420
+ return Physics2D.getDesignScaleY(this.owner);
1421
+ }
1422
+ get pivotoffx() {
1423
+ return this._x - this.owner.pivotX;
1424
+ }
1425
+ get pivotoffy() {
1426
+ return this._y - this.owner.pivotY;
1427
+ }
1428
+ get x() {
1429
+ return this._x;
1430
+ }
1431
+ set x(value) {
1432
+ if (this._x == value)
1433
+ return;
1434
+ this._x = value;
1435
+ this._needupdataShapeAttribute();
1436
+ }
1437
+ get y() {
1438
+ return this._y;
1439
+ }
1440
+ set y(value) {
1441
+ if (this._y == value)
1442
+ return;
1443
+ this._y = value;
1444
+ this._needupdataShapeAttribute();
1445
+ }
1446
+ constructor() {
1447
+ super();
1448
+ this._isAwake = true;
1449
+ this._useAutoMass = true;
1450
+ this._mass = 1;
1451
+ this._inertia = 10;
1452
+ this._centerOfMass = new Laya.Vector2(0.5, 0.5);
1453
+ this._bodyDef = new RigidBody2DInfo();
1454
+ this._x = 0;
1455
+ this._y = 0;
1456
+ this._isConnectedJoint = false;
1457
+ this._lastPhysicsScaleX = NaN;
1458
+ this._lastPhysicsScaleY = NaN;
1459
+ this._shapeDef = new Box2DShapeDef();
1460
+ this._isSensor = false;
1461
+ this._density = 10;
1462
+ this._friction = 0.2;
1463
+ this._restitution = 0;
1464
+ this._singleton = false;
1465
+ }
1466
+ getBox2DBody() {
1467
+ if (this._box2DBody) {
1468
+ return this._box2DBody;
1469
+ }
1470
+ }
1471
+ getInertia() {
1472
+ if (!this._box2DBody)
1473
+ return this._inertia;
1474
+ return Physics2D.I._factory.get_rigidBody_Inertia(this._box2DBody);
1475
+ }
1476
+ _onEnable() {
1477
+ this._getPhysicsManager();
1478
+ this._box2DBodyDef = Physics2D.I._factory.createBodyDef(this._physics2DManager.box2DWorld, this._bodyDef);
1479
+ this._box2DBody = Physics2D.I._factory.createBody(this._physics2DManager.box2DWorld, this._box2DBodyDef);
1480
+ this.owner.on(Laya.SpriteGlobalTransform.CHANGED, this, this._onOwnerGlobalTransformChanged);
1481
+ this._lastPhysicsScaleX = this.scaleX;
1482
+ this._lastPhysicsScaleY = this.scaleY;
1483
+ }
1484
+ _getPhysicsManager() {
1485
+ var _a, _b;
1486
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
1487
+ }
1488
+ getWorldPoint(x, y) {
1489
+ return Physics2D.localToDesignPoint(this.owner, x, y, _tempWorldPoint);
1490
+ }
1491
+ _onOwnerGlobalTransformChanged() {
1492
+ const scaleX = this.scaleX;
1493
+ const scaleY = this.scaleY;
1494
+ const scaleChanged = Math.abs(scaleX - this._lastPhysicsScaleX) > 1e-6
1495
+ || Math.abs(scaleY - this._lastPhysicsScaleY) > 1e-6;
1496
+ if (scaleChanged) {
1497
+ this._lastPhysicsScaleX = scaleX;
1498
+ this._lastPhysicsScaleY = scaleY;
1499
+ this._onPhysicsScaleChanged();
1500
+ this.owner.event("shapeChange");
1501
+ }
1502
+ this._updateStaticBodyTransform();
1503
+ }
1504
+ _onPhysicsScaleChanged() {
1505
+ if (this._rigidbody && this._rigidbody.applyOwnerColliderComponent) {
1506
+ this.createShape(this._rigidbody);
1507
+ }
1508
+ }
1509
+ _updateStaticBodyTransform() {
1510
+ const sp = this.owner;
1511
+ if (this._box2DBody) {
1512
+ Physics2D.getDesignPosition(sp, _tempWorldPoint);
1513
+ const factory = Physics2D.I._factory;
1514
+ factory.get_RigidBody_Position(this._box2DBody, _tempBodyPosition);
1515
+ const angle = Physics2D.getDesignRotation(sp) * Math.PI / 180;
1516
+ const oldAngle = factory.get_RigidBody_Angle(this._box2DBody);
1517
+ if (Math.abs(_tempBodyPosition.x - _tempWorldPoint.x) > 1e-4
1518
+ || Math.abs(_tempBodyPosition.y - _tempWorldPoint.y) > 1e-4
1519
+ || Math.abs(oldAngle - angle) > 1e-6) {
1520
+ factory.set_RigibBody_Transform(this._box2DBody, _tempWorldPoint.x, _tempWorldPoint.y, angle);
1521
+ factory.set_rigidBody_Awake(this._box2DBody, true);
1522
+ }
1523
+ }
1524
+ }
1525
+ _needupdataShapeAttribute() {
1526
+ if (this._rigidbody && this._rigidbody.applyOwnerColliderComponent) {
1527
+ this.createShape(this._rigidbody);
1528
+ }
1529
+ this._lastPhysicsScaleX = this.scaleX;
1530
+ this._lastPhysicsScaleY = this.scaleY;
1531
+ this._updateStaticBodyTransform();
1532
+ this.owner.event("shapeChange");
1533
+ }
1534
+ _onDisable() {
1535
+ this._box2DBody && Physics2D.I._factory.removeBody(this._physics2DManager.box2DWorld, this._box2DBody);
1536
+ this._box2DBody = null;
1537
+ this._box2DBodyDef && Physics2D.I._factory.destroyData(this._box2DBodyDef);
1538
+ this._box2DBodyDef = null;
1539
+ this.owner.off(Laya.SpriteGlobalTransform.CHANGED, this, this._onOwnerGlobalTransformChanged);
1540
+ }
1541
+ _onDestroy() {
1542
+ this._box2DBody && Physics2D.I._factory.removeBody(this._physics2DManager.box2DWorld, this._box2DBody);
1543
+ this._box2DBodyDef && Physics2D.I._factory.destroyData(this._box2DBodyDef);
1544
+ this._box2DBody = null;
1545
+ this._box2DBodyDef = null;
1546
+ }
1547
+ get isSensor() {
1548
+ return this._isSensor;
1549
+ }
1550
+ set isSensor(value) {
1551
+ if (this._isSensor == value)
1552
+ return;
1553
+ this._isSensor = value;
1554
+ this._needupdataShapeAttribute();
1555
+ }
1556
+ get density() {
1557
+ return this._density;
1558
+ }
1559
+ set density(value) {
1560
+ if (this._density == value)
1561
+ return;
1562
+ this._density = value;
1563
+ this._needupdataShapeAttribute();
1564
+ }
1565
+ get friction() {
1566
+ return this._friction;
1567
+ }
1568
+ set friction(value) {
1569
+ if (this._friction == value)
1570
+ return;
1571
+ this._friction = value;
1572
+ this._needupdataShapeAttribute();
1573
+ }
1574
+ get restitution() {
1575
+ return this._restitution;
1576
+ }
1577
+ set restitution(value) {
1578
+ if (this._restitution == value)
1579
+ return;
1580
+ this._restitution = value;
1581
+ this._needupdataShapeAttribute();
1582
+ }
1583
+ createShape(collider) {
1584
+ }
1585
+ _setRigidbodyValue(collider) {
1586
+ }
1587
+ }
1588
+
1589
+ const _tempV0$1 = new Laya.Vector2();
1590
+ const _tempP0 = new Laya.Point();
1591
+ class RigidBody extends ColliderBase {
1592
+ get body() {
1593
+ return this._box2DBody;
1594
+ }
1595
+ get type() {
1596
+ return this._type;
1597
+ }
1598
+ set type(value) {
1599
+ if (value !== "dynamic" && value !== "kinematic") {
1600
+ console.warn("Rigidbody only can set as dynamic or kinematic.");
1601
+ }
1602
+ this._type = value;
1603
+ this._updateBodyType();
1604
+ }
1605
+ get gravityScale() {
1606
+ return this._gravityScale;
1607
+ }
1608
+ set gravityScale(value) {
1609
+ this._gravityScale = value;
1610
+ if (this._box2DBody)
1611
+ Physics2D.I._factory.set_rigidBody_gravityScale(this._box2DBody, value);
1612
+ }
1613
+ get allowRotation() {
1614
+ return this._allowRotation;
1615
+ }
1616
+ set allowRotation(value) {
1617
+ this._allowRotation = value;
1618
+ if (this._box2DBody)
1619
+ Physics2D.I._factory.set_rigidBody_allowRotation(this._box2DBody, value);
1620
+ }
1621
+ get allowSleep() {
1622
+ return this._allowSleep;
1623
+ }
1624
+ set allowSleep(value) {
1625
+ this._allowSleep = value;
1626
+ if (this._box2DBody)
1627
+ Physics2D.I._factory.set_rigidBody_allowSleep(this._box2DBody, value);
1628
+ }
1629
+ get angularDamping() {
1630
+ return this._angularDamping;
1631
+ }
1632
+ set angularDamping(value) {
1633
+ this._angularDamping = value;
1634
+ if (this._box2DBody)
1635
+ Physics2D.I._factory.set_rigidBody_angularDamping(this._box2DBody, value);
1636
+ }
1637
+ get angularVelocity() {
1638
+ if (this._box2DBody)
1639
+ return Physics2D.I._factory.get_rigidBody_angularVelocity(this._box2DBody);
1640
+ return this._angularVelocity;
1641
+ }
1642
+ set angularVelocity(value) {
1643
+ this._angularVelocity = value;
1644
+ if (this._type == "static") {
1645
+ return;
1646
+ }
1647
+ if (this._box2DBody)
1648
+ Physics2D.I._factory.set_rigidBody_angularVelocity(this._box2DBody, value);
1649
+ }
1650
+ get linearDamping() {
1651
+ return this._linearDamping;
1652
+ }
1653
+ set linearDamping(value) {
1654
+ this._linearDamping = value;
1655
+ if (this._box2DBody)
1656
+ Physics2D.I._factory.set_rigidBody_linearDamping(this._box2DBody, value);
1657
+ }
1658
+ get linearVelocity() {
1659
+ if (this._box2DBody) {
1660
+ var vec = Physics2D.I._factory.get_rigidBody_linearVelocity(this._box2DBody);
1661
+ vec.x = vec.x;
1662
+ vec.y = vec.y;
1663
+ return { x: vec.x, y: vec.y };
1664
+ }
1665
+ return this._linearVelocity;
1666
+ }
1667
+ set linearVelocity(value) {
1668
+ if (!value)
1669
+ return;
1670
+ if (value instanceof Array) {
1671
+ throw new Error('set linearVelocity: value is not implement IV2');
1672
+ }
1673
+ this._linearVelocity = value;
1674
+ if (this._type == "static") {
1675
+ return;
1676
+ }
1677
+ if (this._box2DBody)
1678
+ Physics2D.I._factory.set_rigidBody_linearVelocity(this._box2DBody, value);
1679
+ }
1680
+ get bullet() {
1681
+ return this._bullet;
1682
+ }
1683
+ set bullet(value) {
1684
+ this._bullet = value;
1685
+ if (this._box2DBody)
1686
+ Physics2D.I._factory.set_rigidBody_bullet(this._box2DBody, value);
1687
+ }
1688
+ get shapes() {
1689
+ return this._shapes;
1690
+ }
1691
+ set shapes(shapes) {
1692
+ const next = shapes || [];
1693
+ for (const shape of this._shapes || []) {
1694
+ if (next.indexOf(shape) < 0)
1695
+ shape.destroy();
1696
+ }
1697
+ this._shapes = shapes;
1698
+ if (shapes)
1699
+ this.applyOwnerColliderComponent = false;
1700
+ shapes = next;
1701
+ shapes.forEach((shape) => {
1702
+ shape.setCollider(this);
1703
+ });
1704
+ if (this._useAutoMass) {
1705
+ this._box2DBody && Physics2D.I._factory.retSet_rigidBody_MassData(this._box2DBody);
1706
+ }
1707
+ else {
1708
+ this._box2DBody && Physics2D.I._factory.set_rigidBody_Mass(this._box2DBody, this._mass, this._centerOfMass, this._inertia, this._massData);
1709
+ }
1710
+ }
1711
+ get applyOwnerColliderComponent() {
1712
+ return this._applyOwnerColliderComponent;
1713
+ }
1714
+ set applyOwnerColliderComponent(value) {
1715
+ this._applyOwnerColliderComponent = value;
1716
+ }
1717
+ set position(pos) {
1718
+ if (!this._box2DBody)
1719
+ return;
1720
+ var factory = Physics2D.I._factory;
1721
+ let rotateValue = factory.get_RigidBody_Angle(this._box2DBody);
1722
+ _tempP0.x = pos.x;
1723
+ _tempP0.y = pos.y;
1724
+ let globalPos = this.owner.parent.localToGlobal(_tempP0);
1725
+ factory.set_RigibBody_Transform(this._box2DBody, globalPos.x, globalPos.y, rotateValue);
1726
+ factory.set_rigidBody_Awake(this._box2DBody, true);
1727
+ Physics2D.I._addRigidBody(this);
1728
+ }
1729
+ get position() {
1730
+ if (!this._box2DBody) {
1731
+ _tempP0.x = this.owner.x;
1732
+ _tempP0.y = this.owner.y;
1733
+ return _tempP0;
1734
+ }
1735
+ var pos = Laya.Vector2.TEMP;
1736
+ Physics2D.I._factory.get_RigidBody_Position(this._box2DBody, pos);
1737
+ _tempP0.x = pos.x;
1738
+ _tempP0.y = pos.y;
1739
+ let localPos = this.owner.parent.globalToLocal(_tempP0);
1740
+ _tempP0.x = localPos.x;
1741
+ _tempP0.y = localPos.y;
1742
+ return _tempP0;
1743
+ }
1744
+ set rotation(number) {
1745
+ if (!this._box2DBody)
1746
+ return;
1747
+ var factory = Physics2D.I._factory;
1748
+ var pos = Laya.Vector2.TEMP;
1749
+ factory.get_RigidBody_Position(this._box2DBody, pos);
1750
+ pos.setValue(pos.x, pos.y);
1751
+ factory.set_RigibBody_Transform(this._box2DBody, pos.x, pos.y, Laya.Utils.toRadian(number));
1752
+ factory.set_rigidBody_Awake(this._box2DBody, true);
1753
+ Physics2D.I._addRigidBody(this);
1754
+ }
1755
+ get rotation() {
1756
+ if (!this._box2DBody)
1757
+ return this.owner.rotation;
1758
+ return Laya.Utils.toAngle(Physics2D.I._factory.get_RigidBody_Angle(this._box2DBody));
1759
+ }
1760
+ constructor() {
1761
+ super();
1762
+ this._allowSleep = true;
1763
+ this._angularVelocity = 0;
1764
+ this._angularDamping = 0;
1765
+ this._linearVelocity = { x: 0, y: 0 };
1766
+ this._linearDamping = 0;
1767
+ this._bullet = false;
1768
+ this._allowRotation = true;
1769
+ this._gravityScale = 1;
1770
+ this._colliders = [];
1771
+ this.group = 0;
1772
+ this.category = 1;
1773
+ this.mask = -1;
1774
+ this.label = "RigidBody";
1775
+ this._applyOwnerColliderComponent = true;
1776
+ this._type = "dynamic";
1777
+ this._massData = Physics2D.I._factory.createMassData();
1778
+ }
1779
+ _updateBodyType() {
1780
+ if (!this._box2DBody)
1781
+ return;
1782
+ Physics2D.I._factory.set_rigidBody_type(this._box2DBody, this._type);
1783
+ if (this.type == "static") {
1784
+ Physics2D.I._removeRigidBody(this);
1785
+ }
1786
+ else {
1787
+ Physics2D.I._addRigidBody(this);
1788
+ }
1789
+ }
1790
+ _globalChangeHandler(flag) {
1791
+ this._updatePhysicsTransformToRender();
1792
+ }
1793
+ _onPhysicsScaleChanged() {
1794
+ if (this.applyOwnerColliderComponent) {
1795
+ for (let i = 0, n = this._colliders.length; i < n; i++) {
1796
+ this._colliders[i].createShape(this);
1797
+ }
1798
+ }
1799
+ else if (this._shapes) {
1800
+ for (let i = 0, n = this._shapes.length; i < n; i++) {
1801
+ this._shapes[i].setCollider(this);
1802
+ }
1803
+ if (this._useAutoMass) {
1804
+ this._box2DBody && Physics2D.I._factory.retSet_rigidBody_MassData(this._box2DBody);
1805
+ }
1806
+ else {
1807
+ this._box2DBody && Physics2D.I._factory.set_rigidBody_Mass(this._box2DBody, this._mass, this._centerOfMass, this._inertia, this._massData);
1808
+ }
1809
+ }
1810
+ }
1811
+ _onAwake() {
1812
+ this.owner.globalTrans.cache = true;
1813
+ }
1814
+ _setBodyDefValue() {
1815
+ if (this._type == "static") {
1816
+ let owner = this.owner;
1817
+ Physics2D.getDesignPosition(owner, _tempP0);
1818
+ this._bodyDef.position.setValue(_tempP0.x, _tempP0.y);
1819
+ this._bodyDef.angle = Laya.Utils.toRadian(Physics2D.getDesignRotation(owner));
1820
+ this._bodyDef.allowSleep = false;
1821
+ this._bodyDef.angularVelocity = 0;
1822
+ this._bodyDef.angularDamping = 0;
1823
+ this._bodyDef.linearDamping = 0;
1824
+ this._bodyDef.linearVelocity.setValue(0, 0);
1825
+ this._bodyDef.bullet = false;
1826
+ this._bodyDef.fixedRotation = false;
1827
+ this._bodyDef.gravityScale = 0;
1828
+ return;
1829
+ }
1830
+ let owner = this.owner;
1831
+ Physics2D.getDesignPosition(owner, _tempP0);
1832
+ this._bodyDef.position.setValue(_tempP0.x, _tempP0.y);
1833
+ this._bodyDef.angle = Laya.Utils.toRadian(Physics2D.getDesignRotation(owner));
1834
+ this._bodyDef.fixedRotation = !this._allowRotation;
1835
+ this._bodyDef.allowSleep = this._allowSleep;
1836
+ this._bodyDef.angularVelocity = this._angularVelocity;
1837
+ this._bodyDef.angularDamping = this._angularDamping;
1838
+ this._bodyDef.linearDamping = this._linearDamping;
1839
+ if (this._linearVelocity.x != 0 || this._linearVelocity.y != 0) {
1840
+ this._bodyDef.linearVelocity.setValue(this._linearVelocity.x, this._linearVelocity.y);
1841
+ }
1842
+ this._bodyDef.type = this._type;
1843
+ this._bodyDef.bullet = this._bullet;
1844
+ this._bodyDef.gravityScale = this._gravityScale;
1845
+ this._bodyDef.group = this.group;
1846
+ }
1847
+ _onEnable() {
1848
+ this.owner.globalTrans.cache = true;
1849
+ this._setBodyDefValue();
1850
+ super._onEnable();
1851
+ this._updateBodyType();
1852
+ if (this.applyOwnerColliderComponent) {
1853
+ this._colliders = this.owner.getComponents(ColliderBase);
1854
+ this._colliders.forEach((collider) => {
1855
+ collider.createShape(this);
1856
+ });
1857
+ }
1858
+ else {
1859
+ this.shapes = this._shapes;
1860
+ }
1861
+ if (this.isConnectedJoint) {
1862
+ this.owner.event("bodyCreated");
1863
+ this.isConnectedJoint = false;
1864
+ }
1865
+ this.angularVelocity = this._angularVelocity;
1866
+ this.linearVelocity = this._linearVelocity;
1867
+ }
1868
+ getBody() {
1869
+ if (!this._box2DBody)
1870
+ this._onAwake();
1871
+ return this._box2DBody;
1872
+ }
1873
+ _updatePhysicsTransformToRender() {
1874
+ if (this.type == "static") {
1875
+ return;
1876
+ }
1877
+ var factory = Physics2D.I._factory;
1878
+ if (Physics2D.I._factory.get_rigidBody_IsAwake(this._box2DBody)) {
1879
+ var pos = Laya.Vector2.TEMP;
1880
+ factory.get_RigidBody_Position(this._box2DBody, pos);
1881
+ Physics2D.setDesignPosition(this.owner, pos.x, pos.y, _tempP0);
1882
+ Physics2D.setDesignRotation(this.owner, Laya.Utils.toAngle(factory.get_RigidBody_Angle(this._box2DBody)));
1883
+ }
1884
+ }
1885
+ _destroyAllShape() {
1886
+ if (this._box2DBody) {
1887
+ const colliders = this.owner.getComponents(StaticCollider);
1888
+ for (const collider of colliders || []) {
1889
+ if (collider.getBox2DBody() === this._box2DBody)
1890
+ collider._removeShapeAndDestroyData();
1891
+ }
1892
+ }
1893
+ if (!this._shapes)
1894
+ return;
1895
+ for (let i = 0; i < this._shapes.length; i++) {
1896
+ let shape = this._shapes[i];
1897
+ shape.destroy();
1898
+ }
1899
+ }
1900
+ _onDisable() {
1901
+ Physics2D.I._removeRigidBody(this);
1902
+ this._destroyAllShape();
1903
+ super._onDisable();
1904
+ }
1905
+ _onDestroy() {
1906
+ this._destroyAllShape();
1907
+ Physics2D.I._removeRigidBody(this);
1908
+ this._box2DBody && Physics2D.I._factory.removeBody(this._physics2DManager.box2DWorld, this._box2DBody);
1909
+ super._onDestroy();
1910
+ Physics2D.I._factory.destroyData(this._massData);
1911
+ this._massData = null;
1912
+ }
1913
+ getUserData() {
1914
+ if (!this._box2DBody)
1915
+ return;
1916
+ return Physics2D.I._factory.get_rigidBody_userData(this._box2DBody);
1917
+ }
1918
+ getLinearVelocityFromWorldPoint(worldPoint) {
1919
+ if (!this._box2DBody)
1920
+ return _tempV0$1;
1921
+ let velocity = Physics2D.I._factory.get_rigidBody_linearVelocityFromWorldPoint(this._box2DBody, worldPoint);
1922
+ _tempV0$1.x = velocity.x;
1923
+ _tempV0$1.y = velocity.y;
1924
+ return _tempV0$1;
1925
+ }
1926
+ getLinearVelocityFromLocalPoint(localPoint) {
1927
+ if (!this._box2DBody)
1928
+ return _tempV0$1;
1929
+ let velocity = Physics2D.I._factory.get_rigidBody_linearVelocityFromLocalPoint(this._box2DBody, localPoint);
1930
+ _tempV0$1.x = velocity.x;
1931
+ _tempV0$1.y = velocity.y;
1932
+ return _tempV0$1;
1933
+ }
1934
+ applyForce(position, force, wake = true) {
1935
+ if (!this._box2DBody)
1936
+ return;
1937
+ Physics2D.I._factory.rigidBody_applyForce(this._box2DBody, force, position, wake);
1938
+ }
1939
+ applyForceToCenter(force, wake = true) {
1940
+ if (!this._box2DBody)
1941
+ return;
1942
+ Physics2D.I._factory.rigidBody_applyForceToCenter(this._box2DBody, force, wake);
1943
+ }
1944
+ applyLinearImpulse(position, impulse, wake = true) {
1945
+ if (!this._box2DBody)
1946
+ return;
1947
+ Physics2D.I._factory.rigidbody_ApplyLinearImpulse(this._box2DBody, impulse, position, wake);
1948
+ }
1949
+ applyLinearImpulseToCenter(impulse, wake = true) {
1950
+ if (!this._box2DBody)
1951
+ return;
1952
+ Physics2D.I._factory.rigidbody_ApplyLinearImpulseToCenter(this._box2DBody, impulse, wake);
1953
+ }
1954
+ applyAngularImpulse(impulse, wake = true) {
1955
+ if (!this._box2DBody)
1956
+ return;
1957
+ Physics2D.I._factory.rigidbody_ApplyAngularImpulse(this._box2DBody, impulse, wake);
1958
+ }
1959
+ applyTorque(torque, wake = true) {
1960
+ if (!this._box2DBody)
1961
+ return;
1962
+ Physics2D.I._factory.rigidbody_applyTorque(this._box2DBody, torque, wake);
1963
+ }
1964
+ setVelocity(velocity) {
1965
+ if (!this._box2DBody)
1966
+ return;
1967
+ Physics2D.I._factory.set_rigidBody_linearVelocity(this._box2DBody, velocity);
1968
+ }
1969
+ setAngle(value) {
1970
+ if (!this._box2DBody)
1971
+ return;
1972
+ var factory = Physics2D.I._factory;
1973
+ Physics2D.getDesignPosition(this.owner, _tempP0);
1974
+ factory.set_RigibBody_Transform(this._box2DBody, _tempP0.x, _tempP0.y, Laya.Utils.toRadian(value));
1975
+ factory.set_rigidBody_Awake(this._box2DBody, true);
1976
+ }
1977
+ getMass() {
1978
+ return this._box2DBody ? Physics2D.I._factory.get_rigidBody_Mass(this._box2DBody) : 0;
1979
+ }
1980
+ getCenter() {
1981
+ let center = this._box2DBody ? Physics2D.I._factory.get_rigidBody_Center(this._box2DBody) : null;
1982
+ center.x = center.x;
1983
+ center.y = center.y;
1984
+ return center;
1985
+ }
1986
+ getInertia() {
1987
+ if (!this._box2DBody)
1988
+ return this._inertia;
1989
+ return Physics2D.I._factory.get_rigidBody_Inertia(this._box2DBody);
1990
+ }
1991
+ getWorldCenter() {
1992
+ let center = this._box2DBody ? Physics2D.I._factory.get_rigidBody_WorldCenter(this._box2DBody) : null;
1993
+ center.x = center.x;
1994
+ center.y = center.y;
1995
+ return center;
1996
+ }
1997
+ getWorldPoint(x, y) {
1998
+ return Physics2D.localToDesignPoint(this.owner, x, y, _tempP0);
1999
+ }
2000
+ getLocalPoint(x, y) {
2001
+ return Physics2D.designToLocalPoint(this.owner, x, y, _tempP0);
2002
+ }
2003
+ }
2004
+
2005
+ class StaticCollider extends ColliderBase {
2006
+ get type() {
2007
+ return this._type;
2008
+ }
2009
+ set type(value) {
2010
+ if (value != "static") {
2011
+ console.warn("StaticCollider only can set as static.");
2012
+ value = "static";
2013
+ }
2014
+ this._type = value;
2015
+ }
2016
+ get shapes() {
2017
+ return this._shapes;
2018
+ }
2019
+ set shapes(value) {
2020
+ const next = value || [];
2021
+ for (const shape of this._shapes || []) {
2022
+ if (next.indexOf(shape) < 0)
2023
+ shape.destroy();
2024
+ }
2025
+ this._shapes = value = next;
2026
+ value.forEach((shape) => {
2027
+ shape.setCollider(this);
2028
+ });
2029
+ }
2030
+ constructor() {
2031
+ super();
2032
+ this.label = "StaticCollider";
2033
+ this._shapes = [];
2034
+ }
2035
+ _setBodyDefValue() {
2036
+ let owner = this.owner;
2037
+ Physics2D.getDesignPosition(owner, _tempPosition);
2038
+ this._bodyDef.position.setValue(_tempPosition.x, _tempPosition.y);
2039
+ this._bodyDef.angle = Laya.Utils.toRadian(Physics2D.getDesignRotation(owner));
2040
+ this._bodyDef.allowSleep = false;
2041
+ this._bodyDef.angularVelocity = 0;
2042
+ this._bodyDef.angularDamping = 0;
2043
+ this._bodyDef.linearDamping = 0;
2044
+ this._bodyDef.linearVelocity.setValue(0, 0);
2045
+ this._bodyDef.bullet = false;
2046
+ this._bodyDef.fixedRotation = false;
2047
+ this._bodyDef.gravityScale = 0;
2048
+ }
2049
+ _onAwake() {
2050
+ this.owner.globalTrans.cache = true;
2051
+ }
2052
+ _onEnable() {
2053
+ this._getPhysicsManager();
2054
+ this.owner.globalTrans.cache = true;
2055
+ let rig = this.owner.getComponent(RigidBody);
2056
+ if (rig && rig.applyOwnerColliderComponent) {
2057
+ this._setRigidbodyValue(rig);
2058
+ this.createShape(rig);
2059
+ }
2060
+ else {
2061
+ this._setBodyDefValue();
2062
+ super._onEnable();
2063
+ this.shapes = this._shapes;
2064
+ }
2065
+ if (this.isConnectedJoint) {
2066
+ this.owner.event("bodyCreated");
2067
+ this.isConnectedJoint = false;
2068
+ }
2069
+ }
2070
+ _onPhysicsScaleChanged() {
2071
+ if (this._rigidbody) {
2072
+ super._onPhysicsScaleChanged();
2073
+ return;
2074
+ }
2075
+ if (!this._shapes)
2076
+ return;
2077
+ for (let i = 0, n = this._shapes.length; i < n; i++) {
2078
+ this._shapes[i].setCollider(this);
2079
+ }
2080
+ }
2081
+ _removeShapeAndDestroyData() {
2082
+ if (this._rigidbody) {
2083
+ let body = this._box2DBody;
2084
+ if (body && !body.destroyed && this._box2DShape) {
2085
+ Physics2D.I._factory.destroyShape(this._physics2DManager.box2DWorld, body, this._box2DShape);
2086
+ }
2087
+ }
2088
+ else {
2089
+ if (this._shapes) {
2090
+ for (let i = 0; i < this._shapes.length; i++) {
2091
+ let shape = this._shapes[i];
2092
+ shape.destroy();
2093
+ }
2094
+ }
2095
+ if (this._box2DBody) {
2096
+ Physics2D.I._factory.removeBody(this._physics2DManager.box2DWorld, this._box2DBody);
2097
+ }
2098
+ }
2099
+ this._box2DFilter && Physics2D.I._factory.destroyData(this._box2DFilter);
2100
+ if (this._box2DShapeDef && this._box2DShapeDef._shape) {
2101
+ Physics2D.I._factory.destroyData(this._box2DShapeDef._shape);
2102
+ this._box2DShapeDef._shape = null;
2103
+ }
2104
+ this._box2DShapeDef && Physics2D.I._factory.destroyData(this._box2DShapeDef);
2105
+ this._box2DBody = null;
2106
+ this._box2DFilter = null;
2107
+ this._box2DShape = null;
2108
+ this._box2DShapeDef = null;
2109
+ }
2110
+ _onDisable() {
2111
+ this._removeShapeAndDestroyData();
2112
+ super._onDisable();
2113
+ }
2114
+ _onDestroy() {
2115
+ this._shapeDef = null;
2116
+ this._removeShapeAndDestroyData();
2117
+ this._shapes = null;
2118
+ super._onDestroy();
2119
+ }
2120
+ createShape(collider) {
2121
+ if (!collider)
2122
+ return;
2123
+ const body = collider.getBox2DBody();
2124
+ if (!body || body.destroyed)
2125
+ return;
2126
+ this._getPhysicsManager();
2127
+ this._setRigidbodyValue(collider);
2128
+ this._rigidbody = collider;
2129
+ this._box2DBody = body;
2130
+ if (this._box2DShape) {
2131
+ Physics2D.I._factory.destroyShape(this._physics2DManager.box2DWorld, this._box2DBody, this._box2DShape);
2132
+ if (this._box2DShapeDef && this._box2DShapeDef._shape) {
2133
+ Physics2D.I._factory.destroyData(this._box2DShapeDef._shape);
2134
+ this._box2DShapeDef._shape = null;
2135
+ }
2136
+ Physics2D.I._factory.destroyData(this._box2DShapeDef);
2137
+ this._box2DShape = null;
2138
+ this._box2DShapeDef = null;
2139
+ }
2140
+ if (!this._box2DFilter) {
2141
+ this._box2DFilter = Physics2D.I._factory.createFilter();
2142
+ this._box2DFilter.groupIndex = collider.group;
2143
+ this._box2DFilter.categoryBits = collider.category;
2144
+ this._box2DFilter.maskBits = collider.mask;
2145
+ }
2146
+ else {
2147
+ this._box2DFilter.groupIndex = collider.group;
2148
+ this._box2DFilter.categoryBits = collider.category;
2149
+ this._box2DFilter.maskBits = collider.mask;
2150
+ }
2151
+ this._box2DShapeDef = Physics2D.I._factory.createShapeDef(this._physics2DManager.box2DWorld, this._shapeDef, this._box2DFilter);
2152
+ this._setShapeData(this._box2DShapeDef._shape);
2153
+ this._box2DShape = Physics2D.I._factory.createShape(this._physics2DManager.box2DWorld, this._box2DBody, this._shapeDef.shapeType, this._box2DShapeDef);
2154
+ Physics2D.I._factory.set_shape_collider(this._box2DShape, this);
2155
+ }
2156
+ _setShapeData(shape) {
2157
+ }
2158
+ _setRigidbodyValue(collider) {
2159
+ this._shapeDef.density = this.density;
2160
+ this._shapeDef.friction = this.friction;
2161
+ this._shapeDef.isSensor = this.isSensor;
2162
+ this._shapeDef.restitution = this.restitution;
2163
+ this._shapeDef.filter.group = collider.group;
2164
+ this._shapeDef.filter.category = collider.category;
2165
+ this._shapeDef.filter.mask = collider.mask;
2166
+ }
2167
+ }
2168
+ const _tempPosition = new Laya.Point();
2169
+
2170
+ class BoxCollider extends StaticCollider {
2171
+ get width() {
2172
+ return this._width;
2173
+ }
2174
+ set width(value) {
2175
+ if (value <= 0)
2176
+ throw "BoxCollider size cannot be less than 0";
2177
+ if (this._width == value)
2178
+ return;
2179
+ this._width = value;
2180
+ this._rigidbody && this.createShape(this._rigidbody);
2181
+ }
2182
+ get height() {
2183
+ return this._height;
2184
+ }
2185
+ set height(value) {
2186
+ if (value <= 0)
2187
+ throw "BoxCollider size cannot be less than 0";
2188
+ if (this._height == value)
2189
+ return;
2190
+ this._height = value;
2191
+ this._rigidbody && this.createShape(this._rigidbody);
2192
+ }
2193
+ constructor() {
2194
+ super();
2195
+ this._width = 100;
2196
+ this._height = 100;
2197
+ this._shapeDef.shapeType = exports.EPhysics2DShape.BoxShape;
2198
+ }
2199
+ _setShapeData(shape) {
2200
+ if (!shape)
2201
+ return;
2202
+ let helfW = this._width * 0.5;
2203
+ let helfH = this._height * 0.5;
2204
+ var center = {
2205
+ x: helfW + this.pivotoffx,
2206
+ y: helfH + this.pivotoffy
2207
+ };
2208
+ Physics2D.I._factory.set_collider_SetAsBox(shape, helfW, helfH, center, Math.abs(this.scaleX), Math.abs(this.scaleY));
2209
+ }
2210
+ }
2211
+
2212
+ class ChainCollider extends StaticCollider {
2213
+ get points() {
2214
+ return this._points;
2215
+ }
2216
+ set points(value) {
2217
+ if (!value)
2218
+ throw "ChainCollider points cannot be empty";
2219
+ this._points = value;
2220
+ var arr = this._points.split(",");
2221
+ let length = arr.length;
2222
+ this._datas = [];
2223
+ for (var i = 0, n = length; i < n; i++) {
2224
+ this._datas.push(parseInt(arr[i]));
2225
+ }
2226
+ this._rigidbody && this.createShape(this._rigidbody);
2227
+ }
2228
+ get datas() {
2229
+ return this._datas;
2230
+ }
2231
+ set datas(value) {
2232
+ if (!value)
2233
+ throw "ChainCollider datas cannot be empty";
2234
+ this._datas = value;
2235
+ this._rigidbody && this.createShape(this._rigidbody);
2236
+ }
2237
+ get loop() {
2238
+ return this._loop;
2239
+ }
2240
+ set loop(value) {
2241
+ if (this._loop == value)
2242
+ return;
2243
+ this._loop = value;
2244
+ if (this._datas.length <= 4) {
2245
+ console.warn("To loop Chain, the length of points must be greater than 4");
2246
+ return;
2247
+ }
2248
+ this._rigidbody && this.createShape(this._rigidbody);
2249
+ }
2250
+ constructor() {
2251
+ super();
2252
+ this._points = "0,0,100,0";
2253
+ this._datas = [0, 0, 100, 0];
2254
+ this._loop = false;
2255
+ this._shapeDef.shapeType = exports.EPhysics2DShape.ChainShape;
2256
+ }
2257
+ _setShapeData(shape) {
2258
+ if (!shape)
2259
+ return;
2260
+ var len = this._datas.length;
2261
+ if (len % 2 == 1)
2262
+ throw "ChainCollider datas lenth must a multiplier of 2";
2263
+ Physics2D.I._factory.set_ChainShape_data(shape, this.pivotoffx, this.pivotoffy, this._datas, this._loop, this.scaleX, this.scaleY);
2264
+ }
2265
+ onAdded() {
2266
+ super.onAdded();
2267
+ if (this._datas.length == 0) {
2268
+ let sp = this.owner;
2269
+ this._datas.push(0, 0, sp.width, 0, 0, sp.height, sp.width, sp.height);
2270
+ }
2271
+ }
2272
+ }
2273
+
2274
+ class CircleCollider extends StaticCollider {
2275
+ get radius() {
2276
+ return this._radius;
2277
+ }
2278
+ set radius(value) {
2279
+ if (value <= 0)
2280
+ throw "CircleCollider radius cannot be less than 0";
2281
+ if (this._radius == value)
2282
+ return;
2283
+ this._radius = value;
2284
+ this._rigidbody && this.createShape(this._rigidbody);
2285
+ }
2286
+ constructor() {
2287
+ super();
2288
+ this._radius = 50;
2289
+ this._shapeDef.shapeType = exports.EPhysics2DShape.CircleShape;
2290
+ }
2291
+ _setShapeData(shape) {
2292
+ if (!shape)
2293
+ return;
2294
+ var scale = Math.max(Math.abs(this.scaleX), Math.abs(this.scaleY));
2295
+ let radius = this.radius;
2296
+ Physics2D.I._factory.set_CircleShape_radius(shape, radius, scale);
2297
+ Physics2D.I._factory.set_CircleShape_pos(shape, this.x, this.y, this.scaleX, this.scaleY);
2298
+ }
2299
+ }
2300
+
2301
+ class EdgeCollider extends StaticCollider {
2302
+ get points() {
2303
+ return this._points;
2304
+ }
2305
+ set points(value) {
2306
+ if (!value)
2307
+ throw "EdgeCollider points cannot be empty";
2308
+ this._points = value;
2309
+ var arr = this._points.split(",");
2310
+ let length = arr.length;
2311
+ this._datas = [];
2312
+ for (var i = 0, n = length; i < n; i++) {
2313
+ this._datas.push(parseInt(arr[i]));
2314
+ }
2315
+ this._rigidbody && this.createShape(this._rigidbody);
2316
+ }
2317
+ get datas() {
2318
+ return this._datas;
2319
+ }
2320
+ set datas(value) {
2321
+ if (!value)
2322
+ throw "EdgeCollider points cannot be empty";
2323
+ this._datas = value;
2324
+ this._rigidbody && this.createShape(this._rigidbody);
2325
+ }
2326
+ constructor() {
2327
+ super();
2328
+ this._points = "0,0,100,0";
2329
+ this._datas = [0, 0, 100, 0];
2330
+ this._shapeDef.shapeType = exports.EPhysics2DShape.EdgeShape;
2331
+ }
2332
+ _setShapeData(shape) {
2333
+ if (!shape)
2334
+ return;
2335
+ var len = this._datas.length;
2336
+ if (len % 2 == 1)
2337
+ throw "EdgeCollider points lenth must a multiplier of 2";
2338
+ Physics2D.I._factory.set_EdgeShape_data(shape, this.pivotoffx, this.pivotoffy, this._datas, this.scaleX, this.scaleY);
2339
+ }
2340
+ }
2341
+
2342
+ class PolygonCollider extends StaticCollider {
2343
+ get points() {
2344
+ return this._points;
2345
+ }
2346
+ set points(value) {
2347
+ if (!value)
2348
+ throw "PolygonCollider points cannot be empty";
2349
+ this._points = value;
2350
+ var arr = this._points.split(",");
2351
+ let length = arr.length;
2352
+ this._datas = [];
2353
+ for (var i = 0, n = length; i < n; i++) {
2354
+ this._datas.push(parseInt(arr[i]));
2355
+ }
2356
+ this._rigidbody && this.createShape(this._rigidbody);
2357
+ }
2358
+ get datas() {
2359
+ return this._datas;
2360
+ }
2361
+ set datas(value) {
2362
+ if (!value)
2363
+ throw "PolygonCollider points cannot be empty";
2364
+ this._datas = value;
2365
+ this._rigidbody && this.createShape(this._rigidbody);
2366
+ }
2367
+ constructor() {
2368
+ super();
2369
+ this._points = "50,0,100,100,0,100";
2370
+ this._datas = [50, 0, 100, 100, 0, 100];
2371
+ this._shapeDef.shapeType = exports.EPhysics2DShape.PolygonShape;
2372
+ }
2373
+ _setShapeData(shape) {
2374
+ if (!shape)
2375
+ return;
2376
+ var len = this.datas.length;
2377
+ if (len < 6)
2378
+ throw "PolygonCollider points must be greater than 3";
2379
+ if (len % 2 == 1)
2380
+ throw "PolygonCollider points lenth must a multiplier of 2";
2381
+ Physics2D.I._factory.set_PolygonShape_data(shape, this.pivotoffx, this.pivotoffy, this.datas, this.scaleX, this.scaleY);
2382
+ }
2383
+ }
2384
+
2385
+ const _tempV0 = new Laya.Vector2();
2386
+ class JointBase extends Laya.Component {
2387
+ get joint() {
2388
+ if (!this._joint)
2389
+ this._createJoint();
2390
+ return this._joint;
2391
+ }
2392
+ constructor() {
2393
+ super();
2394
+ this._factory = Physics2D.I._factory;
2395
+ this._singleton = false;
2396
+ }
2397
+ getJointRecationForce() {
2398
+ let force;
2399
+ if (this._joint) {
2400
+ force = Physics2D.I._factory.get_joint_recationForce(this._joint);
2401
+ }
2402
+ _tempV0.x = force.x;
2403
+ _tempV0.y = force.y;
2404
+ return _tempV0;
2405
+ }
2406
+ getJointRecationTorque() {
2407
+ let torque;
2408
+ if (this._joint) {
2409
+ torque = Physics2D.I._factory.get_joint_reactionTorque(this._joint);
2410
+ }
2411
+ return torque;
2412
+ }
2413
+ isValid() {
2414
+ let isvalid = false;
2415
+ if (this._joint) {
2416
+ isvalid = Physics2D.I._factory.isValidJoint(this._joint);
2417
+ }
2418
+ return isvalid;
2419
+ }
2420
+ getBodyAnchor(body, anchorx, anchory) {
2421
+ const node = body.owner;
2422
+ Laya.Point.TEMP.setTo(anchorx * Physics2D.getDesignScaleX(node), anchory * Physics2D.getDesignScaleY(node));
2423
+ return Laya.Point.TEMP;
2424
+ }
2425
+ _onAdded() {
2426
+ }
2427
+ _onEnable() {
2428
+ this._createJoint();
2429
+ }
2430
+ _onAwake() {
2431
+ }
2432
+ _createJoint() {
2433
+ }
2434
+ _onDisable() {
2435
+ if (this._factory.isValidJoint(this._joint)) {
2436
+ Physics2D.I._factory.removeJoint(this._physics2DManager.box2DWorld, this._joint);
2437
+ }
2438
+ this._joint = null;
2439
+ }
2440
+ }
2441
+
2442
+ class DistanceJoint extends JointBase {
2443
+ constructor() {
2444
+ super(...arguments);
2445
+ this._length = 0;
2446
+ this._maxLength = -1;
2447
+ this._minLength = -1;
2448
+ this._frequency = 1;
2449
+ this._dampingRatio = 0;
2450
+ this.selfAnchor = [0, 0];
2451
+ this.otherAnchor = [0, 0];
2452
+ this.collideConnected = false;
2453
+ }
2454
+ get length() {
2455
+ return this._length;
2456
+ }
2457
+ set length(value) {
2458
+ this._length = value;
2459
+ if (this._joint)
2460
+ this._factory.set_DistanceJoint_length(this._joint, value);
2461
+ }
2462
+ get minLength() {
2463
+ return this._minLength;
2464
+ }
2465
+ set minLength(value) {
2466
+ this._minLength = value;
2467
+ if (this._joint)
2468
+ this._factory.set_DistanceJoint_MinLength(this._joint, value);
2469
+ }
2470
+ get maxLength() {
2471
+ return this._maxLength;
2472
+ }
2473
+ set maxLength(value) {
2474
+ this._maxLength = value;
2475
+ if (this._joint)
2476
+ this._factory.set_DistanceJoint_MaxLength(this._joint, value);
2477
+ }
2478
+ get frequency() {
2479
+ return this._frequency;
2480
+ }
2481
+ set frequency(value) {
2482
+ this._frequency = value;
2483
+ if (this._joint) {
2484
+ this._factory.set_DistanceJointStiffnessDamping(this._joint, this._frequency, this._dampingRatio);
2485
+ }
2486
+ }
2487
+ get damping() {
2488
+ return this._dampingRatio;
2489
+ }
2490
+ set damping(value) {
2491
+ this._dampingRatio = value;
2492
+ if (this._joint) {
2493
+ this._factory.set_DistanceJointStiffnessDamping(this._joint, this._frequency, this._dampingRatio);
2494
+ }
2495
+ }
2496
+ get jointLength() {
2497
+ if (this._joint) {
2498
+ return Physics2D.I._factory.get_DistanceJoint_length(this._joint);
2499
+ }
2500
+ else {
2501
+ return 0;
2502
+ }
2503
+ }
2504
+ _createJoint() {
2505
+ var _a, _b;
2506
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
2507
+ if (!this._joint) {
2508
+ this.selfBody = this.selfBody || this.owner.getComponent(RigidBody);
2509
+ if (!this.selfBody)
2510
+ throw "selfBody can not be empty";
2511
+ let point = this.getBodyAnchor(this.selfBody, this.selfAnchor[0], this.selfAnchor[1]);
2512
+ var def = DistanceJoint._temp || (DistanceJoint._temp = new physics2D_DistancJointDef());
2513
+ def.bodyB = this.selfBody.getBox2DBody();
2514
+ if (!def.bodyB) {
2515
+ this.selfBody.isConnectedJoint = true;
2516
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
2517
+ return;
2518
+ }
2519
+ def.localAnchorB.setValue(point.x, point.y);
2520
+ this.selfBody.owner.on("shapeChange", this, this._refeahJoint);
2521
+ if (this.otherBody) {
2522
+ def.bodyA = this.otherBody.getBox2DBody();
2523
+ if (!def.bodyA) {
2524
+ this.otherBody.isConnectedJoint = true;
2525
+ this.otherBody.owner.on("bodyCreated", this, this._createJoint);
2526
+ return;
2527
+ }
2528
+ point = this.getBodyAnchor(this.otherBody, this.otherAnchor[0], this.otherAnchor[1]);
2529
+ def.localAnchorA.setValue(point.x, point.y);
2530
+ this.otherBody.owner.on("shapeChange", this, this._refeahJoint);
2531
+ }
2532
+ else {
2533
+ def.bodyA = this._physics2DManager.getEmptyBody();
2534
+ def.localAnchorA.setValue(this.otherAnchor[0], this.otherAnchor[1]);
2535
+ }
2536
+ def.dampingRatio = this._dampingRatio;
2537
+ def.frequency = this._frequency;
2538
+ def.collideConnected = this.collideConnected;
2539
+ def.length = this._length;
2540
+ def.maxLength = this._maxLength;
2541
+ def.minLength = this._minLength;
2542
+ this._box2DJointDef = Physics2D.I._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.DistanceJoint, def);
2543
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.DistanceJoint, this._box2DJointDef);
2544
+ this.selfBody.owner.off("bodyCreated", this._createJoint);
2545
+ if (this.otherBody)
2546
+ this.otherBody.owner.off("bodyCreated", this._createJoint);
2547
+ }
2548
+ }
2549
+ _refeahJoint() {
2550
+ if (this._joint) {
2551
+ this._factory.set_DistanceJointStiffnessDamping(this._joint, this._frequency, this._dampingRatio);
2552
+ }
2553
+ }
2554
+ onDestroy() {
2555
+ super.onDestroy();
2556
+ this.selfBody.owner.off("shapeChange", this._refeahJoint);
2557
+ if (this.otherBody)
2558
+ this.otherBody.owner.off("shapeChange", this._refeahJoint);
2559
+ }
2560
+ }
2561
+
2562
+ class PrismaticJoint extends JointBase {
2563
+ constructor() {
2564
+ super(...arguments);
2565
+ this._enableMotor = false;
2566
+ this._motorSpeed = 0;
2567
+ this._maxMotorForce = 10000;
2568
+ this._enableLimit = false;
2569
+ this._lowerTranslation = 0;
2570
+ this._upperTranslation = 0;
2571
+ this._axis = [1, 0];
2572
+ this.anchor = [0, 0];
2573
+ this.angle = 0;
2574
+ this.collideConnected = false;
2575
+ }
2576
+ get enableMotor() {
2577
+ return this._enableMotor;
2578
+ }
2579
+ set enableMotor(value) {
2580
+ this._enableMotor = value;
2581
+ if (this._joint)
2582
+ this._factory.set_Joint_EnableMotor(this._joint, value);
2583
+ }
2584
+ get motorSpeed() {
2585
+ return this._motorSpeed;
2586
+ }
2587
+ set motorSpeed(value) {
2588
+ this._motorSpeed = value;
2589
+ if (this._joint)
2590
+ this._factory.set_Joint_SetMotorSpeed(this._joint, value);
2591
+ }
2592
+ get maxMotorForce() {
2593
+ return this._maxMotorForce;
2594
+ }
2595
+ set maxMotorForce(value) {
2596
+ this._maxMotorForce = value;
2597
+ if (this._joint)
2598
+ this._factory.set_Joint_SetMaxMotorForce(this._joint, value);
2599
+ }
2600
+ get enableLimit() {
2601
+ return this._enableLimit;
2602
+ }
2603
+ set enableLimit(value) {
2604
+ this._enableLimit = value;
2605
+ if (this._joint)
2606
+ this._factory.set_Joint_EnableLimit(this._joint, value);
2607
+ }
2608
+ get lowerTranslation() {
2609
+ return this._lowerTranslation;
2610
+ }
2611
+ set lowerTranslation(value) {
2612
+ this._lowerTranslation = value;
2613
+ if (this._joint)
2614
+ this._factory.set_Joint_SetTranslationLimits(this._joint, value, this._upperTranslation);
2615
+ }
2616
+ get upperTranslation() {
2617
+ return this._upperTranslation;
2618
+ }
2619
+ set upperTranslation(value) {
2620
+ this._upperTranslation = value;
2621
+ if (this._joint)
2622
+ this._factory.set_Joint_SetTranslationLimits(this._joint, this._lowerTranslation, value);
2623
+ }
2624
+ get axis() {
2625
+ return this._axis;
2626
+ }
2627
+ set axis(value) {
2628
+ this._axis = value;
2629
+ this.angle = Laya.Utils.toAngle(Math.atan2(value[1], value[0]));
2630
+ }
2631
+ _createJoint() {
2632
+ var _a, _b;
2633
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
2634
+ if (!this._joint) {
2635
+ this.selfBody = this.selfBody || this.owner.getComponent(ColliderBase);
2636
+ if (!this.selfBody)
2637
+ throw "selfBody can not be empty";
2638
+ var def = PrismaticJoint._temp || (PrismaticJoint._temp = new physics2D_PrismaticJointDef());
2639
+ def.bodyB = this.selfBody.getBox2DBody();
2640
+ if (!def.bodyB) {
2641
+ this.selfBody.isConnectedJoint = true;
2642
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
2643
+ return;
2644
+ }
2645
+ def.bodyA = this.otherBody ? this.otherBody.getBox2DBody() : this._physics2DManager.getEmptyBody();
2646
+ if (!def.bodyA) {
2647
+ this.otherBody.isConnectedJoint = true;
2648
+ this.otherBody.owner.on("bodyCreated", this, this._createJoint);
2649
+ return;
2650
+ }
2651
+ let p = this.selfBody.getWorldPoint(this.anchor[0], this.anchor[1]);
2652
+ def.anchor.setValue(p.x, p.y);
2653
+ let radian = Laya.Utils.toRadian(this.angle);
2654
+ def.axis.setValue(Math.cos(radian), Math.sin(radian));
2655
+ def.enableMotor = this._enableMotor;
2656
+ def.motorSpeed = this._motorSpeed;
2657
+ def.maxMotorForce = this._maxMotorForce;
2658
+ def.enableLimit = this._enableLimit;
2659
+ def.lowerTranslation = this._lowerTranslation;
2660
+ def.upperTranslation = this._upperTranslation;
2661
+ def.collideConnected = this.collideConnected;
2662
+ this._box2DJointDef = this._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.PrismaticJoint, def);
2663
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.PrismaticJoint, this._box2DJointDef);
2664
+ this.selfBody.owner.off("bodyCreated", this, this._createJoint);
2665
+ this.otherBody && this.otherBody.owner.off("bodyCreated", this, this._createJoint);
2666
+ }
2667
+ }
2668
+ }
2669
+
2670
+ class RevoluteJoint extends JointBase {
2671
+ constructor() {
2672
+ super(...arguments);
2673
+ this._enableMotor = false;
2674
+ this._motorSpeed = 0;
2675
+ this._maxMotorTorque = 10000;
2676
+ this._enableLimit = false;
2677
+ this._lowerAngle = 0;
2678
+ this._upperAngle = 0;
2679
+ this.anchor = [0, 0];
2680
+ this.collideConnected = false;
2681
+ }
2682
+ get enableMotor() {
2683
+ return this._enableMotor;
2684
+ }
2685
+ set enableMotor(value) {
2686
+ this._enableMotor = value;
2687
+ if (this._joint)
2688
+ this._factory.set_Joint_EnableMotor(this._joint, value);
2689
+ }
2690
+ get motorSpeed() {
2691
+ return this._motorSpeed;
2692
+ }
2693
+ set motorSpeed(value) {
2694
+ this._motorSpeed = value;
2695
+ if (this._joint)
2696
+ this._factory.set_Joint_SetMotorSpeed(this._joint, value);
2697
+ }
2698
+ get maxMotorTorque() {
2699
+ return this._maxMotorTorque;
2700
+ }
2701
+ set maxMotorTorque(value) {
2702
+ this._maxMotorTorque = value;
2703
+ if (this._joint)
2704
+ this._factory.set_Joint_SetMaxMotorTorque(this._joint, value);
2705
+ }
2706
+ get enableLimit() {
2707
+ return this._enableLimit;
2708
+ }
2709
+ set enableLimit(value) {
2710
+ this._enableLimit = value;
2711
+ if (this._joint)
2712
+ this._factory.set_Joint_EnableLimit(this._joint, value);
2713
+ }
2714
+ get lowerAngle() {
2715
+ return this._lowerAngle;
2716
+ }
2717
+ set lowerAngle(value) {
2718
+ this._lowerAngle = value;
2719
+ if (this._joint)
2720
+ this._factory.set_Joint_SetLimits(this._joint, Laya.Utils.toRadian(value), Laya.Utils.toRadian(this._upperAngle));
2721
+ }
2722
+ get upperAngle() {
2723
+ return this._upperAngle;
2724
+ }
2725
+ set upperAngle(value) {
2726
+ this._upperAngle = value;
2727
+ if (this._joint)
2728
+ this._factory.set_Joint_SetLimits(this._joint, Laya.Utils.toRadian(this._lowerAngle), Laya.Utils.toRadian(value));
2729
+ }
2730
+ _createJoint() {
2731
+ var _a, _b;
2732
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
2733
+ if (!this._joint) {
2734
+ this.selfBody = this.selfBody || this.owner.getComponent(ColliderBase);
2735
+ if (!this.selfBody)
2736
+ throw "selfBody can not be empty";
2737
+ var def = RevoluteJoint._temp || (RevoluteJoint._temp = new physics2D_RevoluteJointDef());
2738
+ def.bodyB = this.selfBody.getBox2DBody();
2739
+ if (!def.bodyB) {
2740
+ this.selfBody.isConnectedJoint = true;
2741
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
2742
+ return;
2743
+ }
2744
+ def.bodyA = this.otherBody ? this.otherBody.getBox2DBody() : this._physics2DManager.getEmptyBody();
2745
+ if (!def.bodyA) {
2746
+ this.otherBody.isConnectedJoint = true;
2747
+ this.otherBody.owner.on("bodyCreated", this, this._createJoint);
2748
+ return;
2749
+ }
2750
+ let global = this.selfBody.getWorldPoint(this.anchor[0], this.anchor[1]);
2751
+ def.anchor.setValue(global.x, global.y);
2752
+ def.enableMotor = this._enableMotor;
2753
+ def.motorSpeed = this._motorSpeed;
2754
+ def.maxMotorTorque = this._maxMotorTorque;
2755
+ def.enableLimit = this._enableLimit;
2756
+ def.lowerAngle = Laya.Utils.toRadian(this._lowerAngle);
2757
+ def.upperAngle = Laya.Utils.toRadian(this._upperAngle);
2758
+ def.collideConnected = this.collideConnected;
2759
+ this._box2DJointDef = this._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.RevoluteJoint, def);
2760
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.RevoluteJoint, this._box2DJointDef);
2761
+ this.selfBody.owner.off("bodyCreated", this, this._createJoint);
2762
+ this.otherBody && this.otherBody.owner.off("bodyCreated", this, this._createJoint);
2763
+ }
2764
+ }
2765
+ }
2766
+
2767
+ class GearJoint extends JointBase {
2768
+ constructor() {
2769
+ super(...arguments);
2770
+ this._ratio = 1;
2771
+ this.collideConnected = false;
2772
+ }
2773
+ set joint1(value) {
2774
+ if (value instanceof RevoluteJoint || value instanceof PrismaticJoint) {
2775
+ this._joint1 = value;
2776
+ }
2777
+ else {
2778
+ console.warn("joint1 must be a RevoluteJoint or PrismaticJoint");
2779
+ this._joint1 = null;
2780
+ }
2781
+ }
2782
+ get joint1() {
2783
+ return this._joint1;
2784
+ }
2785
+ set joint2(value) {
2786
+ if (value instanceof RevoluteJoint || value instanceof PrismaticJoint) {
2787
+ this._joint2 = value;
2788
+ }
2789
+ else {
2790
+ console.warn("joint2 must be a RevoluteJoint or PrismaticJoint");
2791
+ this._joint2 = null;
2792
+ }
2793
+ }
2794
+ get joint2() {
2795
+ return this._joint2;
2796
+ }
2797
+ get ratio() {
2798
+ return this._ratio;
2799
+ }
2800
+ set ratio(value) {
2801
+ this._ratio = value;
2802
+ if (this._joint)
2803
+ this._factory.set_GearJoint_SetRatio(this._joint, -value);
2804
+ }
2805
+ _createJoint() {
2806
+ var _a, _b;
2807
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
2808
+ if (!this._joint) {
2809
+ if (!this.joint1)
2810
+ throw "Joint1 can not be empty";
2811
+ if (!this.joint2)
2812
+ throw "Joint2 can not be empty";
2813
+ var def = GearJoint._temp || (GearJoint._temp = new physics2D_GearJointDef());
2814
+ def.bodyA = this.joint1.owner.getComponent(ColliderBase).getBox2DBody();
2815
+ if (!def.bodyA) {
2816
+ this.joint1.owner.getComponent(ColliderBase).isConnectedJoint = true;
2817
+ this.joint1.owner.on("bodyCreated", this, this._createJoint);
2818
+ return;
2819
+ }
2820
+ def.bodyB = this.joint2.owner.getComponent(ColliderBase).getBox2DBody();
2821
+ if (!def.bodyB) {
2822
+ this.joint2.owner.getComponent(ColliderBase).isConnectedJoint = true;
2823
+ this.joint2.owner.on("bodyCreated", this, this._createJoint);
2824
+ return;
2825
+ }
2826
+ def.joint1 = this.joint1.joint;
2827
+ def.joint2 = this.joint2.joint;
2828
+ def.ratio = -this._ratio;
2829
+ def.collideConnected = this.collideConnected;
2830
+ this._box2DJointDef = Physics2D.I._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.GearJoint, def);
2831
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.GearJoint, this._box2DJointDef);
2832
+ this.joint1.owner.off("bodyCreated", this, this._createJoint);
2833
+ this.joint2.owner.off("bodyCreated", this, this._createJoint);
2834
+ }
2835
+ }
2836
+ }
2837
+
2838
+ class MotorJoint extends JointBase {
2839
+ constructor() {
2840
+ super(...arguments);
2841
+ this._linearOffset = [0, 0];
2842
+ this._angularOffset = 0;
2843
+ this._maxForce = 1000;
2844
+ this._maxTorque = 1000;
2845
+ this._correctionFactor = 0.3;
2846
+ this.collideConnected = false;
2847
+ }
2848
+ get linearOffset() {
2849
+ return this._linearOffset;
2850
+ }
2851
+ set linearOffset(value) {
2852
+ this._linearOffset = value;
2853
+ if (this._joint) {
2854
+ this._factory.set_MotorJoint_linearOffset(this._joint, value[0], value[1]);
2855
+ }
2856
+ }
2857
+ get angularOffset() {
2858
+ return this._angularOffset;
2859
+ }
2860
+ set angularOffset(value) {
2861
+ this._angularOffset = value;
2862
+ if (this._joint)
2863
+ this._factory.set_MotorJoint_SetAngularOffset(this._joint, Laya.Utils.toRadian(-value));
2864
+ }
2865
+ get maxForce() {
2866
+ return this._maxForce;
2867
+ }
2868
+ set maxForce(value) {
2869
+ this._maxForce = value;
2870
+ if (this._joint)
2871
+ this._factory.set_MotorJoint_SetMaxForce(this._joint, value);
2872
+ }
2873
+ get maxTorque() {
2874
+ return this._maxTorque;
2875
+ }
2876
+ set maxTorque(value) {
2877
+ this._maxTorque = value;
2878
+ if (this._joint)
2879
+ this._factory.set_MotorJoint_SetMaxTorque(this._joint, value);
2880
+ }
2881
+ get correctionFactor() {
2882
+ return this._correctionFactor;
2883
+ }
2884
+ set correctionFactor(value) {
2885
+ this._correctionFactor = value;
2886
+ if (this._joint)
2887
+ this._factory.set_MotorJoint_SetCorrectionFactor(this._joint, value);
2888
+ }
2889
+ _createJoint() {
2890
+ var _a, _b;
2891
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
2892
+ if (!this._joint) {
2893
+ if (!this.otherBody)
2894
+ throw "otherBody can not be empty";
2895
+ this.selfBody = this.selfBody || this.owner.getComponent(ColliderBase);
2896
+ if (!this.selfBody)
2897
+ throw "selfBody can not be empty";
2898
+ var def = MotorJoint._temp || (MotorJoint._temp = new physics2D_MotorJointDef());
2899
+ def.bodyA = this.selfBody.getBox2DBody();
2900
+ if (!def.bodyA) {
2901
+ this.selfBody.isConnectedJoint = true;
2902
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
2903
+ return;
2904
+ }
2905
+ def.bodyB = this.otherBody.getBox2DBody();
2906
+ if (!def.bodyB) {
2907
+ this.otherBody.isConnectedJoint = true;
2908
+ this.otherBody.owner.on("bodyCreated", this, this._createJoint);
2909
+ return;
2910
+ }
2911
+ def.linearOffset.setValue(this._linearOffset[0], this._linearOffset[1]);
2912
+ def.angularOffset = Laya.Utils.toRadian(-this._angularOffset);
2913
+ def.maxForce = this._maxForce;
2914
+ def.maxTorque = this._maxTorque;
2915
+ def.correctionFactor = this._correctionFactor;
2916
+ def.collideConnected = this.collideConnected;
2917
+ this._box2DJointDef = Physics2D.I._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.MotorJoint, def);
2918
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.MotorJoint, this._box2DJointDef);
2919
+ this.selfBody.owner.off("bodyCreated", this, this._createJoint);
2920
+ this.otherBody.owner.off("bodyCreated", this, this._createJoint);
2921
+ }
2922
+ }
2923
+ }
2924
+
2925
+ class MouseJoint extends JointBase {
2926
+ constructor() {
2927
+ super(...arguments);
2928
+ this._maxForce = 1000;
2929
+ this._frequency = 5;
2930
+ this._dampingRatio = 0.7;
2931
+ }
2932
+ get maxForce() {
2933
+ return this._maxForce;
2934
+ }
2935
+ set maxForce(value) {
2936
+ this._maxForce = value;
2937
+ if (this._joint)
2938
+ this._factory.set_MouseJoint_MaxForce(this._joint, value);
2939
+ }
2940
+ get frequency() {
2941
+ return this._frequency;
2942
+ }
2943
+ set frequency(value) {
2944
+ this._frequency = value;
2945
+ if (this._joint) {
2946
+ this._factory.set_MouseJoint_frequencyAndDampingRatio(this._joint, this._frequency, this._dampingRatio);
2947
+ }
2948
+ }
2949
+ get damping() {
2950
+ return this._dampingRatio;
2951
+ }
2952
+ set damping(value) {
2953
+ this._dampingRatio = value;
2954
+ if (this._joint) {
2955
+ this._factory.set_MouseJoint_frequencyAndDampingRatio(this._joint, this._frequency, this._dampingRatio);
2956
+ }
2957
+ }
2958
+ _onEnable() {
2959
+ this.owner.on(Laya.Event.MOUSE_DOWN, this, this._onMouseDown);
2960
+ }
2961
+ _createJoint() {
2962
+ var _a, _b;
2963
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
2964
+ if (!this._joint) {
2965
+ this.selfBody = this.selfBody || this.owner.getComponent(ColliderBase);
2966
+ if (!this.selfBody)
2967
+ throw "selfBody can not be empty";
2968
+ var def = MouseJoint._temp || (MouseJoint._temp = new physics2D_MouseJointJointDef());
2969
+ if (this.anchor) {
2970
+ var anchorPos = this.selfBody.owner.localToGlobal(Laya.Point.TEMP.setTo(this.anchor[0], this.anchor[1]), false, this._physics2DManager.getRootSprite());
2971
+ anchorPos.x = Physics2D.toPhysicsX(anchorPos.x);
2972
+ anchorPos.y = Physics2D.toPhysicsY(anchorPos.y);
2973
+ }
2974
+ else {
2975
+ anchorPos = this._physics2DManager.getRootSprite().globalToLocal(Laya.Point.TEMP.setTo(Laya.ILaya.InputManager.mouseX, Laya.ILaya.InputManager.mouseY));
2976
+ anchorPos.x = Physics2D.toPhysicsX(anchorPos.x);
2977
+ anchorPos.y = Physics2D.toPhysicsY(anchorPos.y);
2978
+ }
2979
+ def.bodyA = this._physics2DManager.getEmptyBody();
2980
+ def.bodyB = this.selfBody.getBox2DBody();
2981
+ if (!def.bodyB) {
2982
+ this.selfBody.isConnectedJoint = true;
2983
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
2984
+ return;
2985
+ }
2986
+ def.target.setValue(anchorPos.x, anchorPos.y);
2987
+ def.maxForce = this._maxForce;
2988
+ def.dampingRatio = this._dampingRatio;
2989
+ def.frequency = this._frequency;
2990
+ this._box2DJointDef = Physics2D.I._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.MouseJoint, def);
2991
+ this._factory.set_rigidBody_Awake(def.bodyB, true);
2992
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.MouseJoint, this._box2DJointDef);
2993
+ this.selfBody.owner.off("bodyCreated", this, this._createJoint);
2994
+ }
2995
+ }
2996
+ _onMouseDown() {
2997
+ this._createJoint();
2998
+ Laya.ILaya.stage.on(Laya.Event.MOUSE_MOVE, this, this._onMouseMove);
2999
+ Laya.ILaya.stage.once(Laya.Event.MOUSE_UP, this, this._onStageMouseUp);
3000
+ Laya.ILaya.stage.once(Laya.Event.MOUSE_OUT, this, this._onStageMouseUp);
3001
+ }
3002
+ _onStageMouseUp() {
3003
+ Laya.ILaya.stage.off(Laya.Event.MOUSE_MOVE, this, this._onMouseMove);
3004
+ Laya.ILaya.stage.off(Laya.Event.MOUSE_UP, this, this._onStageMouseUp);
3005
+ Laya.ILaya.stage.off(Laya.Event.MOUSE_OUT, this, this._onStageMouseUp);
3006
+ this._factory.removeJoint(this._physics2DManager.box2DWorld, this._joint);
3007
+ this._joint = null;
3008
+ }
3009
+ _onMouseMove() {
3010
+ if (this._joint)
3011
+ this._factory.set_MouseJoint_target(this._joint, Physics2D.toPhysicsX(Laya.ILaya.InputManager.mouseX), Physics2D.toPhysicsY(Laya.ILaya.InputManager.mouseY));
3012
+ }
3013
+ _onDisable() {
3014
+ super._onDisable();
3015
+ this.owner.off(Laya.Event.MOUSE_DOWN, this, this._onMouseDown);
3016
+ }
3017
+ }
3018
+
3019
+ class PulleyJoint extends JointBase {
3020
+ constructor() {
3021
+ super(...arguments);
3022
+ this.selfAnchor = [0, 0];
3023
+ this.otherAnchor = [0, 0];
3024
+ this.selfGroundPoint = [0, -100];
3025
+ this.otherGroundPoint = [0, -100];
3026
+ this.ratio = 1;
3027
+ this.collideConnected = false;
3028
+ }
3029
+ _createJoint() {
3030
+ var _a, _b;
3031
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
3032
+ if (!this._joint) {
3033
+ if (!this.otherBody)
3034
+ throw "otherBody can not be empty";
3035
+ this.selfBody = this.selfBody || this.owner.getComponent(ColliderBase);
3036
+ if (!this.selfBody)
3037
+ throw "selfBody can not be empty";
3038
+ var def = PulleyJoint._temp || (PulleyJoint._temp = new physics2D_PulleyJointDef);
3039
+ def.bodyA = this.otherBody.getBox2DBody();
3040
+ if (!def.bodyA) {
3041
+ this.otherBody.isConnectedJoint = true;
3042
+ this.otherBody.owner.on("bodyCreated", this, this._createJoint);
3043
+ return;
3044
+ }
3045
+ def.bodyB = this.selfBody.getBox2DBody();
3046
+ if (!def.bodyB) {
3047
+ this.selfBody.isConnectedJoint = true;
3048
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
3049
+ return;
3050
+ }
3051
+ var posA = this.otherBody.getWorldPoint(this.otherAnchor[0], this.otherAnchor[1]);
3052
+ def.localAnchorA.setValue(posA.x, posA.y);
3053
+ var posB = this.selfBody.getWorldPoint(this.selfAnchor[0], this.selfAnchor[1]);
3054
+ def.localAnchorB.setValue(posB.x, posB.y);
3055
+ var groundA = this.otherBody.getWorldPoint(this.otherGroundPoint[0], this.otherGroundPoint[1]);
3056
+ def.groundAnchorA.setValue(groundA.x, groundA.y);
3057
+ var groundB = this.selfBody.getWorldPoint(this.selfGroundPoint[0], this.selfGroundPoint[1]);
3058
+ def.groundAnchorB.setValue(groundB.x, groundB.y);
3059
+ def.ratio = this.ratio;
3060
+ def.collideConnected = this.collideConnected;
3061
+ this._box2DJointDef = Physics2D.I._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.PulleyJoint, def);
3062
+ this._joint = Physics2D.I._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.PulleyJoint, this._box2DJointDef);
3063
+ this.otherBody.owner.off("bodyCreated", this, this._createJoint);
3064
+ this.selfBody.owner.off("bodyCreated", this, this._createJoint);
3065
+ }
3066
+ }
3067
+ }
3068
+
3069
+ class WeldJoint extends JointBase {
3070
+ constructor() {
3071
+ super(...arguments);
3072
+ this._frequency = 5;
3073
+ this._dampingRatio = 0.7;
3074
+ this.anchor = [0, 0];
3075
+ this.collideConnected = false;
3076
+ }
3077
+ get frequency() {
3078
+ return this._frequency;
3079
+ }
3080
+ set frequency(value) {
3081
+ this._frequency = value;
3082
+ if (this._joint) {
3083
+ this._factory.set_Joint_frequencyAndDampingRatio(this._joint, this._frequency, this._dampingRatio, false);
3084
+ }
3085
+ }
3086
+ get damping() {
3087
+ return this._dampingRatio;
3088
+ }
3089
+ set damping(value) {
3090
+ this._dampingRatio = value;
3091
+ if (this._joint) {
3092
+ this._factory.set_Joint_frequencyAndDampingRatio(this._joint, this._frequency, this._dampingRatio, true);
3093
+ }
3094
+ }
3095
+ _createJoint() {
3096
+ var _a, _b;
3097
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
3098
+ if (!this._joint) {
3099
+ if (!this.otherBody)
3100
+ throw "otherBody can not be empty";
3101
+ this.selfBody = this.selfBody || this.owner.getComponent(ColliderBase);
3102
+ if (!this.selfBody)
3103
+ throw "selfBody can not be empty";
3104
+ var def = WeldJoint._temp || (WeldJoint._temp = new physics2D_WeldJointDef());
3105
+ var anchorPos = this.selfBody.getWorldPoint(this.anchor[0], this.anchor[1]);
3106
+ def.bodyA = this.otherBody.getBox2DBody();
3107
+ if (!def.bodyA) {
3108
+ this.otherBody.isConnectedJoint = true;
3109
+ this.otherBody.owner.on("bodyCreated", this, this._createJoint);
3110
+ return;
3111
+ }
3112
+ def.bodyB = this.selfBody.getBox2DBody();
3113
+ if (!def.bodyB) {
3114
+ this.selfBody.isConnectedJoint = true;
3115
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
3116
+ return;
3117
+ }
3118
+ def.anchor.setValue(anchorPos.x, anchorPos.y);
3119
+ def.frequency = this._frequency;
3120
+ def.dampingRatio = this._dampingRatio;
3121
+ def.collideConnected = this.collideConnected;
3122
+ this._box2DJointDef = Physics2D.I._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.WeldJoint, def);
3123
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.WeldJoint, this._box2DJointDef);
3124
+ this.otherBody.owner.off("bodyCreated", this, this._createJoint);
3125
+ this.selfBody.owner.off("bodyCreated", this, this._createJoint);
3126
+ }
3127
+ }
3128
+ }
3129
+
3130
+ class WheelJoint extends JointBase {
3131
+ constructor() {
3132
+ super(...arguments);
3133
+ this._frequency = 1;
3134
+ this._dampingRatio = 0.7;
3135
+ this._enableMotor = false;
3136
+ this._motorSpeed = 0;
3137
+ this._maxMotorTorque = 10000;
3138
+ this._enableLimit = true;
3139
+ this._lowerTranslation = 0;
3140
+ this._upperTranslation = 0;
3141
+ this.anchor = [0, 0];
3142
+ this.collideConnected = false;
3143
+ this._axis = [0, 1];
3144
+ this.angle = 90;
3145
+ }
3146
+ get frequency() {
3147
+ return this._frequency;
3148
+ }
3149
+ set frequency(value) {
3150
+ this._frequency = value;
3151
+ if (this._joint) {
3152
+ this._factory.set_Joint_frequencyAndDampingRatio(this._joint, this._frequency, this._dampingRatio, false, false);
3153
+ }
3154
+ }
3155
+ get damping() {
3156
+ return this._dampingRatio;
3157
+ }
3158
+ set damping(value) {
3159
+ this._dampingRatio = value;
3160
+ if (this._joint) {
3161
+ this._factory.set_Joint_frequencyAndDampingRatio(this._joint, this._frequency, this._dampingRatio, true, false);
3162
+ }
3163
+ }
3164
+ get enableMotor() {
3165
+ return this._enableMotor;
3166
+ }
3167
+ set enableMotor(value) {
3168
+ this._enableMotor = value;
3169
+ if (this._joint)
3170
+ this._factory.set_Joint_EnableMotor(this._joint, value);
3171
+ }
3172
+ get motorSpeed() {
3173
+ return this._motorSpeed;
3174
+ }
3175
+ set motorSpeed(value) {
3176
+ this._motorSpeed = value;
3177
+ if (this._joint)
3178
+ this._factory.set_Joint_SetMotorSpeed(this._joint, value);
3179
+ }
3180
+ get maxMotorTorque() {
3181
+ return this._maxMotorTorque;
3182
+ }
3183
+ set maxMotorTorque(value) {
3184
+ this._maxMotorTorque = value;
3185
+ if (this._joint)
3186
+ this._factory.set_Joint_SetMaxMotorTorque(this._joint, value);
3187
+ }
3188
+ get enableLimit() {
3189
+ return this._enableLimit;
3190
+ }
3191
+ set enableLimit(value) {
3192
+ this._enableLimit = value;
3193
+ if (this._joint)
3194
+ this._factory.set_Joint_EnableLimit(this._joint, value);
3195
+ }
3196
+ get lowerTranslation() {
3197
+ return this._lowerTranslation;
3198
+ }
3199
+ set lowerTranslation(value) {
3200
+ this._lowerTranslation = value;
3201
+ if (this._joint)
3202
+ this._factory.set_Joint_SetTranslationLimits(this._joint, value, this._upperTranslation);
3203
+ }
3204
+ get upperTranslation() {
3205
+ return this._upperTranslation;
3206
+ }
3207
+ set upperTranslation(value) {
3208
+ this._upperTranslation = value;
3209
+ if (this._joint)
3210
+ this._factory.set_Joint_SetTranslationLimits(this._joint, this._lowerTranslation, value);
3211
+ }
3212
+ get axis() {
3213
+ return this._axis;
3214
+ }
3215
+ set axis(value) {
3216
+ this._axis = value;
3217
+ this.angle = Laya.Utils.toAngle(Math.atan2(value[1], value[0]));
3218
+ }
3219
+ _createJoint() {
3220
+ var _a, _b;
3221
+ this._physics2DManager = (_b = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
3222
+ if (!this._joint) {
3223
+ if (!this.otherBody)
3224
+ throw "otherBody can not be empty";
3225
+ this.selfBody = this.selfBody || this.owner.getComponent(ColliderBase);
3226
+ if (!this.selfBody)
3227
+ throw "selfBody can not be empty";
3228
+ var def = WheelJoint._temp || (WheelJoint._temp = new physics2D_WheelJointDef());
3229
+ var anchorPos = this.selfBody.getWorldPoint(this.anchor[0], this.anchor[1]);
3230
+ def.anchor.setValue(anchorPos.x, anchorPos.y);
3231
+ let radian = Laya.Utils.toRadian(this.angle);
3232
+ def.axis.setValue(Math.cos(radian), Math.sin(radian));
3233
+ def.bodyA = this.otherBody.getBox2DBody();
3234
+ if (!def.bodyA) {
3235
+ this.otherBody.isConnectedJoint = true;
3236
+ this.otherBody.owner.on("bodyCreated", this, this._createJoint);
3237
+ return;
3238
+ }
3239
+ def.bodyB = this.selfBody.getBox2DBody();
3240
+ if (!def.bodyB) {
3241
+ this.selfBody.isConnectedJoint = true;
3242
+ this.selfBody.owner.on("bodyCreated", this, this._createJoint);
3243
+ return;
3244
+ }
3245
+ def.enableMotor = this._enableMotor;
3246
+ def.motorSpeed = this._motorSpeed;
3247
+ def.maxMotorTorque = this._maxMotorTorque;
3248
+ def.collideConnected = this.collideConnected;
3249
+ def.enableLimit = this._enableLimit;
3250
+ def.lowerTranslation = this._lowerTranslation;
3251
+ def.upperTranslation = this._upperTranslation;
3252
+ def.frequency = this._frequency;
3253
+ def.dampingRatio = this._dampingRatio;
3254
+ this._box2DJointDef = this._factory.createJointDef(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.WheelJoint, def);
3255
+ this._joint = this._factory.createJoint(this._physics2DManager.box2DWorld, exports.EPhysics2DJoint.WheelJoint, this._box2DJointDef);
3256
+ this.otherBody.owner.off("bodyCreated", this, this._createJoint);
3257
+ this.selfBody.owner.off("bodyCreated", this, this._createJoint);
3258
+ }
3259
+ }
3260
+ }
3261
+
3262
+ class Physics2DShapeBase {
3263
+ get x() {
3264
+ return this._x;
3265
+ }
3266
+ set x(value) {
3267
+ if (this._x == value)
3268
+ return;
3269
+ this._x = value;
3270
+ this._updateShapeData();
3271
+ }
3272
+ get y() {
3273
+ return this._y;
3274
+ }
3275
+ set y(value) {
3276
+ if (this._y == value)
3277
+ return;
3278
+ this._y = value;
3279
+ this._updateShapeData();
3280
+ }
3281
+ get filterData() {
3282
+ return this._filterData;
3283
+ }
3284
+ set filterData(value) {
3285
+ this._filterData = value;
3286
+ this._updateFilterData();
3287
+ }
3288
+ get density() {
3289
+ return this._density;
3290
+ }
3291
+ set density(value) {
3292
+ this._density = value;
3293
+ this._shapeDef.density = value;
3294
+ if (this._box2DShape) {
3295
+ Physics2D.I._factory.set_shape_density(this._box2DShape, value);
3296
+ this._body._resetMassData();
3297
+ }
3298
+ }
3299
+ get restitution() {
3300
+ return this._restitution;
3301
+ }
3302
+ set restitution(value) {
3303
+ this._restitution = value;
3304
+ this._shapeDef.restitution = value;
3305
+ this._box2DShape && Physics2D.I._factory.set_shape_restitution(this._box2DShape, value);
3306
+ }
3307
+ get restitutionThreshold() {
3308
+ return this._restitutionThreshold;
3309
+ }
3310
+ set restitutionThreshold(value) {
3311
+ this._restitutionThreshold = value;
3312
+ this._shapeDef.restitutionThreshold = value;
3313
+ this._box2DShape && Physics2D.I._factory.set_shape_restitutionThreshold(this._box2DShape, value);
3314
+ }
3315
+ get friction() {
3316
+ return this._friction;
3317
+ }
3318
+ set friction(value) {
3319
+ this._friction = value;
3320
+ this._shapeDef.friction = value;
3321
+ this._box2DShape && Physics2D.I._factory.set_shape_friction(this._box2DShape, value);
3322
+ }
3323
+ get isSensor() {
3324
+ return this._isSensor;
3325
+ }
3326
+ set isSensor(value) {
3327
+ this._isSensor = value;
3328
+ this._shapeDef.isSensor = value;
3329
+ this._box2DShape && Physics2D.I._factory.set_shape_isSensor(this._box2DShape, value);
3330
+ }
3331
+ get scaleX() {
3332
+ return Physics2D.getDesignScaleX(this._body.owner);
3333
+ }
3334
+ get scaleY() {
3335
+ return Physics2D.getDesignScaleY(this._body.owner);
3336
+ }
3337
+ get pivotoffx() {
3338
+ return this._x - this._body.owner.pivotX;
3339
+ }
3340
+ get pivotoffy() {
3341
+ return this._y - this._body.owner.pivotY;
3342
+ }
3343
+ constructor() {
3344
+ this._shapeDef = new Box2DShapeDef();
3345
+ this._filterData = new FilterData();
3346
+ this._isSensor = false;
3347
+ this._density = 10;
3348
+ this._friction = 0.2;
3349
+ this._restitution = 0;
3350
+ this._restitutionThreshold = 1.0;
3351
+ this._x = 0;
3352
+ this._y = 0;
3353
+ this._box2DFilter = Physics2D.I._factory.createFilter();
3354
+ }
3355
+ _updateFilterData() {
3356
+ if (!this._box2DShape || !this._box2DFilter)
3357
+ return;
3358
+ this._box2DFilter.groupIndex = this._filterData.group;
3359
+ this._box2DFilter.categoryBits = this._filterData.category;
3360
+ this._box2DFilter.maskBits = this._filterData.mask;
3361
+ this._shapeDef.filter = this._filterData;
3362
+ Physics2D.I._factory.setfilterData(this._box2DShape, this._box2DFilter);
3363
+ Physics2D.I._factory.set_shape_reFilter(this._box2DShape);
3364
+ }
3365
+ setCollider(body) {
3366
+ var _a, _b;
3367
+ this._body = body;
3368
+ this._box2DBody = body.getBox2DBody();
3369
+ if (!this._box2DBody)
3370
+ return;
3371
+ if (this._box2DShape) {
3372
+ Physics2D.I._factory.destroyShape(this._physics2DManager.box2DWorld, this._box2DBody, this._box2DShape);
3373
+ if (this._box2DShapeDef && this._box2DShapeDef._shape) {
3374
+ Physics2D.I._factory.destroyData(this._box2DShapeDef._shape);
3375
+ this._box2DShapeDef._shape = null;
3376
+ }
3377
+ Physics2D.I._factory.destroyData(this._box2DShapeDef);
3378
+ this._box2DShape = null;
3379
+ this._box2DShapeDef = null;
3380
+ }
3381
+ if (!this._box2DFilter) {
3382
+ this._box2DFilter = Physics2D.I._factory.createFilter();
3383
+ }
3384
+ this._physics2DManager = (_b = (_a = this._body.owner) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.getComponentElementManager(Physics2DWorldManager.__managerName);
3385
+ this.filterData = this._filterData;
3386
+ this._box2DShapeDef = Physics2D.I._factory.createShapeDef(this._physics2DManager.box2DWorld, this._shapeDef, this._box2DFilter);
3387
+ Physics2D.I._factory.set_shape_collider(this._box2DShapeDef, this._body);
3388
+ this._updateShapeData();
3389
+ this._initShape();
3390
+ }
3391
+ _refreshShape(update) {
3392
+ const factory = Physics2D.I._factory;
3393
+ update(factory.getShapeByDef(this._box2DShapeDef, this._shapeDef.shapeType));
3394
+ if (!this._box2DShape)
3395
+ return;
3396
+ update(factory.getShape(this._box2DShape, this._shapeDef.shapeType));
3397
+ factory.synchronizeShape(this._box2DBody, this._box2DShape);
3398
+ this._body._resetMassData();
3399
+ }
3400
+ _initShape() {
3401
+ if (!Laya.LayaEnv.isPlaying)
3402
+ return;
3403
+ this._createShape();
3404
+ if (!this._box2DShape)
3405
+ return;
3406
+ Physics2D.I._factory.set_shape_collider(this._box2DShape, this._body);
3407
+ this._updateFilterData();
3408
+ this.x = this._x;
3409
+ this.y = this._y;
3410
+ this.density = this._density;
3411
+ this.friction = this._friction;
3412
+ this.isSensor = this._isSensor;
3413
+ this.restitution = this._restitution;
3414
+ this.restitutionThreshold = this._restitutionThreshold;
3415
+ }
3416
+ _createShape() {
3417
+ }
3418
+ _updateShapeData() {
3419
+ }
3420
+ getAABB() {
3421
+ return Physics2D.I._factory.get_shape_AABB(this._box2DShape);
3422
+ }
3423
+ rayCast(index = 0) {
3424
+ return Physics2D.I._factory.shape_rayCast(this._box2DShape, null, null, index);
3425
+ }
3426
+ destroy() {
3427
+ if (!this._box2DBody || !this._box2DShape)
3428
+ return;
3429
+ Physics2D.I._factory.destroyShape(this._physics2DManager.box2DWorld, this._box2DBody, this._box2DShape);
3430
+ Physics2D.I._factory.destroyData(this._box2DFilter);
3431
+ if (this._box2DShapeDef && this._box2DShapeDef._shape) {
3432
+ Physics2D.I._factory.destroyData(this._box2DShapeDef._shape);
3433
+ this._box2DShapeDef._shape = null;
3434
+ }
3435
+ Physics2D.I._factory.destroyData(this._box2DShapeDef);
3436
+ this._box2DShape = null;
3437
+ this._box2DFilter = null;
3438
+ this._box2DShapeDef = null;
3439
+ this._body = null;
3440
+ this._box2DBody = null;
3441
+ }
3442
+ clone() {
3443
+ }
3444
+ cloneTo(destObject) {
3445
+ destObject.density = this.density;
3446
+ destObject.filterData = Object.assign(new FilterData(), this.filterData);
3447
+ destObject.friction = this.friction;
3448
+ destObject.isSensor = this.isSensor;
3449
+ destObject.restitution = this.restitution;
3450
+ destObject.restitutionThreshold = this.restitutionThreshold;
3451
+ destObject.x = this.x;
3452
+ destObject.y = this.y;
3453
+ }
3454
+ }
3455
+
3456
+ class BoxShape2D extends Physics2DShapeBase {
3457
+ get height() {
3458
+ return this._height;
3459
+ }
3460
+ set height(value) {
3461
+ if (value < 0)
3462
+ console.warn("BoxCollider size cannot be less than 0");
3463
+ if (this._height == value)
3464
+ return;
3465
+ this._height = value;
3466
+ this._updateShapeData();
3467
+ }
3468
+ get width() {
3469
+ return this._width;
3470
+ }
3471
+ set width(value) {
3472
+ if (value < 0)
3473
+ console.warn("BoxCollider size cannot be less than 0");
3474
+ if (this._width == value)
3475
+ return;
3476
+ this._width = value;
3477
+ this._updateShapeData();
3478
+ }
3479
+ constructor() {
3480
+ super();
3481
+ this._width = 100;
3482
+ this._height = 100;
3483
+ this._shapeDef.shapeType = exports.EPhysics2DShape.BoxShape;
3484
+ }
3485
+ _createShape() {
3486
+ this._box2DShape = Physics2D.I._factory.createShape(this._physics2DManager.box2DWorld, this._box2DBody, exports.EPhysics2DShape.BoxShape, this._box2DShapeDef);
3487
+ }
3488
+ _updateShapeData() {
3489
+ if (!Laya.LayaEnv.isPlaying || !this._body || !this._box2DBody)
3490
+ return;
3491
+ let helfW = this._width * 0.5;
3492
+ let helfH = this._height * 0.5;
3493
+ var center = {
3494
+ x: helfW + this.pivotoffx,
3495
+ y: helfH + this.pivotoffy
3496
+ };
3497
+ this._refreshShape(shape => {
3498
+ Physics2D.I._factory.set_collider_SetAsBox(shape, helfW, helfH, center, Math.abs(this.scaleX), Math.abs(this.scaleY));
3499
+ });
3500
+ }
3501
+ clone() {
3502
+ let dest = new BoxShape2D();
3503
+ this.cloneTo(dest);
3504
+ return dest;
3505
+ }
3506
+ cloneTo(destObject) {
3507
+ super.cloneTo(destObject);
3508
+ destObject.width = this.width;
3509
+ destObject.height = this.height;
3510
+ }
3511
+ }
3512
+
3513
+ class ChainShape2D extends Physics2DShapeBase {
3514
+ get datas() {
3515
+ return this._datas;
3516
+ }
3517
+ set datas(value) {
3518
+ if (!value)
3519
+ throw "ChainCollider datas cannot be empty";
3520
+ this._datas = value;
3521
+ this._updateShapeData();
3522
+ }
3523
+ get loop() {
3524
+ return this._loop;
3525
+ }
3526
+ set loop(value) {
3527
+ if (this._loop == value)
3528
+ return;
3529
+ this._loop = value;
3530
+ this._updateShapeData();
3531
+ }
3532
+ constructor() {
3533
+ super();
3534
+ this._datas = [0, 0, 100, 0];
3535
+ this._loop = false;
3536
+ this._shapeDef.shapeType = exports.EPhysics2DShape.ChainShape;
3537
+ }
3538
+ _createShape() {
3539
+ }
3540
+ _updateShapeData() {
3541
+ if (!Laya.LayaEnv.isPlaying || !this._body || !this._box2DBody)
3542
+ return;
3543
+ var len = this._datas.length;
3544
+ if (len % 2 == 1)
3545
+ throw "ChainCollider datas lenth must a multiplier of 2";
3546
+ var pointCount = len >> 1;
3547
+ if (pointCount < 2 || (this._loop && pointCount < 3))
3548
+ return;
3549
+ if (this._box2DShape) {
3550
+ Physics2D.I._factory.destroyShape(this._physics2DManager.box2DWorld, this._box2DBody, this._box2DShape);
3551
+ this._box2DShape = null;
3552
+ }
3553
+ let defShape = Physics2D.I._factory.getShapeByDef(this._box2DShapeDef, this._shapeDef.shapeType);
3554
+ Physics2D.I._factory.set_ChainShape_data(defShape, this.pivotoffx, this.pivotoffy, this._datas, this._loop, this.scaleX, this.scaleY);
3555
+ this._box2DShape = Physics2D.I._factory.createShape(this._physics2DManager.box2DWorld, this._box2DBody, exports.EPhysics2DShape.ChainShape, this._box2DShapeDef);
3556
+ Physics2D.I._factory.set_shape_collider(this._box2DShape, this._body);
3557
+ this.filterData = this.filterData;
3558
+ this.density = this.density;
3559
+ this.friction = this.friction;
3560
+ this.isSensor = this.isSensor;
3561
+ this.restitution = this.restitution;
3562
+ this.restitutionThreshold = this.restitutionThreshold;
3563
+ }
3564
+ clone() {
3565
+ let dest = new ChainShape2D();
3566
+ this.cloneTo(dest);
3567
+ return dest;
3568
+ }
3569
+ cloneTo(destObject) {
3570
+ super.cloneTo(destObject);
3571
+ destObject.datas = this.datas.slice();
3572
+ destObject.loop = this.loop;
3573
+ }
3574
+ }
3575
+
3576
+ class EdgeShape2D extends Physics2DShapeBase {
3577
+ get datas() {
3578
+ return this._datas;
3579
+ }
3580
+ set datas(value) {
3581
+ if (!value)
3582
+ throw "EdgeCollider points cannot be empty";
3583
+ this._datas = value;
3584
+ this._updateShapeData();
3585
+ }
3586
+ constructor() {
3587
+ super();
3588
+ this._datas = [0, 0, 100, 0];
3589
+ this._shapeDef.shapeType = exports.EPhysics2DShape.EdgeShape;
3590
+ }
3591
+ _createShape() {
3592
+ this._box2DShape = Physics2D.I._factory.createShape(this._physics2DManager.box2DWorld, this._box2DBody, exports.EPhysics2DShape.EdgeShape, this._box2DShapeDef);
3593
+ }
3594
+ _updateShapeData() {
3595
+ if (!Laya.LayaEnv.isPlaying || !this._body || !this._box2DBody)
3596
+ return;
3597
+ var len = this._datas.length;
3598
+ if (len % 2 == 1)
3599
+ throw "EdgeCollider points lenth must a multiplier of 2";
3600
+ this._refreshShape(shape => {
3601
+ Physics2D.I._factory.set_EdgeShape_data(shape, this.pivotoffx, this.pivotoffy, this._datas, this.scaleX, this.scaleY);
3602
+ });
3603
+ }
3604
+ clone() {
3605
+ let dest = new EdgeShape2D();
3606
+ this.cloneTo(dest);
3607
+ return dest;
3608
+ }
3609
+ cloneTo(destObject) {
3610
+ super.cloneTo(destObject);
3611
+ destObject.datas = this.datas.slice();
3612
+ }
3613
+ }
3614
+
3615
+ class PolygonShape2D extends Physics2DShapeBase {
3616
+ get datas() {
3617
+ return this._datas;
3618
+ }
3619
+ set datas(value) {
3620
+ if (!value)
3621
+ throw "PolygonCollider points cannot be empty";
3622
+ this._datas = value;
3623
+ this._updateShapeData();
3624
+ }
3625
+ constructor() {
3626
+ super();
3627
+ this._datas = [50, 0, 100, 100, 0, 100];
3628
+ this._shapeDef.shapeType = exports.EPhysics2DShape.PolygonShape;
3629
+ }
3630
+ _createShape() {
3631
+ this._box2DShape = Physics2D.I._factory.createShape(this._physics2DManager.box2DWorld, this._box2DBody, exports.EPhysics2DShape.PolygonShape, this._box2DShapeDef);
3632
+ }
3633
+ _updateShapeData() {
3634
+ if (!Laya.LayaEnv.isPlaying || !this._body || !this._box2DBody)
3635
+ return;
3636
+ var len = this.datas.length;
3637
+ if (len < 6)
3638
+ throw "PolygonCollider points must be greater than 3";
3639
+ if (len % 2 == 1)
3640
+ throw "PolygonCollider points lenth must a multiplier of 2";
3641
+ this._refreshShape(shape => {
3642
+ Physics2D.I._factory.set_PolygonShape_data(shape, this.pivotoffx, this.pivotoffy, this.datas, this.scaleX, this.scaleY);
3643
+ });
3644
+ }
3645
+ clone() {
3646
+ let dest = new PolygonShape2D();
3647
+ this.cloneTo(dest);
3648
+ return dest;
3649
+ }
3650
+ cloneTo(destObject) {
3651
+ super.cloneTo(destObject);
3652
+ destObject.datas = this.datas.slice();
3653
+ }
3654
+ }
3655
+
3656
+ class CircleShape2D extends Physics2DShapeBase {
3657
+ get radius() {
3658
+ return this._radius;
3659
+ }
3660
+ set radius(value) {
3661
+ if (this._radius === value)
3662
+ return;
3663
+ this._radius = value;
3664
+ this._updateShapeData();
3665
+ }
3666
+ constructor() {
3667
+ super();
3668
+ this._radius = 50;
3669
+ this._shapeDef.shapeType = exports.EPhysics2DShape.CircleShape;
3670
+ }
3671
+ _createShape() {
3672
+ this._box2DShape = Physics2D.I._factory.createShape(this._physics2DManager.box2DWorld, this._box2DBody, exports.EPhysics2DShape.CircleShape, this._box2DShapeDef);
3673
+ }
3674
+ _updateShapeData() {
3675
+ if (!Laya.LayaEnv.isPlaying || !this._body || !this._box2DBody)
3676
+ return;
3677
+ var scale = Math.max(Math.abs(this.scaleX), Math.abs(this.scaleY));
3678
+ let radius = this.radius;
3679
+ this._refreshShape(shape => {
3680
+ Physics2D.I._factory.set_CircleShape_radius(shape, radius, scale);
3681
+ Physics2D.I._factory.set_CircleShape_pos(shape, this.pivotoffx, this.pivotoffy, this.scaleX, this.scaleY);
3682
+ });
3683
+ }
3684
+ clone() {
3685
+ let dest = new CircleShape2D();
3686
+ this.cloneTo(dest);
3687
+ return dest;
3688
+ }
3689
+ cloneTo(destObject) {
3690
+ super.cloneTo(destObject);
3691
+ destObject.radius = this.radius;
3692
+ }
3693
+ }
3694
+
3695
+ let c = Laya.ClassUtils.regClass;
3696
+ c("Physics2D", Physics2D);
3697
+ c("Physics2DDebugDraw", Physics2DDebugDraw);
3698
+ c("Physics2DWorldManager", Physics2DWorldManager);
3699
+ c("FilterData", FilterData);
3700
+ c("ColliderBase", ColliderBase);
3701
+ c("RigidBody", RigidBody);
3702
+ c("StaticCollider", StaticCollider);
3703
+ c("JointBase", JointBase);
3704
+ c("DistanceJoint", DistanceJoint);
3705
+ c("GearJoint", GearJoint);
3706
+ c("MotorJoint", MotorJoint);
3707
+ c("MouseJoint", MouseJoint);
3708
+ c("PrismaticJoint", PrismaticJoint);
3709
+ c("PulleyJoint", PulleyJoint);
3710
+ c("RevoluteJoint", RevoluteJoint);
3711
+ c("WeldJoint", WeldJoint);
3712
+ c("WheelJoint", WheelJoint);
3713
+ c("BoxCollider", BoxCollider);
3714
+ c("ChainCollider", ChainCollider);
3715
+ c("CircleCollider", CircleCollider);
3716
+ c("EdgeCollider", EdgeCollider);
3717
+ c("PolygonCollider", PolygonCollider);
3718
+ c("Physics2DShapeBase", Physics2DShapeBase);
3719
+ c("BoxShape2D", BoxShape2D);
3720
+ c("CircleShape2D", CircleShape2D);
3721
+ c("ChainShape2D", ChainShape2D);
3722
+ c("EdgeShape2D", EdgeShape2D);
3723
+ c("PolygonShape2D", PolygonShape2D);
3724
+
3725
+ exports.Box2DShapeDef = Box2DShapeDef;
3726
+ exports.BoxCollider = BoxCollider;
3727
+ exports.BoxShape2D = BoxShape2D;
3728
+ exports.ChainCollider = ChainCollider;
3729
+ exports.ChainShape2D = ChainShape2D;
3730
+ exports.CircleCollider = CircleCollider;
3731
+ exports.CircleShape2D = CircleShape2D;
3732
+ exports.ColliderBase = ColliderBase;
3733
+ exports.DistanceJoint = DistanceJoint;
3734
+ exports.EdgeCollider = EdgeCollider;
3735
+ exports.EdgeShape2D = EdgeShape2D;
3736
+ exports.FilterData = FilterData;
3737
+ exports.GearJoint = GearJoint;
3738
+ exports.JointBase = JointBase;
3739
+ exports.MotorJoint = MotorJoint;
3740
+ exports.MouseJoint = MouseJoint;
3741
+ exports.Physics2D = Physics2D;
3742
+ exports.Physics2DContactHitResult = Physics2DContactHitResult;
3743
+ exports.Physics2DDebugDraw = Physics2DDebugDraw;
3744
+ exports.Physics2DHitResult = Physics2DHitResult;
3745
+ exports.Physics2DOption = Physics2DOption;
3746
+ exports.Physics2DShapeBase = Physics2DShapeBase;
3747
+ exports.Physics2DWorldManager = Physics2DWorldManager;
3748
+ exports.PhysicsDrawLine2DCMD = PhysicsDrawLine2DCMD;
3749
+ exports.PhysicsLineGemetry = PhysicsLineGemetry;
3750
+ exports.PhysicsLineShader = PhysicsLineShader;
3751
+ exports.PolygonCollider = PolygonCollider;
3752
+ exports.PolygonShape2D = PolygonShape2D;
3753
+ exports.PrismaticJoint = PrismaticJoint;
3754
+ exports.PulleyJoint = PulleyJoint;
3755
+ exports.RevoluteJoint = RevoluteJoint;
3756
+ exports.RigidBody = RigidBody;
3757
+ exports.RigidBody2DInfo = RigidBody2DInfo;
3758
+ exports.StaticCollider = StaticCollider;
3759
+ exports.WeldJoint = WeldJoint;
3760
+ exports.WheelJoint = WheelJoint;
3761
+ exports.box2DWorldDef = box2DWorldDef;
3762
+ exports.physics2D_BaseJointDef = physics2D_BaseJointDef;
3763
+ exports.physics2D_DistancJointDef = physics2D_DistancJointDef;
3764
+ exports.physics2D_GearJointDef = physics2D_GearJointDef;
3765
+ exports.physics2D_MotorJointDef = physics2D_MotorJointDef;
3766
+ exports.physics2D_MouseJointJointDef = physics2D_MouseJointJointDef;
3767
+ exports.physics2D_PrismaticJointDef = physics2D_PrismaticJointDef;
3768
+ exports.physics2D_PulleyJointDef = physics2D_PulleyJointDef;
3769
+ exports.physics2D_RevoluteJointDef = physics2D_RevoluteJointDef;
3770
+ exports.physics2D_WeldJointDef = physics2D_WeldJointDef;
3771
+ exports.physics2D_WheelJointDef = physics2D_WheelJointDef;
3772
+
3773
+ })(window.Laya = window.Laya || {}, Laya);
3774
+ //# sourceMappingURL=laya.physics2D.js.map