@needle-tools/engine 4.13.0 → 4.13.1-next.6cb1b73
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/CHANGELOG.md +8 -1
- package/README.md +37 -0
- package/components.needle.json +1 -1
- package/custom-elements.json +138 -4
- package/dist/gltf-progressive-BTd714P0.min.js +9 -0
- package/dist/gltf-progressive-CrHduHPm.umd.cjs +9 -0
- package/dist/{gltf-progressive-eiJCrjLb.js → gltf-progressive-CsyU_5lc.js} +364 -287
- package/dist/{needle-engine.bundle-CxaKFQVS.min.js → needle-engine.bundle-DRSn34Va.min.js} +109 -109
- package/dist/{needle-engine.bundle-J4k4znv8.umd.cjs → needle-engine.bundle-qTjHpin6.umd.cjs} +110 -110
- package/dist/{needle-engine.bundle-Dl3TFYyv.js → needle-engine.bundle-wB3o8RB6.js} +2655 -2130
- package/dist/needle-engine.d.ts +4202 -423
- package/dist/needle-engine.js +3 -3
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_context.d.ts +16 -0
- package/lib/engine/engine_context.js +28 -2
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +72 -0
- package/lib/engine/engine_gameobject.js +38 -0
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_input.d.ts +80 -4
- package/lib/engine/engine_input.js +78 -2
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_math.d.ts +81 -2
- package/lib/engine/engine_math.js +68 -2
- package/lib/engine/engine_math.js.map +1 -1
- package/lib/engine/engine_networking.d.ts +181 -14
- package/lib/engine/engine_networking.js +181 -14
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_auto.d.ts +35 -8
- package/lib/engine/engine_networking_auto.js +35 -8
- package/lib/engine/engine_networking_auto.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +37 -1
- package/lib/engine/engine_physics.js +37 -1
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_physics_rapier.d.ts +78 -0
- package/lib/engine/engine_physics_rapier.js +78 -0
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/engine_serialization_decorator.d.ts +28 -2
- package/lib/engine/engine_serialization_decorator.js +28 -2
- package/lib/engine/engine_serialization_decorator.js.map +1 -1
- package/lib/engine/engine_time.d.ts +23 -3
- package/lib/engine/engine_time.js +23 -3
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_util_decorator.d.ts +31 -1
- package/lib/engine/engine_util_decorator.js +31 -1
- package/lib/engine/engine_util_decorator.js.map +1 -1
- package/lib/engine/engine_utils.d.ts +22 -5
- package/lib/engine/engine_utils.js +22 -5
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/engine_utils_screenshot.d.ts +171 -14
- package/lib/engine/engine_utils_screenshot.js +65 -0
- package/lib/engine/engine_utils_screenshot.js.map +1 -1
- package/lib/engine/engine_utils_screenshot.xr.d.ts +1 -1
- package/lib/engine/engine_utils_screenshot.xr.js +1 -1
- package/lib/engine/extensions/NEEDLE_materialx.d.ts +2 -2
- package/lib/engine/extensions/NEEDLE_materialx.js +2 -2
- package/lib/engine/extensions/NEEDLE_materialx.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +3 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine/extensions/index.d.ts +1 -1
- package/lib/engine/extensions/index.js +1 -1
- package/lib/engine/extensions/index.js.map +1 -1
- package/lib/engine/xr/NeedleXRSession.d.ts +5 -0
- package/lib/engine/xr/NeedleXRSession.js +5 -0
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine-components/AlignmentConstraint.d.ts +23 -3
- package/lib/engine-components/AlignmentConstraint.js +23 -3
- package/lib/engine-components/AlignmentConstraint.js.map +1 -1
- package/lib/engine-components/Animation.d.ts +42 -0
- package/lib/engine-components/Animation.js +36 -0
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/Animator.d.ts +37 -4
- package/lib/engine-components/Animator.js +37 -4
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AudioListener.d.ts +1 -1
- package/lib/engine-components/AudioListener.js +1 -1
- package/lib/engine-components/AudioSource.d.ts +32 -10
- package/lib/engine-components/AudioSource.js +32 -10
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/AxesHelper.d.ts +22 -3
- package/lib/engine-components/AxesHelper.js +22 -3
- package/lib/engine-components/AxesHelper.js.map +1 -1
- package/lib/engine-components/BasicIKConstraint.d.ts +27 -4
- package/lib/engine-components/BasicIKConstraint.js +27 -4
- package/lib/engine-components/BasicIKConstraint.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +32 -2
- package/lib/engine-components/Camera.js +32 -2
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CharacterController.d.ts +68 -4
- package/lib/engine-components/CharacterController.js +68 -4
- package/lib/engine-components/CharacterController.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +69 -12
- package/lib/engine-components/Collider.js +69 -12
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/ContactShadows.d.ts +28 -6
- package/lib/engine-components/ContactShadows.js +33 -8
- package/lib/engine-components/ContactShadows.js.map +1 -1
- package/lib/engine-components/DeleteBox.d.ts +43 -2
- package/lib/engine-components/DeleteBox.js +43 -2
- package/lib/engine-components/DeleteBox.js.map +1 -1
- package/lib/engine-components/DeviceFlag.d.ts +21 -2
- package/lib/engine-components/DeviceFlag.js +21 -2
- package/lib/engine-components/DeviceFlag.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +32 -2
- package/lib/engine-components/DragControls.js +32 -2
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/DropListener.d.ts +33 -21
- package/lib/engine-components/DropListener.js +33 -21
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/Duplicatable.d.ts +36 -5
- package/lib/engine-components/Duplicatable.js +36 -5
- package/lib/engine-components/Duplicatable.js.map +1 -1
- package/lib/engine-components/EventList.d.ts +38 -10
- package/lib/engine-components/EventList.js +40 -12
- package/lib/engine-components/EventList.js.map +1 -1
- package/lib/engine-components/EventTrigger.d.ts +1 -1
- package/lib/engine-components/EventTrigger.js +1 -1
- package/lib/engine-components/Fog.d.ts +23 -1
- package/lib/engine-components/Fog.js +23 -1
- package/lib/engine-components/Fog.js.map +1 -1
- package/lib/engine-components/GridHelper.d.ts +18 -2
- package/lib/engine-components/GridHelper.js +18 -2
- package/lib/engine-components/GridHelper.js.map +1 -1
- package/lib/engine-components/GroundProjection.d.ts +24 -2
- package/lib/engine-components/GroundProjection.js +24 -2
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/Interactable.d.ts +17 -2
- package/lib/engine-components/Interactable.js +17 -2
- package/lib/engine-components/Interactable.js.map +1 -1
- package/lib/engine-components/Joints.d.ts +50 -7
- package/lib/engine-components/Joints.js +50 -7
- package/lib/engine-components/Joints.js.map +1 -1
- package/lib/engine-components/LODGroup.d.ts +36 -14
- package/lib/engine-components/LODGroup.js +43 -11
- package/lib/engine-components/LODGroup.js.map +1 -1
- package/lib/engine-components/Light.d.ts +30 -5
- package/lib/engine-components/Light.js +30 -5
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/LookAtConstraint.d.ts +22 -7
- package/lib/engine-components/LookAtConstraint.js +22 -7
- package/lib/engine-components/LookAtConstraint.js.map +1 -1
- package/lib/engine-components/NeedleMenu.d.ts +27 -5
- package/lib/engine-components/NeedleMenu.js +27 -5
- package/lib/engine-components/NeedleMenu.js.map +1 -1
- package/lib/engine-components/NestedGltf.d.ts +39 -4
- package/lib/engine-components/NestedGltf.js +42 -4
- package/lib/engine-components/NestedGltf.js.map +1 -1
- package/lib/engine-components/OffsetConstraint.d.ts +27 -3
- package/lib/engine-components/OffsetConstraint.js +27 -3
- package/lib/engine-components/OffsetConstraint.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +41 -3
- package/lib/engine-components/OrbitControls.js +41 -3
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/PlayerColor.d.ts +1 -1
- package/lib/engine-components/PlayerColor.js +1 -1
- package/lib/engine-components/ReflectionProbe.d.ts +17 -2
- package/lib/engine-components/ReflectionProbe.js +17 -3
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +35 -0
- package/lib/engine-components/Renderer.js +36 -2
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +57 -5
- package/lib/engine-components/RigidBody.js +57 -5
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.d.ts +11 -0
- package/lib/engine-components/SceneSwitcher.js +11 -0
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/ScreenCapture.d.ts +39 -6
- package/lib/engine-components/ScreenCapture.js +39 -6
- package/lib/engine-components/ScreenCapture.js.map +1 -1
- package/lib/engine-components/SeeThrough.d.ts +70 -5
- package/lib/engine-components/SeeThrough.js +70 -5
- package/lib/engine-components/SeeThrough.js.map +1 -1
- package/lib/engine-components/ShadowCatcher.d.ts +56 -4
- package/lib/engine-components/ShadowCatcher.js +56 -4
- package/lib/engine-components/ShadowCatcher.js.map +1 -1
- package/lib/engine-components/Skybox.d.ts +43 -7
- package/lib/engine-components/Skybox.js +43 -7
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/SmoothFollow.d.ts +66 -7
- package/lib/engine-components/SmoothFollow.js +66 -7
- package/lib/engine-components/SmoothFollow.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +48 -1
- package/lib/engine-components/SpatialTrigger.js +48 -1
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +21 -3
- package/lib/engine-components/SpectatorCamera.js +21 -3
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedRoom.d.ts +7 -1
- package/lib/engine-components/SyncedRoom.js +7 -1
- package/lib/engine-components/SyncedRoom.js.map +1 -1
- package/lib/engine-components/SyncedTransform.d.ts +55 -6
- package/lib/engine-components/SyncedTransform.js +55 -6
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +30 -3
- package/lib/engine-components/TransformGizmo.js +30 -3
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/VideoPlayer.d.ts +33 -6
- package/lib/engine-components/VideoPlayer.js +51 -6
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/Voip.d.ts +33 -2
- package/lib/engine-components/Voip.js +33 -2
- package/lib/engine-components/Voip.js.map +1 -1
- package/lib/engine-components/export/usdz/USDZExporter.d.ts +47 -13
- package/lib/engine-components/export/usdz/USDZExporter.js +47 -13
- package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystem.d.ts +82 -3
- package/lib/engine-components/particlesystem/ParticleSystem.js +82 -3
- package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +1 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js +1 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/BloomEffect.js +1 -1
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +1 -1
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +1 -1
- package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js +1 -1
- package/lib/engine-components/postprocessing/Effects/EffectWrapper.d.ts +1 -0
- package/lib/engine-components/postprocessing/Effects/EffectWrapper.js +1 -0
- package/lib/engine-components/postprocessing/Effects/EffectWrapper.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/Pixelation.js +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +1 -1
- package/lib/engine-components/postprocessing/Effects/TiltShiftEffect.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/TiltShiftEffect.js +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +1 -1
- package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/Vignette.js +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +1 -1
- package/lib/engine-components/postprocessing/Volume.d.ts +1 -1
- package/lib/engine-components/postprocessing/Volume.js +1 -1
- package/lib/engine-components/splines/Spline.d.ts +409 -12
- package/lib/engine-components/splines/Spline.js +409 -12
- package/lib/engine-components/splines/Spline.js.map +1 -1
- package/lib/engine-components/splines/SplineUtils.d.ts +1 -0
- package/lib/engine-components/splines/SplineUtils.js +1 -0
- package/lib/engine-components/splines/SplineUtils.js.map +1 -1
- package/lib/engine-components/splines/SplineWalker.d.ts +3 -1
- package/lib/engine-components/splines/SplineWalker.js +3 -1
- package/lib/engine-components/splines/SplineWalker.js.map +1 -1
- package/lib/engine-components/timeline/PlayableDirector.d.ts +103 -14
- package/lib/engine-components/timeline/PlayableDirector.js +95 -25
- package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
- package/lib/engine-components/timeline/TimelineModels.d.ts +14 -0
- package/lib/engine-components/timeline/TimelineModels.js +4 -0
- package/lib/engine-components/timeline/TimelineModels.js.map +1 -1
- package/lib/engine-components/ui/Button.d.ts +29 -3
- package/lib/engine-components/ui/Button.js +29 -3
- package/lib/engine-components/ui/Button.js.map +1 -1
- package/lib/engine-components/ui/Canvas.d.ts +29 -4
- package/lib/engine-components/ui/Canvas.js +29 -4
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/CanvasGroup.d.ts +1 -1
- package/lib/engine-components/ui/CanvasGroup.js +1 -1
- package/lib/engine-components/ui/EventSystem.d.ts +1 -1
- package/lib/engine-components/ui/EventSystem.js +1 -1
- package/lib/engine-components/ui/Graphic.d.ts +1 -0
- package/lib/engine-components/ui/Graphic.js +1 -0
- package/lib/engine-components/ui/Graphic.js.map +1 -1
- package/lib/engine-components/ui/Image.d.ts +22 -3
- package/lib/engine-components/ui/Image.js +22 -3
- package/lib/engine-components/ui/Image.js.map +1 -1
- package/lib/engine-components/ui/InputField.d.ts +1 -1
- package/lib/engine-components/ui/InputField.js +1 -1
- package/lib/engine-components/ui/Layout.d.ts +3 -0
- package/lib/engine-components/ui/Layout.js +3 -0
- package/lib/engine-components/ui/Layout.js.map +1 -1
- package/lib/engine-components/ui/Outline.d.ts +1 -1
- package/lib/engine-components/ui/Outline.js +1 -1
- package/lib/engine-components/ui/PointerEvents.d.ts +1 -1
- package/lib/engine-components/ui/PointerEvents.js +1 -1
- package/lib/engine-components/ui/Raycaster.d.ts +55 -6
- package/lib/engine-components/ui/Raycaster.js +55 -6
- package/lib/engine-components/ui/Raycaster.js.map +1 -1
- package/lib/engine-components/ui/RectTransform.d.ts +1 -1
- package/lib/engine-components/ui/RectTransform.js +1 -1
- package/lib/engine-components/ui/SpatialHtml.d.ts +1 -1
- package/lib/engine-components/ui/SpatialHtml.js +1 -1
- package/lib/engine-components/ui/Text.d.ts +23 -1
- package/lib/engine-components/ui/Text.js +23 -1
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components/utils/LookAt.d.ts +1 -1
- package/lib/engine-components/utils/LookAt.js +1 -1
- package/lib/engine-components/utils/OpenURL.d.ts +2 -1
- package/lib/engine-components/utils/OpenURL.js +2 -1
- package/lib/engine-components/utils/OpenURL.js.map +1 -1
- package/lib/engine-components/web/Clickthrough.d.ts +116 -7
- package/lib/engine-components/web/Clickthrough.js +116 -7
- package/lib/engine-components/web/Clickthrough.js.map +1 -1
- package/lib/engine-components/web/CursorFollow.d.ts +172 -7
- package/lib/engine-components/web/CursorFollow.js +172 -7
- package/lib/engine-components/web/CursorFollow.js.map +1 -1
- package/lib/engine-components/web/HoverAnimation.d.ts +140 -11
- package/lib/engine-components/web/HoverAnimation.js +140 -11
- package/lib/engine-components/web/HoverAnimation.js.map +1 -1
- package/lib/engine-components/web/ScrollFollow.d.ts +5 -1
- package/lib/engine-components/web/ScrollFollow.js +5 -1
- package/lib/engine-components/web/ScrollFollow.js.map +1 -1
- package/lib/engine-components/web/ViewBox.d.ts +116 -16
- package/lib/engine-components/web/ViewBox.js +110 -16
- package/lib/engine-components/web/ViewBox.js.map +1 -1
- package/lib/engine-components/webxr/TeleportTarget.d.ts +21 -2
- package/lib/engine-components/webxr/TeleportTarget.js +21 -2
- package/lib/engine-components/webxr/TeleportTarget.js.map +1 -1
- package/lib/engine-components/webxr/WebARCameraBackground.d.ts +9 -0
- package/lib/engine-components/webxr/WebARCameraBackground.js +9 -0
- package/lib/engine-components/webxr/WebARCameraBackground.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.d.ts +11 -2
- package/lib/engine-components/webxr/WebXR.js +11 -2
- package/lib/engine-components/webxr/WebXR.js.map +1 -1
- package/lib/engine-components/webxr/WebXRAvatar.d.ts +39 -2
- package/lib/engine-components/webxr/WebXRAvatar.js +35 -3
- package/lib/engine-components/webxr/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.d.ts +266 -30
- package/lib/engine-components/webxr/WebXRImageTracking.js +266 -30
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/lib/engine-components/webxr/WebXRPlaneTracking.d.ts +1 -1
- package/lib/engine-components/webxr/WebXRPlaneTracking.js +1 -1
- package/lib/engine-components/webxr/XRFlag.d.ts +29 -2
- package/lib/engine-components/webxr/XRFlag.js +29 -2
- package/lib/engine-components/webxr/XRFlag.js.map +1 -1
- package/package.json +3 -3
- package/plugins/vite/custom-element-data.js +128 -19
- package/src/engine/engine_context.ts +33 -3
- package/src/engine/engine_gameobject.ts +73 -0
- package/src/engine/engine_input.ts +83 -7
- package/src/engine/engine_math.ts +81 -2
- package/src/engine/engine_networking.ts +186 -17
- package/src/engine/engine_networking_auto.ts +36 -9
- package/src/engine/engine_physics.ts +41 -1
- package/src/engine/engine_physics_rapier.ts +81 -0
- package/src/engine/engine_serialization_decorator.ts +28 -2
- package/src/engine/engine_time.ts +23 -3
- package/src/engine/engine_util_decorator.ts +31 -1
- package/src/engine/engine_utils.ts +22 -5
- package/src/engine/engine_utils_screenshot.ts +241 -17
- package/src/engine/engine_utils_screenshot.xr.ts +1 -1
- package/src/engine/extensions/NEEDLE_materialx.ts +5 -4
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +3 -0
- package/src/engine/extensions/index.ts +2 -2
- package/src/engine/xr/NeedleXRSession.ts +5 -0
- package/src/engine-components/AlignmentConstraint.ts +24 -4
- package/src/engine-components/Animation.ts +44 -2
- package/src/engine-components/Animator.ts +40 -7
- package/src/engine-components/AudioListener.ts +1 -1
- package/src/engine-components/AudioSource.ts +37 -15
- package/src/engine-components/AxesHelper.ts +23 -4
- package/src/engine-components/BasicIKConstraint.ts +28 -5
- package/src/engine-components/Camera.ts +33 -3
- package/src/engine-components/CharacterController.ts +74 -7
- package/src/engine-components/Collider.ts +78 -21
- package/src/engine-components/ContactShadows.ts +41 -11
- package/src/engine-components/DeleteBox.ts +43 -2
- package/src/engine-components/DeviceFlag.ts +22 -3
- package/src/engine-components/DragControls.ts +32 -2
- package/src/engine-components/DropListener.ts +41 -29
- package/src/engine-components/Duplicatable.ts +37 -6
- package/src/engine-components/EventList.ts +43 -15
- package/src/engine-components/EventTrigger.ts +1 -1
- package/src/engine-components/Fog.ts +23 -1
- package/src/engine-components/GridHelper.ts +18 -2
- package/src/engine-components/GroundProjection.ts +25 -3
- package/src/engine-components/Interactable.ts +17 -2
- package/src/engine-components/Joints.ts +51 -8
- package/src/engine-components/LODGroup.ts +45 -11
- package/src/engine-components/Light.ts +35 -13
- package/src/engine-components/LookAtConstraint.ts +26 -8
- package/src/engine-components/NeedleMenu.ts +29 -7
- package/src/engine-components/NestedGltf.ts +40 -4
- package/src/engine-components/OffsetConstraint.ts +27 -3
- package/src/engine-components/OrbitControls.ts +41 -3
- package/src/engine-components/PlayerColor.ts +1 -1
- package/src/engine-components/ReflectionProbe.ts +19 -5
- package/src/engine-components/Renderer.ts +35 -1
- package/src/engine-components/RigidBody.ts +64 -8
- package/src/engine-components/SceneSwitcher.ts +11 -0
- package/src/engine-components/ScreenCapture.ts +42 -9
- package/src/engine-components/SeeThrough.ts +76 -9
- package/src/engine-components/ShadowCatcher.ts +61 -6
- package/src/engine-components/Skybox.ts +48 -12
- package/src/engine-components/SmoothFollow.ts +68 -7
- package/src/engine-components/SpatialTrigger.ts +51 -4
- package/src/engine-components/SpectatorCamera.ts +23 -5
- package/src/engine-components/SyncedRoom.ts +8 -2
- package/src/engine-components/SyncedTransform.ts +59 -10
- package/src/engine-components/TransformGizmo.ts +31 -4
- package/src/engine-components/VideoPlayer.ts +54 -6
- package/src/engine-components/Voip.ts +33 -2
- package/src/engine-components/export/usdz/USDZExporter.ts +47 -13
- package/src/engine-components/particlesystem/ParticleSystem.ts +84 -5
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +1 -0
- package/src/engine-components/postprocessing/Effects/BloomEffect.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +1 -1
- package/src/engine-components/postprocessing/Effects/DepthOfField.ts +1 -1
- package/src/engine-components/postprocessing/Effects/EffectWrapper.ts +1 -0
- package/src/engine-components/postprocessing/Effects/Pixelation.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +1 -1
- package/src/engine-components/postprocessing/Effects/TiltShiftEffect.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Vignette.ts +1 -1
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
- package/src/engine-components/postprocessing/Volume.ts +1 -1
- package/src/engine-components/splines/Spline.ts +412 -14
- package/src/engine-components/splines/SplineUtils.ts +1 -0
- package/src/engine-components/splines/SplineWalker.ts +4 -2
- package/src/engine-components/timeline/PlayableDirector.ts +108 -27
- package/src/engine-components/timeline/SignalAsset.ts +1 -1
- package/src/engine-components/timeline/TimelineModels.ts +18 -2
- package/src/engine-components/ui/Button.ts +29 -3
- package/src/engine-components/ui/Canvas.ts +29 -4
- package/src/engine-components/ui/CanvasGroup.ts +2 -2
- package/src/engine-components/ui/EventSystem.ts +1 -1
- package/src/engine-components/ui/Graphic.ts +1 -0
- package/src/engine-components/ui/Image.ts +22 -3
- package/src/engine-components/ui/InputField.ts +2 -2
- package/src/engine-components/ui/Layout.ts +3 -0
- package/src/engine-components/ui/Outline.ts +1 -1
- package/src/engine-components/ui/PointerEvents.ts +1 -1
- package/src/engine-components/ui/Raycaster.ts +57 -8
- package/src/engine-components/ui/RectTransform.ts +2 -2
- package/src/engine-components/ui/SpatialHtml.ts +1 -1
- package/src/engine-components/ui/Text.ts +24 -2
- package/src/engine-components/utils/LookAt.ts +1 -1
- package/src/engine-components/utils/OpenURL.ts +2 -1
- package/src/engine-components/web/Clickthrough.ts +119 -10
- package/src/engine-components/web/CursorFollow.ts +175 -9
- package/src/engine-components/web/HoverAnimation.ts +142 -13
- package/src/engine-components/web/ScrollFollow.ts +5 -1
- package/src/engine-components/web/ViewBox.ts +118 -18
- package/src/engine-components/webxr/TeleportTarget.ts +23 -4
- package/src/engine-components/webxr/WebARCameraBackground.ts +12 -3
- package/src/engine-components/webxr/WebXR.ts +12 -3
- package/src/engine-components/webxr/WebXRAvatar.ts +41 -4
- package/src/engine-components/webxr/WebXRImageTracking.ts +282 -38
- package/src/engine-components/webxr/WebXRPlaneTracking.ts +1 -1
- package/src/engine-components/webxr/XRFlag.ts +30 -3
- package/dist/gltf-progressive-BURrJW0U.umd.cjs +0 -8
- package/dist/gltf-progressive-DHLDFNvQ.min.js +0 -8
package/custom-elements.json
CHANGED
|
@@ -225,16 +225,150 @@
|
|
|
225
225
|
|
|
226
226
|
{
|
|
227
227
|
"name": "background-image",
|
|
228
|
-
"description": "URL to .exr, .hdr, .png, .jpg to be used as skybox",
|
|
228
|
+
"description": "URL to .exr, .hdr, .png, .jpg to be used as skybox. Can also be a magic name for built-in skyboxes, or a FastHDR URL from cdn.needle.tools.",
|
|
229
|
+
"values": [
|
|
230
|
+
{
|
|
231
|
+
"name": "studio",
|
|
232
|
+
"description": "Neutral studio lighting (magic name)"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"name": "blurred-skybox",
|
|
236
|
+
"description": "Soft blurred environment (magic name)"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"name": "quicklook",
|
|
240
|
+
"description": "Apple QuickLook Object Mode (magic name)"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"name": "quicklook-ar",
|
|
244
|
+
"description": "Apple QuickLook AR Mode (magic name)"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"name": "https://cdn.needle.tools/static/hdris/studio_small_09_2k.pmrem.ktx2",
|
|
248
|
+
"description": "FastHDR: Studio Small - neutral product lighting"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"name": "https://cdn.needle.tools/static/hdris/photo_studio_01_2k.pmrem.ktx2",
|
|
252
|
+
"description": "FastHDR: Photo Studio - professional lighting"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"name": "https://cdn.needle.tools/static/hdris/brown_photostudio_02_2k.pmrem.ktx2",
|
|
256
|
+
"description": "FastHDR: Brown Photo Studio - warm tones"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"name": "https://cdn.needle.tools/static/hdris/venice_sunset_2k.pmrem.ktx2",
|
|
260
|
+
"description": "FastHDR: Venice Sunset - golden hour"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"name": "https://cdn.needle.tools/static/hdris/spruit_sunrise_2k.pmrem.ktx2",
|
|
264
|
+
"description": "FastHDR: Spruit Sunrise - morning light"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"name": "https://cdn.needle.tools/static/hdris/meadow_2k.pmrem.ktx2",
|
|
268
|
+
"description": "FastHDR: Meadow - outdoor natural"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"name": "https://cdn.needle.tools/static/hdris/canary_wharf_2k.pmrem.ktx2",
|
|
272
|
+
"description": "FastHDR: Canary Wharf - urban daylight"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
"name": "https://cdn.needle.tools/static/hdris/shanghai_bund_2k.pmrem.ktx2",
|
|
276
|
+
"description": "FastHDR: Shanghai Bund - city night"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"name": "https://cdn.needle.tools/static/hdris/cayley_interior_2k.pmrem.ktx2",
|
|
280
|
+
"description": "FastHDR: Cayley Interior - indoor ambient"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"name": "https://cdn.needle.tools/static/hdris/fireplace_2k.pmrem.ktx2",
|
|
284
|
+
"description": "FastHDR: Fireplace - warm interior"
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"name": "https://cdn.needle.tools/static/hdris/the_sky_is_on_fire_2k.pmrem.ktx2",
|
|
288
|
+
"description": "FastHDR: The Sky is on Fire - dramatic sunset"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"name": "https://cdn.needle.tools/static/hdris/dikhololo_night_2k.pmrem.ktx2",
|
|
292
|
+
"description": "FastHDR: Dikhololo Night - night sky"
|
|
293
|
+
}
|
|
294
|
+
],
|
|
229
295
|
"references": [
|
|
230
|
-
{ "name": "Needle Engine reference", "url": "https://engine.needle.tools/docs/reference/needle-engine-attributes.html" }
|
|
296
|
+
{ "name": "Needle Engine reference", "url": "https://engine.needle.tools/docs/reference/needle-engine-attributes.html" },
|
|
297
|
+
{ "name": "FastHDR Library", "url": "https://cloud.needle.tools/hdris" }
|
|
231
298
|
]
|
|
232
299
|
},
|
|
233
300
|
{
|
|
234
301
|
"name": "environment-image",
|
|
235
|
-
"description": "URL to .exr, .hdr, .png, .jpg to be used for lighting",
|
|
302
|
+
"description": "URL to .exr, .hdr, .png, .jpg to be used for lighting. Can also be a magic name for built-in environments, or a FastHDR URL from cdn.needle.tools.",
|
|
303
|
+
"values": [
|
|
304
|
+
{
|
|
305
|
+
"name": "studio",
|
|
306
|
+
"description": "Neutral studio lighting (magic name)"
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
"name": "blurred-skybox",
|
|
310
|
+
"description": "Soft blurred environment (magic name)"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
"name": "quicklook",
|
|
314
|
+
"description": "Apple QuickLook Object Mode (magic name)"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"name": "quicklook-ar",
|
|
318
|
+
"description": "Apple QuickLook AR Mode (magic name)"
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
"name": "https://cdn.needle.tools/static/hdris/studio_small_09_2k.pmrem.ktx2",
|
|
322
|
+
"description": "FastHDR: Studio Small - neutral product lighting"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
"name": "https://cdn.needle.tools/static/hdris/photo_studio_01_2k.pmrem.ktx2",
|
|
326
|
+
"description": "FastHDR: Photo Studio - professional lighting"
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"name": "https://cdn.needle.tools/static/hdris/brown_photostudio_02_2k.pmrem.ktx2",
|
|
330
|
+
"description": "FastHDR: Brown Photo Studio - warm tones"
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"name": "https://cdn.needle.tools/static/hdris/venice_sunset_2k.pmrem.ktx2",
|
|
334
|
+
"description": "FastHDR: Venice Sunset - golden hour"
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
"name": "https://cdn.needle.tools/static/hdris/spruit_sunrise_2k.pmrem.ktx2",
|
|
338
|
+
"description": "FastHDR: Spruit Sunrise - morning light"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"name": "https://cdn.needle.tools/static/hdris/meadow_2k.pmrem.ktx2",
|
|
342
|
+
"description": "FastHDR: Meadow - outdoor natural"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"name": "https://cdn.needle.tools/static/hdris/canary_wharf_2k.pmrem.ktx2",
|
|
346
|
+
"description": "FastHDR: Canary Wharf - urban daylight"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
"name": "https://cdn.needle.tools/static/hdris/shanghai_bund_2k.pmrem.ktx2",
|
|
350
|
+
"description": "FastHDR: Shanghai Bund - city night"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
"name": "https://cdn.needle.tools/static/hdris/cayley_interior_2k.pmrem.ktx2",
|
|
354
|
+
"description": "FastHDR: Cayley Interior - indoor ambient"
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
"name": "https://cdn.needle.tools/static/hdris/fireplace_2k.pmrem.ktx2",
|
|
358
|
+
"description": "FastHDR: Fireplace - warm interior"
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
"name": "https://cdn.needle.tools/static/hdris/the_sky_is_on_fire_2k.pmrem.ktx2",
|
|
362
|
+
"description": "FastHDR: The Sky is on Fire - dramatic sunset"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
"name": "https://cdn.needle.tools/static/hdris/dikhololo_night_2k.pmrem.ktx2",
|
|
366
|
+
"description": "FastHDR: Dikhololo Night - night sky"
|
|
367
|
+
}
|
|
368
|
+
],
|
|
236
369
|
"references": [
|
|
237
|
-
{ "name": "Needle Engine reference", "url": "https://engine.needle.tools/docs/reference/needle-engine-attributes.html" }
|
|
370
|
+
{ "name": "Needle Engine reference", "url": "https://engine.needle.tools/docs/reference/needle-engine-attributes.html" },
|
|
371
|
+
{ "name": "FastHDR Library", "url": "https://cloud.needle.tools/hdris" }
|
|
238
372
|
]
|
|
239
373
|
},
|
|
240
374
|
{
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{BufferGeometry as W,Mesh as F,Box3 as ie,Vector3 as C,Sphere as ve,CompressedTexture as Re,Texture as R,Matrix3 as $e,InterleavedBuffer as Ge,InterleavedBufferAttribute as je,BufferAttribute as Ne,TextureLoader as We,Matrix4 as Le,Clock as Fe,MeshStandardMaterial as Ue}from"./three-I__hSXzr.min.js";import{DRACOLoader as ze,KTX2Loader as qe,MeshoptDecoder as Ve,GLTFLoader as ae}from"./three-examples-D8zAE_7t.min.js";const Xe="";globalThis.GLTF_PROGRESSIVE_VERSION=Xe,console.debug("[gltf-progressive] version -");let k="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",U="https://cdn.needle.tools/static/three/0.179.1/basis2/";const Ke=k,He=U,_e=new URL(k+"draco_decoder.js");_e.searchParams.append("range","true"),fetch(_e,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(i=>{console.debug(`Failed to fetch remote Draco decoder from ${k} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),k===Ke&&be("./include/draco/"),U===He&&De("./include/ktx2/")}).finally(()=>{Me()});const Ye=()=>({dracoDecoderPath:k,ktx2TranscoderPath:U});function be(i){k=i,P&&P[ue]!=k?(console.debug("Updating Draco decoder path to "+i),P[ue]=k,P.setDecoderPath(k),P.preload()):console.debug("Setting Draco decoder path to "+i)}function De(i){U=i,E&&E.transcoderPath!=U?(console.debug("Updating KTX2 transcoder path to "+i),E.setTranscoderPath(U),E.init()):console.debug("Setting KTX2 transcoder path to "+i)}function ee(i){return Me(),i?E.detectSupport(i):i!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:P,ktx2Loader:E,meshoptDecoder:te}}function le(i){i.dracoLoader||i.setDRACOLoader(P),i.ktx2Loader||i.setKTX2Loader(E),i.meshoptDecoder||i.setMeshoptDecoder(te)}const ue=Symbol("dracoDecoderPath");let P,te,E;function Me(){P||(P=new ze,P[ue]=k,P.setDecoderPath(k),P.setDecoderConfig({type:"js"}),P.preload()),E||(E=new qe,E.setTranscoderPath(U),E.init()),te||(te=Ve)}const ce=new WeakMap;function de(i,t){let e=ce.get(i);e?e=Object.assign(e,t):e=t,ce.set(i,e)}const Qe=ae.prototype.load;function Je(...i){const t=ce.get(this);let e=i[0];const s=new URL(e,window.location.href);if(s.hostname.endsWith("needle.tools")){const o=t?.progressive!==void 0?t.progressive:!0,r=t?.usecase?t.usecase:"default";o?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${r}`:this.requestHeader.Accept=`*/*;usecase=${r}`,e=s.toString()}return i[0]=e,Qe?.call(this,...i)}ae.prototype.load=Je,z("debugprogressive");function z(i){if(typeof window>"u")return!1;const t=new URL(window.location.href).searchParams.get(i);return t==null||t==="0"||t==="false"?!1:t===""?!0:t}function Ze(i,t){if(t===void 0||i===void 0||t.startsWith("./")||t.startsWith("http")||t.startsWith("data:")||t.startsWith("blob:"))return t;const e=i.lastIndexOf("/");if(e>=0){const s=i.substring(0,e+1);for(;s.endsWith("/")&&t.startsWith("/");)t=t.substring(1);return s+t}return t}function Oe(){return se!==void 0||(se=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),z("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",se)),se}let se;function Se(){if(typeof window>"u")return!1;const i=new URL(window.location.href),t=i.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(i.hostname);return i.hostname==="127.0.0.1"||t}class et{constructor(t=100,e={}){this.maxConcurrent=t,this.debug=e.debug??!1,window.requestAnimationFrame(this.tick)}_running=new Map;_queue=[];debug=!1;tick=()=>{this.internalUpdate(),setTimeout(this.tick,10)};slot(t){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${t}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(e=>{this._queue.push({key:t,resolve:e})})}add(t,e){this._running.has(t)||(this._running.set(t,e),e.finally(()=>{this._running.delete(t),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`))}internalUpdate(){const t=this.maxConcurrent-this._running.size;for(let e=0;e<t&&this._queue.length>0;e++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:s,resolve:o}=this._queue.shift();o({use:r=>this.add(s,r)})}}}const tt=typeof window>"u"&&typeof document>"u",he=Symbol("needle:raycast-mesh");function V(i){return i?.[he]instanceof W?i[he]:null}function st(i,t){if((i.type==="Mesh"||i.type==="SkinnedMesh")&&!V(i)){const e=ot(t);e.userData={isRaycastMesh:!0},i[he]=e}}function rt(i=!0){if(i){if(X)return;const t=X=F.prototype.raycast;F.prototype.raycast=function(e,s){const o=this,r=V(o);let n;r&&o.isMesh&&(n=o.geometry,o.geometry=r),t.call(this,e,s),n&&(o.geometry=n)}}else{if(!X)return;F.prototype.raycast=X,X=null}}let X=null;function ot(i){const t=new W;for(const e in i.attributes)t.setAttribute(e,i.getAttribute(e));return t.setIndex(i.getIndex()),t}const j=new Array,g=z("debugprogressive");let K,q=-1;if(g){let i=function(){q+=1,q>=t&&(q=-1),console.log(`Toggle LOD level [${q}]`)},t=6;window.addEventListener("keyup",e=>{e.key==="p"&&i(),e.key==="w"&&(K=!K,console.log(`Toggle wireframe [${K}]`));const s=parseInt(e.key);!isNaN(s)&&s>=0&&(q=s,console.log(`Set LOD level to [${q}]`))})}function Pe(i){if(g&&K!==void 0)if(Array.isArray(i))for(const t of i)Pe(t);else i&&"wireframe"in i&&(i.wireframe=K===!0)}const H=new Array;let nt=0;const it=Oe()?2:10;function at(i){if(H.length<it){const e=H.length;g&&console.warn(`[Worker] Creating new worker #${e}`);const s=we.createWorker(i||{});return H.push(s),s}const t=nt++%H.length;return H[t]}class we{constructor(t,e){this.worker=t,this._debug=e.debug??!1,t.onmessage=s=>{const o=s.data;switch(this._debug&&console.log("[Worker] EVENT",o),o.type){case"loaded-gltf":for(const r of this._running)if(r.url===o.result.url){lt(o.result),r.resolve(o.result);const n=r.url;n.startsWith("blob:")&&URL.revokeObjectURL(n)}}},t.onerror=s=>{console.error("[Worker] Error in gltf-progressive worker:",s)},t.postMessage({type:"init"})}static async createWorker(t){const e=new Worker(URL.createObjectURL(new Blob([`import '${new URL("./loader.worker-C1GG9A7C.js",import.meta.url).toString()}';`],{type:"text/javascript"})),{type:"module"});return new we(e,t)}_running=[];_webglRenderer=null;async load(t,e){const s=Ye();let o=e?.renderer;o||(this._webglRenderer??=(async()=>{const{WebGLRenderer:l}=await import("./three-I__hSXzr.min.js").then(a=>a.THREE);return new l})(),o=await this._webglRenderer);const r=ee(o).ktx2Loader.workerConfig;t instanceof URL?t=t.toString():t.startsWith("file:")?t=URL.createObjectURL(new Blob([t])):!t.startsWith("blob:")&&!t.startsWith("http:")&&!t.startsWith("https:")&&(t=new URL(t,window.location.href).toString());const n={type:"load",url:t,dracoDecoderPath:s.dracoDecoderPath,ktx2TranscoderPath:s.ktx2TranscoderPath,ktx2LoaderConfig:r};return this._debug&&console.debug("[Worker] Sending load request",n),this.worker.postMessage(n),new Promise(l=>{this._running.push({url:t.toString(),resolve:l})})}_debug=!1}function lt(i){for(const t of i.geometries){const e=t.geometry,s=new W;if(s.name=e.name||"",e.index){const o=e.index;s.setIndex(ge(o))}for(const o in e.attributes){const r=e.attributes[o],n=ge(r);s.setAttribute(o,n)}if(e.morphAttributes)for(const o in e.morphAttributes){const r=e.morphAttributes[o].map(n=>ge(n));s.morphAttributes[o]=r}if(s.morphTargetsRelative=e.morphTargetsRelative??!1,s.boundingBox=new ie,s.boundingBox.min=new C(e.boundingBox?.min.x,e.boundingBox?.min.y,e.boundingBox?.min.z),s.boundingBox.max=new C(e.boundingBox?.max.x,e.boundingBox?.max.y,e.boundingBox?.max.z),s.boundingSphere=new ve(new C(e.boundingSphere?.center.x,e.boundingSphere?.center.y,e.boundingSphere?.center.z),e.boundingSphere?.radius),e.groups)for(const o of e.groups)s.addGroup(o.start,o.count,o.materialIndex);e.userData&&(s.userData=e.userData),t.geometry=s}for(const t of i.textures){const e=t.texture;let s=null;if(e.isCompressedTexture){const o=e.mipmaps,r=e.image?.width||e.source?.data?.width||-1,n=e.image?.height||e.source?.data?.height||-1;s=new Re(o,r,n,e.format,e.type,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.anisotropy,e.colorSpace)}else s=new R(e.image,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),s.mipmaps=e.mipmaps,s.channel=e.channel,s.source.data=e.source.data,s.flipY=e.flipY,s.premultiplyAlpha=e.premultiplyAlpha,s.unpackAlignment=e.unpackAlignment,s.matrix=new $e(...e.matrix.elements);if(!s){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}t.texture=s}return i}function ge(i){let t=i;if("isInterleavedBufferAttribute"in i&&i.isInterleavedBufferAttribute){const e=i.data,s=e.array,o=new Ge(s,e.stride);t=new je(o,i.itemSize,s.byteOffset,i.normalized),t.offset=i.offset}else"isBufferAttribute"in i&&i.isBufferAttribute&&(t=new Ne(i.array,i.itemSize,i.normalized),t.usage=i.usage,t.gpuType=i.gpuType,t.updateRanges=i.updateRanges);return t}const ut=z("gltf-progressive-worker"),ct=z("gltf-progressive-reduce-mipmaps"),fe=Symbol("needle-progressive-texture"),$="NEEDLE_progressive";class m{get name(){return $}static getMeshLODExtension(t){const e=this.getAssignedLODInformation(t);return e?.key?this.lodInfos.get(e.key):null}static getPrimitiveIndex(t){return this.getAssignedLODInformation(t)?.index??-1}static getMaterialMinMaxLODsCount(t,e){const s=this,o="LODS:minmax",r=t[o];if(r!=null)return r;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const l of t)this.getMaterialMinMaxLODsCount(l,e);return t[o]=e,e}if(g==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const l=t;for(const a of Object.keys(l.uniforms)){const u=l.uniforms[a].value;u?.isTexture===!0&&n(u,e)}}else if(t.isMaterial)for(const l of Object.keys(t)){const a=t[l];a?.isTexture===!0&&n(a,e)}else g&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${t.type}`);return t[o]=e,e;function n(l,a){const u=s.getAssignedLODInformation(l);if(u){const y=s.lodInfos.get(u.key);if(y&&y.lods){a.min_count=Math.min(a.min_count,y.lods.length),a.max_count=Math.max(a.max_count,y.lods.length);for(let x=0;x<y.lods.length;x++){const w=y.lods[x];w.width&&(a.lods[x]=a.lods[x]||{min_height:1/0,max_height:0},a.lods[x].min_height=Math.min(a.lods[x].min_height,w.height),a.lods[x].max_height=Math.max(a.lods[x].max_height,w.height))}}}}}static hasLODLevelAvailable(t,e){if(Array.isArray(t)){for(const r of t)if(this.hasLODLevelAvailable(r,e))return!0;return!1}if(t.isMaterial===!0){for(const r of Object.keys(t)){const n=t[r];if(n&&n.isTexture&&this.hasLODLevelAvailable(n,e))return!0}return!1}else if(t.isGroup===!0){for(const r of t.children)if(r.isMesh===!0&&this.hasLODLevelAvailable(r,e))return!0}let s,o;if(t.isMesh?s=t.geometry:(t.isBufferGeometry||t.isTexture)&&(s=t),s&&s?.userData?.LODS){const r=s.userData.LODS;if(o=this.lodInfos.get(r.key),e===void 0)return o!=null;if(o)return Array.isArray(o.lods)?e<o.lods.length:e===0}return!1}static assignMeshLOD(t,e){if(!t)return Promise.resolve(null);if(t instanceof F||t.isMesh===!0){const s=t.geometry,o=this.getAssignedLODInformation(s);if(!o)return Promise.resolve(null);for(const r of j)r.onBeforeGetLODMesh?.(t,e);return t["LOD:requested level"]=e,m.getOrLoadLOD(s,e).then(r=>{if(Array.isArray(r)){const n=o.index||0;r=r[n]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],r&&s!=r&&(r?.isBufferGeometry?t.geometry=r:g&&console.error("Invalid LOD geometry",r))),r}).catch(r=>(console.error("Error loading mesh LOD",t,r),null))}else g&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const s=t;if(Array.isArray(s.material)){const o=new Array;for(const r of s.material){const n=this.assignTextureLOD(r,e);o.push(n)}return Promise.all(o).then(r=>{const n=new Array;for(const l of r)Array.isArray(l)&&n.push(...l);return n})}else return this.assignTextureLOD(s.material,e)}if(t.isMaterial===!0){const s=t,o=[],r=new Array;if(s.uniforms&&(s.isRawShaderMaterial||s.isShaderMaterial===!0)){const n=s;for(const l of Object.keys(n.uniforms)){const a=n.uniforms[l].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,s,l).then(y=>(y&&n.uniforms[l].value!=y&&(n.uniforms[l].value=y,n.uniformsNeedUpdate=!0),y));o.push(u),r.push(l)}}}else for(const n of Object.keys(s)){const l=s[n];if(l?.isTexture===!0){const a=this.assignTextureLODForSlot(l,e,s,n);o.push(a),r.push(n)}}return Promise.all(o).then(n=>{const l=new Array;for(let a=0;a<n.length;a++){const u=n[a],y=r[a];u&&u.isTexture===!0?l.push({material:s,slot:y,texture:u,level:e}):l.push({material:s,slot:y,texture:null,level:e})}return l})}if(t instanceof R||t.isTexture===!0){const s=t;return this.assignTextureLODForSlot(s,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,s,o){return t?.isTexture!==!0?Promise.resolve(null):o==="glyphMap"?Promise.resolve(t):m.getOrLoadLOD(t,e).then(r=>{if(Array.isArray(r))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if(r?.isTexture===!0){if(r!=t&&s&&o){const n=s[o];if(n&&!g){const l=this.getAssignedLODInformation(n);if(l&&l?.level<e)return g==="verbose"&&console.warn("Assigned texture level is already higher: ",l.level,e,s,n,r),null}if(ct&&r.mipmaps){const l=r.mipmaps.length;r.mipmaps.length=Math.min(r.mipmaps.length,3),l!==r.mipmaps.length&&g&&console.debug(`Reduced mipmap count from ${l} to ${r.mipmaps.length} for ${r.uuid}: ${r.image?.width}x${r.image?.height}.`)}s[o]=r}return r}else g=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(r=>(console.error("Error loading LOD",t,r),null))}parser;url;constructor(t){const e=t.options.path;g&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}_isLoadingMesh;loadMesh=t=>{if(this._isLoadingMesh)return null;const e=this.parser.json.meshes[t]?.extensions?.[$];return e?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",t).then(s=>(this._isLoadingMesh=!1,s&&m.registerMesh(this.url,e.guid,s,e.lods?.length,0,e),s))):null};afterRoot(t){return g&&console.log("AFTER",this.url,t),this.parser.json.textures?.forEach((e,s)=>{if(e?.extensions){const o=e?.extensions[$];if(o){if(!o.lods){g&&console.warn("Texture has no LODs",o);return}let r=!1;for(const n of this.parser.associations.keys())n.isTexture===!0&&this.parser.associations.get(n)?.textures===s&&(r=!0,m.registerTexture(this.url,n,o.lods?.length,s,o));r||this.parser.getDependency("texture",s).then(n=>{n&&m.registerTexture(this.url,n,o.lods?.length,s,o)})}}}),this.parser.json.meshes?.forEach((e,s)=>{if(e?.extensions){const o=e?.extensions[$];if(o&&o.lods){for(const r of this.parser.associations.keys())if(r.isMesh){const n=this.parser.associations.get(r);n?.meshes===s&&m.registerMesh(this.url,o.guid,r,o.lods.length,n.primitives,o)}}}}),null}static registerTexture=(t,e,s,o,r)=>{if(!e){g&&console.error("!! gltf-progressive: Called register texture without texture");return}if(g){const l=e.image?.width||e.source?.data?.width||0,a=e.image?.height||e.source?.data?.height||0;console.log(`> gltf-progressive: register texture[${o}] "${e.name||e.uuid}", Current: ${l}x${a}, Max: ${r.lods[0]?.width}x${r.lods[0]?.height}, uuid: ${e.uuid}`,r,e)}e.source&&(e.source[fe]=r);const n=r.guid;m.assignLODInformation(t,e,n,s,o),m.lodInfos.set(n,r),m.lowresCache.set(n,new WeakRef(e))};static registerMesh=(t,e,s,o,r,n)=>{const l=s.geometry;if(!l){g&&console.warn("gltf-progressive: Register mesh without geometry");return}l.userData||(l.userData={}),g&&console.log("> Progressive: register mesh "+s.name,{index:r,uuid:s.uuid},n,s),m.assignLODInformation(t,l,e,o,r),m.lodInfos.set(e,n);let a=m.lowresCache.get(e)?.deref();a?a.push(s.geometry):a=[s.geometry],m.lowresCache.set(e,new WeakRef(a)),o>0&&!V(s)&&st(s,l);for(const u of j)u.onRegisteredNewMesh?.(s,n)};static dispose(t){if(t){this.lodInfos.delete(t);const e=this.lowresCache.get(t);if(e){const s=e.deref();if(s){if(s.isTexture)s.dispose();else if(Array.isArray(s))for(const o of s)o.dispose()}this.lowresCache.delete(t)}for(const[s,o]of this.cache)s.includes(t)&&(this._disposeCacheEntry(o),this.cache.delete(s))}else{this.lodInfos.clear();for(const[,e]of this.lowresCache){const s=e.deref();if(s){if(s.isTexture)s.dispose();else if(Array.isArray(s))for(const o of s)o.dispose()}}this.lowresCache.clear();for(const[,e]of this.cache)this._disposeCacheEntry(e);this.cache.clear()}}static _disposeCacheEntry(t){t instanceof WeakRef?t.deref()?.dispose():t.then(e=>{if(e)if(Array.isArray(e))for(const s of e)s.dispose();else e.dispose()}).catch(()=>{})}static lodInfos=new Map;static cache=new Map;static lowresCache=new Map;static _resourceRegistry=new FinalizationRegistry(t=>{const e=m.cache.get(t);g&&console.debug(`[gltf-progressive] Resource GC'd
|
|
2
|
+
${t}`),e instanceof WeakRef&&(e.deref()||(m.cache.delete(t),g&&console.log(`[gltf-progressive] Cache entry auto-cleaned (GC'd): ${t}`)))});static workers=[];static _workersIndex=0;static async getOrLoadLOD(t,e){const s=g=="verbose",o=this.getAssignedLODInformation(t);if(!o)return g&&console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`,t),null;const r=o?.key;let n;if(t.isTexture===!0){const l=t;l.source&&l.source[fe]&&(n=l.source[fe])}if(n||(n=m.lodInfos.get(r)),!n)g&&console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`,t.type,m.lodInfos);else{if(e>0){let u=!1;const y=Array.isArray(n.lods);if(y&&e>=n.lods.length?u=!0:y||(u=!0),u){const x=this.lowresCache.get(r);if(x){const w=x.deref();if(w)return w;this.lowresCache.delete(r),g&&console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${r}`)}return null}}const l=Array.isArray(n.lods)?n.lods[e]?.path:n.lods;if(!l)return g&&!n["missing:uri"]&&(n["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,n)),null;const a=Ze(o.url,l);if(a.endsWith(".glb")||a.endsWith(".gltf")){if(!n.guid)return console.warn("missing pointer for glb/gltf texture",n),null;const u=a+"_"+n.guid,y=await this.queue.slot(a),x=this.cache.get(u);if(x!==void 0)if(s&&console.log(`LOD ${e} was already loading/loaded: ${u}`),x instanceof WeakRef){const c=x.deref();if(c){let p=c,v=!1;if(p instanceof R&&t instanceof R?p.image?.data||p.source?.data?p=this.copySettings(t,p):v=!0:p instanceof W&&t instanceof W&&(p.attributes.position?.array||(v=!0)),!v)return p}this.cache.delete(u),g&&console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${u}`)}else{let c=await x.catch(v=>(console.error(`Error loading LOD ${e} from ${a}
|
|
3
|
+
`,v),null)),p=!1;if(c==null||(c instanceof R&&t instanceof R?c.image?.data||c.source?.data?c=this.copySettings(t,c):(p=!0,this.cache.delete(u)):c instanceof W&&t instanceof W&&(c.attributes.position?.array||(p=!0,this.cache.delete(u)))),!p)return c}if(!y.use)return g&&console.log(`LOD ${e} was aborted: ${a}`),null;const w=n,T=new Promise(async(c,p)=>{if(ut){const h=await(await at({})).load(a);if(h.textures.length>0)for(const d of h.textures){let f=d.texture;return m.assignLODInformation(o.url,f,r,e,void 0),t instanceof R&&(f=this.copySettings(t,f)),f&&(f.guid=w.guid),c(f)}if(h.geometries.length>0){const d=new Array;for(const f of h.geometries){const L=f.geometry;m.assignLODInformation(o.url,L,r,e,f.primitiveIndex),d.push(L)}return c(d)}return c(null)}const v=new ae;le(v),g&&(await new Promise(h=>setTimeout(h,1e3)),s&&console.warn("Start loading (delayed) "+a,w.guid));let A=a;if(w&&Array.isArray(w.lods)){const h=w.lods[e];h.hash&&(A+="?v="+h.hash)}const b=await v.loadAsync(A).catch(h=>(console.error(`Error loading LOD ${e} from ${a}
|
|
4
|
+
`,h),c(null)));if(!b)return c(null);const B=b.parser;s&&console.log("Loading finished "+a,w.guid);let D=0;if(b.parser.json.textures){let h=!1;for(const d of b.parser.json.textures){if(d?.extensions){const f=d?.extensions[$];if(f?.guid&&f.guid===w.guid){h=!0;break}}D++}if(h){let d=await B.getDependency("texture",D);return d&&m.assignLODInformation(o.url,d,r,e,void 0),s&&console.log('change "'+t.name+'" \u2192 "'+d.name+'"',a,D,d,u),t instanceof R&&(d=this.copySettings(t,d)),d&&(d.guid=w.guid),c(d)}else g&&console.warn("Could not find texture with guid",w.guid,b.parser.json)}if(D=0,b.parser.json.meshes){let h=!1;for(const d of b.parser.json.meshes){if(d?.extensions){const f=d?.extensions[$];if(f?.guid&&f.guid===w.guid){h=!0;break}}D++}if(h){const d=await B.getDependency("mesh",D);if(s&&console.log(`Loaded Mesh "${d.name}"`,a,D,d,u),d.isMesh===!0){const f=d.geometry;return m.assignLODInformation(o.url,f,r,e,0),c(f)}else{const f=new Array;for(let L=0;L<d.children.length;L++){const S=d.children[L];if(S.isMesh===!0){const G=S.geometry;m.assignLODInformation(o.url,G,r,e,L),f.push(G)}}return c(f)}}else g&&console.warn("Could not find mesh with guid",w.guid,b.parser.json)}return c(null)});this.cache.set(u,T),y.use(T);const _=await T;return _!=null?_ instanceof R?(this.cache.set(u,new WeakRef(_)),m._resourceRegistry.register(_,u)):Array.isArray(_)?this.cache.set(u,Promise.resolve(_)):this.cache.set(u,Promise.resolve(_)):this.cache.set(u,Promise.resolve(null)),_}else if(t instanceof R){s&&console.log("Load texture from uri: "+a);const u=await new We().loadAsync(a);return u?(u.guid=n.guid,u.flipY=!1,u.needsUpdate=!0,u.colorSpace=t.colorSpace,s&&console.log(n,u)):g&&console.warn("failed loading",a),u}}return null}static maxConcurrent=50;static queue=new et(m.maxConcurrent,{debug:g!=!1});static assignLODInformation(t,e,s,o,r){if(!e)return;e.userData||(e.userData={});const n=new dt(t,s,o,r);e.userData.LODS=n,"source"in e&&typeof e.source=="object"&&(e.source.LODS=n)}static getAssignedLODInformation(t){return t?t.userData?.LODS?t.userData.LODS:"source"in t&&t.source?.LODS?t.source.LODS:null:null}static copySettings(t,e){return e?(g==="verbose"&&console.debug(`Copy texture settings
|
|
5
|
+
`,t.uuid,`
|
|
6
|
+
`,e.uuid),e=e.clone(),e.offset=t.offset,e.repeat=t.repeat,e.colorSpace=t.colorSpace,e.magFilter=t.magFilter,e.minFilter=t.minFilter,e.wrapS=t.wrapS,e.wrapT=t.wrapT,e.flipY=t.flipY,e.anisotropy=t.anisotropy,e.mipmaps||(e.generateMipmaps=t.generateMipmaps),e):t}}class dt{url;key;level;index;constructor(t,e,s,o){this.url=t,this.key=e,this.level=s,o!=null&&(this.index=o)}}class me{static addPromise=(t,e,s,o)=>{o.forEach(r=>{r.add(t,e,s)})};ready;get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}_resolve;_signal;_frame_start;_frames_to_capture;_resolved=!1;_addedCount=0;_resolvedCount=0;_awaiting=[];_maxPromisesPerObject=1;constructor(t,e){const s=Math.max(e.frames??2,2);this._frame_start=e.waitForFirstCapture?void 0:t,this._frames_to_capture=s,this.ready=new Promise(o=>{this._resolve=o}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=e.signal,this._signal?.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,e.maxPromisesPerObject??1)}_currentFrame=0;update(t){this._currentFrame=t,this._frame_start===void 0&&this._addedCount>0&&(this._frame_start=t),(this._signal?.aborted||this._awaiting.length===0&&this._frame_start!==void 0&&t>this._frame_start+this._frames_to_capture)&&this.resolveNow()}_seen=new WeakMap;add(t,e,s){if(this._resolved){g&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._frame_start!==void 0&&this._currentFrame>this._frame_start+this._frames_to_capture)){if(this._maxPromisesPerObject>=1)if(this._seen.has(e)){let o=this._seen.get(e);if(o>=this._maxPromisesPerObject){g&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(e,o+1)}else this._seen.set(e,1);this._awaiting.push(s),this._addedCount++,s.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(s),1)})}}resolveNow(){this._resolved||this._resolve?.({awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:this._signal?.aborted??!1})}}const I=z("debugprogressive"),ht=z("noprogressive"),pe=Symbol("Needle:LODSManager"),xe=Symbol("Needle:LODState"),N=Symbol("Needle:CurrentLOD"),O={mesh_lod:-1,texture_lod:-1};let Y=class M{static debugDrawLine;static getObjectLODState(t){return t[xe]}static addPlugin(t){j.push(t)}static removePlugin(t){const e=j.indexOf(t);e>=0&&j.splice(e,1)}static get(t,e){if(t[pe])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[pe];const s=new M(t,{engine:"unknown",...e});return t[pe]=s,s}renderer;context;projectionScreenMatrix=new Le;get plugins(){return j}overrideLodLevel=void 0;targetTriangleDensity=2e5;skinnedMeshAutoUpdateBoundsInterval=30;updateInterval="auto";#e=1;pause=!1;manual=!1;_newPromiseGroups=[];_promiseGroupIds=0;awaitLoading(t){const e=this._promiseGroupIds++,s=new me(this.#r,{...t});this._newPromiseGroups.push(s);const o=performance.now();return s.ready.finally(()=>{const r=this._newPromiseGroups.indexOf(s);r>=0&&(this._newPromiseGroups.splice(r,1),Se()&&performance.measure("LODsManager:awaitLoading",{start:o,detail:{id:e,name:t?.name,awaited:s.awaitedCount,resolved:s.resolvedCount}}))}),s.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let t=this._newPromiseGroups.length-1;t>=0;t--)this._newPromiseGroups[t].update(this.#r)}_lodchangedlisteners=[];addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const s=this._lodchangedlisteners.indexOf(e);s>=0&&this._lodchangedlisteners.splice(s,1)}}constructor(t,e){this.renderer=t,this.context={...e}}#t;#n=new Fe;#r=0;#o=0;#i=0;#s=0;_fpsBuffer=[60,60,60,60,60];enable(){if(this.#t)return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;this.#t=this.renderer.render;const e=this;ee(this.renderer),this.renderer.render=function(s,o){const r=e.renderer.getRenderTarget();(r==null||"isXRRenderTarget"in r&&r.isXRRenderTarget)&&(t=0,e.#r+=1,e.#o=e.#n.getDelta(),e.#i+=e.#o,e._fpsBuffer.shift(),e._fpsBuffer.push(1/e.#o),e.#s=e._fpsBuffer.reduce((l,a)=>l+a)/e._fpsBuffer.length,I&&e.#r%200===0&&console.log("FPS",Math.round(e.#s),"Interval:",e.#e));const n=t++;e.#t.call(this,s,o),e.onAfterRender(s,o,n)}}disable(){this.#t&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=this.#t,this.#t=void 0)}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,s){if(this.pause)return;const o=this.renderer.renderLists.get(t,0).opaque;let r=!0;if(o.length===1){const n=o[0].material;(n.name==="EffectMaterial"||n.name==="CopyShader")&&(r=!1)}if((e.parent&&e.parent.type==="CubeCamera"||s>=1&&e.type==="OrthographicCamera")&&(r=!1),r){if(ht||(this.updateInterval==="auto"?this.#s<40&&this.#e<10?(this.#e+=1,I&&console.warn("\u2193 Reducing LOD updates",this.#e,this.#s.toFixed(0))):this.#s>=60&&this.#e>1&&(this.#e-=1,I&&console.warn("\u2191 Increasing LOD updates",this.#e,this.#s.toFixed(0))):this.#e=this.updateInterval,this.#e>0&&this.#r%this.#e!=0))return;this.internalUpdate(t,e),this._postprocessPromiseGroups()}}internalUpdate(t,e){const s=this.renderer.renderLists.get(t,0),o=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const r=this.targetTriangleDensity;for(const a of o){if(a.material&&(a.geometry?.type==="BoxGeometry"||a.geometry?.type==="BufferGeometry")&&(a.material.name==="SphericalGaussianBlur"||a.material.name=="BackgroundCubeMaterial"||a.material.name==="CubemapFromEquirect"||a.material.name==="EquirectangularToCubeUV")){I&&(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",a,a.material.name,a.material.type)));continue}switch(a.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(I==="color"&&a.material&&!a.object.progressive_debug_color){a.object.progressive_debug_color=!0;const y=Math.random()*16777215,x=new Ue({color:y});a.object.material=x}const u=a.object;(u instanceof F||u.isMesh)&&this.updateLODs(t,e,u,r)}const n=s.transparent;for(const a of n){const u=a.object;(u instanceof F||u.isMesh)&&this.updateLODs(t,e,u,r)}const l=s.transmissive;for(const a of l){const u=a.object;(u instanceof F||u.isMesh)&&this.updateLODs(t,e,u,r)}}updateLODs(t,e,s,o){s.userData||(s.userData={});let r=s[xe];if(r||(r=new gt,s[xe]=r),r.frames++<2)return;for(const l of j)l.onBeforeUpdateLOD?.(this.renderer,t,e,s);const n=this.overrideLodLevel!==void 0?this.overrideLodLevel:q;n>=0?(O.mesh_lod=n,O.texture_lod=n):(this.calculateLodLevel(e,s,r,o,O),O.mesh_lod=Math.round(O.mesh_lod),O.texture_lod=Math.round(O.texture_lod)),O.mesh_lod>=0&&this.loadProgressiveMeshes(s,O.mesh_lod),s.material&&O.texture_lod>=0&&this.loadProgressiveTextures(s.material,O.texture_lod,n),g&&s.material&&!s.isGizmo&&Pe(s.material);for(const l of j)l.onAfterUpdatedLOD?.(this.renderer,t,e,s,O);r.lastLodLevel_Mesh=O.mesh_lod,r.lastLodLevel_Texture=O.texture_lod}loadProgressiveTextures(t,e,s){if(!t)return;if(Array.isArray(t)){for(const r of t)this.loadProgressiveTextures(r,e);return}let o=!1;if((t[N]===void 0||e<t[N])&&(o=!0),s!==void 0&&s>=0&&(o=t[N]!=s,e=s),o){t[N]=e;const r=m.assignTextureLOD(t,e).then(n=>{this._lodchangedlisteners.forEach(l=>l({type:"texture",level:e,object:t}))});me.addPromise("texture",t,r,this._newPromiseGroups)}}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);let s=t[N]!==e;const o=t["DEBUG:LOD"];if(o!=null&&(s=t[N]!=o,e=o),s){t[N]=e;const r=t.geometry,n=m.assignMeshLOD(t,e).then(l=>(l&&t[N]==e&&r!=t.geometry&&this._lodchangedlisteners.forEach(a=>a({type:"mesh",level:e,object:t})),l));return me.addPromise("mesh",t,n,this._newPromiseGroups),n}return Promise.resolve(null)}_sphere=new ve;_tempBox=new ie;_tempBox2=new ie;tempMatrix=new Le;_tempWorldPosition=new C;_tempBoxSize=new C;_tempBox2Size=new C;static corner0=new C;static corner1=new C;static corner2=new C;static corner3=new C;static _tempPtInside=new C;static isInside(t,e){const s=t.min,o=t.max,r=(s.x+o.x)*.5,n=(s.y+o.y)*.5;return this._tempPtInside.set(r,n,s.z).applyMatrix4(e).z<0}static skinnedMeshBoundsFrameOffsetCounter=0;static $skinnedMeshBoundsOffset=Symbol("gltf-progressive-skinnedMeshBoundsOffset");calculateLodLevel(t,e,s,o,r){if(!e){r.mesh_lod=-1,r.texture_lod=-1;return}if(!t){r.mesh_lod=-1,r.texture_lod=-1;return}let n=10+1,l=!1;if(I&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const a=m.getMeshLODExtension(e.geometry)?.lods,u=m.getPrimitiveIndex(e.geometry),y=a&&a.length>0,x=m.getMaterialMinMaxLODsCount(e.material),w=x.min_count!==1/0&&x.min_count>=0&&x.max_count>=0;if(!y&&!w){r.mesh_lod=0,r.texture_lod=0;return}y||(l=!0,n=0);const T=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let _=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const c=e;if(!c.boundingBox)c.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!c[M.$skinnedMeshBoundsOffset]){const v=M.skinnedMeshBoundsFrameOffsetCounter++;c[M.$skinnedMeshBoundsOffset]=v}const p=c[M.$skinnedMeshBoundsOffset];if((s.frames+p)%this.skinnedMeshAutoUpdateBoundsInterval===0){const v=V(c),A=c.geometry;v&&(c.geometry=v),c.computeBoundingBox(),c.geometry=A}}_=c.boundingBox}if(_){const c=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const h=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(h)){r.mesh_lod=0,r.texture_lod=0;return}}if(this._tempBox.copy(_),this._tempBox.applyMatrix4(e.matrixWorld),c.isPerspectiveCamera&&M.isInside(this._tempBox,this.projectionScreenMatrix)){r.mesh_lod=0,r.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&c.isPerspectiveCamera&&c.fov>70){const h=this._tempBox.min,d=this._tempBox.max;let f=h.x,L=h.y,S=d.x,G=d.y;const Q=2,oe=1.5,J=(h.x+d.x)*.5,Z=(h.y+d.y)*.5;f=(f-J)*Q+J,L=(L-Z)*Q+Z,S=(S-J)*Q+J,G=(G-Z)*Q+Z;const Ie=f<0&&S>0?0:Math.min(Math.abs(h.x),Math.abs(d.x)),Be=L<0&&G>0?0:Math.min(Math.abs(h.y),Math.abs(d.y)),ne=Math.max(Ie,Be);s.lastCentrality=(oe-ne)*(oe-ne)*(oe-ne)}else s.lastCentrality=1;const p=this._tempBox.getSize(this._tempBoxSize);p.multiplyScalar(.5),screen.availHeight>0&&T>0&&p.multiplyScalar(T/screen.availHeight),t.isPerspectiveCamera?p.x*=t.aspect:t.isOrthographicCamera;const v=t.matrixWorldInverse,A=this._tempBox2;A.copy(_),A.applyMatrix4(e.matrixWorld),A.applyMatrix4(v);const b=A.getSize(this._tempBox2Size),B=Math.max(b.x,b.y);if(Math.max(p.x,p.y)!=0&&B!=0&&(p.z=b.z/Math.max(b.x,b.y)*Math.max(p.x,p.y)),s.lastScreenCoverage=Math.max(p.x,p.y,p.z),s.lastScreenspaceVolume.copy(p),s.lastScreenCoverage*=s.lastCentrality,I&&M.debugDrawLine){const h=this.tempMatrix.copy(this.projectionScreenMatrix);h.invert();const d=M.corner0,f=M.corner1,L=M.corner2,S=M.corner3;d.copy(this._tempBox.min),f.copy(this._tempBox.max),f.x=d.x,L.copy(this._tempBox.max),L.y=d.y,S.copy(this._tempBox.max);const G=(d.z+S.z)*.5;d.z=f.z=L.z=S.z=G,d.applyMatrix4(h),f.applyMatrix4(h),L.applyMatrix4(h),S.applyMatrix4(h),M.debugDrawLine(d,f,255),M.debugDrawLine(d,L,255),M.debugDrawLine(f,S,255),M.debugDrawLine(L,S,255)}let D=999;if(a&&s.lastScreenCoverage>0)for(let h=0;h<a.length;h++){const d=a[h],f=(d.densities?.[u]||d.density||1e-5)/s.lastScreenCoverage;if(u>0&&Se()&&!d.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),f<o){D=h;break}}D<n&&(n=D,l=!0)}if(l?r.mesh_lod=n:r.mesh_lod=s.lastLodLevel_Mesh,I&&r.mesh_lod!=s.lastLodLevel_Mesh){const c=a?.[r.mesh_lod];c&&console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} \u2192 ${r.mesh_lod} (density: ${c.densities?.[u].toFixed(0)}) | ${e.name}`)}if(w){const c="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(s.lastLodLevel_Texture<0){if(r.texture_lod=x.max_count-1,I){const p=x.lods[x.max_count-1];I&&console.log(`First Texture LOD ${r.texture_lod} (${p.max_height}px) - ${e.name}`)}}else{const p=s.lastScreenspaceVolume.x+s.lastScreenspaceVolume.y+s.lastScreenspaceVolume.z;let v=s.lastScreenCoverage*4;this.context?.engine==="model-viewer"&&(v*=1.5);const A=T/window.devicePixelRatio*v;let b=!1;for(let B=x.lods.length-1;B>=0;B--){const D=x.lods[B];if(!(c&&D.max_height>=2048)&&!(Oe()&&D.max_height>4096)&&(D.max_height>A||!b&&B===0)){if(b=!0,r.texture_lod=B,I&&r.texture_lod<s.lastLodLevel_Texture){const h=D.max_height;console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} \u2192 ${r.texture_lod} = ${h}px
|
|
7
|
+
Screensize: ${A.toFixed(0)}px, Coverage: ${(100*s.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
|
|
8
|
+
${e.name}`)}break}}}}else r.texture_lod=0}};class gt{frames=0;lastLodLevel_Mesh=-1;lastLodLevel_Texture=-1;lastScreenCoverage=0;lastScreenspaceVolume=new C;lastCentrality=0}const Te=Symbol("NEEDLE_mesh_lod"),re=Symbol("NEEDLE_texture_lod");let ye=null;function Ae(){const i=ft();i&&(i.mapURLs(function(t){return Ce(),t}),Ce(),ye?.disconnect(),ye=new MutationObserver(t=>{t.forEach(e=>{e.addedNodes.forEach(s=>{s instanceof HTMLElement&&s.tagName.toLowerCase()==="model-viewer"&&Ee(s)})})}),ye.observe(document,{childList:!0,subtree:!0}))}function ft(){return typeof customElements>"u"?null:customElements.get("model-viewer")||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Ae()}),null)}function Ce(){typeof document>"u"||document.querySelectorAll("model-viewer").forEach(i=>{Ee(i)})}const ke=new WeakSet;let mt=0;function Ee(i){if(!i||ke.has(i))return null;ke.add(i),console.debug("[gltf-progressive] found new model-viewer..."+ ++mt+`
|
|
9
|
+
`,i.getAttribute("src"));let t=null,e=null,s=null;for(let o=i;o!=null;o=Object.getPrototypeOf(o)){const r=Object.getOwnPropertySymbols(o),n=r.find(u=>u.toString()=="Symbol(renderer)"),l=r.find(u=>u.toString()=="Symbol(scene)"),a=r.find(u=>u.toString()=="Symbol(needsRender)");!t&&n!=null&&(t=i[n].threeRenderer),!e&&l!=null&&(e=i[l]),!s&&a!=null&&(s=i[a])}if(t&&e){let o=function(){if(s){let n=0,l=setInterval(()=>{if(n++>5){clearInterval(l);return}s?.call(i)},300)}};console.debug("[gltf-progressive] setup model-viewer");const r=Y.get(t,{engine:"model-viewer"});return Y.addPlugin(new pt),r.enable(),r.addEventListener("changed",()=>{s?.call(i)}),i.addEventListener("model-visibility",n=>{n.detail.visible&&s?.call(i)}),i.addEventListener("load",()=>{o()}),()=>{r.disable()}}return null}class pt{_didWarnAboutMissingUrl=!1;onBeforeUpdateLOD(t,e,s,o){this.tryParseMeshLOD(e,o),this.tryParseTextureLOD(e,o)}getUrl(t){if(!t)return null;let e=t.getAttribute("src");return e||(e=t.src),e||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",t),this._didWarnAboutMissingUrl=!0),e}tryGetCurrentGLTF(t){return t._currentGLTF}tryGetCurrentModelViewer(t){return t.element}tryParseTextureLOD(t,e){if(e[re]==!0)return;e[re]=!0;const s=this.tryGetCurrentGLTF(t),o=this.tryGetCurrentModelViewer(t),r=this.getUrl(o);if(r&&s&&e.material){let n=function(a){if(a[re]==!0)return;a[re]=!0,a.userData&&(a.userData.LOD=-1);const u=Object.keys(a);for(let y=0;y<u.length;y++){const x=u[y],w=a[x];if(w?.isTexture===!0){const T=w.userData?.associations?.textures;if(T==null)continue;const _=s.parser.json.textures[T];if(!_){console.warn("Texture data not found for texture index "+T);continue}if(_?.extensions?.[$]){const c=_.extensions[$];c&&r&&m.registerTexture(r,w,c.lods.length,T,c)}}}};const l=e.material;if(Array.isArray(l))for(const a of l)n(a);else n(l)}}tryParseMeshLOD(t,e){if(e[Te]==!0)return;e[Te]=!0;const s=this.tryGetCurrentModelViewer(t),o=this.getUrl(s);if(!o)return;const r=e.userData?.gltfExtensions?.[$];if(r&&o){const n=e.uuid;m.registerMesh(o,n,e,0,r.lods.length,r)}}}function xt(...i){let t,e,s,o;switch(i.length){case 2:[s,e]=i,o={};break;case 3:[s,e,o]=i;break;case 4:[t,e,s,o]=i;break;default:throw new Error("Invalid arguments")}ee(e),le(s),de(s,{progressive:!0,...o?.hints}),s.register(n=>new m(n));const r=Y.get(e);return o?.enableLODsManager!==!1&&r.enable(),r}if(Ae(),!tt){const i={gltfProgressive:{useNeedleProgressive:xt,LODsManager:Y,configureLoader:de,getRaycastMesh:V,useRaycastMeshes:rt}};if(!globalThis.Needle)globalThis.Needle=i;else for(const t in i)globalThis.Needle[t]=i[t]}export{Y as LODsManager,m as NEEDLE_progressive,le as addDracoAndKTX2Loaders,de as configureLoader,ee as createLoaders,V as getRaycastMesh,be as setDracoDecoderLocation,De as setKTX2TranscoderLocation};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";const c=require("./three-BW2s1Yl-.umd.cjs"),N=require("./three-examples-Bpfu6ke_.umd.cjs");var ae=typeof document<"u"?document.currentScript:null;const Re="";globalThis.GLTF_PROGRESSIVE_VERSION=Re;console.debug("[gltf-progressive] version -");let R="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",E="https://cdn.needle.tools/static/three/0.179.1/basis2/";const Be=R,$e=E,De=new URL(R+"draco_decoder.js");De.searchParams.append("range","true");fetch(De,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(i=>{console.debug(`Failed to fetch remote Draco decoder from ${R} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),R===Be&&be("./include/draco/"),E===$e&&Oe("./include/ktx2/")}).finally(()=>{Se()});const Ge=()=>({dracoDecoderPath:R,ktx2TranscoderPath:E});function be(i){R=i,C&&C[ge]!=R?(console.debug("Updating Draco decoder path to "+i),C[ge]=R,C.setDecoderPath(R),C.preload()):console.debug("Setting Draco decoder path to "+i)}function Oe(i){E=i,B&&B.transcoderPath!=E?(console.debug("Updating KTX2 transcoder path to "+i),B.setTranscoderPath(E),B.init()):console.debug("Setting KTX2 transcoder path to "+i)}function ne(i){return Se(),i?B.detectSupport(i):i!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:C,ktx2Loader:B,meshoptDecoder:re}}function ye(i){i.dracoLoader||i.setDRACOLoader(C),i.ktx2Loader||i.setKTX2Loader(B),i.meshoptDecoder||i.setMeshoptDecoder(re)}const ge=Symbol("dracoDecoderPath");let C,re,B;function Se(){C||(C=new N.DRACOLoader,C[ge]=R,C.setDecoderPath(R),C.setDecoderConfig({type:"js"}),C.preload()),B||(B=new N.KTX2Loader,B.setTranscoderPath(E),B.init()),re||(re=N.MeshoptDecoder)}const pe=new WeakMap;function xe(i,t){let e=pe.get(i);e?e=Object.assign(e,t):e=t,pe.set(i,e)}const Fe=N.GLTFLoader.prototype.load;function We(...i){const t=pe.get(this);let e=i[0];const s=new URL(e,window.location.href);if(s.hostname.endsWith("needle.tools")){const r=t?.progressive!==void 0?t.progressive:!0,o=t?.usecase?t.usecase:"default";r?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,e=s.toString()}return i[0]=e,Fe?.call(this,...i)}N.GLTFLoader.prototype.load=We;q("debugprogressive");function q(i){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(i);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ue(i,t){if(t===void 0||i===void 0||t.startsWith("./")||t.startsWith("http")||t.startsWith("data:")||t.startsWith("blob:"))return t;const e=i.lastIndexOf("/");if(e>=0){const s=i.substring(0,e+1);for(;s.endsWith("/")&&t.startsWith("/");)t=t.substring(1);return s+t}return t}function Te(){return K!==void 0||(K=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),q("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",K)),K}let K;function Le(){if(typeof window>"u")return!1;const i=new URL(window.location.href),t=i.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(i.hostname);return i.hostname==="127.0.0.1"||t}class ze{constructor(t=100,e={}){this.maxConcurrent=t,this.debug=e.debug??!1,window.requestAnimationFrame(this.tick)}_running=new Map;_queue=[];debug=!1;tick=()=>{this.internalUpdate(),setTimeout(this.tick,10)};slot(t){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${t}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(e=>{this._queue.push({key:t,resolve:e})})}add(t,e){this._running.has(t)||(this._running.set(t,e),e.finally(()=>{this._running.delete(t),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`))}internalUpdate(){const t=this.maxConcurrent-this._running.size;for(let e=0;e<t&&this._queue.length>0;e++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:s,resolve:n}=this._queue.shift();n({use:r=>this.add(s,r)})}}}const Ve=typeof window>"u"&&typeof document>"u",me=Symbol("needle:raycast-mesh");function X(i){return i?.[me]instanceof c.BufferGeometry?i[me]:null}function Ee(i,t){if((i.type==="Mesh"||i.type==="SkinnedMesh")&&!X(i)){const s=Ne(t);s.userData={isRaycastMesh:!0},i[me]=s}}function qe(i=!0){if(i){if(Y)return;const t=Y=c.Mesh.prototype.raycast;c.Mesh.prototype.raycast=function(e,s){const n=this,r=X(n);let o;r&&n.isMesh&&(o=n.geometry,n.geometry=r),t.call(this,e,s),o&&(n.geometry=o)}}else{if(!Y)return;c.Mesh.prototype.raycast=Y,Y=null}}let Y=null;function Ne(i){const t=new c.BufferGeometry;for(const e in i.attributes)t.setAttribute(e,i.getAttribute(e));return t.setIndex(i.getIndex()),t}const U=new Array,g=q("debugprogressive");let Q,V=-1;if(g){let i=function(){V+=1,V>=t&&(V=-1),console.log(`Toggle LOD level [${V}]`)},t=6;window.addEventListener("keyup",e=>{e.key==="p"&&i(),e.key==="w"&&(Q=!Q,console.log(`Toggle wireframe [${Q}]`));const s=parseInt(e.key);!isNaN(s)&&s>=0&&(V=s,console.log(`Set LOD level to [${V}]`))})}function Pe(i){if(g&&Q!==void 0)if(Array.isArray(i))for(const t of i)Pe(t);else i&&"wireframe"in i&&(i.wireframe=Q===!0)}const H=new Array;let Xe=0;const je=Te()?2:10;function Ke(i){if(H.length<je){const s=H.length;g&&console.warn(`[Worker] Creating new worker #${s}`);const n=we.createWorker(i||{});return H.push(n),n}const t=Xe++%H.length;return H[t]}class we{constructor(t,e){this.worker=t,this._debug=e.debug??!1,t.onmessage=s=>{const n=s.data;switch(this._debug&&console.log("[Worker] EVENT",n),n.type){case"loaded-gltf":for(const r of this._running)if(r.url===n.result.url){Ye(n.result),r.resolve(n.result);const o=r.url;o.startsWith("blob:")&&URL.revokeObjectURL(o)}}},t.onerror=s=>{console.error("[Worker] Error in gltf-progressive worker:",s)},t.postMessage({type:"init"})}static async createWorker(t){const e=new Worker(new URL("/loader.worker-C1GG9A7C.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:ae&&ae.tagName.toUpperCase()==="SCRIPT"&&ae.src||new URL("gltf-progressive-CrHduHPm.umd.cjs",document.baseURI).href),{type:"module"});return new we(e,t)}_running=[];_webglRenderer=null;async load(t,e){const s=Ge();let n=e?.renderer;n||(this._webglRenderer??=(async()=>{const{WebGLRenderer:u}=await Promise.resolve().then(()=>require("./three-BW2s1Yl-.umd.cjs")).then(d=>d.THREE);return new u})(),n=await this._webglRenderer);const l=ne(n).ktx2Loader.workerConfig;t instanceof URL?t=t.toString():t.startsWith("file:")?t=URL.createObjectURL(new Blob([t])):!t.startsWith("blob:")&&!t.startsWith("http:")&&!t.startsWith("https:")&&(t=new URL(t,window.location.href).toString());const a={type:"load",url:t,dracoDecoderPath:s.dracoDecoderPath,ktx2TranscoderPath:s.ktx2TranscoderPath,ktx2LoaderConfig:l};return this._debug&&console.debug("[Worker] Sending load request",a),this.worker.postMessage(a),new Promise(u=>{this._running.push({url:t.toString(),resolve:u})})}_debug=!1}function Ye(i){for(const t of i.geometries){const e=t.geometry,s=new c.BufferGeometry;if(s.name=e.name||"",e.index){const n=e.index;s.setIndex(le(n))}for(const n in e.attributes){const r=e.attributes[n],o=le(r);s.setAttribute(n,o)}if(e.morphAttributes)for(const n in e.morphAttributes){const o=e.morphAttributes[n].map(l=>le(l));s.morphAttributes[n]=o}if(s.morphTargetsRelative=e.morphTargetsRelative??!1,s.boundingBox=new c.Box3,s.boundingBox.min=new c.Vector3(e.boundingBox?.min.x,e.boundingBox?.min.y,e.boundingBox?.min.z),s.boundingBox.max=new c.Vector3(e.boundingBox?.max.x,e.boundingBox?.max.y,e.boundingBox?.max.z),s.boundingSphere=new c.Sphere(new c.Vector3(e.boundingSphere?.center.x,e.boundingSphere?.center.y,e.boundingSphere?.center.z),e.boundingSphere?.radius),e.groups)for(const n of e.groups)s.addGroup(n.start,n.count,n.materialIndex);e.userData&&(s.userData=e.userData),t.geometry=s}for(const t of i.textures){const e=t.texture;let s=null;if(e.isCompressedTexture){const n=e.mipmaps,r=e.image?.width||e.source?.data?.width||-1,o=e.image?.height||e.source?.data?.height||-1;s=new c.CompressedTexture(n,r,o,e.format,e.type,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.anisotropy,e.colorSpace)}else s=new c.Texture(e.image,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),s.mipmaps=e.mipmaps,s.channel=e.channel,s.source.data=e.source.data,s.flipY=e.flipY,s.premultiplyAlpha=e.premultiplyAlpha,s.unpackAlignment=e.unpackAlignment,s.matrix=new c.Matrix3(...e.matrix.elements);if(!s){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}t.texture=s}return i}function le(i){let t=i;if("isInterleavedBufferAttribute"in i&&i.isInterleavedBufferAttribute){const e=i.data,s=e.array,n=new c.InterleavedBuffer(s,e.stride);t=new c.InterleavedBufferAttribute(n,i.itemSize,s.byteOffset,i.normalized),t.offset=i.offset}else"isBufferAttribute"in i&&i.isBufferAttribute&&(t=new c.BufferAttribute(i.array,i.itemSize,i.normalized),t.usage=i.usage,t.gpuType=i.gpuType,t.updateRanges=i.updateRanges);return t}const He=q("gltf-progressive-worker"),Qe=q("gltf-progressive-reduce-mipmaps"),ue=Symbol("needle-progressive-texture"),F="NEEDLE_progressive";class y{get name(){return F}static getMeshLODExtension(t){const e=this.getAssignedLODInformation(t);return e?.key?this.lodInfos.get(e.key):null}static getPrimitiveIndex(t){const e=this.getAssignedLODInformation(t)?.index;return e??-1}static getMaterialMinMaxLODsCount(t,e){const s=this,n="LODS:minmax",r=t[n];if(r!=null)return r;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const l of t)this.getMaterialMinMaxLODsCount(l,e);return t[n]=e,e}if(g==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const l=t;for(const a of Object.keys(l.uniforms)){const u=l.uniforms[a].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const l of Object.keys(t)){const a=t[l];a?.isTexture===!0&&o(a,e)}else g&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${t.type}`);return t[n]=e,e;function o(l,a){const u=s.getAssignedLODInformation(l);if(u){const d=s.lodInfos.get(u.key);if(d&&d.lods){a.min_count=Math.min(a.min_count,d.lods.length),a.max_count=Math.max(a.max_count,d.lods.length);for(let x=0;x<d.lods.length;x++){const L=d.lods[x];L.width&&(a.lods[x]=a.lods[x]||{min_height:1/0,max_height:0},a.lods[x].min_height=Math.min(a.lods[x].min_height,L.height),a.lods[x].max_height=Math.max(a.lods[x].max_height,L.height))}}}}}static hasLODLevelAvailable(t,e){if(Array.isArray(t)){for(const r of t)if(this.hasLODLevelAvailable(r,e))return!0;return!1}if(t.isMaterial===!0){for(const r of Object.keys(t)){const o=t[r];if(o&&o.isTexture&&this.hasLODLevelAvailable(o,e))return!0}return!1}else if(t.isGroup===!0){for(const r of t.children)if(r.isMesh===!0&&this.hasLODLevelAvailable(r,e))return!0}let s,n;if(t.isMesh?s=t.geometry:(t.isBufferGeometry||t.isTexture)&&(s=t),s&&s?.userData?.LODS){const r=s.userData.LODS;if(n=this.lodInfos.get(r.key),e===void 0)return n!=null;if(n)return Array.isArray(n.lods)?e<n.lods.length:e===0}return!1}static assignMeshLOD(t,e){if(!t)return Promise.resolve(null);if(t instanceof c.Mesh||t.isMesh===!0){const s=t.geometry,n=this.getAssignedLODInformation(s);if(!n)return Promise.resolve(null);for(const r of U)r.onBeforeGetLODMesh?.(t,e);return t["LOD:requested level"]=e,y.getOrLoadLOD(s,e).then(r=>{if(Array.isArray(r)){const o=n.index||0;r=r[o]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],r&&s!=r&&(r?.isBufferGeometry?t.geometry=r:g&&console.error("Invalid LOD geometry",r))),r}).catch(r=>(console.error("Error loading mesh LOD",t,r),null))}else g&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const s=t;if(Array.isArray(s.material)){const n=new Array;for(const r of s.material){const o=this.assignTextureLOD(r,e);n.push(o)}return Promise.all(n).then(r=>{const o=new Array;for(const l of r)Array.isArray(l)&&o.push(...l);return o})}else return this.assignTextureLOD(s.material,e)}if(t.isMaterial===!0){const s=t,n=[],r=new Array;if(s.uniforms&&(s.isRawShaderMaterial||s.isShaderMaterial===!0)){const o=s;for(const l of Object.keys(o.uniforms)){const a=o.uniforms[l].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,s,l).then(d=>(d&&o.uniforms[l].value!=d&&(o.uniforms[l].value=d,o.uniformsNeedUpdate=!0),d));n.push(u),r.push(l)}}}else for(const o of Object.keys(s)){const l=s[o];if(l?.isTexture===!0){const a=this.assignTextureLODForSlot(l,e,s,o);n.push(a),r.push(o)}}return Promise.all(n).then(o=>{const l=new Array;for(let a=0;a<o.length;a++){const u=o[a],d=r[a];u&&u.isTexture===!0?l.push({material:s,slot:d,texture:u,level:e}):l.push({material:s,slot:d,texture:null,level:e})}return l})}if(t instanceof c.Texture||t.isTexture===!0){const s=t;return this.assignTextureLODForSlot(s,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,s,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):y.getOrLoadLOD(t,e).then(r=>{if(Array.isArray(r))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if(r?.isTexture===!0){if(r!=t&&s&&n){const o=s[n];if(o&&!g){const l=this.getAssignedLODInformation(o);if(l&&l?.level<e)return g==="verbose"&&console.warn("Assigned texture level is already higher: ",l.level,e,s,o,r),null}if(Qe&&r.mipmaps){const l=r.mipmaps.length;r.mipmaps.length=Math.min(r.mipmaps.length,3),l!==r.mipmaps.length&&g&&console.debug(`Reduced mipmap count from ${l} to ${r.mipmaps.length} for ${r.uuid}: ${r.image?.width}x${r.image?.height}.`)}s[n]=r}return r}else g=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(r=>(console.error("Error loading LOD",t,r),null))}parser;url;constructor(t){const e=t.options.path;g&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}_isLoadingMesh;loadMesh=t=>{if(this._isLoadingMesh)return null;const e=this.parser.json.meshes[t]?.extensions?.[F];return e?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",t).then(s=>(this._isLoadingMesh=!1,s&&y.registerMesh(this.url,e.guid,s,e.lods?.length,0,e),s))):null};afterRoot(t){return g&&console.log("AFTER",this.url,t),this.parser.json.textures?.forEach((e,s)=>{if(e?.extensions){const n=e?.extensions[F];if(n){if(!n.lods){g&&console.warn("Texture has no LODs",n);return}let r=!1;for(const o of this.parser.associations.keys())o.isTexture===!0&&this.parser.associations.get(o)?.textures===s&&(r=!0,y.registerTexture(this.url,o,n.lods?.length,s,n));r||this.parser.getDependency("texture",s).then(o=>{o&&y.registerTexture(this.url,o,n.lods?.length,s,n)})}}}),this.parser.json.meshes?.forEach((e,s)=>{if(e?.extensions){const n=e?.extensions[F];if(n&&n.lods){for(const r of this.parser.associations.keys())if(r.isMesh){const o=this.parser.associations.get(r);o?.meshes===s&&y.registerMesh(this.url,n.guid,r,n.lods.length,o.primitives,n)}}}}),null}static registerTexture=(t,e,s,n,r)=>{if(!e){g&&console.error("!! gltf-progressive: Called register texture without texture");return}if(g){const l=e.image?.width||e.source?.data?.width||0,a=e.image?.height||e.source?.data?.height||0;console.log(`> gltf-progressive: register texture[${n}] "${e.name||e.uuid}", Current: ${l}x${a}, Max: ${r.lods[0]?.width}x${r.lods[0]?.height}, uuid: ${e.uuid}`,r,e)}e.source&&(e.source[ue]=r);const o=r.guid;y.assignLODInformation(t,e,o,s,n),y.lodInfos.set(o,r),y.lowresCache.set(o,new WeakRef(e))};static registerMesh=(t,e,s,n,r,o)=>{const l=s.geometry;if(!l){g&&console.warn("gltf-progressive: Register mesh without geometry");return}l.userData||(l.userData={}),g&&console.log("> Progressive: register mesh "+s.name,{index:r,uuid:s.uuid},o,s),y.assignLODInformation(t,l,e,n,r),y.lodInfos.set(e,o);let u=y.lowresCache.get(e)?.deref();u?u.push(s.geometry):u=[s.geometry],y.lowresCache.set(e,new WeakRef(u)),n>0&&!X(s)&&Ee(s,l);for(const d of U)d.onRegisteredNewMesh?.(s,o)};static dispose(t){if(t){this.lodInfos.delete(t);const e=this.lowresCache.get(t);if(e){const s=e.deref();if(s){if(s.isTexture)s.dispose();else if(Array.isArray(s))for(const n of s)n.dispose()}this.lowresCache.delete(t)}for(const[s,n]of this.cache)s.includes(t)&&(this._disposeCacheEntry(n),this.cache.delete(s))}else{this.lodInfos.clear();for(const[,e]of this.lowresCache){const s=e.deref();if(s){if(s.isTexture)s.dispose();else if(Array.isArray(s))for(const n of s)n.dispose()}}this.lowresCache.clear();for(const[,e]of this.cache)this._disposeCacheEntry(e);this.cache.clear()}}static _disposeCacheEntry(t){t instanceof WeakRef?t.deref()?.dispose():t.then(e=>{if(e)if(Array.isArray(e))for(const s of e)s.dispose();else e.dispose()}).catch(()=>{})}static lodInfos=new Map;static cache=new Map;static lowresCache=new Map;static _resourceRegistry=new FinalizationRegistry(t=>{const e=y.cache.get(t);g&&console.debug(`[gltf-progressive] Resource GC'd
|
|
2
|
+
${t}`),e instanceof WeakRef&&(e.deref()||(y.cache.delete(t),g&&console.log(`[gltf-progressive] Cache entry auto-cleaned (GC'd): ${t}`)))});static workers=[];static _workersIndex=0;static async getOrLoadLOD(t,e){const s=g=="verbose",n=this.getAssignedLODInformation(t);if(!n)return g&&console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`,t),null;const r=n?.key;let o;if(t.isTexture===!0){const a=t;a.source&&a.source[ue]&&(o=a.source[ue])}if(o||(o=y.lodInfos.get(r)),!o)g&&console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`,t.type,y.lodInfos);else{if(e>0){let d=!1;const x=Array.isArray(o.lods);if(x&&e>=o.lods.length?d=!0:x||(d=!0),d){const L=this.lowresCache.get(r);if(L){const _=L.deref();if(_)return _;this.lowresCache.delete(r),g&&console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${r}`)}return null}}const a=Array.isArray(o.lods)?o.lods[e]?.path:o.lods;if(!a)return g&&!o["missing:uri"]&&(o["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,o)),null;const u=Ue(n.url,a);if(u.endsWith(".glb")||u.endsWith(".gltf")){if(!o.guid)return console.warn("missing pointer for glb/gltf texture",o),null;const d=u+"_"+o.guid,x=await this.queue.slot(u),L=this.cache.get(d);if(L!==void 0)if(s&&console.log(`LOD ${e} was already loading/loaded: ${d}`),L instanceof WeakRef){const f=L.deref();if(f){let p=f,v=!1;if(p instanceof c.Texture&&t instanceof c.Texture?p.image?.data||p.source?.data?p=this.copySettings(t,p):v=!0:p instanceof c.BufferGeometry&&t instanceof c.BufferGeometry&&(p.attributes.position?.array||(v=!0)),!v)return p}this.cache.delete(d),g&&console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${d}`)}else{let f=await L.catch(v=>(console.error(`Error loading LOD ${e} from ${u}
|
|
3
|
+
`,v),null)),p=!1;if(f==null||(f instanceof c.Texture&&t instanceof c.Texture?f.image?.data||f.source?.data?f=this.copySettings(t,f):(p=!0,this.cache.delete(d)):f instanceof c.BufferGeometry&&t instanceof c.BufferGeometry&&(f.attributes.position?.array||(p=!0,this.cache.delete(d)))),!p)return f}if(!x.use)return g&&console.log(`LOD ${e} was aborted: ${u}`),null;const _=o,I=new Promise(async(f,p)=>{if(He){const w=await(await Ke({})).load(u);if(w.textures.length>0)for(const h of w.textures){let m=h.texture;return y.assignLODInformation(n.url,m,r,e,void 0),t instanceof c.Texture&&(m=this.copySettings(t,m)),m&&(m.guid=_.guid),f(m)}if(w.geometries.length>0){const h=new Array;for(const m of w.geometries){const O=m.geometry;y.assignLODInformation(n.url,O,r,e,m.primitiveIndex),h.push(O)}return f(h)}return f(null)}const v=new N.GLTFLoader;ye(v),g&&(await new Promise(M=>setTimeout(M,1e3)),s&&console.warn("Start loading (delayed) "+u,_.guid));let $=u;if(_&&Array.isArray(_.lods)){const M=_.lods[e];M.hash&&($+="?v="+M.hash)}const b=await v.loadAsync($).catch(M=>(console.error(`Error loading LOD ${e} from ${u}
|
|
4
|
+
`,M),f(null)));if(!b)return f(null);const z=b.parser;s&&console.log("Loading finished "+u,_.guid);let P=0;if(b.parser.json.textures){let M=!1;for(const w of b.parser.json.textures){if(w?.extensions){const h=w?.extensions[F];if(h?.guid&&h.guid===_.guid){M=!0;break}}P++}if(M){let w=await z.getDependency("texture",P);return w&&y.assignLODInformation(n.url,w,r,e,void 0),s&&console.log('change "'+t.name+'" → "'+w.name+'"',u,P,w,d),t instanceof c.Texture&&(w=this.copySettings(t,w)),w&&(w.guid=_.guid),f(w)}else g&&console.warn("Could not find texture with guid",_.guid,b.parser.json)}if(P=0,b.parser.json.meshes){let M=!1;for(const w of b.parser.json.meshes){if(w?.extensions){const h=w?.extensions[F];if(h?.guid&&h.guid===_.guid){M=!0;break}}P++}if(M){const w=await z.getDependency("mesh",P);if(s&&console.log(`Loaded Mesh "${w.name}"`,u,P,w,d),w.isMesh===!0){const h=w.geometry;return y.assignLODInformation(n.url,h,r,e,0),f(h)}else{const h=new Array;for(let m=0;m<w.children.length;m++){const O=w.children[m];if(O.isMesh===!0){const T=O.geometry;y.assignLODInformation(n.url,T,r,e,m),h.push(T)}}return f(h)}}else g&&console.warn("Could not find mesh with guid",_.guid,b.parser.json)}return f(null)});this.cache.set(d,I),x.use(I);const D=await I;return D!=null?D instanceof c.Texture?(this.cache.set(d,new WeakRef(D)),y._resourceRegistry.register(D,d)):Array.isArray(D)?this.cache.set(d,Promise.resolve(D)):this.cache.set(d,Promise.resolve(D)):this.cache.set(d,Promise.resolve(null)),D}else if(t instanceof c.Texture){s&&console.log("Load texture from uri: "+u);const x=await new c.TextureLoader().loadAsync(u);return x?(x.guid=o.guid,x.flipY=!1,x.needsUpdate=!0,x.colorSpace=t.colorSpace,s&&console.log(o,x)):g&&console.warn("failed loading",u),x}}return null}static maxConcurrent=50;static queue=new ze(y.maxConcurrent,{debug:g!=!1});static assignLODInformation(t,e,s,n,r){if(!e)return;e.userData||(e.userData={});const o=new Je(t,s,n,r);e.userData.LODS=o,"source"in e&&typeof e.source=="object"&&(e.source.LODS=o)}static getAssignedLODInformation(t){return t?t.userData?.LODS?t.userData.LODS:"source"in t&&t.source?.LODS?t.source.LODS:null:null}static copySettings(t,e){return e?(g==="verbose"&&console.debug(`Copy texture settings
|
|
5
|
+
`,t.uuid,`
|
|
6
|
+
`,e.uuid),e=e.clone(),e.offset=t.offset,e.repeat=t.repeat,e.colorSpace=t.colorSpace,e.magFilter=t.magFilter,e.minFilter=t.minFilter,e.wrapS=t.wrapS,e.wrapT=t.wrapT,e.flipY=t.flipY,e.anisotropy=t.anisotropy,e.mipmaps||(e.generateMipmaps=t.generateMipmaps),e):t}}class Je{url;key;level;index;constructor(t,e,s,n){this.url=t,this.key=e,this.level=s,n!=null&&(this.index=n)}}class ce{static addPromise=(t,e,s,n)=>{n.forEach(r=>{r.add(t,e,s)})};ready;get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}_resolve;_signal;_frame_start;_frames_to_capture;_resolved=!1;_addedCount=0;_resolvedCount=0;_awaiting=[];_maxPromisesPerObject=1;constructor(t,e){const n=Math.max(e.frames??2,2);this._frame_start=e.waitForFirstCapture?void 0:t,this._frames_to_capture=n,this.ready=new Promise(r=>{this._resolve=r}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=e.signal,this._signal?.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,e.maxPromisesPerObject??1)}_currentFrame=0;update(t){this._currentFrame=t,this._frame_start===void 0&&this._addedCount>0&&(this._frame_start=t),(this._signal?.aborted||this._awaiting.length===0&&this._frame_start!==void 0&&t>this._frame_start+this._frames_to_capture)&&this.resolveNow()}_seen=new WeakMap;add(t,e,s){if(this._resolved){g&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._frame_start!==void 0&&this._currentFrame>this._frame_start+this._frames_to_capture)){if(this._maxPromisesPerObject>=1)if(this._seen.has(e)){let n=this._seen.get(e);if(n>=this._maxPromisesPerObject){g&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(e,n+1)}else this._seen.set(e,1);this._awaiting.push(s),this._addedCount++,s.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(s),1)})}}resolveNow(){this._resolved||this._resolve?.({awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:this._signal?.aborted??!1})}}const k=q("debugprogressive"),Ze=q("noprogressive"),de=Symbol("Needle:LODSManager"),fe=Symbol("Needle:LODState"),W=Symbol("Needle:CurrentLOD"),A={mesh_lod:-1,texture_lod:-1};let J=class S{static debugDrawLine;static getObjectLODState(t){return t[fe]}static addPlugin(t){U.push(t)}static removePlugin(t){const e=U.indexOf(t);e>=0&&U.splice(e,1)}static get(t,e){if(t[de])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[de];const s=new S(t,{engine:"unknown",...e});return t[de]=s,s}renderer;context;projectionScreenMatrix=new c.Matrix4;get plugins(){return U}overrideLodLevel=void 0;targetTriangleDensity=2e5;skinnedMeshAutoUpdateBoundsInterval=30;updateInterval="auto";#e=1;pause=!1;manual=!1;_newPromiseGroups=[];_promiseGroupIds=0;awaitLoading(t){const e=this._promiseGroupIds++,s=new ce(this.#r,{...t});this._newPromiseGroups.push(s);const n=performance.now();return s.ready.finally(()=>{const r=this._newPromiseGroups.indexOf(s);r>=0&&(this._newPromiseGroups.splice(r,1),Le()&&performance.measure("LODsManager:awaitLoading",{start:n,detail:{id:e,name:t?.name,awaited:s.awaitedCount,resolved:s.resolvedCount}}))}),s.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let t=this._newPromiseGroups.length-1;t>=0;t--)this._newPromiseGroups[t].update(this.#r)}_lodchangedlisteners=[];addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const s=this._lodchangedlisteners.indexOf(e);s>=0&&this._lodchangedlisteners.splice(s,1)}}constructor(t,e){this.renderer=t,this.context={...e}}#t;#o=new c.Clock;#r=0;#n=0;#i=0;#s=0;_fpsBuffer=[60,60,60,60,60];enable(){if(this.#t)return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;this.#t=this.renderer.render;const e=this;ne(this.renderer),this.renderer.render=function(s,n){const r=e.renderer.getRenderTarget();(r==null||"isXRRenderTarget"in r&&r.isXRRenderTarget)&&(t=0,e.#r+=1,e.#n=e.#o.getDelta(),e.#i+=e.#n,e._fpsBuffer.shift(),e._fpsBuffer.push(1/e.#n),e.#s=e._fpsBuffer.reduce((l,a)=>l+a)/e._fpsBuffer.length,k&&e.#r%200===0&&console.log("FPS",Math.round(e.#s),"Interval:",e.#e));const o=t++;e.#t.call(this,s,n),e.onAfterRender(s,n,o)}}disable(){this.#t&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=this.#t,this.#t=void 0)}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,s){if(this.pause)return;const r=this.renderer.renderLists.get(t,0).opaque;let o=!0;if(r.length===1){const l=r[0].material;(l.name==="EffectMaterial"||l.name==="CopyShader")&&(o=!1)}if((e.parent&&e.parent.type==="CubeCamera"||s>=1&&e.type==="OrthographicCamera")&&(o=!1),o){if(Ze||(this.updateInterval==="auto"?this.#s<40&&this.#e<10?(this.#e+=1,k&&console.warn("↓ Reducing LOD updates",this.#e,this.#s.toFixed(0))):this.#s>=60&&this.#e>1&&(this.#e-=1,k&&console.warn("↑ Increasing LOD updates",this.#e,this.#s.toFixed(0))):this.#e=this.updateInterval,this.#e>0&&this.#r%this.#e!=0))return;this.internalUpdate(t,e),this._postprocessPromiseGroups()}}internalUpdate(t,e){const s=this.renderer.renderLists.get(t,0),n=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const r=this.targetTriangleDensity;for(const a of n){if(a.material&&(a.geometry?.type==="BoxGeometry"||a.geometry?.type==="BufferGeometry")&&(a.material.name==="SphericalGaussianBlur"||a.material.name=="BackgroundCubeMaterial"||a.material.name==="CubemapFromEquirect"||a.material.name==="EquirectangularToCubeUV")){k&&(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",a,a.material.name,a.material.type)));continue}switch(a.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(k==="color"&&a.material&&!a.object.progressive_debug_color){a.object.progressive_debug_color=!0;const d=Math.random()*16777215,x=new c.MeshStandardMaterial({color:d});a.object.material=x}const u=a.object;(u instanceof c.Mesh||u.isMesh)&&this.updateLODs(t,e,u,r)}const o=s.transparent;for(const a of o){const u=a.object;(u instanceof c.Mesh||u.isMesh)&&this.updateLODs(t,e,u,r)}const l=s.transmissive;for(const a of l){const u=a.object;(u instanceof c.Mesh||u.isMesh)&&this.updateLODs(t,e,u,r)}}updateLODs(t,e,s,n){s.userData||(s.userData={});let r=s[fe];if(r||(r=new et,s[fe]=r),r.frames++<2)return;for(const l of U)l.onBeforeUpdateLOD?.(this.renderer,t,e,s);const o=this.overrideLodLevel!==void 0?this.overrideLodLevel:V;o>=0?(A.mesh_lod=o,A.texture_lod=o):(this.calculateLodLevel(e,s,r,n,A),A.mesh_lod=Math.round(A.mesh_lod),A.texture_lod=Math.round(A.texture_lod)),A.mesh_lod>=0&&this.loadProgressiveMeshes(s,A.mesh_lod),s.material&&A.texture_lod>=0&&this.loadProgressiveTextures(s.material,A.texture_lod,o),g&&s.material&&!s.isGizmo&&Pe(s.material);for(const l of U)l.onAfterUpdatedLOD?.(this.renderer,t,e,s,A);r.lastLodLevel_Mesh=A.mesh_lod,r.lastLodLevel_Texture=A.texture_lod}loadProgressiveTextures(t,e,s){if(!t)return;if(Array.isArray(t)){for(const r of t)this.loadProgressiveTextures(r,e);return}let n=!1;if((t[W]===void 0||e<t[W])&&(n=!0),s!==void 0&&s>=0&&(n=t[W]!=s,e=s),n){t[W]=e;const r=y.assignTextureLOD(t,e).then(o=>{this._lodchangedlisteners.forEach(l=>l({type:"texture",level:e,object:t}))});ce.addPromise("texture",t,r,this._newPromiseGroups)}}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);let s=t[W]!==e;const n=t["DEBUG:LOD"];if(n!=null&&(s=t[W]!=n,e=n),s){t[W]=e;const r=t.geometry,o=y.assignMeshLOD(t,e).then(l=>(l&&t[W]==e&&r!=t.geometry&&this._lodchangedlisteners.forEach(a=>a({type:"mesh",level:e,object:t})),l));return ce.addPromise("mesh",t,o,this._newPromiseGroups),o}return Promise.resolve(null)}_sphere=new c.Sphere;_tempBox=new c.Box3;_tempBox2=new c.Box3;tempMatrix=new c.Matrix4;_tempWorldPosition=new c.Vector3;_tempBoxSize=new c.Vector3;_tempBox2Size=new c.Vector3;static corner0=new c.Vector3;static corner1=new c.Vector3;static corner2=new c.Vector3;static corner3=new c.Vector3;static _tempPtInside=new c.Vector3;static isInside(t,e){const s=t.min,n=t.max,r=(s.x+n.x)*.5,o=(s.y+n.y)*.5;return this._tempPtInside.set(r,o,s.z).applyMatrix4(e).z<0}static skinnedMeshBoundsFrameOffsetCounter=0;static $skinnedMeshBoundsOffset=Symbol("gltf-progressive-skinnedMeshBoundsOffset");calculateLodLevel(t,e,s,n,r){if(!e){r.mesh_lod=-1,r.texture_lod=-1;return}if(!t){r.mesh_lod=-1,r.texture_lod=-1;return}let l=10+1,a=!1;if(k&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const u=y.getMeshLODExtension(e.geometry)?.lods,d=y.getPrimitiveIndex(e.geometry),x=u&&u.length>0,L=y.getMaterialMinMaxLODsCount(e.material),_=L.min_count!==1/0&&L.min_count>=0&&L.max_count>=0;if(!x&&!_){r.mesh_lod=0,r.texture_lod=0;return}x||(a=!0,l=0);const I=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let D=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const f=e;if(!f.boundingBox)f.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!f[S.$skinnedMeshBoundsOffset]){const v=S.skinnedMeshBoundsFrameOffsetCounter++;f[S.$skinnedMeshBoundsOffset]=v}const p=f[S.$skinnedMeshBoundsOffset];if((s.frames+p)%this.skinnedMeshAutoUpdateBoundsInterval===0){const v=X(f),$=f.geometry;v&&(f.geometry=v),f.computeBoundingBox(),f.geometry=$}}D=f.boundingBox}if(D){const f=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const h=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(h)){r.mesh_lod=0,r.texture_lod=0;return}}if(this._tempBox.copy(D),this._tempBox.applyMatrix4(e.matrixWorld),f.isPerspectiveCamera&&S.isInside(this._tempBox,this.projectionScreenMatrix)){r.mesh_lod=0,r.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&f.isPerspectiveCamera&&f.fov>70){const h=this._tempBox.min,m=this._tempBox.max;let O=h.x,T=h.y,G=m.x,j=m.y;const Z=2,oe=1.5,ee=(h.x+m.x)*.5,te=(h.y+m.y)*.5;O=(O-ee)*Z+ee,T=(T-te)*Z+te,G=(G-ee)*Z+ee,j=(j-te)*Z+te;const Ie=O<0&&G>0?0:Math.min(Math.abs(h.x),Math.abs(m.x)),ke=T<0&&j>0?0:Math.min(Math.abs(h.y),Math.abs(m.y)),ie=Math.max(Ie,ke);s.lastCentrality=(oe-ie)*(oe-ie)*(oe-ie)}else s.lastCentrality=1;const p=this._tempBox.getSize(this._tempBoxSize);p.multiplyScalar(.5),screen.availHeight>0&&I>0&&p.multiplyScalar(I/screen.availHeight),t.isPerspectiveCamera?p.x*=t.aspect:t.isOrthographicCamera;const v=t.matrixWorldInverse,$=this._tempBox2;$.copy(D),$.applyMatrix4(e.matrixWorld),$.applyMatrix4(v);const b=$.getSize(this._tempBox2Size),z=Math.max(b.x,b.y);if(Math.max(p.x,p.y)!=0&&z!=0&&(p.z=b.z/Math.max(b.x,b.y)*Math.max(p.x,p.y)),s.lastScreenCoverage=Math.max(p.x,p.y,p.z),s.lastScreenspaceVolume.copy(p),s.lastScreenCoverage*=s.lastCentrality,k&&S.debugDrawLine){const h=this.tempMatrix.copy(this.projectionScreenMatrix);h.invert();const m=S.corner0,O=S.corner1,T=S.corner2,G=S.corner3;m.copy(this._tempBox.min),O.copy(this._tempBox.max),O.x=m.x,T.copy(this._tempBox.max),T.y=m.y,G.copy(this._tempBox.max);const j=(m.z+G.z)*.5;m.z=O.z=T.z=G.z=j,m.applyMatrix4(h),O.applyMatrix4(h),T.applyMatrix4(h),G.applyMatrix4(h),S.debugDrawLine(m,O,255),S.debugDrawLine(m,T,255),S.debugDrawLine(O,G,255),S.debugDrawLine(T,G,255)}let M=999;if(u&&s.lastScreenCoverage>0)for(let h=0;h<u.length;h++){const m=u[h],T=(m.densities?.[d]||m.density||1e-5)/s.lastScreenCoverage;if(d>0&&Le()&&!m.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),T<n){M=h;break}}M<l&&(l=M,a=!0)}if(a?r.mesh_lod=l:r.mesh_lod=s.lastLodLevel_Mesh,k&&r.mesh_lod!=s.lastLodLevel_Mesh){const p=u?.[r.mesh_lod];p&&console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (density: ${p.densities?.[d].toFixed(0)}) | ${e.name}`)}if(_){const f="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(s.lastLodLevel_Texture<0){if(r.texture_lod=L.max_count-1,k){const p=L.lods[L.max_count-1];k&&console.log(`First Texture LOD ${r.texture_lod} (${p.max_height}px) - ${e.name}`)}}else{const p=s.lastScreenspaceVolume.x+s.lastScreenspaceVolume.y+s.lastScreenspaceVolume.z;let v=s.lastScreenCoverage*4;this.context?.engine==="model-viewer"&&(v*=1.5);const b=I/window.devicePixelRatio*v;let z=!1;for(let P=L.lods.length-1;P>=0;P--){const M=L.lods[P];if(!(f&&M.max_height>=2048)&&!(Te()&&M.max_height>4096)&&(M.max_height>b||!z&&P===0)){if(z=!0,r.texture_lod=P,k&&r.texture_lod<s.lastLodLevel_Texture){const w=M.max_height;console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${w}px
|
|
7
|
+
Screensize: ${b.toFixed(0)}px, Coverage: ${(100*s.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
|
|
8
|
+
${e.name}`)}break}}}}else r.texture_lod=0}};class et{frames=0;lastLodLevel_Mesh=-1;lastLodLevel_Texture=-1;lastScreenCoverage=0;lastScreenspaceVolume=new c.Vector3;lastCentrality=0}const _e=Symbol("NEEDLE_mesh_lod"),se=Symbol("NEEDLE_texture_lod");let he=null;function Ae(){const i=tt();i&&(i.mapURLs(function(t){return Me(),t}),Me(),he?.disconnect(),he=new MutationObserver(t=>{t.forEach(e=>{e.addedNodes.forEach(s=>{s instanceof HTMLElement&&s.tagName.toLowerCase()==="model-viewer"&&Ce(s)})})}),he.observe(document,{childList:!0,subtree:!0}))}function tt(){if(typeof customElements>"u")return null;const i=customElements.get("model-viewer");return i||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Ae()}),null)}function Me(){if(typeof document>"u")return;document.querySelectorAll("model-viewer").forEach(t=>{Ce(t)})}const ve=new WeakSet;let st=0;function Ce(i){if(!i||ve.has(i))return null;ve.add(i),console.debug("[gltf-progressive] found new model-viewer..."+ ++st+`
|
|
9
|
+
`,i.getAttribute("src"));let t=null,e=null,s=null;for(let n=i;n!=null;n=Object.getPrototypeOf(n)){const r=Object.getOwnPropertySymbols(n),o=r.find(u=>u.toString()=="Symbol(renderer)"),l=r.find(u=>u.toString()=="Symbol(scene)"),a=r.find(u=>u.toString()=="Symbol(needsRender)");!t&&o!=null&&(t=i[o].threeRenderer),!e&&l!=null&&(e=i[l]),!s&&a!=null&&(s=i[a])}if(t&&e){let n=function(){if(s){let o=0,l=setInterval(()=>{if(o++>5){clearInterval(l);return}s?.call(i)},300)}};console.debug("[gltf-progressive] setup model-viewer");const r=J.get(t,{engine:"model-viewer"});return J.addPlugin(new rt),r.enable(),r.addEventListener("changed",()=>{s?.call(i)}),i.addEventListener("model-visibility",o=>{o.detail.visible&&s?.call(i)}),i.addEventListener("load",()=>{n()}),()=>{r.disable()}}return null}class rt{_didWarnAboutMissingUrl=!1;onBeforeUpdateLOD(t,e,s,n){this.tryParseMeshLOD(e,n),this.tryParseTextureLOD(e,n)}getUrl(t){if(!t)return null;let e=t.getAttribute("src");return e||(e=t.src),e||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",t),this._didWarnAboutMissingUrl=!0),e}tryGetCurrentGLTF(t){return t._currentGLTF}tryGetCurrentModelViewer(t){return t.element}tryParseTextureLOD(t,e){if(e[se]==!0)return;e[se]=!0;const s=this.tryGetCurrentGLTF(t),n=this.tryGetCurrentModelViewer(t),r=this.getUrl(n);if(r&&s&&e.material){let o=function(a){if(a[se]==!0)return;a[se]=!0,a.userData&&(a.userData.LOD=-1);const u=Object.keys(a);for(let d=0;d<u.length;d++){const x=u[d],L=a[x];if(L?.isTexture===!0){const _=L.userData?.associations?.textures;if(_==null)continue;const I=s.parser.json.textures[_];if(!I){console.warn("Texture data not found for texture index "+_);continue}if(I?.extensions?.[F]){const D=I.extensions[F];D&&r&&y.registerTexture(r,L,D.lods.length,_,D)}}}};const l=e.material;if(Array.isArray(l))for(const a of l)o(a);else o(l)}}tryParseMeshLOD(t,e){if(e[_e]==!0)return;e[_e]=!0;const s=this.tryGetCurrentModelViewer(t),n=this.getUrl(s);if(!n)return;const r=e.userData?.gltfExtensions?.[F];if(r&&n){const o=e.uuid;y.registerMesh(n,o,e,0,r.lods.length,r)}}}function nt(...i){let t,e,s,n;switch(i.length){case 2:[s,e]=i,n={};break;case 3:[s,e,n]=i;break;case 4:[t,e,s,n]=i;break;default:throw new Error("Invalid arguments")}ne(e),ye(s),xe(s,{progressive:!0,...n?.hints}),s.register(o=>new y(o));const r=J.get(e);return n?.enableLODsManager!==!1&&r.enable(),r}Ae();if(!Ve){const i={gltfProgressive:{useNeedleProgressive:nt,LODsManager:J,configureLoader:xe,getRaycastMesh:X,useRaycastMeshes:qe}};if(!globalThis.Needle)globalThis.Needle=i;else for(const t in i)globalThis.Needle[t]=i[t]}exports.LODsManager=J;exports.NEEDLE_progressive=y;exports.addDracoAndKTX2Loaders=ye;exports.configureLoader=xe;exports.createLoaders=ne;exports.getRaycastMesh=X;exports.setDracoDecoderLocation=be;exports.setKTX2TranscoderLocation=Oe;
|