@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,337 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Renderable nodes: meshes with optional skinning, morphing and instancing,
|
|
3
|
+
// plus bones, skeletons and camera-facing sprites.
|
|
4
|
+
import { World3DError, requireCount3D } from './core3D.js';
|
|
5
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
6
|
+
import { Material3D, createSpriteMaterial3D } from './Material3D.js';
|
|
7
|
+
import { box3Empty, box3ExpandByPoint, mat4Compose, mat4Copy, mat4Identity, mat4Invert, mat4Multiply, sphereFromBox, sphereTransform } from './math3D.js';
|
|
8
|
+
import { Object3D } from './Object3D.js';
|
|
9
|
+
import { createQuadGeometry3D } from './primitives3D.js';
|
|
10
|
+
/** The most bones, instances and materials a mesh has. */
|
|
11
|
+
export const MESH3D_LIMITS = Object.freeze({ maxBones: 1024, maxInstances: 1048576, maxMaterials: 64 });
|
|
12
|
+
/** A bone of a skeleton. */
|
|
13
|
+
export class Bone3D extends Object3D {
|
|
14
|
+
constructor() {
|
|
15
|
+
super('bone');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Ordered bones with their inverse bind matrices; one instance may drive many meshes. */
|
|
19
|
+
export class Skeleton3D {
|
|
20
|
+
bones;
|
|
21
|
+
/** 16 floats per bone: bind-pose mesh space to bone space. */
|
|
22
|
+
inverseBindMatrices;
|
|
23
|
+
/** 16 floats per bone: boneWorld * inverseBind, refreshed by update(). */
|
|
24
|
+
boneMatrices;
|
|
25
|
+
/** Increases on every update(); backends compare it before re-uploading. */
|
|
26
|
+
version = 0;
|
|
27
|
+
#lastFrame = -1;
|
|
28
|
+
constructor(bones, inverseBindMatrices) {
|
|
29
|
+
requireCount3D(bones.length, 'bones', MESH3D_LIMITS.maxBones);
|
|
30
|
+
if (inverseBindMatrices && inverseBindMatrices.length !== bones.length * 16)
|
|
31
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'inverseBindMatrices');
|
|
32
|
+
this.bones = Object.freeze([...bones]);
|
|
33
|
+
this.boneMatrices = new Float32Array(bones.length * 16);
|
|
34
|
+
if (inverseBindMatrices)
|
|
35
|
+
this.inverseBindMatrices = inverseBindMatrices;
|
|
36
|
+
else {
|
|
37
|
+
// Without explicit data, the current pose becomes the bind pose.
|
|
38
|
+
this.inverseBindMatrices = new Float32Array(bones.length * 16);
|
|
39
|
+
bones.forEach((bone, index) => {
|
|
40
|
+
bone.updateWorldMatrix();
|
|
41
|
+
const view = this.inverseBindMatrices.subarray(index * 16, index * 16 + 16);
|
|
42
|
+
if (!mat4Invert(view, bone.matrixWorld))
|
|
43
|
+
mat4Identity(view);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Recompute skinning matrices once per frame id; later calls in the same frame are free. */
|
|
48
|
+
update(frame) {
|
|
49
|
+
if (frame === this.#lastFrame)
|
|
50
|
+
return;
|
|
51
|
+
this.#lastFrame = frame;
|
|
52
|
+
const bones = this.bones, out = this.boneMatrices, inverse = this.inverseBindMatrices;
|
|
53
|
+
// Written out in place: a view per bone per frame would be thousands of short-lived objects.
|
|
54
|
+
for (let i = 0; i < bones.length; i++) {
|
|
55
|
+
const o = i * 16, a = bones[i].matrixWorld;
|
|
56
|
+
const a00 = a[0], a01 = a[1], a02 = a[2], a10 = a[4], a11 = a[5], a12 = a[6], a20 = a[8], a21 = a[9], a22 = a[10], a30 = a[12], a31 = a[13], a32 = a[14];
|
|
57
|
+
for (let column = 0; column < 4; column++) {
|
|
58
|
+
const c = o + column * 4, b0 = inverse[c], b1 = inverse[c + 1], b2 = inverse[c + 2], b3 = inverse[c + 3];
|
|
59
|
+
out[c] = a00 * b0 + a10 * b1 + a20 * b2 + a30 * b3;
|
|
60
|
+
out[c + 1] = a01 * b0 + a11 * b1 + a21 * b2 + a31 * b3;
|
|
61
|
+
out[c + 2] = a02 * b0 + a12 * b1 + a22 * b2 + a32 * b3;
|
|
62
|
+
// Bone and bind matrices are affine, so the last row stays 0 0 0 1.
|
|
63
|
+
out[c + 3] = b3;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this.version++;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** A geometry drawn with materials, with its morph weights and skeleton. */
|
|
70
|
+
export class Mesh3D extends Object3D {
|
|
71
|
+
geometry;
|
|
72
|
+
/** false leaves the mesh out of ray picking, as for effects whose drawn shape is not their geometry. */
|
|
73
|
+
pickable = true;
|
|
74
|
+
/** One material, or one per geometry group addressed by materialIndex. */
|
|
75
|
+
material;
|
|
76
|
+
/** Weight per geometry morph target; resized automatically to the target count. */
|
|
77
|
+
morphWeights = new Float32Array(0);
|
|
78
|
+
skeleton;
|
|
79
|
+
/** Mesh-space to skeleton-space matrix captured at bind time. */
|
|
80
|
+
bindMatrix = mat4Identity(new Float32Array(16));
|
|
81
|
+
#worldSphere = new Float32Array(4);
|
|
82
|
+
#sphereGeometry;
|
|
83
|
+
// Whether this is exactly a Mesh3D, and whether its transform keeps the winding: asked for every mesh on every frame.
|
|
84
|
+
#exact = false;
|
|
85
|
+
#windingWorld = -1;
|
|
86
|
+
#winding = true;
|
|
87
|
+
#sphereVersion = -1;
|
|
88
|
+
#sphereWorld = -1;
|
|
89
|
+
constructor(geometry = new Geometry3D(), material = new Material3D('unlit')) {
|
|
90
|
+
super('mesh');
|
|
91
|
+
this.#exact = new.target === Mesh3D;
|
|
92
|
+
if (!(geometry instanceof Geometry3D))
|
|
93
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'geometry');
|
|
94
|
+
const list = Array.isArray(material) ? material : [material];
|
|
95
|
+
if (list.length === 0 ||
|
|
96
|
+
list.length > MESH3D_LIMITS.maxMaterials ||
|
|
97
|
+
!list.every(item => item instanceof Material3D))
|
|
98
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'material');
|
|
99
|
+
this.geometry = geometry;
|
|
100
|
+
this.material = material;
|
|
101
|
+
this.castShadow = true;
|
|
102
|
+
this.syncMorphWeights();
|
|
103
|
+
}
|
|
104
|
+
get isInstanced() {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* True when an instanced draw could stand in for this mesh: it is a plain
|
|
109
|
+
* Mesh3D without skinning or morphing, and its transform is not mirrored.
|
|
110
|
+
* The renderer uses it to fold repeated meshes into one draw.
|
|
111
|
+
*/
|
|
112
|
+
get canInstance() {
|
|
113
|
+
if (!this.#exact || this.skeleton !== undefined || this.geometry.morphTargets.length > 0)
|
|
114
|
+
return false;
|
|
115
|
+
const version = this.worldVersion;
|
|
116
|
+
if (version !== this.#windingWorld) {
|
|
117
|
+
const m = this.matrixWorld;
|
|
118
|
+
this.#winding =
|
|
119
|
+
m[0] * (m[5] * m[10] - m[6] * m[9]) -
|
|
120
|
+
m[4] * (m[1] * m[10] - m[2] * m[9]) +
|
|
121
|
+
m[8] * (m[1] * m[6] - m[2] * m[5]) >
|
|
122
|
+
0;
|
|
123
|
+
this.#windingWorld = version;
|
|
124
|
+
}
|
|
125
|
+
return this.#winding;
|
|
126
|
+
}
|
|
127
|
+
/** Material for a geometry group index, falling back to the first slot. */
|
|
128
|
+
materialAt(index) {
|
|
129
|
+
return Array.isArray(this.material) ? (this.material[index] ?? this.material[0]) : this.material;
|
|
130
|
+
}
|
|
131
|
+
/** Keep the weight array the same length as the geometry's morph target list. */
|
|
132
|
+
syncMorphWeights() {
|
|
133
|
+
const count = this.geometry.morphTargets.length;
|
|
134
|
+
if (this.morphWeights.length !== count) {
|
|
135
|
+
const next = new Float32Array(count);
|
|
136
|
+
next.set(this.morphWeights.subarray(0, Math.min(count, this.morphWeights.length)));
|
|
137
|
+
this.morphWeights = next;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Attach a skeleton; the current world matrix becomes the bind matrix. */
|
|
141
|
+
bind(skeleton, bindMatrix) {
|
|
142
|
+
this.skeleton = skeleton;
|
|
143
|
+
if (bindMatrix)
|
|
144
|
+
mat4Copy(this.bindMatrix, bindMatrix);
|
|
145
|
+
else {
|
|
146
|
+
this.updateWorldMatrix();
|
|
147
|
+
mat4Copy(this.bindMatrix, this.matrixWorld);
|
|
148
|
+
}
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* World-space bounding sphere [x, y, z, radius], cached per geometry and
|
|
153
|
+
* world version. Skinned meshes are bounded by their bones instead.
|
|
154
|
+
*/
|
|
155
|
+
get worldBoundingSphere() {
|
|
156
|
+
if (this.skeleton)
|
|
157
|
+
return this.skinnedBounds();
|
|
158
|
+
// Compared as numbers: this runs for every mesh on every frame.
|
|
159
|
+
const geometry = this.geometry,
|
|
160
|
+
// A geometry whose points moved in place (cloth, a rope, a trail) has new bounds without a new structure.
|
|
161
|
+
version = geometry.version * 4294967296 + geometry.boundsVersion, world = this.worldVersion;
|
|
162
|
+
if (geometry !== this.#sphereGeometry || version !== this.#sphereVersion || world !== this.#sphereWorld) {
|
|
163
|
+
sphereTransform(this.#worldSphere, geometry.boundingSphere, this.matrixWorld);
|
|
164
|
+
this.#sphereGeometry = geometry;
|
|
165
|
+
this.#sphereVersion = version;
|
|
166
|
+
this.#sphereWorld = world;
|
|
167
|
+
}
|
|
168
|
+
return this.#worldSphere;
|
|
169
|
+
}
|
|
170
|
+
skinnedBounds() {
|
|
171
|
+
const box = box3Empty(new Float32Array(6));
|
|
172
|
+
for (const bone of this.skeleton.bones)
|
|
173
|
+
box3ExpandByPoint(box, bone.matrixWorld[12], bone.matrixWorld[13], bone.matrixWorld[14]);
|
|
174
|
+
sphereFromBox(this.#worldSphere, box);
|
|
175
|
+
// Pad by the rest-pose radius so skin extending beyond joints stays visible.
|
|
176
|
+
const rest = this.geometry.boundingSphere[3];
|
|
177
|
+
if (this.#worldSphere[3] >= 0 && rest > 0)
|
|
178
|
+
this.#worldSphere[3] += rest * 0.5;
|
|
179
|
+
return this.#worldSphere;
|
|
180
|
+
}
|
|
181
|
+
clone(recursive = true) {
|
|
182
|
+
const copy = new Mesh3D(this.geometry, this.material);
|
|
183
|
+
copy.copyFrom(this);
|
|
184
|
+
if (recursive)
|
|
185
|
+
for (const child of this.children)
|
|
186
|
+
copy.addChild(child.clone(true));
|
|
187
|
+
return copy;
|
|
188
|
+
}
|
|
189
|
+
copyFrom(source) {
|
|
190
|
+
super.copyFrom(source);
|
|
191
|
+
this.morphWeights = source.morphWeights.slice();
|
|
192
|
+
this.skeleton = source.skeleton;
|
|
193
|
+
this.bindMatrix.set(source.bindMatrix);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const scratchScale = new Float32Array(3);
|
|
197
|
+
const readInstanceStreamRevisions = Symbol('instanceStreamRevisions3D');
|
|
198
|
+
/** Reconcile legacy bulk edits before a renderer checks either instance stream. */
|
|
199
|
+
export function instanceStreamRevisions3D(mesh) {
|
|
200
|
+
return mesh[readInstanceStreamRevisions]();
|
|
201
|
+
}
|
|
202
|
+
/** Draw one geometry many times in a single call with per-instance transforms and colors. */
|
|
203
|
+
export class InstancedMesh3D extends Mesh3D {
|
|
204
|
+
capacity;
|
|
205
|
+
/** Number of instances drawn; at most `capacity`. */
|
|
206
|
+
count;
|
|
207
|
+
/** 16 floats per instance, relative to this node. */
|
|
208
|
+
instanceMatrices;
|
|
209
|
+
/** Optional linear RGB (or RGBA) per instance, created on first setColorAt(). */
|
|
210
|
+
instanceColors;
|
|
211
|
+
/** Components per instance color: 3 for RGB, 4 when instances also carry opacity. */
|
|
212
|
+
instanceColorSize;
|
|
213
|
+
/** Bump after editing instance arrays directly. */
|
|
214
|
+
instanceVersion = 1;
|
|
215
|
+
#streamRevisions = { observed: 1, matrices: 1, colors: 1 };
|
|
216
|
+
/** Multiplies each instance's bounding radius, for instances that move beyond the geometry, such as animated ones. */
|
|
217
|
+
boundsScale = 1;
|
|
218
|
+
#boundsVersion = 0;
|
|
219
|
+
#boundsCount = -1;
|
|
220
|
+
#boundsGeometry = undefined;
|
|
221
|
+
#boundsShape = -1;
|
|
222
|
+
#instanceSphere = new Float32Array(4);
|
|
223
|
+
constructor(geometry, material, capacity, instanceColorSize = 3) {
|
|
224
|
+
super(geometry, material);
|
|
225
|
+
if (instanceColorSize !== 3 && instanceColorSize !== 4)
|
|
226
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'instanceColorSize');
|
|
227
|
+
this.instanceColorSize = instanceColorSize;
|
|
228
|
+
this.capacity = requireCount3D(capacity, 'capacity', MESH3D_LIMITS.maxInstances);
|
|
229
|
+
this.count = this.capacity;
|
|
230
|
+
this.instanceMatrices = new Float32Array(this.capacity * 16);
|
|
231
|
+
for (let i = 0; i < this.capacity; i++)
|
|
232
|
+
mat4Identity(this.instanceMatrices.subarray(i * 16, i * 16 + 16));
|
|
233
|
+
}
|
|
234
|
+
get isInstanced() {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
setMatrixAt(index, matrix) {
|
|
238
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= this.capacity)
|
|
239
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'instance index');
|
|
240
|
+
for (let i = 0; i < 16; i++)
|
|
241
|
+
this.instanceMatrices[index * 16 + i] = matrix[i];
|
|
242
|
+
this.touchInstanceStream('matrices');
|
|
243
|
+
}
|
|
244
|
+
setTransformAt(index, position, quaternion = [0, 0, 0, 1], scale = 1) {
|
|
245
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= this.capacity)
|
|
246
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'instance index');
|
|
247
|
+
const s = typeof scale === 'number' ? ((scratchScale[0] = scratchScale[1] = scratchScale[2] = scale), scratchScale) : scale;
|
|
248
|
+
mat4Compose(this.instanceMatrices.subarray(index * 16, index * 16 + 16), position, quaternion, s);
|
|
249
|
+
this.touchInstanceStream('matrices');
|
|
250
|
+
}
|
|
251
|
+
setColorAt(index, r, g, b, a = 1) {
|
|
252
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= this.capacity)
|
|
253
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'instance index');
|
|
254
|
+
const size = this.instanceColorSize, colors = (this.instanceColors ??= new Float32Array(this.capacity * size).fill(1));
|
|
255
|
+
colors[index * size] = r;
|
|
256
|
+
colors[index * size + 1] = g;
|
|
257
|
+
colors[index * size + 2] = b;
|
|
258
|
+
if (size === 4)
|
|
259
|
+
colors[index * size + 3] = a;
|
|
260
|
+
this.touchInstanceStream('colors');
|
|
261
|
+
}
|
|
262
|
+
[readInstanceStreamRevisions]() {
|
|
263
|
+
const revisions = this.#streamRevisions;
|
|
264
|
+
if (revisions.observed !== this.instanceVersion) {
|
|
265
|
+
revisions.observed = this.instanceVersion;
|
|
266
|
+
revisions.matrices++;
|
|
267
|
+
revisions.colors++;
|
|
268
|
+
}
|
|
269
|
+
return revisions;
|
|
270
|
+
}
|
|
271
|
+
touchInstanceStream(stream) {
|
|
272
|
+
// A raw write can precede a narrow setter before either stream reaches a renderer.
|
|
273
|
+
const revisions = this[readInstanceStreamRevisions]();
|
|
274
|
+
revisions.observed = ++this.instanceVersion;
|
|
275
|
+
revisions[stream]++;
|
|
276
|
+
}
|
|
277
|
+
/** Sphere enclosing every instance, in world space. */
|
|
278
|
+
get worldBoundingSphere() {
|
|
279
|
+
const sphere = this.#instanceSphere;
|
|
280
|
+
const shape = this.geometry.version * 4294967296 + this.geometry.boundsVersion;
|
|
281
|
+
if (this.#boundsVersion !== this.instanceVersion ||
|
|
282
|
+
this.#boundsCount !== this.count ||
|
|
283
|
+
this.#boundsGeometry !== this.geometry ||
|
|
284
|
+
this.#boundsShape !== shape) {
|
|
285
|
+
const base = this.geometry.boundingSphere, box = box3Empty(new Float32Array(6)), m = this.instanceMatrices;
|
|
286
|
+
let radius = 0;
|
|
287
|
+
for (let i = 0; i < this.count; i++) {
|
|
288
|
+
const o = i * 16, x = base[0], y = base[1], z = base[2];
|
|
289
|
+
box3ExpandByPoint(box, m[o] * x + m[o + 4] * y + m[o + 8] * z + m[o + 12], m[o + 1] * x + m[o + 5] * y + m[o + 9] * z + m[o + 13], m[o + 2] * x + m[o + 6] * y + m[o + 10] * z + m[o + 14]);
|
|
290
|
+
const scale = Math.sqrt(Math.max(m[o] ** 2 + m[o + 1] ** 2 + m[o + 2] ** 2, m[o + 4] ** 2 + m[o + 5] ** 2 + m[o + 6] ** 2, m[o + 8] ** 2 + m[o + 9] ** 2 + m[o + 10] ** 2));
|
|
291
|
+
radius = Math.max(radius, base[3] * scale * this.boundsScale);
|
|
292
|
+
}
|
|
293
|
+
sphereFromBox(this.localSphere, box);
|
|
294
|
+
if (this.localSphere[3] >= 0)
|
|
295
|
+
this.localSphere[3] += radius;
|
|
296
|
+
this.#boundsVersion = this.instanceVersion;
|
|
297
|
+
this.#boundsCount = this.count;
|
|
298
|
+
this.#boundsGeometry = this.geometry;
|
|
299
|
+
this.#boundsShape = shape;
|
|
300
|
+
}
|
|
301
|
+
return sphereTransform(sphere, this.localSphere, this.matrixWorld);
|
|
302
|
+
}
|
|
303
|
+
localSphere = new Float32Array(4);
|
|
304
|
+
clone() {
|
|
305
|
+
const copy = new InstancedMesh3D(this.geometry, this.material, this.capacity, this.instanceColorSize);
|
|
306
|
+
copy.copyFrom(this);
|
|
307
|
+
copy.count = this.count;
|
|
308
|
+
copy.instanceMatrices.set(this.instanceMatrices);
|
|
309
|
+
if (this.instanceColors)
|
|
310
|
+
copy.instanceColors = this.instanceColors.slice();
|
|
311
|
+
return copy;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
let sharedQuad;
|
|
315
|
+
/** Camera-facing textured quad. Scale the node to size it; all sprites share one quad geometry. */
|
|
316
|
+
export class Sprite3D extends Mesh3D {
|
|
317
|
+
constructor(material = createSpriteMaterial3D()) {
|
|
318
|
+
super((sharedQuad ??= createQuadGeometry3D()), material);
|
|
319
|
+
this.castShadow = false;
|
|
320
|
+
this.receiveShadow = false;
|
|
321
|
+
}
|
|
322
|
+
get worldBoundingSphere() {
|
|
323
|
+
// A billboard may rotate to any orientation: bound it by its diagonal.
|
|
324
|
+
const sphere = super.worldBoundingSphere;
|
|
325
|
+
return sphere;
|
|
326
|
+
}
|
|
327
|
+
clone() {
|
|
328
|
+
const copy = new Sprite3D(this.material);
|
|
329
|
+
copy.copyFrom(this);
|
|
330
|
+
return copy;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/** Makes a sprite: a picture that always faces the camera. */
|
|
334
|
+
export function createSprite3D(options = {}) {
|
|
335
|
+
return new Sprite3D(createSpriteMaterial3D(options));
|
|
336
|
+
}
|
|
337
|
+
//# sourceMappingURL=Mesh3D.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** What meshopt data encodes: vertex attributes, triangles or indices. */
|
|
2
|
+
export type MeshoptMode3D = 'ATTRIBUTES' | 'TRIANGLES' | 'INDICES';
|
|
3
|
+
/** The filter meshopt data was encoded with. */
|
|
4
|
+
export type MeshoptFilter3D = 'NONE' | 'OCTAHEDRAL' | 'QUATERNION' | 'EXPONENTIAL';
|
|
5
|
+
/** The largest stride and count of meshopt data. */
|
|
6
|
+
export declare const MESHOPT3D_LIMITS: Readonly<{
|
|
7
|
+
readonly maxStride: 256;
|
|
8
|
+
readonly maxElements: 268435456;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Decode one EXT_meshopt_compression buffer view. `count` elements of
|
|
12
|
+
* `stride` bytes are returned; for the two index modes the stride is 2 or 4.
|
|
13
|
+
*/
|
|
14
|
+
export declare function decodeMeshopt3D(source: Uint8Array, count: number, stride: number, mode: MeshoptMode3D, filter?: MeshoptFilter3D): Uint8Array;
|
|
15
|
+
//# sourceMappingURL=Meshopt3D.d.ts.map
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Decoder for the EXT_meshopt_compression glTF extension, written from the
|
|
3
|
+
// published bitstream description: the vertex codec ("ATTRIBUTES"), the
|
|
4
|
+
// triangle codec ("TRIANGLES"), the index sequence codec ("INDICES") and the
|
|
5
|
+
// three post-decoding filters. It needs no WebAssembly and no dependency, so
|
|
6
|
+
// glTF files compressed this way load without a decoder hook.
|
|
7
|
+
import { World3DError } from './core3D.js';
|
|
8
|
+
/** The largest stride and count of meshopt data. */
|
|
9
|
+
export const MESHOPT3D_LIMITS = Object.freeze({ maxStride: 256, maxElements: 268435456 });
|
|
10
|
+
const bad = (detail) => new World3DError('WORLD3D_GLTF_INVALID', 'meshopt ' + detail);
|
|
11
|
+
/** Vertex codec: each byte of the element is stored as deltas against the previous element, in groups of sixteen. */
|
|
12
|
+
function decodeVertices(source, count, stride, out) {
|
|
13
|
+
if (source.length < 1 + stride)
|
|
14
|
+
throw bad('vertex data is too short');
|
|
15
|
+
if ((source[0] & 0xf0) !== 0xa0 || (source[0] & 0x0f) !== 0)
|
|
16
|
+
throw bad('vertex header');
|
|
17
|
+
// The stream ends with a tail whose last `stride` bytes are the element before the first one.
|
|
18
|
+
const tail = Math.max(stride, 32), end = source.length, last = source.slice(end - stride, end);
|
|
19
|
+
const blockMax = Math.min(((8192 / stride) | 0) & ~15, 256), deltas = new Uint8Array(256);
|
|
20
|
+
let at = 1;
|
|
21
|
+
for (let first = 0; first < count; first += blockMax) {
|
|
22
|
+
const block = Math.min(blockMax, count - first), aligned = (block + 15) & ~15, headerBytes = ((aligned >> 4) + 3) >> 2;
|
|
23
|
+
for (let k = 0; k < stride; k++) {
|
|
24
|
+
const header = at;
|
|
25
|
+
at += headerBytes;
|
|
26
|
+
if (at > end)
|
|
27
|
+
throw bad('vertex data ends early');
|
|
28
|
+
for (let group = 0; group < aligned; group += 16) {
|
|
29
|
+
const index = group >> 4, mode = (source[header + (index >> 2)] >> ((index & 3) * 2)) & 3;
|
|
30
|
+
if (mode === 0)
|
|
31
|
+
deltas.fill(0, group, group + 16);
|
|
32
|
+
else if (mode === 3) {
|
|
33
|
+
if (at + 16 > end)
|
|
34
|
+
throw bad('vertex data ends early');
|
|
35
|
+
deltas.set(source.subarray(at, at + 16), group);
|
|
36
|
+
at += 16;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Packed 2-bit or 4-bit deltas; the largest packed value means "read a whole byte instead".
|
|
40
|
+
const bits = mode === 1 ? 2 : 4, sentinel = (1 << bits) - 1, packed = mode === 1 ? 4 : 8, perByte = 8 / bits;
|
|
41
|
+
let extra = at + packed;
|
|
42
|
+
if (extra > end)
|
|
43
|
+
throw bad('vertex data ends early');
|
|
44
|
+
for (let i = 0; i < 16; i++) {
|
|
45
|
+
const value = (source[at + ((i / perByte) | 0)] >> (8 - bits - (i % perByte) * bits)) & sentinel;
|
|
46
|
+
if (value !== sentinel) {
|
|
47
|
+
deltas[group + i] = value;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (extra >= end)
|
|
51
|
+
throw bad('vertex data ends early');
|
|
52
|
+
deltas[group + i] = source[extra++];
|
|
53
|
+
}
|
|
54
|
+
at = extra;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let previous = last[k];
|
|
58
|
+
for (let i = 0, write = first * stride + k; i < block; i++, write += stride) {
|
|
59
|
+
// Deltas are stored zigzag: even values count up, odd values count down.
|
|
60
|
+
const delta = deltas[i];
|
|
61
|
+
previous = (previous + ((delta >> 1) ^ -(delta & 1))) & 255;
|
|
62
|
+
out[write] = previous;
|
|
63
|
+
}
|
|
64
|
+
last[k] = previous;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (end - at !== tail)
|
|
68
|
+
throw bad('vertex data has the wrong length');
|
|
69
|
+
}
|
|
70
|
+
/** Read a little-endian base-128 number of up to five bytes. */
|
|
71
|
+
function readVarint(source, state, limit) {
|
|
72
|
+
let result = 0, shift = 0;
|
|
73
|
+
for (let i = 0; i < 5; i++) {
|
|
74
|
+
if (state.at >= limit)
|
|
75
|
+
throw bad('index data ends early');
|
|
76
|
+
const byte = source[state.at++];
|
|
77
|
+
result |= (byte & 127) << shift;
|
|
78
|
+
shift += 7;
|
|
79
|
+
if (byte < 128)
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
return result >>> 0;
|
|
83
|
+
}
|
|
84
|
+
/** Triangle codec: one code byte per triangle refers to recently used edges and vertices. */
|
|
85
|
+
function decodeTriangles(source, count, out) {
|
|
86
|
+
if (count % 3 !== 0)
|
|
87
|
+
throw bad('triangle index count');
|
|
88
|
+
const triangles = count / 3;
|
|
89
|
+
if (source.length < 1 + triangles + 16)
|
|
90
|
+
throw bad('index data is too short');
|
|
91
|
+
const version = source[0] & 0x0f;
|
|
92
|
+
if ((source[0] & 0xf0) !== 0xe0 || version > 1)
|
|
93
|
+
throw bad('index header');
|
|
94
|
+
const edges = new Uint32Array(32).fill(0xffffffff), vertices = new Uint32Array(16).fill(0xffffffff);
|
|
95
|
+
const limit = source.length - 16, table = limit, state = { at: 1 + triangles }, directLimit = version >= 1 ? 13 : 15;
|
|
96
|
+
let edgeAt = 0, vertexAt = 0, next = 0, last = 0;
|
|
97
|
+
const pushEdge = (a, b) => {
|
|
98
|
+
edges[edgeAt * 2] = a;
|
|
99
|
+
edges[edgeAt * 2 + 1] = b;
|
|
100
|
+
edgeAt = (edgeAt + 1) & 15;
|
|
101
|
+
};
|
|
102
|
+
// The slot is always written; it only becomes part of the history when `keep` is set.
|
|
103
|
+
const pushVertex = (v, keep) => {
|
|
104
|
+
vertices[vertexAt] = v;
|
|
105
|
+
if (keep)
|
|
106
|
+
vertexAt = (vertexAt + 1) & 15;
|
|
107
|
+
};
|
|
108
|
+
const readIndex = () => {
|
|
109
|
+
const v = readVarint(source, state, limit);
|
|
110
|
+
return (last = (last + ((v >>> 1) ^ -(v & 1))) >>> 0);
|
|
111
|
+
};
|
|
112
|
+
for (let i = 0; i < triangles; i++) {
|
|
113
|
+
const code = source[1 + i];
|
|
114
|
+
let a, b, c;
|
|
115
|
+
if (code < 0xf0) {
|
|
116
|
+
// Reuse an edge from the history; the third corner is new, recent, or given outright.
|
|
117
|
+
const slot = (edgeAt - 1 - (code >> 4)) & 15, third = code & 15;
|
|
118
|
+
a = edges[slot * 2];
|
|
119
|
+
b = edges[slot * 2 + 1];
|
|
120
|
+
if (third < directLimit) {
|
|
121
|
+
c = third === 0 ? next++ : vertices[(vertexAt - 1 - third) & 15];
|
|
122
|
+
pushVertex(c, third === 0);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
c = third === 15 ? readIndex() : (last = (last + (third === 13 ? -1 : 1)) >>> 0);
|
|
126
|
+
pushVertex(c, true);
|
|
127
|
+
}
|
|
128
|
+
pushEdge(c, b);
|
|
129
|
+
pushEdge(a, c);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (code < 0xfe) {
|
|
133
|
+
// A new first corner; the other two come from a small table stored at the end of the stream.
|
|
134
|
+
const aux = source[table + (code & 15)], second = aux >> 4, third = aux & 15;
|
|
135
|
+
a = next++;
|
|
136
|
+
b = second === 0 ? next++ : vertices[(vertexAt - second) & 15];
|
|
137
|
+
c = third === 0 ? next++ : vertices[(vertexAt - third) & 15];
|
|
138
|
+
pushVertex(a, true);
|
|
139
|
+
pushVertex(b, second === 0);
|
|
140
|
+
pushVertex(c, third === 0);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
if (state.at >= limit)
|
|
144
|
+
throw bad('index data ends early');
|
|
145
|
+
const aux = source[state.at++], second = aux >> 4, third = aux & 15, firstGiven = code === 0xff;
|
|
146
|
+
if (aux === 0)
|
|
147
|
+
next = 0;
|
|
148
|
+
a = firstGiven ? 0 : next++;
|
|
149
|
+
b = second === 0 ? next++ : vertices[(vertexAt - second) & 15];
|
|
150
|
+
c = third === 0 ? next++ : vertices[(vertexAt - third) & 15];
|
|
151
|
+
if (firstGiven)
|
|
152
|
+
a = readIndex();
|
|
153
|
+
if (second === 15)
|
|
154
|
+
b = readIndex();
|
|
155
|
+
if (third === 15)
|
|
156
|
+
c = readIndex();
|
|
157
|
+
pushVertex(a, true);
|
|
158
|
+
pushVertex(b, second === 0 || second === 15);
|
|
159
|
+
pushVertex(c, third === 0 || third === 15);
|
|
160
|
+
}
|
|
161
|
+
pushEdge(b, a);
|
|
162
|
+
pushEdge(c, b);
|
|
163
|
+
pushEdge(a, c);
|
|
164
|
+
}
|
|
165
|
+
out[i * 3] = a;
|
|
166
|
+
out[i * 3 + 1] = b;
|
|
167
|
+
out[i * 3 + 2] = c;
|
|
168
|
+
}
|
|
169
|
+
if (state.at !== limit)
|
|
170
|
+
throw bad('index data has the wrong length');
|
|
171
|
+
}
|
|
172
|
+
/** Index sequence codec: each index is a delta against one of two running values. */
|
|
173
|
+
function decodeSequence(source, count, out) {
|
|
174
|
+
if (source.length < 1 + count + 4)
|
|
175
|
+
throw bad('index data is too short');
|
|
176
|
+
if ((source[0] & 0xf0) !== 0xd0 || (source[0] & 0x0f) > 1)
|
|
177
|
+
throw bad('index header');
|
|
178
|
+
const limit = source.length - 4, state = { at: 1 }, last = [0, 0];
|
|
179
|
+
for (let i = 0; i < count; i++) {
|
|
180
|
+
const v = readVarint(source, state, limit), which = v & 1, rest = v >>> 1;
|
|
181
|
+
out[i] = last[which] = (last[which] + ((rest >>> 1) ^ -(rest & 1))) >>> 0;
|
|
182
|
+
}
|
|
183
|
+
if (state.at !== limit)
|
|
184
|
+
throw bad('index data has the wrong length');
|
|
185
|
+
}
|
|
186
|
+
const round = (value) => (value >= 0 ? Math.floor(value + 0.5) : Math.ceil(value - 0.5));
|
|
187
|
+
/** Unit vectors stored as a point on an octahedron; the fourth component is left as it is. */
|
|
188
|
+
function filterOctahedral(data, count, stride) {
|
|
189
|
+
if (stride !== 4 && stride !== 8)
|
|
190
|
+
throw bad('octahedral filter stride');
|
|
191
|
+
const view = stride === 4
|
|
192
|
+
? new Int8Array(data.buffer, data.byteOffset, count * 4)
|
|
193
|
+
: new Int16Array(data.buffer, data.byteOffset, count * 4), max = stride === 4 ? 127 : 32767;
|
|
194
|
+
for (let i = 0; i < count * 4; i += 4) {
|
|
195
|
+
let x = view[i], y = view[i + 1];
|
|
196
|
+
const one = view[i + 2], z = one - Math.abs(x) - Math.abs(y), fold = Math.max(-z, 0);
|
|
197
|
+
x += x >= 0 ? -fold : fold;
|
|
198
|
+
y += y >= 0 ? -fold : fold;
|
|
199
|
+
const scale = max / Math.sqrt(x * x + y * y + z * z);
|
|
200
|
+
view[i] = round(x * scale);
|
|
201
|
+
view[i + 1] = round(y * scale);
|
|
202
|
+
view[i + 2] = round(z * scale);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** Unit quaternions stored as their three smallest components; the largest is rebuilt. */
|
|
206
|
+
function filterQuaternion(data, count, stride) {
|
|
207
|
+
if (stride !== 8)
|
|
208
|
+
throw bad('quaternion filter stride');
|
|
209
|
+
const view = new Int16Array(data.buffer, data.byteOffset, count * 4);
|
|
210
|
+
for (let i = 0; i < count * 4; i += 4) {
|
|
211
|
+
const packed = view[i + 3], scale = Math.SQRT1_2 / (packed | 3), x = view[i] * scale, y = view[i + 1] * scale, z = view[i + 2] * scale;
|
|
212
|
+
const w = Math.sqrt(Math.max(1 - x * x - y * y - z * z, 0)), largest = packed & 3;
|
|
213
|
+
view[i + ((largest + 1) & 3)] = round(x * 32767);
|
|
214
|
+
view[i + ((largest + 2) & 3)] = round(y * 32767);
|
|
215
|
+
view[i + ((largest + 3) & 3)] = round(z * 32767);
|
|
216
|
+
view[i + largest] = round(w * 32767);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Floats stored as an 8-bit exponent above a 24-bit mantissa. */
|
|
220
|
+
function filterExponential(data, count, stride) {
|
|
221
|
+
if (stride % 4 !== 0)
|
|
222
|
+
throw bad('exponential filter stride');
|
|
223
|
+
const total = (count * stride) / 4, ints = new Int32Array(data.buffer, data.byteOffset, total), floats = new Float32Array(data.buffer, data.byteOffset, total);
|
|
224
|
+
for (let i = 0; i < total; i++) {
|
|
225
|
+
const v = ints[i];
|
|
226
|
+
floats[i] = Math.pow(2, v >> 24) * ((v << 8) >> 8);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Decode one EXT_meshopt_compression buffer view. `count` elements of
|
|
231
|
+
* `stride` bytes are returned; for the two index modes the stride is 2 or 4.
|
|
232
|
+
*/
|
|
233
|
+
export function decodeMeshopt3D(source, count, stride, mode, filter = 'NONE') {
|
|
234
|
+
if (!(source instanceof Uint8Array))
|
|
235
|
+
throw bad('source');
|
|
236
|
+
if (!Number.isSafeInteger(count) ||
|
|
237
|
+
count < 0 ||
|
|
238
|
+
!Number.isSafeInteger(stride) ||
|
|
239
|
+
stride <= 0 ||
|
|
240
|
+
stride > MESHOPT3D_LIMITS.maxStride)
|
|
241
|
+
throw bad('count or stride');
|
|
242
|
+
if (count * stride > MESHOPT3D_LIMITS.maxElements)
|
|
243
|
+
throw new World3DError('WORLD3D_BUDGET', 'meshopt output size');
|
|
244
|
+
// A four-byte multiple keeps the typed views used by the filters and index writers aligned.
|
|
245
|
+
const out = new Uint8Array(new ArrayBuffer((count * stride + 3) & ~3), 0, count * stride);
|
|
246
|
+
if (mode === 'ATTRIBUTES') {
|
|
247
|
+
if (stride % 4 !== 0)
|
|
248
|
+
throw bad('vertex stride must be a multiple of four');
|
|
249
|
+
if (count > 0)
|
|
250
|
+
decodeVertices(source, count, stride, out);
|
|
251
|
+
else if (source.length > 0 && (source[0] & 0xf0) !== 0xa0)
|
|
252
|
+
throw bad('vertex header');
|
|
253
|
+
if (filter === 'OCTAHEDRAL')
|
|
254
|
+
filterOctahedral(out, count, stride);
|
|
255
|
+
else if (filter === 'QUATERNION')
|
|
256
|
+
filterQuaternion(out, count, stride);
|
|
257
|
+
else if (filter === 'EXPONENTIAL')
|
|
258
|
+
filterExponential(out, count, stride);
|
|
259
|
+
else if (filter !== 'NONE')
|
|
260
|
+
throw bad('filter');
|
|
261
|
+
return out;
|
|
262
|
+
}
|
|
263
|
+
if (filter !== 'NONE')
|
|
264
|
+
throw bad('filters apply to vertex data only');
|
|
265
|
+
if (stride !== 2 && stride !== 4)
|
|
266
|
+
throw bad('index stride must be two or four');
|
|
267
|
+
const indices = stride === 2 ? new Uint16Array(out.buffer, 0, count) : new Uint32Array(out.buffer, 0, count);
|
|
268
|
+
if (mode === 'TRIANGLES')
|
|
269
|
+
decodeTriangles(source, count, indices);
|
|
270
|
+
else if (mode === 'INDICES')
|
|
271
|
+
decodeSequence(source, count, indices);
|
|
272
|
+
else
|
|
273
|
+
throw bad('mode');
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=Meshopt3D.js.map
|