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