@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,640 @@
|
|
|
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
|
+
export const EPSILON_3D = 1e-8;
|
|
6
|
+
// ---- vec3 -----------------------------------------------------------------
|
|
7
|
+
export function vec3Set(out, x, y, z) {
|
|
8
|
+
out[0] = x;
|
|
9
|
+
out[1] = y;
|
|
10
|
+
out[2] = z;
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
export function vec3Copy(out, a) {
|
|
14
|
+
out[0] = a[0];
|
|
15
|
+
out[1] = a[1];
|
|
16
|
+
out[2] = a[2];
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
export function vec3Add(out, a, b) {
|
|
20
|
+
out[0] = a[0] + b[0];
|
|
21
|
+
out[1] = a[1] + b[1];
|
|
22
|
+
out[2] = a[2] + b[2];
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
export function vec3Sub(out, a, b) {
|
|
26
|
+
out[0] = a[0] - b[0];
|
|
27
|
+
out[1] = a[1] - b[1];
|
|
28
|
+
out[2] = a[2] - b[2];
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
export function vec3Scale(out, a, s) {
|
|
32
|
+
out[0] = a[0] * s;
|
|
33
|
+
out[1] = a[1] * s;
|
|
34
|
+
out[2] = a[2] * s;
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
export function vec3Dot(a, b) {
|
|
38
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
39
|
+
}
|
|
40
|
+
export function vec3Cross(out, a, b) {
|
|
41
|
+
const ax = a[0], ay = a[1], az = a[2], bx = b[0], by = b[1], bz = b[2];
|
|
42
|
+
out[0] = ay * bz - az * by;
|
|
43
|
+
out[1] = az * bx - ax * bz;
|
|
44
|
+
out[2] = ax * by - ay * bx;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
export function vec3Length(a) {
|
|
48
|
+
return Math.hypot(a[0], a[1], a[2]);
|
|
49
|
+
}
|
|
50
|
+
export function vec3Distance(a, b) {
|
|
51
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
|
52
|
+
}
|
|
53
|
+
/** A zero-length input yields the zero vector instead of NaN. */
|
|
54
|
+
export function vec3Normalize(out, a) {
|
|
55
|
+
const length = Math.hypot(a[0], a[1], a[2]);
|
|
56
|
+
const inverse = length > 0 ? 1 / length : 0;
|
|
57
|
+
out[0] = a[0] * inverse;
|
|
58
|
+
out[1] = a[1] * inverse;
|
|
59
|
+
out[2] = a[2] * inverse;
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
export function vec3Lerp(out, a, b, t) {
|
|
63
|
+
out[0] = a[0] + (b[0] - a[0]) * t;
|
|
64
|
+
out[1] = a[1] + (b[1] - a[1]) * t;
|
|
65
|
+
out[2] = a[2] + (b[2] - a[2]) * t;
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
/** Transform a point (w = 1) with perspective division. */
|
|
69
|
+
export function vec3TransformMat4(out, a, m) {
|
|
70
|
+
const x = a[0], y = a[1], z = a[2];
|
|
71
|
+
const w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
72
|
+
const inverse = w !== 0 ? 1 / w : 1;
|
|
73
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) * inverse;
|
|
74
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) * inverse;
|
|
75
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) * inverse;
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** Transform a direction (w = 0) by the upper 3x3; the result is not normalized. */
|
|
79
|
+
export function vec3TransformDirection(out, a, m) {
|
|
80
|
+
const x = a[0], y = a[1], z = a[2];
|
|
81
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z;
|
|
82
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z;
|
|
83
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z;
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
export function vec3TransformQuat(out, a, q) {
|
|
87
|
+
const x = a[0], y = a[1], z = a[2], qx = q[0], qy = q[1], qz = q[2], qw = q[3];
|
|
88
|
+
// t = 2 * cross(q.xyz, v); v' = v + qw * t + cross(q.xyz, t)
|
|
89
|
+
const tx = 2 * (qy * z - qz * y), ty = 2 * (qz * x - qx * z), tz = 2 * (qx * y - qy * x);
|
|
90
|
+
out[0] = x + qw * tx + (qy * tz - qz * ty);
|
|
91
|
+
out[1] = y + qw * ty + (qz * tx - qx * tz);
|
|
92
|
+
out[2] = z + qw * tz + (qx * ty - qy * tx);
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
// ---- quaternion (x, y, z, w) -----------------------------------------------
|
|
96
|
+
export function quatIdentity(out) {
|
|
97
|
+
out[0] = 0;
|
|
98
|
+
out[1] = 0;
|
|
99
|
+
out[2] = 0;
|
|
100
|
+
out[3] = 1;
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
export function quatCopy(out, a) {
|
|
104
|
+
out[0] = a[0];
|
|
105
|
+
out[1] = a[1];
|
|
106
|
+
out[2] = a[2];
|
|
107
|
+
out[3] = a[3];
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
export function quatNormalize(out, a) {
|
|
111
|
+
const length = Math.hypot(a[0], a[1], a[2], a[3]);
|
|
112
|
+
if (length === 0)
|
|
113
|
+
return quatIdentity(out);
|
|
114
|
+
const inverse = 1 / length;
|
|
115
|
+
out[0] = a[0] * inverse;
|
|
116
|
+
out[1] = a[1] * inverse;
|
|
117
|
+
out[2] = a[2] * inverse;
|
|
118
|
+
out[3] = a[3] * inverse;
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
export function quatMultiply(out, a, b) {
|
|
122
|
+
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];
|
|
123
|
+
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
|
124
|
+
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
|
125
|
+
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
126
|
+
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
export function quatFromAxisAngle(out, axis, radians) {
|
|
130
|
+
const half = radians * 0.5, s = Math.sin(half);
|
|
131
|
+
const length = Math.hypot(axis[0], axis[1], axis[2]) || 1;
|
|
132
|
+
out[0] = (axis[0] / length) * s;
|
|
133
|
+
out[1] = (axis[1] / length) * s;
|
|
134
|
+
out[2] = (axis[2] / length) * s;
|
|
135
|
+
out[3] = Math.cos(half);
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/** Intrinsic XYZ Euler angles in radians (rotate X, then Y, then Z in local axes). */
|
|
139
|
+
export function quatFromEuler(out, x, y, z) {
|
|
140
|
+
const c1 = Math.cos(x / 2), c2 = Math.cos(y / 2), c3 = Math.cos(z / 2);
|
|
141
|
+
const s1 = Math.sin(x / 2), s2 = Math.sin(y / 2), s3 = Math.sin(z / 2);
|
|
142
|
+
out[0] = s1 * c2 * c3 + c1 * s2 * s3;
|
|
143
|
+
out[1] = c1 * s2 * c3 - s1 * c2 * s3;
|
|
144
|
+
out[2] = c1 * c2 * s3 + s1 * s2 * c3;
|
|
145
|
+
out[3] = c1 * c2 * c3 - s1 * s2 * s3;
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
/** Inverse of quatFromEuler; writes radians into out[0..2]. */
|
|
149
|
+
export function quatToEuler(out, q) {
|
|
150
|
+
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
151
|
+
const m13 = 2 * (x * z + w * y);
|
|
152
|
+
out[1] = Math.asin(Math.max(-1, Math.min(1, m13)));
|
|
153
|
+
if (Math.abs(m13) < 0.9999999) {
|
|
154
|
+
out[0] = Math.atan2(-2 * (y * z - w * x), 1 - 2 * (x * x + y * y));
|
|
155
|
+
out[2] = Math.atan2(-2 * (x * y - w * z), 1 - 2 * (y * y + z * z));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
out[0] = Math.atan2(2 * (y * z + w * x), 1 - 2 * (x * x + z * z));
|
|
159
|
+
out[2] = 0;
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
/** Shortest-arc spherical interpolation; falls back to nlerp for close inputs. */
|
|
164
|
+
export function quatSlerp(out, a, b, t) {
|
|
165
|
+
const ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
166
|
+
let bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
167
|
+
let cosine = ax * bx + ay * by + az * bz + aw * bw;
|
|
168
|
+
if (cosine < 0) {
|
|
169
|
+
cosine = -cosine;
|
|
170
|
+
bx = -bx;
|
|
171
|
+
by = -by;
|
|
172
|
+
bz = -bz;
|
|
173
|
+
bw = -bw;
|
|
174
|
+
}
|
|
175
|
+
let s0, s1;
|
|
176
|
+
if (1 - cosine > 1e-6) {
|
|
177
|
+
const omega = Math.acos(cosine), sine = Math.sin(omega);
|
|
178
|
+
s0 = Math.sin((1 - t) * omega) / sine;
|
|
179
|
+
s1 = Math.sin(t * omega) / sine;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
s0 = 1 - t;
|
|
183
|
+
s1 = t;
|
|
184
|
+
}
|
|
185
|
+
out[0] = s0 * ax + s1 * bx;
|
|
186
|
+
out[1] = s0 * ay + s1 * by;
|
|
187
|
+
out[2] = s0 * az + s1 * bz;
|
|
188
|
+
out[3] = s0 * aw + s1 * bw;
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
/** Rotation part of a matrix without scale or shear. */
|
|
192
|
+
export function quatFromRotationMatrix(out, m) {
|
|
193
|
+
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];
|
|
194
|
+
const trace = m00 + m11 + m22;
|
|
195
|
+
if (trace > 0) {
|
|
196
|
+
const s = 0.5 / Math.sqrt(trace + 1);
|
|
197
|
+
out[3] = 0.25 / s;
|
|
198
|
+
out[0] = (m21 - m12) * s;
|
|
199
|
+
out[1] = (m02 - m20) * s;
|
|
200
|
+
out[2] = (m10 - m01) * s;
|
|
201
|
+
}
|
|
202
|
+
else if (m00 > m11 && m00 > m22) {
|
|
203
|
+
const s = 2 * Math.sqrt(1 + m00 - m11 - m22);
|
|
204
|
+
out[3] = (m21 - m12) / s;
|
|
205
|
+
out[0] = 0.25 * s;
|
|
206
|
+
out[1] = (m01 + m10) / s;
|
|
207
|
+
out[2] = (m02 + m20) / s;
|
|
208
|
+
}
|
|
209
|
+
else if (m11 > m22) {
|
|
210
|
+
const s = 2 * Math.sqrt(1 + m11 - m00 - m22);
|
|
211
|
+
out[3] = (m02 - m20) / s;
|
|
212
|
+
out[0] = (m01 + m10) / s;
|
|
213
|
+
out[1] = 0.25 * s;
|
|
214
|
+
out[2] = (m12 + m21) / s;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const s = 2 * Math.sqrt(1 + m22 - m00 - m11);
|
|
218
|
+
out[3] = (m10 - m01) / s;
|
|
219
|
+
out[0] = (m02 + m20) / s;
|
|
220
|
+
out[1] = (m12 + m21) / s;
|
|
221
|
+
out[2] = 0.25 * s;
|
|
222
|
+
}
|
|
223
|
+
return out;
|
|
224
|
+
}
|
|
225
|
+
// ---- mat4 -------------------------------------------------------------------
|
|
226
|
+
export function mat4Identity(out) {
|
|
227
|
+
out[0] = 1;
|
|
228
|
+
out[1] = 0;
|
|
229
|
+
out[2] = 0;
|
|
230
|
+
out[3] = 0;
|
|
231
|
+
out[4] = 0;
|
|
232
|
+
out[5] = 1;
|
|
233
|
+
out[6] = 0;
|
|
234
|
+
out[7] = 0;
|
|
235
|
+
out[8] = 0;
|
|
236
|
+
out[9] = 0;
|
|
237
|
+
out[10] = 1;
|
|
238
|
+
out[11] = 0;
|
|
239
|
+
out[12] = 0;
|
|
240
|
+
out[13] = 0;
|
|
241
|
+
out[14] = 0;
|
|
242
|
+
out[15] = 1;
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
export function mat4Copy(out, a) {
|
|
246
|
+
for (let i = 0; i < 16; i++)
|
|
247
|
+
out[i] = a[i];
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
/** out = a * b: with column vectors, b applies first. */
|
|
251
|
+
export function mat4Multiply(out, a, b) {
|
|
252
|
+
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];
|
|
253
|
+
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];
|
|
254
|
+
for (let column = 0; column < 4; column++) {
|
|
255
|
+
const o = column * 4, b0 = b[o], b1 = b[o + 1], b2 = b[o + 2], b3 = b[o + 3];
|
|
256
|
+
out[o] = a00 * b0 + a10 * b1 + a20 * b2 + a30 * b3;
|
|
257
|
+
out[o + 1] = a01 * b0 + a11 * b1 + a21 * b2 + a31 * b3;
|
|
258
|
+
out[o + 2] = a02 * b0 + a12 * b1 + a22 * b2 + a32 * b3;
|
|
259
|
+
out[o + 3] = a03 * b0 + a13 * b1 + a23 * b2 + a33 * b3;
|
|
260
|
+
}
|
|
261
|
+
return out;
|
|
262
|
+
}
|
|
263
|
+
/** Affine matrix from translation, unit quaternion and scale. */
|
|
264
|
+
export function mat4Compose(out, t, q, s) {
|
|
265
|
+
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
266
|
+
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
267
|
+
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;
|
|
268
|
+
const sx = s[0], sy = s[1], sz = s[2];
|
|
269
|
+
out[0] = (1 - (yy + zz)) * sx;
|
|
270
|
+
out[1] = (xy + wz) * sx;
|
|
271
|
+
out[2] = (xz - wy) * sx;
|
|
272
|
+
out[3] = 0;
|
|
273
|
+
out[4] = (xy - wz) * sy;
|
|
274
|
+
out[5] = (1 - (xx + zz)) * sy;
|
|
275
|
+
out[6] = (yz + wx) * sy;
|
|
276
|
+
out[7] = 0;
|
|
277
|
+
out[8] = (xz + wy) * sz;
|
|
278
|
+
out[9] = (yz - wx) * sz;
|
|
279
|
+
out[10] = (1 - (xx + yy)) * sz;
|
|
280
|
+
out[11] = 0;
|
|
281
|
+
out[12] = t[0];
|
|
282
|
+
out[13] = t[1];
|
|
283
|
+
out[14] = t[2];
|
|
284
|
+
out[15] = 1;
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
const scratchRotation = new Float64Array(16);
|
|
288
|
+
/** Split an affine matrix; a negative determinant is folded into scale X. */
|
|
289
|
+
export function mat4Decompose(m, t, q, s) {
|
|
290
|
+
let sx = Math.hypot(m[0], m[1], m[2]);
|
|
291
|
+
const sy = Math.hypot(m[4], m[5], m[6]), sz = Math.hypot(m[8], m[9], m[10]);
|
|
292
|
+
if (mat4Determinant(m) < 0)
|
|
293
|
+
sx = -sx;
|
|
294
|
+
t[0] = m[12];
|
|
295
|
+
t[1] = m[13];
|
|
296
|
+
t[2] = m[14];
|
|
297
|
+
const ix = sx !== 0 ? 1 / sx : 0, iy = sy !== 0 ? 1 / sy : 0, iz = sz !== 0 ? 1 / sz : 0;
|
|
298
|
+
const r = scratchRotation;
|
|
299
|
+
r[0] = m[0] * ix;
|
|
300
|
+
r[1] = m[1] * ix;
|
|
301
|
+
r[2] = m[2] * ix;
|
|
302
|
+
r[4] = m[4] * iy;
|
|
303
|
+
r[5] = m[5] * iy;
|
|
304
|
+
r[6] = m[6] * iy;
|
|
305
|
+
r[8] = m[8] * iz;
|
|
306
|
+
r[9] = m[9] * iz;
|
|
307
|
+
r[10] = m[10] * iz;
|
|
308
|
+
quatFromRotationMatrix(q, r);
|
|
309
|
+
s[0] = sx;
|
|
310
|
+
s[1] = sy;
|
|
311
|
+
s[2] = sz;
|
|
312
|
+
}
|
|
313
|
+
export function mat4Determinant(m) {
|
|
314
|
+
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];
|
|
315
|
+
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];
|
|
316
|
+
const b0 = a00 * a11 - a01 * a10, b1 = a00 * a12 - a02 * a10, b2 = a01 * a12 - a02 * a11;
|
|
317
|
+
const b3 = a20 * a31 - a21 * a30, b4 = a20 * a32 - a22 * a30, b5 = a21 * a32 - a22 * a31;
|
|
318
|
+
const b6 = a00 * b5 - a01 * b4 + a02 * b3, b7 = a10 * b5 - a11 * b4 + a12 * b3;
|
|
319
|
+
const b8 = a20 * b2 - a21 * b1 + a22 * b0, b9 = a30 * b2 - a31 * b1 + a32 * b0;
|
|
320
|
+
return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
|
|
321
|
+
}
|
|
322
|
+
/** Returns false and leaves `out` untouched when the matrix is singular. */
|
|
323
|
+
export function mat4Invert(out, m) {
|
|
324
|
+
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];
|
|
325
|
+
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];
|
|
326
|
+
const b00 = a00 * a11 - a01 * a10, b01 = a00 * a12 - a02 * a10, b02 = a00 * a13 - a03 * a10;
|
|
327
|
+
const b03 = a01 * a12 - a02 * a11, b04 = a01 * a13 - a03 * a11, b05 = a02 * a13 - a03 * a12;
|
|
328
|
+
const b06 = a20 * a31 - a21 * a30, b07 = a20 * a32 - a22 * a30, b08 = a20 * a33 - a23 * a30;
|
|
329
|
+
const b09 = a21 * a32 - a22 * a31, b10 = a21 * a33 - a23 * a31, b11 = a22 * a33 - a23 * a32;
|
|
330
|
+
const determinant = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
331
|
+
if (determinant === 0 || !Number.isFinite(determinant))
|
|
332
|
+
return false;
|
|
333
|
+
const d = 1 / determinant;
|
|
334
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * d;
|
|
335
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * d;
|
|
336
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * d;
|
|
337
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * d;
|
|
338
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * d;
|
|
339
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * d;
|
|
340
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * d;
|
|
341
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * d;
|
|
342
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * d;
|
|
343
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * d;
|
|
344
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * d;
|
|
345
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * d;
|
|
346
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * d;
|
|
347
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * d;
|
|
348
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * d;
|
|
349
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * d;
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
/** World matrix of an object at `eye` whose negative Z axis points at `target`. */
|
|
353
|
+
export function mat4LookAt(out, eye, target, up) {
|
|
354
|
+
let zx = eye[0] - target[0], zy = eye[1] - target[1], zz = eye[2] - target[2];
|
|
355
|
+
let length = Math.hypot(zx, zy, zz);
|
|
356
|
+
if (length === 0) {
|
|
357
|
+
zz = 1;
|
|
358
|
+
length = 1;
|
|
359
|
+
}
|
|
360
|
+
zx /= length;
|
|
361
|
+
zy /= length;
|
|
362
|
+
zz /= length;
|
|
363
|
+
let xx = up[1] * zz - up[2] * zy, xy = up[2] * zx - up[0] * zz, xz = up[0] * zy - up[1] * zx;
|
|
364
|
+
length = Math.hypot(xx, xy, xz);
|
|
365
|
+
if (length === 0) {
|
|
366
|
+
// `up` is parallel to the view direction: pick any perpendicular axis.
|
|
367
|
+
if (Math.abs(zy) > 0.999) {
|
|
368
|
+
xx = 1;
|
|
369
|
+
xy = 0;
|
|
370
|
+
xz = 0;
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
xx = zz;
|
|
374
|
+
xy = 0;
|
|
375
|
+
xz = -zx;
|
|
376
|
+
}
|
|
377
|
+
length = Math.hypot(xx, xy, xz);
|
|
378
|
+
}
|
|
379
|
+
xx /= length;
|
|
380
|
+
xy /= length;
|
|
381
|
+
xz /= length;
|
|
382
|
+
const yx = zy * xz - zz * xy, yy = zz * xx - zx * xz, yz = zx * xy - zy * xx;
|
|
383
|
+
out[0] = xx;
|
|
384
|
+
out[1] = xy;
|
|
385
|
+
out[2] = xz;
|
|
386
|
+
out[3] = 0;
|
|
387
|
+
out[4] = yx;
|
|
388
|
+
out[5] = yy;
|
|
389
|
+
out[6] = yz;
|
|
390
|
+
out[7] = 0;
|
|
391
|
+
out[8] = zx;
|
|
392
|
+
out[9] = zy;
|
|
393
|
+
out[10] = zz;
|
|
394
|
+
out[11] = 0;
|
|
395
|
+
out[12] = eye[0];
|
|
396
|
+
out[13] = eye[1];
|
|
397
|
+
out[14] = eye[2];
|
|
398
|
+
out[15] = 1;
|
|
399
|
+
return out;
|
|
400
|
+
}
|
|
401
|
+
/** Right-handed perspective projection to clip depth [-1, 1]. */
|
|
402
|
+
export function mat4Perspective(out, verticalFov, aspect, near, far) {
|
|
403
|
+
const f = 1 / Math.tan(verticalFov / 2), range = 1 / (near - far);
|
|
404
|
+
mat4Identity(out);
|
|
405
|
+
out[0] = f / aspect;
|
|
406
|
+
out[5] = f;
|
|
407
|
+
out[10] = (far + near) * range;
|
|
408
|
+
out[11] = -1;
|
|
409
|
+
out[14] = 2 * far * near * range;
|
|
410
|
+
out[15] = 0;
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
export function mat4Orthographic(out, left, right, bottom, top, near, far) {
|
|
414
|
+
const w = 1 / (right - left), h = 1 / (top - bottom), d = 1 / (near - far);
|
|
415
|
+
mat4Identity(out);
|
|
416
|
+
out[0] = 2 * w;
|
|
417
|
+
out[5] = 2 * h;
|
|
418
|
+
out[10] = 2 * d;
|
|
419
|
+
out[12] = -(right + left) * w;
|
|
420
|
+
out[13] = -(top + bottom) * h;
|
|
421
|
+
out[14] = (far + near) * d;
|
|
422
|
+
return out;
|
|
423
|
+
}
|
|
424
|
+
/** 3x3 inverse transpose of the upper-left block, written as nine column-major floats. */
|
|
425
|
+
export function mat3NormalFromMat4(out, m) {
|
|
426
|
+
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];
|
|
427
|
+
const c00 = a11 * a22 - a12 * a21, c01 = a12 * a20 - a10 * a22, c02 = a10 * a21 - a11 * a20;
|
|
428
|
+
const determinant = a00 * c00 + a01 * c01 + a02 * c02;
|
|
429
|
+
const d = determinant !== 0 ? 1 / determinant : 0;
|
|
430
|
+
out[0] = c00 * d;
|
|
431
|
+
out[1] = c01 * d;
|
|
432
|
+
out[2] = c02 * d;
|
|
433
|
+
out[3] = (a02 * a21 - a01 * a22) * d;
|
|
434
|
+
out[4] = (a00 * a22 - a02 * a20) * d;
|
|
435
|
+
out[5] = (a01 * a20 - a00 * a21) * d;
|
|
436
|
+
out[6] = (a01 * a12 - a02 * a11) * d;
|
|
437
|
+
out[7] = (a02 * a10 - a00 * a12) * d;
|
|
438
|
+
out[8] = (a00 * a11 - a01 * a10) * d;
|
|
439
|
+
return out;
|
|
440
|
+
}
|
|
441
|
+
export function mat4MaxScaleOnAxis(m) {
|
|
442
|
+
const x = m[0] * m[0] + m[1] * m[1] + m[2] * m[2];
|
|
443
|
+
const y = m[4] * m[4] + m[5] * m[5] + m[6] * m[6];
|
|
444
|
+
const z = m[8] * m[8] + m[9] * m[9] + m[10] * m[10];
|
|
445
|
+
return Math.sqrt(Math.max(x, y, z));
|
|
446
|
+
}
|
|
447
|
+
// ---- bounds: box = [minX, minY, minZ, maxX, maxY, maxZ], sphere = [x, y, z, radius]
|
|
448
|
+
export function box3Empty(out) {
|
|
449
|
+
out[0] = out[1] = out[2] = Infinity;
|
|
450
|
+
out[3] = out[4] = out[5] = -Infinity;
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
export function box3IsEmpty(box) {
|
|
454
|
+
return box[3] < box[0] || box[4] < box[1] || box[5] < box[2];
|
|
455
|
+
}
|
|
456
|
+
export function box3ExpandByPoint(box, x, y, z) {
|
|
457
|
+
if (x < box[0])
|
|
458
|
+
box[0] = x;
|
|
459
|
+
if (y < box[1])
|
|
460
|
+
box[1] = y;
|
|
461
|
+
if (z < box[2])
|
|
462
|
+
box[2] = z;
|
|
463
|
+
if (x > box[3])
|
|
464
|
+
box[3] = x;
|
|
465
|
+
if (y > box[4])
|
|
466
|
+
box[4] = y;
|
|
467
|
+
if (z > box[5])
|
|
468
|
+
box[5] = z;
|
|
469
|
+
}
|
|
470
|
+
export function box3Union(out, a, b) {
|
|
471
|
+
out[0] = Math.min(a[0], b[0]);
|
|
472
|
+
out[1] = Math.min(a[1], b[1]);
|
|
473
|
+
out[2] = Math.min(a[2], b[2]);
|
|
474
|
+
out[3] = Math.max(a[3], b[3]);
|
|
475
|
+
out[4] = Math.max(a[4], b[4]);
|
|
476
|
+
out[5] = Math.max(a[5], b[5]);
|
|
477
|
+
return out;
|
|
478
|
+
}
|
|
479
|
+
/** Axis-aligned bounds of a transformed box (Arvo's method). */
|
|
480
|
+
export function box3Transform(out, box, m) {
|
|
481
|
+
if (box3IsEmpty(box))
|
|
482
|
+
return box3Empty(out);
|
|
483
|
+
const min = [m[12], m[13], m[14]], max = [m[12], m[13], m[14]];
|
|
484
|
+
for (let row = 0; row < 3; row++) {
|
|
485
|
+
for (let column = 0; column < 3; column++) {
|
|
486
|
+
const e = m[column * 4 + row], a = e * box[column], b = e * box[column + 3];
|
|
487
|
+
min[row] += Math.min(a, b);
|
|
488
|
+
max[row] += Math.max(a, b);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
out[0] = min[0];
|
|
492
|
+
out[1] = min[1];
|
|
493
|
+
out[2] = min[2];
|
|
494
|
+
out[3] = max[0];
|
|
495
|
+
out[4] = max[1];
|
|
496
|
+
out[5] = max[2];
|
|
497
|
+
return out;
|
|
498
|
+
}
|
|
499
|
+
export function sphereFromBox(out, box) {
|
|
500
|
+
if (box3IsEmpty(box)) {
|
|
501
|
+
out[0] = out[1] = out[2] = 0;
|
|
502
|
+
out[3] = -1;
|
|
503
|
+
return out;
|
|
504
|
+
}
|
|
505
|
+
out[0] = (box[0] + box[3]) / 2;
|
|
506
|
+
out[1] = (box[1] + box[4]) / 2;
|
|
507
|
+
out[2] = (box[2] + box[5]) / 2;
|
|
508
|
+
out[3] = Math.hypot(box[3] - box[0], box[4] - box[1], box[5] - box[2]) / 2;
|
|
509
|
+
return out;
|
|
510
|
+
}
|
|
511
|
+
export function sphereTransform(out, sphere, m) {
|
|
512
|
+
const radius = sphere[3];
|
|
513
|
+
vec3TransformMat4(out, sphere, m);
|
|
514
|
+
out[3] = radius < 0 ? radius : radius * mat4MaxScaleOnAxis(m);
|
|
515
|
+
return out;
|
|
516
|
+
}
|
|
517
|
+
// ---- frustum: six inward planes [nx, ny, nz, d] from a view-projection matrix
|
|
518
|
+
export function frustumFromMatrix(out, m) {
|
|
519
|
+
const rows = [0, 1, 2];
|
|
520
|
+
let o = 0;
|
|
521
|
+
for (const row of rows) {
|
|
522
|
+
for (const sign of [1, -1]) {
|
|
523
|
+
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];
|
|
524
|
+
const length = Math.hypot(x, y, z) || 1;
|
|
525
|
+
x /= length;
|
|
526
|
+
y /= length;
|
|
527
|
+
z /= length;
|
|
528
|
+
d /= length;
|
|
529
|
+
out[o++] = x;
|
|
530
|
+
out[o++] = y;
|
|
531
|
+
out[o++] = z;
|
|
532
|
+
out[o++] = d;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return out;
|
|
536
|
+
}
|
|
537
|
+
export function frustumIntersectsSphere(frustum, sphere) {
|
|
538
|
+
const x = sphere[0], y = sphere[1], z = sphere[2], negativeRadius = -sphere[3];
|
|
539
|
+
for (let o = 0; o < 24; o += 4) {
|
|
540
|
+
if (frustum[o] * x + frustum[o + 1] * y + frustum[o + 2] * z + frustum[o + 3] < negativeRadius)
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
export function frustumIntersectsBox(frustum, box) {
|
|
546
|
+
for (let o = 0; o < 24; o += 4) {
|
|
547
|
+
const nx = frustum[o], ny = frustum[o + 1], nz = frustum[o + 2];
|
|
548
|
+
// Test the box corner farthest along the plane normal.
|
|
549
|
+
const x = nx > 0 ? box[3] : box[0], y = ny > 0 ? box[4] : box[1], z = nz > 0 ? box[5] : box[2];
|
|
550
|
+
if (nx * x + ny * y + nz * z + frustum[o + 3] < 0)
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
// ---- rays: origin and unit direction ----------------------------------------
|
|
556
|
+
/** Distance along the ray to the sphere, or -1 when it misses. */
|
|
557
|
+
export function rayIntersectSphere(origin, direction, sphere) {
|
|
558
|
+
const ox = sphere[0] - origin[0], oy = sphere[1] - origin[1], oz = sphere[2] - origin[2];
|
|
559
|
+
const along = ox * direction[0] + oy * direction[1] + oz * direction[2];
|
|
560
|
+
const distance2 = ox * ox + oy * oy + oz * oz - along * along, radius2 = sphere[3] * sphere[3];
|
|
561
|
+
if (distance2 > radius2)
|
|
562
|
+
return -1;
|
|
563
|
+
const half = Math.sqrt(radius2 - distance2), near = along - half, far = along + half;
|
|
564
|
+
if (far < 0)
|
|
565
|
+
return -1;
|
|
566
|
+
return near >= 0 ? near : far;
|
|
567
|
+
}
|
|
568
|
+
/** Slab test; returns the entry distance (0 when the origin is inside) or -1. */
|
|
569
|
+
export function rayIntersectBox(origin, direction, box) {
|
|
570
|
+
let near = -Infinity, far = Infinity;
|
|
571
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
572
|
+
const inverse = 1 / direction[axis];
|
|
573
|
+
let t0 = (box[axis] - origin[axis]) * inverse, t1 = (box[axis + 3] - origin[axis]) * inverse;
|
|
574
|
+
if (t0 > t1) {
|
|
575
|
+
const swap = t0;
|
|
576
|
+
t0 = t1;
|
|
577
|
+
t1 = swap;
|
|
578
|
+
}
|
|
579
|
+
if (Number.isNaN(t0) || Number.isNaN(t1))
|
|
580
|
+
continue;
|
|
581
|
+
if (t0 > near)
|
|
582
|
+
near = t0;
|
|
583
|
+
if (t1 < far)
|
|
584
|
+
far = t1;
|
|
585
|
+
if (near > far)
|
|
586
|
+
return -1;
|
|
587
|
+
}
|
|
588
|
+
if (far < 0)
|
|
589
|
+
return -1;
|
|
590
|
+
return near >= 0 ? near : 0;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Moller-Trumbore. Writes [distance, u, v] into `out` and returns true on a hit.
|
|
594
|
+
* `cull` rejects back faces (counter-clockwise triangles face the ray origin).
|
|
595
|
+
*/
|
|
596
|
+
export function rayIntersectTriangle(out, origin, direction, p, a, b, c, cull) {
|
|
597
|
+
const ax = p[a], ay = p[a + 1], az = p[a + 2];
|
|
598
|
+
const e1x = p[b] - ax, e1y = p[b + 1] - ay, e1z = p[b + 2] - az;
|
|
599
|
+
const e2x = p[c] - ax, e2y = p[c + 1] - ay, e2z = p[c + 2] - az;
|
|
600
|
+
const dx = direction[0], dy = direction[1], dz = direction[2];
|
|
601
|
+
const px = dy * e2z - dz * e2y, py = dz * e2x - dx * e2z, pz = dx * e2y - dy * e2x;
|
|
602
|
+
const determinant = e1x * px + e1y * py + e1z * pz;
|
|
603
|
+
if (cull ? determinant < EPSILON_3D : Math.abs(determinant) < EPSILON_3D)
|
|
604
|
+
return false;
|
|
605
|
+
const inverse = 1 / determinant;
|
|
606
|
+
const tx = origin[0] - ax, ty = origin[1] - ay, tz = origin[2] - az;
|
|
607
|
+
const u = (tx * px + ty * py + tz * pz) * inverse;
|
|
608
|
+
if (u < 0 || u > 1)
|
|
609
|
+
return false;
|
|
610
|
+
const qx = ty * e1z - tz * e1y, qy = tz * e1x - tx * e1z, qz = tx * e1y - ty * e1x;
|
|
611
|
+
const v = (dx * qx + dy * qy + dz * qz) * inverse;
|
|
612
|
+
if (v < 0 || u + v > 1)
|
|
613
|
+
return false;
|
|
614
|
+
const distance = (e2x * qx + e2y * qy + e2z * qz) * inverse;
|
|
615
|
+
if (distance < 0)
|
|
616
|
+
return false;
|
|
617
|
+
out[0] = distance;
|
|
618
|
+
out[1] = u;
|
|
619
|
+
out[2] = v;
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
622
|
+
// ---- color -------------------------------------------------------------------
|
|
623
|
+
export function srgbToLinear(value) {
|
|
624
|
+
return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
|
|
625
|
+
}
|
|
626
|
+
export function linearToSrgb(value) {
|
|
627
|
+
return value <= 0.0031308 ? value * 12.92 : 1.055 * Math.pow(value, 1 / 2.4) - 0.055;
|
|
628
|
+
}
|
|
629
|
+
/** Decode a 0xRRGGBB sRGB color into linear RGB in [0, 1]. */
|
|
630
|
+
export function colorFromHex(out, hex) {
|
|
631
|
+
out[0] = srgbToLinear(((hex >> 16) & 255) / 255);
|
|
632
|
+
out[1] = srgbToLinear(((hex >> 8) & 255) / 255);
|
|
633
|
+
out[2] = srgbToLinear((hex & 255) / 255);
|
|
634
|
+
return out;
|
|
635
|
+
}
|
|
636
|
+
export function clamp(value, min, max) {
|
|
637
|
+
return value < min ? min : value > max ? max : value;
|
|
638
|
+
}
|
|
639
|
+
export const DEG_TO_RAD_3D = Math.PI / 180;
|
|
640
|
+
//# sourceMappingURL=math3D.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
2
|
+
export interface BoxGeometryOptions3D {
|
|
3
|
+
readonly width?: number;
|
|
4
|
+
readonly height?: number;
|
|
5
|
+
readonly depth?: number;
|
|
6
|
+
readonly widthSegments?: number;
|
|
7
|
+
readonly heightSegments?: number;
|
|
8
|
+
readonly depthSegments?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Axis-aligned box centered on the origin with one material group per face (+X, -X, +Y, -Y, +Z, -Z). */
|
|
11
|
+
export declare function createBoxGeometry3D(options?: BoxGeometryOptions3D): Geometry3D;
|
|
12
|
+
export interface PlaneGeometryOptions3D {
|
|
13
|
+
readonly width?: number;
|
|
14
|
+
readonly height?: number;
|
|
15
|
+
readonly widthSegments?: number;
|
|
16
|
+
readonly heightSegments?: number;
|
|
17
|
+
}
|
|
18
|
+
/** Plane in the XY plane facing +Z. Rotate -90 degrees about X for a floor. */
|
|
19
|
+
export declare function createPlaneGeometry3D(options?: PlaneGeometryOptions3D): Geometry3D;
|
|
20
|
+
export interface SphereGeometryOptions3D {
|
|
21
|
+
readonly radius?: number;
|
|
22
|
+
readonly widthSegments?: number;
|
|
23
|
+
readonly heightSegments?: number;
|
|
24
|
+
}
|
|
25
|
+
/** UV sphere with poles on the Y axis. */
|
|
26
|
+
export declare function createSphereGeometry3D(options?: SphereGeometryOptions3D): Geometry3D;
|
|
27
|
+
export interface CylinderGeometryOptions3D {
|
|
28
|
+
readonly radiusTop?: number;
|
|
29
|
+
readonly radiusBottom?: number;
|
|
30
|
+
readonly height?: number;
|
|
31
|
+
readonly radialSegments?: number;
|
|
32
|
+
readonly heightSegments?: number;
|
|
33
|
+
readonly openEnded?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** Cylinder or truncated cone along Y. A zero radius at one end produces a cone. */
|
|
36
|
+
export declare function createCylinderGeometry3D(options?: CylinderGeometryOptions3D): Geometry3D;
|
|
37
|
+
export declare function createConeGeometry3D(options?: {
|
|
38
|
+
readonly radius?: number;
|
|
39
|
+
readonly height?: number;
|
|
40
|
+
readonly radialSegments?: number;
|
|
41
|
+
}): Geometry3D;
|
|
42
|
+
export interface TorusGeometryOptions3D {
|
|
43
|
+
readonly radius?: number;
|
|
44
|
+
readonly tube?: number;
|
|
45
|
+
readonly radialSegments?: number;
|
|
46
|
+
readonly tubularSegments?: number;
|
|
47
|
+
}
|
|
48
|
+
/** Torus around the Z axis. */
|
|
49
|
+
export declare function createTorusGeometry3D(options?: TorusGeometryOptions3D): Geometry3D;
|
|
50
|
+
export interface CapsuleGeometryOptions3D {
|
|
51
|
+
readonly radius?: number;
|
|
52
|
+
readonly height?: number;
|
|
53
|
+
readonly capSegments?: number;
|
|
54
|
+
readonly radialSegments?: number;
|
|
55
|
+
}
|
|
56
|
+
/** Capsule along Y; `height` is the length of the cylindrical middle section. */
|
|
57
|
+
export declare function createCapsuleGeometry3D(options?: CapsuleGeometryOptions3D): Geometry3D;
|
|
58
|
+
/** Unit quad in XY used by sprites: corners at +-0.5, facing +Z. */
|
|
59
|
+
export declare function createQuadGeometry3D(): Geometry3D;
|
|
60
|
+
//# sourceMappingURL=primitives3D.d.ts.map
|