@nice2dev/game-engine 1.3.15 → 1.3.16

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 (434) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/accessibility/Accessibility.js +152 -165
  3. package/dist/cjs/ai/AI.js +292 -294
  4. package/dist/cjs/ai/BehaviorTree.js +1029 -1113
  5. package/dist/cjs/ai/StateMachine.js +694 -756
  6. package/dist/cjs/animation/Animation.js +232 -241
  7. package/dist/cjs/audio/AudioAdvanced.js +221 -236
  8. package/dist/cjs/audio/AudioBridge.js +441 -435
  9. package/dist/cjs/audio/AudioManager.js +242 -259
  10. package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
  11. package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
  12. package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
  13. package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
  14. package/dist/cjs/core/EventBus.js +51 -56
  15. package/dist/cjs/core/GameClock.js +62 -66
  16. package/dist/cjs/core/GameConfig.js +72 -79
  17. package/dist/cjs/core/GameLoop.js +80 -89
  18. package/dist/cjs/core/ServiceLocator.js +61 -65
  19. package/dist/cjs/core/Validation.js +72 -82
  20. package/dist/cjs/core/math.js +108 -112
  21. package/dist/cjs/devtools/DevTools.js +542 -563
  22. package/dist/cjs/devtools/DeveloperExperience.js +521 -559
  23. package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
  24. package/dist/cjs/dialogue/DialogueSystem.js +984 -986
  25. package/dist/cjs/docs/DocGenerator.js +339 -364
  26. package/dist/cjs/ecs/World.js +355 -371
  27. package/dist/cjs/editor/AchievementEditor.js +580 -636
  28. package/dist/cjs/editor/AdvancedEditor.js +184 -191
  29. package/dist/cjs/editor/AnimationRetargeting.js +696 -741
  30. package/dist/cjs/editor/AssetBrowser.js +1072 -1160
  31. package/dist/cjs/editor/AssetManager.js +187 -192
  32. package/dist/cjs/editor/ConsolePro.js +971 -1061
  33. package/dist/cjs/editor/CraftingEditor.js +680 -730
  34. package/dist/cjs/editor/DebugTools.js +187 -185
  35. package/dist/cjs/editor/DialogueSystem.js +844 -901
  36. package/dist/cjs/editor/LeaderboardSystem.js +429 -483
  37. package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
  38. package/dist/cjs/editor/PrefabSystem.js +772 -838
  39. package/dist/cjs/editor/ProfilerPanel.js +649 -700
  40. package/dist/cjs/editor/QuestEditor.js +792 -839
  41. package/dist/cjs/editor/ReplaySystem.js +585 -634
  42. package/dist/cjs/editor/SceneEditor.js +176 -200
  43. package/dist/cjs/editor/ScreenshotMode.js +621 -688
  44. package/dist/cjs/editor/ShaderGraph.js +1556 -1582
  45. package/dist/cjs/editor/TimelineEditor.js +715 -778
  46. package/dist/cjs/editor/UndoRedoPro.js +830 -904
  47. package/dist/cjs/editor/VRARMode.js +582 -645
  48. package/dist/cjs/engine/NiceGameEngine.js +141 -164
  49. package/dist/cjs/engine/SaveSystem.js +441 -495
  50. package/dist/cjs/enterprise/Enterprise.js +254 -261
  51. package/dist/cjs/export/BevyExporter.js +927 -967
  52. package/dist/cjs/export/CocosExporter.js +644 -673
  53. package/dist/cjs/export/Construct3Exporter.js +783 -794
  54. package/dist/cjs/export/DefoldExporter.js +1028 -1069
  55. package/dist/cjs/export/GDevelopExporter.js +674 -708
  56. package/dist/cjs/export/GameMakerExporter.js +791 -805
  57. package/dist/cjs/export/GodotExporter.js +1003 -1045
  58. package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
  59. package/dist/cjs/export/MonoGameExporter.js +1265 -1293
  60. package/dist/cjs/export/Pico8Exporter.js +766 -812
  61. package/dist/cjs/export/PlatformExporter.js +188 -206
  62. package/dist/cjs/export/RPGMakerExporter.js +860 -879
  63. package/dist/cjs/export/RobloxExporter.js +883 -919
  64. package/dist/cjs/export/Solar2DExporter.js +1218 -1256
  65. package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
  66. package/dist/cjs/export/Tic80Exporter.js +1210 -1267
  67. package/dist/cjs/export/UnityExporter.js +1116 -1131
  68. package/dist/cjs/export/UnrealExporter.js +889 -919
  69. package/dist/cjs/export/WebExporter.js +931 -970
  70. package/dist/cjs/export/index.js +42 -65
  71. package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
  72. package/dist/cjs/godot-integration/GodotImport.js +929 -1027
  73. package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
  74. package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
  75. package/dist/cjs/i18n/I18n.js +860 -900
  76. package/dist/cjs/i18n/useTranslation.js +84 -89
  77. package/dist/cjs/import/AsepriteImporter.js +658 -716
  78. package/dist/cjs/import/DragonBonesImporter.js +437 -461
  79. package/dist/cjs/import/GameMakerImporter.js +511 -521
  80. package/dist/cjs/import/GodotSceneImporter.js +788 -822
  81. package/dist/cjs/import/LDtkImporter.js +436 -454
  82. package/dist/cjs/import/Live2DImporter.js +497 -518
  83. package/dist/cjs/import/NdgFormat.js +424 -457
  84. package/dist/cjs/import/OgmoImporter.js +466 -493
  85. package/dist/cjs/import/RPGMakerImporter.js +451 -477
  86. package/dist/cjs/import/SceneImporter.js +378 -423
  87. package/dist/cjs/import/SpineImporter.js +511 -546
  88. package/dist/cjs/import/SpriterImporter.js +590 -613
  89. package/dist/cjs/import/TiledMapImporter.js +811 -846
  90. package/dist/cjs/import/UnitySceneImporter.js +687 -703
  91. package/dist/cjs/import/index.js +206 -251
  92. package/dist/cjs/index.js +275 -278
  93. package/dist/cjs/input/GamepadNavigation.js +185 -205
  94. package/dist/cjs/input/InputManager.js +397 -421
  95. package/dist/cjs/input/useGamepads.js +70 -81
  96. package/dist/cjs/integration/IconSprite.js +129 -256
  97. package/dist/cjs/inventory/InventorySystem.js +920 -995
  98. package/dist/cjs/kids/KidMode.js +997 -1022
  99. package/dist/cjs/kids/KidTools.js +570 -594
  100. package/dist/cjs/monetization/Monetization.js +170 -177
  101. package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
  102. package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
  103. package/dist/cjs/native-engine/AnimationSystem.js +731 -806
  104. package/dist/cjs/native-engine/AssetPipeline.js +454 -515
  105. package/dist/cjs/native-engine/AudioEngine.js +763 -804
  106. package/dist/cjs/native-engine/InputSystem.js +1075 -1145
  107. package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
  108. package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
  109. package/dist/cjs/native-engine/RenderingEngine.js +302 -350
  110. package/dist/cjs/native-engine/SceneGraph.js +769 -808
  111. package/dist/cjs/network/MultiplayerTransport.js +97 -132
  112. package/dist/cjs/network/Networking.js +549 -564
  113. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
  114. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
  115. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
  116. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
  117. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
  118. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
  119. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
  120. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
  121. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
  122. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
  123. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
  124. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
  125. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
  126. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
  127. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
  128. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
  129. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
  130. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
  131. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
  132. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
  133. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
  134. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
  135. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
  136. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
  137. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
  138. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
  139. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
  140. package/dist/cjs/pathfinding/Pathfinding.js +245 -263
  141. package/dist/cjs/performance/AssetStreaming.js +561 -635
  142. package/dist/cjs/performance/BenchmarkSuite.js +283 -311
  143. package/dist/cjs/performance/DeltaCompression.js +467 -526
  144. package/dist/cjs/performance/DeterministicPhysics.js +450 -498
  145. package/dist/cjs/performance/ECSOptimization.js +644 -695
  146. package/dist/cjs/performance/GameSaveSystem.js +509 -556
  147. package/dist/cjs/performance/HotReload.js +447 -500
  148. package/dist/cjs/performance/InputRecording.js +511 -561
  149. package/dist/cjs/performance/InterestManagement.js +453 -500
  150. package/dist/cjs/performance/LocalizationRuntime.js +376 -423
  151. package/dist/cjs/performance/MemoryManagement.js +410 -470
  152. package/dist/cjs/performance/ModSupport.js +445 -496
  153. package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
  154. package/dist/cjs/performance/NetworkPrediction.js +424 -482
  155. package/dist/cjs/performance/ObjectPooling.js +569 -617
  156. package/dist/cjs/performance/Performance.js +174 -190
  157. package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
  158. package/dist/cjs/performance/WebGPURenderer.js +656 -683
  159. package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
  160. package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
  161. package/dist/cjs/plugins/PluginSDK.js +432 -466
  162. package/dist/cjs/plugins/PluginTestKit.js +307 -330
  163. package/dist/cjs/procedural/Procedural.js +243 -254
  164. package/dist/cjs/procedural/WorldBuilding.js +297 -314
  165. package/dist/cjs/quest/QuestSystem.js +975 -932
  166. package/dist/cjs/release/MobileExport.js +157 -163
  167. package/dist/cjs/release/Release.js +225 -238
  168. package/dist/cjs/rendering/Camera2D.js +121 -124
  169. package/dist/cjs/rendering/Renderer2D.js +321 -335
  170. package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
  171. package/dist/cjs/runtime3d/Runtime3D.js +359 -378
  172. package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
  173. package/dist/cjs/scene/SceneManager.js +177 -193
  174. package/dist/cjs/scripting/GraphToAST.js +574 -547
  175. package/dist/cjs/scripting/LanguageExporter.js +254 -279
  176. package/dist/cjs/scripting/NodeGraph.js +546 -570
  177. package/dist/cjs/scripting/ScriptAST.js +31 -39
  178. package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
  179. package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
  180. package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
  181. package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
  182. package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
  183. package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
  184. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
  185. package/dist/cjs/social/Social.js +72 -80
  186. package/dist/cjs/systems/LightingSystem.js +844 -931
  187. package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
  188. package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
  189. package/dist/cjs/systems/TerrainSystem.js +985 -1098
  190. package/dist/cjs/templates/ActionTemplates.js +296 -309
  191. package/dist/cjs/templates/FightingTemplate.js +417 -463
  192. package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
  193. package/dist/cjs/templates/PartyTemplates.js +190 -202
  194. package/dist/cjs/templates/PuzzleTemplates.js +245 -261
  195. package/dist/cjs/templates/RPGTemplates.js +160 -178
  196. package/dist/cjs/templates/SportsTemplates.js +237 -250
  197. package/dist/cjs/templates/StrategyTemplates.js +143 -153
  198. package/dist/cjs/templates/SurvivalTemplate.js +336 -380
  199. package/dist/cjs/templates/WaveDefense.js +499 -526
  200. package/dist/cjs/tilemap/Tilemap.js +207 -214
  201. package/dist/cjs/tutorials/TutorialBranching.js +396 -417
  202. package/dist/cjs/tutorials/TutorialEngine.js +888 -931
  203. package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
  204. package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
  205. package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
  206. package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
  207. package/dist/cjs/ui/GameUI.js +295 -312
  208. package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
  209. package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
  210. package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
  211. package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
  212. package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
  213. package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
  214. package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
  215. package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
  216. package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
  217. package/dist/cjs/xr/ARVR.js +167 -175
  218. package/dist/esm/accessibility/Accessibility.js +160 -164
  219. package/dist/esm/ai/AI.js +310 -293
  220. package/dist/esm/ai/BehaviorTree.js +1057 -1112
  221. package/dist/esm/ai/StateMachine.js +709 -755
  222. package/dist/esm/animation/Animation.js +237 -240
  223. package/dist/esm/audio/AudioAdvanced.js +239 -235
  224. package/dist/esm/audio/AudioBridge.js +448 -434
  225. package/dist/esm/audio/AudioManager.js +243 -258
  226. package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
  227. package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
  228. package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
  229. package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
  230. package/dist/esm/core/EventBus.js +52 -55
  231. package/dist/esm/core/GameClock.js +63 -65
  232. package/dist/esm/core/GameConfig.js +77 -78
  233. package/dist/esm/core/GameLoop.js +81 -88
  234. package/dist/esm/core/ServiceLocator.js +63 -64
  235. package/dist/esm/core/Validation.js +82 -81
  236. package/dist/esm/core/math.js +109 -111
  237. package/dist/esm/devtools/DevTools.js +546 -562
  238. package/dist/esm/devtools/DeveloperExperience.js +535 -558
  239. package/dist/esm/devtools/GameplayAnalytics.js +647 -645
  240. package/dist/esm/dialogue/DialogueSystem.js +998 -985
  241. package/dist/esm/docs/DocGenerator.js +342 -363
  242. package/dist/esm/ecs/World.js +358 -370
  243. package/dist/esm/editor/AchievementEditor.js +584 -635
  244. package/dist/esm/editor/AdvancedEditor.js +191 -190
  245. package/dist/esm/editor/AnimationRetargeting.js +700 -740
  246. package/dist/esm/editor/AssetBrowser.js +1078 -1159
  247. package/dist/esm/editor/AssetManager.js +188 -191
  248. package/dist/esm/editor/ConsolePro.js +977 -1060
  249. package/dist/esm/editor/CraftingEditor.js +684 -729
  250. package/dist/esm/editor/DebugTools.js +194 -184
  251. package/dist/esm/editor/DialogueSystem.js +849 -900
  252. package/dist/esm/editor/LeaderboardSystem.js +433 -482
  253. package/dist/esm/editor/NiceGameEditor.js +1908 -1200
  254. package/dist/esm/editor/PrefabSystem.js +777 -837
  255. package/dist/esm/editor/ProfilerPanel.js +654 -699
  256. package/dist/esm/editor/QuestEditor.js +795 -838
  257. package/dist/esm/editor/ReplaySystem.js +591 -633
  258. package/dist/esm/editor/SceneEditor.js +189 -199
  259. package/dist/esm/editor/ScreenshotMode.js +628 -687
  260. package/dist/esm/editor/ShaderGraph.js +1565 -1581
  261. package/dist/esm/editor/TimelineEditor.js +733 -777
  262. package/dist/esm/editor/UndoRedoPro.js +835 -903
  263. package/dist/esm/editor/VRARMode.js +586 -644
  264. package/dist/esm/engine/NiceGameEngine.js +142 -163
  265. package/dist/esm/engine/SaveSystem.js +447 -494
  266. package/dist/esm/enterprise/Enterprise.js +265 -260
  267. package/dist/esm/export/BevyExporter.js +929 -966
  268. package/dist/esm/export/CocosExporter.js +646 -672
  269. package/dist/esm/export/Construct3Exporter.js +785 -793
  270. package/dist/esm/export/DefoldExporter.js +1030 -1068
  271. package/dist/esm/export/GDevelopExporter.js +676 -707
  272. package/dist/esm/export/GameMakerExporter.js +793 -804
  273. package/dist/esm/export/GodotExporter.js +1004 -1044
  274. package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
  275. package/dist/esm/export/MonoGameExporter.js +1267 -1292
  276. package/dist/esm/export/Pico8Exporter.js +768 -811
  277. package/dist/esm/export/PlatformExporter.js +193 -205
  278. package/dist/esm/export/RPGMakerExporter.js +862 -878
  279. package/dist/esm/export/RobloxExporter.js +885 -918
  280. package/dist/esm/export/Solar2DExporter.js +1220 -1255
  281. package/dist/esm/export/ThreeJSExporter.js +1007 -1072
  282. package/dist/esm/export/Tic80Exporter.js +1212 -1266
  283. package/dist/esm/export/UnityExporter.js +1117 -1130
  284. package/dist/esm/export/UnrealExporter.js +891 -918
  285. package/dist/esm/export/WebExporter.js +933 -969
  286. package/dist/esm/export/index.js +86 -71
  287. package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
  288. package/dist/esm/godot-integration/GodotImport.js +935 -1026
  289. package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
  290. package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
  291. package/dist/esm/i18n/I18n.js +871 -899
  292. package/dist/esm/i18n/useTranslation.js +88 -88
  293. package/dist/esm/import/AsepriteImporter.js +637 -715
  294. package/dist/esm/import/DragonBonesImporter.js +417 -460
  295. package/dist/esm/import/GameMakerImporter.js +491 -520
  296. package/dist/esm/import/GodotSceneImporter.js +767 -821
  297. package/dist/esm/import/LDtkImporter.js +415 -453
  298. package/dist/esm/import/Live2DImporter.js +477 -517
  299. package/dist/esm/import/NdgFormat.js +410 -456
  300. package/dist/esm/import/OgmoImporter.js +446 -492
  301. package/dist/esm/import/RPGMakerImporter.js +431 -476
  302. package/dist/esm/import/SceneImporter.js +385 -422
  303. package/dist/esm/import/SpineImporter.js +491 -545
  304. package/dist/esm/import/SpriterImporter.js +570 -612
  305. package/dist/esm/import/TiledMapImporter.js +790 -845
  306. package/dist/esm/import/UnitySceneImporter.js +666 -702
  307. package/dist/esm/import/index.js +247 -258
  308. package/dist/esm/index.js +1332 -188
  309. package/dist/esm/input/GamepadNavigation.js +187 -204
  310. package/dist/esm/input/InputManager.js +401 -420
  311. package/dist/esm/input/useGamepads.js +72 -80
  312. package/dist/esm/integration/IconSprite.js +143 -255
  313. package/dist/esm/inventory/InventorySystem.js +925 -994
  314. package/dist/esm/kids/KidMode.js +1003 -1021
  315. package/dist/esm/kids/KidTools.js +573 -593
  316. package/dist/esm/monetization/Monetization.js +180 -176
  317. package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
  318. package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
  319. package/dist/esm/native-engine/AnimationSystem.js +735 -805
  320. package/dist/esm/native-engine/AssetPipeline.js +456 -514
  321. package/dist/esm/native-engine/AudioEngine.js +765 -803
  322. package/dist/esm/native-engine/InputSystem.js +1079 -1144
  323. package/dist/esm/native-engine/NetworkingSystem.js +740 -792
  324. package/dist/esm/native-engine/PhysicsEngine.js +585 -606
  325. package/dist/esm/native-engine/RenderingEngine.js +304 -349
  326. package/dist/esm/native-engine/SceneGraph.js +773 -807
  327. package/dist/esm/network/MultiplayerTransport.js +99 -131
  328. package/dist/esm/network/Networking.js +556 -563
  329. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
  330. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
  331. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
  332. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
  333. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
  334. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
  335. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
  336. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
  337. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
  338. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
  339. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
  340. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
  341. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
  342. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
  343. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
  344. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
  345. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
  346. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
  347. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
  348. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
  349. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
  350. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
  351. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
  352. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
  353. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
  354. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
  355. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
  356. package/dist/esm/pathfinding/Pathfinding.js +249 -262
  357. package/dist/esm/performance/AssetStreaming.js +567 -634
  358. package/dist/esm/performance/BenchmarkSuite.js +285 -310
  359. package/dist/esm/performance/DeltaCompression.js +478 -525
  360. package/dist/esm/performance/DeterministicPhysics.js +479 -497
  361. package/dist/esm/performance/ECSOptimization.js +653 -694
  362. package/dist/esm/performance/GameSaveSystem.js +515 -555
  363. package/dist/esm/performance/HotReload.js +454 -499
  364. package/dist/esm/performance/InputRecording.js +520 -560
  365. package/dist/esm/performance/InterestManagement.js +460 -499
  366. package/dist/esm/performance/LocalizationRuntime.js +382 -422
  367. package/dist/esm/performance/MemoryManagement.js +415 -469
  368. package/dist/esm/performance/ModSupport.js +455 -495
  369. package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
  370. package/dist/esm/performance/NetworkPrediction.js +436 -481
  371. package/dist/esm/performance/ObjectPooling.js +582 -616
  372. package/dist/esm/performance/Performance.js +182 -189
  373. package/dist/esm/performance/PerformanceAdvanced.js +621 -636
  374. package/dist/esm/performance/WebGPURenderer.js +660 -682
  375. package/dist/esm/physics/PhysicsAdvanced.js +359 -378
  376. package/dist/esm/physics/PhysicsEngine2D.js +393 -426
  377. package/dist/esm/plugins/PluginSDK.js +435 -465
  378. package/dist/esm/plugins/PluginTestKit.js +315 -329
  379. package/dist/esm/procedural/Procedural.js +248 -253
  380. package/dist/esm/procedural/WorldBuilding.js +316 -313
  381. package/dist/esm/quest/QuestSystem.js +982 -931
  382. package/dist/esm/release/MobileExport.js +163 -162
  383. package/dist/esm/release/Release.js +234 -237
  384. package/dist/esm/rendering/Camera2D.js +122 -123
  385. package/dist/esm/rendering/Renderer2D.js +323 -334
  386. package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
  387. package/dist/esm/runtime3d/Runtime3D.js +368 -377
  388. package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
  389. package/dist/esm/scene/SceneManager.js +178 -192
  390. package/dist/esm/scripting/GraphToAST.js +576 -546
  391. package/dist/esm/scripting/LanguageExporter.js +263 -278
  392. package/dist/esm/scripting/NodeGraph.js +550 -569
  393. package/dist/esm/scripting/ScriptAST.js +45 -38
  394. package/dist/esm/scripting/VisualScripting2.js +1025 -1064
  395. package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
  396. package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
  397. package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
  398. package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
  399. package/dist/esm/scripting/exporters/RustExporter.js +460 -511
  400. package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
  401. package/dist/esm/social/Social.js +77 -79
  402. package/dist/esm/systems/LightingSystem.js +855 -930
  403. package/dist/esm/systems/ParticleSystem2.js +1453 -1450
  404. package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
  405. package/dist/esm/systems/TerrainSystem.js +996 -1097
  406. package/dist/esm/templates/ActionTemplates.js +307 -308
  407. package/dist/esm/templates/FightingTemplate.js +439 -462
  408. package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
  409. package/dist/esm/templates/PartyTemplates.js +206 -201
  410. package/dist/esm/templates/PuzzleTemplates.js +260 -260
  411. package/dist/esm/templates/RPGTemplates.js +172 -177
  412. package/dist/esm/templates/SportsTemplates.js +251 -249
  413. package/dist/esm/templates/StrategyTemplates.js +158 -152
  414. package/dist/esm/templates/SurvivalTemplate.js +367 -379
  415. package/dist/esm/templates/WaveDefense.js +501 -525
  416. package/dist/esm/tilemap/Tilemap.js +209 -213
  417. package/dist/esm/tutorials/TutorialBranching.js +399 -416
  418. package/dist/esm/tutorials/TutorialEngine.js +893 -930
  419. package/dist/esm/tutorials/TutorialOverlay.js +603 -639
  420. package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
  421. package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
  422. package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
  423. package/dist/esm/ui/GameUI.js +296 -311
  424. package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
  425. package/dist/esm/unity-integration/UnityImport.js +1071 -1175
  426. package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
  427. package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
  428. package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
  429. package/dist/esm/unreal-integration/UnrealImport.js +395 -411
  430. package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
  431. package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
  432. package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
  433. package/dist/esm/xr/ARVR.js +181 -174
  434. package/package.json +7 -12
