1681-engine 0.0.0-stage → 0.5.8
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 +304 -0
- package/LICENSE +21 -0
- package/README.md +164 -2
- package/dist/1681-engine.js +417 -0
- package/dist/1681-engine.js.map +1 -0
- package/dist/ambient/ColorGrade.js +41 -0
- package/dist/ambient/ColorGrade.js.map +1 -0
- package/dist/ambient/DayClock.js +57 -0
- package/dist/ambient/DayClock.js.map +1 -0
- package/dist/ambient/WeatherLayer.js +91 -0
- package/dist/ambient/WeatherLayer.js.map +1 -0
- package/dist/ambient/grade.js +13 -0
- package/dist/ambient/grade.js.map +1 -0
- package/dist/ambient/weather.js +52 -0
- package/dist/ambient/weather.js.map +1 -0
- package/dist/anim/AnimStateMachine.js +164 -0
- package/dist/anim/AnimStateMachine.js.map +1 -0
- package/dist/anim/Animator.js +67 -0
- package/dist/anim/Animator.js.map +1 -0
- package/dist/anim/animStateCompile.js +113 -0
- package/dist/anim/animStateCompile.js.map +1 -0
- package/dist/anim/animStateSystem.js +17 -0
- package/dist/anim/animStateSystem.js.map +1 -0
- package/dist/anim/animationSystem.js +15 -0
- package/dist/anim/animationSystem.js.map +1 -0
- package/dist/anim/asepriteSlices.js +22 -0
- package/dist/anim/asepriteSlices.js.map +1 -0
- package/dist/anim/asepriteTags.js +35 -0
- package/dist/anim/asepriteTags.js.map +1 -0
- package/dist/anim/parseAseprite.js +83 -0
- package/dist/anim/parseAseprite.js.map +1 -0
- package/dist/assets/AssetLoader.js +104 -0
- package/dist/assets/AssetLoader.js.map +1 -0
- package/dist/assets/loadAseprite.js +50 -0
- package/dist/assets/loadAseprite.js.map +1 -0
- package/dist/assets/takeCleanerWorker-DTcI_Jqr.js +31 -0
- package/dist/assets/takeCleanerWorker-DTcI_Jqr.js.map +1 -0
- package/dist/audio/Footsteps.js +26 -0
- package/dist/audio/Footsteps.js.map +1 -0
- package/dist/audio/MusicPlayer.js +78 -0
- package/dist/audio/MusicPlayer.js.map +1 -0
- package/dist/audio/SoundEngine.js +119 -0
- package/dist/audio/SoundEngine.js.map +1 -0
- package/dist/audio/cleanTake.js +30 -0
- package/dist/audio/cleanTake.js.map +1 -0
- package/dist/audio/music/ElementVoice.js +35 -0
- package/dist/audio/music/ElementVoice.js.map +1 -0
- package/dist/audio/music/GraphVoice.js +39 -0
- package/dist/audio/music/GraphVoice.js.map +1 -0
- package/dist/audio/music/MusicChannel.js +58 -0
- package/dist/audio/music/MusicChannel.js.map +1 -0
- package/dist/audio/music/musicVoice.js +13 -0
- package/dist/audio/music/musicVoice.js.map +1 -0
- package/dist/audio/sampleBank.js +82 -0
- package/dist/audio/sampleBank.js.map +1 -0
- package/dist/audio/soundTable.js +9 -0
- package/dist/audio/soundTable.js.map +1 -0
- package/dist/audio/synth.js +36 -0
- package/dist/audio/synth.js.map +1 -0
- package/dist/core/BitmapLabel.js +49 -0
- package/dist/core/BitmapLabel.js.map +1 -0
- package/dist/core/Camera.js +150 -0
- package/dist/core/Camera.js.map +1 -0
- package/dist/core/Clock.js +30 -0
- package/dist/core/Clock.js.map +1 -0
- package/dist/core/Graphics.js +69 -0
- package/dist/core/Graphics.js.map +1 -0
- package/dist/core/Group.js +29 -0
- package/dist/core/Group.js.map +1 -0
- package/dist/core/Image.js +51 -0
- package/dist/core/Image.js.map +1 -0
- package/dist/core/ObjectFactory.js +55 -0
- package/dist/core/ObjectFactory.js.map +1 -0
- package/dist/core/Pointer.js +58 -0
- package/dist/core/Pointer.js.map +1 -0
- package/dist/core/Rectangle.js +51 -0
- package/dist/core/Rectangle.js.map +1 -0
- package/dist/core/Stage.js +86 -0
- package/dist/core/Stage.js.map +1 -0
- package/dist/core/Text.js +22 -0
- package/dist/core/Text.js.map +1 -0
- package/dist/core/TextureRegistry.js +111 -0
- package/dist/core/TextureRegistry.js.map +1 -0
- package/dist/core/Timeline.js +211 -0
- package/dist/core/Timeline.js.map +1 -0
- package/dist/core/TimelineBuilder.js +73 -0
- package/dist/core/TimelineBuilder.js.map +1 -0
- package/dist/core/TimelineChild.js +84 -0
- package/dist/core/TimelineChild.js.map +1 -0
- package/dist/core/Tweener.js +136 -0
- package/dist/core/Tweener.js.map +1 -0
- package/dist/core/atlas.js +38 -0
- package/dist/core/atlas.js.map +1 -0
- package/dist/core/atlasPlan.js +22 -0
- package/dist/core/atlasPlan.js.map +1 -0
- package/dist/core/eases.js +21 -0
- package/dist/core/eases.js.map +1 -0
- package/dist/core/gameObject.js +115 -0
- package/dist/core/gameObject.js.map +1 -0
- package/dist/core/pixiPatches.js +18 -0
- package/dist/core/pixiPatches.js.map +1 -0
- package/dist/core/timelinePlace.js +24 -0
- package/dist/core/timelinePlace.js.map +1 -0
- package/dist/core/tweenProps.js +12 -0
- package/dist/core/tweenProps.js.map +1 -0
- package/dist/debug/DebugOverlay.js +94 -0
- package/dist/debug/DebugOverlay.js.map +1 -0
- package/dist/debug/DrawCallCounter.js +41 -0
- package/dist/debug/DrawCallCounter.js.map +1 -0
- package/dist/debug/ErrorLog.js +22 -0
- package/dist/debug/ErrorLog.js.map +1 -0
- package/dist/debug/FrameStats.js +42 -0
- package/dist/debug/FrameStats.js.map +1 -0
- package/dist/debug/inspectWorld.js +29 -0
- package/dist/debug/inspectWorld.js.map +1 -0
- package/dist/diagnostics/ErrorDeduper.js +27 -0
- package/dist/diagnostics/ErrorDeduper.js.map +1 -0
- package/dist/diagnostics/FrameSampler.js +42 -0
- package/dist/diagnostics/FrameSampler.js.map +1 -0
- package/dist/diagnostics/bootWatch.js +21 -0
- package/dist/diagnostics/bootWatch.js.map +1 -0
- package/dist/diagnostics/captureErrors.js +27 -0
- package/dist/diagnostics/captureErrors.js.map +1 -0
- package/dist/diagnostics/contextLoss.js +25 -0
- package/dist/diagnostics/contextLoss.js.map +1 -0
- package/dist/diagnostics/frameStats.js +31 -0
- package/dist/diagnostics/frameStats.js.map +1 -0
- package/dist/diagnostics/gpuInfo.js +22 -0
- package/dist/diagnostics/gpuInfo.js.map +1 -0
- package/dist/diagnostics/renderGuard.js +24 -0
- package/dist/diagnostics/renderGuard.js.map +1 -0
- package/dist/ecs/SparseSet.js +55 -0
- package/dist/ecs/SparseSet.js.map +1 -0
- package/dist/ecs/World.js +307 -0
- package/dist/ecs/World.js.map +1 -0
- package/dist/ecs/fields.js +26 -0
- package/dist/ecs/fields.js.map +1 -0
- package/dist/engine/Engine.js +82 -0
- package/dist/engine/Engine.js.map +1 -0
- package/dist/engine/FixedLoop.js +37 -0
- package/dist/engine/FixedLoop.js.map +1 -0
- package/dist/engine/Scene.js +79 -0
- package/dist/engine/Scene.js.map +1 -0
- package/dist/engine/SceneManager.js +73 -0
- package/dist/engine/SceneManager.js.map +1 -0
- package/dist/events/EventBus.js +42 -0
- package/dist/events/EventBus.js.map +1 -0
- package/dist/fx/FloatingText.js +72 -0
- package/dist/fx/FloatingText.js.map +1 -0
- package/dist/fx/hitStop.js +28 -0
- package/dist/fx/hitStop.js.map +1 -0
- package/dist/fx/viewCull.js +10 -0
- package/dist/fx/viewCull.js.map +1 -0
- package/dist/i18n/Translator.js +72 -0
- package/dist/i18n/Translator.js.map +1 -0
- package/dist/i18n/extractStrings.js +58 -0
- package/dist/i18n/extractStrings.js.map +1 -0
- package/dist/i18n/formatMessage.js +19 -0
- package/dist/i18n/formatMessage.js.map +1 -0
- package/dist/input/Actions.js +131 -0
- package/dist/input/Actions.js.map +1 -0
- package/dist/input/AimGesture.js +75 -0
- package/dist/input/AimGesture.js.map +1 -0
- package/dist/input/Keyboard.js +54 -0
- package/dist/input/Keyboard.js.map +1 -0
- package/dist/input/Keymap.js +171 -0
- package/dist/input/Keymap.js.map +1 -0
- package/dist/input/TargetLock.js +73 -0
- package/dist/input/TargetLock.js.map +1 -0
- package/dist/input/aimAxis.js +8 -0
- package/dist/input/aimAxis.js.map +1 -0
- package/dist/input/keyChord.js +29 -0
- package/dist/input/keyChord.js.map +1 -0
- package/dist/input/longPress.js +32 -0
- package/dist/input/longPress.js.map +1 -0
- package/dist/input/stickAxis.js +23 -0
- package/dist/input/stickAxis.js.map +1 -0
- package/dist/input/touchDetect.js +7 -0
- package/dist/input/touchDetect.js.map +1 -0
- package/dist/light/LightLayer.js +84 -0
- package/dist/light/LightLayer.js.map +1 -0
- package/dist/nav/MinHeap.js +39 -0
- package/dist/nav/MinHeap.js.map +1 -0
- package/dist/nav/findPath.js +78 -0
- package/dist/nav/findPath.js.map +1 -0
- package/dist/nav/navGrid.js +36 -0
- package/dist/nav/navGrid.js.map +1 -0
- package/dist/nav/nearestOpen.js +19 -0
- package/dist/nav/nearestOpen.js.map +1 -0
- package/dist/nav/straightenPath.js +51 -0
- package/dist/nav/straightenPath.js.map +1 -0
- package/dist/net/Connection.js +84 -0
- package/dist/net/Connection.js.map +1 -0
- package/dist/net/InterpolationBuffer.js +57 -0
- package/dist/net/InterpolationBuffer.js.map +1 -0
- package/dist/net/PredictedMover.js +61 -0
- package/dist/net/PredictedMover.js.map +1 -0
- package/dist/net/Room.js +92 -0
- package/dist/net/Room.js.map +1 -0
- package/dist/net/RoomHost.js +101 -0
- package/dist/net/RoomHost.js.map +1 -0
- package/dist/net/cadence.js +22 -0
- package/dist/net/cadence.js.map +1 -0
- package/dist/net/constants.js +11 -0
- package/dist/net/constants.js.map +1 -0
- package/dist/net/lobby/LobbyClient.js +124 -0
- package/dist/net/lobby/LobbyClient.js.map +1 -0
- package/dist/net/lobby/LobbyHost.js +366 -0
- package/dist/net/lobby/LobbyHost.js.map +1 -0
- package/dist/net/lobby/LobbyRooms.js +66 -0
- package/dist/net/lobby/LobbyRooms.js.map +1 -0
- package/dist/net/lobby/Matchmaker.js +106 -0
- package/dist/net/lobby/Matchmaker.js.map +1 -0
- package/dist/net/movement.js +83 -0
- package/dist/net/movement.js.map +1 -0
- package/dist/net/protocol.js +11 -0
- package/dist/net/protocol.js.map +1 -0
- package/dist/net/serverClock.js +22 -0
- package/dist/net/serverClock.js.map +1 -0
- package/dist/net/snapshotCodec.js +92 -0
- package/dist/net/snapshotCodec.js.map +1 -0
- package/dist/parallax/Parallax.js +32 -0
- package/dist/parallax/Parallax.js.map +1 -0
- package/dist/parallax/ParallaxLayer.js +70 -0
- package/dist/parallax/ParallaxLayer.js.map +1 -0
- package/dist/parallax/parallaxMath.js +27 -0
- package/dist/parallax/parallaxMath.js.map +1 -0
- package/dist/particles/Emitter.js +108 -0
- package/dist/particles/Emitter.js.map +1 -0
- package/dist/particles/ParticleBudget.js +32 -0
- package/dist/particles/ParticleBudget.js.map +1 -0
- package/dist/particles/ParticleSim.js +60 -0
- package/dist/particles/ParticleSim.js.map +1 -0
- package/dist/particles/particleCurves.js +48 -0
- package/dist/particles/particleCurves.js.map +1 -0
- package/dist/particles/particleSampling.js +30 -0
- package/dist/particles/particleSampling.js.map +1 -0
- package/dist/physics/Body.js +202 -0
- package/dist/physics/Body.js.map +1 -0
- package/dist/physics/BroadPhase.js +56 -0
- package/dist/physics/BroadPhase.js.map +1 -0
- package/dist/physics/Contact.js +76 -0
- package/dist/physics/Contact.js.map +1 -0
- package/dist/physics/ContactSolver.js +70 -0
- package/dist/physics/ContactSolver.js.map +1 -0
- package/dist/physics/PhysicsWorld.js +221 -0
- package/dist/physics/PhysicsWorld.js.map +1 -0
- package/dist/physics/SpatialHash.js +39 -0
- package/dist/physics/SpatialHash.js.map +1 -0
- package/dist/physics/collide.js +76 -0
- package/dist/physics/collide.js.map +1 -0
- package/dist/physics/collidePolygon.js +94 -0
- package/dist/physics/collidePolygon.js.map +1 -0
- package/dist/physics/contactReport.js +14 -0
- package/dist/physics/contactReport.js.map +1 -0
- package/dist/physics/drawColliders.js +31 -0
- package/dist/physics/drawColliders.js.map +1 -0
- package/dist/physics/physicsSystem.js +8 -0
- package/dist/physics/physicsSystem.js.map +1 -0
- package/dist/physics/polygon.js +80 -0
- package/dist/physics/polygon.js.map +1 -0
- package/dist/physics/raycast.js +62 -0
- package/dist/physics/raycast.js.map +1 -0
- package/dist/physics/syncToBody.js +19 -0
- package/dist/physics/syncToBody.js.map +1 -0
- package/dist/physics/tileBodies.js +59 -0
- package/dist/physics/tileBodies.js.map +1 -0
- package/dist/physics/types.js +8 -0
- package/dist/physics/types.js.map +1 -0
- package/dist/pixel/Darkness.js +166 -0
- package/dist/pixel/Darkness.js.map +1 -0
- package/dist/pixel/DitherVignette.js +57 -0
- package/dist/pixel/DitherVignette.js.map +1 -0
- package/dist/pixel/Evaporation.js +85 -0
- package/dist/pixel/Evaporation.js.map +1 -0
- package/dist/pixel/NightShade.js +34 -0
- package/dist/pixel/NightShade.js.map +1 -0
- package/dist/pixel/PixelLayer.js +211 -0
- package/dist/pixel/PixelLayer.js.map +1 -0
- package/dist/pixel/SwayProp.js +75 -0
- package/dist/pixel/SwayProp.js.map +1 -0
- package/dist/pixel/lights.js +44 -0
- package/dist/pixel/lights.js.map +1 -0
- package/dist/pixel/nineSlice.js +62 -0
- package/dist/pixel/nineSlice.js.map +1 -0
- package/dist/pixel/paintLayer.js +36 -0
- package/dist/pixel/paintLayer.js.map +1 -0
- package/dist/pixel/palette.js +57 -0
- package/dist/pixel/palette.js.map +1 -0
- package/dist/pixel/pixel.js +278 -0
- package/dist/pixel/pixel.js.map +1 -0
- package/dist/pixel/pixelPaint.js +194 -0
- package/dist/pixel/pixelPaint.js.map +1 -0
- package/dist/pixel/pixelTone.js +164 -0
- package/dist/pixel/pixelTone.js.map +1 -0
- package/dist/pixel/propKit.js +41 -0
- package/dist/pixel/propKit.js.map +1 -0
- package/dist/pixel/ramp.js +102 -0
- package/dist/pixel/ramp.js.map +1 -0
- package/dist/pixel/selout.js +35 -0
- package/dist/pixel/selout.js.map +1 -0
- package/dist/pixel/spritePixels.js +59 -0
- package/dist/pixel/spritePixels.js.map +1 -0
- package/dist/pixel/swayRig.js +87 -0
- package/dist/pixel/swayRig.js.map +1 -0
- package/dist/pixel/vignetteMask.js +24 -0
- package/dist/pixel/vignetteMask.js.map +1 -0
- package/dist/pixel/weatherArt.js +61 -0
- package/dist/pixel/weatherArt.js.map +1 -0
- package/dist/pixel.js +90 -0
- package/dist/pixel.js.map +1 -0
- package/dist/platform/touch.js +33 -0
- package/dist/platform/touch.js.map +1 -0
- package/dist/postfx/BloomFilter.js +65 -0
- package/dist/postfx/BloomFilter.js.map +1 -0
- package/dist/postfx/ChromaticAberrationFilter.js +25 -0
- package/dist/postfx/ChromaticAberrationFilter.js.map +1 -0
- package/dist/postfx/ColorAdjustFilter.js +76 -0
- package/dist/postfx/ColorAdjustFilter.js.map +1 -0
- package/dist/postfx/CrtFilter.js +42 -0
- package/dist/postfx/CrtFilter.js.map +1 -0
- package/dist/postfx/PixelateFilter.js +27 -0
- package/dist/postfx/PixelateFilter.js.map +1 -0
- package/dist/postfx/PostFx.js +123 -0
- package/dist/postfx/PostFx.js.map +1 -0
- package/dist/postfx/ShockwaveFilter.js +49 -0
- package/dist/postfx/ShockwaveFilter.js.map +1 -0
- package/dist/postfx/VignetteFilter.js +37 -0
- package/dist/postfx/VignetteFilter.js.map +1 -0
- package/dist/postfx/fxAnimator.js +38 -0
- package/dist/postfx/fxAnimator.js.map +1 -0
- package/dist/postfx/fxShader.js +128 -0
- package/dist/postfx/fxShader.js.map +1 -0
- package/dist/postfx.js +26 -0
- package/dist/postfx.js.map +1 -0
- package/dist/react/ChoiceDialog.js +51 -0
- package/dist/react/ChoiceDialog.js.map +1 -0
- package/dist/react/ConfirmDialog.js +53 -0
- package/dist/react/ConfirmDialog.js.map +1 -0
- package/dist/react/Glyph.js +63 -0
- package/dist/react/Glyph.js.map +1 -0
- package/dist/react/Modal.js +38 -0
- package/dist/react/Modal.js.map +1 -0
- package/dist/react/Panel.js +24 -0
- package/dist/react/Panel.js.map +1 -0
- package/dist/react/PixelImage.js +24 -0
- package/dist/react/PixelImage.js.map +1 -0
- package/dist/react/Select.js +99 -0
- package/dist/react/Select.js.map +1 -0
- package/dist/react/Slider.js +62 -0
- package/dist/react/Slider.js.map +1 -0
- package/dist/react/SplitPane.js +24 -0
- package/dist/react/SplitPane.js.map +1 -0
- package/dist/react/TabStrip.js +32 -0
- package/dist/react/TabStrip.js.map +1 -0
- package/dist/react/TitleTips.js +42 -0
- package/dist/react/TitleTips.js.map +1 -0
- package/dist/react/Tooltip.js +28 -0
- package/dist/react/Tooltip.js.map +1 -0
- package/dist/react/UiProvider.js +50 -0
- package/dist/react/UiProvider.js.map +1 -0
- package/dist/react/baseCss.js +222 -0
- package/dist/react/baseCss.js.map +1 -0
- package/dist/react/choiceStore.js +23 -0
- package/dist/react/choiceStore.js.map +1 -0
- package/dist/react/classNames.js +19 -0
- package/dist/react/classNames.js.map +1 -0
- package/dist/react/confirmStore.js +30 -0
- package/dist/react/confirmStore.js.map +1 -0
- package/dist/react/labels.js +18 -0
- package/dist/react/labels.js.map +1 -0
- package/dist/react/placement.js +49 -0
- package/dist/react/placement.js.map +1 -0
- package/dist/react/useFillSheet.js +23 -0
- package/dist/react/useFillSheet.js.map +1 -0
- package/dist/react/useFitToViewport.js +29 -0
- package/dist/react/useFitToViewport.js.map +1 -0
- package/dist/react/usePicked.js +13 -0
- package/dist/react/usePicked.js.map +1 -0
- package/dist/react/useStore.js +9 -0
- package/dist/react/useStore.js.map +1 -0
- package/dist/react/useViewport.js +17 -0
- package/dist/react/useViewport.js.map +1 -0
- package/dist/react.js +78 -0
- package/dist/react.js.map +1 -0
- package/dist/rig/PosePlayer.js +92 -0
- package/dist/rig/PosePlayer.js.map +1 -0
- package/dist/rig/RigView.js +125 -0
- package/dist/rig/RigView.js.map +1 -0
- package/dist/rig/Skeleton.js +31 -0
- package/dist/rig/Skeleton.js.map +1 -0
- package/dist/rig/humanoid.js +6 -0
- package/dist/rig/humanoid.js.map +1 -0
- package/dist/rig/humanoid.json.js +30 -0
- package/dist/rig/humanoid.json.js.map +1 -0
- package/dist/rig/humanoidPoses.js +30 -0
- package/dist/rig/humanoidPoses.js.map +1 -0
- package/dist/rig/poseMath.js +54 -0
- package/dist/rig/poseMath.js.map +1 -0
- package/dist/rig/poses.json.js +150 -0
- package/dist/rig/poses.json.js.map +1 -0
- package/dist/save/Autosaver.js +54 -0
- package/dist/save/Autosaver.js.map +1 -0
- package/dist/save/MemoryBackend.js +19 -0
- package/dist/save/MemoryBackend.js.map +1 -0
- package/dist/save/SaveStore.js +103 -0
- package/dist/save/SaveStore.js.map +1 -0
- package/dist/save/WebStorageBackend.js +27 -0
- package/dist/save/WebStorageBackend.js.map +1 -0
- package/dist/save/checksum.js +10 -0
- package/dist/save/checksum.js.map +1 -0
- package/dist/save/migrateSave.js +27 -0
- package/dist/save/migrateSave.js.map +1 -0
- package/dist/settings.js +27 -0
- package/dist/settings.js.map +1 -0
- package/dist/tilemap/TilemapView.js +69 -0
- package/dist/tilemap/TilemapView.js.map +1 -0
- package/dist/tilemap/collision.js +25 -0
- package/dist/tilemap/collision.js.map +1 -0
- package/dist/tilemap/tiled.js +138 -0
- package/dist/tilemap/tiled.js.map +1 -0
- package/dist/transitions/CrossfadeTransition.js +24 -0
- package/dist/transitions/CrossfadeTransition.js.map +1 -0
- package/dist/transitions/DitherWipeTransition.js +70 -0
- package/dist/transitions/DitherWipeTransition.js.map +1 -0
- package/dist/transitions/FadeTransition.js +34 -0
- package/dist/transitions/FadeTransition.js.map +1 -0
- package/dist/transitions/Letterbox.js +42 -0
- package/dist/transitions/Letterbox.js.map +1 -0
- package/dist/transitions/ditherMask.js +15 -0
- package/dist/transitions/ditherMask.js.map +1 -0
- package/dist/transitions/transitionTo.js +28 -0
- package/dist/transitions/transitionTo.js.map +1 -0
- package/dist/transitions/tweenDone.js +15 -0
- package/dist/transitions/tweenDone.js.map +1 -0
- package/dist/types/ambient/ColorGrade.d.ts +41 -0
- package/dist/types/ambient/ColorGrade.d.ts.map +1 -0
- package/dist/types/ambient/DayClock.d.ts +80 -0
- package/dist/types/ambient/DayClock.d.ts.map +1 -0
- package/dist/types/ambient/WeatherLayer.d.ts +78 -0
- package/dist/types/ambient/WeatherLayer.d.ts.map +1 -0
- package/dist/types/ambient/grade.d.ts +22 -0
- package/dist/types/ambient/grade.d.ts.map +1 -0
- package/dist/types/ambient/weather.d.ts +49 -0
- package/dist/types/ambient/weather.d.ts.map +1 -0
- package/dist/types/anim/AnimStateMachine.d.ts +80 -0
- package/dist/types/anim/AnimStateMachine.d.ts.map +1 -0
- package/dist/types/anim/Animator.d.ts +50 -0
- package/dist/types/anim/Animator.d.ts.map +1 -0
- package/dist/types/anim/animStateCompile.d.ts +52 -0
- package/dist/types/anim/animStateCompile.d.ts.map +1 -0
- package/dist/types/anim/animStateSystem.d.ts +10 -0
- package/dist/types/anim/animStateSystem.d.ts.map +1 -0
- package/dist/types/anim/animStateTypes.d.ts +50 -0
- package/dist/types/anim/animStateTypes.d.ts.map +1 -0
- package/dist/types/anim/animationSystem.d.ts +13 -0
- package/dist/types/anim/animationSystem.d.ts.map +1 -0
- package/dist/types/anim/asepriteSlices.d.ts +19 -0
- package/dist/types/anim/asepriteSlices.d.ts.map +1 -0
- package/dist/types/anim/asepriteTags.d.ts +16 -0
- package/dist/types/anim/asepriteTags.d.ts.map +1 -0
- package/dist/types/anim/asepriteTypes.d.ts +159 -0
- package/dist/types/anim/asepriteTypes.d.ts.map +1 -0
- package/dist/types/anim/parseAseprite.d.ts +21 -0
- package/dist/types/anim/parseAseprite.d.ts.map +1 -0
- package/dist/types/assets/AssetLoader.d.ts +85 -0
- package/dist/types/assets/AssetLoader.d.ts.map +1 -0
- package/dist/types/assets/loadAseprite.d.ts +27 -0
- package/dist/types/assets/loadAseprite.d.ts.map +1 -0
- package/dist/types/audio/Footsteps.d.ts +33 -0
- package/dist/types/audio/Footsteps.d.ts.map +1 -0
- package/dist/types/audio/MusicPlayer.d.ts +65 -0
- package/dist/types/audio/MusicPlayer.d.ts.map +1 -0
- package/dist/types/audio/SoundEngine.d.ts +42 -0
- package/dist/types/audio/SoundEngine.d.ts.map +1 -0
- package/dist/types/audio/cleanTake.d.ts +3 -0
- package/dist/types/audio/cleanTake.d.ts.map +1 -0
- package/dist/types/audio/music/ElementVoice.d.ts +14 -0
- package/dist/types/audio/music/ElementVoice.d.ts.map +1 -0
- package/dist/types/audio/music/GraphVoice.d.ts +22 -0
- package/dist/types/audio/music/GraphVoice.d.ts.map +1 -0
- package/dist/types/audio/music/MusicChannel.d.ts +35 -0
- package/dist/types/audio/music/MusicChannel.d.ts.map +1 -0
- package/dist/types/audio/music/musicVoice.d.ts +26 -0
- package/dist/types/audio/music/musicVoice.d.ts.map +1 -0
- package/dist/types/audio/sampleBank.d.ts +27 -0
- package/dist/types/audio/sampleBank.d.ts.map +1 -0
- package/dist/types/audio/soundTable.d.ts +14 -0
- package/dist/types/audio/soundTable.d.ts.map +1 -0
- package/dist/types/audio/synth.d.ts +34 -0
- package/dist/types/audio/synth.d.ts.map +1 -0
- package/dist/types/audio/takeCleanerWorker.d.ts +2 -0
- package/dist/types/audio/takeCleanerWorker.d.ts.map +1 -0
- package/dist/types/core/BitmapLabel.d.ts +36 -0
- package/dist/types/core/BitmapLabel.d.ts.map +1 -0
- package/dist/types/core/Camera.d.ts +115 -0
- package/dist/types/core/Camera.d.ts.map +1 -0
- package/dist/types/core/Clock.d.ts +11 -0
- package/dist/types/core/Clock.d.ts.map +1 -0
- package/dist/types/core/Graphics.d.ts +37 -0
- package/dist/types/core/Graphics.d.ts.map +1 -0
- package/dist/types/core/Group.d.ts +15 -0
- package/dist/types/core/Group.d.ts.map +1 -0
- package/dist/types/core/Image.d.ts +25 -0
- package/dist/types/core/Image.d.ts.map +1 -0
- package/dist/types/core/ObjectFactory.d.ts +34 -0
- package/dist/types/core/ObjectFactory.d.ts.map +1 -0
- package/dist/types/core/Pointer.d.ts +27 -0
- package/dist/types/core/Pointer.d.ts.map +1 -0
- package/dist/types/core/Rectangle.d.ts +26 -0
- package/dist/types/core/Rectangle.d.ts.map +1 -0
- package/dist/types/core/Stage.d.ts +58 -0
- package/dist/types/core/Stage.d.ts.map +1 -0
- package/dist/types/core/Text.d.ts +22 -0
- package/dist/types/core/Text.d.ts.map +1 -0
- package/dist/types/core/TextureRegistry.d.ts +51 -0
- package/dist/types/core/TextureRegistry.d.ts.map +1 -0
- package/dist/types/core/Timeline.d.ts +115 -0
- package/dist/types/core/Timeline.d.ts.map +1 -0
- package/dist/types/core/TimelineBuilder.d.ts +53 -0
- package/dist/types/core/TimelineBuilder.d.ts.map +1 -0
- package/dist/types/core/TimelineChild.d.ts +51 -0
- package/dist/types/core/TimelineChild.d.ts.map +1 -0
- package/dist/types/core/Tweener.d.ts +70 -0
- package/dist/types/core/Tweener.d.ts.map +1 -0
- package/dist/types/core/atlas.d.ts +16 -0
- package/dist/types/core/atlas.d.ts.map +1 -0
- package/dist/types/core/atlasPlan.d.ts +34 -0
- package/dist/types/core/atlasPlan.d.ts.map +1 -0
- package/dist/types/core/eases.d.ts +3 -0
- package/dist/types/core/eases.d.ts.map +1 -0
- package/dist/types/core/gameObject.d.ts +42 -0
- package/dist/types/core/gameObject.d.ts.map +1 -0
- package/dist/types/core/pixiPatches.d.ts +9 -0
- package/dist/types/core/pixiPatches.d.ts.map +1 -0
- package/dist/types/core/timelinePlace.d.ts +23 -0
- package/dist/types/core/timelinePlace.d.ts.map +1 -0
- package/dist/types/core/tweenProps.d.ts +8 -0
- package/dist/types/core/tweenProps.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +4 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/debug/DebugOverlay.d.ts +63 -0
- package/dist/types/debug/DebugOverlay.d.ts.map +1 -0
- package/dist/types/debug/DrawCallCounter.d.ts +20 -0
- package/dist/types/debug/DrawCallCounter.d.ts.map +1 -0
- package/dist/types/debug/ErrorLog.d.ts +20 -0
- package/dist/types/debug/ErrorLog.d.ts.map +1 -0
- package/dist/types/debug/FrameStats.d.ts +21 -0
- package/dist/types/debug/FrameStats.d.ts.map +1 -0
- package/dist/types/debug/inspectWorld.d.ts +14 -0
- package/dist/types/debug/inspectWorld.d.ts.map +1 -0
- package/dist/types/diagnostics/ErrorDeduper.d.ts +17 -0
- package/dist/types/diagnostics/ErrorDeduper.d.ts.map +1 -0
- package/dist/types/diagnostics/FrameSampler.d.ts +37 -0
- package/dist/types/diagnostics/FrameSampler.d.ts.map +1 -0
- package/dist/types/diagnostics/bootWatch.d.ts +25 -0
- package/dist/types/diagnostics/bootWatch.d.ts.map +1 -0
- package/dist/types/diagnostics/captureErrors.d.ts +24 -0
- package/dist/types/diagnostics/captureErrors.d.ts.map +1 -0
- package/dist/types/diagnostics/contextLoss.d.ts +35 -0
- package/dist/types/diagnostics/contextLoss.d.ts.map +1 -0
- package/dist/types/diagnostics/frameStats.d.ts +30 -0
- package/dist/types/diagnostics/frameStats.d.ts.map +1 -0
- package/dist/types/diagnostics/gpuInfo.d.ts +9 -0
- package/dist/types/diagnostics/gpuInfo.d.ts.map +1 -0
- package/dist/types/diagnostics/renderGuard.d.ts +12 -0
- package/dist/types/diagnostics/renderGuard.d.ts.map +1 -0
- package/dist/types/ecs/SparseSet.d.ts +25 -0
- package/dist/types/ecs/SparseSet.d.ts.map +1 -0
- package/dist/types/ecs/World.d.ts +137 -0
- package/dist/types/ecs/World.d.ts.map +1 -0
- package/dist/types/ecs/fields.d.ts +34 -0
- package/dist/types/ecs/fields.d.ts.map +1 -0
- package/dist/types/engine/Engine.d.ts +80 -0
- package/dist/types/engine/Engine.d.ts.map +1 -0
- package/dist/types/engine/FixedLoop.d.ts +32 -0
- package/dist/types/engine/FixedLoop.d.ts.map +1 -0
- package/dist/types/engine/Scene.d.ts +67 -0
- package/dist/types/engine/Scene.d.ts.map +1 -0
- package/dist/types/engine/SceneManager.d.ts +36 -0
- package/dist/types/engine/SceneManager.d.ts.map +1 -0
- package/dist/types/events/EventBus.d.ts +20 -0
- package/dist/types/events/EventBus.d.ts.map +1 -0
- package/dist/types/fx/FloatingText.d.ts +71 -0
- package/dist/types/fx/FloatingText.d.ts.map +1 -0
- package/dist/types/fx/hitStop.d.ts +20 -0
- package/dist/types/fx/hitStop.d.ts.map +1 -0
- package/dist/types/fx/viewCull.d.ts +14 -0
- package/dist/types/fx/viewCull.d.ts.map +1 -0
- package/dist/types/i18n/Translator.d.ts +52 -0
- package/dist/types/i18n/Translator.d.ts.map +1 -0
- package/dist/types/i18n/extractStrings.d.ts +25 -0
- package/dist/types/i18n/extractStrings.d.ts.map +1 -0
- package/dist/types/i18n/formatMessage.d.ts +10 -0
- package/dist/types/i18n/formatMessage.d.ts.map +1 -0
- package/dist/types/index.d.ts +149 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/input/Actions.d.ts +94 -0
- package/dist/types/input/Actions.d.ts.map +1 -0
- package/dist/types/input/AimGesture.d.ts +106 -0
- package/dist/types/input/AimGesture.d.ts.map +1 -0
- package/dist/types/input/Keyboard.d.ts +30 -0
- package/dist/types/input/Keyboard.d.ts.map +1 -0
- package/dist/types/input/Keymap.d.ts +85 -0
- package/dist/types/input/Keymap.d.ts.map +1 -0
- package/dist/types/input/TargetLock.d.ts +56 -0
- package/dist/types/input/TargetLock.d.ts.map +1 -0
- package/dist/types/input/aimAxis.d.ts +9 -0
- package/dist/types/input/aimAxis.d.ts.map +1 -0
- package/dist/types/input/keyChord.d.ts +15 -0
- package/dist/types/input/keyChord.d.ts.map +1 -0
- package/dist/types/input/longPress.d.ts +21 -0
- package/dist/types/input/longPress.d.ts.map +1 -0
- package/dist/types/input/stickAxis.d.ts +26 -0
- package/dist/types/input/stickAxis.d.ts.map +1 -0
- package/dist/types/input/touchDetect.d.ts +18 -0
- package/dist/types/input/touchDetect.d.ts.map +1 -0
- package/dist/types/light/LightLayer.d.ts +65 -0
- package/dist/types/light/LightLayer.d.ts.map +1 -0
- package/dist/types/nav/MinHeap.d.ts +15 -0
- package/dist/types/nav/MinHeap.d.ts.map +1 -0
- package/dist/types/nav/findPath.d.ts +38 -0
- package/dist/types/nav/findPath.d.ts.map +1 -0
- package/dist/types/nav/navGrid.d.ts +48 -0
- package/dist/types/nav/navGrid.d.ts.map +1 -0
- package/dist/types/nav/nearestOpen.d.ts +8 -0
- package/dist/types/nav/nearestOpen.d.ts.map +1 -0
- package/dist/types/nav/straightenPath.d.ts +13 -0
- package/dist/types/nav/straightenPath.d.ts.map +1 -0
- package/dist/types/net/Connection.d.ts +66 -0
- package/dist/types/net/Connection.d.ts.map +1 -0
- package/dist/types/net/InterpolationBuffer.d.ts +36 -0
- package/dist/types/net/InterpolationBuffer.d.ts.map +1 -0
- package/dist/types/net/PredictedMover.d.ts +43 -0
- package/dist/types/net/PredictedMover.d.ts.map +1 -0
- package/dist/types/net/Room.d.ts +69 -0
- package/dist/types/net/Room.d.ts.map +1 -0
- package/dist/types/net/RoomHost.d.ts +74 -0
- package/dist/types/net/RoomHost.d.ts.map +1 -0
- package/dist/types/net/cadence.d.ts +22 -0
- package/dist/types/net/cadence.d.ts.map +1 -0
- package/dist/types/net/constants.d.ts +24 -0
- package/dist/types/net/constants.d.ts.map +1 -0
- package/dist/types/net/lobby/LobbyClient.d.ts +107 -0
- package/dist/types/net/lobby/LobbyClient.d.ts.map +1 -0
- package/dist/types/net/lobby/LobbyHost.d.ts +147 -0
- package/dist/types/net/lobby/LobbyHost.d.ts.map +1 -0
- package/dist/types/net/lobby/LobbyRooms.d.ts +56 -0
- package/dist/types/net/lobby/LobbyRooms.d.ts.map +1 -0
- package/dist/types/net/lobby/Matchmaker.d.ts +57 -0
- package/dist/types/net/lobby/Matchmaker.d.ts.map +1 -0
- package/dist/types/net/lobby/index.d.ts +6 -0
- package/dist/types/net/lobby/index.d.ts.map +1 -0
- package/dist/types/net/lobby/lobbyProtocol.d.ts +143 -0
- package/dist/types/net/lobby/lobbyProtocol.d.ts.map +1 -0
- package/dist/types/net/movement.d.ts +50 -0
- package/dist/types/net/movement.d.ts.map +1 -0
- package/dist/types/net/protocol.d.ts +59 -0
- package/dist/types/net/protocol.d.ts.map +1 -0
- package/dist/types/net/serverClock.d.ts +14 -0
- package/dist/types/net/serverClock.d.ts.map +1 -0
- package/dist/types/net/snapshotCodec.d.ts +55 -0
- package/dist/types/net/snapshotCodec.d.ts.map +1 -0
- package/dist/types/parallax/Parallax.d.ts +37 -0
- package/dist/types/parallax/Parallax.d.ts.map +1 -0
- package/dist/types/parallax/ParallaxLayer.d.ts +80 -0
- package/dist/types/parallax/ParallaxLayer.d.ts.map +1 -0
- package/dist/types/parallax/parallaxMath.d.ts +50 -0
- package/dist/types/parallax/parallaxMath.d.ts.map +1 -0
- package/dist/types/particles/Emitter.d.ts +97 -0
- package/dist/types/particles/Emitter.d.ts.map +1 -0
- package/dist/types/particles/ParticleBudget.d.ts +28 -0
- package/dist/types/particles/ParticleBudget.d.ts.map +1 -0
- package/dist/types/particles/ParticleSim.d.ts +38 -0
- package/dist/types/particles/ParticleSim.d.ts.map +1 -0
- package/dist/types/particles/particleCurves.d.ts +21 -0
- package/dist/types/particles/particleCurves.d.ts.map +1 -0
- package/dist/types/particles/particleSampling.d.ts +20 -0
- package/dist/types/particles/particleSampling.d.ts.map +1 -0
- package/dist/types/physics/Body.d.ts +130 -0
- package/dist/types/physics/Body.d.ts.map +1 -0
- package/dist/types/physics/BroadPhase.d.ts +26 -0
- package/dist/types/physics/BroadPhase.d.ts.map +1 -0
- package/dist/types/physics/Contact.d.ts +62 -0
- package/dist/types/physics/Contact.d.ts.map +1 -0
- package/dist/types/physics/ContactSolver.d.ts +29 -0
- package/dist/types/physics/ContactSolver.d.ts.map +1 -0
- package/dist/types/physics/PhysicsWorld.d.ts +78 -0
- package/dist/types/physics/PhysicsWorld.d.ts.map +1 -0
- package/dist/types/physics/PhysicsWorldOptions.d.ts +24 -0
- package/dist/types/physics/PhysicsWorldOptions.d.ts.map +1 -0
- package/dist/types/physics/SpatialHash.d.ts +23 -0
- package/dist/types/physics/SpatialHash.d.ts.map +1 -0
- package/dist/types/physics/collide.d.ts +27 -0
- package/dist/types/physics/collide.d.ts.map +1 -0
- package/dist/types/physics/collidePolygon.d.ts +14 -0
- package/dist/types/physics/collidePolygon.d.ts.map +1 -0
- package/dist/types/physics/contactReport.d.ts +8 -0
- package/dist/types/physics/contactReport.d.ts.map +1 -0
- package/dist/types/physics/drawColliders.d.ts +43 -0
- package/dist/types/physics/drawColliders.d.ts.map +1 -0
- package/dist/types/physics/physicsSystem.d.ts +5 -0
- package/dist/types/physics/physicsSystem.d.ts.map +1 -0
- package/dist/types/physics/polygon.d.ts +28 -0
- package/dist/types/physics/polygon.d.ts.map +1 -0
- package/dist/types/physics/raycast.d.ts +19 -0
- package/dist/types/physics/raycast.d.ts.map +1 -0
- package/dist/types/physics/syncToBody.d.ts +16 -0
- package/dist/types/physics/syncToBody.d.ts.map +1 -0
- package/dist/types/physics/tileBodies.d.ts +36 -0
- package/dist/types/physics/tileBodies.d.ts.map +1 -0
- package/dist/types/physics/types.d.ts +116 -0
- package/dist/types/physics/types.d.ts.map +1 -0
- package/dist/types/pixel/Darkness.d.ts +78 -0
- package/dist/types/pixel/Darkness.d.ts.map +1 -0
- package/dist/types/pixel/DitherVignette.d.ts +35 -0
- package/dist/types/pixel/DitherVignette.d.ts.map +1 -0
- package/dist/types/pixel/Evaporation.d.ts +30 -0
- package/dist/types/pixel/Evaporation.d.ts.map +1 -0
- package/dist/types/pixel/NightShade.d.ts +38 -0
- package/dist/types/pixel/NightShade.d.ts.map +1 -0
- package/dist/types/pixel/PixelLayer.d.ts +85 -0
- package/dist/types/pixel/PixelLayer.d.ts.map +1 -0
- package/dist/types/pixel/SwayProp.d.ts +52 -0
- package/dist/types/pixel/SwayProp.d.ts.map +1 -0
- package/dist/types/pixel/index.d.ts +31 -0
- package/dist/types/pixel/index.d.ts.map +1 -0
- package/dist/types/pixel/lights.d.ts +34 -0
- package/dist/types/pixel/lights.d.ts.map +1 -0
- package/dist/types/pixel/nineSlice.d.ts +71 -0
- package/dist/types/pixel/nineSlice.d.ts.map +1 -0
- package/dist/types/pixel/paintLayer.d.ts +35 -0
- package/dist/types/pixel/paintLayer.d.ts.map +1 -0
- package/dist/types/pixel/palette.d.ts +58 -0
- package/dist/types/pixel/palette.d.ts.map +1 -0
- package/dist/types/pixel/pixel.d.ts +80 -0
- package/dist/types/pixel/pixel.d.ts.map +1 -0
- package/dist/types/pixel/pixelPaint.d.ts +43 -0
- package/dist/types/pixel/pixelPaint.d.ts.map +1 -0
- package/dist/types/pixel/pixelTone.d.ts +51 -0
- package/dist/types/pixel/pixelTone.d.ts.map +1 -0
- package/dist/types/pixel/propKit.d.ts +26 -0
- package/dist/types/pixel/propKit.d.ts.map +1 -0
- package/dist/types/pixel/ramp.d.ts +57 -0
- package/dist/types/pixel/ramp.d.ts.map +1 -0
- package/dist/types/pixel/selout.d.ts +3 -0
- package/dist/types/pixel/selout.d.ts.map +1 -0
- package/dist/types/pixel/spritePixels.d.ts +29 -0
- package/dist/types/pixel/spritePixels.d.ts.map +1 -0
- package/dist/types/pixel/swayRig.d.ts +72 -0
- package/dist/types/pixel/swayRig.d.ts.map +1 -0
- package/dist/types/pixel/vignetteMask.d.ts +16 -0
- package/dist/types/pixel/vignetteMask.d.ts.map +1 -0
- package/dist/types/pixel/weatherArt.d.ts +29 -0
- package/dist/types/pixel/weatherArt.d.ts.map +1 -0
- package/dist/types/platform/touch.d.ts +10 -0
- package/dist/types/platform/touch.d.ts.map +1 -0
- package/dist/types/postfx/BloomFilter.d.ts +33 -0
- package/dist/types/postfx/BloomFilter.d.ts.map +1 -0
- package/dist/types/postfx/ChromaticAberrationFilter.d.ts +11 -0
- package/dist/types/postfx/ChromaticAberrationFilter.d.ts.map +1 -0
- package/dist/types/postfx/ColorAdjustFilter.d.ts +32 -0
- package/dist/types/postfx/ColorAdjustFilter.d.ts.map +1 -0
- package/dist/types/postfx/CrtFilter.d.ts +16 -0
- package/dist/types/postfx/CrtFilter.d.ts.map +1 -0
- package/dist/types/postfx/PixelateFilter.d.ts +8 -0
- package/dist/types/postfx/PixelateFilter.d.ts.map +1 -0
- package/dist/types/postfx/PostFx.d.ts +92 -0
- package/dist/types/postfx/PostFx.d.ts.map +1 -0
- package/dist/types/postfx/ShockwaveFilter.d.ts +20 -0
- package/dist/types/postfx/ShockwaveFilter.d.ts.map +1 -0
- package/dist/types/postfx/VignetteFilter.d.ts +19 -0
- package/dist/types/postfx/VignetteFilter.d.ts.map +1 -0
- package/dist/types/postfx/fxAnimator.d.ts +32 -0
- package/dist/types/postfx/fxAnimator.d.ts.map +1 -0
- package/dist/types/postfx/fxShader.d.ts +49 -0
- package/dist/types/postfx/fxShader.d.ts.map +1 -0
- package/dist/types/postfx/index.d.ts +11 -0
- package/dist/types/postfx/index.d.ts.map +1 -0
- package/dist/types/react/ChoiceDialog.d.ts +8 -0
- package/dist/types/react/ChoiceDialog.d.ts.map +1 -0
- package/dist/types/react/ConfirmDialog.d.ts +9 -0
- package/dist/types/react/ConfirmDialog.d.ts.map +1 -0
- package/dist/types/react/Glyph.d.ts +54 -0
- package/dist/types/react/Glyph.d.ts.map +1 -0
- package/dist/types/react/Modal.d.ts +22 -0
- package/dist/types/react/Modal.d.ts.map +1 -0
- package/dist/types/react/Panel.d.ts +29 -0
- package/dist/types/react/Panel.d.ts.map +1 -0
- package/dist/types/react/PixelImage.d.ts +19 -0
- package/dist/types/react/PixelImage.d.ts.map +1 -0
- package/dist/types/react/Select.d.ts +27 -0
- package/dist/types/react/Select.d.ts.map +1 -0
- package/dist/types/react/Slider.d.ts +24 -0
- package/dist/types/react/Slider.d.ts.map +1 -0
- package/dist/types/react/SplitPane.d.ts +26 -0
- package/dist/types/react/SplitPane.d.ts.map +1 -0
- package/dist/types/react/TabStrip.d.ts +31 -0
- package/dist/types/react/TabStrip.d.ts.map +1 -0
- package/dist/types/react/TitleTips.d.ts +15 -0
- package/dist/types/react/TitleTips.d.ts.map +1 -0
- package/dist/types/react/Tooltip.d.ts +22 -0
- package/dist/types/react/Tooltip.d.ts.map +1 -0
- package/dist/types/react/UiProvider.d.ts +52 -0
- package/dist/types/react/UiProvider.d.ts.map +1 -0
- package/dist/types/react/baseCss.d.ts +27 -0
- package/dist/types/react/baseCss.d.ts.map +1 -0
- package/dist/types/react/choiceStore.d.ts +34 -0
- package/dist/types/react/choiceStore.d.ts.map +1 -0
- package/dist/types/react/classNames.d.ts +12 -0
- package/dist/types/react/classNames.d.ts.map +1 -0
- package/dist/types/react/confirmStore.d.ts +30 -0
- package/dist/types/react/confirmStore.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +33 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/react/labels.d.ts +24 -0
- package/dist/types/react/labels.d.ts.map +1 -0
- package/dist/types/react/placement.d.ts +59 -0
- package/dist/types/react/placement.d.ts.map +1 -0
- package/dist/types/react/useFillSheet.d.ts +9 -0
- package/dist/types/react/useFillSheet.d.ts.map +1 -0
- package/dist/types/react/useFitToViewport.d.ts +20 -0
- package/dist/types/react/useFitToViewport.d.ts.map +1 -0
- package/dist/types/react/usePicked.d.ts +9 -0
- package/dist/types/react/usePicked.d.ts.map +1 -0
- package/dist/types/react/useStore.d.ts +8 -0
- package/dist/types/react/useStore.d.ts.map +1 -0
- package/dist/types/react/useViewport.d.ts +4 -0
- package/dist/types/react/useViewport.d.ts.map +1 -0
- package/dist/types/rig/PosePlayer.d.ts +64 -0
- package/dist/types/rig/PosePlayer.d.ts.map +1 -0
- package/dist/types/rig/RigView.d.ts +68 -0
- package/dist/types/rig/RigView.d.ts.map +1 -0
- package/dist/types/rig/Skeleton.d.ts +14 -0
- package/dist/types/rig/Skeleton.d.ts.map +1 -0
- package/dist/types/rig/humanoid.d.ts +4 -0
- package/dist/types/rig/humanoid.d.ts.map +1 -0
- package/dist/types/rig/humanoidPoses.d.ts +117 -0
- package/dist/types/rig/humanoidPoses.d.ts.map +1 -0
- package/dist/types/rig/poseMath.d.ts +14 -0
- package/dist/types/rig/poseMath.d.ts.map +1 -0
- package/dist/types/rig/rigTypes.d.ts +82 -0
- package/dist/types/rig/rigTypes.d.ts.map +1 -0
- package/dist/types/save/Autosaver.d.ts +43 -0
- package/dist/types/save/Autosaver.d.ts.map +1 -0
- package/dist/types/save/MemoryBackend.d.ts +10 -0
- package/dist/types/save/MemoryBackend.d.ts.map +1 -0
- package/dist/types/save/SaveBackend.d.ts +14 -0
- package/dist/types/save/SaveBackend.d.ts.map +1 -0
- package/dist/types/save/SaveStore.d.ts +73 -0
- package/dist/types/save/SaveStore.d.ts.map +1 -0
- package/dist/types/save/WebStorageBackend.d.ts +14 -0
- package/dist/types/save/WebStorageBackend.d.ts.map +1 -0
- package/dist/types/save/checksum.d.ts +7 -0
- package/dist/types/save/checksum.d.ts.map +1 -0
- package/dist/types/save/migrateSave.d.ts +17 -0
- package/dist/types/save/migrateSave.d.ts.map +1 -0
- package/dist/types/settings.d.ts +25 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/dist/types/tilemap/TilemapView.d.ts +42 -0
- package/dist/types/tilemap/TilemapView.d.ts.map +1 -0
- package/dist/types/tilemap/collision.d.ts +16 -0
- package/dist/types/tilemap/collision.d.ts.map +1 -0
- package/dist/types/tilemap/tiled.d.ts +104 -0
- package/dist/types/tilemap/tiled.d.ts.map +1 -0
- package/dist/types/transitions/CrossfadeTransition.d.ts +20 -0
- package/dist/types/transitions/CrossfadeTransition.d.ts.map +1 -0
- package/dist/types/transitions/DitherWipeTransition.d.ts +35 -0
- package/dist/types/transitions/DitherWipeTransition.d.ts.map +1 -0
- package/dist/types/transitions/FadeTransition.d.ts +20 -0
- package/dist/types/transitions/FadeTransition.d.ts.map +1 -0
- package/dist/types/transitions/Letterbox.d.ts +33 -0
- package/dist/types/transitions/Letterbox.d.ts.map +1 -0
- package/dist/types/transitions/Transition.d.ts +22 -0
- package/dist/types/transitions/Transition.d.ts.map +1 -0
- package/dist/types/transitions/ditherMask.d.ts +13 -0
- package/dist/types/transitions/ditherMask.d.ts.map +1 -0
- package/dist/types/transitions/transitionTo.d.ts +16 -0
- package/dist/types/transitions/transitionTo.d.ts.map +1 -0
- package/dist/types/transitions/tweenDone.d.ts +5 -0
- package/dist/types/transitions/tweenDone.d.ts.map +1 -0
- package/dist/types/ui/Bar.d.ts +41 -0
- package/dist/types/ui/Bar.d.ts.map +1 -0
- package/dist/types/ui/Button.d.ts +47 -0
- package/dist/types/ui/Button.d.ts.map +1 -0
- package/dist/types/ui/Dialog.d.ts +47 -0
- package/dist/types/ui/Dialog.d.ts.map +1 -0
- package/dist/types/ui/FocusManager.d.ts +53 -0
- package/dist/types/ui/FocusManager.d.ts.map +1 -0
- package/dist/types/ui/Label.d.ts +24 -0
- package/dist/types/ui/Label.d.ts.map +1 -0
- package/dist/types/ui/List.d.ts +23 -0
- package/dist/types/ui/List.d.ts.map +1 -0
- package/dist/types/ui/Panel.d.ts +38 -0
- package/dist/types/ui/Panel.d.ts.map +1 -0
- package/dist/types/ui/ScrollView.d.ts +56 -0
- package/dist/types/ui/ScrollView.d.ts.map +1 -0
- package/dist/types/ui/Slider.d.ts +47 -0
- package/dist/types/ui/Slider.d.ts.map +1 -0
- package/dist/types/ui/Stack.d.ts +16 -0
- package/dist/types/ui/Stack.d.ts.map +1 -0
- package/dist/types/ui/Toggle.d.ts +31 -0
- package/dist/types/ui/Toggle.d.ts.map +1 -0
- package/dist/types/ui/UiHost.d.ts +18 -0
- package/dist/types/ui/UiHost.d.ts.map +1 -0
- package/dist/types/ui/UiPointerGate.d.ts +17 -0
- package/dist/types/ui/UiPointerGate.d.ts.map +1 -0
- package/dist/types/ui/UiRoot.d.ts +73 -0
- package/dist/types/ui/UiRoot.d.ts.map +1 -0
- package/dist/types/ui/Widget.d.ts +56 -0
- package/dist/types/ui/Widget.d.ts.map +1 -0
- package/dist/types/ui/dom/DomOverlay.d.ts +52 -0
- package/dist/types/ui/dom/DomOverlay.d.ts.map +1 -0
- package/dist/types/ui/dom/DomWorldAnchors.d.ts +50 -0
- package/dist/types/ui/dom/DomWorldAnchors.d.ts.map +1 -0
- package/dist/types/ui/dom/InputShield.d.ts +20 -0
- package/dist/types/ui/dom/InputShield.d.ts.map +1 -0
- package/dist/types/ui/dom/createStore.d.ts +22 -0
- package/dist/types/ui/dom/createStore.d.ts.map +1 -0
- package/dist/types/ui/dom/shieldDecision.d.ts +34 -0
- package/dist/types/ui/dom/shieldDecision.d.ts.map +1 -0
- package/dist/types/ui/dom/worldToScreen.d.ts +24 -0
- package/dist/types/ui/dom/worldToScreen.d.ts.map +1 -0
- package/dist/types/ui/index.d.ts +38 -0
- package/dist/types/ui/index.d.ts.map +1 -0
- package/dist/types/ui/layout/anchor.d.ts +9 -0
- package/dist/types/ui/layout/anchor.d.ts.map +1 -0
- package/dist/types/ui/layout/barDrain.d.ts +25 -0
- package/dist/types/ui/layout/barDrain.d.ts.map +1 -0
- package/dist/types/ui/layout/fitToViewport.d.ts +32 -0
- package/dist/types/ui/layout/fitToViewport.d.ts.map +1 -0
- package/dist/types/ui/layout/focusNav.d.ts +13 -0
- package/dist/types/ui/layout/focusNav.d.ts.map +1 -0
- package/dist/types/ui/layout/geometry.d.ts +35 -0
- package/dist/types/ui/layout/geometry.d.ts.map +1 -0
- package/dist/types/ui/layout/listWidth.d.ts +13 -0
- package/dist/types/ui/layout/listWidth.d.ts.map +1 -0
- package/dist/types/ui/layout/placeTooltip.d.ts +23 -0
- package/dist/types/ui/layout/placeTooltip.d.ts.map +1 -0
- package/dist/types/ui/layout/scroll.d.ts +17 -0
- package/dist/types/ui/layout/scroll.d.ts.map +1 -0
- package/dist/types/ui/layout/slider.d.ts +7 -0
- package/dist/types/ui/layout/slider.d.ts.map +1 -0
- package/dist/types/ui/layout/stack.d.ts +26 -0
- package/dist/types/ui/layout/stack.d.ts.map +1 -0
- package/dist/types/ui/layout/wrapRow.d.ts +6 -0
- package/dist/types/ui/layout/wrapRow.d.ts.map +1 -0
- package/dist/ui/Bar.js +54 -0
- package/dist/ui/Bar.js.map +1 -0
- package/dist/ui/Button.js +58 -0
- package/dist/ui/Button.js.map +1 -0
- package/dist/ui/Dialog.js +56 -0
- package/dist/ui/Dialog.js.map +1 -0
- package/dist/ui/FocusManager.js +97 -0
- package/dist/ui/FocusManager.js.map +1 -0
- package/dist/ui/Label.js +36 -0
- package/dist/ui/Label.js.map +1 -0
- package/dist/ui/List.js +45 -0
- package/dist/ui/List.js.map +1 -0
- package/dist/ui/Panel.js +38 -0
- package/dist/ui/Panel.js.map +1 -0
- package/dist/ui/ScrollView.js +96 -0
- package/dist/ui/ScrollView.js.map +1 -0
- package/dist/ui/Slider.js +55 -0
- package/dist/ui/Slider.js.map +1 -0
- package/dist/ui/Stack.js +28 -0
- package/dist/ui/Stack.js.map +1 -0
- package/dist/ui/Toggle.js +37 -0
- package/dist/ui/Toggle.js.map +1 -0
- package/dist/ui/UiHost.js +9 -0
- package/dist/ui/UiHost.js.map +1 -0
- package/dist/ui/UiPointerGate.js +25 -0
- package/dist/ui/UiPointerGate.js.map +1 -0
- package/dist/ui/UiRoot.js +93 -0
- package/dist/ui/UiRoot.js.map +1 -0
- package/dist/ui/Widget.js +90 -0
- package/dist/ui/Widget.js.map +1 -0
- package/dist/ui/dom/DomOverlay.js +59 -0
- package/dist/ui/dom/DomOverlay.js.map +1 -0
- package/dist/ui/dom/DomWorldAnchors.js +59 -0
- package/dist/ui/dom/DomWorldAnchors.js.map +1 -0
- package/dist/ui/dom/InputShield.js +27 -0
- package/dist/ui/dom/InputShield.js.map +1 -0
- package/dist/ui/dom/createStore.js +42 -0
- package/dist/ui/dom/createStore.js.map +1 -0
- package/dist/ui/dom/shieldDecision.js +36 -0
- package/dist/ui/dom/shieldDecision.js.map +1 -0
- package/dist/ui/dom/worldToScreen.js +11 -0
- package/dist/ui/dom/worldToScreen.js.map +1 -0
- package/dist/ui/layout/anchor.js +20 -0
- package/dist/ui/layout/anchor.js.map +1 -0
- package/dist/ui/layout/barDrain.js +25 -0
- package/dist/ui/layout/barDrain.js.map +1 -0
- package/dist/ui/layout/fitToViewport.js +17 -0
- package/dist/ui/layout/fitToViewport.js.map +1 -0
- package/dist/ui/layout/focusNav.js +42 -0
- package/dist/ui/layout/focusNav.js.map +1 -0
- package/dist/ui/layout/geometry.js +21 -0
- package/dist/ui/layout/geometry.js.map +1 -0
- package/dist/ui/layout/listWidth.js +10 -0
- package/dist/ui/layout/listWidth.js.map +1 -0
- package/dist/ui/layout/placeTooltip.js +28 -0
- package/dist/ui/layout/placeTooltip.js.map +1 -0
- package/dist/ui/layout/scroll.js +24 -0
- package/dist/ui/layout/scroll.js.map +1 -0
- package/dist/ui/layout/slider.js +20 -0
- package/dist/ui/layout/slider.js.map +1 -0
- package/dist/ui/layout/stack.js +27 -0
- package/dist/ui/layout/stack.js.map +1 -0
- package/dist/ui/layout/wrapRow.js +13 -0
- package/dist/ui/layout/wrapRow.js.map +1 -0
- package/dist/ui.js +85 -0
- package/dist/ui.js.map +1 -0
- package/package.json +115 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Contact.js","sources":["../../src/physics/Contact.ts"],"sourcesContent":["import type { Body } from './Body';\nimport type { ContactInfo, Vec2 } from './types';\n\n/** One point of a contact and the solver's terms for it. */\nexport class ContactPoint {\n /** World position when measured, and the depth there (px, < 0 a gap). */\n x = 0;\n y = 0;\n depth = 0;\n /** Which corners or faces made it: matched from step to step to carry the impulses over. */\n id = 0;\n /** Accumulated normal and friction impulses. */\n jn = 0;\n jt = 0;\n /** Per sub-step solver terms. */\n massN = 0;\n massT = 0;\n target = 0;\n /** Offsets from each body's centre, refreshed every sub-step. */\n rax = 0;\n ray = 0;\n rbx = 0;\n rby = 0;\n /** The point in each body's own frame when measured, so position correction can track its depth as they move and turn. */\n lax = 0;\n lay = 0;\n lbx = 0;\n lby = 0;\n}\n\n/**\n * One touching pair, kept from step to step while they touch: the impulses it ended the last step with start the\n * next one (warm starting), which is what lets a stack settle in a few solver iterations instead of shivering.\n */\nexport class Contact implements ContactInfo {\n nx = 0;\n ny = 1;\n depth = 0;\n /** One or two points; only the first `count` are in use. */\n readonly pts: [ContactPoint, ContactPoint] = [new ContactPoint(), new ContactPoint()];\n count = 0;\n mu = 0;\n /** Solved this sub-step (false when the pre-solve hook turned it off). */\n enabled = true;\n /** The world step and sub-step that last found it. */\n seenStep = -1;\n seenSub = -1;\n /** Reported as touching (a `begin` went out and no `end` yet). */\n reported = false;\n\n constructor(\n readonly a: Body,\n readonly b: Body,\n readonly key: number,\n ) {}\n\n get sensor(): boolean {\n return this.a.sensor || this.b.sensor;\n }\n\n /** Where the two touch, world px. */\n get points(): Vec2[] {\n const out: Vec2[] = [];\n for (let i = 0; i < this.count; i++) out.push({ x: this.pts[i]!.x, y: this.pts[i]!.y });\n return out;\n }\n\n /** Accumulated normal impulse over the points: how hard the pair pressed together on the last sub-step. */\n get normalImpulse(): number {\n let j = 0;\n for (let i = 0; i < this.count; i++) j += this.pts[i]!.jn;\n return j;\n }\n\n /** The other body of the pair. */\n other(body: Body): Body {\n return body === this.a ? this.b : this.a;\n }\n\n /** A stable number for the pair, whichever order it is asked in. */\n static keyOf(a: Body, b: Body): number {\n const lo = a.id < b.id ? a.id : b.id;\n const hi = a.id < b.id ? b.id : a.id;\n return lo * 0x4000000 + hi;\n }\n}\n"],"names":["ContactPoint","Contact","a","b","key","out","i","j","body","lo","hi"],"mappings":"AAIO,MAAMA,EAAa;AAAA;AAAA,EAExB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,QAAQ;AAAA;AAAA,EAER,KAAK;AAAA;AAAA,EAEL,KAAK;AAAA,EACL,KAAK;AAAA;AAAA,EAEL,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA;AAAA,EAET,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA;AAAA,EAEN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAMO,MAAMC,EAA+B;AAAA,EAgB1C,YACWC,GACAC,GACAC,GACT;AAHS,SAAA,IAAAF,GACA,KAAA,IAAAC,GACA,KAAA,MAAAC;AAAA,EACR;AAAA,EAHQ;AAAA,EACA;AAAA,EACA;AAAA,EAlBX,KAAK;AAAA,EACL,KAAK;AAAA,EACL,QAAQ;AAAA;AAAA,EAEC,MAAoC,CAAC,IAAIJ,KAAgB,IAAIA,GAAc;AAAA,EACpF,QAAQ;AAAA,EACR,KAAK;AAAA;AAAA,EAEL,UAAU;AAAA;AAAA,EAEV,WAAW;AAAA,EACX,UAAU;AAAA;AAAA,EAEV,WAAW;AAAA,EAQX,IAAI,SAAkB;AACpB,WAAO,KAAK,EAAE,UAAU,KAAK,EAAE;AAAA,EACjC;AAAA;AAAA,EAGA,IAAI,SAAiB;AACnB,UAAMK,IAAc,CAAA;AACpB,aAASC,IAAI,GAAGA,IAAI,KAAK,OAAOA,IAAK,CAAAD,EAAI,KAAK,EAAE,GAAG,KAAK,IAAIC,CAAC,EAAG,GAAG,GAAG,KAAK,IAAIA,CAAC,EAAG,GAAG;AACtF,WAAOD;AAAA,EACT;AAAA;AAAA,EAGA,IAAI,gBAAwB;AAC1B,QAAIE,IAAI;AACR,aAASD,IAAI,GAAGA,IAAI,KAAK,OAAOA,IAAK,CAAAC,KAAK,KAAK,IAAID,CAAC,EAAG;AACvD,WAAOC;AAAA,EACT;AAAA;AAAA,EAGA,MAAMC,GAAkB;AACtB,WAAOA,MAAS,KAAK,IAAI,KAAK,IAAI,KAAK;AAAA,EACzC;AAAA;AAAA,EAGA,OAAO,MAAMN,GAASC,GAAiB;AACrC,UAAMM,IAAKP,EAAE,KAAKC,EAAE,KAAKD,EAAE,KAAKC,EAAE,IAC5BO,IAAKR,EAAE,KAAKC,EAAE,KAAKA,EAAE,KAAKD,EAAE;AAClC,WAAOO,IAAK,WAAYC;AAAA,EAC1B;AACF;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const g = (l, e, s, i) => l * i - e * s, N = (l) => l.awake ? l.invInertia : 0;
|
|
2
|
+
class z {
|
|
3
|
+
constructor(e) {
|
|
4
|
+
this.settings = e;
|
|
5
|
+
}
|
|
6
|
+
settings;
|
|
7
|
+
/** Mass, friction and the velocity target of every enabled contact point; then the impulses carried over from the last sub-step are applied (warm start). */
|
|
8
|
+
prepare(e, s) {
|
|
9
|
+
const { restitutionThreshold: i } = this.settings;
|
|
10
|
+
for (const c of e) {
|
|
11
|
+
if (!c.enabled) continue;
|
|
12
|
+
const a = c.a, n = c.b, r = a.solverInvMass, y = n.solverInvMass, f = N(a), h = N(n);
|
|
13
|
+
c.mu = Math.sqrt(a.friction * n.friction);
|
|
14
|
+
const u = c.nx, x = c.ny, b = -x, o = u, v = Math.max(a.restitution, n.restitution);
|
|
15
|
+
for (let M = 0; M < c.count; M++) {
|
|
16
|
+
const t = c.pts[M];
|
|
17
|
+
t.rax = t.x - a.x, t.ray = t.y - a.y, t.rbx = t.x - n.x, t.rby = t.y - n.y;
|
|
18
|
+
const d = g(t.rax, t.ray, u, x), I = g(t.rbx, t.rby, u, x), m = r + y + f * d * d + h * I * I;
|
|
19
|
+
t.massN = m > 0 ? 1 / m : 0;
|
|
20
|
+
const j = g(t.rax, t.ray, b, o), p = g(t.rbx, t.rby, b, o), V = r + y + f * j * j + h * p * p;
|
|
21
|
+
t.massT = V > 0 ? 1 / V : 0;
|
|
22
|
+
const T = A(a, n, t) * u + B(a, n, t) * x;
|
|
23
|
+
t.depth < 0 ? t.target = t.depth / s : t.target = T < -i ? -v * T : 0, C(a, n, t, t.jn * u + t.jt * b, t.jn * x + t.jt * o, r, y, f, h);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
solveVelocities(e) {
|
|
28
|
+
for (const s of e) {
|
|
29
|
+
if (!s.enabled) continue;
|
|
30
|
+
const i = s.a, c = s.b, a = i.solverInvMass, n = c.solverInvMass, r = N(i), y = N(c), f = s.nx, h = s.ny, u = -h, x = f;
|
|
31
|
+
for (let b = 0; b < s.count; b++) {
|
|
32
|
+
const o = s.pts[b];
|
|
33
|
+
if (o.massN === 0) continue;
|
|
34
|
+
const v = A(i, c, o) * u + B(i, c, o) * x, M = s.mu * o.jn, t = Math.max(-M, Math.min(M, o.jt - v * o.massT)), d = t - o.jt;
|
|
35
|
+
o.jt = t, C(i, c, o, d * u, d * x, a, n, r, y);
|
|
36
|
+
const I = A(i, c, o) * f + B(i, c, o) * h, m = Math.max(0, o.jn + (o.target - I) * o.massN), j = m - o.jn;
|
|
37
|
+
o.jn = m, C(i, c, o, j * f, j * h, a, n, r, y);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Pushes overlapping pairs apart along their normals, by position (and angle) only. */
|
|
42
|
+
solvePositions(e) {
|
|
43
|
+
const { slop: s, correction: i, maxCorrection: c } = this.settings;
|
|
44
|
+
for (const a of e) {
|
|
45
|
+
if (!a.enabled) continue;
|
|
46
|
+
const n = a.a, r = a.b, y = n.solverInvMass, f = r.solverInvMass, h = N(n), u = N(r), x = a.nx, b = a.ny;
|
|
47
|
+
for (let o = 0; o < a.count; o++) {
|
|
48
|
+
const v = a.pts[o], M = n.rotates ? Math.cos(n.angle) : n.cos, t = n.rotates ? Math.sin(n.angle) : n.sin, d = r.rotates ? Math.cos(r.angle) : r.cos, I = r.rotates ? Math.sin(r.angle) : r.sin, m = M * v.lax - t * v.lay, j = t * v.lax + M * v.lay, p = d * v.lbx - I * v.lby, V = I * v.lbx + d * v.lby, T = (r.x + p - (n.x + m)) * x + (r.y + V - (n.y + j)) * b, q = v.depth - T;
|
|
49
|
+
if (q <= s) continue;
|
|
50
|
+
const P = g(m, j, x, b), S = g(p, V, x, b), X = y + f + h * P * P + u * S * S;
|
|
51
|
+
if (X === 0) continue;
|
|
52
|
+
const Y = Math.min(c, i * (q - s)) / X, k = Y * x, w = Y * b;
|
|
53
|
+
n.x -= k * y, n.y -= w * y, r.x += k * f, r.y += w * f, h > 0 && (n.angle -= h * g(m, j, k, w)), u > 0 && (r.angle += u * g(p, V, k, w));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function A(l, e, s) {
|
|
59
|
+
return e.vx - e.angularVelocity * s.rby - (l.vx - l.angularVelocity * s.ray);
|
|
60
|
+
}
|
|
61
|
+
function B(l, e, s) {
|
|
62
|
+
return e.vy + e.angularVelocity * s.rbx - (l.vy + l.angularVelocity * s.rax);
|
|
63
|
+
}
|
|
64
|
+
function C(l, e, s, i, c, a, n, r, y) {
|
|
65
|
+
l.vx -= i * a, l.vy -= c * a, e.vx += i * n, e.vy += c * n, r > 0 && (l.angularVelocity -= r * g(s.rax, s.ray, i, c)), y > 0 && (e.angularVelocity += y * g(s.rbx, s.rby, i, c));
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
z as ContactSolver
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=ContactSolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContactSolver.js","sources":["../../src/physics/ContactSolver.ts"],"sourcesContent":["import type { Body } from './Body';\nimport type { Contact, ContactPoint } from './Contact';\n\n/** Tuning the solver reads; `PhysicsWorld` owns the values. */\nexport interface SolverSettings {\n /** Approach speed (px/s) below which nothing bounces, so a resting body does not hop on gravity's own step. */\n restitutionThreshold: number;\n /** Overlap (px) left alone by position correction: a little keeps resting contacts alive and steady. */\n slop: number;\n /** Share of the remaining overlap removed per position iteration. */\n correction: number;\n /** The most one position iteration moves a pair apart (px), so a deep overlap is undone over a few steps, not flung. */\n maxCorrection: number;\n}\n\nconst cross = (ax: number, ay: number, bx: number, by: number): number => ax * by - ay * bx;\n\n/** Angular inverse mass as the solver sees it: a sleeping body holds still like ground. */\nconst solverInvInertia = (b: Body): number => (b.awake ? b.invInertia : 0);\n\n/**\n * Sequential impulses: each contact point is a normal constraint (no approach, plus bounce) and a friction constraint\n * clamped by its normal impulse (Coulomb), applied at the point so a body that rotates is turned by it. Penetration\n * is not fed back into the velocities (no Baumgarte energy): it is removed afterwards by moving positions and angles\n * only, tracked as the bodies move (a \"split impulse\" in its simplest form), so resting bodies do not bounce off their\n * own correction. Bodies that do not rotate have no inverse inertia, and every angular term drops out.\n */\nexport class ContactSolver {\n constructor(private readonly settings: SolverSettings) {}\n\n /** Mass, friction and the velocity target of every enabled contact point; then the impulses carried over from the last sub-step are applied (warm start). */\n prepare(contacts: readonly Contact[], dt: number): void {\n const { restitutionThreshold } = this.settings;\n for (const c of contacts) {\n if (!c.enabled) continue;\n const a = c.a;\n const b = c.b;\n const ia = a.solverInvMass;\n const ib = b.solverInvMass;\n const iia = solverInvInertia(a);\n const iib = solverInvInertia(b);\n c.mu = Math.sqrt(a.friction * b.friction);\n const nx = c.nx;\n const ny = c.ny;\n const tx = -ny;\n const ty = nx;\n const e = Math.max(a.restitution, b.restitution);\n for (let i = 0; i < c.count; i++) {\n const p = c.pts[i]!;\n p.rax = p.x - a.x;\n p.ray = p.y - a.y;\n p.rbx = p.x - b.x;\n p.rby = p.y - b.y;\n const rnA = cross(p.rax, p.ray, nx, ny);\n const rnB = cross(p.rbx, p.rby, nx, ny);\n const kn = ia + ib + iia * rnA * rnA + iib * rnB * rnB;\n p.massN = kn > 0 ? 1 / kn : 0;\n const rtA = cross(p.rax, p.ray, tx, ty);\n const rtB = cross(p.rbx, p.rby, tx, ty);\n const kt = ia + ib + iia * rtA * rtA + iib * rtB * rtB;\n p.massT = kt > 0 ? 1 / kt : 0;\n const vn = relX(a, b, p) * nx + relY(a, b, p) * ny;\n if (p.depth < 0) {\n // still a hair apart: let them close the gap this sub-step, no more (a speculative contact)\n p.target = p.depth / dt;\n } else {\n p.target = vn < -restitutionThreshold ? -e * vn : 0;\n }\n apply(a, b, p, p.jn * nx + p.jt * tx, p.jn * ny + p.jt * ty, ia, ib, iia, iib);\n }\n }\n }\n\n solveVelocities(contacts: readonly Contact[]): void {\n for (const c of contacts) {\n if (!c.enabled) continue;\n const a = c.a;\n const b = c.b;\n const ia = a.solverInvMass;\n const ib = b.solverInvMass;\n const iia = solverInvInertia(a);\n const iib = solverInvInertia(b);\n const nx = c.nx;\n const ny = c.ny;\n const tx = -ny;\n const ty = nx;\n for (let i = 0; i < c.count; i++) {\n const p = c.pts[i]!;\n if (p.massN === 0) continue;\n // friction first, bounded by the normal impulse of the last iteration\n const vt = relX(a, b, p) * tx + relY(a, b, p) * ty;\n const maxT = c.mu * p.jn;\n const jtNew = Math.max(-maxT, Math.min(maxT, p.jt - vt * p.massT));\n const dT = jtNew - p.jt;\n p.jt = jtNew;\n apply(a, b, p, dT * tx, dT * ty, ia, ib, iia, iib);\n\n const vn = relX(a, b, p) * nx + relY(a, b, p) * ny;\n const jnNew = Math.max(0, p.jn + (p.target - vn) * p.massN);\n const dn = jnNew - p.jn;\n p.jn = jnNew;\n apply(a, b, p, dn * nx, dn * ny, ia, ib, iia, iib);\n }\n }\n }\n\n /** Pushes overlapping pairs apart along their normals, by position (and angle) only. */\n solvePositions(contacts: readonly Contact[]): void {\n const { slop, correction, maxCorrection } = this.settings;\n for (const c of contacts) {\n if (!c.enabled) continue;\n const a = c.a;\n const b = c.b;\n const ia = a.solverInvMass;\n const ib = b.solverInvMass;\n const iia = solverInvInertia(a);\n const iib = solverInvInertia(b);\n const nx = c.nx;\n const ny = c.ny;\n for (let i = 0; i < c.count; i++) {\n const p = c.pts[i]!;\n // where the point's two anchors are now: their drift apart along the normal is what the depth has lost\n const ca = a.rotates ? Math.cos(a.angle) : a.cos;\n const sa = a.rotates ? Math.sin(a.angle) : a.sin;\n const cb = b.rotates ? Math.cos(b.angle) : b.cos;\n const sb = b.rotates ? Math.sin(b.angle) : b.sin;\n const rax = ca * p.lax - sa * p.lay;\n const ray = sa * p.lax + ca * p.lay;\n const rbx = cb * p.lbx - sb * p.lby;\n const rby = sb * p.lbx + cb * p.lby;\n const moved = (b.x + rbx - (a.x + rax)) * nx + (b.y + rby - (a.y + ray)) * ny;\n const depth = p.depth - moved;\n if (depth <= slop) continue;\n const rnA = cross(rax, ray, nx, ny);\n const rnB = cross(rbx, rby, nx, ny);\n const k = ia + ib + iia * rnA * rnA + iib * rnB * rnB;\n if (k === 0) continue;\n const push = Math.min(maxCorrection, correction * (depth - slop)) / k;\n const px = push * nx;\n const py = push * ny;\n a.x -= px * ia;\n a.y -= py * ia;\n b.x += px * ib;\n b.y += py * ib;\n if (iia > 0) a.angle -= iia * cross(rax, ray, px, py);\n if (iib > 0) b.angle += iib * cross(rbx, rby, px, py);\n }\n }\n }\n}\n\n/** Velocity of b's material at the point less a's. */\nfunction relX(a: Body, b: Body, p: ContactPoint): number {\n return b.vx - b.angularVelocity * p.rby - (a.vx - a.angularVelocity * p.ray);\n}\n\nfunction relY(a: Body, b: Body, p: ContactPoint): number {\n return b.vy + b.angularVelocity * p.rbx - (a.vy + a.angularVelocity * p.rax);\n}\n\n/** Impulse (px, py) on b at the point, its opposite on a. */\nfunction apply(a: Body, b: Body, p: ContactPoint, px: number, py: number, ia: number, ib: number, iia: number, iib: number): void {\n a.vx -= px * ia;\n a.vy -= py * ia;\n b.vx += px * ib;\n b.vy += py * ib;\n if (iia > 0) a.angularVelocity -= iia * cross(p.rax, p.ray, px, py);\n if (iib > 0) b.angularVelocity += iib * cross(p.rbx, p.rby, px, py);\n}\n"],"names":["cross","ax","ay","bx","by","solverInvInertia","b","ContactSolver","settings","contacts","dt","restitutionThreshold","ia","ib","iia","iib","nx","ny","tx","ty","e","i","p","rnA","rnB","kn","rtA","rtB","kt","vn","relX","relY","apply","c","a","vt","maxT","jtNew","dT","jnNew","dn","slop","correction","maxCorrection","ca","sa","cb","sb","rax","ray","rbx","rby","moved","depth","k","push","px","py"],"mappings":"AAeA,MAAMA,IAAQ,CAACC,GAAYC,GAAYC,GAAYC,MAAuBH,IAAKG,IAAKF,IAAKC,GAGnFE,IAAmB,CAACC,MAAqBA,EAAE,QAAQA,EAAE,aAAa;AASjE,MAAMC,EAAc;AAAA,EACzB,YAA6BC,GAA0B;AAA1B,SAAA,WAAAA;AAAA,EAA2B;AAAA,EAA3B;AAAA;AAAA,EAG7B,QAAQC,GAA8BC,GAAkB;AACtD,UAAM,EAAE,sBAAAC,MAAyB,KAAK;AACtC,eAAW,KAAKF,GAAU;AACxB,UAAI,CAAC,EAAE,QAAS;AAChB,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AK5C,GACTC,IAAM,MAAGoB,EAAE,mBAAmBpB,IAAMd,EAAMsB,EAAE,KAAKA,EAAE,KAAKkC,GAAIC,CAAE,IAC9D1C,IAAM,MAAGT,EAAE,mBAAmBS,IAAMf,EAAMsB,EAAE,KAAKA,EAAE,KAAKkC,GAAIC,CAAE;AACpE;"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { EventBus as k } from "../events/EventBus.js";
|
|
2
|
+
import { Body as x } from "./Body.js";
|
|
3
|
+
import { BroadPhase as M } from "./BroadPhase.js";
|
|
4
|
+
import { emptyManifold as w, collide as C } from "./collide.js";
|
|
5
|
+
import { Contact as b } from "./Contact.js";
|
|
6
|
+
import { ContactSolver as I } from "./ContactSolver.js";
|
|
7
|
+
import { info as p, setGround as S } from "./contactReport.js";
|
|
8
|
+
import { castRay as j } from "./raycast.js";
|
|
9
|
+
class O {
|
|
10
|
+
gravityX;
|
|
11
|
+
gravityY;
|
|
12
|
+
events = new k();
|
|
13
|
+
/** Called for each touching solid pair every sub-step; returning false skips its response this sub-step (one-way platforms). */
|
|
14
|
+
preSolve = null;
|
|
15
|
+
list = [];
|
|
16
|
+
broad;
|
|
17
|
+
solver;
|
|
18
|
+
contacts = /* @__PURE__ */ new Map();
|
|
19
|
+
active = [];
|
|
20
|
+
manifold = w();
|
|
21
|
+
removals = [];
|
|
22
|
+
settings;
|
|
23
|
+
velocityIterations;
|
|
24
|
+
positionIterations;
|
|
25
|
+
maxSubsteps;
|
|
26
|
+
maxSpeed;
|
|
27
|
+
margin;
|
|
28
|
+
groundNormal;
|
|
29
|
+
allowSleep;
|
|
30
|
+
sleepSpeed;
|
|
31
|
+
sleepTime;
|
|
32
|
+
stepCount = 0;
|
|
33
|
+
subCount = 0;
|
|
34
|
+
stepping = !1;
|
|
35
|
+
constructor(e = {}) {
|
|
36
|
+
this.gravityX = e.gravityX ?? 0, this.gravityY = e.gravityY ?? 980, this.margin = e.contactMargin ?? 0.5, this.settings = {
|
|
37
|
+
restitutionThreshold: e.restitutionThreshold ?? 40,
|
|
38
|
+
slop: e.slop ?? 0.05,
|
|
39
|
+
correction: e.correction ?? 0.4,
|
|
40
|
+
maxCorrection: e.maxCorrection ?? 4
|
|
41
|
+
}, this.solver = new I(this.settings), this.broad = new M(e.cellSize ?? 64, this.margin), this.velocityIterations = e.velocityIterations ?? 8, this.positionIterations = e.positionIterations ?? 3, this.maxSubsteps = Math.max(1, e.maxSubsteps ?? 16), this.maxSpeed = e.maxSpeed ?? 4e3, this.groundNormal = e.groundNormal ?? 0.7, this.allowSleep = e.allowSleep ?? !1, this.sleepSpeed = e.sleepSpeed ?? 4, this.sleepTime = e.sleepTime ?? 0.5;
|
|
42
|
+
}
|
|
43
|
+
/** Adds a body (or makes one from options) and returns it. */
|
|
44
|
+
add(e) {
|
|
45
|
+
const i = e instanceof x ? e : new x(e);
|
|
46
|
+
return i.inWorld || (i.inWorld = !0, i.updateBounds(), i.wake(), this.list.push(i), i.isStatic && this.broad.markStaticsDirty()), i;
|
|
47
|
+
}
|
|
48
|
+
addAll(e) {
|
|
49
|
+
for (const i of e) this.add(i);
|
|
50
|
+
}
|
|
51
|
+
/** Takes a body out; its contacts end (with `end` events). During a step it waits until the step is over. */
|
|
52
|
+
remove(e) {
|
|
53
|
+
if (!e.inWorld) return;
|
|
54
|
+
if (this.stepping) {
|
|
55
|
+
this.removals.push(e);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
e.inWorld = !1;
|
|
59
|
+
const i = this.list.indexOf(e);
|
|
60
|
+
i >= 0 && this.list.splice(i, 1), e.isStatic && this.broad.markStaticsDirty(), e.grounded = !1, e.ground = null;
|
|
61
|
+
const t = [];
|
|
62
|
+
for (const [n, s] of this.contacts)
|
|
63
|
+
s.a !== e && s.b !== e || (s.other(e).wake(), s.reported && t.push(p(s)), this.contacts.delete(n));
|
|
64
|
+
for (const n of t) this.events.emit("end", n);
|
|
65
|
+
}
|
|
66
|
+
/** Call after moving, resizing or retyping a static body by hand. */
|
|
67
|
+
staticsChanged() {
|
|
68
|
+
this.broad.markStaticsDirty();
|
|
69
|
+
}
|
|
70
|
+
get bodyCount() {
|
|
71
|
+
return this.list.length;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Every body in the world, in the order added: for tools (a debug drawing, an inspector) that would otherwise keep
|
|
75
|
+
* a second list beside the world's. Read it, never hold it across a step: adding and removing change it in place.
|
|
76
|
+
*/
|
|
77
|
+
get bodies() {
|
|
78
|
+
return this.list;
|
|
79
|
+
}
|
|
80
|
+
/** Advances the world by `dt` seconds; call it with the fixed step (`FixedLoop.stepSeconds`). */
|
|
81
|
+
step(e) {
|
|
82
|
+
if (!(!(e > 0) || !Number.isFinite(e))) {
|
|
83
|
+
this.stepping = !0;
|
|
84
|
+
try {
|
|
85
|
+
this.stepCount++;
|
|
86
|
+
for (const t of this.list)
|
|
87
|
+
t.prevX = t.x, t.prevY = t.y, t.prevAngle = t.angle;
|
|
88
|
+
const i = this.substepsFor(e);
|
|
89
|
+
for (let t = 0; t < i; t++) this.substep(e / i);
|
|
90
|
+
for (const t of this.list)
|
|
91
|
+
t.fx = 0, t.fy = 0, t.torque = 0;
|
|
92
|
+
this.allowSleep && this.updateSleep(e);
|
|
93
|
+
} finally {
|
|
94
|
+
this.stepping = !1;
|
|
95
|
+
}
|
|
96
|
+
this.finishContacts();
|
|
97
|
+
for (const i of this.removals.splice(0)) this.remove(i);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** The first body on the segment from (x0, y0) to (x1, y1). Bodies the ray starts inside are skipped. */
|
|
101
|
+
raycast(e, i, t, n, s) {
|
|
102
|
+
for (const r of this.list) r.isStatic || r.updateBounds();
|
|
103
|
+
return this.broad.rebuild(this.list), j([this.broad.statics, this.broad.movers], e, i, t, n, s);
|
|
104
|
+
}
|
|
105
|
+
/** The pairs touching `body` after the last step (sensors' overlaps included). */
|
|
106
|
+
contactsOf(e, i = []) {
|
|
107
|
+
i.length = 0;
|
|
108
|
+
for (const t of this.contacts.values()) t.reported && (t.a === e || t.b === e) && i.push(t);
|
|
109
|
+
return i;
|
|
110
|
+
}
|
|
111
|
+
/** Whether `body` stood on something at the end of the last step (also `body.grounded`). */
|
|
112
|
+
isGrounded(e) {
|
|
113
|
+
return e.grounded;
|
|
114
|
+
}
|
|
115
|
+
substepsFor(e) {
|
|
116
|
+
const i = this.gravityX, t = this.gravityY;
|
|
117
|
+
let n = 0;
|
|
118
|
+
for (const s of this.list) {
|
|
119
|
+
if (!s.moving) continue;
|
|
120
|
+
const r = s.isDynamic ? Math.hypot(i, t) * Math.abs(s.gravityScale) * e : 0, l = Math.min(this.maxSpeed, Math.hypot(s.vx, s.vy) + r + Math.abs(s.angularVelocity) * s.maxExtent);
|
|
121
|
+
n = Math.max(n, l * e / Math.max(0.5, s.minHalfExtent));
|
|
122
|
+
}
|
|
123
|
+
return Math.min(this.maxSubsteps, Math.max(1, Math.ceil(n)));
|
|
124
|
+
}
|
|
125
|
+
substep(e) {
|
|
126
|
+
this.subCount++;
|
|
127
|
+
const i = this.maxSpeed * this.maxSpeed;
|
|
128
|
+
for (const t of this.list) {
|
|
129
|
+
if (!t.isDynamic || !t.awake) continue;
|
|
130
|
+
if (t.vx += (this.gravityX * t.gravityScale + t.fx * t.invMass) * e, t.vy += (this.gravityY * t.gravityScale + t.fy * t.invMass) * e, t.linearDamping > 0) {
|
|
131
|
+
const s = 1 / (1 + t.linearDamping * e);
|
|
132
|
+
t.vx *= s, t.vy *= s;
|
|
133
|
+
}
|
|
134
|
+
const n = t.vx * t.vx + t.vy * t.vy;
|
|
135
|
+
if (n > i) {
|
|
136
|
+
const s = this.maxSpeed / Math.sqrt(n);
|
|
137
|
+
t.vx *= s, t.vy *= s;
|
|
138
|
+
}
|
|
139
|
+
if (t.invInertia > 0) {
|
|
140
|
+
t.angularVelocity += t.torque * t.invInertia * e, t.angularDamping > 0 && (t.angularVelocity /= 1 + t.angularDamping * e);
|
|
141
|
+
const s = this.maxSpeed / Math.max(1, t.maxExtent);
|
|
142
|
+
Math.abs(t.angularVelocity) > s && (t.angularVelocity = Math.sign(t.angularVelocity) * s);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
this.broad.rebuild(this.list), this.active.length = 0, this.broad.pairs(this.list, this.visitPair), this.solver.prepare(this.active, e);
|
|
146
|
+
for (let t = 0; t < this.velocityIterations; t++) this.solver.solveVelocities(this.active);
|
|
147
|
+
for (const t of this.list)
|
|
148
|
+
t.moving && (t.x += t.vx * e, t.y += t.vy * e, t.rotates && (t.angle += t.angularVelocity * e));
|
|
149
|
+
for (let t = 0; t < this.positionIterations; t++) this.solver.solvePositions(this.active);
|
|
150
|
+
for (const t of this.list) t.moving && t.updateBounds();
|
|
151
|
+
}
|
|
152
|
+
visitPair = (e, i) => {
|
|
153
|
+
if (!(e.layer & i.mask) || !(i.layer & e.mask)) return;
|
|
154
|
+
const t = e.sensor || i.sensor;
|
|
155
|
+
if (e.invMass === 0 && i.invMass === 0 && !t) return;
|
|
156
|
+
const n = e.id < i.id ? e : i, s = n === e ? i : e, r = this.manifold;
|
|
157
|
+
if (!C(n, s, t ? 0 : this.margin, r) || t && r.depth <= 0) return;
|
|
158
|
+
const l = b.keyOf(n, s);
|
|
159
|
+
let o = this.contacts.get(l);
|
|
160
|
+
if (o || (o = new b(n, s, l), this.contacts.set(l, o)), this.takeManifold(o, r, o.seenSub === this.subCount - 1), o.seenSub = this.subCount, o.seenStep = this.stepCount, t) {
|
|
161
|
+
o.enabled = !1;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
n.awake !== s.awake && this.wakeOnImpact(n, s), o.enabled = this.preSolve ? this.preSolve(o) !== !1 : !0, o.enabled && this.active.push(o);
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Copies the narrow phase's points into the contact, carrying each point's impulses over from the last sub-step
|
|
168
|
+
* when the same feature touches again (`warm`: the pair touched on the last sub-step).
|
|
169
|
+
*/
|
|
170
|
+
takeManifold(e, i, t) {
|
|
171
|
+
const n = e.a, s = e.b;
|
|
172
|
+
let r = 0, l = 0, o = 0, d = 0, f = -1, u = -1;
|
|
173
|
+
t && (e.count > 0 && (f = e.pts[0].id, r = e.pts[0].jn, l = e.pts[0].jt), e.count > 1 && (u = e.pts[1].id, o = e.pts[1].jn, d = e.pts[1].jt)), e.nx = i.nx, e.ny = i.ny, e.depth = i.depth, e.count = i.count;
|
|
174
|
+
for (let c = 0; c < i.count; c++) {
|
|
175
|
+
const a = e.pts[c], h = i.id[c];
|
|
176
|
+
a.x = i.px[c], a.y = i.py[c], a.depth = i.pd[c], a.id = h, a.jn = h === f ? r : h === u ? o : 0, a.jt = h === f ? l : h === u ? d : 0;
|
|
177
|
+
const v = a.x - n.x, m = a.y - n.y;
|
|
178
|
+
a.lax = n.cos * v + n.sin * m, a.lay = -n.sin * v + n.cos * m;
|
|
179
|
+
const g = a.x - s.x, y = a.y - s.y;
|
|
180
|
+
a.lbx = s.cos * g + s.sin * y, a.lby = -s.sin * g + s.cos * y;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** A sleeping body wakes when something meets it faster than the sleep speed (a kinematic platform always does). */
|
|
184
|
+
wakeOnImpact(e, i) {
|
|
185
|
+
const t = e.awake ? i : e, n = e.awake ? e : i;
|
|
186
|
+
if (t.isStatic) return;
|
|
187
|
+
const s = Math.hypot(n.vx - t.vx, n.vy - t.vy);
|
|
188
|
+
(n.type === "kinematic" || s > this.sleepSpeed) && t.wake();
|
|
189
|
+
}
|
|
190
|
+
updateSleep(e) {
|
|
191
|
+
const i = this.sleepSpeed * this.sleepSpeed;
|
|
192
|
+
for (const t of this.list) {
|
|
193
|
+
if (!t.isDynamic || !t.awake) continue;
|
|
194
|
+
const n = t.angularVelocity * t.maxExtent;
|
|
195
|
+
if (t.vx * t.vx + t.vy * t.vy + n * n > i || t.fx !== 0 || t.fy !== 0 || t.torque !== 0) {
|
|
196
|
+
t.restTime = 0;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
t.restTime += e, t.restTime >= this.sleepTime && (t.awake = !1, t.vx = 0, t.vy = 0, t.angularVelocity = 0);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** Ends pairs no longer touching, starts new ones, refreshes `grounded`, then emits the events. */
|
|
203
|
+
finishContacts() {
|
|
204
|
+
for (const n of this.list)
|
|
205
|
+
n.grounded = !1, n.ground = null;
|
|
206
|
+
const e = [], i = [], t = this.groundNormal;
|
|
207
|
+
for (const [n, s] of this.contacts) {
|
|
208
|
+
if (!(s.seenStep === this.stepCount || s.reported && !s.a.moving && !s.b.moving)) {
|
|
209
|
+
s.reported && i.push(p(s)), this.contacts.delete(n);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
s.reported || (s.reported = !0, e.push(p(s))), !(s.sensor || !s.enabled) && (s.ny < -t ? S(s.b, s.a, s) : s.ny > t && S(s.a, s.b, s));
|
|
213
|
+
}
|
|
214
|
+
for (const n of i) this.events.emit("end", n);
|
|
215
|
+
for (const n of e) this.events.emit("begin", n);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
export {
|
|
219
|
+
O as PhysicsWorld
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=PhysicsWorld.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhysicsWorld.js","sources":["../../src/physics/PhysicsWorld.ts"],"sourcesContent":["import { EventBus } from '../events/EventBus';\nimport { Body } from './Body';\nimport { BroadPhase } from './BroadPhase';\nimport { collide, emptyManifold, type Manifold } from './collide';\nimport { Contact } from './Contact';\nimport { ContactSolver, type SolverSettings } from './ContactSolver';\nimport { info, setGround } from './contactReport';\nimport type { PhysicsWorldOptions } from './PhysicsWorldOptions';\nimport { castRay } from './raycast';\nimport type { BodyOptions, ContactInfo, PhysicsEvents, RayHit, RaycastOptions } from './types';\n\n/**\n * A rigid-body world for platformers and physics toys: dynamic, static and kinematic circles, boxes and convex\n * polygons, turned by contacts when made with `rotates: true`, stepped at a fixed dt (`physicsSystem` runs it as a\n * `fixed` system). Each step: forces and gravity (semi-implicit Euler), broad phase, narrow phase, sequential impulses\n * with warm starting, then positions, then overlap removed by moving positions. Fast bodies are handled by\n * sub-stepping, not swept tests.\n *\n * Not deterministic across machines: the solver's results depend on body order and floating point, which is fine for\n * a single player's world but not for one a server must replay (use `net/movement` for that).\n */\nexport class PhysicsWorld {\n gravityX: number;\n gravityY: number;\n readonly events = new EventBus<PhysicsEvents>();\n /** Called for each touching solid pair every sub-step; returning false skips its response this sub-step (one-way platforms). */\n preSolve: ((contact: Contact) => boolean) | null = null;\n private readonly list: Body[] = [];\n private readonly broad: BroadPhase;\n private readonly solver: ContactSolver;\n private readonly contacts = new Map<number, Contact>();\n private readonly active: Contact[] = [];\n private readonly manifold = emptyManifold();\n private readonly removals: Body[] = [];\n private readonly settings: SolverSettings;\n private readonly velocityIterations: number;\n private readonly positionIterations: number;\n private readonly maxSubsteps: number;\n private readonly maxSpeed: number;\n private readonly margin: number;\n private readonly groundNormal: number;\n private readonly allowSleep: boolean;\n private readonly sleepSpeed: number;\n private readonly sleepTime: number;\n private stepCount = 0;\n private subCount = 0;\n private stepping = false;\n\n constructor(options: PhysicsWorldOptions = {}) {\n this.gravityX = options.gravityX ?? 0;\n this.gravityY = options.gravityY ?? 980;\n this.margin = options.contactMargin ?? 0.5;\n this.settings = {\n restitutionThreshold: options.restitutionThreshold ?? 40,\n slop: options.slop ?? 0.05,\n correction: options.correction ?? 0.4,\n maxCorrection: options.maxCorrection ?? 4,\n };\n this.solver = new ContactSolver(this.settings);\n this.broad = new BroadPhase(options.cellSize ?? 64, this.margin);\n this.velocityIterations = options.velocityIterations ?? 8;\n this.positionIterations = options.positionIterations ?? 3;\n this.maxSubsteps = Math.max(1, options.maxSubsteps ?? 16);\n this.maxSpeed = options.maxSpeed ?? 4000;\n this.groundNormal = options.groundNormal ?? 0.7;\n this.allowSleep = options.allowSleep ?? false;\n this.sleepSpeed = options.sleepSpeed ?? 4;\n this.sleepTime = options.sleepTime ?? 0.5;\n }\n\n /** Adds a body (or makes one from options) and returns it. */\n add(body: Body | BodyOptions): Body {\n const b = body instanceof Body ? body : new Body(body);\n if (b.inWorld) return b;\n b.inWorld = true;\n b.updateBounds();\n b.wake();\n this.list.push(b);\n if (b.isStatic) this.broad.markStaticsDirty();\n return b;\n }\n\n addAll(bodies: Iterable<Body>): void {\n for (const b of bodies) this.add(b);\n }\n\n /** Takes a body out; its contacts end (with `end` events). During a step it waits until the step is over. */\n remove(body: Body): void {\n if (!body.inWorld) return;\n if (this.stepping) {\n this.removals.push(body);\n return;\n }\n body.inWorld = false;\n const i = this.list.indexOf(body);\n if (i >= 0) this.list.splice(i, 1);\n if (body.isStatic) this.broad.markStaticsDirty();\n body.grounded = false;\n body.ground = null;\n const ended: ContactInfo[] = [];\n for (const [key, c] of this.contacts) {\n if (c.a !== body && c.b !== body) continue;\n c.other(body).wake();\n if (c.reported) ended.push(info(c));\n this.contacts.delete(key);\n }\n for (const e of ended) this.events.emit('end', e);\n }\n\n /** Call after moving, resizing or retyping a static body by hand. */\n staticsChanged(): void {\n this.broad.markStaticsDirty();\n }\n\n get bodyCount(): number {\n return this.list.length;\n }\n\n /**\n * Every body in the world, in the order added: for tools (a debug drawing, an inspector) that would otherwise keep\n * a second list beside the world's. Read it, never hold it across a step: adding and removing change it in place.\n */\n get bodies(): readonly Body[] {\n return this.list;\n }\n\n /** Advances the world by `dt` seconds; call it with the fixed step (`FixedLoop.stepSeconds`). */\n step(dt: number): void {\n if (!(dt > 0) || !Number.isFinite(dt)) return;\n this.stepping = true;\n try {\n this.stepCount++;\n for (const b of this.list) {\n b.prevX = b.x;\n b.prevY = b.y;\n b.prevAngle = b.angle;\n }\n const n = this.substepsFor(dt);\n for (let i = 0; i < n; i++) this.substep(dt / n);\n for (const b of this.list) {\n b.fx = 0;\n b.fy = 0;\n b.torque = 0;\n }\n if (this.allowSleep) this.updateSleep(dt);\n } finally {\n this.stepping = false;\n }\n this.finishContacts();\n for (const b of this.removals.splice(0)) this.remove(b);\n }\n\n /** The first body on the segment from (x0, y0) to (x1, y1). Bodies the ray starts inside are skipped. */\n raycast(x0: number, y0: number, x1: number, y1: number, options?: RaycastOptions): RayHit | null {\n for (const b of this.list) if (!b.isStatic) b.updateBounds();\n this.broad.rebuild(this.list);\n return castRay([this.broad.statics, this.broad.movers], x0, y0, x1, y1, options);\n }\n\n /** The pairs touching `body` after the last step (sensors' overlaps included). */\n contactsOf(body: Body, out: ContactInfo[] = []): ContactInfo[] {\n out.length = 0;\n for (const c of this.contacts.values()) if (c.reported && (c.a === body || c.b === body)) out.push(c);\n return out;\n }\n\n /** Whether `body` stood on something at the end of the last step (also `body.grounded`). */\n isGrounded(body: Body): boolean {\n return body.grounded;\n }\n\n private substepsFor(dt: number): number {\n const gx = this.gravityX;\n const gy = this.gravityY;\n let worst = 0;\n for (const b of this.list) {\n if (!b.moving) continue;\n const g = b.isDynamic ? Math.hypot(gx, gy) * Math.abs(b.gravityScale) * dt : 0;\n // a turning body's corners sweep too\n const speed = Math.min(this.maxSpeed, Math.hypot(b.vx, b.vy) + g + Math.abs(b.angularVelocity) * b.maxExtent);\n worst = Math.max(worst, (speed * dt) / Math.max(0.5, b.minHalfExtent));\n }\n return Math.min(this.maxSubsteps, Math.max(1, Math.ceil(worst)));\n }\n\n private substep(h: number): void {\n this.subCount++;\n const max2 = this.maxSpeed * this.maxSpeed;\n for (const b of this.list) {\n if (!b.isDynamic || !b.awake) continue;\n b.vx += (this.gravityX * b.gravityScale + b.fx * b.invMass) * h;\n b.vy += (this.gravityY * b.gravityScale + b.fy * b.invMass) * h;\n if (b.linearDamping > 0) {\n const k = 1 / (1 + b.linearDamping * h);\n b.vx *= k;\n b.vy *= k;\n }\n const s2 = b.vx * b.vx + b.vy * b.vy;\n if (s2 > max2) {\n const k = this.maxSpeed / Math.sqrt(s2);\n b.vx *= k;\n b.vy *= k;\n }\n if (b.invInertia > 0) {\n b.angularVelocity += b.torque * b.invInertia * h;\n if (b.angularDamping > 0) b.angularVelocity /= 1 + b.angularDamping * h;\n // no corner faster than the speed limit\n const maxW = this.maxSpeed / Math.max(1, b.maxExtent);\n if (Math.abs(b.angularVelocity) > maxW) b.angularVelocity = Math.sign(b.angularVelocity) * maxW;\n }\n }\n this.broad.rebuild(this.list);\n this.active.length = 0;\n this.broad.pairs(this.list, this.visitPair);\n this.solver.prepare(this.active, h);\n for (let i = 0; i < this.velocityIterations; i++) this.solver.solveVelocities(this.active);\n for (const b of this.list) {\n if (!b.moving) continue;\n b.x += b.vx * h;\n b.y += b.vy * h;\n if (b.rotates) b.angle += b.angularVelocity * h;\n }\n for (let i = 0; i < this.positionIterations; i++) this.solver.solvePositions(this.active);\n for (const b of this.list) if (b.moving) b.updateBounds();\n }\n\n private readonly visitPair = (p: Body, q: Body): void => {\n if (!(p.layer & q.mask) || !(q.layer & p.mask)) return;\n const sensor = p.sensor || q.sensor;\n // two bodies nothing can push: only a sensor among them has anything to report\n if (p.invMass === 0 && q.invMass === 0 && !sensor) return;\n const a = p.id < q.id ? p : q;\n const b = a === p ? q : p;\n const m = this.manifold;\n if (!collide(a, b, sensor ? 0 : this.margin, m)) return;\n if (sensor && m.depth <= 0) return;\n const key = Contact.keyOf(a, b);\n let c = this.contacts.get(key);\n if (!c) {\n c = new Contact(a, b, key);\n this.contacts.set(key, c);\n }\n this.takeManifold(c, m, c.seenSub === this.subCount - 1);\n c.seenSub = this.subCount;\n c.seenStep = this.stepCount;\n if (sensor) {\n c.enabled = false;\n return;\n }\n if (a.awake !== b.awake) this.wakeOnImpact(a, b);\n c.enabled = this.preSolve ? this.preSolve(c) !== false : true;\n if (c.enabled) this.active.push(c);\n };\n\n /**\n * Copies the narrow phase's points into the contact, carrying each point's impulses over from the last sub-step\n * when the same feature touches again (`warm`: the pair touched on the last sub-step).\n */\n private takeManifold(c: Contact, m: Manifold, warm: boolean): void {\n const a = c.a;\n const b = c.b;\n let j0n = 0;\n let j0t = 0;\n let j1n = 0;\n let j1t = 0;\n let id0 = -1;\n let id1 = -1;\n if (warm) {\n if (c.count > 0) {\n id0 = c.pts[0].id;\n j0n = c.pts[0].jn;\n j0t = c.pts[0].jt;\n }\n if (c.count > 1) {\n id1 = c.pts[1].id;\n j1n = c.pts[1].jn;\n j1t = c.pts[1].jt;\n }\n }\n c.nx = m.nx;\n c.ny = m.ny;\n c.depth = m.depth;\n c.count = m.count;\n for (let i = 0; i < m.count; i++) {\n const p = c.pts[i]!;\n const id = m.id[i]!;\n p.x = m.px[i]!;\n p.y = m.py[i]!;\n p.depth = m.pd[i]!;\n p.id = id;\n p.jn = id === id0 ? j0n : id === id1 ? j1n : 0;\n p.jt = id === id0 ? j0t : id === id1 ? j1t : 0;\n const dax = p.x - a.x;\n const day = p.y - a.y;\n p.lax = a.cos * dax + a.sin * day;\n p.lay = -a.sin * dax + a.cos * day;\n const dbx = p.x - b.x;\n const dby = p.y - b.y;\n p.lbx = b.cos * dbx + b.sin * dby;\n p.lby = -b.sin * dbx + b.cos * dby;\n }\n }\n\n /** A sleeping body wakes when something meets it faster than the sleep speed (a kinematic platform always does). */\n private wakeOnImpact(a: Body, b: Body): void {\n const sleeper = a.awake ? b : a;\n const mover = a.awake ? a : b;\n if (sleeper.isStatic) return;\n const rv = Math.hypot(mover.vx - sleeper.vx, mover.vy - sleeper.vy);\n if (mover.type === 'kinematic' || rv > this.sleepSpeed) sleeper.wake();\n }\n\n private updateSleep(dt: number): void {\n const s2 = this.sleepSpeed * this.sleepSpeed;\n for (const b of this.list) {\n if (!b.isDynamic || !b.awake) continue;\n const spin = b.angularVelocity * b.maxExtent;\n if (b.vx * b.vx + b.vy * b.vy + spin * spin > s2 || b.fx !== 0 || b.fy !== 0 || b.torque !== 0) {\n b.restTime = 0;\n continue;\n }\n b.restTime += dt;\n if (b.restTime >= this.sleepTime) {\n b.awake = false;\n b.vx = 0;\n b.vy = 0;\n b.angularVelocity = 0;\n }\n }\n }\n\n /** Ends pairs no longer touching, starts new ones, refreshes `grounded`, then emits the events. */\n private finishContacts(): void {\n for (const b of this.list) {\n b.grounded = false;\n b.ground = null;\n }\n const begun: ContactInfo[] = [];\n const ended: ContactInfo[] = [];\n const cos = this.groundNormal;\n for (const [key, c] of this.contacts) {\n // a pair of bodies that are both at rest is not re-tested: it keeps touching as it was\n const touching = c.seenStep === this.stepCount || (c.reported && !c.a.moving && !c.b.moving);\n if (!touching) {\n if (c.reported) ended.push(info(c));\n this.contacts.delete(key);\n continue;\n }\n if (!c.reported) {\n c.reported = true;\n begun.push(info(c));\n }\n if (c.sensor || !c.enabled) continue;\n if (c.ny < -cos) setGround(c.b, c.a, c);\n else if (c.ny > cos) setGround(c.a, c.b, c);\n }\n for (const e of ended) this.events.emit('end', e);\n for (const e of begun) this.events.emit('begin', e);\n }\n}\n"],"names":["PhysicsWorld","EventBus","emptyManifold","options","ContactSolver","BroadPhase","body","b","Body","bodies","ended","key","c","info","e","dt","n","i","x0","y0","x1","y1","castRay","out","gx","gy","worst","g","speed","h","max2","k","s2","maxW","p","q","sensor","a","m","collide","Contact","warm","j0n","j0t","j1n","j1t","id0","id1","id","dax","day","dbx","dby","sleeper","mover","rv","spin","begun","cos","setGround"],"mappings":";;;;;;;;AAqBO,MAAMA,EAAa;AAAA,EACxB;AAAA,EACA;AAAA,EACS,SAAS,IAAIC,EAAA;AAAA;AAAA,EAEtB,WAAmD;AAAA,EAClC,OAAe,CAAA;AAAA,EACf;AAAA,EACA;AAAA,EACA,+BAAe,IAAA;AAAA,EACf,SAAoB,CAAA;AAAA,EACpB,WAAWC,EAAA;AAAA,EACX,WAAmB,CAAA;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EAEnB,YAAYC,IAA+B,IAAI;AAC7C,SAAK,WAAWA,EAAQ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AAuB,CAAA,GACvBgD,IAAM,KAAK;AACjB,eAAW,CAAC/C,GAAKC,CAAC,KAAK,KAAK,UAAU;AAGpC,UAAI,EADaA,EAAE,aAAa,KAAK,aAAcA,EAAE,YAAY,CAACA,EAAE,EAAE,UAAU,CAACA,EAAE,EAAE,SACtE;AACb,QAAIA,EAAE,YAAUF,EAAM,KAAKG,EAAKD,CAAC,CAAC,GAClC,KAAK,SAAS,OAAOD,CAAG;AACxB;AAAA,MACF;AAKA,MAJKC,EAAE,aACLA,EAAE,WAAW,IACb6C,EAAM,KAAK5C,EAAKD,CAAC,CAAC,IAEhB,EAAAA,EAAE,UAAU,CAACA,EAAE,aACfA,EAAE,KAAK,CAAC8C,MAAe9C,EAAE,GAAGA,EAAE,GAAGA,CAAC,IAC7BA,EAAE,KAAK8C,KAAKC,EAAU/C,EAAE,GAAGA,EAAE,GAAGA,CAAC;AAAA,IAC5C;AACA,eAAWE,KAAKJ,EAAO,MAAK,OAAO,KAAK,OAAOI,CAAC;AAChD,eAAWA,KAAK2C,EAAO,MAAK,OAAO,KAAK,SAAS3C,CAAC;AAAA,EACpD;AACF;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class i {
|
|
2
|
+
cellSize;
|
|
3
|
+
inv;
|
|
4
|
+
cells = /* @__PURE__ */ new Map();
|
|
5
|
+
/** Lists emptied by `clear`, kept for reuse so a rebuild every step allocates nothing once warm. */
|
|
6
|
+
spare = [];
|
|
7
|
+
constructor(t) {
|
|
8
|
+
if (!(t > 0)) throw new Error(`SpatialHash: cell size must be positive, got ${t}`);
|
|
9
|
+
this.cellSize = t, this.inv = 1 / t;
|
|
10
|
+
}
|
|
11
|
+
static key(t, s) {
|
|
12
|
+
return (t + 32768 & 65535) * 65536 + (s + 32768 & 65535);
|
|
13
|
+
}
|
|
14
|
+
cellOf(t) {
|
|
15
|
+
return Math.floor(t * this.inv);
|
|
16
|
+
}
|
|
17
|
+
clear() {
|
|
18
|
+
for (const t of this.cells.values())
|
|
19
|
+
t.length = 0, this.spare.push(t);
|
|
20
|
+
this.cells.clear();
|
|
21
|
+
}
|
|
22
|
+
insert(t, s = 0) {
|
|
23
|
+
const h = this.cellOf(t.minX - s), n = this.cellOf(t.maxX + s), o = this.cellOf(t.minY - s), f = this.cellOf(t.maxY + s);
|
|
24
|
+
for (let l = o; l <= f; l++)
|
|
25
|
+
for (let c = h; c <= n; c++) {
|
|
26
|
+
const r = i.key(c, l);
|
|
27
|
+
let e = this.cells.get(r);
|
|
28
|
+
e || (e = this.spare.pop() ?? [], this.cells.set(r, e)), e.push(t);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The bodies listed in one cell (undefined when empty). Do not keep or edit the array. */
|
|
32
|
+
at(t, s) {
|
|
33
|
+
return this.cells.get(i.key(t, s));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
i as SpatialHash
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=SpatialHash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpatialHash.js","sources":["../../src/physics/SpatialHash.ts"],"sourcesContent":["import type { Body } from './Body';\n\n/**\n * Broad phase: a uniform grid hashed into a map, each cell listing the bodies whose bounds touch it. A body spans\n * as many cells as its bounds cover, so a long merged floor sits in a row of cells and is still one body.\n *\n * Cells are keyed by their coordinates packed into one number (16 bits each, wrapping): two cells 65,536 cells\n * apart share a list, which only costs a few extra narrow-phase tests, never a missed pair.\n */\nexport class SpatialHash {\n readonly cellSize: number;\n private readonly inv: number;\n private readonly cells = new Map<number, Body[]>();\n /** Lists emptied by `clear`, kept for reuse so a rebuild every step allocates nothing once warm. */\n private readonly spare: Body[][] = [];\n\n constructor(cellSize: number) {\n if (!(cellSize > 0)) throw new Error(`SpatialHash: cell size must be positive, got ${cellSize}`);\n this.cellSize = cellSize;\n this.inv = 1 / cellSize;\n }\n\n static key(cx: number, cy: number): number {\n return ((cx + 0x8000) & 0xffff) * 0x10000 + ((cy + 0x8000) & 0xffff);\n }\n\n cellOf(v: number): number {\n return Math.floor(v * this.inv);\n }\n\n clear(): void {\n for (const list of this.cells.values()) {\n list.length = 0;\n this.spare.push(list);\n }\n this.cells.clear();\n }\n\n insert(body: Body, margin = 0): void {\n const x0 = this.cellOf(body.minX - margin);\n const x1 = this.cellOf(body.maxX + margin);\n const y0 = this.cellOf(body.minY - margin);\n const y1 = this.cellOf(body.maxY + margin);\n for (let cy = y0; cy <= y1; cy++) {\n for (let cx = x0; cx <= x1; cx++) {\n const k = SpatialHash.key(cx, cy);\n let list = this.cells.get(k);\n if (!list) {\n list = this.spare.pop() ?? [];\n this.cells.set(k, list);\n }\n list.push(body);\n }\n }\n }\n\n /** The bodies listed in one cell (undefined when empty). Do not keep or edit the array. */\n at(cx: number, cy: number): readonly Body[] | undefined {\n return this.cells.get(SpatialHash.key(cx, cy));\n }\n}\n"],"names":["SpatialHash","cellSize","cx","cy","v","list","body","margin","x0","x1","y0","y1","k"],"mappings":"AASO,MAAMA,EAAY;AAAA,EACd;AAAA,EACQ;AAAA,EACA,4BAAY,IAAA;AAAA;AAAA,EAEZ,QAAkB,CAAA;AAAA,EAEnC,YAAYC,GAAkB;AAC5B,QAAI,EAAEA,IAAW,GAAI,OAAM,IAAI,MAAM,gDAAgDA,CAAQ,EAAE;AAC/F,SAAK,WAAWA,GAChB,KAAK,MAAM,IAAIA;AAAA,EACjB;AAAA,EAEA,OAAO,IAAIC,GAAYC,GAAoB;AACzC,YAASD,IAAK,QAAU,SAAU,SAAYC,IAAK,QAAU;AAAA,EAC/D;AAAA,EAEA,OAAOC,GAAmB;AACxB,WAAO,KAAK,MAAMA,IAAI,KAAK,GAAG;AAAA,EAChC;AAAA,EAEA,QAAc;AACZ,eAAWC,KAAQ,KAAK,MAAM,OAAA;AAC5B,MAAAA,EAAK,SAAS,GACd,KAAK,MAAM,KAAKA,CAAI;AAEtB,SAAK,MAAM,MAAA;AAAA,EACb;AAAA,EAEA,OAAOC,GAAYC,IAAS,GAAS;AACnC,UAAMC,IAAK,KAAK,OAAOF,EAAK,OAAOC,CAAM,GACnCE,IAAK,KAAK,OAAOH,EAAK,OAAOC,CAAM,GACnCG,IAAK,KAAK,OAAOJ,EAAK,OAAOC,CAAM,GACnCI,IAAK,KAAK,OAAOL,EAAK,OAAOC,CAAM;AACzC,aAASJ,IAAKO,GAAIP,KAAMQ,GAAIR;AAC1B,eAASD,IAAKM,GAAIN,KAAMO,GAAIP,KAAM;AAChC,cAAMU,IAAIZ,EAAY,IAAIE,GAAIC,CAAE;AAChC,YAAIE,IAAO,KAAK,MAAM,IAAIO,CAAC;AAC3B,QAAKP,MACHA,IAAO,KAAK,MAAM,IAAA,KAAS,CAAA,GAC3B,KAAK,MAAM,IAAIO,GAAGP,CAAI,IAExBA,EAAK,KAAKC,CAAI;AAAA,MAChB;AAAA,EAEJ;AAAA;AAAA,EAGA,GAAGJ,GAAYC,GAAyC;AACtD,WAAO,KAAK,MAAM,IAAIH,EAAY,IAAIE,GAAIC,CAAE,CAAC;AAAA,EAC/C;AACF;"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { circlePolygon as _, polygonPolygon as W } from "./collidePolygon.js";
|
|
2
|
+
import { FACE_RIGHT as m, FACE_LEFT as C, FACE_BOTTOM as E, FACE_TOP as O } from "./types.js";
|
|
3
|
+
function L() {
|
|
4
|
+
return { nx: 0, ny: 0, depth: 0, count: 0, px: [0, 0], py: [0, 0], pd: [0, 0], id: [0, 0] };
|
|
5
|
+
}
|
|
6
|
+
function R(n, s, t, r) {
|
|
7
|
+
const i = n.shape, e = s.shape;
|
|
8
|
+
return i.kind === "circle" && e.kind === "circle" ? v(n, i, s, e, t, r) ? (X(r, n.x + r.nx * (i.radius - r.depth / 2), n.y + r.ny * (i.radius - r.depth / 2)), !0) : !1 : i.kind === "circle" ? s.axisAligned ? I(n, i, s, e, t, r) ? (r.nx = -r.nx, r.ny = -r.ny, X(r, n.x + r.nx * (i.radius - r.depth / 2), n.y + r.ny * (i.radius - r.depth / 2)), !0) : !1 : _(n, i.radius, s, t, !0, r) : e.kind === "circle" ? n.axisAligned ? I(s, e, n, i, t, r) ? (X(r, s.x - r.nx * (e.radius - r.depth / 2), s.y - r.ny * (e.radius - r.depth / 2)), !0) : !1 : _(s, e.radius, n, t, !1, r) : n.axisAligned && s.axisAligned && n.invInertia === 0 && s.invInertia === 0 ? q(n, i, s, e, t, r) ? (X(r, (Math.max(n.minX, s.minX) + Math.min(n.maxX, s.maxX)) / 2, (Math.max(n.minY, s.minY) + Math.min(n.maxY, s.maxY)) / 2), !0) : !1 : W(n, s, t, r);
|
|
9
|
+
}
|
|
10
|
+
function X(n, s, t) {
|
|
11
|
+
n.count = 1, n.px[0] = s, n.py[0] = t, n.pd[0] = n.depth, n.id[0] = 0;
|
|
12
|
+
}
|
|
13
|
+
function w(n, s, t) {
|
|
14
|
+
return t > 0 ? !(n.internalFaces & m) && !(s.internalFaces & C) : !(n.internalFaces & C) && !(s.internalFaces & m);
|
|
15
|
+
}
|
|
16
|
+
function B(n, s, t) {
|
|
17
|
+
return t > 0 ? !(n.internalFaces & E) && !(s.internalFaces & O) : !(n.internalFaces & O) && !(s.internalFaces & E);
|
|
18
|
+
}
|
|
19
|
+
function q(n, s, t, r, i, e) {
|
|
20
|
+
const d = t.x - n.x, h = t.y - n.y, c = s.halfWidth + r.halfWidth - Math.abs(d), f = s.halfHeight + r.halfHeight - Math.abs(h);
|
|
21
|
+
if (c <= -i || f <= -i || c < 0 && f < 0) return !1;
|
|
22
|
+
const a = d < 0 ? -1 : 1, M = h < 0 ? -1 : 1;
|
|
23
|
+
let x;
|
|
24
|
+
if (c < 0) x = !0;
|
|
25
|
+
else if (f < 0) x = !1;
|
|
26
|
+
else {
|
|
27
|
+
const p = w(n, t, a), y = B(n, t, M);
|
|
28
|
+
x = p && y ? c < f : p ? !0 : y ? !1 : c < f;
|
|
29
|
+
}
|
|
30
|
+
if (x) {
|
|
31
|
+
if (c < 0 && !w(n, t, a)) return !1;
|
|
32
|
+
e.nx = a, e.ny = 0, e.depth = c;
|
|
33
|
+
} else {
|
|
34
|
+
if (f < 0 && !B(n, t, M)) return !1;
|
|
35
|
+
e.nx = 0, e.ny = M, e.depth = f;
|
|
36
|
+
}
|
|
37
|
+
return !0;
|
|
38
|
+
}
|
|
39
|
+
function v(n, s, t, r, i, e) {
|
|
40
|
+
const d = t.x - n.x, h = t.y - n.y, c = s.radius + r.radius, f = d * d + h * h;
|
|
41
|
+
if (f >= (c + i) * (c + i)) return !1;
|
|
42
|
+
const a = Math.sqrt(f);
|
|
43
|
+
return a > 1e-9 ? (e.nx = d / a, e.ny = h / a) : (e.nx = 0, e.ny = 1), e.depth = c - a, !0;
|
|
44
|
+
}
|
|
45
|
+
function I(n, s, t, r, i, e) {
|
|
46
|
+
const d = r.halfWidth, h = r.halfHeight, c = s.radius, f = n.x - t.x, a = n.y - t.y, M = t.internalFaces, x = f < 0 ? -1 : 1, p = a < 0 ? -1 : 1, y = !(M & (x > 0 ? m : C)), u = !(M & (p > 0 ? E : O)), T = Math.abs(f) <= d, H = Math.abs(a) <= h;
|
|
47
|
+
if (T && H) {
|
|
48
|
+
const l = d - Math.abs(f) + c, Y = h - Math.abs(a) + c, k = y && u ? l < Y : y ? !0 : u ? !1 : l < Y;
|
|
49
|
+
return e.nx = k ? x : 0, e.ny = k ? 0 : p, e.depth = k ? l : Y, !0;
|
|
50
|
+
}
|
|
51
|
+
if (H) {
|
|
52
|
+
if (!y) return !1;
|
|
53
|
+
const l = Math.abs(f) - d;
|
|
54
|
+
return l >= c + i ? !1 : (e.nx = x, e.ny = 0, e.depth = c - l, !0);
|
|
55
|
+
}
|
|
56
|
+
if (T) {
|
|
57
|
+
if (!u) return !1;
|
|
58
|
+
const l = Math.abs(a) - h;
|
|
59
|
+
return l >= c + i ? !1 : (e.nx = 0, e.ny = p, e.depth = c - l, !0);
|
|
60
|
+
}
|
|
61
|
+
const o = f - x * d, A = a - p * h;
|
|
62
|
+
if (!y && !u) return !1;
|
|
63
|
+
if (!y || !u) {
|
|
64
|
+
const l = Math.abs(y ? o : A);
|
|
65
|
+
return l >= c + i ? !1 : (e.nx = y ? x : 0, e.ny = y ? 0 : p, e.depth = c - l, !0);
|
|
66
|
+
}
|
|
67
|
+
const P = o * o + A * A;
|
|
68
|
+
if (P >= (c + i) * (c + i)) return !1;
|
|
69
|
+
const F = Math.sqrt(P);
|
|
70
|
+
return e.nx = F > 1e-9 ? o / F : x, e.ny = F > 1e-9 ? A / F : 0, e.depth = c - F, !0;
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
R as collide,
|
|
74
|
+
L as emptyManifold
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=collide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collide.js","sources":["../../src/physics/collide.ts"],"sourcesContent":["import type { Body } from './Body';\nimport { circlePolygon, polygonPolygon } from './collidePolygon';\nimport { FACE_BOTTOM, FACE_LEFT, FACE_RIGHT, FACE_TOP, type BoxShape, type CircleShape } from './types';\n\n/**\n * The result of a narrow-phase test: the normal points from `a` to `b`, `depth` > 0 is overlap, < 0 a gap (the\n * deepest of the points). Up to two contact points, each with its own depth and a feature id that stays the same\n * while the same corners touch, so the solver can carry each point's impulse over from step to step.\n */\nexport interface Manifold {\n nx: number;\n ny: number;\n depth: number;\n count: number;\n readonly px: [number, number];\n readonly py: [number, number];\n readonly pd: [number, number];\n readonly id: [number, number];\n}\n\nexport function emptyManifold(): Manifold {\n return { nx: 0, ny: 0, depth: 0, count: 0, px: [0, 0], py: [0, 0], pd: [0, 0], id: [0, 0] };\n}\n\n/**\n * Narrow phase. Fills `out` and returns true when the two shapes overlap or lie closer than `margin`. The margin\n * keeps a resting contact alive while the solver holds the bodies a hair apart, so a body standing on the ground is\n * grounded on every step instead of flickering between touching and not.\n *\n * Two bodies that never turn and sit square (boxes at no angle, circles) take the axis-aligned tests, which know the\n * internal faces of merged tile boxes; anything turned or turning takes the polygon tests (`collidePolygon.ts`).\n */\nexport function collide(a: Body, b: Body, margin: number, out: Manifold): boolean {\n const sa = a.shape;\n const sb = b.shape;\n if (sa.kind === 'circle' && sb.kind === 'circle') {\n if (!circleCircle(a, sa, b, sb, margin, out)) return false;\n onePoint(out, a.x + out.nx * (sa.radius - out.depth / 2), a.y + out.ny * (sa.radius - out.depth / 2));\n return true;\n }\n if (sa.kind === 'circle') {\n if (!b.axisAligned) return circlePolygon(a, sa.radius, b, margin, true, out);\n if (!circleBox(a, sa, b, sb as BoxShape, margin, out)) return false;\n out.nx = -out.nx;\n out.ny = -out.ny;\n // the normal now runs from the circle (a) to the box: the circle's surface point is ahead of its centre\n onePoint(out, a.x + out.nx * (sa.radius - out.depth / 2), a.y + out.ny * (sa.radius - out.depth / 2));\n return true;\n }\n if (sb.kind === 'circle') {\n if (!a.axisAligned) return circlePolygon(b, sb.radius, a, margin, false, out);\n if (!circleBox(b, sb, a, sa as BoxShape, margin, out)) return false;\n // circleBox gives the normal from the box (a) to the circle (b): already a → b\n onePoint(out, b.x - out.nx * (sb.radius - out.depth / 2), b.y - out.ny * (sb.radius - out.depth / 2));\n return true;\n }\n if (a.axisAligned && b.axisAligned && a.invInertia === 0 && b.invInertia === 0) {\n if (!boxBox(a, sa as BoxShape, b, sb as BoxShape, margin, out)) return false;\n // neither turns, so where the point lies changes nothing: the middle of the overlap\n onePoint(out, (Math.max(a.minX, b.minX) + Math.min(a.maxX, b.maxX)) / 2, (Math.max(a.minY, b.minY) + Math.min(a.maxY, b.maxY)) / 2);\n return true;\n }\n return polygonPolygon(a, b, margin, out);\n}\n\nfunction onePoint(out: Manifold, x: number, y: number): void {\n out.count = 1;\n out.px[0] = x;\n out.py[0] = y;\n out.pd[0] = out.depth;\n out.id[0] = 0;\n}\n\n/** The narrow phase's three numbers, for the axis-aligned tests below. */\ninterface Normal {\n nx: number;\n ny: number;\n depth: number;\n}\n\n/** Whether a normal along x (sign sx, from a to b) may be used: not out of a face either box marks as internal. */\nfunction xAllowed(a: Body, b: Body, sx: number): boolean {\n return sx > 0 ? !(a.internalFaces & FACE_RIGHT) && !(b.internalFaces & FACE_LEFT) : !(a.internalFaces & FACE_LEFT) && !(b.internalFaces & FACE_RIGHT);\n}\n\nfunction yAllowed(a: Body, b: Body, sy: number): boolean {\n return sy > 0 ? !(a.internalFaces & FACE_BOTTOM) && !(b.internalFaces & FACE_TOP) : !(a.internalFaces & FACE_TOP) && !(b.internalFaces & FACE_BOTTOM);\n}\n\nfunction boxBox(a: Body, sa: BoxShape, b: Body, sb: BoxShape, margin: number, out: Normal): boolean {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const px = sa.halfWidth + sb.halfWidth - Math.abs(dx);\n const py = sa.halfHeight + sb.halfHeight - Math.abs(dy);\n if (px <= -margin || py <= -margin) return false;\n // corner to corner across a gap: no face faces the other, and a contact here only snags bodies sliding past\n if (px < 0 && py < 0) return false;\n const sx = dx < 0 ? -1 : 1;\n const sy = dy < 0 ? -1 : 1;\n let useX: boolean;\n if (px < 0) useX = true;\n else if (py < 0) useX = false;\n else {\n const okX = xAllowed(a, b, sx);\n const okY = yAllowed(a, b, sy);\n useX = okX && okY ? px < py : okX ? true : okY ? false : px < py;\n }\n if (useX) {\n if (px < 0 && !xAllowed(a, b, sx)) return false;\n out.nx = sx;\n out.ny = 0;\n out.depth = px;\n } else {\n if (py < 0 && !yAllowed(a, b, sy)) return false;\n out.nx = 0;\n out.ny = sy;\n out.depth = py;\n }\n return true;\n}\n\nfunction circleCircle(a: Body, sa: CircleShape, b: Body, sb: CircleShape, margin: number, out: Normal): boolean {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const r = sa.radius + sb.radius;\n const d2 = dx * dx + dy * dy;\n if (d2 >= (r + margin) * (r + margin)) return false;\n const d = Math.sqrt(d2);\n if (d > 1e-9) {\n out.nx = dx / d;\n out.ny = dy / d;\n } else {\n out.nx = 0;\n out.ny = 1;\n }\n out.depth = r - d;\n return true;\n}\n\n/**\n * Circle `c` against box `b`; the normal is written from the box to the circle. A face the box marks as internal\n * is never pushed out of, and at a corner beside an internal face the other face's axis is used instead, so a ball\n * rolls over the seam between two ground boxes without a bump.\n */\nfunction circleBox(c: Body, sc: CircleShape, b: Body, sb: BoxShape, margin: number, out: Normal): boolean {\n const hw = sb.halfWidth;\n const hh = sb.halfHeight;\n const r = sc.radius;\n const dx = c.x - b.x;\n const dy = c.y - b.y;\n const faces = b.internalFaces;\n const sx = dx < 0 ? -1 : 1;\n const sy = dy < 0 ? -1 : 1;\n const xFaceOpen = !(faces & (sx > 0 ? FACE_RIGHT : FACE_LEFT));\n const yFaceOpen = !(faces & (sy > 0 ? FACE_BOTTOM : FACE_TOP));\n const insideX = Math.abs(dx) <= hw;\n const insideY = Math.abs(dy) <= hh;\n if (insideX && insideY) {\n const penX = hw - Math.abs(dx) + r;\n const penY = hh - Math.abs(dy) + r;\n const useX = xFaceOpen && yFaceOpen ? penX < penY : xFaceOpen ? true : yFaceOpen ? false : penX < penY;\n out.nx = useX ? sx : 0;\n out.ny = useX ? 0 : sy;\n out.depth = useX ? penX : penY;\n return true;\n }\n if (insideY) {\n // beside a vertical face\n if (!xFaceOpen) return false;\n const gap = Math.abs(dx) - hw;\n if (gap >= r + margin) return false;\n out.nx = sx;\n out.ny = 0;\n out.depth = r - gap;\n return true;\n }\n if (insideX) {\n if (!yFaceOpen) return false;\n const gap = Math.abs(dy) - hh;\n if (gap >= r + margin) return false;\n out.nx = 0;\n out.ny = sy;\n out.depth = r - gap;\n return true;\n }\n // a corner region\n const ex = dx - sx * hw;\n const ey = dy - sy * hh;\n if (!xFaceOpen && !yFaceOpen) return false;\n if (!xFaceOpen || !yFaceOpen) {\n // the corner belongs to a longer surface: collide with that surface's line, not the corner's point\n const gap = !xFaceOpen ? Math.abs(ey) : Math.abs(ex);\n if (gap >= r + margin) return false;\n out.nx = !xFaceOpen ? 0 : sx;\n out.ny = !xFaceOpen ? sy : 0;\n out.depth = r - gap;\n return true;\n }\n const d2 = ex * ex + ey * ey;\n if (d2 >= (r + margin) * (r + margin)) return false;\n const d = Math.sqrt(d2);\n out.nx = d > 1e-9 ? ex / d : sx;\n out.ny = d > 1e-9 ? ey / d : 0;\n out.depth = r - d;\n return true;\n}\n"],"names":["emptyManifold","collide","a","b","margin","out","sa","sb","circleCircle","onePoint","circleBox","circlePolygon","boxBox","polygonPolygon","x","y","xAllowed","sx","FACE_RIGHT","FACE_LEFT","yAllowed","sy","FACE_BOTTOM","FACE_TOP","dx","dy","px","py","useX","okX","okY","r","d2","d","c","sc","hw","hh","faces","xFaceOpen","yFaceOpen","insideX","insideY","penX","penY","gap","ex","ey"],"mappings":";;AAoBO,SAASA,IAA0B;AACxC,SAAO,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAA;AAC1F;AAUO,SAASC,EAAQC,GAASC,GAASC,GAAgBC,GAAwB;AAChF,QAAMC,IAAKJ,EAAE,OACPK,IAAKJ,EAAE;AACb,SAAIG,EAAG,SAAS,YAAYC,EAAG,SAAS,WACjCC,EAAaN,GAAGI,GAAIH,GAAGI,GAAIH,GAAQC,CAAG,KAC3CI,EAASJ,GAAKH,EAAE,IAAIG,EAAI,MAAMC,EAAG,SAASD,EAAI,QAAQ,IAAIH,EAAE,IAAIG,EAAI,MAAMC,EAAG,SAASD,EAAI,QAAQ,EAAE,GAC7F,MAF8C,KAInDC,EAAG,SAAS,WACTH,EAAE,cACFO,EAAUR,GAAGI,GAAIH,GAAGI,GAAgBH,GAAQC,CAAG,KACpDA,EAAI,KAAK,CAACA,EAAI,IACdA,EAAI,KAAK,CAACA,EAAI,IAEdI,EAASJ,GAAKH,EAAE,IAAIG,EAAI,MAAMC,EAAG,SAASD,EAAI,QAAQ,IAAIH,EAAE,IAAIG,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
|
|
2
|
+
const Y = [D, G, H, N], L = 0.05;
|
|
3
|
+
function M(t, e, c) {
|
|
4
|
+
if (!t.internalFaces || !t.axisAligned) return !1;
|
|
5
|
+
for (let n = 0; n < 4; n++)
|
|
6
|
+
if (t.internalFaces & Y[n] && t.wnx[n] * e + t.wny[n] * c > 0.999) return !0;
|
|
7
|
+
return !1;
|
|
8
|
+
}
|
|
9
|
+
function S(t, e, c, n) {
|
|
10
|
+
return !M(t, c, n) && !M(e, -c, -n);
|
|
11
|
+
}
|
|
12
|
+
function X(t, e, c) {
|
|
13
|
+
const n = t.wnx[e], r = t.wny[e], o = t.wx[e], s = t.wy[e];
|
|
14
|
+
let i = 1 / 0;
|
|
15
|
+
for (let f = 0; f < c.corners; f++) {
|
|
16
|
+
const l = (c.wx[f] - o) * n + (c.wy[f] - s) * r;
|
|
17
|
+
l < i && (i = l);
|
|
18
|
+
}
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
function g(t, e, c, n) {
|
|
22
|
+
let r = -1 / 0;
|
|
23
|
+
n.sep = -1 / 0, n.face = -1;
|
|
24
|
+
for (let o = 0; o < t.corners; o++) {
|
|
25
|
+
const s = X(t, o, e);
|
|
26
|
+
s > r && (r = s);
|
|
27
|
+
const i = c ? t.wnx[o] : -t.wnx[o], f = c ? t.wny[o] : -t.wny[o];
|
|
28
|
+
(c ? S(t, e, i, f) : S(e, t, i, f)) && s > n.sep && (n.sep = s, n.face = o);
|
|
29
|
+
}
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
const h = { sep: 0, face: -1 }, m = { sep: 0, face: -1 }, p = [0, 0], u = [0, 0], k = [0, 0];
|
|
33
|
+
function z(t, e, c, n) {
|
|
34
|
+
const r = g(t, e, !0, h);
|
|
35
|
+
if (r > c) return !1;
|
|
36
|
+
const o = g(e, t, !1, m);
|
|
37
|
+
if (o > c) return !1;
|
|
38
|
+
let s;
|
|
39
|
+
h.face < 0 && m.face < 0 ? (s = o > r + L, s ? m.face = j(e, t, o) : h.face = j(t, e, r)) : h.face < 0 ? s = !0 : m.face < 0 ? s = !1 : s = m.sep > h.sep + L;
|
|
40
|
+
const i = s ? e : t, f = s ? t : e, l = s ? m.face : h.face, d = i.wnx[l], F = i.wny[l];
|
|
41
|
+
let A = 0, B = 1 / 0;
|
|
42
|
+
for (let x = 0; x < f.corners; x++) {
|
|
43
|
+
const w = f.wnx[x] * d + f.wny[x] * F;
|
|
44
|
+
w < B && (B = w, A = x);
|
|
45
|
+
}
|
|
46
|
+
const E = (A + 1) % f.corners;
|
|
47
|
+
p[0] = f.wx[A], u[0] = f.wy[A], k[0] = A, p[1] = f.wx[E], u[1] = f.wy[E], k[1] = E;
|
|
48
|
+
const a = (l + 1) % i.corners, y = i.wx[l], v = i.wy[l], T = i.wx[a], _ = i.wy[a], C = Math.hypot(T - y, _ - v), O = (T - y) / C, I = (_ - v) / C;
|
|
49
|
+
if (!R(-O, -I, -(O * y + I * v), 16) || !R(O, I, O * T + I * _, 17)) return !1;
|
|
50
|
+
n.nx = s ? -d : d, n.ny = s ? -F : F, n.count = 0, n.depth = -1 / 0;
|
|
51
|
+
for (let x = 0; x < 2; x++) {
|
|
52
|
+
const w = (p[x] - y) * d + (u[x] - v) * F;
|
|
53
|
+
if (w > c) continue;
|
|
54
|
+
const P = n.count++;
|
|
55
|
+
n.px[P] = p[x] - d * w * 0.5, n.py[P] = u[x] - F * w * 0.5, n.pd[P] = -w, n.id[P] = (s ? 1 : 0) << 12 | l << 6 | k[x], -w > n.depth && (n.depth = -w);
|
|
56
|
+
}
|
|
57
|
+
return n.count > 0;
|
|
58
|
+
}
|
|
59
|
+
function j(t, e, c) {
|
|
60
|
+
for (let n = 0; n < t.corners; n++) if (X(t, n, e) === c) return n;
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
function R(t, e, c, n) {
|
|
64
|
+
const r = t * p[0] + e * u[0] - c, o = t * p[1] + e * u[1] - c;
|
|
65
|
+
if (r > 0 && o > 0) return !1;
|
|
66
|
+
if (r <= 0 && o <= 0) return !0;
|
|
67
|
+
const s = r / (r - o), i = p[0] + (p[1] - p[0]) * s, f = u[0] + (u[1] - u[0]) * s;
|
|
68
|
+
return r > 0 ? (p[0] = i, u[0] = f, k[0] = n) : (p[1] = i, u[1] = f, k[1] = n), !0;
|
|
69
|
+
}
|
|
70
|
+
function J(t, e, c, n, r, o) {
|
|
71
|
+
const s = t.x, i = t.y;
|
|
72
|
+
let f = 0, l = -1 / 0;
|
|
73
|
+
for (let a = 0; a < c.corners; a++) {
|
|
74
|
+
const y = (s - c.wx[a]) * c.wnx[a] + (i - c.wy[a]) * c.wny[a];
|
|
75
|
+
y > l && (l = y, f = a);
|
|
76
|
+
}
|
|
77
|
+
if (l > e + n) return !1;
|
|
78
|
+
let d = c.wnx[f], F = c.wny[f], A = l, B = f;
|
|
79
|
+
if (l > 0) {
|
|
80
|
+
const a = (f + 1) % c.corners, y = c.wx[f], v = c.wy[f], T = c.wx[a], _ = c.wy[a], C = (s - y) * (T - y) + (i - v) * (_ - v), O = (s - T) * (y - T) + (i - _) * (v - _);
|
|
81
|
+
if (C <= 0 || O <= 0) {
|
|
82
|
+
const I = C <= 0 ? y : T, x = C <= 0 ? v : _, w = Math.hypot(s - I, i - x);
|
|
83
|
+
if (w > e + n) return !1;
|
|
84
|
+
w > 1e-9 && (d = (s - I) / w, F = (i - x) / w), A = w, B = 32 + (C <= 0 ? f : a);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const E = e - A;
|
|
88
|
+
return o.nx = r ? -d : d, o.ny = r ? -F : F, o.depth = E, o.count = 1, o.px[0] = s - d * (e - E / 2), o.py[0] = i - F * (e - E / 2), o.pd[0] = E, o.id[0] = B, !0;
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
J as circlePolygon,
|
|
92
|
+
z as polygonPolygon
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=collidePolygon.js.map
|