@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,851 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// A whole small 3D game from one call. The picture is a World3D app; everything else is `play`, drawn clear over
|
|
3
|
+
// it on a canvas of its own: the keys, the pointer, sound, timers, tweens, text and buttons. What is added here is
|
|
4
|
+
// what a 3D game makes its world of: boxes, balls and a ground that are placed by plain numbers, a camera that
|
|
5
|
+
// follows, a sun, tests of distance and overlap, and pieces thrown out by a hit.
|
|
6
|
+
import { EgretError } from '@egret/runtime';
|
|
7
|
+
import { play } from '../play.js';
|
|
8
|
+
import { Object3D, Scene3D } from '../../rendering/world3d/Object3D.js';
|
|
9
|
+
import { Mesh3D } from '../../rendering/world3d/Mesh3D.js';
|
|
10
|
+
import { createPerspectiveCamera3D } from '../../rendering/world3d/Camera3D.js';
|
|
11
|
+
import { createDirectionalLight3D, createHemisphereLight3D } from '../../rendering/world3d/Light3D.js';
|
|
12
|
+
import { createStandardMaterial3D, setColor3D } from '../../rendering/world3d/Material3D.js';
|
|
13
|
+
import { createBoxGeometry3D, createCylinderGeometry3D, createSphereGeometry3D } from '../../rendering/world3d/primitives3D.js';
|
|
14
|
+
import { linearColor3D } from '../../rendering/world3d/GeometryBuilder3D.js';
|
|
15
|
+
import { Raycaster3D } from '../../rendering/world3d/Raycast3D.js';
|
|
16
|
+
import { mat4Identity, mat4Multiply, quatToEuler, vec3TransformMat4 } from '../../rendering/world3d/math3D.js';
|
|
17
|
+
import { createWorld3DApp } from './app3D.js';
|
|
18
|
+
const invalid = (why) => new EgretError('PLAY_OPTIONS_INVALID', { cause: new TypeError(why) });
|
|
19
|
+
const finite = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
20
|
+
const above = (value) => finite(value) && value > 0;
|
|
21
|
+
const colour = (value) => typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 0xffffff;
|
|
22
|
+
const RADIANS = Math.PI / 180;
|
|
23
|
+
// Primitive geometry is transferred to its thing. Loaded models remain borrowed; burst geometry belongs to the game.
|
|
24
|
+
const ownedGeometry = new WeakMap();
|
|
25
|
+
const throwCleanupFailures = (failures) => {
|
|
26
|
+
if (failures.length === 1)
|
|
27
|
+
throw failures[0];
|
|
28
|
+
if (failures.length > 1)
|
|
29
|
+
throw new AggregateError(failures, 'Play3D cleanup failed');
|
|
30
|
+
};
|
|
31
|
+
const cleanUp = (actions) => {
|
|
32
|
+
const failures = [];
|
|
33
|
+
for (const action of actions) {
|
|
34
|
+
try {
|
|
35
|
+
action();
|
|
36
|
+
}
|
|
37
|
+
catch (cause) {
|
|
38
|
+
failures.push(cause);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throwCleanupFailures(failures);
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A thing of the world: a box, a ball, a cylinder or a cone. It is placed, turned and sized by plain numbers, which
|
|
45
|
+
* can be set at any time and tweened, and it takes properties of the game's own.
|
|
46
|
+
*/
|
|
47
|
+
export class PlayThing3D {
|
|
48
|
+
/** What the thing is drawn with: its own mesh, or the model given to `game.add`. */
|
|
49
|
+
node;
|
|
50
|
+
/** Half its width, height and depth as made, before its scale. */
|
|
51
|
+
halfX;
|
|
52
|
+
halfY;
|
|
53
|
+
halfZ;
|
|
54
|
+
/**
|
|
55
|
+
* Where the middle of its box is from its place, before its scale: 0 for what `play3d` makes, and for a model
|
|
56
|
+
* whatever its geometry says, as for a figure that stands on its place.
|
|
57
|
+
*/
|
|
58
|
+
middleX;
|
|
59
|
+
middleY;
|
|
60
|
+
middleZ;
|
|
61
|
+
#material;
|
|
62
|
+
#color;
|
|
63
|
+
#turn = [0, 0, 0];
|
|
64
|
+
#removed = false;
|
|
65
|
+
/**
|
|
66
|
+
* A thing of its own geometry and colour, or one of a model made elsewhere: then `half` and `middle` are its box,
|
|
67
|
+
* and its colour is the model's own. Geometry passed directly is owned and released when the thing leaves;
|
|
68
|
+
* an Object3D and its geometry and materials stay owned by their caller.
|
|
69
|
+
*/
|
|
70
|
+
constructor(shape, color, half, middle = [0, 0, 0]) {
|
|
71
|
+
this.#color = color;
|
|
72
|
+
if (shape instanceof Object3D) {
|
|
73
|
+
this.node = shape;
|
|
74
|
+
quatToEuler(this.#turn, shape.quaternion);
|
|
75
|
+
for (const axis of [0, 1, 2])
|
|
76
|
+
this.#turn[axis] /= RADIANS;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
ownedGeometry.set(this, shape);
|
|
80
|
+
this.#material = createStandardMaterial3D({ color, roughness: 0.75 });
|
|
81
|
+
const mesh = new Mesh3D(shape, this.#material);
|
|
82
|
+
mesh.castShadow = true;
|
|
83
|
+
mesh.receiveShadow = true;
|
|
84
|
+
this.node = mesh;
|
|
85
|
+
}
|
|
86
|
+
[this.halfX, this.halfY, this.halfZ] = half;
|
|
87
|
+
[this.middleX, this.middleY, this.middleZ] = middle;
|
|
88
|
+
}
|
|
89
|
+
#place(index, value) {
|
|
90
|
+
if (!finite(value))
|
|
91
|
+
return;
|
|
92
|
+
this.node.position[index] = value;
|
|
93
|
+
this.node.markTransformDirty();
|
|
94
|
+
}
|
|
95
|
+
#size(index, value) {
|
|
96
|
+
if (!finite(value))
|
|
97
|
+
return;
|
|
98
|
+
this.node.scale[index] = value;
|
|
99
|
+
this.node.markTransformDirty();
|
|
100
|
+
}
|
|
101
|
+
#turned(index, degrees) {
|
|
102
|
+
if (!finite(degrees))
|
|
103
|
+
return;
|
|
104
|
+
this.#turn[index] = degrees;
|
|
105
|
+
this.node.setRotation(this.#turn[0] * RADIANS, this.#turn[1] * RADIANS, this.#turn[2] * RADIANS);
|
|
106
|
+
}
|
|
107
|
+
get x() {
|
|
108
|
+
return this.node.position[0];
|
|
109
|
+
}
|
|
110
|
+
set x(value) {
|
|
111
|
+
this.#place(0, value);
|
|
112
|
+
}
|
|
113
|
+
/** Up. */
|
|
114
|
+
get y() {
|
|
115
|
+
return this.node.position[1];
|
|
116
|
+
}
|
|
117
|
+
set y(value) {
|
|
118
|
+
this.#place(1, value);
|
|
119
|
+
}
|
|
120
|
+
/** Towards the camera as the game starts; away from it is less. */
|
|
121
|
+
get z() {
|
|
122
|
+
return this.node.position[2];
|
|
123
|
+
}
|
|
124
|
+
set z(value) {
|
|
125
|
+
this.#place(2, value);
|
|
126
|
+
}
|
|
127
|
+
/** Turns about its own axes, in degrees. */
|
|
128
|
+
get rotationX() {
|
|
129
|
+
return this.#turn[0];
|
|
130
|
+
}
|
|
131
|
+
set rotationX(value) {
|
|
132
|
+
this.#turned(0, value);
|
|
133
|
+
}
|
|
134
|
+
get rotationY() {
|
|
135
|
+
return this.#turn[1];
|
|
136
|
+
}
|
|
137
|
+
set rotationY(value) {
|
|
138
|
+
this.#turned(1, value);
|
|
139
|
+
}
|
|
140
|
+
get rotationZ() {
|
|
141
|
+
return this.#turn[2];
|
|
142
|
+
}
|
|
143
|
+
set rotationZ(value) {
|
|
144
|
+
this.#turned(2, value);
|
|
145
|
+
}
|
|
146
|
+
/** Its size as a share of the size it was made with; setting it sets all three of the ones below. */
|
|
147
|
+
get scale() {
|
|
148
|
+
return this.node.scale[0];
|
|
149
|
+
}
|
|
150
|
+
set scale(value) {
|
|
151
|
+
if (!finite(value))
|
|
152
|
+
return;
|
|
153
|
+
this.node.setScale(value);
|
|
154
|
+
}
|
|
155
|
+
get scaleX() {
|
|
156
|
+
return this.node.scale[0];
|
|
157
|
+
}
|
|
158
|
+
set scaleX(value) {
|
|
159
|
+
this.#size(0, value);
|
|
160
|
+
}
|
|
161
|
+
get scaleY() {
|
|
162
|
+
return this.node.scale[1];
|
|
163
|
+
}
|
|
164
|
+
set scaleY(value) {
|
|
165
|
+
this.#size(1, value);
|
|
166
|
+
}
|
|
167
|
+
get scaleZ() {
|
|
168
|
+
return this.node.scale[2];
|
|
169
|
+
}
|
|
170
|
+
set scaleZ(value) {
|
|
171
|
+
this.#size(2, value);
|
|
172
|
+
}
|
|
173
|
+
get visible() {
|
|
174
|
+
return this.node.visible;
|
|
175
|
+
}
|
|
176
|
+
set visible(value) {
|
|
177
|
+
this.node.visible = value === true;
|
|
178
|
+
}
|
|
179
|
+
/** Its colour, `0xRRGGBB`. What is not a colour is not taken; a model keeps the colours it has. */
|
|
180
|
+
get color() {
|
|
181
|
+
return this.#color;
|
|
182
|
+
}
|
|
183
|
+
set color(value) {
|
|
184
|
+
if (!colour(value) || this.#material === undefined)
|
|
185
|
+
return;
|
|
186
|
+
this.#color = value;
|
|
187
|
+
setColor3D(this.#material.color, value);
|
|
188
|
+
}
|
|
189
|
+
/** Whether `game.remove` has taken it out of the world. Setting it afterwards does nothing that is seen. */
|
|
190
|
+
get removed() {
|
|
191
|
+
return this.#removed;
|
|
192
|
+
}
|
|
193
|
+
/** Used by game removal and teardown; only resources made for this thing are retired. */
|
|
194
|
+
leave() {
|
|
195
|
+
if (this.#removed)
|
|
196
|
+
return;
|
|
197
|
+
this.#removed = true;
|
|
198
|
+
const geometry = ownedGeometry.get(this);
|
|
199
|
+
ownedGeometry.delete(this);
|
|
200
|
+
cleanUp([() => this.node.removeFromParent(), () => geometry?.dispose(), () => this.#material?.dispose()]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const PIECES = 96;
|
|
204
|
+
/** How deep a ground is under its top. */
|
|
205
|
+
const GROUND_DEPTH = 8;
|
|
206
|
+
/** The upright box of a thing in the world: its middle and half its size, scaled. */
|
|
207
|
+
function boxOf(thing) {
|
|
208
|
+
return [
|
|
209
|
+
thing.x + thing.middleX * thing.scaleX,
|
|
210
|
+
thing.y + thing.middleY * thing.scaleY,
|
|
211
|
+
thing.z + thing.middleZ * thing.scaleZ,
|
|
212
|
+
thing.halfX * Math.abs(thing.scaleX),
|
|
213
|
+
thing.halfY * Math.abs(thing.scaleY),
|
|
214
|
+
thing.halfZ * Math.abs(thing.scaleZ)
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
/** How far two things overlap on each axis; all three are above 0 when they overlap. */
|
|
218
|
+
export function overlap3D(a, b, shrink = 0) {
|
|
219
|
+
const p = boxOf(a), q = boxOf(b);
|
|
220
|
+
return [
|
|
221
|
+
p[3] + q[3] - 2 * shrink - Math.abs(p[0] - q[0]),
|
|
222
|
+
p[4] + q[4] - 2 * shrink - Math.abs(p[1] - q[1]),
|
|
223
|
+
p[5] + q[5] - 2 * shrink - Math.abs(p[2] - q[2])
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The box of a model, in its own units and about its own place: half its size and where its middle is. Every mesh
|
|
228
|
+
* under it counts, placed as it is under it; the model's own place, turn and scale do not.
|
|
229
|
+
*/
|
|
230
|
+
export function modelBox3D(model) {
|
|
231
|
+
const low = [Infinity, Infinity, Infinity], high = [-Infinity, -Infinity, -Infinity], corner = new Float32Array(3);
|
|
232
|
+
const visit = (node, matrix) => {
|
|
233
|
+
const geometry = node.geometry;
|
|
234
|
+
if (geometry !== undefined && geometry.vertexCount > 0) {
|
|
235
|
+
const box = geometry.boundingBox;
|
|
236
|
+
for (let i = 0; i < 8; i++) {
|
|
237
|
+
corner[0] = i & 1 ? box[3] : box[0];
|
|
238
|
+
corner[1] = i & 2 ? box[4] : box[1];
|
|
239
|
+
corner[2] = i & 4 ? box[5] : box[2];
|
|
240
|
+
vec3TransformMat4(corner, corner, matrix);
|
|
241
|
+
for (let k = 0; k < 3; k++) {
|
|
242
|
+
low[k] = Math.min(low[k], corner[k]);
|
|
243
|
+
high[k] = Math.max(high[k], corner[k]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const child of node.children) {
|
|
248
|
+
child.updateWorldMatrix();
|
|
249
|
+
const placed = new Float32Array(16);
|
|
250
|
+
mat4Multiply(placed, matrix, child.matrix);
|
|
251
|
+
visit(child, placed);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
visit(model, mat4Identity(new Float32Array(16)));
|
|
255
|
+
if (!(low[0] <= high[0]))
|
|
256
|
+
return { half: [0.5, 0.5, 0.5], middle: [0, 0, 0] };
|
|
257
|
+
return {
|
|
258
|
+
half: [(high[0] - low[0]) / 2, (high[1] - low[1]) / 2, (high[2] - low[2]) / 2],
|
|
259
|
+
middle: [(high[0] + low[0]) / 2, (high[1] + low[1]) / 2, (high[2] + low[2]) / 2]
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/** The move that takes `a` out of `b` by the shortest way, or undefined when they are apart. */
|
|
263
|
+
export function pushOut3D(a, b) {
|
|
264
|
+
const [x, y, z] = overlap3D(a, b);
|
|
265
|
+
if (!(x > 0 && y > 0 && z > 0))
|
|
266
|
+
return undefined;
|
|
267
|
+
const p = boxOf(a), q = boxOf(b);
|
|
268
|
+
// Compare the same box centres as the overlap, including offset or mirrored models.
|
|
269
|
+
// Up or down first where the ways are as short as one another: a thing set down on a floor stands on it.
|
|
270
|
+
if (y <= x && y <= z)
|
|
271
|
+
return { x: 0, y: p[1] >= q[1] ? y : -y, z: 0 };
|
|
272
|
+
if (x <= z)
|
|
273
|
+
return { x: p[0] >= q[0] ? x : -x, y: 0, z: 0 };
|
|
274
|
+
return { x: 0, y: 0, z: p[2] >= q[2] ? z : -z };
|
|
275
|
+
}
|
|
276
|
+
/** Starts a 3D game in the page. See the guide `play3d.md`. */
|
|
277
|
+
export async function play3d(options) {
|
|
278
|
+
if (options === null || typeof options !== 'object')
|
|
279
|
+
throw invalid('play3d takes an object of options');
|
|
280
|
+
const { setup, update, background = 0x0b1020 } = options;
|
|
281
|
+
if (!colour(background))
|
|
282
|
+
throw invalid('background is a colour from 0 to 0xffffff');
|
|
283
|
+
if (setup !== undefined && typeof setup !== 'function')
|
|
284
|
+
throw invalid('setup is a function');
|
|
285
|
+
if (update !== undefined && typeof update !== 'function')
|
|
286
|
+
throw invalid('update is a function');
|
|
287
|
+
if (options.canvas !== undefined)
|
|
288
|
+
throw invalid('play3d makes its own canvases');
|
|
289
|
+
let game, app, creatingApp, deep, unplace;
|
|
290
|
+
let clearing = false, closing = false, generation = 0;
|
|
291
|
+
let disposal;
|
|
292
|
+
const admit = () => {
|
|
293
|
+
if (clearing || closing)
|
|
294
|
+
throw invalid('the 3D world is clearing or disposed');
|
|
295
|
+
};
|
|
296
|
+
const beginClosing = () => {
|
|
297
|
+
if (closing)
|
|
298
|
+
return;
|
|
299
|
+
closing = true;
|
|
300
|
+
generation++;
|
|
301
|
+
};
|
|
302
|
+
const scene = new Scene3D();
|
|
303
|
+
scene.background = linearColor3D(background);
|
|
304
|
+
const eye = createPerspectiveCamera3D({ fov: 55, near: 0.1, far: 500 });
|
|
305
|
+
const sky = createHemisphereLight3D({ color: 0xcfe3ff, groundColor: 0x3a3f4a, intensity: 0.9 });
|
|
306
|
+
const sun = createDirectionalLight3D({ color: 0xfff4e0, intensity: 2.4, castShadow: true });
|
|
307
|
+
sun.shadow.extent = 24;
|
|
308
|
+
sun.shadow.far = 120;
|
|
309
|
+
const things = new Set();
|
|
310
|
+
// The camera: where the game put it, what it looks at, and how far a shake has it out of place.
|
|
311
|
+
const base = [0, 6, 12], aim = [0, 0, 0], shaken = [0, 0, 0];
|
|
312
|
+
let followed, turning = false, offset = [0, 4, 8], smooth = 6, shakeAmount = 0, shakeLeft = 0, shakeSpan = 1;
|
|
313
|
+
const settle = () => {
|
|
314
|
+
eye.setPosition(base[0] + shaken[0], base[1] + shaken[1], base[2] + shaken[2]);
|
|
315
|
+
eye.lookAt(aim[0], aim[1], aim[2]);
|
|
316
|
+
// The sun keeps its direction and stays over what is looked at, so its shadows are there.
|
|
317
|
+
sun.setPosition(aim[0] + 8, aim[1] + 16, aim[2] + 10);
|
|
318
|
+
sun.lookAt(aim[0], aim[1], aim[2]);
|
|
319
|
+
};
|
|
320
|
+
const camera = {
|
|
321
|
+
get x() {
|
|
322
|
+
return base[0];
|
|
323
|
+
},
|
|
324
|
+
set x(value) {
|
|
325
|
+
if (finite(value))
|
|
326
|
+
base[0] = value;
|
|
327
|
+
},
|
|
328
|
+
get y() {
|
|
329
|
+
return base[1];
|
|
330
|
+
},
|
|
331
|
+
set y(value) {
|
|
332
|
+
if (finite(value))
|
|
333
|
+
base[1] = value;
|
|
334
|
+
},
|
|
335
|
+
get z() {
|
|
336
|
+
return base[2];
|
|
337
|
+
},
|
|
338
|
+
set z(value) {
|
|
339
|
+
if (finite(value))
|
|
340
|
+
base[2] = value;
|
|
341
|
+
},
|
|
342
|
+
get fov() {
|
|
343
|
+
return eye.fov;
|
|
344
|
+
},
|
|
345
|
+
set fov(value) {
|
|
346
|
+
if (finite(value) && value > 1 && value < 170)
|
|
347
|
+
eye.fov = value;
|
|
348
|
+
},
|
|
349
|
+
lookAt(x, y, z) {
|
|
350
|
+
if (!finite(x) || !finite(y) || !finite(z))
|
|
351
|
+
return;
|
|
352
|
+
aim[0] = x;
|
|
353
|
+
aim[1] = y;
|
|
354
|
+
aim[2] = z;
|
|
355
|
+
},
|
|
356
|
+
node: eye
|
|
357
|
+
};
|
|
358
|
+
// Pieces of a burst: a few small boxes, made once and used again.
|
|
359
|
+
const pieceShape = createBoxGeometry3D({ width: 1, height: 1, depth: 1 });
|
|
360
|
+
const pieces = [];
|
|
361
|
+
let nextPiece = 0;
|
|
362
|
+
const make = (geometry, color, half, at) => {
|
|
363
|
+
admit();
|
|
364
|
+
if (!colour(color))
|
|
365
|
+
throw invalid('a colour is a number from 0 to 0xffffff');
|
|
366
|
+
if (at === null || typeof at !== 'object')
|
|
367
|
+
throw invalid('a place is an object with x, y and z');
|
|
368
|
+
const { x, y, z } = at;
|
|
369
|
+
// Read caller properties before allocating, then recheck in case a getter began teardown.
|
|
370
|
+
admit();
|
|
371
|
+
const thing = new PlayThing3D(geometry(), color, half);
|
|
372
|
+
thing.node.setPosition(finite(x) ? x : 0, finite(y) ? y : 0, finite(z) ? z : 0);
|
|
373
|
+
scene.addChild(thing.node);
|
|
374
|
+
things.add(thing);
|
|
375
|
+
return thing;
|
|
376
|
+
};
|
|
377
|
+
const isThing = (body) => body instanceof PlayThing3D;
|
|
378
|
+
// Taps on things: found by a ray from the camera through the pointer when it goes down.
|
|
379
|
+
const taps = new Map(), ray = new Raycaster3D();
|
|
380
|
+
// A tap reports errors to the scene that received it. A returned restart may reject after that scene is gone.
|
|
381
|
+
let tapErrors = {};
|
|
382
|
+
const tapped = (flat) => {
|
|
383
|
+
if (taps.size === 0 || !flat.pointer.pressed)
|
|
384
|
+
return;
|
|
385
|
+
for (const thing of taps.keys())
|
|
386
|
+
if (thing.removed)
|
|
387
|
+
taps.delete(thing);
|
|
388
|
+
eye.updateWorldMatrices();
|
|
389
|
+
scene.updateWorldMatrices();
|
|
390
|
+
ray.setFromCamera((flat.pointer.x / flat.width) * 2 - 1, 1 - (flat.pointer.y / flat.height) * 2, eye);
|
|
391
|
+
let hits;
|
|
392
|
+
try {
|
|
393
|
+
hits = ray.intersect(scene);
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
for (const hit of hits) {
|
|
399
|
+
// The thing a mesh that was hit belongs to: the nearest one up its line that has a tap.
|
|
400
|
+
for (let node = hit.object; node !== undefined; node = node.parent) {
|
|
401
|
+
const thing = [...taps.keys()].find(each => each.node === node);
|
|
402
|
+
if (thing === undefined || !thing.visible)
|
|
403
|
+
continue;
|
|
404
|
+
const callback = taps.get(thing);
|
|
405
|
+
const owner = tapErrors;
|
|
406
|
+
const fail = (cause) => {
|
|
407
|
+
owner.failure ??= { cause };
|
|
408
|
+
};
|
|
409
|
+
try {
|
|
410
|
+
const result = callback();
|
|
411
|
+
if (result !== null && result !== undefined && typeof result.then === 'function')
|
|
412
|
+
result.then(undefined, fail);
|
|
413
|
+
}
|
|
414
|
+
catch (cause) {
|
|
415
|
+
fail(cause);
|
|
416
|
+
}
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
const clear = () => {
|
|
422
|
+
if (clearing)
|
|
423
|
+
throw invalid('the 3D world is clearing or disposed');
|
|
424
|
+
clearing = true;
|
|
425
|
+
generation++;
|
|
426
|
+
try {
|
|
427
|
+
const leaving = [...things];
|
|
428
|
+
things.clear();
|
|
429
|
+
taps.clear();
|
|
430
|
+
tapErrors = {};
|
|
431
|
+
for (const piece of pieces) {
|
|
432
|
+
piece.life = 0;
|
|
433
|
+
piece.thing.visible = false;
|
|
434
|
+
}
|
|
435
|
+
followed = undefined;
|
|
436
|
+
base[0] = 0;
|
|
437
|
+
base[1] = 6;
|
|
438
|
+
base[2] = 12;
|
|
439
|
+
aim[0] = aim[1] = aim[2] = 0;
|
|
440
|
+
shakeLeft = 0;
|
|
441
|
+
shaken[0] = shaken[1] = shaken[2] = 0;
|
|
442
|
+
cleanUp(leaving.map(thing => () => thing.leave()));
|
|
443
|
+
}
|
|
444
|
+
finally {
|
|
445
|
+
clearing = false;
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
const disposeWorld = async () => {
|
|
449
|
+
beginClosing();
|
|
450
|
+
const failures = [];
|
|
451
|
+
// Join only the SDK factory. Application setup may still be waiting on an unrelated download.
|
|
452
|
+
if (creatingApp !== undefined) {
|
|
453
|
+
try {
|
|
454
|
+
await creatingApp;
|
|
455
|
+
}
|
|
456
|
+
catch (cause) {
|
|
457
|
+
failures.push(cause);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
cleanUp([
|
|
462
|
+
clear,
|
|
463
|
+
...pieces.map(piece => () => piece.thing.leave()),
|
|
464
|
+
() => pieceShape.dispose(),
|
|
465
|
+
() => unplace?.(),
|
|
466
|
+
() => app?.dispose(),
|
|
467
|
+
() => deep?.remove()
|
|
468
|
+
]);
|
|
469
|
+
}
|
|
470
|
+
catch (cause) {
|
|
471
|
+
failures.push(cause);
|
|
472
|
+
}
|
|
473
|
+
try {
|
|
474
|
+
// World3DApp is a synchronous Disposable. Its Engine owns the shared asynchronous close result.
|
|
475
|
+
await app?.engine.dispose();
|
|
476
|
+
}
|
|
477
|
+
catch (cause) {
|
|
478
|
+
failures.push(cause);
|
|
479
|
+
}
|
|
480
|
+
throwCleanupFailures(failures);
|
|
481
|
+
};
|
|
482
|
+
// Where the camera keeps to by a thing: its offset, turned with the thing when asked.
|
|
483
|
+
const placeBy = (thing) => {
|
|
484
|
+
let [x, y, z] = offset;
|
|
485
|
+
if (turning) {
|
|
486
|
+
const turn = thing.rotationY * RADIANS, c = Math.cos(turn), s = Math.sin(turn);
|
|
487
|
+
[x, z] = [x * c + z * s, -x * s + z * c];
|
|
488
|
+
}
|
|
489
|
+
return [thing.x + x, thing.y + y, thing.z + z];
|
|
490
|
+
};
|
|
491
|
+
const after = (seconds) => {
|
|
492
|
+
if (followed !== undefined && !followed.removed) {
|
|
493
|
+
const share = smooth > 0 ? 1 - Math.exp(-smooth * seconds) : 1, [x, y, z] = placeBy(followed);
|
|
494
|
+
base[0] = base[0] + (x - base[0]) * share;
|
|
495
|
+
base[1] = base[1] + (y - base[1]) * share;
|
|
496
|
+
base[2] = base[2] + (z - base[2]) * share;
|
|
497
|
+
aim[0] = followed.x;
|
|
498
|
+
aim[1] = followed.y;
|
|
499
|
+
aim[2] = followed.z;
|
|
500
|
+
}
|
|
501
|
+
if (shakeLeft > 0) {
|
|
502
|
+
shakeLeft -= seconds;
|
|
503
|
+
const reach = shakeLeft > 0 ? shakeAmount * (shakeLeft / shakeSpan) : 0;
|
|
504
|
+
for (let i = 0; i < 3; i++)
|
|
505
|
+
shaken[i] = (Math.random() * 2 - 1) * reach;
|
|
506
|
+
}
|
|
507
|
+
for (const piece of pieces) {
|
|
508
|
+
if (piece.life <= 0)
|
|
509
|
+
continue;
|
|
510
|
+
piece.life -= seconds;
|
|
511
|
+
if (piece.life <= 0) {
|
|
512
|
+
piece.thing.visible = false;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
piece.vy -= piece.gravity * seconds;
|
|
516
|
+
piece.thing.x += piece.vx * seconds;
|
|
517
|
+
piece.thing.y += piece.vy * seconds;
|
|
518
|
+
piece.thing.z += piece.vz * seconds;
|
|
519
|
+
piece.thing.scale = piece.size * (piece.life / piece.span);
|
|
520
|
+
}
|
|
521
|
+
settle();
|
|
522
|
+
};
|
|
523
|
+
const extend = (flat) => {
|
|
524
|
+
const added = {
|
|
525
|
+
box(width, height, depth, color, at = {}) {
|
|
526
|
+
admit();
|
|
527
|
+
if (!above(width) || !above(height) || !above(depth))
|
|
528
|
+
throw invalid('a box has a width, height and depth above 0');
|
|
529
|
+
return make(() => createBoxGeometry3D({ width, height, depth }), color, [width / 2, height / 2, depth / 2], at);
|
|
530
|
+
},
|
|
531
|
+
sphere(radius, color, at = {}) {
|
|
532
|
+
admit();
|
|
533
|
+
if (!above(radius))
|
|
534
|
+
throw invalid('a sphere has a radius above 0');
|
|
535
|
+
return make(() => createSphereGeometry3D({ radius, widthSegments: 24, heightSegments: 16 }), color, [radius, radius, radius], at);
|
|
536
|
+
},
|
|
537
|
+
cylinder(radius, height, color, at = {}) {
|
|
538
|
+
admit();
|
|
539
|
+
if (!above(radius) || !above(height))
|
|
540
|
+
throw invalid('a cylinder has a radius and a height above 0');
|
|
541
|
+
return make(() => createCylinderGeometry3D({ radiusTop: radius, radiusBottom: radius, height, radialSegments: 24 }), color, [radius, height / 2, radius], at);
|
|
542
|
+
},
|
|
543
|
+
cone(radius, height, color, at = {}) {
|
|
544
|
+
admit();
|
|
545
|
+
if (!above(radius) || !above(height))
|
|
546
|
+
throw invalid('a cone has a radius and a height above 0');
|
|
547
|
+
return make(() => createCylinderGeometry3D({ radiusTop: 0, radiusBottom: radius, height, radialSegments: 24 }), color, [radius, height / 2, radius], at);
|
|
548
|
+
},
|
|
549
|
+
ground(size, color, y = 0) {
|
|
550
|
+
admit();
|
|
551
|
+
if (!above(size) || !finite(y))
|
|
552
|
+
throw invalid('a ground has a size above 0');
|
|
553
|
+
// Deep, so that a thing falling fast in a slow frame is still pushed back up out of it and not through it.
|
|
554
|
+
const thing = make(() => createBoxGeometry3D({ width: size, height: GROUND_DEPTH, depth: size }), color, [size / 2, GROUND_DEPTH / 2, size / 2], {
|
|
555
|
+
y: y - GROUND_DEPTH / 2
|
|
556
|
+
});
|
|
557
|
+
thing.node.castShadow = false;
|
|
558
|
+
return thing;
|
|
559
|
+
},
|
|
560
|
+
add(model, at = {}) {
|
|
561
|
+
admit();
|
|
562
|
+
if (!(model instanceof Object3D))
|
|
563
|
+
throw invalid('add takes a mesh, a group or a loaded model');
|
|
564
|
+
if (at === null || typeof at !== 'object')
|
|
565
|
+
throw invalid('a place is an object with x, y and z');
|
|
566
|
+
const { x, y, z } = at;
|
|
567
|
+
admit();
|
|
568
|
+
const { half, middle } = modelBox3D(model);
|
|
569
|
+
admit();
|
|
570
|
+
if (model.parent !== undefined)
|
|
571
|
+
model.removeFromParent();
|
|
572
|
+
const thing = new PlayThing3D(model, 0xffffff, half, middle);
|
|
573
|
+
if (finite(x))
|
|
574
|
+
thing.x = x;
|
|
575
|
+
if (finite(y))
|
|
576
|
+
thing.y = y;
|
|
577
|
+
if (finite(z))
|
|
578
|
+
thing.z = z;
|
|
579
|
+
scene.addChild(model);
|
|
580
|
+
things.add(thing);
|
|
581
|
+
return thing;
|
|
582
|
+
},
|
|
583
|
+
onTap(target, callback) {
|
|
584
|
+
if (typeof callback !== 'function')
|
|
585
|
+
throw invalid('onTap takes a thing or a sprite, and a function');
|
|
586
|
+
if (!isThing(target)) {
|
|
587
|
+
flat.onTap(target, callback);
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
taps.set(target, callback);
|
|
591
|
+
},
|
|
592
|
+
remove(body) {
|
|
593
|
+
if (isThing(body)) {
|
|
594
|
+
things.delete(body);
|
|
595
|
+
taps.delete(body);
|
|
596
|
+
if (followed === body)
|
|
597
|
+
followed = undefined;
|
|
598
|
+
body.leave();
|
|
599
|
+
}
|
|
600
|
+
else
|
|
601
|
+
flat.remove(body);
|
|
602
|
+
},
|
|
603
|
+
near(a, b, distance) {
|
|
604
|
+
if (!isThing(a) || !isThing(b))
|
|
605
|
+
return !isThing(a) && !isThing(b) && flat.near(a, b, distance ?? 0);
|
|
606
|
+
if (a.removed || b.removed || !a.visible || !b.visible)
|
|
607
|
+
return false;
|
|
608
|
+
const reach = distance ??
|
|
609
|
+
Math.max(a.halfX * Math.abs(a.scaleX), a.halfZ * Math.abs(a.scaleZ)) +
|
|
610
|
+
Math.max(b.halfX * Math.abs(b.scaleX), b.halfZ * Math.abs(b.scaleZ));
|
|
611
|
+
const dx = a.x - b.x, dy = a.y - b.y, dz = a.z - b.z;
|
|
612
|
+
return dx * dx + dy * dy + dz * dz <= reach * reach;
|
|
613
|
+
},
|
|
614
|
+
overlaps(a, b, shrink = 0) {
|
|
615
|
+
if (!isThing(a) || !isThing(b))
|
|
616
|
+
return !isThing(a) && !isThing(b) && flat.overlaps(a, b, shrink);
|
|
617
|
+
if (a === b || a.removed || b.removed || !a.visible || !b.visible)
|
|
618
|
+
return false;
|
|
619
|
+
const [x, y, z] = overlap3D(a, b, finite(shrink) ? shrink : 0);
|
|
620
|
+
return x > 0 && y > 0 && z > 0;
|
|
621
|
+
},
|
|
622
|
+
hits(a, others, shrink = 0) {
|
|
623
|
+
for (const other of others)
|
|
624
|
+
if (other !== a && whole.overlaps(a, other, shrink))
|
|
625
|
+
return other;
|
|
626
|
+
return undefined;
|
|
627
|
+
},
|
|
628
|
+
hitsAll(a, others, shrink = 0) {
|
|
629
|
+
return others.filter(other => other !== a && whole.overlaps(a, other, shrink));
|
|
630
|
+
},
|
|
631
|
+
pushOut(a, b) {
|
|
632
|
+
if (!isThing(a) || !isThing(b) || a === b || a.removed || b.removed || !a.visible || !b.visible)
|
|
633
|
+
return undefined;
|
|
634
|
+
return pushOut3D(a, b);
|
|
635
|
+
},
|
|
636
|
+
follow(thing, where = {}) {
|
|
637
|
+
if (thing !== undefined && !isThing(thing))
|
|
638
|
+
throw invalid('follow takes a thing of the world');
|
|
639
|
+
followed = thing;
|
|
640
|
+
if (thing === undefined)
|
|
641
|
+
return;
|
|
642
|
+
offset = [finite(where.x) ? where.x : 0, finite(where.y) ? where.y : 4, finite(where.z) ? where.z : 8];
|
|
643
|
+
smooth = finite(where.smooth) && where.smooth >= 0 ? where.smooth : 6;
|
|
644
|
+
turning = where.turn === true;
|
|
645
|
+
// It starts where it will stay, and does not fly in from where the camera was.
|
|
646
|
+
[base[0], base[1], base[2]] = placeBy(thing);
|
|
647
|
+
aim[0] = thing.x;
|
|
648
|
+
aim[1] = thing.y;
|
|
649
|
+
aim[2] = thing.z;
|
|
650
|
+
},
|
|
651
|
+
hitStop(seconds = 0.06) {
|
|
652
|
+
flat.hitStop(seconds);
|
|
653
|
+
if (above(seconds))
|
|
654
|
+
generation++;
|
|
655
|
+
},
|
|
656
|
+
shake(amount = 0.3, seconds = 0.25) {
|
|
657
|
+
if (!above(amount) || !above(seconds))
|
|
658
|
+
return;
|
|
659
|
+
shakeAmount = Math.max(shakeLeft > 0 ? shakeAmount : 0, Math.min(amount, 10));
|
|
660
|
+
shakeLeft = shakeSpan = Math.min(seconds, 5);
|
|
661
|
+
},
|
|
662
|
+
burst(x, y, z, o = {}) {
|
|
663
|
+
admit();
|
|
664
|
+
if (!finite(x) || !finite(y) || !finite(z) || o === null || typeof o !== 'object')
|
|
665
|
+
return;
|
|
666
|
+
const count = Math.min(PIECES, Math.max(1, Math.floor(finite(o.count) ? o.count : 12))), speed = above(o.speed) ? o.speed : 5, life = above(o.life) ? Math.min(o.life, 10) : 0.6, size = above(o.size) ? o.size : 0.18, gravity = finite(o.gravity) ? o.gravity : 12, color = colour(o.color) ? o.color : 0xffffff;
|
|
667
|
+
admit();
|
|
668
|
+
for (let i = 0; i < count; i++) {
|
|
669
|
+
let piece = pieces[nextPiece];
|
|
670
|
+
if (piece === undefined) {
|
|
671
|
+
const thing = new PlayThing3D(pieceShape, color, [0.5, 0.5, 0.5]);
|
|
672
|
+
// Pieces own their separate material, while the game owns their one shared shape.
|
|
673
|
+
ownedGeometry.delete(thing);
|
|
674
|
+
thing.node.castShadow = false;
|
|
675
|
+
scene.addChild(thing.node);
|
|
676
|
+
piece = pieces[nextPiece] = { thing, vx: 0, vy: 0, vz: 0, life: 0, span: 1, gravity: 0, size: 1 };
|
|
677
|
+
}
|
|
678
|
+
nextPiece = (nextPiece + 1) % PIECES;
|
|
679
|
+
// A direction over the whole ball, a little upwards.
|
|
680
|
+
const turn = flat.random.range(0, 2 * Math.PI), lift = flat.random.range(-0.4, 1), flatness = Math.sqrt(Math.max(0, 1 - lift * lift)), pace = speed * flat.random.range(0.5, 1);
|
|
681
|
+
piece.vx = Math.cos(turn) * flatness * pace;
|
|
682
|
+
piece.vy = lift * pace;
|
|
683
|
+
piece.vz = Math.sin(turn) * flatness * pace;
|
|
684
|
+
piece.life = piece.span = life * flat.random.range(0.6, 1);
|
|
685
|
+
piece.gravity = gravity;
|
|
686
|
+
piece.size = size;
|
|
687
|
+
piece.thing.color = color;
|
|
688
|
+
piece.thing.x = x;
|
|
689
|
+
piece.thing.y = y;
|
|
690
|
+
piece.thing.z = z;
|
|
691
|
+
piece.thing.scale = size;
|
|
692
|
+
piece.thing.visible = true;
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
dispose() {
|
|
696
|
+
if (disposal !== undefined)
|
|
697
|
+
return disposal;
|
|
698
|
+
beginClosing();
|
|
699
|
+
// Publish before callbacks, but stop the flat game synchronously so a motion cannot keep chaining.
|
|
700
|
+
let resolve, reject;
|
|
701
|
+
disposal = new Promise((done, fail) => {
|
|
702
|
+
resolve = done;
|
|
703
|
+
reject = fail;
|
|
704
|
+
});
|
|
705
|
+
void (async () => {
|
|
706
|
+
const failures = [];
|
|
707
|
+
try {
|
|
708
|
+
await flat.dispose();
|
|
709
|
+
}
|
|
710
|
+
catch (cause) {
|
|
711
|
+
failures.push(cause);
|
|
712
|
+
}
|
|
713
|
+
try {
|
|
714
|
+
await disposeWorld();
|
|
715
|
+
}
|
|
716
|
+
catch (cause) {
|
|
717
|
+
failures.push(cause);
|
|
718
|
+
}
|
|
719
|
+
throwCleanupFailures(failures);
|
|
720
|
+
})().then(resolve, reject);
|
|
721
|
+
return disposal;
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
// Everything of the flat game is there under these: its getters read the game's own state, whoever asks.
|
|
725
|
+
const whole = Object.create(flat, {
|
|
726
|
+
...Object.getOwnPropertyDescriptors(added),
|
|
727
|
+
scene: { value: scene, enumerable: true },
|
|
728
|
+
camera: { value: camera, enumerable: true },
|
|
729
|
+
sun: { value: sun, enumerable: true },
|
|
730
|
+
app: {
|
|
731
|
+
get: () => app,
|
|
732
|
+
enumerable: true
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
return whole;
|
|
736
|
+
};
|
|
737
|
+
const flat = await play({
|
|
738
|
+
...options,
|
|
739
|
+
// The interface is drawn by WebGL2 unless WebGPU is asked for, as the overlay of a World3D app is.
|
|
740
|
+
backend: options.backend ?? 'webgl2',
|
|
741
|
+
transparent: true,
|
|
742
|
+
async setup(given) {
|
|
743
|
+
admit();
|
|
744
|
+
if (game === undefined) {
|
|
745
|
+
// The picture goes on a canvas of its own, under the game's, in the same place whatever the page does.
|
|
746
|
+
const over = given.canvas, holder = over.parentElement;
|
|
747
|
+
if (holder === null)
|
|
748
|
+
throw invalid('play3d needs its canvas in the page');
|
|
749
|
+
const page = over.ownerDocument, win = page.defaultView ?? globalThis;
|
|
750
|
+
const under = (deep = page.createElement('canvas'));
|
|
751
|
+
under.style.cssText = 'position:absolute;left:0;top:0;width:0;height:0;display:block';
|
|
752
|
+
over.style.position = 'relative';
|
|
753
|
+
holder.insertBefore(under, over);
|
|
754
|
+
const place = () => {
|
|
755
|
+
const outer = holder.getBoundingClientRect(), box = over.getBoundingClientRect();
|
|
756
|
+
under.style.left = box.left - outer.left + holder.scrollLeft + 'px';
|
|
757
|
+
under.style.top = box.top - outer.top + holder.scrollTop + 'px';
|
|
758
|
+
under.style.width = box.width + 'px';
|
|
759
|
+
under.style.height = box.height + 'px';
|
|
760
|
+
};
|
|
761
|
+
place();
|
|
762
|
+
const Resize = globalThis.ResizeObserver, observer = Resize ? new Resize(place) : undefined;
|
|
763
|
+
observer?.observe(over);
|
|
764
|
+
win.addEventListener('resize', place);
|
|
765
|
+
unplace = () => {
|
|
766
|
+
observer?.disconnect();
|
|
767
|
+
win.removeEventListener('resize', place);
|
|
768
|
+
};
|
|
769
|
+
creatingApp = createWorld3DApp(under, {
|
|
770
|
+
backend: options.backend === 'webgpu' ? 'webgpu' : 'webgl2',
|
|
771
|
+
...(options.onError === undefined ? {} : { onError: options.onError })
|
|
772
|
+
});
|
|
773
|
+
try {
|
|
774
|
+
app = await creatingApp;
|
|
775
|
+
}
|
|
776
|
+
finally {
|
|
777
|
+
creatingApp = undefined;
|
|
778
|
+
}
|
|
779
|
+
if (closing || given.scope.state !== 'open')
|
|
780
|
+
throw new EgretError('SCOPE_CLOSED');
|
|
781
|
+
scene.addChild(eye);
|
|
782
|
+
scene.addChild(sky);
|
|
783
|
+
scene.addChild(sun);
|
|
784
|
+
settle();
|
|
785
|
+
app.show(scene, eye);
|
|
786
|
+
game = extend(given);
|
|
787
|
+
}
|
|
788
|
+
else
|
|
789
|
+
clear();
|
|
790
|
+
try {
|
|
791
|
+
await setup?.(game);
|
|
792
|
+
if (closing || given.scope.state !== 'open')
|
|
793
|
+
throw new EgretError('SCOPE_CLOSED');
|
|
794
|
+
settle();
|
|
795
|
+
}
|
|
796
|
+
catch (cause) {
|
|
797
|
+
// A failed setup may already have attached borrowed models and allocated owned primitives.
|
|
798
|
+
if (!closing) {
|
|
799
|
+
try {
|
|
800
|
+
clear();
|
|
801
|
+
}
|
|
802
|
+
catch (cleanupFailure) {
|
|
803
|
+
throw new AggregateError([cause, cleanupFailure], 'Play3D setup and rollback failed');
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
throw cause;
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
update(seconds) {
|
|
810
|
+
if (game === undefined)
|
|
811
|
+
return;
|
|
812
|
+
const current = game, version = generation;
|
|
813
|
+
const running = () => generation === version &&
|
|
814
|
+
!clearing &&
|
|
815
|
+
!closing &&
|
|
816
|
+
!current.paused &&
|
|
817
|
+
current.scope.state === 'open' &&
|
|
818
|
+
current.browser.loop.state === 'running';
|
|
819
|
+
if (!running())
|
|
820
|
+
return;
|
|
821
|
+
if (tapErrors.failure !== undefined) {
|
|
822
|
+
const { cause } = tapErrors.failure;
|
|
823
|
+
delete tapErrors.failure;
|
|
824
|
+
throw cause;
|
|
825
|
+
}
|
|
826
|
+
tapped(current);
|
|
827
|
+
if (!running())
|
|
828
|
+
return;
|
|
829
|
+
update?.(seconds, current);
|
|
830
|
+
if (!running())
|
|
831
|
+
return;
|
|
832
|
+
after(seconds);
|
|
833
|
+
}
|
|
834
|
+
}).catch(async (cause) => {
|
|
835
|
+
try {
|
|
836
|
+
// A callback may have closed the published game while its initial setup was pending.
|
|
837
|
+
if (game === undefined)
|
|
838
|
+
await disposeWorld();
|
|
839
|
+
else
|
|
840
|
+
await game.dispose();
|
|
841
|
+
}
|
|
842
|
+
catch (cleanupFailure) {
|
|
843
|
+
if (cause === cleanupFailure)
|
|
844
|
+
throw cause;
|
|
845
|
+
throw new AggregateError([cause, cleanupFailure], 'Play3D setup and cleanup failed');
|
|
846
|
+
}
|
|
847
|
+
throw cause;
|
|
848
|
+
});
|
|
849
|
+
return game ?? extend(flat);
|
|
850
|
+
}
|
|
851
|
+
//# sourceMappingURL=BrowserPlay3D.js.map
|