@@ -1,1218 +1,1156 @@
1
- /**
2
- * @file PhysicsDebugSystem.ts
3
- * @description Advanced Physics Debug Visualization System
4
- * PRO-1.4: Professional Editor Features
5
- *
6
- * Features:
7
- * - Collider visualization (all shapes)
8
- * - Contact point visualization
9
- * - Force/velocity vectors
10
- * - Physics stats overlay
11
- * - Joint visualization
12
- * - Collision layers matrix
13
- * - Performance profiling
14
- * - Configurable visualizations
15
- */
16
1
  const DEFAULT_DEBUG_COLORS = {
17
- staticCollider: { r: 0.5, g: 0.5, b: 0.5, a: 0.5 },
18
- kinematicCollider: { r: 0.8, g: 0.5, b: 0.2, a: 0.5 },
19
- dynamicCollider: { r: 0.2, g: 0.8, b: 0.2, a: 0.5 },
20
- triggerCollider: { r: 0.2, g: 0.8, b: 0.8, a: 0.3 },
21
- sleepingCollider: { r: 0.4, g: 0.4, b: 0.6, a: 0.3 },
22
- activeBody: { r: 0.2, g: 1.0, b: 0.2, a: 0.8 },
23
- sleepingBody: { r: 0.5, g: 0.5, b: 0.8, a: 0.5 },
24
- contactPoint: { r: 1.0, g: 0.5, b: 0.0, a: 1.0 },
25
- contactNormal: { r: 0.0, g: 1.0, b: 1.0, a: 0.8 },
26
- contactImpulse: { r: 1.0, g: 0.0, b: 0.0, a: 0.8 },
27
- velocity: { r: 0.0, g: 1.0, b: 0.0, a: 0.8 },
28
- angularVelocity: { r: 1.0, g: 1.0, b: 0.0, a: 0.8 },
29
- force: { r: 1.0, g: 0.0, b: 0.5, a: 0.8 },
30
- torque: { r: 0.5, g: 0.0, b: 1.0, a: 0.8 },
31
- jointActive: { r: 0.0, g: 0.8, b: 0.0, a: 0.8 },
32
- jointBroken: { r: 1.0, g: 0.0, b: 0.0, a: 0.8 },
33
- jointLimit: { r: 1.0, g: 0.5, b: 0.0, a: 0.6 },
34
- jointMotor: { r: 0.0, g: 0.5, b: 1.0, a: 0.8 },
35
- raycastHit: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 },
36
- raycastMiss: { r: 0.5, g: 0.5, b: 0.5, a: 0.5 },
37
- aabbOverlap: { r: 1.0, g: 1.0, b: 0.0, a: 0.3 },
38
- layerColors: [
39
- { r: 1.0, g: 0.0, b: 0.0, a: 0.5 },
40
- { r: 0.0, g: 1.0, b: 0.0, a: 0.5 },
41
- { r: 0.0, g: 0.0, b: 1.0, a: 0.5 },
42
- { r: 1.0, g: 1.0, b: 0.0, a: 0.5 },
43
- { r: 1.0, g: 0.0, b: 1.0, a: 0.5 },
44
- { r: 0.0, g: 1.0, b: 1.0, a: 0.5 },
45
- { r: 1.0, g: 0.5, b: 0.0, a: 0.5 },
46
- { r: 0.5, g: 0.0, b: 1.0, a: 0.5 },
47
- ],
2
+ staticCollider: { r: 0.5, g: 0.5, b: 0.5, a: 0.5 },
3
+ kinematicCollider: { r: 0.8, g: 0.5, b: 0.2, a: 0.5 },
4
+ dynamicCollider: { r: 0.2, g: 0.8, b: 0.2, a: 0.5 },
5
+ triggerCollider: { r: 0.2, g: 0.8, b: 0.8, a: 0.3 },
6
+ sleepingCollider: { r: 0.4, g: 0.4, b: 0.6, a: 0.3 },
7
+ activeBody: { r: 0.2, g: 1, b: 0.2, a: 0.8 },
8
+ sleepingBody: { r: 0.5, g: 0.5, b: 0.8, a: 0.5 },
9
+ contactPoint: { r: 1, g: 0.5, b: 0, a: 1 },
10
+ contactNormal: { r: 0, g: 1, b: 1, a: 0.8 },
11
+ contactImpulse: { r: 1, g: 0, b: 0, a: 0.8 },
12
+ velocity: { r: 0, g: 1, b: 0, a: 0.8 },
13
+ angularVelocity: { r: 1, g: 1, b: 0, a: 0.8 },
14
+ force: { r: 1, g: 0, b: 0.5, a: 0.8 },
15
+ torque: { r: 0.5, g: 0, b: 1, a: 0.8 },
16
+ jointActive: { r: 0, g: 0.8, b: 0, a: 0.8 },
17
+ jointBroken: { r: 1, g: 0, b: 0, a: 0.8 },
18
+ jointLimit: { r: 1, g: 0.5, b: 0, a: 0.6 },
19
+ jointMotor: { r: 0, g: 0.5, b: 1, a: 0.8 },
20
+ raycastHit: { r: 1, g: 0, b: 0, a: 1 },
21
+ raycastMiss: { r: 0.5, g: 0.5, b: 0.5, a: 0.5 },
22
+ aabbOverlap: { r: 1, g: 1, b: 0, a: 0.3 },
23
+ layerColors: [
24
+ { r: 1, g: 0, b: 0, a: 0.5 },
25
+ { r: 0, g: 1, b: 0, a: 0.5 },
26
+ { r: 0, g: 0, b: 1, a: 0.5 },
27
+ { r: 1, g: 1, b: 0, a: 0.5 },
28
+ { r: 1, g: 0, b: 1, a: 0.5 },
29
+ { r: 0, g: 1, b: 1, a: 0.5 },
30
+ { r: 1, g: 0.5, b: 0, a: 0.5 },
31
+ { r: 0.5, g: 0, b: 1, a: 0.5 }
32
+ ]
48
33
  };
