@egret/engine 0.0.0-stage → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +101 -2
- package/README.zh-CN.md +102 -0
- package/dist/Engine.d.ts +77 -0
- package/dist/Engine.js +469 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.js +5 -0
- package/dist/animation/sequenceController.d.ts +22 -0
- package/dist/animation/sequenceController.js +618 -0
- package/dist/animation/sequenceCoordinator.d.ts +26 -0
- package/dist/animation/sequenceCoordinator.js +161 -0
- package/dist/animation/sequenceInput.d.ts +25 -0
- package/dist/animation/sequenceInput.js +108 -0
- package/dist/animation/sequenceMath.d.ts +35 -0
- package/dist/animation/sequenceMath.js +164 -0
- package/dist/animation/sequenceResetSlot.d.ts +7 -0
- package/dist/animation/sequenceResetSlot.js +367 -0
- package/dist/animation/sequenceResetTypes.d.ts +48 -0
- package/dist/animation/sequenceResetTypes.js +2 -0
- package/dist/animation/types.d.ts +75 -0
- package/dist/animation/types.js +2 -0
- package/dist/assetBundle.d.ts +54 -0
- package/dist/assetBundle.js +173 -0
- package/dist/assetGroup.d.ts +17 -0
- package/dist/assetGroup.js +332 -0
- package/dist/assetGroupTypes.d.ts +17 -0
- package/dist/assetGroupTypes.js +2 -0
- package/dist/audio.d.ts +4 -0
- package/dist/audio.js +4 -0
- package/dist/audioCues.d.ts +47 -0
- package/dist/audioCues.js +127 -0
- package/dist/audioMixer.d.ts +7 -0
- package/dist/audioMixer.js +785 -0
- package/dist/audioTypes.d.ts +246 -0
- package/dist/audioTypes.js +3 -0
- package/dist/bitmapBindingTicket.d.ts +24 -0
- package/dist/bitmapBindingTicket.js +215 -0
- package/dist/bitmapButton.d.ts +4 -0
- package/dist/bitmapButton.js +407 -0
- package/dist/bitmapButtonTypes.d.ts +31 -0
- package/dist/bitmapButtonTypes.js +2 -0
- package/dist/bitmapFontParse.d.ts +10 -0
- package/dist/bitmapFontParse.js +246 -0
- package/dist/bitmapFontTypes.d.ts +112 -0
- package/dist/bitmapFontTypes.js +2 -0
- package/dist/bitmapResourceSlot.d.ts +26 -0
- package/dist/bitmapResourceSlot.js +340 -0
- package/dist/bitmapText.d.ts +6 -0
- package/dist/bitmapText.js +320 -0
- package/dist/bitmapfont.d.ts +5 -0
- package/dist/bitmapfont.js +5 -0
- package/dist/camera.d.ts +4 -0
- package/dist/camera.js +4 -0
- package/dist/camera2d.d.ts +7 -0
- package/dist/camera2d.js +419 -0
- package/dist/cameraTypes.d.ts +126 -0
- package/dist/cameraTypes.js +2 -0
- package/dist/closeHost.d.ts +4 -0
- package/dist/closeHost.js +66 -0
- package/dist/contentArtifacts.d.ts +12 -0
- package/dist/contentArtifacts.js +153 -0
- package/dist/contentAtlasPages.d.ts +13 -0
- package/dist/contentAtlasPages.js +117 -0
- package/dist/contentLoader.d.ts +6 -0
- package/dist/contentLoader.js +327 -0
- package/dist/contentTypes.d.ts +35 -0
- package/dist/contentTypes.js +2 -0
- package/dist/createEngine.d.ts +7 -0
- package/dist/createEngine.js +25 -0
- package/dist/createEngineForProfile.d.ts +5 -0
- package/dist/createEngineForProfile.js +45 -0
- package/dist/displaySubtreeTicket.d.ts +25 -0
- package/dist/displaySubtreeTicket.js +76 -0
- package/dist/fontContentLoader.d.ts +6 -0
- package/dist/fontContentLoader.js +298 -0
- package/dist/fontContentTypes.d.ts +39 -0
- package/dist/fontContentTypes.js +2 -0
- package/dist/gameClock.d.ts +24 -0
- package/dist/gameClock.js +246 -0
- package/dist/gameClockTypes.d.ts +37 -0
- package/dist/gameClockTypes.js +2 -0
- package/dist/gameRun.d.ts +53 -0
- package/dist/gameRun.js +97 -0
- package/dist/gamepad.d.ts +5 -0
- package/dist/gamepad.js +5 -0
- package/dist/gamepadInput.d.ts +4 -0
- package/dist/gamepadInput.js +281 -0
- package/dist/gamepadKeys.d.ts +4 -0
- package/dist/gamepadKeys.js +205 -0
- package/dist/gamepadTypes.d.ts +142 -0
- package/dist/gamepadTypes.js +3 -0
- package/dist/hover.d.ts +4 -0
- package/dist/hover.js +4 -0
- package/dist/hoverInput.d.ts +8 -0
- package/dist/hoverInput.js +503 -0
- package/dist/hoverInputTypes.d.ts +129 -0
- package/dist/hoverInputTypes.js +2 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +21 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +5 -0
- package/dist/inputActions.d.ts +86 -0
- package/dist/inputActions.js +330 -0
- package/dist/internal/contentFactoryState.d.ts +19 -0
- package/dist/internal/contentFactoryState.js +42 -0
- package/dist/internal/mouseInputFactoryState.d.ts +57 -0
- package/dist/internal/mouseInputFactoryState.js +125 -0
- package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
- package/dist/internal/sequenceControllerFactoryState.js +98 -0
- package/dist/internal/textFieldFactoryState.d.ts +11 -0
- package/dist/internal/textFieldFactoryState.js +32 -0
- package/dist/internal/texturedFrameState.d.ts +4 -0
- package/dist/internal/texturedFrameState.js +12 -0
- package/dist/internal/uiFactoryState.d.ts +68 -0
- package/dist/internal/uiFactoryState.js +173 -0
- package/dist/internal/uiRootState.d.ts +67 -0
- package/dist/internal/uiRootState.js +103 -0
- package/dist/keyboardInput.d.ts +13 -0
- package/dist/keyboardInput.js +579 -0
- package/dist/keyboardInputTypes.d.ts +93 -0
- package/dist/keyboardInputTypes.js +2 -0
- package/dist/kit.d.ts +16 -0
- package/dist/kit.js +10 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.js +132 -0
- package/dist/layoutTypes.d.ts +28 -0
- package/dist/layoutTypes.js +2 -0
- package/dist/manifestAssetGroup.d.ts +10 -0
- package/dist/manifestAssetGroup.js +477 -0
- package/dist/manifestResourceState.d.ts +17 -0
- package/dist/manifestResourceState.js +58 -0
- package/dist/manifestResourceTypes.d.ts +26 -0
- package/dist/manifestResourceTypes.js +2 -0
- package/dist/motion.d.ts +35 -0
- package/dist/motion.js +206 -0
- package/dist/mouseInput.d.ts +102 -0
- package/dist/mouseInput.js +562 -0
- package/dist/mouseInputTypes.d.ts +41 -0
- package/dist/mouseInputTypes.js +2 -0
- package/dist/paragraph.d.ts +8 -0
- package/dist/paragraph.js +7 -0
- package/dist/particleEmitter.d.ts +4 -0
- package/dist/particleEmitter.js +300 -0
- package/dist/particleTypes.d.ts +115 -0
- package/dist/particleTypes.js +2 -0
- package/dist/particles.d.ts +4 -0
- package/dist/particles.js +4 -0
- package/dist/physics2d.d.ts +4 -0
- package/dist/physics2d.js +4 -0
- package/dist/physics2dGeometry.d.ts +39 -0
- package/dist/physics2dGeometry.js +230 -0
- package/dist/physics2dTypes.d.ts +221 -0
- package/dist/physics2dTypes.js +2 -0
- package/dist/physics2dWorld.d.ts +4 -0
- package/dist/physics2dWorld.js +823 -0
- package/dist/pointerInput.d.ts +12 -0
- package/dist/pointerInput.js +300 -0
- package/dist/pointerInputTypes.d.ts +41 -0
- package/dist/pointerInputTypes.js +2 -0
- package/dist/random.d.ts +30 -0
- package/dist/random.js +131 -0
- package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
- package/dist/rendering/ownedPreparationFailure2D.js +33 -0
- package/dist/rendering/packSharedDraws2D.d.ts +50 -0
- package/dist/rendering/packSharedDraws2D.js +379 -0
- package/dist/rendering/packedOrientation.d.ts +4 -0
- package/dist/rendering/packedOrientation.js +7 -0
- package/dist/rendering/prepareRectangles2D.d.ts +92 -0
- package/dist/rendering/prepareRectangles2D.js +481 -0
- package/dist/rendering/prepareSharedDraws2D.d.ts +90 -0
- package/dist/rendering/prepareSharedDraws2D.js +663 -0
- package/dist/rendering/preparedBatches2D.d.ts +17 -0
- package/dist/rendering/preparedBatches2D.js +30 -0
- package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
- package/dist/rendering/preparedSharedBatches2D.js +247 -0
- package/dist/rendering/sharedColor2D.d.ts +52 -0
- package/dist/rendering/sharedColor2D.js +191 -0
- package/dist/rendering/sharedEffects2D.d.ts +23 -0
- package/dist/rendering/sharedEffects2D.js +126 -0
- package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
- package/dist/rendering/sharedPreparationRetention2D.js +357 -0
- package/dist/rendering/srgbBytes.d.ts +3 -0
- package/dist/rendering/srgbBytes.js +64 -0
- package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
- package/dist/rendering/texturedPreparationBudget2D.js +81 -0
- package/dist/rendering/world3d/Animation3D.d.ts +104 -0
- package/dist/rendering/world3d/Animation3D.js +384 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +163 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +603 -0
- package/dist/rendering/world3d/Batch3D.d.ts +75 -0
- package/dist/rendering/world3d/Batch3D.js +332 -0
- package/dist/rendering/world3d/Camera3D.d.ts +62 -0
- package/dist/rendering/world3d/Camera3D.js +132 -0
- package/dist/rendering/world3d/Character3D.d.ts +127 -0
- package/dist/rendering/world3d/Character3D.js +305 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +130 -0
- package/dist/rendering/world3d/Cloth3D.js +503 -0
- package/dist/rendering/world3d/Compression3D.d.ts +22 -0
- package/dist/rendering/world3d/Compression3D.js +703 -0
- package/dist/rendering/world3d/Curves3D.d.ts +119 -0
- package/dist/rendering/world3d/Curves3D.js +460 -0
- package/dist/rendering/world3d/Decal3D.d.ts +43 -0
- package/dist/rendering/world3d/Decal3D.js +242 -0
- package/dist/rendering/world3d/Export3D.d.ts +13 -0
- package/dist/rendering/world3d/Export3D.js +263 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +95 -0
- package/dist/rendering/world3d/Geometry3D.js +335 -0
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +53 -0
- package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +80 -0
- package/dist/rendering/world3d/Gizmo3D.js +514 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +73 -0
- package/dist/rendering/world3d/Gltf3D.js +996 -0
- package/dist/rendering/world3d/GpuParticles3D.d.ts +109 -0
- package/dist/rendering/world3d/GpuParticles3D.js +401 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +35 -0
- package/dist/rendering/world3d/Hdr3D.js +191 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +77 -0
- package/dist/rendering/world3d/Jelly3D.js +267 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +30 -0
- package/dist/rendering/world3d/Ktx23D.js +112 -0
- package/dist/rendering/world3d/Light3D.d.ts +84 -0
- package/dist/rendering/world3d/Light3D.js +97 -0
- package/dist/rendering/world3d/Material3D.d.ts +253 -0
- package/dist/rendering/world3d/Material3D.js +269 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +112 -0
- package/dist/rendering/world3d/Mesh3D.js +337 -0
- package/dist/rendering/world3d/Meshopt3D.d.ts +15 -0
- package/dist/rendering/world3d/Meshopt3D.js +276 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +213 -0
- package/dist/rendering/world3d/Navigation3D.js +1043 -0
- package/dist/rendering/world3d/Object3D.d.ts +118 -0
- package/dist/rendering/world3d/Object3D.js +315 -0
- package/dist/rendering/world3d/Particles3D.d.ts +90 -0
- package/dist/rendering/world3d/Particles3D.js +277 -0
- package/dist/rendering/world3d/Physics3D.d.ts +430 -0
- package/dist/rendering/world3d/Physics3D.js +2840 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +37 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +229 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +41 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +340 -0
- package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
- package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +179 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +536 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +74 -0
- package/dist/rendering/world3d/Ragdoll3D.js +202 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +40 -0
- package/dist/rendering/world3d/Raycast3D.js +247 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +91 -0
- package/dist/rendering/world3d/RenderList3D.js +502 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +21 -0
- package/dist/rendering/world3d/Retarget3D.js +185 -0
- package/dist/rendering/world3d/Rig3D.d.ts +57 -0
- package/dist/rendering/world3d/Rig3D.js +219 -0
- package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
- package/dist/rendering/world3d/Sdf3D.js +1136 -0
- package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
- package/dist/rendering/world3d/SdfLod3D.js +56 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +66 -0
- package/dist/rendering/world3d/Serialize3D.js +629 -0
- package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
- package/dist/rendering/world3d/Simplify3D.js +426 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +87 -0
- package/dist/rendering/world3d/StateMachine3D.js +280 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +248 -0
- package/dist/rendering/world3d/Terrain3D.js +827 -0
- package/dist/rendering/world3d/Text3D.d.ts +95 -0
- package/dist/rendering/world3d/Text3D.js +560 -0
- package/dist/rendering/world3d/Texture3D.d.ts +148 -0
- package/dist/rendering/world3d/Texture3D.js +270 -0
- package/dist/rendering/world3d/Trail3D.d.ts +62 -0
- package/dist/rendering/world3d/Trail3D.js +195 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +102 -0
- package/dist/rendering/world3d/Vehicle3D.js +228 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +57 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +230 -0
- package/dist/rendering/world3d/Water3D.d.ts +165 -0
- package/dist/rendering/world3d/Water3D.js +607 -0
- package/dist/rendering/world3d/core3D.d.ts +36 -0
- package/dist/rendering/world3d/core3D.js +99 -0
- package/dist/rendering/world3d/debug3D.d.ts +69 -0
- package/dist/rendering/world3d/debug3D.js +262 -0
- package/dist/rendering/world3d/decoders3D.d.ts +42 -0
- package/dist/rendering/world3d/decoders3D.js +133 -0
- package/dist/rendering/world3d/geometries3D.d.ts +111 -0
- package/dist/rendering/world3d/geometries3D.js +610 -0
- package/dist/rendering/world3d/helpers3D.d.ts +67 -0
- package/dist/rendering/world3d/helpers3D.js +178 -0
- package/dist/rendering/world3d/index.d.ts +103 -0
- package/dist/rendering/world3d/index.js +62 -0
- package/dist/rendering/world3d/math3D.d.ts +114 -0
- package/dist/rendering/world3d/math3D.js +675 -0
- package/dist/rendering/world3d/primitives3D.d.ts +67 -0
- package/dist/rendering/world3d/primitives3D.js +197 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +6 -0
- package/dist/saveStore.d.ts +71 -0
- package/dist/saveStore.js +182 -0
- package/dist/semanticList.d.ts +126 -0
- package/dist/semanticList.js +175 -0
- package/dist/semanticTree.d.ts +10 -0
- package/dist/semanticTree.js +539 -0
- package/dist/semanticTypes.d.ts +175 -0
- package/dist/semanticTypes.js +2 -0
- package/dist/semantics.d.ts +6 -0
- package/dist/semantics.js +5 -0
- package/dist/sequencePlayback.d.ts +19 -0
- package/dist/sequencePlayback.js +391 -0
- package/dist/sequencePlaybackTypes.d.ts +24 -0
- package/dist/sequencePlaybackTypes.js +2 -0
- package/dist/sequenceTargetClaims.d.ts +10 -0
- package/dist/sequenceTargetClaims.js +31 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/startEngine.d.ts +5 -0
- package/dist/startEngine.js +31 -0
- package/dist/surfaceOwnership.d.ts +3 -0
- package/dist/surfaceOwnership.js +15 -0
- package/dist/text.d.ts +24 -0
- package/dist/text.js +4 -0
- package/dist/textField.d.ts +6 -0
- package/dist/textField.js +6 -0
- package/dist/textTable.d.ts +41 -0
- package/dist/textTable.js +114 -0
- package/dist/tileMapDraw.d.ts +7 -0
- package/dist/tileMapDraw.js +310 -0
- package/dist/tiledImport.d.ts +9 -0
- package/dist/tiledImport.js +357 -0
- package/dist/tilemap.d.ts +5 -0
- package/dist/tilemap.js +5 -0
- package/dist/tilemapTypes.d.ts +182 -0
- package/dist/tilemapTypes.js +2 -0
- package/dist/timer.d.ts +34 -0
- package/dist/timer.js +119 -0
- package/dist/tween.d.ts +15 -0
- package/dist/tween.js +329 -0
- package/dist/tweenTypes.d.ts +31 -0
- package/dist/tweenTypes.js +2 -0
- package/dist/ui/controlKeys.d.ts +113 -0
- package/dist/ui/controlKeys.js +250 -0
- package/dist/ui/controls.d.ts +58 -0
- package/dist/ui/controls.js +290 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +11 -0
- package/dist/ui/keyboardFocus.d.ts +32 -0
- package/dist/ui/keyboardFocus.js +146 -0
- package/dist/ui/layerTypes.d.ts +98 -0
- package/dist/ui/layerTypes.js +2 -0
- package/dist/ui/layers.d.ts +4 -0
- package/dist/ui/layers.js +586 -0
- package/dist/ui/leafContent.d.ts +21 -0
- package/dist/ui/leafContent.js +136 -0
- package/dist/ui/rangeControl.d.ts +53 -0
- package/dist/ui/rangeControl.js +168 -0
- package/dist/ui/scrollControl.d.ts +84 -0
- package/dist/ui/scrollControl.js +222 -0
- package/dist/ui/stateControls.d.ts +90 -0
- package/dist/ui/stateControls.js +331 -0
- package/dist/ui/textEditor.d.ts +54 -0
- package/dist/ui/textEditor.js +371 -0
- package/dist/ui/textEditorTypes.d.ts +85 -0
- package/dist/ui/textEditorTypes.js +2 -0
- package/dist/ui/textFieldControl.d.ts +100 -0
- package/dist/ui/textFieldControl.js +260 -0
- package/dist/ui/theme.d.ts +64 -0
- package/dist/ui/theme.js +166 -0
- package/dist/ui/types.d.ts +285 -0
- package/dist/ui/types.js +2 -0
- package/dist/ui/uiRoot.d.ts +4 -0
- package/dist/ui/uiRoot.js +1526 -0
- package/dist/ui/uiRootDisplay.d.ts +46 -0
- package/dist/ui/uiRootDisplay.js +148 -0
- package/dist/ui/uiRootModel.d.ts +114 -0
- package/dist/ui/uiRootModel.js +66 -0
- package/dist/ui/virtualList.d.ts +20 -0
- package/dist/ui/virtualList.js +105 -0
- package/dist/video.d.ts +4 -0
- package/dist/video.js +4 -0
- package/dist/videoPlayer.d.ts +4 -0
- package/dist/videoPlayer.js +215 -0
- package/dist/videoTypes.d.ts +77 -0
- package/dist/videoTypes.js +2 -0
- package/dist/web/BrowserAssetBundle.d.ts +41 -0
- package/dist/web/BrowserAssetBundle.js +136 -0
- package/dist/web/BrowserAudio.d.ts +74 -0
- package/dist/web/BrowserAudio.js +503 -0
- package/dist/web/BrowserFrameLoop.d.ts +69 -0
- package/dist/web/BrowserFrameLoop.js +125 -0
- package/dist/web/BrowserGame.d.ts +174 -0
- package/dist/web/BrowserGame.js +473 -0
- package/dist/web/BrowserGamepadInput.d.ts +38 -0
- package/dist/web/BrowserGamepadInput.js +134 -0
- package/dist/web/BrowserHoverInput.d.ts +25 -0
- package/dist/web/BrowserHoverInput.js +266 -0
- package/dist/web/BrowserImageTextures.d.ts +72 -0
- package/dist/web/BrowserImageTextures.js +169 -0
- package/dist/web/BrowserInputActions.d.ts +63 -0
- package/dist/web/BrowserInputActions.js +345 -0
- package/dist/web/BrowserKeyboardInput.d.ts +4 -0
- package/dist/web/BrowserKeyboardInput.js +223 -0
- package/dist/web/BrowserPlay.d.ts +417 -0
- package/dist/web/BrowserPlay.js +1648 -0
- package/dist/web/BrowserPointerInput.d.ts +4 -0
- package/dist/web/BrowserPointerInput.js +511 -0
- package/dist/web/BrowserPreferences.d.ts +10 -0
- package/dist/web/BrowserPreferences.js +39 -0
- package/dist/web/BrowserSemantics.d.ts +36 -0
- package/dist/web/BrowserSemantics.js +418 -0
- package/dist/web/BrowserStatsPanel.d.ts +56 -0
- package/dist/web/BrowserStatsPanel.js +143 -0
- package/dist/web/BrowserStorage.d.ts +35 -0
- package/dist/web/BrowserStorage.js +132 -0
- package/dist/web/BrowserTextEditor.d.ts +52 -0
- package/dist/web/BrowserTextEditor.js +839 -0
- package/dist/web/BrowserTextInput.d.ts +89 -0
- package/dist/web/BrowserTextInput.js +524 -0
- package/dist/web/BrowserTextureProvider.d.ts +58 -0
- package/dist/web/BrowserTextureProvider.js +935 -0
- package/dist/web/BrowserVideo.d.ts +40 -0
- package/dist/web/BrowserVideo.js +237 -0
- package/dist/web/CanvasKitFontSetProvider.d.ts +32 -0
- package/dist/web/CanvasKitFontSetProvider.js +215 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +173 -0
- package/dist/web/CanvasKitParagraphProvider.js +692 -0
- package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
- package/dist/web/CanvasTextRasterProvider.js +312 -0
- package/dist/web/ManifestByteSource.d.ts +151 -0
- package/dist/web/ManifestByteSource.js +975 -0
- package/dist/web/ManifestFontContentLoader.d.ts +13 -0
- package/dist/web/ManifestFontContentLoader.js +30 -0
- package/dist/web/MouseInput.d.ts +4 -0
- package/dist/web/MouseInput.js +218 -0
- package/dist/web/WebGL2Host.d.ts +5 -0
- package/dist/web/WebGL2Host.js +2711 -0
- package/dist/web/WebGPUHost.d.ts +100 -0
- package/dist/web/WebGPUHost.js +3430 -0
- package/dist/web/audio.d.ts +3 -0
- package/dist/web/audio.js +4 -0
- package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
- package/dist/web/canvasKitParagraphGeometry.js +83 -0
- package/dist/web/editing.d.ts +5 -0
- package/dist/web/editing.js +4 -0
- package/dist/web/editorFonts.d.ts +54 -0
- package/dist/web/editorFonts.js +297 -0
- package/dist/web/game.d.ts +5 -0
- package/dist/web/game.js +6 -0
- package/dist/web/gamepad.d.ts +3 -0
- package/dist/web/gamepad.js +4 -0
- package/dist/web/hover.d.ts +3 -0
- package/dist/web/hover.js +4 -0
- package/dist/web/image.d.ts +4 -0
- package/dist/web/image.js +4 -0
- package/dist/web/imageProjections2D.d.ts +16 -0
- package/dist/web/imageProjections2D.js +2 -0
- package/dist/web/input.d.ts +6 -0
- package/dist/web/input.js +4 -0
- package/dist/web/keyboard.d.ts +3 -0
- package/dist/web/keyboard.js +3 -0
- package/dist/web/kit.d.ts +11 -0
- package/dist/web/kit.js +8 -0
- package/dist/web/loop.d.ts +3 -0
- package/dist/web/loop.js +4 -0
- package/dist/web/paragraph.d.ts +6 -0
- package/dist/web/paragraph.js +4 -0
- package/dist/web/play.d.ts +10 -0
- package/dist/web/play.js +9 -0
- package/dist/web/playMusic.d.ts +33 -0
- package/dist/web/playMusic.js +194 -0
- package/dist/web/playSfx.d.ts +36 -0
- package/dist/web/playSfx.js +112 -0
- package/dist/web/playTouch.d.ts +45 -0
- package/dist/web/playTouch.js +141 -0
- package/dist/web/playWidgets.d.ts +71 -0
- package/dist/web/playWidgets.js +431 -0
- package/dist/web/pointer.d.ts +3 -0
- package/dist/web/pointer.js +3 -0
- package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
- package/dist/web/prepareSharedSubmission2D.js +63 -0
- package/dist/web/resources.d.ts +29 -0
- package/dist/web/resources.js +96 -0
- package/dist/web/semantics.d.ts +3 -0
- package/dist/web/semantics.js +4 -0
- package/dist/web/sharedDeviceSession.d.ts +64 -0
- package/dist/web/sharedDeviceSession.js +2 -0
- package/dist/web/sharedEffectShaders.d.ts +13 -0
- package/dist/web/sharedEffectShaders.js +181 -0
- package/dist/web/sharedFrameUpload.d.ts +25 -0
- package/dist/web/sharedFrameUpload.js +2 -0
- package/dist/web/sharedHostDeferred.d.ts +7 -0
- package/dist/web/sharedHostDeferred.js +12 -0
- package/dist/web/sharedRetentionLedger.d.ts +85 -0
- package/dist/web/sharedRetentionLedger.js +391 -0
- package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
- package/dist/web/sharedSubmissionStorage2D.js +73 -0
- package/dist/web/sharedWebGL2Arena.d.ts +40 -0
- package/dist/web/sharedWebGL2Arena.js +77 -0
- package/dist/web/sharedWebGL2Options.d.ts +33 -0
- package/dist/web/sharedWebGL2Options.js +102 -0
- package/dist/web/sharedWebGL2Shaders.d.ts +33 -0
- package/dist/web/sharedWebGL2Shaders.js +408 -0
- package/dist/web/sharedWebGPUOptions.d.ts +41 -0
- package/dist/web/sharedWebGPUOptions.js +130 -0
- package/dist/web/text.d.ts +3 -0
- package/dist/web/text.js +3 -0
- package/dist/web/textInput.d.ts +3 -0
- package/dist/web/textInput.js +3 -0
- package/dist/web/video.d.ts +3 -0
- package/dist/web/video.js +4 -0
- package/dist/web/webgl2.d.ts +7 -0
- package/dist/web/webgl2.js +4 -0
- package/dist/web/webgl2LayerState.d.ts +50 -0
- package/dist/web/webgl2LayerState.js +102 -0
- package/dist/web/webgl2Native.d.ts +72 -0
- package/dist/web/webgl2Native.js +572 -0
- package/dist/web/webgl2Types.d.ts +150 -0
- package/dist/web/webgl2Types.js +2 -0
- package/dist/web/webgpu.d.ts +6 -0
- package/dist/web/webgpu.js +2 -0
- package/dist/web/webgpuBindingCache.d.ts +26 -0
- package/dist/web/webgpuBindingCache.js +223 -0
- package/dist/web/webgpuBufferPool.d.ts +51 -0
- package/dist/web/webgpuBufferPool.js +58 -0
- package/dist/web/webgpuImageResidency.d.ts +56 -0
- package/dist/web/webgpuImageResidency.js +65 -0
- package/dist/web/webgpuLifetime.d.ts +45 -0
- package/dist/web/webgpuLifetime.js +64 -0
- package/dist/web/webgpuRetentionPool.d.ts +66 -0
- package/dist/web/webgpuRetentionPool.js +85 -0
- package/dist/web/webgpuSharedPass.d.ts +7 -0
- package/dist/web/webgpuSharedPass.js +293 -0
- package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
- package/dist/web/webgpuSharedResolvePass.js +34 -0
- package/dist/web/world3d/Audio3D.d.ts +85 -0
- package/dist/web/world3d/Audio3D.js +271 -0
- package/dist/web/world3d/BrowserPlay3D.d.ts +295 -0
- package/dist/web/world3d/BrowserPlay3D.js +1256 -0
- package/dist/web/world3d/FlyControls3D.d.ts +59 -0
- package/dist/web/world3d/FlyControls3D.js +162 -0
- package/dist/web/world3d/FollowControls3D.d.ts +31 -0
- package/dist/web/world3d/FollowControls3D.js +119 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +58 -0
- package/dist/web/world3d/OrbitControls3D.js +189 -0
- package/dist/web/world3d/TransformControls3D.d.ts +37 -0
- package/dist/web/world3d/TransformControls3D.js +128 -0
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +136 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +1175 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +112 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1916 -0
- package/dist/web/world3d/World3DView.d.ts +54 -0
- package/dist/web/world3d/World3DView.js +79 -0
- package/dist/web/world3d/app3D.d.ts +143 -0
- package/dist/web/world3d/app3D.js +305 -0
- package/dist/web/world3d/assets3D.d.ts +39 -0
- package/dist/web/world3d/assets3D.js +112 -0
- package/dist/web/world3d/atmosphere3D.d.ts +56 -0
- package/dist/web/world3d/atmosphere3D.js +193 -0
- package/dist/web/world3d/canvasFont3D.d.ts +21 -0
- package/dist/web/world3d/canvasFont3D.js +165 -0
- package/dist/web/world3d/frame3D.d.ts +144 -0
- package/dist/web/world3d/frame3D.js +388 -0
- package/dist/web/world3d/gpuResources3D.d.ts +98 -0
- package/dist/web/world3d/gpuResources3D.js +901 -0
- package/dist/web/world3d/host3D.d.ts +24 -0
- package/dist/web/world3d/host3D.js +61 -0
- package/dist/web/world3d/index.d.ts +40 -0
- package/dist/web/world3d/index.js +24 -0
- package/dist/web/world3d/loaders3D.d.ts +27 -0
- package/dist/web/world3d/loaders3D.js +138 -0
- package/dist/web/world3d/markers3D.d.ts +53 -0
- package/dist/web/world3d/markers3D.js +130 -0
- package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
- package/dist/web/world3d/materialWebGL23D.js +218 -0
- package/dist/web/world3d/overlay3D.d.ts +47 -0
- package/dist/web/world3d/overlay3D.js +187 -0
- package/dist/web/world3d/post3D.d.ts +116 -0
- package/dist/web/world3d/post3D.js +462 -0
- package/dist/web/world3d/postWebGL23D.d.ts +24 -0
- package/dist/web/world3d/postWebGL23D.js +237 -0
- package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
- package/dist/web/world3d/postWebGPU3D.js +255 -0
- package/dist/web/world3d/probe3D.d.ts +15 -0
- package/dist/web/world3d/probe3D.js +66 -0
- package/dist/web/world3d/shaders3D.d.ts +43 -0
- package/dist/web/world3d/shaders3D.js +851 -0
- package/dist/web/world3d/stats3D.d.ts +34 -0
- package/dist/web/world3d/stats3D.js +81 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +71 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
- package/dist/web/world3d/webgpu.d.ts +37 -0
- package/dist/web/world3d/webgpu.js +23 -0
- package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
- package/dist/web/world3d/webgpuPacking3D.js +85 -0
- package/dist/web/world3d/wgsl3D.d.ts +68 -0
- package/dist/web/world3d/wgsl3D.js +781 -0
- package/package.json +220 -4
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Water: a wavy, refracting, reflecting surface, and the mirror camera that
|
|
3
|
+
// gives any flat surface a true reflection of the scene. DOM-free; the same
|
|
4
|
+
// wave formula runs in both shading languages and on the CPU, so objects can
|
|
5
|
+
// float on what the player sees.
|
|
6
|
+
import { World3DError, requireCount3D, requireFinite3D, requirePositive3D } from './core3D.js';
|
|
7
|
+
import { Camera3D } from './Camera3D.js';
|
|
8
|
+
import { Attribute3D, Geometry3D } from './Geometry3D.js';
|
|
9
|
+
import { Material3D, createCustomShader3D, createStandardMaterial3D } from './Material3D.js';
|
|
10
|
+
import { Mesh3D } from './Mesh3D.js';
|
|
11
|
+
import { RenderTarget3D, TEXTURE3D_LIMITS } from './Texture3D.js';
|
|
12
|
+
import { colorFromHex, mat4Invert, quatFromRotationMatrix } from './math3D.js';
|
|
13
|
+
/**
|
|
14
|
+
* A mirror camera and the target it draws into. Each frame, before the main
|
|
15
|
+
* view, call `render` with the plane of the mirror; assign `texture` to a
|
|
16
|
+
* standard material's `reflectionMap`. Whatever lies behind the plane is cut
|
|
17
|
+
* away, so the ground under a lake does not show up in its reflection.
|
|
18
|
+
*/
|
|
19
|
+
export class PlanarReflection3D {
|
|
20
|
+
target;
|
|
21
|
+
#perspectiveCamera = new Camera3D();
|
|
22
|
+
#orthographicCamera = new Camera3D('orthographic');
|
|
23
|
+
#camera = this.#perspectiveCamera;
|
|
24
|
+
get camera() {
|
|
25
|
+
return this.#camera;
|
|
26
|
+
}
|
|
27
|
+
/** Moves the cutting plane back by this distance so geometry touching the mirror leaves no gap. */
|
|
28
|
+
clipBias = 0.05;
|
|
29
|
+
/** Draw the mirror image on every Nth call only; in between, the last image is kept. 1 draws every time. */
|
|
30
|
+
interval = 1;
|
|
31
|
+
/** Only objects on these layers appear in the mirror image: leave small or distant things out to save time. */
|
|
32
|
+
layerMask = 0xffffffff;
|
|
33
|
+
/** false leaves shadows out of the mirror image, which saves the shadow passes for it. */
|
|
34
|
+
shadows = true;
|
|
35
|
+
/** Override tone mapping in the mirror only. Undefined inherits the renderer's setting. */
|
|
36
|
+
toneMapping = undefined;
|
|
37
|
+
#calls = 0;
|
|
38
|
+
#drawn;
|
|
39
|
+
#projection = new Float32Array(16);
|
|
40
|
+
#perspectiveProjection = new Float32Array(16);
|
|
41
|
+
#orthographicProjection = new Float32Array(16);
|
|
42
|
+
#inverseProjection = new Float64Array(16);
|
|
43
|
+
#basis = new Float32Array(16);
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
const width = requireCount3D(options.width ?? 512, 'reflection width', TEXTURE3D_LIMITS.maxEdge), height = requireCount3D(options.height ?? 512, 'reflection height', TEXTURE3D_LIMITS.maxEdge);
|
|
46
|
+
this.target = new RenderTarget3D(width, height, { name: 'planar-reflection' });
|
|
47
|
+
this.#perspectiveCamera.name = this.#orthographicCamera.name = 'reflection-camera';
|
|
48
|
+
}
|
|
49
|
+
get texture() {
|
|
50
|
+
return this.target.texture;
|
|
51
|
+
}
|
|
52
|
+
/** Capture the reflection settings for this viewing camera and the excluded subtrees. */
|
|
53
|
+
createPass(camera, hidden = []) {
|
|
54
|
+
return {
|
|
55
|
+
target: this.target,
|
|
56
|
+
toneMapping: this.toneMapping,
|
|
57
|
+
shadows: this.shadows,
|
|
58
|
+
layerMask: camera.layerMask & this.layerMask,
|
|
59
|
+
hidden: [...hidden]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Refresh on the next call, for example after a camera cut or a skipped region. */
|
|
63
|
+
invalidate() {
|
|
64
|
+
this.#calls = 0;
|
|
65
|
+
this.#drawn = undefined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Place the mirror camera for a viewing camera and a world plane given as
|
|
69
|
+
* [nx, ny, nz, d] with unit normal, where n . p + d = 0 and the normal
|
|
70
|
+
* points to the side the viewer is on. Returns false when the viewer is
|
|
71
|
+
* behind the plane or the projection cannot represent a forward clip.
|
|
72
|
+
*/
|
|
73
|
+
update(camera, plane) {
|
|
74
|
+
const nx = requireFinite3D(plane[0], 'plane'), ny = requireFinite3D(plane[1], 'plane'), nz = requireFinite3D(plane[2], 'plane'), d = requireFinite3D(plane[3], 'plane');
|
|
75
|
+
if (Math.abs(Math.hypot(nx, ny, nz) - 1) > 1e-3)
|
|
76
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'plane normal must have unit length');
|
|
77
|
+
camera.updateViewMatrices();
|
|
78
|
+
const from = camera.matrixWorld, basis = this.#basis;
|
|
79
|
+
const orthographic = camera.projectionKind === 'orthographic';
|
|
80
|
+
const mirror = orthographic ? this.#orthographicCamera : this.#perspectiveCamera;
|
|
81
|
+
const height = from[12] * nx + from[13] * ny + from[14] * nz + d;
|
|
82
|
+
if (height <= 0)
|
|
83
|
+
return false;
|
|
84
|
+
// Reflect the camera's axes and position; flipping its X axis as well keeps it a proper rotation.
|
|
85
|
+
for (let column = 0; column < 3; column++) {
|
|
86
|
+
const x = from[column * 4], y = from[column * 4 + 1], z = from[column * 4 + 2], length = Math.hypot(x, y, z) || 1, along = 2 * (x * nx + y * ny + z * nz), sign = (column === 0 ? -1 : 1) / length;
|
|
87
|
+
basis[column * 4] = (x - along * nx) * sign;
|
|
88
|
+
basis[column * 4 + 1] = (y - along * ny) * sign;
|
|
89
|
+
basis[column * 4 + 2] = (z - along * nz) * sign;
|
|
90
|
+
}
|
|
91
|
+
quatFromRotationMatrix(mirror.quaternion, basis);
|
|
92
|
+
mirror.setQuaternion(mirror.quaternion[0], mirror.quaternion[1], mirror.quaternion[2], mirror.quaternion[3]);
|
|
93
|
+
mirror.setPosition(from[12] - 2 * height * nx, from[13] - 2 * height * ny, from[14] - 2 * height * nz);
|
|
94
|
+
mirror.fov = camera.fov;
|
|
95
|
+
mirror.aspect = camera.aspect;
|
|
96
|
+
mirror.near = camera.near;
|
|
97
|
+
mirror.far = camera.far;
|
|
98
|
+
mirror.zoom = camera.zoom;
|
|
99
|
+
mirror.orthographicHeight = camera.orthographicHeight;
|
|
100
|
+
mirror.layerMask = camera.layerMask;
|
|
101
|
+
const p = this.#projection, inverse = this.#inverseProjection;
|
|
102
|
+
p.set(camera.projectionMatrix);
|
|
103
|
+
if (!mat4Invert(inverse, p))
|
|
104
|
+
return false;
|
|
105
|
+
mirror.updateWorldMatrix();
|
|
106
|
+
const world = mirror.matrixWorld;
|
|
107
|
+
const cx = world[0] * nx + world[1] * ny + world[2] * nz, cy = world[4] * nx + world[5] * ny + world[6] * nz, cz = world[8] * nx + world[9] * ny + world[10] * nz;
|
|
108
|
+
const cw = world[12] * nx + world[13] * ny + world[14] * nz + d + requireFinite3D(this.clipBias, 'clipBias');
|
|
109
|
+
if (cw < 0 || orthographic) {
|
|
110
|
+
// Transform the plane to clip space. Its furthest kept corner sets the scale;
|
|
111
|
+
// replacing z + w clips against the plane while preserving the projected x and y.
|
|
112
|
+
const clip = (column) => cx * inverse[column] + cy * inverse[column + 1] + cz * inverse[column + 2] + cw * inverse[column + 3];
|
|
113
|
+
const depth = clip(8), farSide = Math.abs(clip(0)) + Math.abs(clip(4)) + Math.abs(depth) + clip(12);
|
|
114
|
+
if (depth === 0 || !Number.isFinite(farSide) || farSide <= 0)
|
|
115
|
+
return false;
|
|
116
|
+
// Orthographic rays share a direction. A tangent or backward plane
|
|
117
|
+
// would make the replacement depth singular or reverse depth order.
|
|
118
|
+
if (orthographic && depth / farSide <= 1e-7)
|
|
119
|
+
return false;
|
|
120
|
+
const scale = 2 / farSide;
|
|
121
|
+
p[2] = cx * scale - p[3];
|
|
122
|
+
p[6] = cy * scale - p[7];
|
|
123
|
+
p[10] = cz * scale - p[11];
|
|
124
|
+
p[14] = cw * scale - p[15];
|
|
125
|
+
}
|
|
126
|
+
const projection = orthographic ? this.#orthographicProjection : this.#perspectiveProjection;
|
|
127
|
+
projection.set(p);
|
|
128
|
+
mirror.customProjection = projection;
|
|
129
|
+
mirror.updateViewMatrices();
|
|
130
|
+
this.#camera = mirror;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Update the mirror camera and draw the scene into the target. Objects in
|
|
135
|
+
* `hidden`, normally the mirror itself, are left out of the image.
|
|
136
|
+
*/
|
|
137
|
+
render(renderer, scene, camera, plane, hidden = []) {
|
|
138
|
+
const interval = requireCount3D(this.interval, 'reflection interval', Number.MAX_SAFE_INTEGER);
|
|
139
|
+
if (interval === 0)
|
|
140
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'reflection interval');
|
|
141
|
+
if (this.target.isDisposed || !this.update(camera, plane)) {
|
|
142
|
+
this.#drawn = undefined;
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
const pass = this.createPass(camera, hidden);
|
|
146
|
+
this.camera.layerMask = pass.layerMask;
|
|
147
|
+
if (pass.toneMapping !== undefined && !renderer.renderReflectionPass)
|
|
148
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'reflection tone mapping requires a pass-aware renderer');
|
|
149
|
+
const inheritedTone = 'toneMapping' in renderer ? renderer.toneMapping : undefined;
|
|
150
|
+
const toneMapping = pass.toneMapping ?? (typeof inheritedTone === 'string' ? inheritedTone : undefined);
|
|
151
|
+
const shadows = pass.shadows && renderer.shadowsEnabled !== false;
|
|
152
|
+
const scheduled = this.#calls === 0;
|
|
153
|
+
this.#calls = (this.#calls + 1) % interval;
|
|
154
|
+
const drawn = this.#drawn;
|
|
155
|
+
if (!scheduled &&
|
|
156
|
+
drawn?.renderer === renderer &&
|
|
157
|
+
drawn.scene === scene &&
|
|
158
|
+
drawn.version === this.target.version &&
|
|
159
|
+
drawn.toneMapping === toneMapping &&
|
|
160
|
+
drawn.shadows === shadows &&
|
|
161
|
+
drawn.layerMask === pass.layerMask &&
|
|
162
|
+
drawn.clipBias === this.clipBias &&
|
|
163
|
+
drawn.plane.every((value, index) => value === plane[index]) &&
|
|
164
|
+
drawn.hidden.length === pass.hidden.length &&
|
|
165
|
+
drawn.hidden.every((object, index) => object === pass.hidden[index]) &&
|
|
166
|
+
(renderer.reuseReflection?.(this.target) ?? true))
|
|
167
|
+
return true;
|
|
168
|
+
this.#drawn = undefined;
|
|
169
|
+
const result = renderer.renderReflectionPass
|
|
170
|
+
? renderer.renderReflectionPass(scene, this.camera, pass)
|
|
171
|
+
: this.renderLegacy(renderer, scene, hidden);
|
|
172
|
+
if (result)
|
|
173
|
+
this.#drawn = {
|
|
174
|
+
renderer,
|
|
175
|
+
scene,
|
|
176
|
+
version: this.target.version,
|
|
177
|
+
toneMapping,
|
|
178
|
+
shadows,
|
|
179
|
+
layerMask: pass.layerMask,
|
|
180
|
+
hidden: pass.hidden,
|
|
181
|
+
plane: [plane[0], plane[1], plane[2], plane[3]],
|
|
182
|
+
clipBias: this.clipBias
|
|
183
|
+
};
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
renderLegacy(renderer, scene, hidden) {
|
|
187
|
+
const shadowsEnabled = renderer.shadowsEnabled, post = renderer.postProcess, postEnabled = post?.enabled;
|
|
188
|
+
const disableShadows = !this.shadows && shadowsEnabled !== undefined;
|
|
189
|
+
const shown = hidden.map(object => object.visible);
|
|
190
|
+
let touchedShadows = false, touchedPost = false, touchedHidden = 0;
|
|
191
|
+
let result = false, primary, cleanupErrors;
|
|
192
|
+
try {
|
|
193
|
+
if (disableShadows) {
|
|
194
|
+
touchedShadows = true;
|
|
195
|
+
renderer.shadowsEnabled = false;
|
|
196
|
+
}
|
|
197
|
+
for (const object of hidden) {
|
|
198
|
+
touchedHidden++;
|
|
199
|
+
object.visible = false;
|
|
200
|
+
}
|
|
201
|
+
if (post) {
|
|
202
|
+
touchedPost = true;
|
|
203
|
+
post.enabled = false;
|
|
204
|
+
}
|
|
205
|
+
result = renderer.renderReflection
|
|
206
|
+
? renderer.renderReflection(scene, this.camera, this.target)
|
|
207
|
+
: renderer.render(scene, this.camera, this.target);
|
|
208
|
+
}
|
|
209
|
+
catch (cause) {
|
|
210
|
+
primary = { cause };
|
|
211
|
+
}
|
|
212
|
+
// Restore every owned setting, even when setup, rendering or another restoration fails.
|
|
213
|
+
const restore = (action) => {
|
|
214
|
+
try {
|
|
215
|
+
action();
|
|
216
|
+
}
|
|
217
|
+
catch (cause) {
|
|
218
|
+
(cleanupErrors ??= []).push(cause);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
if (post && touchedPost)
|
|
222
|
+
restore(() => {
|
|
223
|
+
post.enabled = postEnabled;
|
|
224
|
+
});
|
|
225
|
+
for (let i = touchedHidden - 1; i >= 0; i--)
|
|
226
|
+
restore(() => {
|
|
227
|
+
hidden[i].visible = shown[i];
|
|
228
|
+
});
|
|
229
|
+
if (touchedShadows)
|
|
230
|
+
restore(() => {
|
|
231
|
+
renderer.shadowsEnabled = shadowsEnabled;
|
|
232
|
+
});
|
|
233
|
+
if (cleanupErrors) {
|
|
234
|
+
const causes = primary ? [primary.cause, ...cleanupErrors] : cleanupErrors;
|
|
235
|
+
if (causes.length === 1)
|
|
236
|
+
throw causes[0];
|
|
237
|
+
throw new AggregateError(causes, 'WORLD3D_REFLECTION_FAILED');
|
|
238
|
+
}
|
|
239
|
+
if (primary)
|
|
240
|
+
throw primary.cause;
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
dispose() {
|
|
244
|
+
this.#drawn = undefined;
|
|
245
|
+
this.target.dispose();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Four waves share one formula: each is turned from the main direction,
|
|
249
|
+
// shorter and lower than the one before. Deep-water waves travel at
|
|
250
|
+
// sqrt(g * wavelength / 2 pi), so the short ones run slower.
|
|
251
|
+
const WAVE_TURN = [0, 0.63, -0.94, 1.71], WAVE_LENGTH = [1, 0.62, 0.37, 0.23], WAVE_HEIGHT = [1, 0.55, 0.3, 0.16];
|
|
252
|
+
const GLSL_WAVES = /* glsl */ `
|
|
253
|
+
const float WATER_TURN[4] = float[4](0.0, 0.63, -0.94, 1.71);
|
|
254
|
+
const float WATER_LENGTH[4] = float[4](1.0, 0.62, 0.37, 0.23);
|
|
255
|
+
const float WATER_HEIGHT[4] = float[4](1.0, 0.55, 0.3, 0.16);
|
|
256
|
+
// Returns the sideways pull in xz and the height in y; writes the surface slope.
|
|
257
|
+
vec3 waterWaves(vec2 p, out vec2 slope) {
|
|
258
|
+
vec4 a = uCustom[0], b = uCustom[1];
|
|
259
|
+
vec3 moved = vec3(0.0);
|
|
260
|
+
slope = vec2(0.0);
|
|
261
|
+
float heading = atan(b.y, b.x);
|
|
262
|
+
for (int i = 0; i < 4; i++) {
|
|
263
|
+
float angle = heading + WATER_TURN[i], wavelength = a.z * WATER_LENGTH[i], k = 6.2831853 / wavelength, height = a.y * WATER_HEIGHT[i];
|
|
264
|
+
vec2 d = vec2(cos(angle), sin(angle));
|
|
265
|
+
float phase = k * dot(d, p) - sqrt(9.81 * k) * a.w * a.x;
|
|
266
|
+
moved.y += height * sin(phase);
|
|
267
|
+
moved.xz -= d * (b.z * height * cos(phase));
|
|
268
|
+
slope += d * (height * k * cos(phase));
|
|
269
|
+
}
|
|
270
|
+
return moved;
|
|
271
|
+
}
|
|
272
|
+
`;
|
|
273
|
+
const GLSL_VERTEX = GLSL_WAVES +
|
|
274
|
+
/* glsl */ `
|
|
275
|
+
vec3 customVertex(vec3 worldPosition, vec3 localPosition, vec3 normal, vec2 uv, vec4 color) {
|
|
276
|
+
vec2 slope;
|
|
277
|
+
vec3 moved = waterWaves(worldPosition.xz, slope);
|
|
278
|
+
return worldPosition + vec3(moved.x, moved.y, moved.z);
|
|
279
|
+
}
|
|
280
|
+
`;
|
|
281
|
+
const GLSL_NORMAL = GLSL_WAVES +
|
|
282
|
+
/* glsl */ `
|
|
283
|
+
vec3 customNormal(vec3 normal, vec3 worldPosition, vec2 uv) {
|
|
284
|
+
vec2 slope;
|
|
285
|
+
waterWaves(worldPosition.xz, slope);
|
|
286
|
+
// Fine ripples: short waves that fade with distance so they do not shimmer far away.
|
|
287
|
+
vec4 a = uCustom[0], b = uCustom[1], c = uCustom[2];
|
|
288
|
+
float fade = b.w / (1.0 + distance(uCameraPosition.xyz, worldPosition) * c.y);
|
|
289
|
+
for (int i = 0; i < 5; i++) {
|
|
290
|
+
float angle = 1.3 + float(i) * 2.399963, k = 6.2831853 / (c.x * (1.0 + float(i) * 0.37));
|
|
291
|
+
vec2 d = vec2(cos(angle), sin(angle));
|
|
292
|
+
slope += d * (fade * cos(k * dot(d, worldPosition.xz) - sqrt(9.81 * k) * a.w * a.x + float(i) * 1.7));
|
|
293
|
+
}
|
|
294
|
+
return vec3(-slope.x, 1.0, -slope.y);
|
|
295
|
+
}
|
|
296
|
+
`;
|
|
297
|
+
const WGSL_VERTEX = /* wgsl */ `
|
|
298
|
+
struct WaterWaves { moved: vec3f, slope: vec2f }
|
|
299
|
+
fn waterWaves(p: vec2f) -> WaterWaves {
|
|
300
|
+
var turn = array<f32, 4>(0.0, 0.63, -0.94, 1.71);
|
|
301
|
+
var lengths = array<f32, 4>(1.0, 0.62, 0.37, 0.23);
|
|
302
|
+
var heights = array<f32, 4>(1.0, 0.55, 0.3, 0.16);
|
|
303
|
+
let a = material.custom[0];
|
|
304
|
+
let b = material.custom[1];
|
|
305
|
+
var out: WaterWaves;
|
|
306
|
+
out.moved = vec3f(0.0);
|
|
307
|
+
out.slope = vec2f(0.0);
|
|
308
|
+
let heading = atan2(b.y, b.x);
|
|
309
|
+
for (var i = 0; i < 4; i++) {
|
|
310
|
+
let angle = heading + turn[i];
|
|
311
|
+
let k = 6.2831853 / (a.z * lengths[i]);
|
|
312
|
+
let height = a.y * heights[i];
|
|
313
|
+
let d = vec2f(cos(angle), sin(angle));
|
|
314
|
+
let phase = k * dot(d, p) - sqrt(9.81 * k) * a.w * a.x;
|
|
315
|
+
out.moved.y += height * sin(phase);
|
|
316
|
+
let pull = d * (b.z * height * cos(phase));
|
|
317
|
+
out.moved.x -= pull.x;
|
|
318
|
+
out.moved.z -= pull.y;
|
|
319
|
+
out.slope += d * (height * k * cos(phase));
|
|
320
|
+
}
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
323
|
+
fn customVertex(worldPosition: vec3f, localPosition: vec3f, normal: vec3f, uv: vec2f, color: vec4f) -> vec3f {
|
|
324
|
+
return worldPosition + waterWaves(worldPosition.xz).moved;
|
|
325
|
+
}
|
|
326
|
+
`;
|
|
327
|
+
const WGSL_NORMAL = /* wgsl */ `
|
|
328
|
+
fn customNormal(normal: vec3f, worldPosition: vec3f, uv: vec2f) -> vec3f {
|
|
329
|
+
var slope = waterWaves(worldPosition.xz).slope;
|
|
330
|
+
let a = material.custom[0];
|
|
331
|
+
let b = material.custom[1];
|
|
332
|
+
let c = material.custom[2];
|
|
333
|
+
let fade = b.w / (1.0 + distance(frame.cameraPosition.xyz, worldPosition) * c.y);
|
|
334
|
+
for (var i = 0; i < 5; i++) {
|
|
335
|
+
let angle = 1.3 + f32(i) * 2.399963;
|
|
336
|
+
let k = 6.2831853 / (c.x * (1.0 + f32(i) * 0.37));
|
|
337
|
+
let d = vec2f(cos(angle), sin(angle));
|
|
338
|
+
slope += d * (fade * cos(k * dot(d, worldPosition.xz) - sqrt(9.81 * k) * a.w * a.x + f32(i) * 1.7));
|
|
339
|
+
}
|
|
340
|
+
return vec3f(-slope.x, 1.0, -slope.y);
|
|
341
|
+
}
|
|
342
|
+
`;
|
|
343
|
+
const GLSL_FRAGMENT = /* glsl */ `
|
|
344
|
+
vec4 customFragment(vec4 color, vec3 worldPosition, vec3 normal, vec2 uv) {
|
|
345
|
+
vec4 a = uCustom[0], look = uCustom[3];
|
|
346
|
+
float gap = sceneDistance - surfaceDistance;
|
|
347
|
+
// Without a depth image there is no telling how deep the water is here.
|
|
348
|
+
if (gap > 1.0e8 || gap < 0.0) return vec4(color.rgb, 1.0);
|
|
349
|
+
float clock = a.x * a.w;
|
|
350
|
+
// Foam: a band along the shore, broken up by two crossing ripples that drift.
|
|
351
|
+
float edge = 1.0 - smoothstep(0.0, max(look.x, 0.0001), gap);
|
|
352
|
+
float broken = 0.5 + 0.5 * sin(dot(worldPosition.xz, vec2(1.7, 2.3)) * 2.0 + clock * 1.5) * sin(dot(worldPosition.xz, vec2(-2.1, 1.3)) * 1.6 - clock);
|
|
353
|
+
float foam = smoothstep(0.35, 0.8, edge * (0.6 + 0.8 * broken)) * look.y;
|
|
354
|
+
// Caustics: light gathered by the waves, drawn on the bottom where it is seen through shallow water.
|
|
355
|
+
vec3 ray = normalize(worldPosition - uCameraPosition.xyz);
|
|
356
|
+
float facing = max(dot(ray, -vec3(uView[0].z, uView[1].z, uView[2].z)), 0.05);
|
|
357
|
+
vec3 bottom = worldPosition + ray * (gap / facing);
|
|
358
|
+
float web = sin(bottom.x * 2.1 + sin(bottom.z * 1.7 + clock)) + sin(bottom.z * 2.3 + sin(bottom.x * 1.9 - clock * 1.3));
|
|
359
|
+
float light = pow(1.0 - abs(web) * 0.5, 6.0) * look.z * exp(-gap / max(look.w, 0.0001));
|
|
360
|
+
vec3 lit = color.rgb + vec3(0.85, 1.0, 0.9) * light;
|
|
361
|
+
return vec4(mix(lit, vec3(0.92), foam), 1.0 - foam);
|
|
362
|
+
}
|
|
363
|
+
`;
|
|
364
|
+
const WGSL_FRAGMENT = /* wgsl */ `
|
|
365
|
+
fn customFragment(color: vec4f, worldPosition: vec3f, normal: vec3f, uv: vec2f) -> vec4f {
|
|
366
|
+
let a = material.custom[0];
|
|
367
|
+
let look = material.custom[3];
|
|
368
|
+
let gap = sceneDistance - surfaceDistance;
|
|
369
|
+
// Without a depth image there is no telling how deep the water is here.
|
|
370
|
+
if (gap > 1.0e8 || gap < 0.0) { return vec4f(color.rgb, 1.0); }
|
|
371
|
+
let clock = a.x * a.w;
|
|
372
|
+
// Foam: a band along the shore, broken up by two crossing ripples that drift.
|
|
373
|
+
let edge = 1.0 - smoothstep(0.0, max(look.x, 0.0001), gap);
|
|
374
|
+
let broken = 0.5 + 0.5 * sin(dot(worldPosition.xz, vec2f(1.7, 2.3)) * 2.0 + clock * 1.5) * sin(dot(worldPosition.xz, vec2f(-2.1, 1.3)) * 1.6 - clock);
|
|
375
|
+
let foam = smoothstep(0.35, 0.8, edge * (0.6 + 0.8 * broken)) * look.y;
|
|
376
|
+
// Caustics: light gathered by the waves, drawn on the bottom where it is seen through shallow water.
|
|
377
|
+
let ray = normalize(worldPosition - frame.cameraPosition.xyz);
|
|
378
|
+
let facing = max(dot(ray, -vec3f(frame.view[0].z, frame.view[1].z, frame.view[2].z)), 0.05);
|
|
379
|
+
let bottom = worldPosition + ray * (gap / facing);
|
|
380
|
+
let web = sin(bottom.x * 2.1 + sin(bottom.z * 1.7 + clock)) + sin(bottom.z * 2.3 + sin(bottom.x * 1.9 - clock * 1.3));
|
|
381
|
+
let light = pow(1.0 - abs(web) * 0.5, 6.0) * look.z * exp(-gap / max(look.w, 0.0001));
|
|
382
|
+
let lit = color.rgb + vec3f(0.85, 1.0, 0.9) * light;
|
|
383
|
+
return vec4f(mix(lit, vec3f(0.92), foam), 1.0 - foam);
|
|
384
|
+
}
|
|
385
|
+
`;
|
|
386
|
+
// A scene has one fog slot; another water node waits until its owner releases it.
|
|
387
|
+
const underwaterFogOwners = new WeakMap();
|
|
388
|
+
/**
|
|
389
|
+
* A horizontal water surface. Waves move its vertices and its shading
|
|
390
|
+
* normal; what is under the surface is seen bent through it; the sky reflects
|
|
391
|
+
* from the scene's environment map, and the scene itself after each
|
|
392
|
+
* `renderReflection`. Keep the mesh unrotated: the mirror plane is its world
|
|
393
|
+
* height.
|
|
394
|
+
*/
|
|
395
|
+
export class Water3D extends Mesh3D {
|
|
396
|
+
reflection;
|
|
397
|
+
#uniforms;
|
|
398
|
+
#plane = [0, 1, 0, 0];
|
|
399
|
+
#fogOverride;
|
|
400
|
+
constructor(options = {}) {
|
|
401
|
+
const width = requirePositive3D(options.width ?? 100, 'width'), depth = requirePositive3D(options.depth ?? 100, 'depth'), segments = requireCount3D(options.segments ?? 96, 'segments', 1024);
|
|
402
|
+
if (segments < 1)
|
|
403
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'segments');
|
|
404
|
+
const side = segments + 1, positions = new Float32Array(side * side * 3), normals = new Float32Array(side * side * 3), uvs = new Float32Array(side * side * 2), indices = new Uint32Array(segments * segments * 6);
|
|
405
|
+
for (let iz = 0, at = 0; iz < side; iz++) {
|
|
406
|
+
for (let ix = 0; ix < side; ix++, at++) {
|
|
407
|
+
positions[at * 3] = (ix / segments - 0.5) * width;
|
|
408
|
+
positions[at * 3 + 2] = (iz / segments - 0.5) * depth;
|
|
409
|
+
normals[at * 3 + 1] = 1;
|
|
410
|
+
uvs[at * 2] = ix / segments;
|
|
411
|
+
uvs[at * 2 + 1] = iz / segments;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
for (let iz = 0, at = 0; iz < segments; iz++) {
|
|
415
|
+
for (let ix = 0; ix < segments; ix++) {
|
|
416
|
+
const a = iz * side + ix, b = a + 1, d = a + side, e = d + 1;
|
|
417
|
+
indices[at++] = a;
|
|
418
|
+
indices[at++] = d;
|
|
419
|
+
indices[at++] = b;
|
|
420
|
+
indices[at++] = b;
|
|
421
|
+
indices[at++] = d;
|
|
422
|
+
indices[at++] = e;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const geometry = new Geometry3D();
|
|
426
|
+
geometry.setAttribute('position', new Attribute3D(positions, 3));
|
|
427
|
+
geometry.setAttribute('normal', new Attribute3D(normals, 3));
|
|
428
|
+
geometry.setAttribute('uv', new Attribute3D(uvs, 2));
|
|
429
|
+
geometry.setIndex(side * side > 65535 ? indices : Uint16Array.from(indices));
|
|
430
|
+
const material = createWaterMaterial3D(options);
|
|
431
|
+
super(geometry, material);
|
|
432
|
+
this.name = 'water';
|
|
433
|
+
this.castShadow = false;
|
|
434
|
+
this.#uniforms = material.shader.uniforms;
|
|
435
|
+
const size = requireCount3D(options.reflectionSize ?? 512, 'reflectionSize', TEXTURE3D_LIMITS.maxEdge);
|
|
436
|
+
if (size > 0) {
|
|
437
|
+
this.reflection = new PlanarReflection3D({ width: size, height: size });
|
|
438
|
+
material.reflectionMap = this.reflection.texture;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/** Seconds the waves have been running; set it to keep several clients in step. */
|
|
442
|
+
get time() {
|
|
443
|
+
return this.#uniforms[0];
|
|
444
|
+
}
|
|
445
|
+
set time(value) {
|
|
446
|
+
this.#uniforms[0] = requireFinite3D(value, 'time');
|
|
447
|
+
}
|
|
448
|
+
get amplitude() {
|
|
449
|
+
return this.#uniforms[1];
|
|
450
|
+
}
|
|
451
|
+
set amplitude(value) {
|
|
452
|
+
this.#uniforms[1] = requireFinite3D(value, 'amplitude');
|
|
453
|
+
}
|
|
454
|
+
/** Advance the waves by a time step in seconds. */
|
|
455
|
+
update(deltaSeconds) {
|
|
456
|
+
this.#uniforms[0] = this.#uniforms[0] + requireFinite3D(deltaSeconds, 'deltaSeconds');
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* World height of the surface at a world point now, for floating objects.
|
|
460
|
+
* It ignores the sideways pull of steep waves, so it is exact at steepness 0
|
|
461
|
+
* and close otherwise.
|
|
462
|
+
*/
|
|
463
|
+
heightAt(x, z) {
|
|
464
|
+
const u = this.#uniforms, heading = Math.atan2(u[5], u[4]);
|
|
465
|
+
let height = this.matrixWorld[13];
|
|
466
|
+
for (let i = 0; i < 4; i++) {
|
|
467
|
+
const angle = heading + WAVE_TURN[i], k = (Math.PI * 2) / (u[2] * WAVE_LENGTH[i]);
|
|
468
|
+
height +=
|
|
469
|
+
u[1] *
|
|
470
|
+
WAVE_HEIGHT[i] *
|
|
471
|
+
Math.sin(k * (Math.cos(angle) * x + Math.sin(angle) * z) - Math.sqrt(9.81 * k) * u[3] * u[0]);
|
|
472
|
+
}
|
|
473
|
+
return height;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Draw the scene's mirror image for this frame; call it before rendering
|
|
477
|
+
* the main view. Returns false, and draws nothing, when the camera is under
|
|
478
|
+
* the surface or true reflections are disabled.
|
|
479
|
+
*/
|
|
480
|
+
renderReflection(renderer, scene, camera) {
|
|
481
|
+
if (!this.reflection)
|
|
482
|
+
return false;
|
|
483
|
+
this.updateWorldMatrix();
|
|
484
|
+
this.#plane[3] = -this.matrixWorld[13];
|
|
485
|
+
return this.reflection.render(renderer, scene, camera, this.#plane, [this]);
|
|
486
|
+
}
|
|
487
|
+
/** Test the horizontal wave height at a point, including beyond the rendered mesh edges. */
|
|
488
|
+
isUnderwater(point) {
|
|
489
|
+
this.updateWorldMatrix();
|
|
490
|
+
return point[1] < this.heightAt(point[0], point[2]);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Give the scene the look of being under water while the camera is below
|
|
494
|
+
* the surface: thick fog in the water's color. The scene's own fog is put
|
|
495
|
+
* back when the camera comes up. Call it each frame; it returns whether the
|
|
496
|
+
* camera is under water, where there is no mirror image to draw.
|
|
497
|
+
*/
|
|
498
|
+
updateUnderwater(scene, camera, density = 0.06) {
|
|
499
|
+
camera.updateWorldMatrix();
|
|
500
|
+
const eye = camera.matrixWorld, under = this.isUnderwater([eye[12], eye[13], eye[14]]);
|
|
501
|
+
if (!under || this.#fogOverride?.scene !== scene)
|
|
502
|
+
this.restoreUnderwaterFog();
|
|
503
|
+
if (under && !this.#fogOverride && !underwaterFogOwners.has(scene)) {
|
|
504
|
+
density = requireFinite3D(density, 'density');
|
|
505
|
+
if (density < 0)
|
|
506
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'density');
|
|
507
|
+
const tint = this.material.attenuationColor;
|
|
508
|
+
const installed = {
|
|
509
|
+
kind: 'exponential',
|
|
510
|
+
color: [tint[0] * 1.6, tint[1] * 1.6, tint[2] * 1.6],
|
|
511
|
+
density
|
|
512
|
+
};
|
|
513
|
+
const override = { scene, previous: scene.fog, installed };
|
|
514
|
+
scene.fog = installed;
|
|
515
|
+
underwaterFogOwners.set(scene, override);
|
|
516
|
+
this.#fogOverride = override;
|
|
517
|
+
}
|
|
518
|
+
return under;
|
|
519
|
+
}
|
|
520
|
+
restoreUnderwaterFog() {
|
|
521
|
+
const override = this.#fogOverride;
|
|
522
|
+
this.#fogOverride = undefined;
|
|
523
|
+
if (!override || underwaterFogOwners.get(override.scene) !== override)
|
|
524
|
+
return;
|
|
525
|
+
underwaterFogOwners.delete(override.scene);
|
|
526
|
+
// A later scene edit has already superseded our temporary value.
|
|
527
|
+
if (override.scene.fog === override.installed)
|
|
528
|
+
override.scene.fog = override.previous;
|
|
529
|
+
}
|
|
530
|
+
/** Release the geometry, the material and the mirror image. */
|
|
531
|
+
dispose() {
|
|
532
|
+
this.restoreUnderwaterFog();
|
|
533
|
+
this.geometry.dispose();
|
|
534
|
+
this.material.dispose();
|
|
535
|
+
this.reflection?.dispose();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/** Makes a water surface with waves, reflections and foam. */
|
|
539
|
+
export function createWater3D(options = {}) {
|
|
540
|
+
return new Water3D(options);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* The material Water3D uses, for a water surface on your own geometry: a
|
|
544
|
+
* standard material that refracts, with the wave hooks attached. Advance
|
|
545
|
+
* `material.shader.uniforms[0]`, the time in seconds, every frame.
|
|
546
|
+
*/
|
|
547
|
+
export function createWaterMaterial3D(options = {}) {
|
|
548
|
+
const amplitude = requireFinite3D(options.amplitude ?? 0.15, 'amplitude'), wavelength = requirePositive3D(options.wavelength ?? 9, 'wavelength'), speed = requireFinite3D(options.speed ?? 1, 'speed');
|
|
549
|
+
const direction = options.direction ?? [1, 0.35], dx = requireFinite3D(direction[0], 'direction'), dz = requireFinite3D(direction[1], 'direction'), length = Math.hypot(dx, dz);
|
|
550
|
+
if (length < 1e-6)
|
|
551
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'direction');
|
|
552
|
+
const steepness = requireFinite3D(options.steepness ?? 0.5, 'steepness'), ripple = requireFinite3D(options.rippleStrength ?? 0.12, 'rippleStrength'), rippleLength = requirePositive3D(options.rippleLength ?? 0.9, 'rippleLength');
|
|
553
|
+
const clarity = requireFinite3D(options.clarity ?? 0.85, 'clarity');
|
|
554
|
+
if (steepness < 0 || steepness > 1 || clarity < 0 || clarity > 1)
|
|
555
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'steepness and clarity are 0 to 1');
|
|
556
|
+
const material = createStandardMaterial3D({
|
|
557
|
+
color: options.color ?? 0x2f7f9f,
|
|
558
|
+
roughness: options.roughness ?? 0.06,
|
|
559
|
+
metallic: 0
|
|
560
|
+
});
|
|
561
|
+
material.transmission = clarity;
|
|
562
|
+
material.ior = 1.33;
|
|
563
|
+
material.thickness = requireFinite3D(options.thickness ?? 0.5, 'thickness');
|
|
564
|
+
const tint = colorFromHex(new Float32Array(3), options.color ?? 0x2f7f9f);
|
|
565
|
+
if (options.deepColor === undefined) {
|
|
566
|
+
material.attenuationColor[0] = tint[0] * 0.25;
|
|
567
|
+
material.attenuationColor[1] = tint[1] * 0.35;
|
|
568
|
+
material.attenuationColor[2] = tint[2] * 0.45;
|
|
569
|
+
}
|
|
570
|
+
else
|
|
571
|
+
colorFromHex(material.attenuationColor, options.deepColor);
|
|
572
|
+
const depthFade = requirePositive3D(options.depthFade ?? 6, 'depthFade'), foamWidth = requireFinite3D(options.foamWidth ?? 0.5, 'foamWidth'), caustics = requireFinite3D(options.caustics ?? 0.35, 'caustics');
|
|
573
|
+
material.attenuationDistance = depthFade;
|
|
574
|
+
// Asking for the depth of the solid scene: shore, foam and caustics all depend on how deep the water is.
|
|
575
|
+
material.softness = 1;
|
|
576
|
+
// The underside is drawn too, for a camera below the surface.
|
|
577
|
+
material.side = 'double';
|
|
578
|
+
material.shader = createCustomShader3D({
|
|
579
|
+
key: 'world3d-water',
|
|
580
|
+
glslVertex: GLSL_VERTEX,
|
|
581
|
+
wgslVertex: WGSL_VERTEX,
|
|
582
|
+
glslNormal: GLSL_NORMAL,
|
|
583
|
+
wgslNormal: WGSL_NORMAL,
|
|
584
|
+
glsl: GLSL_FRAGMENT,
|
|
585
|
+
wgsl: WGSL_FRAGMENT,
|
|
586
|
+
uniforms: [
|
|
587
|
+
0,
|
|
588
|
+
amplitude,
|
|
589
|
+
wavelength,
|
|
590
|
+
speed,
|
|
591
|
+
dx / length,
|
|
592
|
+
dz / length,
|
|
593
|
+
steepness,
|
|
594
|
+
ripple,
|
|
595
|
+
rippleLength,
|
|
596
|
+
0.03,
|
|
597
|
+
0,
|
|
598
|
+
0,
|
|
599
|
+
foamWidth,
|
|
600
|
+
foamWidth > 0 ? 1 : 0,
|
|
601
|
+
caustics,
|
|
602
|
+
depthFade * 0.5
|
|
603
|
+
]
|
|
604
|
+
});
|
|
605
|
+
return material;
|
|
606
|
+
}
|
|
607
|
+
//# sourceMappingURL=Water3D.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** What went wrong in the 3D world. */
|
|
2
|
+
export type World3DErrorCode = 'WORLD3D_INPUT_INVALID' | 'WORLD3D_BUDGET' | 'WORLD3D_DISPOSED' | 'WORLD3D_HIERARCHY_INVALID' | 'WORLD3D_GLTF_INVALID' | 'WORLD3D_GLTF_UNSUPPORTED' | 'WORLD3D_RESOURCE_FAILED' | 'WORLD3D_CONTEXT_UNAVAILABLE' | 'WORLD3D_CONTEXT_LOST' | 'WORLD3D_SHADER_FAILED';
|
|
3
|
+
/** Stable machine-readable code plus a human-readable detail and the original cause. */
|
|
4
|
+
export declare class World3DError extends Error {
|
|
5
|
+
readonly code: World3DErrorCode;
|
|
6
|
+
readonly detail: string | undefined;
|
|
7
|
+
constructor(code: World3DErrorCode, detail?: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
/** Process-unique positive integer identity for sort keys and cache lookups. */
|
|
10
|
+
export declare function allocateId3D(): number;
|
|
11
|
+
export declare function requireFinite3D(value: unknown, field: string): number;
|
|
12
|
+
export declare function requirePositive3D(value: unknown, field: string): number;
|
|
13
|
+
export declare function requireCount3D(value: unknown, field: string, max: number): number;
|
|
14
|
+
/** Called when something is disposed of. */
|
|
15
|
+
export type DisposeListener3D = () => void;
|
|
16
|
+
/**
|
|
17
|
+
* CPU-side resource with a version counter and terminal disposal.
|
|
18
|
+
* Backends subscribe through onDispose to retire their GPU objects; the
|
|
19
|
+
* resource never references a backend, so the core stays host-independent.
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class Resource3D {
|
|
22
|
+
#private;
|
|
23
|
+
readonly id: number;
|
|
24
|
+
name: string;
|
|
25
|
+
/** Increases whenever content changed and a backend copy must be refreshed. */
|
|
26
|
+
get version(): number;
|
|
27
|
+
get isDisposed(): boolean;
|
|
28
|
+
/** Mark CPU content as changed. */
|
|
29
|
+
touch(): void;
|
|
30
|
+
/** Returns an unsubscribe function. Listeners run once, in registration order. */
|
|
31
|
+
onDispose(listener: DisposeListener3D): () => void;
|
|
32
|
+
/** Idempotent. Listener failures are collected and rethrown after all have run. */
|
|
33
|
+
dispose(): void;
|
|
34
|
+
protected assertLive(): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=core3D.d.ts.map
|