@egret/engine 0.0.0-stage → 7.0.1-rc.3
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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +101 -2
- package/README.zh-CN.md +102 -0
- package/dist/Engine.d.ts +77 -0
- package/dist/Engine.js +464 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.js +5 -0
- package/dist/animation/sequenceController.d.ts +22 -0
- package/dist/animation/sequenceController.js +618 -0
- package/dist/animation/sequenceCoordinator.d.ts +26 -0
- package/dist/animation/sequenceCoordinator.js +161 -0
- package/dist/animation/sequenceInput.d.ts +25 -0
- package/dist/animation/sequenceInput.js +108 -0
- package/dist/animation/sequenceMath.d.ts +35 -0
- package/dist/animation/sequenceMath.js +164 -0
- package/dist/animation/sequenceResetSlot.d.ts +7 -0
- package/dist/animation/sequenceResetSlot.js +367 -0
- package/dist/animation/sequenceResetTypes.d.ts +42 -0
- package/dist/animation/sequenceResetTypes.js +2 -0
- package/dist/animation/types.d.ts +69 -0
- package/dist/animation/types.js +2 -0
- package/dist/assetBundle.d.ts +52 -0
- package/dist/assetBundle.js +173 -0
- package/dist/assetGroup.d.ts +17 -0
- package/dist/assetGroup.js +332 -0
- package/dist/assetGroupTypes.d.ts +15 -0
- package/dist/assetGroupTypes.js +2 -0
- package/dist/audio.d.ts +4 -0
- package/dist/audio.js +4 -0
- package/dist/audioCues.d.ts +43 -0
- package/dist/audioCues.js +127 -0
- package/dist/audioMixer.d.ts +7 -0
- package/dist/audioMixer.js +785 -0
- package/dist/audioTypes.d.ts +233 -0
- package/dist/audioTypes.js +3 -0
- package/dist/bitmapBindingTicket.d.ts +24 -0
- package/dist/bitmapBindingTicket.js +215 -0
- package/dist/bitmapButton.d.ts +4 -0
- package/dist/bitmapButton.js +407 -0
- package/dist/bitmapButtonTypes.d.ts +29 -0
- package/dist/bitmapButtonTypes.js +2 -0
- package/dist/bitmapFontParse.d.ts +10 -0
- package/dist/bitmapFontParse.js +246 -0
- package/dist/bitmapFontTypes.d.ts +109 -0
- package/dist/bitmapFontTypes.js +2 -0
- package/dist/bitmapResourceSlot.d.ts +25 -0
- package/dist/bitmapResourceSlot.js +340 -0
- package/dist/bitmapText.d.ts +6 -0
- package/dist/bitmapText.js +320 -0
- package/dist/bitmapfont.d.ts +5 -0
- package/dist/bitmapfont.js +5 -0
- package/dist/camera.d.ts +4 -0
- package/dist/camera.js +4 -0
- package/dist/camera2d.d.ts +7 -0
- package/dist/camera2d.js +411 -0
- package/dist/cameraTypes.d.ts +114 -0
- package/dist/cameraTypes.js +2 -0
- package/dist/closeHost.d.ts +4 -0
- package/dist/closeHost.js +66 -0
- package/dist/contentArtifacts.d.ts +12 -0
- package/dist/contentArtifacts.js +153 -0
- package/dist/contentAtlasPages.d.ts +13 -0
- package/dist/contentAtlasPages.js +117 -0
- package/dist/contentLoader.d.ts +6 -0
- package/dist/contentLoader.js +327 -0
- package/dist/contentTypes.d.ts +33 -0
- package/dist/contentTypes.js +2 -0
- package/dist/createEngine.d.ts +7 -0
- package/dist/createEngine.js +25 -0
- package/dist/createEngineForProfile.d.ts +5 -0
- package/dist/createEngineForProfile.js +42 -0
- package/dist/displaySubtreeTicket.d.ts +25 -0
- package/dist/displaySubtreeTicket.js +76 -0
- package/dist/fontContentLoader.d.ts +6 -0
- package/dist/fontContentLoader.js +298 -0
- package/dist/fontContentTypes.d.ts +34 -0
- package/dist/fontContentTypes.js +2 -0
- package/dist/gameClock.d.ts +24 -0
- package/dist/gameClock.js +246 -0
- package/dist/gameClockTypes.d.ts +31 -0
- package/dist/gameClockTypes.js +2 -0
- package/dist/gameRun.d.ts +50 -0
- package/dist/gameRun.js +97 -0
- package/dist/gamepad.d.ts +5 -0
- package/dist/gamepad.js +5 -0
- package/dist/gamepadInput.d.ts +4 -0
- package/dist/gamepadInput.js +281 -0
- package/dist/gamepadKeys.d.ts +4 -0
- package/dist/gamepadKeys.js +205 -0
- package/dist/gamepadTypes.d.ts +134 -0
- package/dist/gamepadTypes.js +3 -0
- package/dist/hover.d.ts +4 -0
- package/dist/hover.js +4 -0
- package/dist/hoverInput.d.ts +8 -0
- package/dist/hoverInput.js +503 -0
- package/dist/hoverInputTypes.d.ts +119 -0
- package/dist/hoverInputTypes.js +2 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +20 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +5 -0
- package/dist/inputActions.d.ts +81 -0
- package/dist/inputActions.js +330 -0
- package/dist/internal/contentFactoryState.d.ts +19 -0
- package/dist/internal/contentFactoryState.js +42 -0
- package/dist/internal/mouseInputFactoryState.d.ts +57 -0
- package/dist/internal/mouseInputFactoryState.js +125 -0
- package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
- package/dist/internal/sequenceControllerFactoryState.js +98 -0
- package/dist/internal/textFieldFactoryState.d.ts +11 -0
- package/dist/internal/textFieldFactoryState.js +32 -0
- package/dist/internal/texturedFrameState.d.ts +4 -0
- package/dist/internal/texturedFrameState.js +12 -0
- package/dist/internal/uiFactoryState.d.ts +64 -0
- package/dist/internal/uiFactoryState.js +157 -0
- package/dist/internal/uiRootState.d.ts +67 -0
- package/dist/internal/uiRootState.js +103 -0
- package/dist/keyboardInput.d.ts +12 -0
- package/dist/keyboardInput.js +578 -0
- package/dist/keyboardInputTypes.d.ts +81 -0
- package/dist/keyboardInputTypes.js +2 -0
- package/dist/kit.d.ts +14 -0
- package/dist/kit.js +9 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.js +132 -0
- package/dist/layoutTypes.d.ts +28 -0
- package/dist/layoutTypes.js +2 -0
- package/dist/manifestAssetGroup.d.ts +10 -0
- package/dist/manifestAssetGroup.js +477 -0
- package/dist/manifestResourceState.d.ts +16 -0
- package/dist/manifestResourceState.js +57 -0
- package/dist/manifestResourceTypes.d.ts +25 -0
- package/dist/manifestResourceTypes.js +2 -0
- package/dist/motion.d.ts +33 -0
- package/dist/motion.js +206 -0
- package/dist/mouseInput.d.ts +102 -0
- package/dist/mouseInput.js +562 -0
- package/dist/mouseInputTypes.d.ts +37 -0
- package/dist/mouseInputTypes.js +2 -0
- package/dist/paragraph.d.ts +8 -0
- package/dist/paragraph.js +7 -0
- package/dist/particleEmitter.d.ts +4 -0
- package/dist/particleEmitter.js +292 -0
- package/dist/particleTypes.d.ts +107 -0
- package/dist/particleTypes.js +2 -0
- package/dist/particles.d.ts +4 -0
- package/dist/particles.js +4 -0
- package/dist/physics2d.d.ts +4 -0
- package/dist/physics2d.js +4 -0
- package/dist/physics2dGeometry.d.ts +39 -0
- package/dist/physics2dGeometry.js +230 -0
- package/dist/physics2dTypes.d.ts +167 -0
- package/dist/physics2dTypes.js +2 -0
- package/dist/physics2dWorld.d.ts +4 -0
- package/dist/physics2dWorld.js +623 -0
- package/dist/pointerInput.d.ts +11 -0
- package/dist/pointerInput.js +299 -0
- package/dist/pointerInputTypes.d.ts +38 -0
- package/dist/pointerInputTypes.js +2 -0
- package/dist/random.d.ts +29 -0
- package/dist/random.js +131 -0
- package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
- package/dist/rendering/ownedPreparationFailure2D.js +33 -0
- package/dist/rendering/packSharedDraws2D.d.ts +50 -0
- package/dist/rendering/packSharedDraws2D.js +331 -0
- package/dist/rendering/packedOrientation.d.ts +4 -0
- package/dist/rendering/packedOrientation.js +7 -0
- package/dist/rendering/prepareRectangles2D.d.ts +92 -0
- package/dist/rendering/prepareRectangles2D.js +481 -0
- package/dist/rendering/prepareSharedDraws2D.d.ts +88 -0
- package/dist/rendering/prepareSharedDraws2D.js +652 -0
- package/dist/rendering/preparedBatches2D.d.ts +17 -0
- package/dist/rendering/preparedBatches2D.js +30 -0
- package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
- package/dist/rendering/preparedSharedBatches2D.js +247 -0
- package/dist/rendering/sharedColor2D.d.ts +18 -0
- package/dist/rendering/sharedColor2D.js +68 -0
- package/dist/rendering/sharedEffects2D.d.ts +23 -0
- package/dist/rendering/sharedEffects2D.js +118 -0
- package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
- package/dist/rendering/sharedPreparationRetention2D.js +357 -0
- package/dist/rendering/srgbBytes.d.ts +3 -0
- package/dist/rendering/srgbBytes.js +64 -0
- package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
- package/dist/rendering/texturedPreparationBudget2D.js +81 -0
- package/dist/rendering/world3d/Animation3D.d.ts +95 -0
- package/dist/rendering/world3d/Animation3D.js +380 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +157 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +601 -0
- package/dist/rendering/world3d/Batch3D.d.ts +71 -0
- package/dist/rendering/world3d/Batch3D.js +329 -0
- package/dist/rendering/world3d/Camera3D.d.ts +57 -0
- package/dist/rendering/world3d/Camera3D.js +129 -0
- package/dist/rendering/world3d/Character3D.d.ts +123 -0
- package/dist/rendering/world3d/Character3D.js +303 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +115 -0
- package/dist/rendering/world3d/Cloth3D.js +498 -0
- package/dist/rendering/world3d/Compression3D.d.ts +21 -0
- package/dist/rendering/world3d/Compression3D.js +702 -0
- package/dist/rendering/world3d/Curves3D.d.ts +111 -0
- package/dist/rendering/world3d/Curves3D.js +455 -0
- package/dist/rendering/world3d/Decal3D.d.ts +41 -0
- package/dist/rendering/world3d/Decal3D.js +241 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +85 -0
- package/dist/rendering/world3d/Geometry3D.js +326 -0
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +51 -0
- package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +75 -0
- package/dist/rendering/world3d/Gizmo3D.js +512 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +67 -0
- package/dist/rendering/world3d/Gltf3D.js +976 -0
- package/dist/rendering/world3d/GpuParticles3D.d.ts +107 -0
- package/dist/rendering/world3d/GpuParticles3D.js +400 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +33 -0
- package/dist/rendering/world3d/Hdr3D.js +190 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +75 -0
- package/dist/rendering/world3d/Jelly3D.js +266 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +27 -0
- package/dist/rendering/world3d/Ktx23D.js +112 -0
- package/dist/rendering/world3d/Light3D.d.ts +75 -0
- package/dist/rendering/world3d/Light3D.js +93 -0
- package/dist/rendering/world3d/Material3D.d.ts +243 -0
- package/dist/rendering/world3d/Material3D.js +267 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +108 -0
- package/dist/rendering/world3d/Mesh3D.js +323 -0
- package/dist/rendering/world3d/Meshopt3D.d.ts +12 -0
- package/dist/rendering/world3d/Meshopt3D.js +275 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +173 -0
- package/dist/rendering/world3d/Navigation3D.js +971 -0
- package/dist/rendering/world3d/Object3D.d.ts +107 -0
- package/dist/rendering/world3d/Object3D.js +305 -0
- package/dist/rendering/world3d/Particles3D.d.ts +85 -0
- package/dist/rendering/world3d/Particles3D.js +274 -0
- package/dist/rendering/world3d/Physics3D.d.ts +416 -0
- package/dist/rendering/world3d/Physics3D.js +2835 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +35 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +227 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +39 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +338 -0
- package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
- package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +174 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +534 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +69 -0
- package/dist/rendering/world3d/Ragdoll3D.js +200 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +37 -0
- package/dist/rendering/world3d/Raycast3D.js +246 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +88 -0
- package/dist/rendering/world3d/RenderList3D.js +490 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +20 -0
- package/dist/rendering/world3d/Retarget3D.js +185 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +49 -0
- package/dist/rendering/world3d/Serialize3D.js +607 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +78 -0
- package/dist/rendering/world3d/StateMachine3D.js +277 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +227 -0
- package/dist/rendering/world3d/Terrain3D.js +803 -0
- package/dist/rendering/world3d/Text3D.d.ts +90 -0
- package/dist/rendering/world3d/Text3D.js +558 -0
- package/dist/rendering/world3d/Texture3D.d.ts +133 -0
- package/dist/rendering/world3d/Texture3D.js +252 -0
- package/dist/rendering/world3d/Trail3D.d.ts +59 -0
- package/dist/rendering/world3d/Trail3D.js +193 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +97 -0
- package/dist/rendering/world3d/Vehicle3D.js +226 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +55 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +229 -0
- package/dist/rendering/world3d/Water3D.d.ts +163 -0
- package/dist/rendering/world3d/Water3D.js +606 -0
- package/dist/rendering/world3d/core3D.d.ts +34 -0
- package/dist/rendering/world3d/core3D.js +99 -0
- package/dist/rendering/world3d/debug3D.d.ts +64 -0
- package/dist/rendering/world3d/debug3D.js +257 -0
- package/dist/rendering/world3d/decoders3D.d.ts +42 -0
- package/dist/rendering/world3d/decoders3D.js +133 -0
- package/dist/rendering/world3d/geometries3D.d.ts +99 -0
- package/dist/rendering/world3d/geometries3D.js +605 -0
- package/dist/rendering/world3d/helpers3D.d.ts +65 -0
- package/dist/rendering/world3d/helpers3D.js +177 -0
- package/dist/rendering/world3d/index.d.ts +91 -0
- package/dist/rendering/world3d/index.js +56 -0
- package/dist/rendering/world3d/math3D.d.ts +78 -0
- package/dist/rendering/world3d/math3D.js +640 -0
- package/dist/rendering/world3d/primitives3D.d.ts +60 -0
- package/dist/rendering/world3d/primitives3D.js +196 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +6 -0
- package/dist/saveStore.d.ts +56 -0
- package/dist/saveStore.js +163 -0
- package/dist/semanticList.d.ts +122 -0
- package/dist/semanticList.js +174 -0
- package/dist/semanticTree.d.ts +10 -0
- package/dist/semanticTree.js +532 -0
- package/dist/semanticTypes.d.ts +167 -0
- package/dist/semanticTypes.js +2 -0
- package/dist/semantics.d.ts +6 -0
- package/dist/semantics.js +5 -0
- package/dist/sequencePlayback.d.ts +19 -0
- package/dist/sequencePlayback.js +391 -0
- package/dist/sequencePlaybackTypes.d.ts +21 -0
- package/dist/sequencePlaybackTypes.js +2 -0
- package/dist/sequenceTargetClaims.d.ts +10 -0
- package/dist/sequenceTargetClaims.js +31 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/startEngine.d.ts +5 -0
- package/dist/startEngine.js +31 -0
- package/dist/surfaceOwnership.d.ts +3 -0
- package/dist/surfaceOwnership.js +15 -0
- package/dist/text.d.ts +23 -0
- package/dist/text.js +4 -0
- package/dist/textField.d.ts +6 -0
- package/dist/textField.js +6 -0
- package/dist/tileMapDraw.d.ts +7 -0
- package/dist/tileMapDraw.js +310 -0
- package/dist/tiledImport.d.ts +9 -0
- package/dist/tiledImport.js +357 -0
- package/dist/tilemap.d.ts +5 -0
- package/dist/tilemap.js +5 -0
- package/dist/tilemapTypes.d.ts +169 -0
- package/dist/tilemapTypes.js +2 -0
- package/dist/tween.d.ts +15 -0
- package/dist/tween.js +329 -0
- package/dist/tweenTypes.d.ts +27 -0
- package/dist/tweenTypes.js +2 -0
- package/dist/ui/controlKeys.d.ts +109 -0
- package/dist/ui/controlKeys.js +249 -0
- package/dist/ui/controls.d.ts +52 -0
- package/dist/ui/controls.js +288 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +11 -0
- package/dist/ui/keyboardFocus.d.ts +32 -0
- package/dist/ui/keyboardFocus.js +146 -0
- package/dist/ui/layerTypes.d.ts +91 -0
- package/dist/ui/layerTypes.js +2 -0
- package/dist/ui/layers.d.ts +4 -0
- package/dist/ui/layers.js +586 -0
- package/dist/ui/leafContent.d.ts +21 -0
- package/dist/ui/leafContent.js +136 -0
- package/dist/ui/rangeControl.d.ts +50 -0
- package/dist/ui/rangeControl.js +167 -0
- package/dist/ui/scrollControl.d.ts +72 -0
- package/dist/ui/scrollControl.js +218 -0
- package/dist/ui/stateControls.d.ts +82 -0
- package/dist/ui/stateControls.js +328 -0
- package/dist/ui/textEditor.d.ts +53 -0
- package/dist/ui/textEditor.js +370 -0
- package/dist/ui/textEditorTypes.d.ts +78 -0
- package/dist/ui/textEditorTypes.js +2 -0
- package/dist/ui/textFieldControl.d.ts +96 -0
- package/dist/ui/textFieldControl.js +259 -0
- package/dist/ui/theme.d.ts +59 -0
- package/dist/ui/theme.js +165 -0
- package/dist/ui/types.d.ts +265 -0
- package/dist/ui/types.js +2 -0
- package/dist/ui/uiRoot.d.ts +4 -0
- package/dist/ui/uiRoot.js +1497 -0
- package/dist/ui/uiRootDisplay.d.ts +46 -0
- package/dist/ui/uiRootDisplay.js +148 -0
- package/dist/ui/uiRootModel.d.ts +112 -0
- package/dist/ui/uiRootModel.js +60 -0
- package/dist/ui/virtualList.d.ts +20 -0
- package/dist/ui/virtualList.js +105 -0
- package/dist/video.d.ts +4 -0
- package/dist/video.js +4 -0
- package/dist/videoPlayer.d.ts +4 -0
- package/dist/videoPlayer.js +215 -0
- package/dist/videoTypes.d.ts +74 -0
- package/dist/videoTypes.js +2 -0
- package/dist/web/BrowserAssetBundle.d.ts +39 -0
- package/dist/web/BrowserAssetBundle.js +136 -0
- package/dist/web/BrowserAudio.d.ts +41 -0
- package/dist/web/BrowserAudio.js +473 -0
- package/dist/web/BrowserFrameLoop.d.ts +65 -0
- package/dist/web/BrowserFrameLoop.js +125 -0
- package/dist/web/BrowserGame.d.ts +112 -0
- package/dist/web/BrowserGame.js +352 -0
- package/dist/web/BrowserGamepadInput.d.ts +35 -0
- package/dist/web/BrowserGamepadInput.js +134 -0
- package/dist/web/BrowserHoverInput.d.ts +24 -0
- package/dist/web/BrowserHoverInput.js +266 -0
- package/dist/web/BrowserImageTextures.d.ts +66 -0
- package/dist/web/BrowserImageTextures.js +169 -0
- package/dist/web/BrowserInputActions.d.ts +53 -0
- package/dist/web/BrowserInputActions.js +342 -0
- package/dist/web/BrowserKeyboardInput.d.ts +4 -0
- package/dist/web/BrowserKeyboardInput.js +223 -0
- package/dist/web/BrowserPlay.d.ts +289 -0
- package/dist/web/BrowserPlay.js +1301 -0
- package/dist/web/BrowserPointerInput.d.ts +4 -0
- package/dist/web/BrowserPointerInput.js +511 -0
- package/dist/web/BrowserSemantics.d.ts +34 -0
- package/dist/web/BrowserSemantics.js +418 -0
- package/dist/web/BrowserStatsPanel.d.ts +46 -0
- package/dist/web/BrowserStatsPanel.js +137 -0
- package/dist/web/BrowserStorage.d.ts +33 -0
- package/dist/web/BrowserStorage.js +132 -0
- package/dist/web/BrowserTextEditor.d.ts +49 -0
- package/dist/web/BrowserTextEditor.js +839 -0
- package/dist/web/BrowserTextInput.d.ts +83 -0
- package/dist/web/BrowserTextInput.js +524 -0
- package/dist/web/BrowserTextureProvider.d.ts +52 -0
- package/dist/web/BrowserTextureProvider.js +935 -0
- package/dist/web/BrowserVideo.d.ts +28 -0
- package/dist/web/BrowserVideo.js +211 -0
- package/dist/web/CanvasKitFontSetProvider.d.ts +29 -0
- package/dist/web/CanvasKitFontSetProvider.js +215 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +169 -0
- package/dist/web/CanvasKitParagraphProvider.js +691 -0
- package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
- package/dist/web/CanvasTextRasterProvider.js +312 -0
- package/dist/web/ManifestByteSource.d.ts +147 -0
- package/dist/web/ManifestByteSource.js +974 -0
- package/dist/web/ManifestFontContentLoader.d.ts +12 -0
- package/dist/web/ManifestFontContentLoader.js +30 -0
- package/dist/web/MouseInput.d.ts +4 -0
- package/dist/web/MouseInput.js +218 -0
- package/dist/web/WebGL2Host.d.ts +5 -0
- package/dist/web/WebGL2Host.js +2672 -0
- package/dist/web/WebGPUHost.d.ts +87 -0
- package/dist/web/WebGPUHost.js +3349 -0
- package/dist/web/audio.d.ts +3 -0
- package/dist/web/audio.js +4 -0
- package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
- package/dist/web/canvasKitParagraphGeometry.js +83 -0
- package/dist/web/editing.d.ts +5 -0
- package/dist/web/editing.js +4 -0
- package/dist/web/editorFonts.d.ts +50 -0
- package/dist/web/editorFonts.js +297 -0
- package/dist/web/game.d.ts +5 -0
- package/dist/web/game.js +6 -0
- package/dist/web/gamepad.d.ts +3 -0
- package/dist/web/gamepad.js +4 -0
- package/dist/web/hover.d.ts +3 -0
- package/dist/web/hover.js +4 -0
- package/dist/web/image.d.ts +4 -0
- package/dist/web/image.js +4 -0
- package/dist/web/imageProjections2D.d.ts +14 -0
- package/dist/web/imageProjections2D.js +2 -0
- package/dist/web/input.d.ts +6 -0
- package/dist/web/input.js +4 -0
- package/dist/web/keyboard.d.ts +3 -0
- package/dist/web/keyboard.js +3 -0
- package/dist/web/kit.d.ts +10 -0
- package/dist/web/kit.js +7 -0
- package/dist/web/loop.d.ts +3 -0
- package/dist/web/loop.js +4 -0
- package/dist/web/paragraph.d.ts +6 -0
- package/dist/web/paragraph.js +4 -0
- package/dist/web/play.d.ts +5 -0
- package/dist/web/play.js +6 -0
- package/dist/web/playSfx.d.ts +36 -0
- package/dist/web/playSfx.js +112 -0
- package/dist/web/pointer.d.ts +3 -0
- package/dist/web/pointer.js +3 -0
- package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
- package/dist/web/prepareSharedSubmission2D.js +57 -0
- package/dist/web/resources.d.ts +27 -0
- package/dist/web/resources.js +96 -0
- package/dist/web/semantics.d.ts +3 -0
- package/dist/web/semantics.js +4 -0
- package/dist/web/sharedDeviceSession.d.ts +64 -0
- package/dist/web/sharedDeviceSession.js +2 -0
- package/dist/web/sharedEffectShaders.d.ts +9 -0
- package/dist/web/sharedEffectShaders.js +165 -0
- package/dist/web/sharedFrameUpload.d.ts +25 -0
- package/dist/web/sharedFrameUpload.js +2 -0
- package/dist/web/sharedHostDeferred.d.ts +7 -0
- package/dist/web/sharedHostDeferred.js +12 -0
- package/dist/web/sharedRetentionLedger.d.ts +85 -0
- package/dist/web/sharedRetentionLedger.js +391 -0
- package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
- package/dist/web/sharedSubmissionStorage2D.js +73 -0
- package/dist/web/sharedWebGL2Arena.d.ts +40 -0
- package/dist/web/sharedWebGL2Arena.js +77 -0
- package/dist/web/sharedWebGL2Options.d.ts +30 -0
- package/dist/web/sharedWebGL2Options.js +96 -0
- package/dist/web/sharedWebGL2Shaders.d.ts +20 -0
- package/dist/web/sharedWebGL2Shaders.js +314 -0
- package/dist/web/sharedWebGPUOptions.d.ts +37 -0
- package/dist/web/sharedWebGPUOptions.js +126 -0
- package/dist/web/text.d.ts +3 -0
- package/dist/web/text.js +3 -0
- package/dist/web/textInput.d.ts +3 -0
- package/dist/web/textInput.js +3 -0
- package/dist/web/video.d.ts +3 -0
- package/dist/web/video.js +4 -0
- package/dist/web/webgl2.d.ts +7 -0
- package/dist/web/webgl2.js +4 -0
- package/dist/web/webgl2LayerState.d.ts +50 -0
- package/dist/web/webgl2LayerState.js +102 -0
- package/dist/web/webgl2Native.d.ts +70 -0
- package/dist/web/webgl2Native.js +568 -0
- package/dist/web/webgl2Types.d.ts +132 -0
- package/dist/web/webgl2Types.js +2 -0
- package/dist/web/webgpu.d.ts +6 -0
- package/dist/web/webgpu.js +2 -0
- package/dist/web/webgpuBindingCache.d.ts +26 -0
- package/dist/web/webgpuBindingCache.js +223 -0
- package/dist/web/webgpuBufferPool.d.ts +51 -0
- package/dist/web/webgpuBufferPool.js +58 -0
- package/dist/web/webgpuImageResidency.d.ts +53 -0
- package/dist/web/webgpuImageResidency.js +61 -0
- package/dist/web/webgpuLifetime.d.ts +45 -0
- package/dist/web/webgpuLifetime.js +64 -0
- package/dist/web/webgpuRetentionPool.d.ts +66 -0
- package/dist/web/webgpuRetentionPool.js +84 -0
- package/dist/web/webgpuSharedPass.d.ts +7 -0
- package/dist/web/webgpuSharedPass.js +211 -0
- package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
- package/dist/web/webgpuSharedResolvePass.js +29 -0
- package/dist/web/world3d/Audio3D.d.ts +68 -0
- package/dist/web/world3d/Audio3D.js +212 -0
- package/dist/web/world3d/BrowserPlay3D.d.ts +182 -0
- package/dist/web/world3d/BrowserPlay3D.js +851 -0
- package/dist/web/world3d/FlyControls3D.d.ts +55 -0
- package/dist/web/world3d/FlyControls3D.js +160 -0
- package/dist/web/world3d/FollowControls3D.d.ts +28 -0
- package/dist/web/world3d/FollowControls3D.js +117 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +55 -0
- package/dist/web/world3d/OrbitControls3D.js +187 -0
- package/dist/web/world3d/TransformControls3D.d.ts +34 -0
- package/dist/web/world3d/TransformControls3D.js +125 -0
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +133 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +1173 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +110 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1915 -0
- package/dist/web/world3d/World3DView.d.ts +51 -0
- package/dist/web/world3d/World3DView.js +77 -0
- package/dist/web/world3d/app3D.d.ts +136 -0
- package/dist/web/world3d/app3D.js +304 -0
- package/dist/web/world3d/assets3D.d.ts +38 -0
- package/dist/web/world3d/assets3D.js +112 -0
- package/dist/web/world3d/atmosphere3D.d.ts +47 -0
- package/dist/web/world3d/atmosphere3D.js +178 -0
- package/dist/web/world3d/frame3D.d.ts +142 -0
- package/dist/web/world3d/frame3D.js +388 -0
- package/dist/web/world3d/gpuResources3D.d.ts +98 -0
- package/dist/web/world3d/gpuResources3D.js +901 -0
- package/dist/web/world3d/host3D.d.ts +23 -0
- package/dist/web/world3d/host3D.js +61 -0
- package/dist/web/world3d/index.d.ts +38 -0
- package/dist/web/world3d/index.js +23 -0
- package/dist/web/world3d/loaders3D.d.ts +26 -0
- package/dist/web/world3d/loaders3D.js +138 -0
- package/dist/web/world3d/markers3D.d.ts +49 -0
- package/dist/web/world3d/markers3D.js +130 -0
- package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
- package/dist/web/world3d/materialWebGL23D.js +218 -0
- package/dist/web/world3d/overlay3D.d.ts +28 -0
- package/dist/web/world3d/overlay3D.js +170 -0
- package/dist/web/world3d/post3D.d.ts +112 -0
- package/dist/web/world3d/post3D.js +459 -0
- package/dist/web/world3d/postWebGL23D.d.ts +24 -0
- package/dist/web/world3d/postWebGL23D.js +237 -0
- package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
- package/dist/web/world3d/postWebGPU3D.js +255 -0
- package/dist/web/world3d/probe3D.d.ts +14 -0
- package/dist/web/world3d/probe3D.js +66 -0
- package/dist/web/world3d/shaders3D.d.ts +43 -0
- package/dist/web/world3d/shaders3D.js +851 -0
- package/dist/web/world3d/stats3D.d.ts +31 -0
- package/dist/web/world3d/stats3D.js +80 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +66 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
- package/dist/web/world3d/webgpu.d.ts +35 -0
- package/dist/web/world3d/webgpu.js +22 -0
- package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
- package/dist/web/world3d/webgpuPacking3D.js +85 -0
- package/dist/web/world3d/wgsl3D.d.ts +68 -0
- package/dist/web/world3d/wgsl3D.js +781 -0
- package/package.json +220 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
2
|
+
export declare const PHYSICS_HULL3D_LIMITS: Readonly<{
|
|
3
|
+
readonly maxPoints: 64;
|
|
4
|
+
readonly maxInputPoints: 1048576;
|
|
5
|
+
}>;
|
|
6
|
+
export declare class ConvexHullShape3D {
|
|
7
|
+
/** Corner points, three floats each, around the body origin. */
|
|
8
|
+
readonly points: Float32Array;
|
|
9
|
+
/** Face planes as [nx, ny, nz, d] with unit outward normals; inside is n . p + d < 0. */
|
|
10
|
+
readonly planes: Float32Array;
|
|
11
|
+
/** Distance from the origin to the farthest corner. */
|
|
12
|
+
readonly radius: number;
|
|
13
|
+
/** Half extents of the axis-aligned box around the points. */
|
|
14
|
+
readonly halfExtents: readonly [number, number, number];
|
|
15
|
+
/** Edges as pairs of corner indices. */
|
|
16
|
+
readonly edges: Uint8Array;
|
|
17
|
+
/** Radius of the largest sphere around the origin that fits inside. */
|
|
18
|
+
readonly innerRadius: number;
|
|
19
|
+
/**
|
|
20
|
+
* @param points Flat [x, y, z, ...] corner candidates. Interior points are
|
|
21
|
+
* dropped; more than 64 corners are reduced to the 64 most extreme ones.
|
|
22
|
+
* The points should surround the origin, which acts as the center of mass.
|
|
23
|
+
*/
|
|
24
|
+
constructor(points: ArrayLike<number>);
|
|
25
|
+
/**
|
|
26
|
+
* Largest signed plane distance of a local point: negative inside, and the
|
|
27
|
+
* penetration depth when negated. Writes that plane's normal.
|
|
28
|
+
*/
|
|
29
|
+
signedDistance(x: number, y: number, z: number, normal: number[]): number;
|
|
30
|
+
/** Distance along a local unit ray to the solid, or -1. Writes the entry face normal. */
|
|
31
|
+
raycast(ox: number, oy: number, oz: number, dx: number, dy: number, dz: number, limit: number, normal: number[]): number;
|
|
32
|
+
}
|
|
33
|
+
/** Build a convex hull shape from a geometry's vertices, or from a flat list of points. */
|
|
34
|
+
export declare function createConvexHullShape3D(source: Geometry3D | ArrayLike<number>): ConvexHullShape3D;
|
|
35
|
+
//# sourceMappingURL=PhysicsHull3D.d.ts.map
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Convex hull collision shape: a closed convex solid described by its corner
|
|
3
|
+
// points and the outward planes of its faces. It fills the gap between boxes
|
|
4
|
+
// and full triangle meshes for moving props such as rocks, crates with
|
|
5
|
+
// bevels and furniture.
|
|
6
|
+
import { World3DError } from './core3D.js';
|
|
7
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
8
|
+
export const PHYSICS_HULL3D_LIMITS = Object.freeze({ maxPoints: 64, maxInputPoints: 1048576 });
|
|
9
|
+
export class ConvexHullShape3D {
|
|
10
|
+
/** Corner points, three floats each, around the body origin. */
|
|
11
|
+
points;
|
|
12
|
+
/** Face planes as [nx, ny, nz, d] with unit outward normals; inside is n . p + d < 0. */
|
|
13
|
+
planes;
|
|
14
|
+
/** Distance from the origin to the farthest corner. */
|
|
15
|
+
radius;
|
|
16
|
+
/** Half extents of the axis-aligned box around the points. */
|
|
17
|
+
halfExtents;
|
|
18
|
+
/** Edges as pairs of corner indices. */
|
|
19
|
+
edges;
|
|
20
|
+
/** Radius of the largest sphere around the origin that fits inside. */
|
|
21
|
+
innerRadius;
|
|
22
|
+
/**
|
|
23
|
+
* @param points Flat [x, y, z, ...] corner candidates. Interior points are
|
|
24
|
+
* dropped; more than 64 corners are reduced to the 64 most extreme ones.
|
|
25
|
+
* The points should surround the origin, which acts as the center of mass.
|
|
26
|
+
*/
|
|
27
|
+
constructor(points) {
|
|
28
|
+
if (!points || points.length < 12 || points.length % 3 !== 0)
|
|
29
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'hull points');
|
|
30
|
+
if (points.length / 3 > PHYSICS_HULL3D_LIMITS.maxInputPoints)
|
|
31
|
+
throw new World3DError('WORLD3D_BUDGET', 'hull points');
|
|
32
|
+
// Weld duplicates first.
|
|
33
|
+
const unique = [], seen = new Set();
|
|
34
|
+
for (let i = 0; i < points.length; i += 3) {
|
|
35
|
+
const x = points[i], y = points[i + 1], z = points[i + 2];
|
|
36
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
|
|
37
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'hull points');
|
|
38
|
+
const key = Math.round(x * 1e4) + ',' + Math.round(y * 1e4) + ',' + Math.round(z * 1e4);
|
|
39
|
+
if (!seen.has(key)) {
|
|
40
|
+
seen.add(key);
|
|
41
|
+
unique.push(x, y, z);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let candidates = unique;
|
|
45
|
+
if (unique.length / 3 > PHYSICS_HULL3D_LIMITS.maxPoints) {
|
|
46
|
+
// Keep the points that reach farthest along directions spread evenly over the sphere.
|
|
47
|
+
const picked = new Set(), directions = PHYSICS_HULL3D_LIMITS.maxPoints;
|
|
48
|
+
for (let k = 0; k < directions; k++) {
|
|
49
|
+
const y = 1 - ((k + 0.5) * 2) / directions, ring = Math.sqrt(1 - y * y), angle = k * 2.399963, dx = Math.cos(angle) * ring, dz = Math.sin(angle) * ring;
|
|
50
|
+
let best = 0, reach = -Infinity;
|
|
51
|
+
for (let i = 0; i < unique.length; i += 3) {
|
|
52
|
+
const d = unique[i] * dx + unique[i + 1] * y + unique[i + 2] * dz;
|
|
53
|
+
if (d > reach) {
|
|
54
|
+
reach = d;
|
|
55
|
+
best = i;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
picked.add(best);
|
|
59
|
+
}
|
|
60
|
+
candidates = [];
|
|
61
|
+
for (const i of picked)
|
|
62
|
+
candidates.push(unique[i], unique[i + 1], unique[i + 2]);
|
|
63
|
+
}
|
|
64
|
+
const count = candidates.length / 3, planes = [], used = new Set();
|
|
65
|
+
// A triple of points spans a face when every other point lies on one side of its plane.
|
|
66
|
+
for (let a = 0; a < count; a++)
|
|
67
|
+
for (let b = a + 1; b < count; b++)
|
|
68
|
+
for (let c = b + 1; c < count; c++) {
|
|
69
|
+
const ax = candidates[a * 3], ay = candidates[a * 3 + 1], az = candidates[a * 3 + 2];
|
|
70
|
+
const ux = candidates[b * 3] - ax, uy = candidates[b * 3 + 1] - ay, uz = candidates[b * 3 + 2] - az, vx = candidates[c * 3] - ax, vy = candidates[c * 3 + 1] - ay, vz = candidates[c * 3 + 2] - az;
|
|
71
|
+
let nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;
|
|
72
|
+
const length = Math.hypot(nx, ny, nz);
|
|
73
|
+
if (length < 1e-9)
|
|
74
|
+
continue;
|
|
75
|
+
nx /= length;
|
|
76
|
+
ny /= length;
|
|
77
|
+
nz /= length;
|
|
78
|
+
let d = -(nx * ax + ny * ay + nz * az), front = false, back = false;
|
|
79
|
+
for (let i = 0; i < count && !(front && back); i++) {
|
|
80
|
+
const side = nx * candidates[i * 3] + ny * candidates[i * 3 + 1] + nz * candidates[i * 3 + 2] + d;
|
|
81
|
+
if (side > 1e-5)
|
|
82
|
+
front = true;
|
|
83
|
+
else if (side < -1e-5)
|
|
84
|
+
back = true;
|
|
85
|
+
}
|
|
86
|
+
if (front && back)
|
|
87
|
+
continue;
|
|
88
|
+
if (!front && !back)
|
|
89
|
+
continue; // every point is coplanar: no volume
|
|
90
|
+
if (front) {
|
|
91
|
+
nx = -nx;
|
|
92
|
+
ny = -ny;
|
|
93
|
+
nz = -nz;
|
|
94
|
+
d = -d;
|
|
95
|
+
}
|
|
96
|
+
used.add(a);
|
|
97
|
+
used.add(b);
|
|
98
|
+
used.add(c);
|
|
99
|
+
let known = false;
|
|
100
|
+
for (let i = 0; i < planes.length && !known; i += 4)
|
|
101
|
+
known =
|
|
102
|
+
planes[i] * nx + planes[i + 1] * ny + planes[i + 2] * nz > 0.99999 &&
|
|
103
|
+
Math.abs(planes[i + 3] - d) < 1e-4;
|
|
104
|
+
if (!known)
|
|
105
|
+
planes.push(nx, ny, nz, d);
|
|
106
|
+
}
|
|
107
|
+
if (planes.length < 16)
|
|
108
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'hull points do not enclose a volume');
|
|
109
|
+
const corners = [];
|
|
110
|
+
for (const i of [...used].sort((x, y) => x - y))
|
|
111
|
+
corners.push(candidates[i * 3], candidates[i * 3 + 1], candidates[i * 3 + 2]);
|
|
112
|
+
this.points = Float32Array.from(corners);
|
|
113
|
+
this.planes = Float32Array.from(planes);
|
|
114
|
+
let radius = 0, hx = 0, hy = 0, hz = 0;
|
|
115
|
+
for (let i = 0; i < corners.length; i += 3) {
|
|
116
|
+
radius = Math.max(radius, Math.hypot(corners[i], corners[i + 1], corners[i + 2]));
|
|
117
|
+
hx = Math.max(hx, Math.abs(corners[i]));
|
|
118
|
+
hy = Math.max(hy, Math.abs(corners[i + 1]));
|
|
119
|
+
hz = Math.max(hz, Math.abs(corners[i + 2]));
|
|
120
|
+
}
|
|
121
|
+
this.radius = radius;
|
|
122
|
+
this.halfExtents = [hx, hy, hz];
|
|
123
|
+
// The corners lying on one face, walked in order around its normal, give that face's edges.
|
|
124
|
+
const edges = [], known = new Set(), total = corners.length / 3, tolerance = 1e-4 * Math.max(1, radius);
|
|
125
|
+
let inner = Infinity;
|
|
126
|
+
for (let f = 0; f < planes.length; f += 4) {
|
|
127
|
+
const nx = planes[f], ny = planes[f + 1], nz = planes[f + 2], d = planes[f + 3];
|
|
128
|
+
inner = Math.min(inner, -d);
|
|
129
|
+
const on = [];
|
|
130
|
+
let cx = 0, cy = 0, cz = 0;
|
|
131
|
+
for (let i = 0; i < total; i++)
|
|
132
|
+
if (Math.abs(nx * corners[i * 3] + ny * corners[i * 3 + 1] + nz * corners[i * 3 + 2] + d) <= tolerance) {
|
|
133
|
+
on.push(i);
|
|
134
|
+
cx += corners[i * 3];
|
|
135
|
+
cy += corners[i * 3 + 1];
|
|
136
|
+
cz += corners[i * 3 + 2];
|
|
137
|
+
}
|
|
138
|
+
if (on.length < 3)
|
|
139
|
+
continue;
|
|
140
|
+
cx /= on.length;
|
|
141
|
+
cy /= on.length;
|
|
142
|
+
cz /= on.length;
|
|
143
|
+
// Two axes spanning the face.
|
|
144
|
+
const first = on[0];
|
|
145
|
+
let ux = corners[first * 3] - cx, uy = corners[first * 3 + 1] - cy, uz = corners[first * 3 + 2] - cz;
|
|
146
|
+
const size = Math.hypot(ux, uy, uz) || 1;
|
|
147
|
+
ux /= size;
|
|
148
|
+
uy /= size;
|
|
149
|
+
uz /= size;
|
|
150
|
+
const vx = ny * uz - nz * uy, vy = nz * ux - nx * uz, vz = nx * uy - ny * ux;
|
|
151
|
+
const angle = (i) => {
|
|
152
|
+
const x = corners[i * 3] - cx, y = corners[i * 3 + 1] - cy, z = corners[i * 3 + 2] - cz;
|
|
153
|
+
return Math.atan2(x * vx + y * vy + z * vz, x * ux + y * uy + z * uz);
|
|
154
|
+
};
|
|
155
|
+
on.sort((a, b) => angle(a) - angle(b));
|
|
156
|
+
for (let i = 0; i < on.length; i++) {
|
|
157
|
+
const a = on[i], b = on[(i + 1) % on.length], key = a < b ? a * 256 + b : b * 256 + a;
|
|
158
|
+
if (!known.has(key)) {
|
|
159
|
+
known.add(key);
|
|
160
|
+
edges.push(a, b);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
this.edges = Uint8Array.from(edges);
|
|
165
|
+
this.innerRadius = Math.max(inner, 0);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Largest signed plane distance of a local point: negative inside, and the
|
|
169
|
+
* penetration depth when negated. Writes that plane's normal.
|
|
170
|
+
*/
|
|
171
|
+
signedDistance(x, y, z, normal) {
|
|
172
|
+
const planes = this.planes;
|
|
173
|
+
let best = -Infinity, at = 0;
|
|
174
|
+
for (let i = 0; i < planes.length; i += 4) {
|
|
175
|
+
const d = planes[i] * x + planes[i + 1] * y + planes[i + 2] * z + planes[i + 3];
|
|
176
|
+
if (d > best) {
|
|
177
|
+
best = d;
|
|
178
|
+
at = i;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
normal[0] = planes[at];
|
|
182
|
+
normal[1] = planes[at + 1];
|
|
183
|
+
normal[2] = planes[at + 2];
|
|
184
|
+
return best;
|
|
185
|
+
}
|
|
186
|
+
/** Distance along a local unit ray to the solid, or -1. Writes the entry face normal. */
|
|
187
|
+
raycast(ox, oy, oz, dx, dy, dz, limit, normal) {
|
|
188
|
+
const planes = this.planes;
|
|
189
|
+
let enter = 0, exit = limit, face = -1;
|
|
190
|
+
for (let i = 0; i < planes.length; i += 4) {
|
|
191
|
+
const along = planes[i] * dx + planes[i + 1] * dy + planes[i + 2] * dz, side = planes[i] * ox + planes[i + 1] * oy + planes[i + 2] * oz + planes[i + 3];
|
|
192
|
+
if (Math.abs(along) < 1e-12) {
|
|
193
|
+
if (side > 0)
|
|
194
|
+
return -1;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const t = -side / along;
|
|
198
|
+
if (along < 0) {
|
|
199
|
+
if (t > enter) {
|
|
200
|
+
enter = t;
|
|
201
|
+
face = i;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else if (t < exit)
|
|
205
|
+
exit = t;
|
|
206
|
+
if (enter > exit)
|
|
207
|
+
return -1;
|
|
208
|
+
}
|
|
209
|
+
if (face < 0)
|
|
210
|
+
return -1; // The ray starts inside.
|
|
211
|
+
normal[0] = planes[face];
|
|
212
|
+
normal[1] = planes[face + 1];
|
|
213
|
+
normal[2] = planes[face + 2];
|
|
214
|
+
return enter;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** Build a convex hull shape from a geometry's vertices, or from a flat list of points. */
|
|
218
|
+
export function createConvexHullShape3D(source) {
|
|
219
|
+
if (source instanceof Geometry3D) {
|
|
220
|
+
const position = source.getAttribute('position');
|
|
221
|
+
if (!position)
|
|
222
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'hull geometry');
|
|
223
|
+
return new ConvexHullShape3D(position.data);
|
|
224
|
+
}
|
|
225
|
+
return new ConvexHullShape3D(source);
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=PhysicsHull3D.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
2
|
+
import { Object3D } from './Object3D.js';
|
|
3
|
+
export declare const PHYSICS_MESH3D_LIMITS: Readonly<{
|
|
4
|
+
readonly maxTriangles: 4194304;
|
|
5
|
+
readonly leafTriangles: 4;
|
|
6
|
+
}>;
|
|
7
|
+
export declare class TriangleMeshShape3D {
|
|
8
|
+
#private;
|
|
9
|
+
/** Vertex positions, three floats each, in the shape's local space. */
|
|
10
|
+
readonly positions: Float32Array;
|
|
11
|
+
/** Vertex indices, three per triangle, reordered for the hierarchy. */
|
|
12
|
+
readonly indices: Uint32Array;
|
|
13
|
+
readonly triangleCount: number;
|
|
14
|
+
/** Local bounds as [minX, minY, minZ, maxX, maxY, maxZ]. */
|
|
15
|
+
readonly bounds: Float32Array<ArrayBuffer>;
|
|
16
|
+
constructor(positions: ArrayLike<number>, indices?: ArrayLike<number>);
|
|
17
|
+
/** Call `visit` with each triangle index whose bounds may touch the box. */
|
|
18
|
+
query(minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number, visit: (triangle: number) => void): void;
|
|
19
|
+
/** Unit normal of a triangle's front side. */
|
|
20
|
+
triangleNormal(triangle: number, out: number[]): number[];
|
|
21
|
+
/**
|
|
22
|
+
* Closest point on a triangle to (x, y, z). Returns true when it lies in
|
|
23
|
+
* the triangle's interior rather than on an edge or a corner.
|
|
24
|
+
*/
|
|
25
|
+
closestPoint(triangle: number, x: number, y: number, z: number, out: number[]): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Distance along a unit ray to the nearest front-facing triangle within
|
|
28
|
+
* `limit`, or -1. Writes that triangle's normal.
|
|
29
|
+
*/
|
|
30
|
+
raycast(ox: number, oy: number, oz: number, dx: number, dy: number, dz: number, limit: number, normal: number[]): number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build a collision mesh from a geometry or the unskinned, non-instanced
|
|
34
|
+
* triangle meshes under an object. Bake their base positions in world space.
|
|
35
|
+
* Use the result as
|
|
36
|
+
* `{type: 'mesh', mesh}` on a static body left at the origin.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createMeshShape3D(source: Geometry3D | Object3D): TriangleMeshShape3D;
|
|
39
|
+
//# sourceMappingURL=PhysicsMesh3D.d.ts.map
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Static triangle-mesh collision shape for level geometry: terrain, floors,
|
|
3
|
+
// walls and props. Triangles are solid on their front (counter-clockwise)
|
|
4
|
+
// side. A bounding-volume hierarchy keeps queries proportional to the
|
|
5
|
+
// triangles actually near the moving body rather than to the whole level.
|
|
6
|
+
import { World3DError } from './core3D.js';
|
|
7
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
8
|
+
import { Mesh3D } from './Mesh3D.js';
|
|
9
|
+
import { Object3D } from './Object3D.js';
|
|
10
|
+
export const PHYSICS_MESH3D_LIMITS = Object.freeze({ maxTriangles: 4194304, leafTriangles: 4 });
|
|
11
|
+
export class TriangleMeshShape3D {
|
|
12
|
+
/** Vertex positions, three floats each, in the shape's local space. */
|
|
13
|
+
positions;
|
|
14
|
+
/** Vertex indices, three per triangle, reordered for the hierarchy. */
|
|
15
|
+
indices;
|
|
16
|
+
triangleCount;
|
|
17
|
+
/** Local bounds as [minX, minY, minZ, maxX, maxY, maxZ]. */
|
|
18
|
+
bounds = new Float32Array(6);
|
|
19
|
+
// Hierarchy nodes: bounds, then either two children (left, left + 1) or a triangle range.
|
|
20
|
+
#nodeBounds;
|
|
21
|
+
#nodeLeft;
|
|
22
|
+
#nodeStart;
|
|
23
|
+
#nodeCount;
|
|
24
|
+
#stack = new Int32Array(64);
|
|
25
|
+
constructor(positions, indices) {
|
|
26
|
+
if (!positions || positions.length < 9 || positions.length % 3 !== 0)
|
|
27
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'mesh positions');
|
|
28
|
+
const vertexCount = positions.length / 3, source = indices ?? Array.from({ length: vertexCount }, (_, i) => i);
|
|
29
|
+
if (source.length < 3 || source.length % 3 !== 0)
|
|
30
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'mesh indices');
|
|
31
|
+
if (source.length / 3 > PHYSICS_MESH3D_LIMITS.maxTriangles)
|
|
32
|
+
throw new World3DError('WORLD3D_BUDGET', 'mesh triangles');
|
|
33
|
+
this.positions = Float32Array.from(positions);
|
|
34
|
+
for (let i = 0; i < this.positions.length; i++)
|
|
35
|
+
if (!Number.isFinite(this.positions[i]))
|
|
36
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'mesh positions');
|
|
37
|
+
// Drop triangles without area: they have no normal and can never be hit.
|
|
38
|
+
const kept = [], p = this.positions;
|
|
39
|
+
for (let i = 0; i < source.length; i += 3) {
|
|
40
|
+
const a = source[i], b = source[i + 1], c = source[i + 2];
|
|
41
|
+
if (!(a >= 0 && a < vertexCount && b >= 0 && b < vertexCount && c >= 0 && c < vertexCount))
|
|
42
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'mesh index range');
|
|
43
|
+
const ux = p[b * 3] - p[a * 3], uy = p[b * 3 + 1] - p[a * 3 + 1], uz = p[b * 3 + 2] - p[a * 3 + 2], vx = p[c * 3] - p[a * 3], vy = p[c * 3 + 1] - p[a * 3 + 1], vz = p[c * 3 + 2] - p[a * 3 + 2];
|
|
44
|
+
if (Math.hypot(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx) > 1e-12)
|
|
45
|
+
kept.push(a, b, c);
|
|
46
|
+
}
|
|
47
|
+
if (kept.length === 0)
|
|
48
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'mesh has no triangles with area');
|
|
49
|
+
const count = (this.triangleCount = kept.length / 3);
|
|
50
|
+
// Per-triangle bounds and centroids drive the median splits.
|
|
51
|
+
const boxes = new Float32Array(count * 6), centers = new Float32Array(count * 3), order = new Uint32Array(count);
|
|
52
|
+
for (let t = 0; t < count; t++) {
|
|
53
|
+
order[t] = t;
|
|
54
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
55
|
+
const a = p[kept[t * 3] * 3 + axis], b = p[kept[t * 3 + 1] * 3 + axis], c = p[kept[t * 3 + 2] * 3 + axis];
|
|
56
|
+
boxes[t * 6 + axis] = Math.min(a, b, c);
|
|
57
|
+
boxes[t * 6 + 3 + axis] = Math.max(a, b, c);
|
|
58
|
+
centers[t * 3 + axis] = (a + b + c) / 3;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const maxNodes = Math.max(2 * count, 2), nodeBounds = new Float32Array(maxNodes * 6), nodeLeft = new Int32Array(maxNodes).fill(-1), nodeStart = new Int32Array(maxNodes), nodeCount = new Int32Array(maxNodes);
|
|
62
|
+
let used = 1;
|
|
63
|
+
const pending = [0];
|
|
64
|
+
nodeStart[0] = 0;
|
|
65
|
+
nodeCount[0] = count;
|
|
66
|
+
while (pending.length > 0) {
|
|
67
|
+
const node = pending.pop(), start = nodeStart[node], size = nodeCount[node];
|
|
68
|
+
let x0 = Infinity, y0 = Infinity, z0 = Infinity, x1 = -Infinity, y1 = -Infinity, z1 = -Infinity, cx0 = Infinity, cy0 = Infinity, cz0 = Infinity, cx1 = -Infinity, cy1 = -Infinity, cz1 = -Infinity;
|
|
69
|
+
for (let i = start; i < start + size; i++) {
|
|
70
|
+
const t = order[i];
|
|
71
|
+
x0 = Math.min(x0, boxes[t * 6]);
|
|
72
|
+
y0 = Math.min(y0, boxes[t * 6 + 1]);
|
|
73
|
+
z0 = Math.min(z0, boxes[t * 6 + 2]);
|
|
74
|
+
x1 = Math.max(x1, boxes[t * 6 + 3]);
|
|
75
|
+
y1 = Math.max(y1, boxes[t * 6 + 4]);
|
|
76
|
+
z1 = Math.max(z1, boxes[t * 6 + 5]);
|
|
77
|
+
cx0 = Math.min(cx0, centers[t * 3]);
|
|
78
|
+
cy0 = Math.min(cy0, centers[t * 3 + 1]);
|
|
79
|
+
cz0 = Math.min(cz0, centers[t * 3 + 2]);
|
|
80
|
+
cx1 = Math.max(cx1, centers[t * 3]);
|
|
81
|
+
cy1 = Math.max(cy1, centers[t * 3 + 1]);
|
|
82
|
+
cz1 = Math.max(cz1, centers[t * 3 + 2]);
|
|
83
|
+
}
|
|
84
|
+
nodeBounds.set([x0, y0, z0, x1, y1, z1], node * 6);
|
|
85
|
+
if (size <= PHYSICS_MESH3D_LIMITS.leafTriangles)
|
|
86
|
+
continue;
|
|
87
|
+
const ex = cx1 - cx0, ey = cy1 - cy0, ez = cz1 - cz0, axis = ex >= ey && ex >= ez ? 0 : ey >= ez ? 1 : 2;
|
|
88
|
+
const middle = axis === 0 ? (cx0 + cx1) / 2 : axis === 1 ? (cy0 + cy1) / 2 : (cz0 + cz1) / 2;
|
|
89
|
+
let i = start, j = start + size - 1;
|
|
90
|
+
while (i <= j) {
|
|
91
|
+
if (centers[order[i] * 3 + axis] < middle)
|
|
92
|
+
i++;
|
|
93
|
+
else {
|
|
94
|
+
const swap = order[i];
|
|
95
|
+
order[i] = order[j];
|
|
96
|
+
order[j] = swap;
|
|
97
|
+
j--;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Coincident centroids cannot be separated; split the range in half instead.
|
|
101
|
+
let leftSize = i - start;
|
|
102
|
+
if (leftSize === 0 || leftSize === size)
|
|
103
|
+
leftSize = size >> 1;
|
|
104
|
+
const left = used;
|
|
105
|
+
used += 2;
|
|
106
|
+
nodeLeft[node] = left;
|
|
107
|
+
nodeStart[left] = start;
|
|
108
|
+
nodeCount[left] = leftSize;
|
|
109
|
+
nodeStart[left + 1] = start + leftSize;
|
|
110
|
+
nodeCount[left + 1] = size - leftSize;
|
|
111
|
+
pending.push(left, left + 1);
|
|
112
|
+
}
|
|
113
|
+
const sorted = new Uint32Array(count * 3);
|
|
114
|
+
for (let i = 0; i < count; i++) {
|
|
115
|
+
const t = order[i];
|
|
116
|
+
sorted[i * 3] = kept[t * 3];
|
|
117
|
+
sorted[i * 3 + 1] = kept[t * 3 + 1];
|
|
118
|
+
sorted[i * 3 + 2] = kept[t * 3 + 2];
|
|
119
|
+
}
|
|
120
|
+
this.indices = sorted;
|
|
121
|
+
this.#nodeBounds = nodeBounds.slice(0, used * 6);
|
|
122
|
+
this.#nodeLeft = nodeLeft.slice(0, used);
|
|
123
|
+
this.#nodeStart = nodeStart.slice(0, used);
|
|
124
|
+
this.#nodeCount = nodeCount.slice(0, used);
|
|
125
|
+
this.bounds.set(this.#nodeBounds.subarray(0, 6));
|
|
126
|
+
}
|
|
127
|
+
/** Call `visit` with each triangle index whose bounds may touch the box. */
|
|
128
|
+
query(minX, minY, minZ, maxX, maxY, maxZ, visit) {
|
|
129
|
+
const bounds = this.#nodeBounds, left = this.#nodeLeft, stack = this.#stack;
|
|
130
|
+
let top = 0;
|
|
131
|
+
stack[top++] = 0;
|
|
132
|
+
while (top > 0) {
|
|
133
|
+
const node = stack[--top], at = node * 6;
|
|
134
|
+
if (bounds[at] > maxX ||
|
|
135
|
+
bounds[at + 3] < minX ||
|
|
136
|
+
bounds[at + 1] > maxY ||
|
|
137
|
+
bounds[at + 4] < minY ||
|
|
138
|
+
bounds[at + 2] > maxZ ||
|
|
139
|
+
bounds[at + 5] < minZ)
|
|
140
|
+
continue;
|
|
141
|
+
const child = left[node];
|
|
142
|
+
if (child >= 0) {
|
|
143
|
+
if (top < 62) {
|
|
144
|
+
stack[top++] = child;
|
|
145
|
+
stack[top++] = child + 1;
|
|
146
|
+
}
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
for (let i = this.#nodeStart[node], end = i + this.#nodeCount[node]; i < end; i++)
|
|
150
|
+
visit(i);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Unit normal of a triangle's front side. */
|
|
154
|
+
triangleNormal(triangle, out) {
|
|
155
|
+
const p = this.positions, a = this.indices[triangle * 3] * 3, b = this.indices[triangle * 3 + 1] * 3, c = this.indices[triangle * 3 + 2] * 3;
|
|
156
|
+
const ux = p[b] - p[a], uy = p[b + 1] - p[a + 1], uz = p[b + 2] - p[a + 2], vx = p[c] - p[a], vy = p[c + 1] - p[a + 1], vz = p[c + 2] - p[a + 2];
|
|
157
|
+
const x = uy * vz - uz * vy, y = uz * vx - ux * vz, z = ux * vy - uy * vx, length = Math.sqrt(x * x + y * y + z * z) || 1;
|
|
158
|
+
out[0] = x / length;
|
|
159
|
+
out[1] = y / length;
|
|
160
|
+
out[2] = z / length;
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Closest point on a triangle to (x, y, z). Returns true when it lies in
|
|
165
|
+
* the triangle's interior rather than on an edge or a corner.
|
|
166
|
+
*/
|
|
167
|
+
closestPoint(triangle, x, y, z, out) {
|
|
168
|
+
const p = this.positions, ia = this.indices[triangle * 3] * 3, ib = this.indices[triangle * 3 + 1] * 3, ic = this.indices[triangle * 3 + 2] * 3;
|
|
169
|
+
const ax = p[ia], ay = p[ia + 1], az = p[ia + 2], bx = p[ib], by = p[ib + 1], bz = p[ib + 2], cx = p[ic], cy = p[ic + 1], cz = p[ic + 2];
|
|
170
|
+
const abx = bx - ax, aby = by - ay, abz = bz - az, acx = cx - ax, acy = cy - ay, acz = cz - az, apx = x - ax, apy = y - ay, apz = z - az;
|
|
171
|
+
const d1 = abx * apx + aby * apy + abz * apz, d2 = acx * apx + acy * apy + acz * apz;
|
|
172
|
+
if (d1 <= 0 && d2 <= 0) {
|
|
173
|
+
out[0] = ax;
|
|
174
|
+
out[1] = ay;
|
|
175
|
+
out[2] = az;
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const bpx = x - bx, bpy = y - by, bpz = z - bz, d3 = abx * bpx + aby * bpy + abz * bpz, d4 = acx * bpx + acy * bpy + acz * bpz;
|
|
179
|
+
if (d3 >= 0 && d4 <= d3) {
|
|
180
|
+
out[0] = bx;
|
|
181
|
+
out[1] = by;
|
|
182
|
+
out[2] = bz;
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const vc = d1 * d4 - d3 * d2;
|
|
186
|
+
if (vc <= 0 && d1 >= 0 && d3 <= 0) {
|
|
187
|
+
const v = d1 / (d1 - d3);
|
|
188
|
+
out[0] = ax + abx * v;
|
|
189
|
+
out[1] = ay + aby * v;
|
|
190
|
+
out[2] = az + abz * v;
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const cpx = x - cx, cpy = y - cy, cpz = z - cz, d5 = abx * cpx + aby * cpy + abz * cpz, d6 = acx * cpx + acy * cpy + acz * cpz;
|
|
194
|
+
if (d6 >= 0 && d5 <= d6) {
|
|
195
|
+
out[0] = cx;
|
|
196
|
+
out[1] = cy;
|
|
197
|
+
out[2] = cz;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
const vb = d5 * d2 - d1 * d6;
|
|
201
|
+
if (vb <= 0 && d2 >= 0 && d6 <= 0) {
|
|
202
|
+
const w = d2 / (d2 - d6);
|
|
203
|
+
out[0] = ax + acx * w;
|
|
204
|
+
out[1] = ay + acy * w;
|
|
205
|
+
out[2] = az + acz * w;
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
const va = d3 * d6 - d5 * d4;
|
|
209
|
+
if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
|
|
210
|
+
const w = (d4 - d3) / (d4 - d3 + (d5 - d6));
|
|
211
|
+
out[0] = bx + (cx - bx) * w;
|
|
212
|
+
out[1] = by + (cy - by) * w;
|
|
213
|
+
out[2] = bz + (cz - bz) * w;
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
const denominator = 1 / (va + vb + vc), v = vb * denominator, w = vc * denominator;
|
|
217
|
+
out[0] = ax + abx * v + acx * w;
|
|
218
|
+
out[1] = ay + aby * v + acy * w;
|
|
219
|
+
out[2] = az + abz * v + acz * w;
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Distance along a unit ray to the nearest front-facing triangle within
|
|
224
|
+
* `limit`, or -1. Writes that triangle's normal.
|
|
225
|
+
*/
|
|
226
|
+
raycast(ox, oy, oz, dx, dy, dz, limit, normal) {
|
|
227
|
+
const bounds = this.#nodeBounds, left = this.#nodeLeft, stack = this.#stack, p = this.positions, indices = this.indices;
|
|
228
|
+
let best = limit, hit = -1, top = 0;
|
|
229
|
+
stack[top++] = 0;
|
|
230
|
+
while (top > 0) {
|
|
231
|
+
const node = stack[--top], at = node * 6;
|
|
232
|
+
// Slab test against the node bounds, clipped to the best hit so far.
|
|
233
|
+
let t0 = 0, t1 = best, outside = false;
|
|
234
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
235
|
+
const origin = axis === 0 ? ox : axis === 1 ? oy : oz, direction = axis === 0 ? dx : axis === 1 ? dy : dz, low = bounds[at + axis], high = bounds[at + 3 + axis];
|
|
236
|
+
// A ray parallel to a slab either stays inside it for its whole length or never enters.
|
|
237
|
+
if (Math.abs(direction) < 1e-12) {
|
|
238
|
+
if (origin < low || origin > high)
|
|
239
|
+
outside = true;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const near = (low - origin) / direction, far = (high - origin) / direction;
|
|
243
|
+
t0 = Math.max(t0, Math.min(near, far));
|
|
244
|
+
t1 = Math.min(t1, Math.max(near, far));
|
|
245
|
+
}
|
|
246
|
+
if (outside)
|
|
247
|
+
continue;
|
|
248
|
+
if (!(t0 <= t1))
|
|
249
|
+
continue;
|
|
250
|
+
const child = left[node];
|
|
251
|
+
if (child >= 0) {
|
|
252
|
+
if (top < 62) {
|
|
253
|
+
stack[top++] = child;
|
|
254
|
+
stack[top++] = child + 1;
|
|
255
|
+
}
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
for (let i = this.#nodeStart[node], end = i + this.#nodeCount[node]; i < end; i++) {
|
|
259
|
+
const a = indices[i * 3] * 3, b = indices[i * 3 + 1] * 3, c = indices[i * 3 + 2] * 3;
|
|
260
|
+
const e1x = p[b] - p[a], e1y = p[b + 1] - p[a + 1], e1z = p[b + 2] - p[a + 2], e2x = p[c] - p[a], e2y = p[c + 1] - p[a + 1], e2z = p[c + 2] - p[a + 2];
|
|
261
|
+
const px = dy * e2z - dz * e2y, py = dz * e2x - dx * e2z, pz = dx * e2y - dy * e2x, determinant = e1x * px + e1y * py + e1z * pz;
|
|
262
|
+
// A positive determinant means the ray meets the front side.
|
|
263
|
+
if (determinant < 1e-12)
|
|
264
|
+
continue;
|
|
265
|
+
const tx = ox - p[a], ty = oy - p[a + 1], tz = oz - p[a + 2], u = tx * px + ty * py + tz * pz;
|
|
266
|
+
if (u < 0 || u > determinant)
|
|
267
|
+
continue;
|
|
268
|
+
const qx = ty * e1z - tz * e1y, qy = tz * e1x - tx * e1z, qz = tx * e1y - ty * e1x, v = dx * qx + dy * qy + dz * qz;
|
|
269
|
+
if (v < 0 || u + v > determinant)
|
|
270
|
+
continue;
|
|
271
|
+
const t = (e2x * qx + e2y * qy + e2z * qz) / determinant;
|
|
272
|
+
if (t >= 0 && t < best) {
|
|
273
|
+
best = t;
|
|
274
|
+
hit = i;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (hit < 0)
|
|
279
|
+
return -1;
|
|
280
|
+
this.triangleNormal(hit, normal);
|
|
281
|
+
return best;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Build a collision mesh from a geometry or the unskinned, non-instanced
|
|
286
|
+
* triangle meshes under an object. Bake their base positions in world space.
|
|
287
|
+
* Use the result as
|
|
288
|
+
* `{type: 'mesh', mesh}` on a static body left at the origin.
|
|
289
|
+
*/
|
|
290
|
+
export function createMeshShape3D(source) {
|
|
291
|
+
const positions = [], indices = [];
|
|
292
|
+
const append = (geometry, m) => {
|
|
293
|
+
if (geometry.topology !== 'triangles')
|
|
294
|
+
return;
|
|
295
|
+
const attribute = geometry.getAttribute('position');
|
|
296
|
+
if (!attribute)
|
|
297
|
+
return;
|
|
298
|
+
const data = attribute.data, base = positions.length / 3;
|
|
299
|
+
for (let i = 0; i < data.length; i += 3) {
|
|
300
|
+
const x = data[i], y = data[i + 1], z = data[i + 2];
|
|
301
|
+
if (m)
|
|
302
|
+
positions.push(m[0] * x + m[4] * y + m[8] * z + m[12], m[1] * x + m[5] * y + m[9] * z + m[13], m[2] * x + m[6] * y + m[10] * z + m[14]);
|
|
303
|
+
else
|
|
304
|
+
positions.push(x, y, z);
|
|
305
|
+
}
|
|
306
|
+
const index = geometry.index?.data, count = index ? index.length : attribute.count;
|
|
307
|
+
// A mirrored transform reverses winding; swap two corners to keep the front side outward.
|
|
308
|
+
const mirrored = m !== undefined &&
|
|
309
|
+
m[0] * (m[5] * m[10] - m[6] * m[9]) -
|
|
310
|
+
m[4] * (m[1] * m[10] - m[2] * m[9]) +
|
|
311
|
+
m[8] * (m[1] * m[6] - m[2] * m[5]) <
|
|
312
|
+
0;
|
|
313
|
+
for (let i = 0; i + 2 < count; i += 3) {
|
|
314
|
+
const a = base + (index ? index[i] : i), b = base + (index ? index[i + 1] : i + 1), c = base + (index ? index[i + 2] : i + 2);
|
|
315
|
+
if (mirrored)
|
|
316
|
+
indices.push(a, c, b);
|
|
317
|
+
else
|
|
318
|
+
indices.push(a, b, c);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
if (source instanceof Geometry3D)
|
|
322
|
+
append(source, undefined);
|
|
323
|
+
else if (source instanceof Object3D) {
|
|
324
|
+
// Refresh the whole tree so baking from a subtree also updates moved ancestors and siblings.
|
|
325
|
+
let root = source;
|
|
326
|
+
while (root.parent)
|
|
327
|
+
root = root.parent;
|
|
328
|
+
root.updateWorldMatrices(true);
|
|
329
|
+
source.traverse(node => {
|
|
330
|
+
if (node instanceof Mesh3D && !node.isInstanced && node.skeleton === undefined)
|
|
331
|
+
append(node.geometry, node.matrixWorld);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
else
|
|
335
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'mesh shape source');
|
|
336
|
+
return new TriangleMeshShape3D(positions, indices);
|
|
337
|
+
}
|
|
338
|
+
//# sourceMappingURL=PhysicsMesh3D.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RigidBody3D } from './Physics3D.js';
|
|
2
|
+
/**
|
|
3
|
+
* Bodies that never move, kept in a hierarchy of boxes so that a moving body, a ray or a
|
|
4
|
+
* sweep only looks at the ones nearby. It is rebuilt when a static body is added, removed or moved.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StaticTree {
|
|
7
|
+
#private;
|
|
8
|
+
readonly bodies: RigidBody3D[];
|
|
9
|
+
add(body: RigidBody3D): void;
|
|
10
|
+
remove(body: RigidBody3D): void;
|
|
11
|
+
touch(): void;
|
|
12
|
+
private build;
|
|
13
|
+
private split;
|
|
14
|
+
/** Call `visit` for every static body whose bounds meet the box. */
|
|
15
|
+
query(lx: number, ly: number, lz: number, hx: number, hy: number, hz: number, visit: (body: RigidBody3D) => void): void;
|
|
16
|
+
/** Call `visit` for static bodies whose bounds the ray crosses within the distance `visit` returns. */
|
|
17
|
+
ray(o: ArrayLike<number>, d: ArrayLike<number>, limit: number, visit: (body: RigidBody3D, limit: number) => number): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Distance along a unit ray to a body, or -1. Writes the surface normal at the hit.
|
|
21
|
+
* The caller supplies the existing mesh-normal scratch, also reused by compound parts.
|
|
22
|
+
*/
|
|
23
|
+
export declare function rayShape(body: RigidBody3D, o: number[], d: number[], limit: number, normal: number[], meshNormal: number[]): number;
|
|
24
|
+
//# sourceMappingURL=PhysicsQueries3D.d.ts.map
|