49
34
  const DEFAULT_DEBUG_OPTIONS = {
50
- enabled: true,
51
- showColliders: true,
52
- showTriggers: true,
53
- showContactPoints: true,
54
- showContactNormals: true,
55
- showContactImpulse: false,
56
- showVelocities: true,
57
- showAngularVelocities: false,
58
- showForces: false,
59
- showJoints: true,
60
- showJointLimits: true,
61
- showCenterOfMass: true,
62
- showAABB: false,
63
- showSleepState: true,
64
- showLayerColors: false,
65
- showRaycasts: true,
66
- filterByLayer: null,
67
- filterByBodyType: null,
68
- filterByEntity: null,
69
- hideStaticColliders: false,
70
- hideSleepingBodies: false,
71
- velocityScale: 1,
72
- forceScale: 0.1,
73
- normalScale: 1,
74
- impulseScale: 0.01,
75
- colliderLineWidth: 2,
76
- vectorLineWidth: 2,
77
- jointLineWidth: 3,
78
- contactHistoryDuration: 500,
79
- maxContactHistory: 100,
80
- showStatsOverlay: true,
81
- statsPosition: 'top-left',
82
- colors: DEFAULT_DEBUG_COLORS,
35
+ enabled: true,
36
+ showColliders: true,
37
+ showTriggers: true,
38
+ showContactPoints: true,
39
+ showContactNormals: true,
40
+ showContactImpulse: false,
41
+ showVelocities: true,
42
+ showAngularVelocities: false,
43
+ showForces: false,
44
+ showJoints: true,
45
+ showJointLimits: true,
46
+ showCenterOfMass: true,
47
+ showAABB: false,
48
+ showSleepState: true,
49
+ showLayerColors: false,
50
+ showRaycasts: true,
51
+ filterByLayer: null,
52
+ filterByBodyType: null,
53
+ filterByEntity: null,
54
+ hideStaticColliders: false,
55
+ hideSleepingBodies: false,
56
+ velocityScale: 1,
57
+ forceScale: 0.1,
58
+ normalScale: 1,
59
+ impulseScale: 0.01,
60
+ colliderLineWidth: 2,
61
+ vectorLineWidth: 2,
62
+ jointLineWidth: 3,
63
+ contactHistoryDuration: 500,
64
+ maxContactHistory: 100,
65
+ showStatsOverlay: true,
66
+ statsPosition: "top-left",
67
+ colors: DEFAULT_DEBUG_COLORS
83
68
  };
