@egret/engine 0.0.0-stage → 7.0.2
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 +469 -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 +48 -0
- package/dist/animation/sequenceResetTypes.js +2 -0
- package/dist/animation/types.d.ts +75 -0
- package/dist/animation/types.js +2 -0
- package/dist/assetBundle.d.ts +54 -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 +17 -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 +47 -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 +246 -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 +31 -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 +112 -0
- package/dist/bitmapFontTypes.js +2 -0
- package/dist/bitmapResourceSlot.d.ts +26 -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 +419 -0
- package/dist/cameraTypes.d.ts +126 -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 +35 -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 +45 -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 +39 -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 +37 -0
- package/dist/gameClockTypes.js +2 -0
- package/dist/gameRun.d.ts +53 -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 +142 -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 +129 -0
- package/dist/hoverInputTypes.js +2 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +21 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +5 -0
- package/dist/inputActions.d.ts +86 -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 +68 -0
- package/dist/internal/uiFactoryState.js +173 -0
- package/dist/internal/uiRootState.d.ts +67 -0
- package/dist/internal/uiRootState.js +103 -0
- package/dist/keyboardInput.d.ts +13 -0
- package/dist/keyboardInput.js +579 -0
- package/dist/keyboardInputTypes.d.ts +93 -0
- package/dist/keyboardInputTypes.js +2 -0
- package/dist/kit.d.ts +16 -0
- package/dist/kit.js +10 -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 +17 -0
- package/dist/manifestResourceState.js +58 -0
- package/dist/manifestResourceTypes.d.ts +26 -0
- package/dist/manifestResourceTypes.js +2 -0
- package/dist/motion.d.ts +35 -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 +41 -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 +300 -0
- package/dist/particleTypes.d.ts +115 -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 +221 -0
- package/dist/physics2dTypes.js +2 -0
- package/dist/physics2dWorld.d.ts +4 -0
- package/dist/physics2dWorld.js +823 -0
- package/dist/pointerInput.d.ts +12 -0
- package/dist/pointerInput.js +300 -0
- package/dist/pointerInputTypes.d.ts +41 -0
- package/dist/pointerInputTypes.js +2 -0
- package/dist/random.d.ts +30 -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 +379 -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 +90 -0
- package/dist/rendering/prepareSharedDraws2D.js +663 -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 +52 -0
- package/dist/rendering/sharedColor2D.js +191 -0
- package/dist/rendering/sharedEffects2D.d.ts +23 -0
- package/dist/rendering/sharedEffects2D.js +126 -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 +104 -0
- package/dist/rendering/world3d/Animation3D.js +384 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +163 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +603 -0
- package/dist/rendering/world3d/Batch3D.d.ts +75 -0
- package/dist/rendering/world3d/Batch3D.js +332 -0
- package/dist/rendering/world3d/Camera3D.d.ts +62 -0
- package/dist/rendering/world3d/Camera3D.js +132 -0
- package/dist/rendering/world3d/Character3D.d.ts +127 -0
- package/dist/rendering/world3d/Character3D.js +305 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +130 -0
- package/dist/rendering/world3d/Cloth3D.js +503 -0
- package/dist/rendering/world3d/Compression3D.d.ts +22 -0
- package/dist/rendering/world3d/Compression3D.js +703 -0
- package/dist/rendering/world3d/Curves3D.d.ts +119 -0
- package/dist/rendering/world3d/Curves3D.js +460 -0
- package/dist/rendering/world3d/Decal3D.d.ts +43 -0
- package/dist/rendering/world3d/Decal3D.js +242 -0
- package/dist/rendering/world3d/Export3D.d.ts +13 -0
- package/dist/rendering/world3d/Export3D.js +263 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +95 -0
- package/dist/rendering/world3d/Geometry3D.js +335 -0
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +53 -0
- package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +80 -0
- package/dist/rendering/world3d/Gizmo3D.js +514 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +73 -0
- package/dist/rendering/world3d/Gltf3D.js +996 -0
- package/dist/rendering/world3d/GpuParticles3D.d.ts +109 -0
- package/dist/rendering/world3d/GpuParticles3D.js +401 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +35 -0
- package/dist/rendering/world3d/Hdr3D.js +191 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +77 -0
- package/dist/rendering/world3d/Jelly3D.js +267 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +30 -0
- package/dist/rendering/world3d/Ktx23D.js +112 -0
- package/dist/rendering/world3d/Light3D.d.ts +84 -0
- package/dist/rendering/world3d/Light3D.js +97 -0
- package/dist/rendering/world3d/Material3D.d.ts +253 -0
- package/dist/rendering/world3d/Material3D.js +269 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +112 -0
- package/dist/rendering/world3d/Mesh3D.js +337 -0
- package/dist/rendering/world3d/Meshopt3D.d.ts +15 -0
- package/dist/rendering/world3d/Meshopt3D.js +276 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +213 -0
- package/dist/rendering/world3d/Navigation3D.js +1043 -0
- package/dist/rendering/world3d/Object3D.d.ts +118 -0
- package/dist/rendering/world3d/Object3D.js +315 -0
- package/dist/rendering/world3d/Particles3D.d.ts +90 -0
- package/dist/rendering/world3d/Particles3D.js +277 -0
- package/dist/rendering/world3d/Physics3D.d.ts +430 -0
- package/dist/rendering/world3d/Physics3D.js +2840 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +37 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +229 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +41 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +340 -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 +179 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +536 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +74 -0
- package/dist/rendering/world3d/Ragdoll3D.js +202 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +40 -0
- package/dist/rendering/world3d/Raycast3D.js +247 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +91 -0
- package/dist/rendering/world3d/RenderList3D.js +502 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +21 -0
- package/dist/rendering/world3d/Retarget3D.js +185 -0
- package/dist/rendering/world3d/Rig3D.d.ts +57 -0
- package/dist/rendering/world3d/Rig3D.js +219 -0
- package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
- package/dist/rendering/world3d/Sdf3D.js +1136 -0
- package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
- package/dist/rendering/world3d/SdfLod3D.js +56 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +66 -0
- package/dist/rendering/world3d/Serialize3D.js +629 -0
- package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
- package/dist/rendering/world3d/Simplify3D.js +426 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +87 -0
- package/dist/rendering/world3d/StateMachine3D.js +280 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +248 -0
- package/dist/rendering/world3d/Terrain3D.js +827 -0
- package/dist/rendering/world3d/Text3D.d.ts +95 -0
- package/dist/rendering/world3d/Text3D.js +560 -0
- package/dist/rendering/world3d/Texture3D.d.ts +148 -0
- package/dist/rendering/world3d/Texture3D.js +270 -0
- package/dist/rendering/world3d/Trail3D.d.ts +62 -0
- package/dist/rendering/world3d/Trail3D.js +195 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +102 -0
- package/dist/rendering/world3d/Vehicle3D.js +228 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +57 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +230 -0
- package/dist/rendering/world3d/Water3D.d.ts +165 -0
- package/dist/rendering/world3d/Water3D.js +607 -0
- package/dist/rendering/world3d/core3D.d.ts +36 -0
- package/dist/rendering/world3d/core3D.js +99 -0
- package/dist/rendering/world3d/debug3D.d.ts +69 -0
- package/dist/rendering/world3d/debug3D.js +262 -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 +111 -0
- package/dist/rendering/world3d/geometries3D.js +610 -0
- package/dist/rendering/world3d/helpers3D.d.ts +67 -0
- package/dist/rendering/world3d/helpers3D.js +178 -0
- package/dist/rendering/world3d/index.d.ts +103 -0
- package/dist/rendering/world3d/index.js +62 -0
- package/dist/rendering/world3d/math3D.d.ts +114 -0
- package/dist/rendering/world3d/math3D.js +675 -0
- package/dist/rendering/world3d/primitives3D.d.ts +67 -0
- package/dist/rendering/world3d/primitives3D.js +197 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +6 -0
- package/dist/saveStore.d.ts +71 -0
- package/dist/saveStore.js +182 -0
- package/dist/semanticList.d.ts +126 -0
- package/dist/semanticList.js +175 -0
- package/dist/semanticTree.d.ts +10 -0
- package/dist/semanticTree.js +539 -0
- package/dist/semanticTypes.d.ts +175 -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 +24 -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 +24 -0
- package/dist/text.js +4 -0
- package/dist/textField.d.ts +6 -0
- package/dist/textField.js +6 -0
- package/dist/textTable.d.ts +41 -0
- package/dist/textTable.js +114 -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 +182 -0
- package/dist/tilemapTypes.js +2 -0
- package/dist/timer.d.ts +34 -0
- package/dist/timer.js +119 -0
- package/dist/tween.d.ts +15 -0
- package/dist/tween.js +329 -0
- package/dist/tweenTypes.d.ts +31 -0
- package/dist/tweenTypes.js +2 -0
- package/dist/ui/controlKeys.d.ts +113 -0
- package/dist/ui/controlKeys.js +250 -0
- package/dist/ui/controls.d.ts +58 -0
- package/dist/ui/controls.js +290 -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 +98 -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 +53 -0
- package/dist/ui/rangeControl.js +168 -0
- package/dist/ui/scrollControl.d.ts +84 -0
- package/dist/ui/scrollControl.js +222 -0
- package/dist/ui/stateControls.d.ts +90 -0
- package/dist/ui/stateControls.js +331 -0
- package/dist/ui/textEditor.d.ts +54 -0
- package/dist/ui/textEditor.js +371 -0
- package/dist/ui/textEditorTypes.d.ts +85 -0
- package/dist/ui/textEditorTypes.js +2 -0
- package/dist/ui/textFieldControl.d.ts +100 -0
- package/dist/ui/textFieldControl.js +260 -0
- package/dist/ui/theme.d.ts +64 -0
- package/dist/ui/theme.js +166 -0
- package/dist/ui/types.d.ts +285 -0
- package/dist/ui/types.js +2 -0
- package/dist/ui/uiRoot.d.ts +4 -0
- package/dist/ui/uiRoot.js +1526 -0
- package/dist/ui/uiRootDisplay.d.ts +46 -0
- package/dist/ui/uiRootDisplay.js +148 -0
- package/dist/ui/uiRootModel.d.ts +114 -0
- package/dist/ui/uiRootModel.js +66 -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 +77 -0
- package/dist/videoTypes.js +2 -0
- package/dist/web/BrowserAssetBundle.d.ts +41 -0
- package/dist/web/BrowserAssetBundle.js +136 -0
- package/dist/web/BrowserAudio.d.ts +74 -0
- package/dist/web/BrowserAudio.js +503 -0
- package/dist/web/BrowserFrameLoop.d.ts +69 -0
- package/dist/web/BrowserFrameLoop.js +125 -0
- package/dist/web/BrowserGame.d.ts +174 -0
- package/dist/web/BrowserGame.js +473 -0
- package/dist/web/BrowserGamepadInput.d.ts +38 -0
- package/dist/web/BrowserGamepadInput.js +134 -0
- package/dist/web/BrowserHoverInput.d.ts +25 -0
- package/dist/web/BrowserHoverInput.js +266 -0
- package/dist/web/BrowserImageTextures.d.ts +72 -0
- package/dist/web/BrowserImageTextures.js +169 -0
- package/dist/web/BrowserInputActions.d.ts +63 -0
- package/dist/web/BrowserInputActions.js +345 -0
- package/dist/web/BrowserKeyboardInput.d.ts +4 -0
- package/dist/web/BrowserKeyboardInput.js +223 -0
- package/dist/web/BrowserPlay.d.ts +417 -0
- package/dist/web/BrowserPlay.js +1648 -0
- package/dist/web/BrowserPointerInput.d.ts +4 -0
- package/dist/web/BrowserPointerInput.js +511 -0
- package/dist/web/BrowserPreferences.d.ts +10 -0
- package/dist/web/BrowserPreferences.js +39 -0
- package/dist/web/BrowserSemantics.d.ts +36 -0
- package/dist/web/BrowserSemantics.js +418 -0
- package/dist/web/BrowserStatsPanel.d.ts +56 -0
- package/dist/web/BrowserStatsPanel.js +143 -0
- package/dist/web/BrowserStorage.d.ts +35 -0
- package/dist/web/BrowserStorage.js +132 -0
- package/dist/web/BrowserTextEditor.d.ts +52 -0
- package/dist/web/BrowserTextEditor.js +839 -0
- package/dist/web/BrowserTextInput.d.ts +89 -0
- package/dist/web/BrowserTextInput.js +524 -0
- package/dist/web/BrowserTextureProvider.d.ts +58 -0
- package/dist/web/BrowserTextureProvider.js +935 -0
- package/dist/web/BrowserVideo.d.ts +40 -0
- package/dist/web/BrowserVideo.js +237 -0
- package/dist/web/CanvasKitFontSetProvider.d.ts +32 -0
- package/dist/web/CanvasKitFontSetProvider.js +215 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +173 -0
- package/dist/web/CanvasKitParagraphProvider.js +692 -0
- package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
- package/dist/web/CanvasTextRasterProvider.js +312 -0
- package/dist/web/ManifestByteSource.d.ts +151 -0
- package/dist/web/ManifestByteSource.js +975 -0
- package/dist/web/ManifestFontContentLoader.d.ts +13 -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 +2711 -0
- package/dist/web/WebGPUHost.d.ts +100 -0
- package/dist/web/WebGPUHost.js +3430 -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 +54 -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 +16 -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 +11 -0
- package/dist/web/kit.js +8 -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 +10 -0
- package/dist/web/play.js +9 -0
- package/dist/web/playMusic.d.ts +33 -0
- package/dist/web/playMusic.js +194 -0
- package/dist/web/playSfx.d.ts +36 -0
- package/dist/web/playSfx.js +112 -0
- package/dist/web/playTouch.d.ts +45 -0
- package/dist/web/playTouch.js +141 -0
- package/dist/web/playWidgets.d.ts +71 -0
- package/dist/web/playWidgets.js +431 -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 +63 -0
- package/dist/web/resources.d.ts +29 -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 +13 -0
- package/dist/web/sharedEffectShaders.js +181 -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 +33 -0
- package/dist/web/sharedWebGL2Options.js +102 -0
- package/dist/web/sharedWebGL2Shaders.d.ts +33 -0
- package/dist/web/sharedWebGL2Shaders.js +408 -0
- package/dist/web/sharedWebGPUOptions.d.ts +41 -0
- package/dist/web/sharedWebGPUOptions.js +130 -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 +72 -0
- package/dist/web/webgl2Native.js +572 -0
- package/dist/web/webgl2Types.d.ts +150 -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 +56 -0
- package/dist/web/webgpuImageResidency.js +65 -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 +85 -0
- package/dist/web/webgpuSharedPass.d.ts +7 -0
- package/dist/web/webgpuSharedPass.js +293 -0
- package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
- package/dist/web/webgpuSharedResolvePass.js +34 -0
- package/dist/web/world3d/Audio3D.d.ts +85 -0
- package/dist/web/world3d/Audio3D.js +271 -0
- package/dist/web/world3d/BrowserPlay3D.d.ts +295 -0
- package/dist/web/world3d/BrowserPlay3D.js +1256 -0
- package/dist/web/world3d/FlyControls3D.d.ts +59 -0
- package/dist/web/world3d/FlyControls3D.js +162 -0
- package/dist/web/world3d/FollowControls3D.d.ts +31 -0
- package/dist/web/world3d/FollowControls3D.js +119 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +58 -0
- package/dist/web/world3d/OrbitControls3D.js +189 -0
- package/dist/web/world3d/TransformControls3D.d.ts +37 -0
- package/dist/web/world3d/TransformControls3D.js +128 -0
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +136 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +1175 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +112 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1916 -0
- package/dist/web/world3d/World3DView.d.ts +54 -0
- package/dist/web/world3d/World3DView.js +79 -0
- package/dist/web/world3d/app3D.d.ts +143 -0
- package/dist/web/world3d/app3D.js +305 -0
- package/dist/web/world3d/assets3D.d.ts +39 -0
- package/dist/web/world3d/assets3D.js +112 -0
- package/dist/web/world3d/atmosphere3D.d.ts +56 -0
- package/dist/web/world3d/atmosphere3D.js +193 -0
- package/dist/web/world3d/canvasFont3D.d.ts +21 -0
- package/dist/web/world3d/canvasFont3D.js +165 -0
- package/dist/web/world3d/frame3D.d.ts +144 -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 +24 -0
- package/dist/web/world3d/host3D.js +61 -0
- package/dist/web/world3d/index.d.ts +40 -0
- package/dist/web/world3d/index.js +24 -0
- package/dist/web/world3d/loaders3D.d.ts +27 -0
- package/dist/web/world3d/loaders3D.js +138 -0
- package/dist/web/world3d/markers3D.d.ts +53 -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 +47 -0
- package/dist/web/world3d/overlay3D.js +187 -0
- package/dist/web/world3d/post3D.d.ts +116 -0
- package/dist/web/world3d/post3D.js +462 -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 +15 -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 +34 -0
- package/dist/web/world3d/stats3D.js +81 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +71 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
- package/dist/web/world3d/webgpu.d.ts +37 -0
- package/dist/web/world3d/webgpu.js +23 -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,675 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Allocation-free 3D math over caller-owned numeric storage. Matrices are
|
|
3
|
+
// column-major with column vectors; cameras look down negative view Z.
|
|
4
|
+
// Every function writes into `out` and tolerates `out` aliasing an input.
|
|
5
|
+
/** How close two numbers must be to count as equal. */
|
|
6
|
+
export const EPSILON_3D = 1e-8;
|
|
7
|
+
// ---- vec3 -----------------------------------------------------------------
|
|
8
|
+
/** Sets a vector's x, y and z. */
|
|
9
|
+
export function vec3Set(out, x, y, z) {
|
|
10
|
+
out[0] = x;
|
|
11
|
+
out[1] = y;
|
|
12
|
+
out[2] = z;
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
/** Copies a vector. */
|
|
16
|
+
export function vec3Copy(out, a) {
|
|
17
|
+
out[0] = a[0];
|
|
18
|
+
out[1] = a[1];
|
|
19
|
+
out[2] = a[2];
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
/** Adds two vectors. */
|
|
23
|
+
export function vec3Add(out, a, b) {
|
|
24
|
+
out[0] = a[0] + b[0];
|
|
25
|
+
out[1] = a[1] + b[1];
|
|
26
|
+
out[2] = a[2] + b[2];
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
/** Takes one vector from another. */
|
|
30
|
+
export function vec3Sub(out, a, b) {
|
|
31
|
+
out[0] = a[0] - b[0];
|
|
32
|
+
out[1] = a[1] - b[1];
|
|
33
|
+
out[2] = a[2] - b[2];
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
/** Multiplies a vector by a number. */
|
|
37
|
+
export function vec3Scale(out, a, s) {
|
|
38
|
+
out[0] = a[0] * s;
|
|
39
|
+
out[1] = a[1] * s;
|
|
40
|
+
out[2] = a[2] * s;
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** The dot product of two vectors. */
|
|
44
|
+
export function vec3Dot(a, b) {
|
|
45
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
46
|
+
}
|
|
47
|
+
/** The cross product of two vectors. */
|
|
48
|
+
export function vec3Cross(out, a, b) {
|
|
49
|
+
const ax = a[0], ay = a[1], az = a[2], bx = b[0], by = b[1], bz = b[2];
|
|
50
|
+
out[0] = ay * bz - az * by;
|
|
51
|
+
out[1] = az * bx - ax * bz;
|
|
52
|
+
out[2] = ax * by - ay * bx;
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/** The length of a vector. */
|
|
56
|
+
export function vec3Length(a) {
|
|
57
|
+
return Math.hypot(a[0], a[1], a[2]);
|
|
58
|
+
}
|
|
59
|
+
/** The distance between two points. */
|
|
60
|
+
export function vec3Distance(a, b) {
|
|
61
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
|
62
|
+
}
|
|
63
|
+
/** A zero-length input yields the zero vector instead of NaN. */
|
|
64
|
+
export function vec3Normalize(out, a) {
|
|
65
|
+
const length = Math.hypot(a[0], a[1], a[2]);
|
|
66
|
+
const inverse = length > 0 ? 1 / length : 0;
|
|
67
|
+
out[0] = a[0] * inverse;
|
|
68
|
+
out[1] = a[1] * inverse;
|
|
69
|
+
out[2] = a[2] * inverse;
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** The point a fraction of the way from one vector to another. */
|
|
73
|
+
export function vec3Lerp(out, a, b, t) {
|
|
74
|
+
out[0] = a[0] + (b[0] - a[0]) * t;
|
|
75
|
+
out[1] = a[1] + (b[1] - a[1]) * t;
|
|
76
|
+
out[2] = a[2] + (b[2] - a[2]) * t;
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
/** Transform a point (w = 1) with perspective division. */
|
|
80
|
+
export function vec3TransformMat4(out, a, m) {
|
|
81
|
+
const x = a[0], y = a[1], z = a[2];
|
|
82
|
+
const w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
83
|
+
const inverse = w !== 0 ? 1 / w : 1;
|
|
84
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) * inverse;
|
|
85
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) * inverse;
|
|
86
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) * inverse;
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/** Transform a direction (w = 0) by the upper 3x3; the result is not normalized. */
|
|
90
|
+
export function vec3TransformDirection(out, a, m) {
|
|
91
|
+
const x = a[0], y = a[1], z = a[2];
|
|
92
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z;
|
|
93
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z;
|
|
94
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z;
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
/** Turns a vector by a quaternion. */
|
|
98
|
+
export function vec3TransformQuat(out, a, q) {
|
|
99
|
+
const x = a[0], y = a[1], z = a[2], qx = q[0], qy = q[1], qz = q[2], qw = q[3];
|
|
100
|
+
// t = 2 * cross(q.xyz, v); v' = v + qw * t + cross(q.xyz, t)
|
|
101
|
+
const tx = 2 * (qy * z - qz * y), ty = 2 * (qz * x - qx * z), tz = 2 * (qx * y - qy * x);
|
|
102
|
+
out[0] = x + qw * tx + (qy * tz - qz * ty);
|
|
103
|
+
out[1] = y + qw * ty + (qz * tx - qx * tz);
|
|
104
|
+
out[2] = z + qw * tz + (qx * ty - qy * tx);
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
// ---- quaternion (x, y, z, w) -----------------------------------------------
|
|
108
|
+
/** Sets a quaternion to no rotation. */
|
|
109
|
+
export function quatIdentity(out) {
|
|
110
|
+
out[0] = 0;
|
|
111
|
+
out[1] = 0;
|
|
112
|
+
out[2] = 0;
|
|
113
|
+
out[3] = 1;
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
/** Copies a quaternion. */
|
|
117
|
+
export function quatCopy(out, a) {
|
|
118
|
+
out[0] = a[0];
|
|
119
|
+
out[1] = a[1];
|
|
120
|
+
out[2] = a[2];
|
|
121
|
+
out[3] = a[3];
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** Scales a quaternion to length 1. */
|
|
125
|
+
export function quatNormalize(out, a) {
|
|
126
|
+
const length = Math.hypot(a[0], a[1], a[2], a[3]);
|
|
127
|
+
if (length === 0)
|
|
128
|
+
return quatIdentity(out);
|
|
129
|
+
const inverse = 1 / length;
|
|
130
|
+
out[0] = a[0] * inverse;
|
|
131
|
+
out[1] = a[1] * inverse;
|
|
132
|
+
out[2] = a[2] * inverse;
|
|
133
|
+
out[3] = a[3] * inverse;
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
/** Multiplies two quaternions: the rotation of b, then a. */
|
|
137
|
+
export function quatMultiply(out, a, b) {
|
|
138
|
+
const ax = a[0], ay = a[1], az = a[2], aw = a[3], bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
139
|
+
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
|
140
|
+
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
|
141
|
+
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
142
|
+
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/** A quaternion that turns by an angle about an axis. */
|
|
146
|
+
export function quatFromAxisAngle(out, axis, radians) {
|
|
147
|
+
const half = radians * 0.5, s = Math.sin(half);
|
|
148
|
+
const length = Math.hypot(axis[0], axis[1], axis[2]) || 1;
|
|
149
|
+
out[0] = (axis[0] / length) * s;
|
|
150
|
+
out[1] = (axis[1] / length) * s;
|
|
151
|
+
out[2] = (axis[2] / length) * s;
|
|
152
|
+
out[3] = Math.cos(half);
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
/** Intrinsic XYZ Euler angles in radians (rotate X, then Y, then Z in local axes). */
|
|
156
|
+
export function quatFromEuler(out, x, y, z) {
|
|
157
|
+
const c1 = Math.cos(x / 2), c2 = Math.cos(y / 2), c3 = Math.cos(z / 2);
|
|
158
|
+
const s1 = Math.sin(x / 2), s2 = Math.sin(y / 2), s3 = Math.sin(z / 2);
|
|
159
|
+
out[0] = s1 * c2 * c3 + c1 * s2 * s3;
|
|
160
|
+
out[1] = c1 * s2 * c3 - s1 * c2 * s3;
|
|
161
|
+
out[2] = c1 * c2 * s3 + s1 * s2 * c3;
|
|
162
|
+
out[3] = c1 * c2 * c3 - s1 * s2 * s3;
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
/** Inverse of quatFromEuler; writes radians into out[0..2]. */
|
|
166
|
+
export function quatToEuler(out, q) {
|
|
167
|
+
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
168
|
+
const m13 = 2 * (x * z + w * y);
|
|
169
|
+
out[1] = Math.asin(Math.max(-1, Math.min(1, m13)));
|
|
170
|
+
if (Math.abs(m13) < 0.9999999) {
|
|
171
|
+
out[0] = Math.atan2(-2 * (y * z - w * x), 1 - 2 * (x * x + y * y));
|
|
172
|
+
out[2] = Math.atan2(-2 * (x * y - w * z), 1 - 2 * (y * y + z * z));
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
out[0] = Math.atan2(2 * (y * z + w * x), 1 - 2 * (x * x + z * z));
|
|
176
|
+
out[2] = 0;
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
/** Shortest-arc spherical interpolation; falls back to nlerp for close inputs. */
|
|
181
|
+
export function quatSlerp(out, a, b, t) {
|
|
182
|
+
const ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
183
|
+
let bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
184
|
+
let cosine = ax * bx + ay * by + az * bz + aw * bw;
|
|
185
|
+
if (cosine < 0) {
|
|
186
|
+
cosine = -cosine;
|
|
187
|
+
bx = -bx;
|
|
188
|
+
by = -by;
|
|
189
|
+
bz = -bz;
|
|
190
|
+
bw = -bw;
|
|
191
|
+
}
|
|
192
|
+
let s0, s1;
|
|
193
|
+
if (1 - cosine > 1e-6) {
|
|
194
|
+
const omega = Math.acos(cosine), sine = Math.sin(omega);
|
|
195
|
+
s0 = Math.sin((1 - t) * omega) / sine;
|
|
196
|
+
s1 = Math.sin(t * omega) / sine;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
s0 = 1 - t;
|
|
200
|
+
s1 = t;
|
|
201
|
+
}
|
|
202
|
+
out[0] = s0 * ax + s1 * bx;
|
|
203
|
+
out[1] = s0 * ay + s1 * by;
|
|
204
|
+
out[2] = s0 * az + s1 * bz;
|
|
205
|
+
out[3] = s0 * aw + s1 * bw;
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
/** Rotation part of a matrix without scale or shear. */
|
|
209
|
+
export function quatFromRotationMatrix(out, m) {
|
|
210
|
+
const m00 = m[0], m01 = m[4], m02 = m[8], m10 = m[1], m11 = m[5], m12 = m[9], m20 = m[2], m21 = m[6], m22 = m[10];
|
|
211
|
+
const trace = m00 + m11 + m22;
|
|
212
|
+
if (trace > 0) {
|
|
213
|
+
const s = 0.5 / Math.sqrt(trace + 1);
|
|
214
|
+
out[3] = 0.25 / s;
|
|
215
|
+
out[0] = (m21 - m12) * s;
|
|
216
|
+
out[1] = (m02 - m20) * s;
|
|
217
|
+
out[2] = (m10 - m01) * s;
|
|
218
|
+
}
|
|
219
|
+
else if (m00 > m11 && m00 > m22) {
|
|
220
|
+
const s = 2 * Math.sqrt(1 + m00 - m11 - m22);
|
|
221
|
+
out[3] = (m21 - m12) / s;
|
|
222
|
+
out[0] = 0.25 * s;
|
|
223
|
+
out[1] = (m01 + m10) / s;
|
|
224
|
+
out[2] = (m02 + m20) / s;
|
|
225
|
+
}
|
|
226
|
+
else if (m11 > m22) {
|
|
227
|
+
const s = 2 * Math.sqrt(1 + m11 - m00 - m22);
|
|
228
|
+
out[3] = (m02 - m20) / s;
|
|
229
|
+
out[0] = (m01 + m10) / s;
|
|
230
|
+
out[1] = 0.25 * s;
|
|
231
|
+
out[2] = (m12 + m21) / s;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
const s = 2 * Math.sqrt(1 + m22 - m00 - m11);
|
|
235
|
+
out[3] = (m10 - m01) / s;
|
|
236
|
+
out[0] = (m02 + m20) / s;
|
|
237
|
+
out[1] = (m12 + m21) / s;
|
|
238
|
+
out[2] = 0.25 * s;
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
// ---- mat4 -------------------------------------------------------------------
|
|
243
|
+
/** Sets a 4x4 matrix to the identity. */
|
|
244
|
+
export function mat4Identity(out) {
|
|
245
|
+
out[0] = 1;
|
|
246
|
+
out[1] = 0;
|
|
247
|
+
out[2] = 0;
|
|
248
|
+
out[3] = 0;
|
|
249
|
+
out[4] = 0;
|
|
250
|
+
out[5] = 1;
|
|
251
|
+
out[6] = 0;
|
|
252
|
+
out[7] = 0;
|
|
253
|
+
out[8] = 0;
|
|
254
|
+
out[9] = 0;
|
|
255
|
+
out[10] = 1;
|
|
256
|
+
out[11] = 0;
|
|
257
|
+
out[12] = 0;
|
|
258
|
+
out[13] = 0;
|
|
259
|
+
out[14] = 0;
|
|
260
|
+
out[15] = 1;
|
|
261
|
+
return out;
|
|
262
|
+
}
|
|
263
|
+
/** Copies a 4x4 matrix. */
|
|
264
|
+
export function mat4Copy(out, a) {
|
|
265
|
+
for (let i = 0; i < 16; i++)
|
|
266
|
+
out[i] = a[i];
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
/** out = a * b: with column vectors, b applies first. */
|
|
270
|
+
export function mat4Multiply(out, a, b) {
|
|
271
|
+
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
272
|
+
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
|
273
|
+
for (let column = 0; column < 4; column++) {
|
|
274
|
+
const o = column * 4, b0 = b[o], b1 = b[o + 1], b2 = b[o + 2], b3 = b[o + 3];
|
|
275
|
+
out[o] = a00 * b0 + a10 * b1 + a20 * b2 + a30 * b3;
|
|
276
|
+
out[o + 1] = a01 * b0 + a11 * b1 + a21 * b2 + a31 * b3;
|
|
277
|
+
out[o + 2] = a02 * b0 + a12 * b1 + a22 * b2 + a32 * b3;
|
|
278
|
+
out[o + 3] = a03 * b0 + a13 * b1 + a23 * b2 + a33 * b3;
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
/** Affine matrix from translation, unit quaternion and scale. */
|
|
283
|
+
export function mat4Compose(out, t, q, s) {
|
|
284
|
+
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
285
|
+
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
286
|
+
const xx = x * x2, xy = x * y2, xz = x * z2, yy = y * y2, yz = y * z2, zz = z * z2, wx = w * x2, wy = w * y2, wz = w * z2;
|
|
287
|
+
const sx = s[0], sy = s[1], sz = s[2];
|
|
288
|
+
out[0] = (1 - (yy + zz)) * sx;
|
|
289
|
+
out[1] = (xy + wz) * sx;
|
|
290
|
+
out[2] = (xz - wy) * sx;
|
|
291
|
+
out[3] = 0;
|
|
292
|
+
out[4] = (xy - wz) * sy;
|
|
293
|
+
out[5] = (1 - (xx + zz)) * sy;
|
|
294
|
+
out[6] = (yz + wx) * sy;
|
|
295
|
+
out[7] = 0;
|
|
296
|
+
out[8] = (xz + wy) * sz;
|
|
297
|
+
out[9] = (yz - wx) * sz;
|
|
298
|
+
out[10] = (1 - (xx + yy)) * sz;
|
|
299
|
+
out[11] = 0;
|
|
300
|
+
out[12] = t[0];
|
|
301
|
+
out[13] = t[1];
|
|
302
|
+
out[14] = t[2];
|
|
303
|
+
out[15] = 1;
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
306
|
+
const scratchRotation = new Float64Array(16);
|
|
307
|
+
/** Split an affine matrix; a negative determinant is folded into scale X. */
|
|
308
|
+
export function mat4Decompose(m, t, q, s) {
|
|
309
|
+
let sx = Math.hypot(m[0], m[1], m[2]);
|
|
310
|
+
const sy = Math.hypot(m[4], m[5], m[6]), sz = Math.hypot(m[8], m[9], m[10]);
|
|
311
|
+
if (mat4Determinant(m) < 0)
|
|
312
|
+
sx = -sx;
|
|
313
|
+
t[0] = m[12];
|
|
314
|
+
t[1] = m[13];
|
|
315
|
+
t[2] = m[14];
|
|
316
|
+
const ix = sx !== 0 ? 1 / sx : 0, iy = sy !== 0 ? 1 / sy : 0, iz = sz !== 0 ? 1 / sz : 0;
|
|
317
|
+
const r = scratchRotation;
|
|
318
|
+
r[0] = m[0] * ix;
|
|
319
|
+
r[1] = m[1] * ix;
|
|
320
|
+
r[2] = m[2] * ix;
|
|
321
|
+
r[4] = m[4] * iy;
|
|
322
|
+
r[5] = m[5] * iy;
|
|
323
|
+
r[6] = m[6] * iy;
|
|
324
|
+
r[8] = m[8] * iz;
|
|
325
|
+
r[9] = m[9] * iz;
|
|
326
|
+
r[10] = m[10] * iz;
|
|
327
|
+
quatFromRotationMatrix(q, r);
|
|
328
|
+
s[0] = sx;
|
|
329
|
+
s[1] = sy;
|
|
330
|
+
s[2] = sz;
|
|
331
|
+
}
|
|
332
|
+
/** The determinant of a 4x4 matrix. */
|
|
333
|
+
export function mat4Determinant(m) {
|
|
334
|
+
const a00 = m[0], a01 = m[1], a02 = m[2], a03 = m[3], a10 = m[4], a11 = m[5], a12 = m[6], a13 = m[7];
|
|
335
|
+
const a20 = m[8], a21 = m[9], a22 = m[10], a23 = m[11], a30 = m[12], a31 = m[13], a32 = m[14], a33 = m[15];
|
|
336
|
+
const b0 = a00 * a11 - a01 * a10, b1 = a00 * a12 - a02 * a10, b2 = a01 * a12 - a02 * a11;
|
|
337
|
+
const b3 = a20 * a31 - a21 * a30, b4 = a20 * a32 - a22 * a30, b5 = a21 * a32 - a22 * a31;
|
|
338
|
+
const b6 = a00 * b5 - a01 * b4 + a02 * b3, b7 = a10 * b5 - a11 * b4 + a12 * b3;
|
|
339
|
+
const b8 = a20 * b2 - a21 * b1 + a22 * b0, b9 = a30 * b2 - a31 * b1 + a32 * b0;
|
|
340
|
+
return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
|
|
341
|
+
}
|
|
342
|
+
/** Returns false and leaves `out` untouched when the matrix is singular. */
|
|
343
|
+
export function mat4Invert(out, m) {
|
|
344
|
+
const a00 = m[0], a01 = m[1], a02 = m[2], a03 = m[3], a10 = m[4], a11 = m[5], a12 = m[6], a13 = m[7];
|
|
345
|
+
const a20 = m[8], a21 = m[9], a22 = m[10], a23 = m[11], a30 = m[12], a31 = m[13], a32 = m[14], a33 = m[15];
|
|
346
|
+
const b00 = a00 * a11 - a01 * a10, b01 = a00 * a12 - a02 * a10, b02 = a00 * a13 - a03 * a10;
|
|
347
|
+
const b03 = a01 * a12 - a02 * a11, b04 = a01 * a13 - a03 * a11, b05 = a02 * a13 - a03 * a12;
|
|
348
|
+
const b06 = a20 * a31 - a21 * a30, b07 = a20 * a32 - a22 * a30, b08 = a20 * a33 - a23 * a30;
|
|
349
|
+
const b09 = a21 * a32 - a22 * a31, b10 = a21 * a33 - a23 * a31, b11 = a22 * a33 - a23 * a32;
|
|
350
|
+
const determinant = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
351
|
+
if (determinant === 0 || !Number.isFinite(determinant))
|
|
352
|
+
return false;
|
|
353
|
+
const d = 1 / determinant;
|
|
354
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * d;
|
|
355
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * d;
|
|
356
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * d;
|
|
357
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * d;
|
|
358
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * d;
|
|
359
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * d;
|
|
360
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * d;
|
|
361
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * d;
|
|
362
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * d;
|
|
363
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * d;
|
|
364
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * d;
|
|
365
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * d;
|
|
366
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * d;
|
|
367
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * d;
|
|
368
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * d;
|
|
369
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * d;
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
/** World matrix of an object at `eye` whose negative Z axis points at `target`. */
|
|
373
|
+
export function mat4LookAt(out, eye, target, up) {
|
|
374
|
+
let zx = eye[0] - target[0], zy = eye[1] - target[1], zz = eye[2] - target[2];
|
|
375
|
+
let length = Math.hypot(zx, zy, zz);
|
|
376
|
+
if (length === 0) {
|
|
377
|
+
zz = 1;
|
|
378
|
+
length = 1;
|
|
379
|
+
}
|
|
380
|
+
zx /= length;
|
|
381
|
+
zy /= length;
|
|
382
|
+
zz /= length;
|
|
383
|
+
let xx = up[1] * zz - up[2] * zy, xy = up[2] * zx - up[0] * zz, xz = up[0] * zy - up[1] * zx;
|
|
384
|
+
length = Math.hypot(xx, xy, xz);
|
|
385
|
+
if (length === 0) {
|
|
386
|
+
// `up` is parallel to the view direction: pick any perpendicular axis.
|
|
387
|
+
if (Math.abs(zy) > 0.999) {
|
|
388
|
+
xx = 1;
|
|
389
|
+
xy = 0;
|
|
390
|
+
xz = 0;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
xx = zz;
|
|
394
|
+
xy = 0;
|
|
395
|
+
xz = -zx;
|
|
396
|
+
}
|
|
397
|
+
length = Math.hypot(xx, xy, xz);
|
|
398
|
+
}
|
|
399
|
+
xx /= length;
|
|
400
|
+
xy /= length;
|
|
401
|
+
xz /= length;
|
|
402
|
+
const yx = zy * xz - zz * xy, yy = zz * xx - zx * xz, yz = zx * xy - zy * xx;
|
|
403
|
+
out[0] = xx;
|
|
404
|
+
out[1] = xy;
|
|
405
|
+
out[2] = xz;
|
|
406
|
+
out[3] = 0;
|
|
407
|
+
out[4] = yx;
|
|
408
|
+
out[5] = yy;
|
|
409
|
+
out[6] = yz;
|
|
410
|
+
out[7] = 0;
|
|
411
|
+
out[8] = zx;
|
|
412
|
+
out[9] = zy;
|
|
413
|
+
out[10] = zz;
|
|
414
|
+
out[11] = 0;
|
|
415
|
+
out[12] = eye[0];
|
|
416
|
+
out[13] = eye[1];
|
|
417
|
+
out[14] = eye[2];
|
|
418
|
+
out[15] = 1;
|
|
419
|
+
return out;
|
|
420
|
+
}
|
|
421
|
+
/** Right-handed perspective projection to clip depth [-1, 1]. */
|
|
422
|
+
export function mat4Perspective(out, verticalFov, aspect, near, far) {
|
|
423
|
+
const f = 1 / Math.tan(verticalFov / 2), range = 1 / (near - far);
|
|
424
|
+
mat4Identity(out);
|
|
425
|
+
out[0] = f / aspect;
|
|
426
|
+
out[5] = f;
|
|
427
|
+
out[10] = (far + near) * range;
|
|
428
|
+
out[11] = -1;
|
|
429
|
+
out[14] = 2 * far * near * range;
|
|
430
|
+
out[15] = 0;
|
|
431
|
+
return out;
|
|
432
|
+
}
|
|
433
|
+
/** Sets a 4x4 matrix to an orthographic projection. */
|
|
434
|
+
export function mat4Orthographic(out, left, right, bottom, top, near, far) {
|
|
435
|
+
const w = 1 / (right - left), h = 1 / (top - bottom), d = 1 / (near - far);
|
|
436
|
+
mat4Identity(out);
|
|
437
|
+
out[0] = 2 * w;
|
|
438
|
+
out[5] = 2 * h;
|
|
439
|
+
out[10] = 2 * d;
|
|
440
|
+
out[12] = -(right + left) * w;
|
|
441
|
+
out[13] = -(top + bottom) * h;
|
|
442
|
+
out[14] = (far + near) * d;
|
|
443
|
+
return out;
|
|
444
|
+
}
|
|
445
|
+
/** 3x3 inverse transpose of the upper-left block, written as nine column-major floats. */
|
|
446
|
+
export function mat3NormalFromMat4(out, m) {
|
|
447
|
+
const a00 = m[0], a01 = m[1], a02 = m[2], a10 = m[4], a11 = m[5], a12 = m[6], a20 = m[8], a21 = m[9], a22 = m[10];
|
|
448
|
+
const c00 = a11 * a22 - a12 * a21, c01 = a12 * a20 - a10 * a22, c02 = a10 * a21 - a11 * a20;
|
|
449
|
+
const determinant = a00 * c00 + a01 * c01 + a02 * c02;
|
|
450
|
+
const d = determinant !== 0 ? 1 / determinant : 0;
|
|
451
|
+
out[0] = c00 * d;
|
|
452
|
+
out[1] = c01 * d;
|
|
453
|
+
out[2] = c02 * d;
|
|
454
|
+
out[3] = (a02 * a21 - a01 * a22) * d;
|
|
455
|
+
out[4] = (a00 * a22 - a02 * a20) * d;
|
|
456
|
+
out[5] = (a01 * a20 - a00 * a21) * d;
|
|
457
|
+
out[6] = (a01 * a12 - a02 * a11) * d;
|
|
458
|
+
out[7] = (a02 * a10 - a00 * a12) * d;
|
|
459
|
+
out[8] = (a00 * a11 - a01 * a10) * d;
|
|
460
|
+
return out;
|
|
461
|
+
}
|
|
462
|
+
/** The largest scale a 4x4 matrix applies along an axis. */
|
|
463
|
+
export function mat4MaxScaleOnAxis(m) {
|
|
464
|
+
const x = m[0] * m[0] + m[1] * m[1] + m[2] * m[2];
|
|
465
|
+
const y = m[4] * m[4] + m[5] * m[5] + m[6] * m[6];
|
|
466
|
+
const z = m[8] * m[8] + m[9] * m[9] + m[10] * m[10];
|
|
467
|
+
return Math.sqrt(Math.max(x, y, z));
|
|
468
|
+
}
|
|
469
|
+
// ---- bounds: box = [minX, minY, minZ, maxX, maxY, maxZ], sphere = [x, y, z, radius]
|
|
470
|
+
/** Sets a box to empty. */
|
|
471
|
+
export function box3Empty(out) {
|
|
472
|
+
out[0] = out[1] = out[2] = Infinity;
|
|
473
|
+
out[3] = out[4] = out[5] = -Infinity;
|
|
474
|
+
return out;
|
|
475
|
+
}
|
|
476
|
+
/** Whether a box is empty. */
|
|
477
|
+
export function box3IsEmpty(box) {
|
|
478
|
+
return box[3] < box[0] || box[4] < box[1] || box[5] < box[2];
|
|
479
|
+
}
|
|
480
|
+
/** Grows a box to hold a point. */
|
|
481
|
+
export function box3ExpandByPoint(box, x, y, z) {
|
|
482
|
+
if (x < box[0])
|
|
483
|
+
box[0] = x;
|
|
484
|
+
if (y < box[1])
|
|
485
|
+
box[1] = y;
|
|
486
|
+
if (z < box[2])
|
|
487
|
+
box[2] = z;
|
|
488
|
+
if (x > box[3])
|
|
489
|
+
box[3] = x;
|
|
490
|
+
if (y > box[4])
|
|
491
|
+
box[4] = y;
|
|
492
|
+
if (z > box[5])
|
|
493
|
+
box[5] = z;
|
|
494
|
+
}
|
|
495
|
+
/** The box that holds two boxes. */
|
|
496
|
+
export function box3Union(out, a, b) {
|
|
497
|
+
out[0] = Math.min(a[0], b[0]);
|
|
498
|
+
out[1] = Math.min(a[1], b[1]);
|
|
499
|
+
out[2] = Math.min(a[2], b[2]);
|
|
500
|
+
out[3] = Math.max(a[3], b[3]);
|
|
501
|
+
out[4] = Math.max(a[4], b[4]);
|
|
502
|
+
out[5] = Math.max(a[5], b[5]);
|
|
503
|
+
return out;
|
|
504
|
+
}
|
|
505
|
+
/** Axis-aligned bounds of a transformed box (Arvo's method). */
|
|
506
|
+
export function box3Transform(out, box, m) {
|
|
507
|
+
if (box3IsEmpty(box))
|
|
508
|
+
return box3Empty(out);
|
|
509
|
+
const min = [m[12], m[13], m[14]], max = [m[12], m[13], m[14]];
|
|
510
|
+
for (let row = 0; row < 3; row++) {
|
|
511
|
+
for (let column = 0; column < 3; column++) {
|
|
512
|
+
const e = m[column * 4 + row], a = e * box[column], b = e * box[column + 3];
|
|
513
|
+
min[row] += Math.min(a, b);
|
|
514
|
+
max[row] += Math.max(a, b);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
out[0] = min[0];
|
|
518
|
+
out[1] = min[1];
|
|
519
|
+
out[2] = min[2];
|
|
520
|
+
out[3] = max[0];
|
|
521
|
+
out[4] = max[1];
|
|
522
|
+
out[5] = max[2];
|
|
523
|
+
return out;
|
|
524
|
+
}
|
|
525
|
+
/** The sphere around a box. */
|
|
526
|
+
export function sphereFromBox(out, box) {
|
|
527
|
+
if (box3IsEmpty(box)) {
|
|
528
|
+
out[0] = out[1] = out[2] = 0;
|
|
529
|
+
out[3] = -1;
|
|
530
|
+
return out;
|
|
531
|
+
}
|
|
532
|
+
out[0] = (box[0] + box[3]) / 2;
|
|
533
|
+
out[1] = (box[1] + box[4]) / 2;
|
|
534
|
+
out[2] = (box[2] + box[5]) / 2;
|
|
535
|
+
out[3] = Math.hypot(box[3] - box[0], box[4] - box[1], box[5] - box[2]) / 2;
|
|
536
|
+
return out;
|
|
537
|
+
}
|
|
538
|
+
/** Moves and scales a sphere by a 4x4 matrix. */
|
|
539
|
+
export function sphereTransform(out, sphere, m) {
|
|
540
|
+
const radius = sphere[3];
|
|
541
|
+
vec3TransformMat4(out, sphere, m);
|
|
542
|
+
out[3] = radius < 0 ? radius : radius * mat4MaxScaleOnAxis(m);
|
|
543
|
+
return out;
|
|
544
|
+
}
|
|
545
|
+
// ---- frustum: six inward planes [nx, ny, nz, d] from a view-projection matrix
|
|
546
|
+
/** The six planes of the frustum a projection-view matrix sees. */
|
|
547
|
+
export function frustumFromMatrix(out, m) {
|
|
548
|
+
const rows = [0, 1, 2];
|
|
549
|
+
let o = 0;
|
|
550
|
+
for (const row of rows) {
|
|
551
|
+
for (const sign of [1, -1]) {
|
|
552
|
+
let x = m[3] + sign * m[row], y = m[7] + sign * m[4 + row], z = m[11] + sign * m[8 + row], d = m[15] + sign * m[12 + row];
|
|
553
|
+
const length = Math.hypot(x, y, z) || 1;
|
|
554
|
+
x /= length;
|
|
555
|
+
y /= length;
|
|
556
|
+
z /= length;
|
|
557
|
+
d /= length;
|
|
558
|
+
out[o++] = x;
|
|
559
|
+
out[o++] = y;
|
|
560
|
+
out[o++] = z;
|
|
561
|
+
out[o++] = d;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return out;
|
|
565
|
+
}
|
|
566
|
+
/** Whether a sphere is at least partly inside a frustum. */
|
|
567
|
+
export function frustumIntersectsSphere(frustum, sphere) {
|
|
568
|
+
const x = sphere[0], y = sphere[1], z = sphere[2], negativeRadius = -sphere[3];
|
|
569
|
+
for (let o = 0; o < 24; o += 4) {
|
|
570
|
+
if (frustum[o] * x + frustum[o + 1] * y + frustum[o + 2] * z + frustum[o + 3] < negativeRadius)
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
/** Whether a box is at least partly inside a frustum. */
|
|
576
|
+
export function frustumIntersectsBox(frustum, box) {
|
|
577
|
+
for (let o = 0; o < 24; o += 4) {
|
|
578
|
+
const nx = frustum[o], ny = frustum[o + 1], nz = frustum[o + 2];
|
|
579
|
+
// Test the box corner farthest along the plane normal.
|
|
580
|
+
const x = nx > 0 ? box[3] : box[0], y = ny > 0 ? box[4] : box[1], z = nz > 0 ? box[5] : box[2];
|
|
581
|
+
if (nx * x + ny * y + nz * z + frustum[o + 3] < 0)
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
return true;
|
|
585
|
+
}
|
|
586
|
+
// ---- rays: origin and unit direction ----------------------------------------
|
|
587
|
+
/** Distance along the ray to the sphere, or -1 when it misses. */
|
|
588
|
+
export function rayIntersectSphere(origin, direction, sphere) {
|
|
589
|
+
const ox = sphere[0] - origin[0], oy = sphere[1] - origin[1], oz = sphere[2] - origin[2];
|
|
590
|
+
const along = ox * direction[0] + oy * direction[1] + oz * direction[2];
|
|
591
|
+
const distance2 = ox * ox + oy * oy + oz * oz - along * along, radius2 = sphere[3] * sphere[3];
|
|
592
|
+
if (distance2 > radius2)
|
|
593
|
+
return -1;
|
|
594
|
+
const half = Math.sqrt(radius2 - distance2), near = along - half, far = along + half;
|
|
595
|
+
if (far < 0)
|
|
596
|
+
return -1;
|
|
597
|
+
return near >= 0 ? near : far;
|
|
598
|
+
}
|
|
599
|
+
/** Slab test; returns the entry distance (0 when the origin is inside) or -1. */
|
|
600
|
+
export function rayIntersectBox(origin, direction, box) {
|
|
601
|
+
let near = -Infinity, far = Infinity;
|
|
602
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
603
|
+
const inverse = 1 / direction[axis];
|
|
604
|
+
let t0 = (box[axis] - origin[axis]) * inverse, t1 = (box[axis + 3] - origin[axis]) * inverse;
|
|
605
|
+
if (t0 > t1) {
|
|
606
|
+
const swap = t0;
|
|
607
|
+
t0 = t1;
|
|
608
|
+
t1 = swap;
|
|
609
|
+
}
|
|
610
|
+
if (Number.isNaN(t0) || Number.isNaN(t1))
|
|
611
|
+
continue;
|
|
612
|
+
if (t0 > near)
|
|
613
|
+
near = t0;
|
|
614
|
+
if (t1 < far)
|
|
615
|
+
far = t1;
|
|
616
|
+
if (near > far)
|
|
617
|
+
return -1;
|
|
618
|
+
}
|
|
619
|
+
if (far < 0)
|
|
620
|
+
return -1;
|
|
621
|
+
return near >= 0 ? near : 0;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Moller-Trumbore. Writes [distance, u, v] into `out` and returns true on a hit.
|
|
625
|
+
* `cull` rejects back faces (counter-clockwise triangles face the ray origin).
|
|
626
|
+
*/
|
|
627
|
+
export function rayIntersectTriangle(out, origin, direction, p, a, b, c, cull) {
|
|
628
|
+
const ax = p[a], ay = p[a + 1], az = p[a + 2];
|
|
629
|
+
const e1x = p[b] - ax, e1y = p[b + 1] - ay, e1z = p[b + 2] - az;
|
|
630
|
+
const e2x = p[c] - ax, e2y = p[c + 1] - ay, e2z = p[c + 2] - az;
|
|
631
|
+
const dx = direction[0], dy = direction[1], dz = direction[2];
|
|
632
|
+
const px = dy * e2z - dz * e2y, py = dz * e2x - dx * e2z, pz = dx * e2y - dy * e2x;
|
|
633
|
+
const determinant = e1x * px + e1y * py + e1z * pz;
|
|
634
|
+
if (cull ? determinant < EPSILON_3D : Math.abs(determinant) < EPSILON_3D)
|
|
635
|
+
return false;
|
|
636
|
+
const inverse = 1 / determinant;
|
|
637
|
+
const tx = origin[0] - ax, ty = origin[1] - ay, tz = origin[2] - az;
|
|
638
|
+
const u = (tx * px + ty * py + tz * pz) * inverse;
|
|
639
|
+
if (u < 0 || u > 1)
|
|
640
|
+
return false;
|
|
641
|
+
const qx = ty * e1z - tz * e1y, qy = tz * e1x - tx * e1z, qz = tx * e1y - ty * e1x;
|
|
642
|
+
const v = (dx * qx + dy * qy + dz * qz) * inverse;
|
|
643
|
+
if (v < 0 || u + v > 1)
|
|
644
|
+
return false;
|
|
645
|
+
const distance = (e2x * qx + e2y * qy + e2z * qz) * inverse;
|
|
646
|
+
if (distance < 0)
|
|
647
|
+
return false;
|
|
648
|
+
out[0] = distance;
|
|
649
|
+
out[1] = u;
|
|
650
|
+
out[2] = v;
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
// ---- color -------------------------------------------------------------------
|
|
654
|
+
/** Turns an sRGB color value into a linear one. */
|
|
655
|
+
export function srgbToLinear(value) {
|
|
656
|
+
return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
|
|
657
|
+
}
|
|
658
|
+
/** Turns a linear color value into an sRGB one. */
|
|
659
|
+
export function linearToSrgb(value) {
|
|
660
|
+
return value <= 0.0031308 ? value * 12.92 : 1.055 * Math.pow(value, 1 / 2.4) - 0.055;
|
|
661
|
+
}
|
|
662
|
+
/** Decode a 0xRRGGBB sRGB color into linear RGB in [0, 1]. */
|
|
663
|
+
export function colorFromHex(out, hex) {
|
|
664
|
+
out[0] = srgbToLinear(((hex >> 16) & 255) / 255);
|
|
665
|
+
out[1] = srgbToLinear(((hex >> 8) & 255) / 255);
|
|
666
|
+
out[2] = srgbToLinear((hex & 255) / 255);
|
|
667
|
+
return out;
|
|
668
|
+
}
|
|
669
|
+
/** The value, kept between `min` and `max`. */
|
|
670
|
+
export function clamp(value, min, max) {
|
|
671
|
+
return value < min ? min : value > max ? max : value;
|
|
672
|
+
}
|
|
673
|
+
/** Degrees times this are radians. */
|
|
674
|
+
export const DEG_TO_RAD_3D = Math.PI / 180;
|
|
675
|
+
//# sourceMappingURL=math3D.js.map
|