84
- // ============================================================
85
- // Physics Debug System
86
- // ============================================================
87
69
  class PhysicsDebugSystem {
88
- constructor() {
89
- this.options = { ...DEFAULT_DEBUG_OPTIONS };
90
- this.drawCommands = [];
91
- this.contactHistory = [];
92
- // Data caches (updated by physics engine)
93
- this.colliders2D = new Map();
94
- this.colliders3D = new Map();
95
- this.bodies2D = new Map();
96
- this.bodies3D = new Map();
97
- this.joints2D = new Map();
98
- this.joints3D = new Map();
99
- this.transforms2D = new Map();
100
- this.transforms3D = new Map();
101
- this.collisionPairs = [];
102
- this.raycasts = [];
103
- this.is3D = false;
104
- this.stats = this.createEmptyStats();
70
+ constructor() {
71
+ this.options = { ...DEFAULT_DEBUG_OPTIONS };
72
+ this.drawCommands = [];
73
+ this.contactHistory = [];
74
+ this.colliders2D = /* @__PURE__ */ new Map();
75
+ this.colliders3D = /* @__PURE__ */ new Map();
76
+ this.bodies2D = /* @__PURE__ */ new Map();
77
+ this.bodies3D = /* @__PURE__ */ new Map();
78
+ this.joints2D = /* @__PURE__ */ new Map();
79
+ this.joints3D = /* @__PURE__ */ new Map();
80
+ this.transforms2D = /* @__PURE__ */ new Map();
81
+ this.transforms3D = /* @__PURE__ */ new Map();
82
+ this.collisionPairs = [];
83
+ this.raycasts = [];
84
+ this.is3D = false;
85
+ this.stats = this.createEmptyStats();
86
+ }
87
+ createEmptyStats() {
88
+ return {
89
+ totalBodies: 0,
90
+ dynamicBodies: 0,
91
+ kinematicBodies: 0,
92
+ staticBodies: 0,
93
+ awakeBodies: 0,
94
+ sleepingBodies: 0,
95
+ totalColliders: 0,
96
+ activeColliders: 0,
97
+ triggers: 0,
98
+ collisionPairs: 0,
99
+ contactPoints: 0,
100
+ islandCount: 0,
101
+ stepTime: 0,
102
+ broadphaseTime: 0,
103
+ narrowphaseTime: 0,
104
+ solverTime: 0,
105
+ integrationTime: 0,
106
+ bodyMemory: 0,
107
+ colliderMemory: 0,
108
+ contactMemory: 0,
109
+ totalJoints: 0,
110
+ activeJoints: 0,
111
+ brokenJoints: 0,
112
+ raycastsThisFrame: 0,
113
+ overlapTestsThisFrame: 0
114
+ };
115
+ }
116
+ // ─── Configuration ─────────────────────────────────────
117
+ setOptions(options) {
118
+ this.options = { ...this.options, ...options };
119
+ }
120
+ getOptions() {
121
+ return { ...this.options };
122
+ }
123
+ setEnabled(enabled) {
124
+ this.options.enabled = enabled;
125
+ }
126
+ isEnabled() {
127
+ return this.options.enabled;
128
+ }
129
+ set3DMode(is3D) {
130
+ this.is3D = is3D;
131
+ }
132
+ // ─── Data Update (called by physics engine) ────────────
133
+ updateCollider2D(collider) {
134
+ this.colliders2D.set(collider.id, collider);
135
+ }
136
+ removeCollider2D(colliderId) {
137
+ this.colliders2D.delete(colliderId);
138
+ }
139
+ updateCollider3D(collider) {
140
+ this.colliders3D.set(collider.id, collider);
141
+ }
142
+ removeCollider3D(colliderId) {
143
+ this.colliders3D.delete(colliderId);
144
+ }
145
+ updateBody2D(body) {
146
+ this.bodies2D.set(body.id, body);
147
+ }
148
+ removeBody2D(bodyId) {
149
+ this.bodies2D.delete(bodyId);
150
+ }
151
+ updateBody3D(body) {
152
+ this.bodies3D.set(body.id, body);
153
+ }
154
+ removeBody3D(bodyId) {
155
+ this.bodies3D.delete(bodyId);
156
+ }
157
+ updateTransform2D(entityId, transform) {
158
+ this.transforms2D.set(entityId, transform);
159
+ }
160
+ updateTransform3D(entityId, transform) {
161
+ this.transforms3D.set(entityId, transform);
162
+ }
163
+ updateJoint2D(joint) {
164
+ this.joints2D.set(joint.id, joint);
165
+ }
166
+ removeJoint2D(jointId) {
167
+ this.joints2D.delete(jointId);
168
+ }
169
+ updateJoint3D(joint) {
170
+ this.joints3D.set(joint.id, joint);
171
+ }
172
+ removeJoint3D(jointId) {
173
+ this.joints3D.delete(jointId);
174
+ }
175
+ setCollisionPairs(pairs) {
176
+ this.collisionPairs = pairs;
177
+ const now = Date.now();
178
+ for (const pair of pairs) {
179
+ for (const contact of pair.contacts) {
180
+ if (this.contactHistory.length >= this.options.maxContactHistory) {
181
+ this.contactHistory.shift();
182
+ }
183
+ "z" in contact.point;
184
+ this.contactHistory.push({
185
+ timestamp: now,
186
+ point: contact.point,
187
+ normal: contact.normal,
188
+ impulse: contact.impulse,
189
+ idA: pair.idA,
190
+ idB: pair.idB
191
+ });
192
+ }
193
+ }
194
+ const cutoff = now - this.options.contactHistoryDuration;
195
+ this.contactHistory = this.contactHistory.filter((c) => c.timestamp > cutoff);
196
+ }
197
+ addRaycast(origin, direction, maxDistance, hit) {
198
+ this.raycasts.push({ origin, direction, maxDistance, hit });
199
+ }
200
+ updateStats(stats) {
201
+ Object.assign(this.stats, stats);
202
+ }
203
+ // ─── Generate Draw Commands ────────────────────────────
204
+ generateDrawCommands() {
205
+ this.drawCommands = [];
206
+ if (!this.options.enabled) {
207
+ return this.drawCommands;
208
+ }
209
+ this.calculateStats();
210
+ if (this.is3D) {
211
+ this.generateDrawCommands3D();
212
+ } else {
213
+ this.generateDrawCommands2D();
214
+ }
215
+ this.drawCommands.sort((a, b) => a.zOrder - b.zOrder);
216
+ return this.drawCommands;
217
+ }
218
+ generateDrawCommands2D() {
219
+ const opts = this.options;
220
+ const colors = opts.colors;
221
+ if (opts.showColliders || opts.showTriggers) {
222
+ for (const [_id, collider] of this.colliders2D) {
223
+ if (!this.shouldDrawCollider2D(collider)) {
224
+ continue;
225
+ }
226
+ const transform = this.transforms2D.get(collider.entityId);
227
+ if (!transform) {
228
+ continue;
229
+ }
230
+ const body = this.findBody2DForEntity(collider.entityId);
231
+ const color = this.getColliderColor2D(collider, body);
232
+ this.drawCollider2D(collider, transform, color);
233
+ }
234
+ }
235
+ if (opts.showVelocities) {
236
+ for (const [_id, body] of this.bodies2D) {
237
+ if (body.bodyType === "static") {
238
+ continue;
239
+ }
240
+ if (opts.hideSleepingBodies && body.isSleeping) {
241
+ continue;
242
+ }
243
+ const transform = this.transforms2D.get(body.entityId);
244
+ if (!transform) {
245
+ continue;
246
+ }
247
+ const endX = transform.position.x + body.linearVelocity.x * opts.velocityScale;
248
+ const endY = transform.position.y + body.linearVelocity.y * opts.velocityScale;
249
+ this.drawCommands.push({
250
+ type: "arrow",
251
+ color: colors.velocity,
252
+ zOrder: 10,
253
+ points: [transform.position, { x: endX, y: endY }],
254
+ lineWidth: opts.vectorLineWidth
255
+ });
256
+ }
257
+ }
258
+ if (opts.showAngularVelocities) {
259
+ for (const [_id, body] of this.bodies2D) {
260
+ if (body.bodyType === "static") {
261
+ continue;
262
+ }
263
+ const transform = this.transforms2D.get(body.entityId);
264
+ if (!transform) {
265
+ continue;
266
+ }
267
+ const radius = Math.abs(body.angularVelocity) * opts.velocityScale * 0.5;
268
+ this.drawCommands.push({
269
+ type: "arc",
270
+ color: colors.angularVelocity,
271
+ zOrder: 10,
272
+ position: transform.position,
273
+ radius: Math.max(radius, 0.2),
274
+ startAngle: 0,
275
+ endAngle: body.angularVelocity > 0 ? Math.PI : -Math.PI,
276
+ lineWidth: opts.vectorLineWidth
277
+ });
278
+ }
279
+ }
280
+ if (opts.showForces) {
281
+ for (const [_id, body] of this.bodies2D) {
282
+ const transform = this.transforms2D.get(body.entityId);
283
+ if (!transform) {
284
+ continue;
285
+ }
286
+ if (body.forceAccumulator.x !== 0 || body.forceAccumulator.y !== 0) {
287
+ const endX = transform.position.x + body.forceAccumulator.x * opts.forceScale;
288
+ const endY = transform.position.y + body.forceAccumulator.y * opts.forceScale;
289
+ this.drawCommands.push({
290
+ type: "arrow",
291
+ color: colors.force,
292
+ zOrder: 11,
293
+ points: [transform.position, { x: endX, y: endY }],
294
+ lineWidth: opts.vectorLineWidth
295
+ });
296
+ }
297
+ }
298
+ }
299
+ if (opts.showJoints) {
300
+ for (const [_id, joint] of this.joints2D) {
301
+ this.drawJoint2D(joint);
302
+ }
303
+ }
304
+ if (opts.showContactPoints || opts.showContactNormals || opts.showContactImpulse) {
305
+ this.drawContacts2D();
306
+ }
307
+ if (opts.showRaycasts) {
308
+ this.drawRaycasts2D();
309
+ }
310
+ if (opts.showCenterOfMass) {
311
+ for (const [_id, body] of this.bodies2D) {
312
+ if (body.bodyType === "static") {
313
+ continue;
314
+ }
315
+ const transform = this.transforms2D.get(body.entityId);
316
+ if (!transform) {
317
+ continue;
318
+ }
319
+ this.drawCommands.push({
320
+ type: "cross",
321
+ color: colors.activeBody,
322
+ zOrder: 12,
323
+ position: transform.position,
324
+ size: { x: 0.3, y: 0.3 },
325
+ lineWidth: 2
326
+ });
327
+ }
105
328
  }
106
- createEmptyStats() {
107
- return {
108
- totalBodies: 0,
109
- dynamicBodies: 0,
110
- kinematicBodies: 0,
111
- staticBodies: 0,
112
- awakeBodies: 0,
113
- sleepingBodies: 0,
114
- totalColliders: 0,
115
- activeColliders: 0,
116
- triggers: 0,
117
- collisionPairs: 0,
118
- contactPoints: 0,
119
- islandCount: 0,
120
- stepTime: 0,
121
- broadphaseTime: 0,
122
- narrowphaseTime: 0,
123
- solverTime: 0,
124
- integrationTime: 0,
125
- bodyMemory: 0,
126
- colliderMemory: 0,
127
- contactMemory: 0,
128
- totalJoints: 0,
129
- activeJoints: 0,
130
- brokenJoints: 0,
131
- raycastsThisFrame: 0,
132
- overlapTestsThisFrame: 0,
329
+ }
330
+ generateDrawCommands3D() {
331
+ const opts = this.options;
332
+ const colors = opts.colors;
333
+ if (opts.showColliders || opts.showTriggers) {
334
+ for (const [_id, collider] of this.colliders3D) {
335
+ if (!this.shouldDrawCollider3D(collider)) {
336
+ continue;
337
+ }
338
+ const transform = this.transforms3D.get(collider.entityId);
339
+ if (!transform) {
340
+ continue;
341
+ }
342
+ const body = this.findBody3DForEntity(collider.entityId);
343
+ const color = this.getColliderColor3D(collider, body);
344
+ this.drawCollider3D(collider, transform, color);
345
+ }
346
+ }
347
+ if (opts.showVelocities) {
348
+ for (const [_id, body] of this.bodies3D) {
349
+ if (body.bodyType === "static") {
350
+ continue;
351
+ }
352
+ if (opts.hideSleepingBodies && body.isSleeping) {
353
+ continue;
354
+ }
355
+ const transform = this.transforms3D.get(body.entityId);
356
+ if (!transform) {
357
+ continue;
358
+ }
359
+ const end = {
360
+ x: transform.position.x + body.linearVelocity.x * opts.velocityScale,
361
+ y: transform.position.y + body.linearVelocity.y * opts.velocityScale,
362
+ z: transform.position.z + body.linearVelocity.z * opts.velocityScale
133
363
  };
364
+ this.drawCommands.push({
365
+ type: "arrow",
366
+ color: colors.velocity,
367
+ zOrder: 10,
368
+ points: [transform.position, end],
369
+ lineWidth: opts.vectorLineWidth
370
+ });
371
+ }
134
372
  }
135
- // ─── Configuration ─────────────────────────────────────
136
- setOptions(options) {
137
- this.options = { ...this.options, ...options };
373
+ if (opts.showJoints) {
374
+ for (const [_id, joint] of this.joints3D) {
375
+ this.drawJoint3D(joint);
376
+ }
138
377
  }
139
- getOptions() {
140
- return { ...this.options };
378
+ if (opts.showContactPoints || opts.showContactNormals) {
379
+ this.drawContacts3D();
141
380
  }
142
- setEnabled(enabled) {
143
- this.options.enabled = enabled;
381
+ if (opts.showRaycasts) {
382
+ this.drawRaycasts3D();
144
383
  }
145
- isEnabled() {
146
- return this.options.enabled;
384
+ }
385
+ shouldDrawCollider2D(collider) {
386
+ const opts = this.options;
387
+ if (collider.isTrigger && !opts.showTriggers) {
388
+ return false;
147
389
  }
148
- set3DMode(is3D) {
149
- this.is3D = is3D;
390
+ if (!collider.isTrigger && !opts.showColliders) {
391
+ return false;
150
392
  }
151
- // ─── Data Update (called by physics engine) ────────────
152
- updateCollider2D(collider) {
153
- this.colliders2D.set(collider.id, collider);
393
+ if (opts.filterByLayer !== null && collider.layer !== opts.filterByLayer) {
394
+ return false;
154
395
  }
155
- removeCollider2D(colliderId) {
156
- this.colliders2D.delete(colliderId);
396
+ if (opts.filterByEntity !== null && !opts.filterByEntity.includes(collider.entityId)) {
397
+ return false;
157
398
  }
158
- updateCollider3D(collider) {
159
- this.colliders3D.set(collider.id, collider);
399
+ const body = this.findBody2DForEntity(collider.entityId);
400
+ if (body) {
401
+ if (opts.filterByBodyType !== null && body.bodyType !== opts.filterByBodyType) {
402
+ return false;
403
+ }
404
+ if (opts.hideStaticColliders && body.bodyType === "static") {
405
+ return false;
406
+ }
407
+ if (opts.hideSleepingBodies && body.isSleeping) {
408
+ return false;
409
+ }
160
410
  }
161
- removeCollider3D(colliderId) {
162
- this.colliders3D.delete(colliderId);
411
+ return true;
412
+ }
413
+ shouldDrawCollider3D(collider) {
414
+ const opts = this.options;
415
+ if (collider.isTrigger && !opts.showTriggers) {
416
+ return false;
163
417
  }
164
- updateBody2D(body) {
165
- this.bodies2D.set(body.id, body);
418
+ if (!collider.isTrigger && !opts.showColliders) {
419
+ return false;
166
420
  }
167
- removeBody2D(bodyId) {
168
- this.bodies2D.delete(bodyId);
421
+ if (opts.filterByLayer !== null && collider.layer !== opts.filterByLayer) {
422
+ return false;
169
423
  }
170
- updateBody3D(body) {
171
- this.bodies3D.set(body.id, body);
424
+ if (opts.filterByEntity !== null && !opts.filterByEntity.includes(collider.entityId)) {
425
+ return false;
172
426
  }
173
- removeBody3D(bodyId) {
174
- this.bodies3D.delete(bodyId);
427
+ const body = this.findBody3DForEntity(collider.entityId);
428
+ if (body) {
429
+ if (opts.filterByBodyType !== null && body.bodyType !== opts.filterByBodyType) {
430
+ return false;
431
+ }
432
+ if (opts.hideStaticColliders && body.bodyType === "static") {
433
+ return false;
434
+ }
435
+ if (opts.hideSleepingBodies && body.isSleeping) {
436
+ return false;
437
+ }
175
438
  }
176
- updateTransform2D(entityId, transform) {
177
- this.transforms2D.set(entityId, transform);
439
+ return true;
440
+ }
441
+ findBody2DForEntity(entityId) {
442
+ for (const body of this.bodies2D.values()) {
443
+ if (body.entityId === entityId) {
444
+ return body;
445
+ }
178
446
  }
179
- updateTransform3D(entityId, transform) {
180
- this.transforms3D.set(entityId, transform);
447
+ return void 0;
448
+ }
449
+ findBody3DForEntity(entityId) {
450
+ for (const body of this.bodies3D.values()) {
451
+ if (body.entityId === entityId) {
452
+ return body;
453
+ }
181
454
  }
182
- updateJoint2D(joint) {
183
- this.joints2D.set(joint.id, joint);
455
+ return void 0;
456
+ }
457
+ getColliderColor2D(collider, body) {
458
+ const colors = this.options.colors;
459
+ if (this.options.showLayerColors && collider.layer < colors.layerColors.length) {
460
+ return colors.layerColors[collider.layer];
184
461
  }
185
- removeJoint2D(jointId) {
186
- this.joints2D.delete(jointId);
462
+ if (collider.isTrigger) {
463
+ return colors.triggerCollider;
187
464
  }
188
- updateJoint3D(joint) {
189
- this.joints3D.set(joint.id, joint);
465
+ if (!body) {
466
+ return colors.staticCollider;
190
467
  }
191
- removeJoint3D(jointId) {
192
- this.joints3D.delete(jointId);
468
+ if (body.isSleeping) {
469
+ return colors.sleepingCollider;
193
470
  }
194
- setCollisionPairs(pairs) {
195
- this.collisionPairs = pairs;
196
- // Add to contact history
197
- const now = Date.now();
198
- for (const pair of pairs) {
199
- for (const contact of pair.contacts) {
200
- if (this.contactHistory.length >= this.options.maxContactHistory) {
201
- this.contactHistory.shift();
202
- }
203
- 'z' in contact.point;
204
- this.contactHistory.push({
205
- timestamp: now,
206
- point: contact.point,
207
- normal: contact.normal,
208
- impulse: contact.impulse,
209
- idA: pair.idA,
210
- idB: pair.idB,
211
- });
212
- }
213
- }
214
- // Prune old history
215
- const cutoff = now - this.options.contactHistoryDuration;
216
- this.contactHistory = this.contactHistory.filter((c) => c.timestamp > cutoff);
471
+ switch (body.bodyType) {
472
+ case "static":
473
+ return colors.staticCollider;
474
+ case "kinematic":
475
+ return colors.kinematicCollider;
476
+ case "dynamic":
477
+ return colors.dynamicCollider;
217
478
  }
218
- addRaycast(origin, direction, maxDistance, hit) {
219
- this.raycasts.push({ origin, direction, maxDistance, hit });
479
+ }
480
+ getColliderColor3D(collider, body) {
481
+ const colors = this.options.colors;
482
+ if (this.options.showLayerColors && collider.layer < colors.layerColors.length) {
483
+ return colors.layerColors[collider.layer];
220
484
  }
221
- updateStats(stats) {
222
- Object.assign(this.stats, stats);
485
+ if (collider.isTrigger) {
486
+ return colors.triggerCollider;
223
487
  }
224
- // ─── Generate Draw Commands ────────────────────────────
225
- generateDrawCommands() {
226
- this.drawCommands = [];
227
- if (!this.options.enabled) {
228
- return this.drawCommands;
229
- }
230
- // Calculate stats
231
- this.calculateStats();
232
- if (this.is3D) {
233
- this.generateDrawCommands3D();
234
- }
235
- else {
236
- this.generateDrawCommands2D();
237
- }
238
- // Sort by zOrder
239
- this.drawCommands.sort((a, b) => a.zOrder - b.zOrder);
240
- return this.drawCommands;
488
+ if (!body) {
489
+ return colors.staticCollider;
241
490
  }
242
- generateDrawCommands2D() {
243
- const opts = this.options;
244
- const colors = opts.colors;
245
- // Draw colliders
246
- if (opts.showColliders || opts.showTriggers) {
247
- for (const [_id, collider] of this.colliders2D) {
248
- if (!this.shouldDrawCollider2D(collider)) {
249
- continue;
250
- }
251
- const transform = this.transforms2D.get(collider.entityId);
252
- if (!transform) {
253
- continue;
254
- }
255
- const body = this.findBody2DForEntity(collider.entityId);
256
- const color = this.getColliderColor2D(collider, body);
257
- this.drawCollider2D(collider, transform, color);
258
- }
259
- }
260
- // Draw velocities
261
- if (opts.showVelocities) {
262
- for (const [_id, body] of this.bodies2D) {
263
- if (body.bodyType === 'static') {
264
- continue;
265
- }
266
- if (opts.hideSleepingBodies && body.isSleeping) {
267
- continue;
268
- }
269
- const transform = this.transforms2D.get(body.entityId);
270
- if (!transform) {
271
- continue;
272
- }
273
- const endX = transform.position.x + body.linearVelocity.x * opts.velocityScale;
274
- const endY = transform.position.y + body.linearVelocity.y * opts.velocityScale;
275
- this.drawCommands.push({
276
- type: 'arrow',
277
- color: colors.velocity,
278
- zOrder: 10,
279
- points: [transform.position, { x: endX, y: endY }],
280
- lineWidth: opts.vectorLineWidth,
281
- });
282
- }
283
- }
284
- // Draw angular velocities
285
- if (opts.showAngularVelocities) {
286
- for (const [_id, body] of this.bodies2D) {
287
- if (body.bodyType === 'static') {
288
- continue;
289
- }
290
- const transform = this.transforms2D.get(body.entityId);
291
- if (!transform) {
292
- continue;
293
- }
294
- const radius = Math.abs(body.angularVelocity) * opts.velocityScale * 0.5;
295
- this.drawCommands.push({
296
- type: 'arc',
297
- color: colors.angularVelocity,
298
- zOrder: 10,
299
- position: transform.position,
300
- radius: Math.max(radius, 0.2),
301
- startAngle: 0,
302
- endAngle: body.angularVelocity > 0 ? Math.PI : -Math.PI,
303
- lineWidth: opts.vectorLineWidth,
304
- });
305
- }
306
- }
307
- // Draw forces
308
- if (opts.showForces) {
309
- for (const [_id, body] of this.bodies2D) {
310
- const transform = this.transforms2D.get(body.entityId);
311
- if (!transform) {
312
- continue;
313
- }
314
- if (body.forceAccumulator.x !== 0 || body.forceAccumulator.y !== 0) {
315
- const endX = transform.position.x + body.forceAccumulator.x * opts.forceScale;
316
- const endY = transform.position.y + body.forceAccumulator.y * opts.forceScale;
317
- this.drawCommands.push({
318
- type: 'arrow',
319
- color: colors.force,
320
- zOrder: 11,
321
- points: [transform.position, { x: endX, y: endY }],
322
- lineWidth: opts.vectorLineWidth,
323
- });
324
- }
325
- }
326
- }
327
- // Draw joints
328
- if (opts.showJoints) {
329
- for (const [_id, joint] of this.joints2D) {
330
- this.drawJoint2D(joint);
331
- }
332
- }
333
- // Draw contact points
334
- if (opts.showContactPoints || opts.showContactNormals || opts.showContactImpulse) {
335
- this.drawContacts2D();
336
- }
337
- // Draw raycasts
338
- if (opts.showRaycasts) {
339
- this.drawRaycasts2D();
340
- }
341
- // Draw center of mass
342
- if (opts.showCenterOfMass) {
343
- for (const [_id, body] of this.bodies2D) {
344
- if (body.bodyType === 'static') {
345
- continue;
346
- }
347
- const transform = this.transforms2D.get(body.entityId);
348
- if (!transform) {
349
- continue;
350
- }
351
- this.drawCommands.push({
352
- type: 'cross',
353
- color: colors.activeBody,
354
- zOrder: 12,
355
- position: transform.position,
356
- size: { x: 0.3, y: 0.3 },
357
- lineWidth: 2,
358
- });
359
- }
360
- }
491
+ if (body.isSleeping) {
492
+ return colors.sleepingCollider;
361
493
  }
362
- generateDrawCommands3D() {
363
- const opts = this.options;
364
- const colors = opts.colors;
365
- // Draw colliders
366
- if (opts.showColliders || opts.showTriggers) {
367
- for (const [_id, collider] of this.colliders3D) {
368
- if (!this.shouldDrawCollider3D(collider)) {
369
- continue;
370
- }
371
- const transform = this.transforms3D.get(collider.entityId);
372
- if (!transform) {
373
- continue;
374
- }
375
- const body = this.findBody3DForEntity(collider.entityId);
376
- const color = this.getColliderColor3D(collider, body);
377
- this.drawCollider3D(collider, transform, color);
378
- }
379
- }
380
- // Draw velocities
381
- if (opts.showVelocities) {
382
- for (const [_id, body] of this.bodies3D) {
383
- if (body.bodyType === 'static') {
384
- continue;
385
- }
386
- if (opts.hideSleepingBodies && body.isSleeping) {
387
- continue;
388
- }
389
- const transform = this.transforms3D.get(body.entityId);
390
- if (!transform) {
391
- continue;
392
- }
393
- const end = {
394
- x: transform.position.x + body.linearVelocity.x * opts.velocityScale,
395
- y: transform.position.y + body.linearVelocity.y * opts.velocityScale,
396
- z: transform.position.z + body.linearVelocity.z * opts.velocityScale,
397
- };
398
- this.drawCommands.push({
399
- type: 'arrow',
400
- color: colors.velocity,
401
- zOrder: 10,
402
- points: [transform.position, end],
403
- lineWidth: opts.vectorLineWidth,
404
- });
405
- }
406
- }
407
- // Draw joints
408
- if (opts.showJoints) {
409
- for (const [_id, joint] of this.joints3D) {
410
- this.drawJoint3D(joint);
411
- }
412
- }
413
- // Draw contact points
414
- if (opts.showContactPoints || opts.showContactNormals) {
415
- this.drawContacts3D();
416
- }
417
- // Draw raycasts
418
- if (opts.showRaycasts) {
419
- this.drawRaycasts3D();
420
- }
494
+ switch (body.bodyType) {
495
+ case "static":
496
+ return colors.staticCollider;
497
+ case "kinematic":
498
+ return colors.kinematicCollider;
499
+ case "dynamic":
500
+ return colors.dynamicCollider;
421
501
  }
422
- shouldDrawCollider2D(collider) {
423
- const opts = this.options;
424
- if (collider.isTrigger && !opts.showTriggers) {
425
- return false;
426
- }
427
- if (!collider.isTrigger && !opts.showColliders) {
428
- return false;
429
- }
430
- if (opts.filterByLayer !== null && collider.layer !== opts.filterByLayer) {
431
- return false;
502
+ }
503
+ drawCollider2D(collider, transform, color) {
504
+ const pos = {
505
+ x: transform.position.x + collider.offset.x,
506
+ y: transform.position.y + collider.offset.y
507
+ };
508
+ const rotation = transform.rotation + collider.rotation;
509
+ switch (collider.type) {
510
+ case "circle":
511
+ this.drawCommands.push({
512
+ type: "circle",
513
+ color,
514
+ zOrder: 1,
515
+ position: pos,
516
+ radius: collider.radius ?? 1,
517
+ lineWidth: this.options.colliderLineWidth
518
+ });
519
+ break;
520
+ case "box":
521
+ this.drawCommands.push({
522
+ type: "rect",
523
+ color,
524
+ zOrder: 1,
525
+ position: pos,
526
+ size: collider.halfExtents ? { x: collider.halfExtents.x * 2, y: collider.halfExtents.y * 2 } : { x: 1, y: 1 },
527
+ rotation,
528
+ lineWidth: this.options.colliderLineWidth
529
+ });
530
+ break;
531
+ case "polygon":
532
+ if (collider.vertices && collider.vertices.length >= 3) {
533
+ const transformedVerts = collider.vertices.map((v) => {
534
+ const cos = Math.cos(rotation);
535
+ const sin = Math.sin(rotation);
536
+ return {
537
+ x: pos.x + v.x * cos - v.y * sin,
538
+ y: pos.y + v.x * sin + v.y * cos
539
+ };
540
+ });
541
+ this.drawCommands.push({
542
+ type: "polygon",
543
+ color,
544
+ zOrder: 1,
545
+ points: transformedVerts,
546
+ lineWidth: this.options.colliderLineWidth
547
+ });
432
548
  }
433
- if (opts.filterByEntity !== null && !opts.filterByEntity.includes(collider.entityId)) {
434
- return false;
549
+ break;
550
+ case "edge":
551
+ if (collider.edgeStart && collider.edgeEnd) {
552
+ this.drawCommands.push({
553
+ type: "line",
554
+ color,
555
+ zOrder: 1,
556
+ points: [
557
+ { x: pos.x + collider.edgeStart.x, y: pos.y + collider.edgeStart.y },
558
+ { x: pos.x + collider.edgeEnd.x, y: pos.y + collider.edgeEnd.y }
559
+ ],
560
+ lineWidth: this.options.colliderLineWidth
561
+ });
435
562
  }
436
- const body = this.findBody2DForEntity(collider.entityId);
437
- if (body) {
438
- if (opts.filterByBodyType !== null && body.bodyType !== opts.filterByBodyType) {
439
- return false;
440
- }
441
- if (opts.hideStaticColliders && body.bodyType === 'static') {
442
- return false;
443
- }
444
- if (opts.hideSleepingBodies && body.isSleeping) {
445
- return false;
446
- }
563
+ break;
564
+ case "chain":
565
+ if (collider.chainVertices && collider.chainVertices.length >= 2) {
566
+ const transformedVerts = collider.chainVertices.map((v) => ({
567
+ x: pos.x + v.x,
568
+ y: pos.y + v.y
569
+ }));
570
+ for (let i = 0; i < transformedVerts.length - 1; i++) {
571
+ this.drawCommands.push({
572
+ type: "line",
573
+ color,
574
+ zOrder: 1,
575
+ points: [transformedVerts[i], transformedVerts[i + 1]],
576
+ lineWidth: this.options.colliderLineWidth
577
+ });
578
+ }
447
579
  }
448
- return true;
580
+ break;
581
+ case "capsule":
582
+ this.drawCommands.push({
583
+ type: "capsule",
584
+ color,
585
+ zOrder: 1,
586
+ position: pos,
587
+ radius: collider.radius ?? 0.5,
588
+ size: { x: collider.capsuleHeight ?? 2, y: 0 },
589
+ rotation,
590
+ lineWidth: this.options.colliderLineWidth
591
+ });
592
+ break;
449
593
  }
450
- shouldDrawCollider3D(collider) {
451
- const opts = this.options;
452
- if (collider.isTrigger && !opts.showTriggers) {
453
- return false;
454
- }
455
- if (!collider.isTrigger && !opts.showColliders) {
456
- return false;
457
- }
458
- if (opts.filterByLayer !== null && collider.layer !== opts.filterByLayer) {
459
- return false;
460
- }
461
- if (opts.filterByEntity !== null && !opts.filterByEntity.includes(collider.entityId)) {
462
- return false;
463
- }
464
- const body = this.findBody3DForEntity(collider.entityId);
465
- if (body) {
466
- if (opts.filterByBodyType !== null && body.bodyType !== opts.filterByBodyType) {
467
- return false;
468
- }
469
- if (opts.hideStaticColliders && body.bodyType === 'static') {
470
- return false;
471
- }
472
- if (opts.hideSleepingBodies && body.isSleeping) {
473
- return false;
474
- }
475
- }
476
- return true;
594
+ }
595
+ drawCollider3D(collider, transform, color) {
596
+ const pos = {
597
+ x: transform.position.x + collider.offset.x,
598
+ y: transform.position.y + collider.offset.y,
599
+ z: transform.position.z + collider.offset.z
600
+ };
601
+ switch (collider.type) {
602
+ case "sphere":
603
+ this.drawCommands.push({
604
+ type: "sphere",
605
+ color,
606
+ zOrder: 1,
607
+ position: pos,
608
+ radius: collider.radius ?? 1,
609
+ lineWidth: this.options.colliderLineWidth
610
+ });
611
+ break;
612
+ case "box":
613
+ this.drawCommands.push({
614
+ type: "box3d",
615
+ color,
616
+ zOrder: 1,
617
+ position: pos,
618
+ size: collider.halfExtents ? {
619
+ x: collider.halfExtents.x * 2,
620
+ y: collider.halfExtents.y * 2,
621
+ z: collider.halfExtents.z * 2
622
+ } : { x: 1, y: 1, z: 1 },
623
+ rotation: collider.rotation,
624
+ lineWidth: this.options.colliderLineWidth
625
+ });
626
+ break;
627
+ case "capsule":
628
+ this.drawCommands.push({
629
+ type: "capsule",
630
+ color,
631
+ zOrder: 1,
632
+ position: pos,
633
+ radius: collider.capsuleRadius ?? 0.5,
634
+ size: { x: 0, y: collider.capsuleHeight ?? 2, z: 0 },
635
+ rotation: collider.rotation,
636
+ lineWidth: this.options.colliderLineWidth
637
+ });
638
+ break;
477
639
  }
478
- findBody2DForEntity(entityId) {
479
- for (const body of this.bodies2D.values()) {
480
- if (body.entityId === entityId) {
481
- return body;
482
- }
483
- }
484
- return undefined;
640
+ }
641
+ drawJoint2D(joint) {
642
+ const colors = this.options.colors;
643
+ const bodyA = this.bodies2D.get(joint.bodyA);
644
+ const bodyB = this.bodies2D.get(joint.bodyB);
645
+ if (!bodyA || !bodyB) {
646
+ return;
485
647
  }
486
- findBody3DForEntity(entityId) {
487
- for (const body of this.bodies3D.values()) {
488
- if (body.entityId === entityId) {
489
- return body;
490
- }
491
- }
492
- return undefined;
648
+ const transformA = this.transforms2D.get(bodyA.entityId);
649
+ const transformB = this.transforms2D.get(bodyB.entityId);
650
+ if (!transformA || !transformB) {
651
+ return;
493
652
  }
494
- getColliderColor2D(collider, body) {
495
- const colors = this.options.colors;
496
- if (this.options.showLayerColors && collider.layer < colors.layerColors.length) {
497
- return colors.layerColors[collider.layer];
498
- }
499
- if (collider.isTrigger) {
500
- return colors.triggerCollider;
501
- }
502
- if (!body) {
503
- return colors.staticCollider;
504
- }
505
- if (body.isSleeping) {
506
- return colors.sleepingCollider;
507
- }
508
- switch (body.bodyType) {
509
- case 'static':
510
- return colors.staticCollider;
511
- case 'kinematic':
512
- return colors.kinematicCollider;
513
- case 'dynamic':
514
- return colors.dynamicCollider;
515
- }
653
+ const anchorA = {
654
+ x: transformA.position.x + joint.anchorA.x,
655
+ y: transformA.position.y + joint.anchorA.y
656
+ };
657
+ const anchorB = {
658
+ x: transformB.position.x + joint.anchorB.x,
659
+ y: transformB.position.y + joint.anchorB.y
660
+ };
661
+ this.drawCommands.push({
662
+ type: "line",
663
+ color: colors.jointActive,
664
+ zOrder: 5,
665
+ points: [anchorA, anchorB],
666
+ lineWidth: this.options.jointLineWidth
667
+ });
668
+ this.drawCommands.push({
669
+ type: "filledCircle",
670
+ color: colors.jointActive,
671
+ zOrder: 6,
672
+ position: anchorA,
673
+ radius: 0.1
674
+ });
675
+ this.drawCommands.push({
676
+ type: "filledCircle",
677
+ color: colors.jointActive,
678
+ zOrder: 6,
679
+ position: anchorB,
680
+ radius: 0.1
681
+ });
682
+ if (this.options.showJointLimits && joint.useLimits) {
683
+ if (joint.type === "hinge" && joint.minAngle !== void 0 && joint.maxAngle !== void 0) {
684
+ this.drawCommands.push({
685
+ type: "arc",
686
+ color: colors.jointLimit,
687
+ zOrder: 4,
688
+ position: anchorA,
689
+ radius: 0.5,
690
+ startAngle: joint.minAngle,
691
+ endAngle: joint.maxAngle,
692
+ lineWidth: 2
693
+ });
694
+ }
516
695
  }
517
- getColliderColor3D(collider, body) {
518
- const colors = this.options.colors;
519
- if (this.options.showLayerColors && collider.layer < colors.layerColors.length) {
520
- return colors.layerColors[collider.layer];
521
- }
522
- if (collider.isTrigger) {
523
- return colors.triggerCollider;
524
- }
525
- if (!body) {
526
- return colors.staticCollider;
527
- }
528
- if (body.isSleeping) {
529
- return colors.sleepingCollider;
696
+ }
697
+ drawJoint3D(joint) {
698
+ const colors = this.options.colors;
699
+ const bodyA = this.bodies3D.get(joint.bodyA);
700
+ const bodyB = this.bodies3D.get(joint.bodyB);
701
+ if (!bodyA || !bodyB) {
702
+ return;
703
+ }
704
+ const transformA = this.transforms3D.get(bodyA.entityId);
705
+ const transformB = this.transforms3D.get(bodyB.entityId);
706
+ if (!transformA || !transformB) {
707
+ return;
708
+ }
709
+ const anchorA = {
710
+ x: transformA.position.x + joint.anchor.x,
711
+ y: transformA.position.y + joint.anchor.y,
712
+ z: transformA.position.z + joint.anchor.z
713
+ };
714
+ const anchorB = {
715
+ x: transformB.position.x + joint.connectedAnchor.x,
716
+ y: transformB.position.y + joint.connectedAnchor.y,
717
+ z: transformB.position.z + joint.connectedAnchor.z
718
+ };
719
+ this.drawCommands.push({
720
+ type: "line",
721
+ color: colors.jointActive,
722
+ zOrder: 5,
723
+ points: [anchorA, anchorB],
724
+ lineWidth: this.options.jointLineWidth
725
+ });
726
+ }
727
+ drawContacts2D() {
728
+ const opts = this.options;
729
+ const colors = opts.colors;
730
+ for (const pair of this.collisionPairs) {
731
+ for (const contact of pair.contacts) {
732
+ const point = contact.point;
733
+ const normal = contact.normal;
734
+ if (opts.showContactPoints) {
735
+ this.drawCommands.push({
736
+ type: "filledCircle",
737
+ color: colors.contactPoint,
738
+ zOrder: 20,
739
+ position: point,
740
+ radius: 0.08
741
+ });
530
742
  }
531
- switch (body.bodyType) {
532
- case 'static':
533
- return colors.staticCollider;
534
- case 'kinematic':
535
- return colors.kinematicCollider;
536
- case 'dynamic':
537
- return colors.dynamicCollider;
743
+ if (opts.showContactNormals) {
744
+ const end = {
745
+ x: point.x + normal.x * opts.normalScale,
746
+ y: point.y + normal.y * opts.normalScale
747
+ };
748
+ this.drawCommands.push({
749
+ type: "arrow",
750
+ color: colors.contactNormal,
751
+ zOrder: 21,
752
+ points: [point, end],
753
+ lineWidth: opts.vectorLineWidth
754
+ });
538
755
  }
539
- }
540
- drawCollider2D(collider, transform, color) {
541
- const pos = {
542
- x: transform.position.x + collider.offset.x,
543
- y: transform.position.y + collider.offset.y,
544
- };
545
- const rotation = transform.rotation + collider.rotation;
546
- switch (collider.type) {
547
- case 'circle':
548
- this.drawCommands.push({
549
- type: 'circle',
550
- color,
551
- zOrder: 1,
552
- position: pos,
553
- radius: collider.radius ?? 1,
554
- lineWidth: this.options.colliderLineWidth,
555
- });
556
- break;
557
- case 'box':
558
- this.drawCommands.push({
559
- type: 'rect',
560
- color,
561
- zOrder: 1,
562
- position: pos,
563
- size: collider.halfExtents
564
- ? { x: collider.halfExtents.x * 2, y: collider.halfExtents.y * 2 }
565
- : { x: 1, y: 1 },
566
- rotation,
567
- lineWidth: this.options.colliderLineWidth,
568
- });
569
- break;
570
- case 'polygon':
571
- if (collider.vertices && collider.vertices.length >= 3) {
572
- const transformedVerts = collider.vertices.map((v) => {
573
- const cos = Math.cos(rotation);
574
- const sin = Math.sin(rotation);
575
- return {
576
- x: pos.x + v.x * cos - v.y * sin,
577
- y: pos.y + v.x * sin + v.y * cos,
578
- };
579
- });
580
- this.drawCommands.push({
581
- type: 'polygon',
582
- color,
583
- zOrder: 1,
584
- points: transformedVerts,
585
- lineWidth: this.options.colliderLineWidth,
586
- });
587
- }
588
- break;
589
- case 'edge':
590
- if (collider.edgeStart && collider.edgeEnd) {
591
- this.drawCommands.push({
592
- type: 'line',
593
- color,
594
- zOrder: 1,
595
- points: [
596
- { x: pos.x + collider.edgeStart.x, y: pos.y + collider.edgeStart.y },
597
- { x: pos.x + collider.edgeEnd.x, y: pos.y + collider.edgeEnd.y },
598
- ],
599
- lineWidth: this.options.colliderLineWidth,
600
- });
601
- }
602
- break;
603
- case 'chain':
604
- if (collider.chainVertices && collider.chainVertices.length >= 2) {
605
- const transformedVerts = collider.chainVertices.map((v) => ({
606
- x: pos.x + v.x,
607
- y: pos.y + v.y,
608
- }));
609
- for (let i = 0; i < transformedVerts.length - 1; i++) {
610
- this.drawCommands.push({
611
- type: 'line',
612
- color,
613
- zOrder: 1,
614
- points: [transformedVerts[i], transformedVerts[i + 1]],
615
- lineWidth: this.options.colliderLineWidth,
616
- });
617
- }
618
- }
619
- break;
620
- case 'capsule':
621
- this.drawCommands.push({
622
- type: 'capsule',
623
- color,
624
- zOrder: 1,
625
- position: pos,
626
- radius: collider.radius ?? 0.5,
627
- size: { x: collider.capsuleHeight ?? 2, y: 0 },
628
- rotation,
629
- lineWidth: this.options.colliderLineWidth,
630
- });
631
- break;
756
+ if (opts.showContactImpulse && contact.impulse > 0) {
757
+ const impulseLength = contact.impulse * opts.impulseScale;
758
+ const end = {
759
+ x: point.x + normal.x * impulseLength,
760
+ y: point.y + normal.y * impulseLength
761
+ };
762
+ this.drawCommands.push({
763
+ type: "arrow",
764
+ color: colors.contactImpulse,
765
+ zOrder: 22,
766
+ points: [point, end],
767
+ lineWidth: opts.vectorLineWidth * 1.5
768
+ });
632
769
  }
770
+ }
633
771
  }
634
- drawCollider3D(collider, transform, color) {
635
- const pos = {
636
- x: transform.position.x + collider.offset.x,
637
- y: transform.position.y + collider.offset.y,
638
- z: transform.position.z + collider.offset.z,
639
- };
640
- switch (collider.type) {
641
- case 'sphere':
642
- this.drawCommands.push({
643
- type: 'sphere',
644
- color,
645
- zOrder: 1,
646
- position: pos,
647
- radius: collider.radius ?? 1,
648
- lineWidth: this.options.colliderLineWidth,
649
- });
650
- break;
651
- case 'box':
652
- this.drawCommands.push({
653
- type: 'box3d',
654
- color,
655
- zOrder: 1,
656
- position: pos,
657
- size: collider.halfExtents
658
- ? {
659
- x: collider.halfExtents.x * 2,
660
- y: collider.halfExtents.y * 2,
661
- z: collider.halfExtents.z * 2,
662
- }
663
- : { x: 1, y: 1, z: 1 },
664
- rotation: collider.rotation,
665
- lineWidth: this.options.colliderLineWidth,
666
- });
667
- break;
668
- case 'capsule':
669
- this.drawCommands.push({
670
- type: 'capsule',
671
- color,
672
- zOrder: 1,
673
- position: pos,
674
- radius: collider.capsuleRadius ?? 0.5,
675
- size: { x: 0, y: collider.capsuleHeight ?? 2, z: 0 },
676
- rotation: collider.rotation,
677
- lineWidth: this.options.colliderLineWidth,
678
- });
679
- break;
680
- // Additional shapes would be drawn similarly
681
- }
772
+ const now = Date.now();
773
+ for (const entry of this.contactHistory) {
774
+ const age = now - entry.timestamp;
775
+ const alpha = 1 - age / opts.contactHistoryDuration;
776
+ if (alpha <= 0) {
777
+ continue;
778
+ }
779
+ const point = entry.point;
780
+ const fadedColor = {
781
+ ...colors.contactPoint,
782
+ a: colors.contactPoint.a * alpha * 0.5
783
+ };
784
+ this.drawCommands.push({
785
+ type: "filledCircle",
786
+ color: fadedColor,
787
+ zOrder: 19,
788
+ position: point,
789
+ radius: 0.05
790
+ });
682
791
  }
683
- drawJoint2D(joint) {
684
- const colors = this.options.colors;
685
- const bodyA = this.bodies2D.get(joint.bodyA);
686
- const bodyB = this.bodies2D.get(joint.bodyB);
687
- if (!bodyA || !bodyB) {
688
- return;
792
+ }
793
+ drawContacts3D() {
794
+ const opts = this.options;
795
+ const colors = opts.colors;
796
+ for (const pair of this.collisionPairs) {
797
+ for (const contact of pair.contacts) {
798
+ const point = contact.point;
799
+ const normal = contact.normal;
800
+ if (opts.showContactPoints) {
801
+ this.drawCommands.push({
802
+ type: "sphere",
803
+ color: colors.contactPoint,
804
+ zOrder: 20,
805
+ position: point,
806
+ radius: 0.05
807
+ });
689
808
  }
690
- const transformA = this.transforms2D.get(bodyA.entityId);
691
- const transformB = this.transforms2D.get(bodyB.entityId);
692
- if (!transformA || !transformB) {
693
- return;
809
+ if (opts.showContactNormals) {
810
+ const end = {
811
+ x: point.x + normal.x * opts.normalScale,
812
+ y: point.y + normal.y * opts.normalScale,
813
+ z: point.z + normal.z * opts.normalScale
814
+ };
815
+ this.drawCommands.push({
816
+ type: "arrow",
817
+ color: colors.contactNormal,
818
+ zOrder: 21,
819
+ points: [point, end],
820
+ lineWidth: opts.vectorLineWidth
821
+ });
694
822
  }
695
- const anchorA = {
696
- x: transformA.position.x + joint.anchorA.x,
697
- y: transformA.position.y + joint.anchorA.y,
823
+ }
824
+ }
825
+ }
826
+ drawRaycasts2D() {
827
+ const colors = this.options.colors;
828
+ for (const raycast of this.raycasts) {
829
+ const origin = raycast.origin;
830
+ const direction = raycast.direction;
831
+ if (raycast.hit) {
832
+ const hit = raycast.hit;
833
+ this.drawCommands.push({
834
+ type: "line",
835
+ color: colors.raycastHit,
836
+ zOrder: 15,
837
+ points: [origin, hit.point],
838
+ lineWidth: 1
839
+ });
840
+ this.drawCommands.push({
841
+ type: "cross",
842
+ color: colors.raycastHit,
843
+ zOrder: 16,
844
+ position: hit.point,
845
+ size: { x: 0.2, y: 0.2 },
846
+ lineWidth: 2
847
+ });
848
+ const normalEnd = {
849
+ x: hit.point.x + hit.normal.x * 0.5,
850
+ y: hit.point.y + hit.normal.y * 0.5
698
851
  };
699
- const anchorB = {
700
- x: transformB.position.x + joint.anchorB.x,
701
- y: transformB.position.y + joint.anchorB.y,
852
+ this.drawCommands.push({
853
+ type: "arrow",
854
+ color: colors.contactNormal,
855
+ zOrder: 17,
856
+ points: [hit.point, normalEnd],
857
+ lineWidth: 1
858
+ });
859
+ } else {
860
+ const end = {
861
+ x: origin.x + direction.x * raycast.maxDistance,
862
+ y: origin.y + direction.y * raycast.maxDistance
702
863
  };
703
- // Draw joint connection line
704
864
  this.drawCommands.push({
705
- type: 'line',
706
- color: colors.jointActive,
707
- zOrder: 5,
708
- points: [anchorA, anchorB],
709
- lineWidth: this.options.jointLineWidth,
865
+ type: "line",
866
+ color: colors.raycastMiss,
867
+ zOrder: 15,
868
+ points: [origin, end],
869
+ lineWidth: 1
710
870
  });
711
- // Draw anchors
871
+ }
872
+ }
873
+ this.raycasts = [];
874
+ }
875
+ drawRaycasts3D() {
876
+ const colors = this.options.colors;
877
+ for (const raycast of this.raycasts) {
878
+ const origin = raycast.origin;
879
+ const direction = raycast.direction;
880
+ if (raycast.hit) {
881
+ const hit = raycast.hit;
712
882
  this.drawCommands.push({
713
- type: 'filledCircle',
714
- color: colors.jointActive,
715
- zOrder: 6,
716
- position: anchorA,
717
- radius: 0.1,
883
+ type: "line",
884
+ color: colors.raycastHit,
885
+ zOrder: 15,
886
+ points: [origin, hit.point],
887
+ lineWidth: 1
718
888
  });
719
889
  this.drawCommands.push({
720
- type: 'filledCircle',
721
- color: colors.jointActive,
722
- zOrder: 6,
723
- position: anchorB,
724
- radius: 0.1,
890
+ type: "sphere",
891
+ color: colors.raycastHit,
892
+ zOrder: 16,
893
+ position: hit.point,
894
+ radius: 0.05
725
895
  });
726
- // Draw limits if applicable
727
- if (this.options.showJointLimits && joint.useLimits) {
728
- if (joint.type === 'hinge' && joint.minAngle !== undefined && joint.maxAngle !== undefined) {
729
- this.drawCommands.push({
730
- type: 'arc',
731
- color: colors.jointLimit,
732
- zOrder: 4,
733
- position: anchorA,
734
- radius: 0.5,
735
- startAngle: joint.minAngle,
736
- endAngle: joint.maxAngle,
737
- lineWidth: 2,
738
- });
739
- }
740
- }
741
- }
742
- drawJoint3D(joint) {
743
- const colors = this.options.colors;
744
- const bodyA = this.bodies3D.get(joint.bodyA);
745
- const bodyB = this.bodies3D.get(joint.bodyB);
746
- if (!bodyA || !bodyB) {
747
- return;
748
- }
749
- const transformA = this.transforms3D.get(bodyA.entityId);
750
- const transformB = this.transforms3D.get(bodyB.entityId);
751
- if (!transformA || !transformB) {
752
- return;
753
- }
754
- const anchorA = {
755
- x: transformA.position.x + joint.anchor.x,
756
- y: transformA.position.y + joint.anchor.y,
757
- z: transformA.position.z + joint.anchor.z,
758
- };
759
- const anchorB = {
760
- x: transformB.position.x + joint.connectedAnchor.x,
761
- y: transformB.position.y + joint.connectedAnchor.y,
762
- z: transformB.position.z + joint.connectedAnchor.z,
896
+ } else {
897
+ const end = {
898
+ x: origin.x + direction.x * raycast.maxDistance,
899
+ y: origin.y + direction.y * raycast.maxDistance,
900
+ z: origin.z + direction.z * raycast.maxDistance
763
901
  };
764
902
  this.drawCommands.push({
765
- type: 'line',
766
- color: colors.jointActive,
767
- zOrder: 5,
768
- points: [anchorA, anchorB],
769
- lineWidth: this.options.jointLineWidth,
903
+ type: "line",
904
+ color: colors.raycastMiss,
905
+ zOrder: 15,
906
+ points: [origin, end],
907
+ lineWidth: 1
770
908
  });
909
+ }
771
910
  }
772
- drawContacts2D() {
773
- const opts = this.options;
774
- const colors = opts.colors;
775
- // Draw current contacts
776
- for (const pair of this.collisionPairs) {
777
- for (const contact of pair.contacts) {
778
- const point = contact.point;
779
- const normal = contact.normal;
780
- if (opts.showContactPoints) {
781
- this.drawCommands.push({
782
- type: 'filledCircle',
783
- color: colors.contactPoint,
784
- zOrder: 20,
785
- position: point,
786
- radius: 0.08,
787
- });
788
- }
789
- if (opts.showContactNormals) {
790
- const end = {
791
- x: point.x + normal.x * opts.normalScale,
792
- y: point.y + normal.y * opts.normalScale,
793
- };
794
- this.drawCommands.push({
795
- type: 'arrow',
796
- color: colors.contactNormal,
797
- zOrder: 21,
798
- points: [point, end],
799
- lineWidth: opts.vectorLineWidth,
800
- });
801
- }
802
- if (opts.showContactImpulse && contact.impulse > 0) {
803
- const impulseLength = contact.impulse * opts.impulseScale;
804
- const end = {
805
- x: point.x + normal.x * impulseLength,
806
- y: point.y + normal.y * impulseLength,
807
- };
808
- this.drawCommands.push({
809
- type: 'arrow',
810
- color: colors.contactImpulse,
811
- zOrder: 22,
812
- points: [point, end],
813
- lineWidth: opts.vectorLineWidth * 1.5,
814
- });
815
- }
816
- }
817
- }
818
- // Draw contact history with fading
819
- const now = Date.now();
820
- for (const entry of this.contactHistory) {
821
- const age = now - entry.timestamp;
822
- const alpha = 1 - age / opts.contactHistoryDuration;
823
- if (alpha <= 0) {
824
- continue;
825
- }
826
- const point = entry.point;
827
- const fadedColor = {
828
- ...colors.contactPoint,
829
- a: colors.contactPoint.a * alpha * 0.5,
830
- };
831
- this.drawCommands.push({
832
- type: 'filledCircle',
833
- color: fadedColor,
834
- zOrder: 19,
835
- position: point,
836
- radius: 0.05,
837
- });
838
- }
911
+ this.raycasts = [];
912
+ }
913
+ // ─── Stats ─────────────────────────────────────────────
914
+ calculateStats() {
915
+ this.stats.totalBodies = this.bodies2D.size + this.bodies3D.size;
916
+ this.stats.dynamicBodies = 0;
917
+ this.stats.kinematicBodies = 0;
918
+ this.stats.staticBodies = 0;
919
+ this.stats.awakeBodies = 0;
920
+ this.stats.sleepingBodies = 0;
921
+ for (const body of this.bodies2D.values()) {
922
+ if (body.bodyType === "dynamic") {
923
+ this.stats.dynamicBodies++;
924
+ } else if (body.bodyType === "kinematic") {
925
+ this.stats.kinematicBodies++;
926
+ } else {
927
+ this.stats.staticBodies++;
928
+ }
929
+ if (body.isSleeping) {
930
+ this.stats.sleepingBodies++;
931
+ } else {
932
+ this.stats.awakeBodies++;
933
+ }
839
934
  }
840
- drawContacts3D() {
841
- const opts = this.options;
842
- const colors = opts.colors;
843
- for (const pair of this.collisionPairs) {
844
- for (const contact of pair.contacts) {
845
- const point = contact.point;
846
- const normal = contact.normal;
847
- if (opts.showContactPoints) {
848
- this.drawCommands.push({
849
- type: 'sphere',
850
- color: colors.contactPoint,
851
- zOrder: 20,
852
- position: point,
853
- radius: 0.05,
854
- });
855
- }
856
- if (opts.showContactNormals) {
857
- const end = {
858
- x: point.x + normal.x * opts.normalScale,
859
- y: point.y + normal.y * opts.normalScale,
860
- z: point.z + normal.z * opts.normalScale,
861
- };
862
- this.drawCommands.push({
863
- type: 'arrow',
864
- color: colors.contactNormal,
865
- zOrder: 21,
866
- points: [point, end],
867
- lineWidth: opts.vectorLineWidth,
868
- });
869
- }
870
- }
871
- }
935
+ for (const body of this.bodies3D.values()) {
936
+ if (body.bodyType === "dynamic") {
937
+ this.stats.dynamicBodies++;
938
+ } else if (body.bodyType === "kinematic") {
939
+ this.stats.kinematicBodies++;
940
+ } else {
941
+ this.stats.staticBodies++;
942
+ }
943
+ if (body.isSleeping) {
944
+ this.stats.sleepingBodies++;
945
+ } else {
946
+ this.stats.awakeBodies++;
947
+ }
872
948
  }
873
- drawRaycasts2D() {
874
- const colors = this.options.colors;
875
- for (const raycast of this.raycasts) {
876
- const origin = raycast.origin;
877
- const direction = raycast.direction;
878
- if (raycast.hit) {
879
- const hit = raycast.hit;
880
- // Draw ray to hit point
881
- this.drawCommands.push({
882
- type: 'line',
883
- color: colors.raycastHit,
884
- zOrder: 15,
885
- points: [origin, hit.point],
886
- lineWidth: 1,
887
- });
888
- // Draw hit point
889
- this.drawCommands.push({
890
- type: 'cross',
891
- color: colors.raycastHit,
892
- zOrder: 16,
893
- position: hit.point,
894
- size: { x: 0.2, y: 0.2 },
895
- lineWidth: 2,
896
- });
897
- // Draw hit normal
898
- const normalEnd = {
899
- x: hit.point.x + hit.normal.x * 0.5,
900
- y: hit.point.y + hit.normal.y * 0.5,
901
- };
902
- this.drawCommands.push({
903
- type: 'arrow',
904
- color: colors.contactNormal,
905
- zOrder: 17,
906
- points: [hit.point, normalEnd],
907
- lineWidth: 1,
908
- });
909
- }
910
- else {
911
- // Draw full ray (miss)
912
- const end = {
913
- x: origin.x + direction.x * raycast.maxDistance,
914
- y: origin.y + direction.y * raycast.maxDistance,
915
- };
916
- this.drawCommands.push({
917
- type: 'line',
918
- color: colors.raycastMiss,
919
- zOrder: 15,
920
- points: [origin, end],
921
- lineWidth: 1,
922
- });
923
- }
924
- }
925
- // Clear raycasts for next frame
926
- this.raycasts = [];
949
+ this.stats.totalColliders = this.colliders2D.size + this.colliders3D.size;
950
+ this.stats.activeColliders = this.stats.totalColliders;
951
+ this.stats.triggers = 0;
952
+ for (const collider of this.colliders2D.values()) {
953
+ if (collider.isTrigger) {
954
+ this.stats.triggers++;
955
+ }
927
956
  }
928
- drawRaycasts3D() {
929
- const colors = this.options.colors;
930
- for (const raycast of this.raycasts) {
931
- const origin = raycast.origin;
932
- const direction = raycast.direction;
933
- if (raycast.hit) {
934
- const hit = raycast.hit;
935
- this.drawCommands.push({
936
- type: 'line',
937
- color: colors.raycastHit,
938
- zOrder: 15,
939
- points: [origin, hit.point],
940
- lineWidth: 1,
941
- });
942
- this.drawCommands.push({
943
- type: 'sphere',
944
- color: colors.raycastHit,
945
- zOrder: 16,
946
- position: hit.point,
947
- radius: 0.05,
948
- });
949
- }
950
- else {
951
- const end = {
952
- x: origin.x + direction.x * raycast.maxDistance,
953
- y: origin.y + direction.y * raycast.maxDistance,
954
- z: origin.z + direction.z * raycast.maxDistance,
955
- };
956
- this.drawCommands.push({
957
- type: 'line',
958
- color: colors.raycastMiss,
959
- zOrder: 15,
960
- points: [origin, end],
961
- lineWidth: 1,
962
- });
963
- }
964
- }
965
- this.raycasts = [];
957
+ for (const collider of this.colliders3D.values()) {
958
+ if (collider.isTrigger) {
959
+ this.stats.triggers++;
960
+ }
966
961
  }
967
- // ─── Stats ─────────────────────────────────────────────
968
- calculateStats() {
969
- // Bodies
970
- this.stats.totalBodies = this.bodies2D.size + this.bodies3D.size;
971
- this.stats.dynamicBodies = 0;
972
- this.stats.kinematicBodies = 0;
973
- this.stats.staticBodies = 0;
974
- this.stats.awakeBodies = 0;
975
- this.stats.sleepingBodies = 0;
976
- for (const body of this.bodies2D.values()) {
977
- if (body.bodyType === 'dynamic') {
978
- this.stats.dynamicBodies++;
979
- }
980
- else if (body.bodyType === 'kinematic') {
981
- this.stats.kinematicBodies++;
982
- }
983
- else {
984
- this.stats.staticBodies++;
985
- }
986
- if (body.isSleeping) {
987
- this.stats.sleepingBodies++;
988
- }
989
- else {
990
- this.stats.awakeBodies++;
991
- }
992
- }
993
- for (const body of this.bodies3D.values()) {
994
- if (body.bodyType === 'dynamic') {
995
- this.stats.dynamicBodies++;
996
- }
997
- else if (body.bodyType === 'kinematic') {
998
- this.stats.kinematicBodies++;
999
- }
1000
- else {
1001
- this.stats.staticBodies++;
1002
- }
1003
- if (body.isSleeping) {
1004
- this.stats.sleepingBodies++;
1005
- }
1006
- else {
1007
- this.stats.awakeBodies++;
1008
- }
1009
- }
1010
- // Colliders
1011
- this.stats.totalColliders = this.colliders2D.size + this.colliders3D.size;
1012
- this.stats.activeColliders = this.stats.totalColliders;
1013
- this.stats.triggers = 0;
962
+ this.stats.collisionPairs = this.collisionPairs.length;
963
+ this.stats.contactPoints = 0;
964
+ for (const pair of this.collisionPairs) {
965
+ this.stats.contactPoints += pair.contacts.length;
966
+ }
967
+ this.stats.totalJoints = this.joints2D.size + this.joints3D.size;
968
+ this.stats.activeJoints = this.stats.totalJoints;
969
+ this.stats.brokenJoints = 0;
970
+ this.stats.bodyMemory = this.stats.totalBodies * 256;
971
+ this.stats.colliderMemory = this.stats.totalColliders * 128;
972
+ this.stats.contactMemory = this.stats.contactPoints * 64;
973
+ }
974
+ getStats() {
975
+ return { ...this.stats };
976
+ }
977
+ // ─── Stats Overlay Text ────────────────────────────────
978
+ generateStatsOverlayText() {
979
+ const s = this.stats;
980
+ return [
981
+ "=== Physics Debug ===",
982
+ "",
983
+ "--- Bodies ---",
984
+ `Total: ${s.totalBodies}`,
985
+ ` Dynamic: ${s.dynamicBodies}`,
986
+ ` Kinematic: ${s.kinematicBodies}`,
987
+ ` Static: ${s.staticBodies}`,
988
+ `Awake: ${s.awakeBodies} / Sleeping: ${s.sleepingBodies}`,
989
+ "",
990
+ "--- Colliders ---",
991
+ `Total: ${s.totalColliders}`,
992
+ `Active: ${s.activeColliders}`,
993
+ `Triggers: ${s.triggers}`,
994
+ "",
995
+ "--- Simulation ---",
996
+ `Collision Pairs: ${s.collisionPairs}`,
997
+ `Contact Points: ${s.contactPoints}`,
998
+ `Islands: ${s.islandCount}`,
999
+ "",
1000
+ "--- Timing (ms) ---",
1001
+ `Step: ${s.stepTime.toFixed(2)}`,
1002
+ ` Broadphase: ${s.broadphaseTime.toFixed(2)}`,
1003
+ ` Narrowphase: ${s.narrowphaseTime.toFixed(2)}`,
1004
+ ` Solver: ${s.solverTime.toFixed(2)}`,
1005
+ ` Integration: ${s.integrationTime.toFixed(2)}`,
1006
+ "",
1007
+ "--- Memory (KB) ---",
1008
+ `Bodies: ${(s.bodyMemory / 1024).toFixed(1)}`,
1009
+ `Colliders: ${(s.colliderMemory / 1024).toFixed(1)}`,
1010
+ `Contacts: ${(s.contactMemory / 1024).toFixed(1)}`,
1011
+ "",
1012
+ "--- Joints ---",
1013
+ `Total: ${s.totalJoints}`,
1014
+ `Active: ${s.activeJoints}`,
1015
+ `Broken: ${s.brokenJoints}`,
1016
+ "",
1017
+ "--- Queries/Frame ---",
1018
+ `Raycasts: ${s.raycastsThisFrame}`,
1019
+ `Overlaps: ${s.overlapTestsThisFrame}`
1020
+ ];
1021
+ }
1022
+ // ─── Collision Layer Matrix ────────────────────────────
1023
+ generateLayerMatrix(layerCount = 32) {
1024
+ const matrix = [];
1025
+ for (let i = 0; i < layerCount; i++) {
1026
+ matrix[i] = [];
1027
+ for (let j = 0; j < layerCount; j++) {
1028
+ let canCollide = false;
1014
1029
  for (const collider of this.colliders2D.values()) {
1015
- if (collider.isTrigger) {
1016
- this.stats.triggers++;
1017
- }
1030
+ if (collider.layer === i && (collider.mask & 1 << j) !== 0) {
1031
+ canCollide = true;
1032
+ break;
1033
+ }
1018
1034
  }
1019
- for (const collider of this.colliders3D.values()) {
1020
- if (collider.isTrigger) {
1021
- this.stats.triggers++;
1022
- }
1023
- }
1024
- // Collision pairs and contacts
1025
- this.stats.collisionPairs = this.collisionPairs.length;
1026
- this.stats.contactPoints = 0;
1027
- for (const pair of this.collisionPairs) {
1028
- this.stats.contactPoints += pair.contacts.length;
1029
- }
1030
- // Joints
1031
- this.stats.totalJoints = this.joints2D.size + this.joints3D.size;
1032
- this.stats.activeJoints = this.stats.totalJoints;
1033
- this.stats.brokenJoints = 0;
1034
- // Memory estimates
1035
- this.stats.bodyMemory = this.stats.totalBodies * 256; // Rough estimate
1036
- this.stats.colliderMemory = this.stats.totalColliders * 128;
1037
- this.stats.contactMemory = this.stats.contactPoints * 64;
1038
- }
1039
- getStats() {
1040
- return { ...this.stats };
1041
- }
1042
- // ─── Stats Overlay Text ────────────────────────────────
1043
- generateStatsOverlayText() {
1044
- const s = this.stats;
1045
- return [
1046
- '=== Physics Debug ===',
1047
- '',
1048
- '--- Bodies ---',
1049
- `Total: ${s.totalBodies}`,
1050
- ` Dynamic: ${s.dynamicBodies}`,
1051
- ` Kinematic: ${s.kinematicBodies}`,
1052
- ` Static: ${s.staticBodies}`,
1053
- `Awake: ${s.awakeBodies} / Sleeping: ${s.sleepingBodies}`,
1054
- '',
1055
- '--- Colliders ---',
1056
- `Total: ${s.totalColliders}`,
1057
- `Active: ${s.activeColliders}`,
1058
- `Triggers: ${s.triggers}`,
1059
- '',
1060
- '--- Simulation ---',
1061
- `Collision Pairs: ${s.collisionPairs}`,
1062
- `Contact Points: ${s.contactPoints}`,
1063
- `Islands: ${s.islandCount}`,
1064
- '',
1065
- '--- Timing (ms) ---',
1066
- `Step: ${s.stepTime.toFixed(2)}`,
1067
- ` Broadphase: ${s.broadphaseTime.toFixed(2)}`,
1068
- ` Narrowphase: ${s.narrowphaseTime.toFixed(2)}`,
1069
- ` Solver: ${s.solverTime.toFixed(2)}`,
1070
- ` Integration: ${s.integrationTime.toFixed(2)}`,
1071
- '',
1072
- '--- Memory (KB) ---',
1073
- `Bodies: ${(s.bodyMemory / 1024).toFixed(1)}`,
1074
- `Colliders: ${(s.colliderMemory / 1024).toFixed(1)}`,
1075
- `Contacts: ${(s.contactMemory / 1024).toFixed(1)}`,
1076
- '',
1077
- '--- Joints ---',
1078
- `Total: ${s.totalJoints}`,
1079
- `Active: ${s.activeJoints}`,
1080
- `Broken: ${s.brokenJoints}`,
1081
- '',
1082
- '--- Queries/Frame ---',
1083
- `Raycasts: ${s.raycastsThisFrame}`,
1084
- `Overlaps: ${s.overlapTestsThisFrame}`,
1085
- ];
1086
- }
1087
- // ─── Collision Layer Matrix ────────────────────────────
1088
- generateLayerMatrix(layerCount = 32) {
1089
- // Generate a collision layer matrix based on mask settings
1090
- const matrix = [];
1091
- for (let i = 0; i < layerCount; i++) {
1092
- matrix[i] = [];
1093
- for (let j = 0; j < layerCount; j++) {
1094
- // Check if any collider on layer i can collide with layer j
1095
- let canCollide = false;
1096
- for (const collider of this.colliders2D.values()) {
1097
- if (collider.layer === i && (collider.mask & (1 << j)) !== 0) {
1098
- canCollide = true;
1099
- break;
1100
- }
1101
- }
1102
- if (!canCollide) {
1103
- for (const collider of this.colliders3D.values()) {
1104
- if (collider.layer === i && (collider.mask & (1 << j)) !== 0) {
1105
- canCollide = true;
1106
- break;
1107
- }
1108
- }
1109
- }
1110
- matrix[i][j] = canCollide;
1035
+ if (!canCollide) {
1036
+ for (const collider of this.colliders3D.values()) {
1037
+ if (collider.layer === i && (collider.mask & 1 << j) !== 0) {
1038
+ canCollide = true;
1039
+ break;
1111
1040
  }
1041
+ }
1112
1042
  }
1113
- return matrix;
1114
- }
1115
- // ─── Clear ─────────────────────────────────────────────
1116
- clear() {
1117
- this.colliders2D.clear();
1118
- this.colliders3D.clear();
1119
- this.bodies2D.clear();
1120
- this.bodies3D.clear();
1121
- this.joints2D.clear();
1122
- this.joints3D.clear();
1123
- this.transforms2D.clear();
1124
- this.transforms3D.clear();
1125
- this.collisionPairs = [];
1126
- this.raycasts = [];
1127
- this.contactHistory = [];
1128
- this.drawCommands = [];
1129
- this.stats = this.createEmptyStats();
1043
+ matrix[i][j] = canCollide;
1044
+ }
1130
1045
  }
1046
+ return matrix;
1047
+ }
1048
+ // ─── Clear ─────────────────────────────────────────────
1049
+ clear() {
1050
+ this.colliders2D.clear();
1051
+ this.colliders3D.clear();
1052
+ this.bodies2D.clear();
1053
+ this.bodies3D.clear();
1054
+ this.joints2D.clear();
1055
+ this.joints3D.clear();
1056
+ this.transforms2D.clear();
1057
+ this.transforms3D.clear();
1058
+ this.collisionPairs = [];
1059
+ this.raycasts = [];
1060
+ this.contactHistory = [];
1061
+ this.drawCommands = [];
1062
+ this.stats = this.createEmptyStats();
1063
+ }
1131
1064
  }
1132
- // ============================================================
1133
- // Factory Functions
1134
- // ============================================================
1135
1065
  function createPhysicsDebugSystem() {
1136
- return new PhysicsDebugSystem();
1066
+ return new PhysicsDebugSystem();
1137
1067
  }
1138
1068
  function createCollider2D(type, entityId) {
1139
- return {
1140
- id: `col2d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1141
- entityId,
1142
- type,
1143
- offset: { x: 0, y: 0 },
1144
- rotation: 0,
1145
- isTrigger: false,
1146
- layer: 0,
1147
- mask: 0xffffffff,
1148
- radius: type === 'circle' || type === 'capsule' ? 0.5 : undefined,
1149
- halfExtents: type === 'box' ? { x: 0.5, y: 0.5 } : undefined,
1150
- capsuleHeight: type === 'capsule' ? 1 : undefined,
1151
- };
1069
+ return {
1070
+ id: `col2d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1071
+ entityId,
1072
+ type,
1073
+ offset: { x: 0, y: 0 },
1074
+ rotation: 0,
1075
+ isTrigger: false,
1076
+ layer: 0,
1077
+ mask: 4294967295,
1078
+ radius: type === "circle" || type === "capsule" ? 0.5 : void 0,
1079
+ halfExtents: type === "box" ? { x: 0.5, y: 0.5 } : void 0,
1080
+ capsuleHeight: type === "capsule" ? 1 : void 0
1081
+ };
1152
1082
  }
1153
1083
  function createCollider3D(type, entityId) {
1154
- return {
1155
- id: `col3d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1156
- entityId,
1157
- type,
1158
- offset: { x: 0, y: 0, z: 0 },
1159
- rotation: { x: 0, y: 0, z: 0 },
1160
- isTrigger: false,
1161
- layer: 0,
1162
- mask: 0xffffffff,
1163
- radius: type === 'sphere' ? 0.5 : undefined,
1164
- halfExtents: type === 'box' ? { x: 0.5, y: 0.5, z: 0.5 } : undefined,
1165
- capsuleRadius: type === 'capsule' ? 0.5 : undefined,
1166
- capsuleHeight: type === 'capsule' ? 1 : undefined,
1167
- cylinderRadius: type === 'cylinder' ? 0.5 : undefined,
1168
- cylinderHeight: type === 'cylinder' ? 1 : undefined,
1169
- };
1084
+ return {
1085
+ id: `col3d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1086
+ entityId,
1087
+ type,
1088
+ offset: { x: 0, y: 0, z: 0 },
1089
+ rotation: { x: 0, y: 0, z: 0 },
1090
+ isTrigger: false,
1091
+ layer: 0,
1092
+ mask: 4294967295,
1093
+ radius: type === "sphere" ? 0.5 : void 0,
1094
+ halfExtents: type === "box" ? { x: 0.5, y: 0.5, z: 0.5 } : void 0,
1095
+ capsuleRadius: type === "capsule" ? 0.5 : void 0,
1096
+ capsuleHeight: type === "capsule" ? 1 : void 0,
1097
+ cylinderRadius: type === "cylinder" ? 0.5 : void 0,
1098
+ cylinderHeight: type === "cylinder" ? 1 : void 0
1099
+ };
1170
1100
  }
1171
- function createRigidbody2D(entityId, bodyType = 'dynamic') {
1172
- return {
1173
- id: `rb2d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1174
- entityId,
1175
- bodyType,
1176
- mass: 1,
1177
- linearDamping: 0,
1178
- angularDamping: 0.05,
1179
- gravityScale: 1,
1180
- fixedRotation: false,
1181
- isBullet: false,
1182
- isAwake: true,
1183
- isSleeping: false,
1184
- linearVelocity: { x: 0, y: 0 },
1185
- angularVelocity: 0,
1186
- forceAccumulator: { x: 0, y: 0 },
1187
- torqueAccumulator: 0,
1188
- };
1101
+ function createRigidbody2D(entityId, bodyType = "dynamic") {
1102
+ return {
1103
+ id: `rb2d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1104
+ entityId,
1105
+ bodyType,
1106
+ mass: 1,
1107
+ linearDamping: 0,
1108
+ angularDamping: 0.05,
1109
+ gravityScale: 1,
1110
+ fixedRotation: false,
1111
+ isBullet: false,
1112
+ isAwake: true,
1113
+ isSleeping: false,
1114
+ linearVelocity: { x: 0, y: 0 },
1115
+ angularVelocity: 0,
1116
+ forceAccumulator: { x: 0, y: 0 },
1117
+ torqueAccumulator: 0
1118
+ };
1189
1119
  }
1190
- function createRigidbody3D(entityId, bodyType = 'dynamic') {
1191
- return {
1192
- id: `rb3d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1193
- entityId,
1194
- bodyType,
1195
- mass: 1,
1196
- linearDamping: 0,
1197
- angularDamping: 0.05,
1198
- useGravity: true,
1199
- constraints: {
1200
- freezePositionX: false,
1201
- freezePositionY: false,
1202
- freezePositionZ: false,
1203
- freezeRotationX: false,
1204
- freezeRotationY: false,
1205
- freezeRotationZ: false,
1206
- },
1207
- interpolation: 'none',
1208
- collisionDetection: 'discrete',
1209
- isAwake: true,
1210
- isSleeping: false,
1211
- linearVelocity: { x: 0, y: 0, z: 0 },
1212
- angularVelocity: { x: 0, y: 0, z: 0 },
1213
- forceAccumulator: { x: 0, y: 0, z: 0 },
1214
- torqueAccumulator: { x: 0, y: 0, z: 0 },
1215
- };
1120
+ function createRigidbody3D(entityId, bodyType = "dynamic") {
1121
+ return {
1122
+ id: `rb3d_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
1123
+ entityId,
1124
+ bodyType,
1125
+ mass: 1,
1126
+ linearDamping: 0,
1127
+ angularDamping: 0.05,
1128
+ useGravity: true,
1129
+ constraints: {
1130
+ freezePositionX: false,
1131
+ freezePositionY: false,
1132
+ freezePositionZ: false,
1133
+ freezeRotationX: false,
1134
+ freezeRotationY: false,
1135
+ freezeRotationZ: false
1136
+ },
1137
+ interpolation: "none",
1138
+ collisionDetection: "discrete",
1139
+ isAwake: true,
1140
+ isSleeping: false,
1141
+ linearVelocity: { x: 0, y: 0, z: 0 },
1142
+ angularVelocity: { x: 0, y: 0, z: 0 },
1143
+ forceAccumulator: { x: 0, y: 0, z: 0 },
1144
+ torqueAccumulator: { x: 0, y: 0, z: 0 }
1145
+ };
1216
1146
  }
1217
-
1218
- export { DEFAULT_DEBUG_COLORS, DEFAULT_DEBUG_OPTIONS, PhysicsDebugSystem, createCollider2D, createCollider3D, createPhysicsDebugSystem, createRigidbody2D, createRigidbody3D };
1147
+ export {
1148
+ DEFAULT_DEBUG_COLORS,
1149
+ DEFAULT_DEBUG_OPTIONS,
1150
+ PhysicsDebugSystem,
1151
+ createCollider2D,
1152
+ createCollider3D,
1153
+ createPhysicsDebugSystem,
1154
+ createRigidbody2D,
1155
+ createRigidbody3D
1156
+ };