@onerjs/core 9.0.2 → 9.0.4
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/Buffers/buffer.pure.js +4 -0
- package/Buffers/buffer.pure.js.map +1 -1
- package/Cameras/camera.pure.d.ts +14 -0
- package/Cameras/camera.pure.js +15 -0
- package/Cameras/camera.pure.js.map +1 -1
- package/Compute/computeShader.pure.d.ts +2 -1
- package/Compute/computeShader.pure.js +29 -10
- package/Compute/computeShader.pure.js.map +1 -1
- package/Culling/ray.core.js +22 -9
- package/Culling/ray.core.js.map +1 -1
- package/Engines/IDrawContext.d.ts +2 -0
- package/Engines/IDrawContext.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +55 -4
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Native/nativeRenderTargetWrapper.d.ts +1 -0
- package/Engines/Native/nativeRenderTargetWrapper.js +5 -1
- package/Engines/Native/nativeRenderTargetWrapper.js.map +1 -1
- package/Engines/Processors/shaderCodeInliner.d.ts +2 -0
- package/Engines/Processors/shaderCodeInliner.js +251 -6
- package/Engines/Processors/shaderCodeInliner.js.map +1 -1
- package/Engines/Processors/shaderProcessor.js +10 -1
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.debugging.pure.js +12 -0
- package/Engines/WebGPU/Extensions/engine.debugging.pure.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.multiRender.pure.js +0 -1
- package/Engines/WebGPU/Extensions/engine.multiRender.pure.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.query.pure.js +5 -0
- package/Engines/WebGPU/Extensions/engine.query.pure.js.map +1 -1
- package/Engines/WebGPU/webgpuBufferManager.js +7 -0
- package/Engines/WebGPU/webgpuBufferManager.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheTextureView.d.ts +1 -1
- package/Engines/WebGPU/webgpuCacheTextureView.js +20 -8
- package/Engines/WebGPU/webgpuCacheTextureView.js.map +1 -1
- package/Engines/WebGPU/webgpuDrawContext.d.ts +2 -0
- package/Engines/WebGPU/webgpuDrawContext.js +6 -0
- package/Engines/WebGPU/webgpuDrawContext.js.map +1 -1
- package/Engines/WebGPU/webgpuQuerySet.d.ts +3 -3
- package/Engines/WebGPU/webgpuQuerySet.js +23 -9
- package/Engines/WebGPU/webgpuQuerySet.js.map +1 -1
- package/Engines/WebGPU/webgpuRenderPassCommandStream.d.ts +156 -0
- package/Engines/WebGPU/webgpuRenderPassCommandStream.js +323 -0
- package/Engines/WebGPU/webgpuRenderPassCommandStream.js.map +1 -0
- package/Engines/WebGPU/webgpuTextureManager.d.ts +1 -1
- package/Engines/WebGPU/webgpuTextureManager.js +4 -3
- package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
- package/Engines/WebGPU/webgpuTimestampQuery.d.ts +3 -1
- package/Engines/WebGPU/webgpuTimestampQuery.js +9 -6
- package/Engines/WebGPU/webgpuTimestampQuery.js.map +1 -1
- package/Engines/abstractEngine.pure.d.ts +2 -0
- package/Engines/abstractEngine.pure.js +14 -5
- package/Engines/abstractEngine.pure.js.map +1 -1
- package/Engines/constants.d.ts +6 -0
- package/Engines/constants.js +6 -0
- package/Engines/constants.js.map +1 -1
- package/Engines/engine.d.ts +198 -24
- package/Engines/pure.d.ts +1 -0
- package/Engines/pure.js +1 -0
- package/Engines/pure.js.map +1 -1
- package/Engines/renderCommandBatcher.pure.d.ts +16 -0
- package/Engines/renderCommandBatcher.pure.js +24 -0
- package/Engines/renderCommandBatcher.pure.js.map +1 -0
- package/Engines/thinEngine.functions.js +3 -2
- package/Engines/thinEngine.functions.js.map +1 -1
- package/Engines/thinEngine.pure.js +18 -2
- package/Engines/thinEngine.pure.js.map +1 -1
- package/Engines/thinNativeEngine.pure.d.ts +10 -7
- package/Engines/thinNativeEngine.pure.js +117 -46
- package/Engines/thinNativeEngine.pure.js.map +1 -1
- package/Engines/thinWebGPUEngine.d.ts +8 -0
- package/Engines/thinWebGPUEngine.js +11 -0
- package/Engines/thinWebGPUEngine.js.map +1 -1
- package/Engines/webgpuEngine.pure.d.ts +60 -1
- package/Engines/webgpuEngine.pure.js +238 -42
- package/Engines/webgpuEngine.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Audio/flowGraphGetSoundVolumeBlock.pure.d.ts +3 -3
- package/FlowGraph/Blocks/Data/Audio/flowGraphGetSoundVolumeBlock.pure.js +2 -1
- package/FlowGraph/Blocks/Data/Audio/flowGraphGetSoundVolumeBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Data/Audio/flowGraphIsSoundPlayingBlock.pure.d.ts +3 -3
- package/FlowGraph/Blocks/Data/Audio/flowGraphIsSoundPlayingBlock.pure.js +2 -1
- package/FlowGraph/Blocks/Data/Audio/flowGraphIsSoundPlayingBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.d.ts +5 -0
- package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.js +8 -0
- package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.js.map +1 -0
- package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.pure.d.ts +77 -0
- package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.pure.js +141 -0
- package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.pure.js.map +1 -0
- package/FlowGraph/Blocks/Event/flowGraphSoundEndedEventBlock.pure.d.ts +5 -3
- package/FlowGraph/Blocks/Event/flowGraphSoundEndedEventBlock.pure.js +38 -7
- package/FlowGraph/Blocks/Event/flowGraphSoundEndedEventBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Event/index.d.ts +1 -0
- package/FlowGraph/Blocks/Event/index.js +1 -0
- package/FlowGraph/Blocks/Event/index.js.map +1 -1
- package/FlowGraph/Blocks/Event/pure.d.ts +1 -0
- package/FlowGraph/Blocks/Event/pure.js +1 -0
- package/FlowGraph/Blocks/Event/pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPauseSoundBlock.pure.d.ts +3 -3
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPauseSoundBlock.pure.js +2 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPauseSoundBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPlaySoundBlock.pure.d.ts +3 -3
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPlaySoundBlock.pure.js +2 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPlaySoundBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphSetSoundVolumeBlock.pure.d.ts +3 -3
- package/FlowGraph/Blocks/Execution/Audio/flowGraphSetSoundVolumeBlock.pure.js +2 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphSetSoundVolumeBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphStopSoundBlock.pure.d.ts +3 -3
- package/FlowGraph/Blocks/Execution/Audio/flowGraphStopSoundBlock.pure.js +2 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphStopSoundBlock.pure.js.map +1 -1
- package/FlowGraph/Blocks/allBlocks.pure.js +2 -0
- package/FlowGraph/Blocks/allBlocks.pure.js.map +1 -1
- package/FlowGraph/Blocks/flowGraphBlockFactory.js +2 -0
- package/FlowGraph/Blocks/flowGraphBlockFactory.js.map +1 -1
- package/FlowGraph/Blocks/flowGraphBlockNames.d.ts +1 -0
- package/FlowGraph/Blocks/flowGraphBlockNames.js +1 -0
- package/FlowGraph/Blocks/flowGraphBlockNames.js.map +1 -1
- package/FlowGraph/flowGraph.d.ts +12 -1
- package/FlowGraph/flowGraph.js +38 -0
- package/FlowGraph/flowGraph.js.map +1 -1
- package/FlowGraph/flowGraphCoordinator.d.ts +44 -0
- package/FlowGraph/flowGraphCoordinator.js +141 -0
- package/FlowGraph/flowGraphCoordinator.js.map +1 -1
- package/FlowGraph/flowGraphDataConnection.pure.js +41 -14
- package/FlowGraph/flowGraphDataConnection.pure.js.map +1 -1
- package/FlowGraph/flowGraphParser.js +105 -5
- package/FlowGraph/flowGraphParser.js.map +1 -1
- package/FlowGraph/flowGraphSoundAssets.d.ts +40 -0
- package/FlowGraph/flowGraphSoundAssets.js +33 -0
- package/FlowGraph/flowGraphSoundAssets.js.map +1 -0
- package/FlowGraph/index.d.ts +1 -0
- package/FlowGraph/index.js +1 -0
- package/FlowGraph/index.js.map +1 -1
- package/FlowGraph/pure.d.ts +1 -0
- package/FlowGraph/pure.js +1 -0
- package/FlowGraph/pure.js.map +1 -1
- package/FlowGraph/serialization.d.ts +8 -0
- package/FlowGraph/serialization.js +31 -12
- package/FlowGraph/serialization.js.map +1 -1
- package/FlowGraph/typeDefinitions.d.ts +25 -0
- package/FlowGraph/typeDefinitions.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/taaTask.js +2 -0
- package/FrameGraph/Tasks/PostProcesses/taaTask.js.map +1 -1
- package/Instrumentation/engineInstrumentation.d.ts +1 -0
- package/Instrumentation/engineInstrumentation.js +25 -6
- package/Instrumentation/engineInstrumentation.js.map +1 -1
- package/Lights/Clustered/clusteredLightContainer.pure.js +2 -0
- package/Lights/Clustered/clusteredLightContainer.pure.js.map +1 -1
- package/Lights/Shadows/cascadedShadowGenerator.pure.d.ts +36 -1
- package/Lights/Shadows/cascadedShadowGenerator.pure.js +202 -27
- package/Lights/Shadows/cascadedShadowGenerator.pure.js.map +1 -1
- package/Lights/directionalLight.pure.d.ts +24 -10
- package/Lights/directionalLight.pure.js +29 -11
- package/Lights/directionalLight.pure.js.map +1 -1
- package/Loading/sceneLoader.d.ts +1 -1
- package/Loading/sceneLoader.js +1 -1
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.pure.js +4 -4
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.pure.js.map +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.pure.js +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.pure.js.map +1 -1
- package/Materials/Node/Blocks/Input/inputBlock.pure.js +4 -0
- package/Materials/Node/Blocks/Input/inputBlock.pure.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.d.ts +9 -0
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js +23 -3
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js.map +1 -1
- package/Materials/PBR/openpbrMaterial.pure.js +1 -1
- package/Materials/PBR/openpbrMaterial.pure.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.pure.d.ts +9 -0
- package/Materials/PBR/pbrBaseMaterial.pure.js +60 -1
- package/Materials/PBR/pbrBaseMaterial.pure.js.map +1 -1
- package/Materials/PBR/pbrBaseSimpleMaterial.d.ts +11 -0
- package/Materials/PBR/pbrBaseSimpleMaterial.js +21 -2
- package/Materials/PBR/pbrBaseSimpleMaterial.js.map +1 -1
- package/Materials/PBR/pbrMaterial.pure.d.ts +12 -0
- package/Materials/PBR/pbrMaterial.pure.js +23 -3
- package/Materials/PBR/pbrMaterial.pure.js.map +1 -1
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +1 -0
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +10 -0
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -1
- package/Materials/Textures/HTML/htmlInCanvasPolyfill.d.ts +5 -0
- package/Materials/Textures/HTML/htmlInCanvasPolyfill.js +7 -0
- package/Materials/Textures/HTML/htmlInCanvasPolyfill.js.map +1 -1
- package/Materials/Textures/HTML/htmlInteractionManager.d.ts +9 -3
- package/Materials/Textures/HTML/htmlInteractionManager.js +64 -5
- package/Materials/Textures/HTML/htmlInteractionManager.js.map +1 -1
- package/Materials/Textures/HTML/htmlTexture.d.ts +11 -11
- package/Materials/Textures/HTML/htmlTexture.js +106 -65
- package/Materials/Textures/HTML/htmlTexture.js.map +1 -1
- package/Materials/Textures/Loaders/internalTextureLoader.d.ts +2 -1
- package/Materials/Textures/Loaders/internalTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/ktxTextureLoader.d.ts +2 -1
- package/Materials/Textures/Loaders/ktxTextureLoader.js +4 -50
- package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.pure.js +10 -0
- package/Materials/Textures/Procedurals/proceduralTexture.pure.js.map +1 -1
- package/Materials/Textures/dynamicTexture.pure.js +6 -0
- package/Materials/Textures/dynamicTexture.pure.js.map +1 -1
- package/Materials/Textures/ktx2encoderTypes.d.ts +51 -0
- package/Materials/Textures/ktx2encoderTypes.js +2 -0
- package/Materials/Textures/ktx2encoderTypes.js.map +1 -0
- package/Materials/Textures/renderTargetTexture.pure.js +10 -2
- package/Materials/Textures/renderTargetTexture.pure.js.map +1 -1
- package/Materials/Textures/textureMerger.d.ts +11 -0
- package/Materials/Textures/textureMerger.js +34 -19
- package/Materials/Textures/textureMerger.js.map +1 -1
- package/Materials/Textures/textureProcessor.d.ts +145 -0
- package/Materials/Textures/textureProcessor.js +445 -45
- package/Materials/Textures/textureProcessor.js.map +1 -1
- package/Materials/Textures/textureSampling.functions.d.ts +41 -0
- package/Materials/Textures/textureSampling.functions.js +82 -0
- package/Materials/Textures/textureSampling.functions.js.map +1 -0
- package/Materials/drawWrapper.d.ts +8 -0
- package/Materials/drawWrapper.js +19 -0
- package/Materials/drawWrapper.js.map +1 -1
- package/Materials/effect.pure.d.ts +6 -0
- package/Materials/effect.pure.js +28 -6
- package/Materials/effect.pure.js.map +1 -1
- package/Materials/effect.webgl.functions.pure.js +1 -1
- package/Materials/effect.webgl.functions.pure.js.map +1 -1
- package/Materials/material.pure.d.ts +5 -0
- package/Materials/material.pure.js +9 -2
- package/Materials/material.pure.js.map +1 -1
- package/Materials/materialFlags.d.ts +6 -0
- package/Materials/materialFlags.js +14 -0
- package/Materials/materialFlags.js.map +1 -1
- package/Materials/materialHelper.functions.d.ts +2 -1
- package/Materials/materialHelper.functions.js +36 -2
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/materialHelper.geometryrendering.js +19 -16
- package/Materials/materialHelper.geometryrendering.js.map +1 -1
- package/Materials/materialPluginManager.pure.js +12 -8
- package/Materials/materialPluginManager.pure.js.map +1 -1
- package/Materials/prePassConfiguration.js +19 -16
- package/Materials/prePassConfiguration.js.map +1 -1
- package/Materials/shaderMaterial.pure.js +19 -6
- package/Materials/shaderMaterial.pure.js.map +1 -1
- package/Materials/shadowDepthWrapper.d.ts +6 -0
- package/Materials/shadowDepthWrapper.js +17 -0
- package/Materials/shadowDepthWrapper.js.map +1 -1
- package/Meshes/Compression/dracoCodec.d.ts +14 -0
- package/Meshes/Compression/dracoCodec.js +22 -0
- package/Meshes/Compression/dracoCodec.js.map +1 -1
- package/Meshes/Compression/dracoDecoder.d.ts +1 -0
- package/Meshes/Compression/dracoDecoder.js +27 -0
- package/Meshes/Compression/dracoDecoder.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.d.ts +1 -0
- package/Meshes/Compression/dracoEncoder.js +8 -0
- package/Meshes/Compression/dracoEncoder.js.map +1 -1
- package/Meshes/Compression/meshoptCompression.d.ts +1 -0
- package/Meshes/Compression/meshoptCompression.js +9 -0
- package/Meshes/Compression/meshoptCompression.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.d.ts +415 -0
- package/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.js +912 -0
- package/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.js.map +1 -0
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.d.ts +3 -0
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js +40 -9
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.d.ts +112 -8
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js +696 -74
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js.map +1 -1
- package/Meshes/abstractMesh.pure.js +12 -4
- package/Meshes/abstractMesh.pure.js.map +1 -1
- package/Meshes/geometry.d.ts +5 -0
- package/Meshes/geometry.js +25 -0
- package/Meshes/geometry.js.map +1 -1
- package/Meshes/index.d.ts +1 -0
- package/Meshes/index.js +1 -0
- package/Meshes/index.js.map +1 -1
- package/Meshes/mesh.pure.d.ts +7 -0
- package/Meshes/mesh.pure.js +18 -13
- package/Meshes/mesh.pure.js.map +1 -1
- package/Meshes/pure.d.ts +1 -0
- package/Meshes/pure.js +1 -0
- package/Meshes/pure.js.map +1 -1
- package/Meshes/subMesh.pure.d.ts +3 -0
- package/Meshes/subMesh.pure.js +26 -0
- package/Meshes/subMesh.pure.js.map +1 -1
- package/Meshes/thinInstanceMesh.pure.js +5 -3
- package/Meshes/thinInstanceMesh.pure.js.map +1 -1
- package/Misc/index.d.ts +1 -0
- package/Misc/index.js +1 -0
- package/Misc/index.js.map +1 -1
- package/Misc/khronosTextureContainer2.d.ts +3 -2
- package/Misc/khronosTextureContainer2.js +24 -6
- package/Misc/khronosTextureContainer2.js.map +1 -1
- package/Misc/khronosTextureContainer2Encoder.d.ts +166 -0
- package/Misc/khronosTextureContainer2Encoder.js +556 -0
- package/Misc/khronosTextureContainer2Encoder.js.map +1 -0
- package/Misc/khronosTextureContainer2EncoderWorker.d.ts +61 -0
- package/Misc/khronosTextureContainer2EncoderWorker.js +55 -0
- package/Misc/khronosTextureContainer2EncoderWorker.js.map +1 -0
- package/Misc/pure.d.ts +1 -0
- package/Misc/pure.js +1 -0
- package/Misc/pure.js.map +1 -1
- package/Misc/textureFormat.functions.d.ts +6 -0
- package/Misc/textureFormat.functions.js +54 -0
- package/Misc/textureFormat.functions.js.map +1 -0
- package/Misc/textureTools.d.ts +6 -2
- package/Misc/textureTools.js +100 -42
- package/Misc/textureTools.js.map +1 -1
- package/Misc/tools.pure.js +1 -1
- package/Misc/tools.pure.js.map +1 -1
- package/Particles/Node/Blocks/systemBlock.pure.d.ts +1 -1
- package/Particles/Node/Blocks/systemBlock.pure.js +6 -3
- package/Particles/Node/Blocks/systemBlock.pure.js.map +1 -1
- package/Particles/computeShaderParticleSystem.pure.js +5 -0
- package/Particles/computeShaderParticleSystem.pure.js.map +1 -1
- package/Particles/gpuParticleSystem.pure.d.ts +2 -0
- package/Particles/gpuParticleSystem.pure.js +25 -1
- package/Particles/gpuParticleSystem.pure.js.map +1 -1
- package/Particles/solidParticle.d.ts +5 -0
- package/Particles/solidParticle.js +5 -0
- package/Particles/solidParticle.js.map +1 -1
- package/Particles/solidParticleSystem.d.ts +10 -0
- package/Particles/solidParticleSystem.js +72 -13
- package/Particles/solidParticleSystem.js.map +1 -1
- package/Particles/thinParticleSystem.pure.js +4 -0
- package/Particles/thinParticleSystem.pure.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/taaMaterialManager.pure.d.ts +27 -6
- package/PostProcesses/RenderPipeline/Pipelines/taaMaterialManager.pure.js +60 -5
- package/PostProcesses/RenderPipeline/Pipelines/taaMaterialManager.pure.js.map +1 -1
- package/PostProcesses/thinTAAPostProcess.d.ts +1 -0
- package/PostProcesses/thinTAAPostProcess.js +17 -1
- package/PostProcesses/thinTAAPostProcess.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.pure.d.ts +2 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.pure.js +6 -5
- package/PostProcesses/volumetricLightScatteringPostProcess.pure.js.map +1 -1
- package/Rendering/boundingBoxRenderer.pure.js +2 -3
- package/Rendering/boundingBoxRenderer.pure.js.map +1 -1
- package/Rendering/geometryBufferRenderer.pure.js +8 -2
- package/Rendering/geometryBufferRenderer.pure.js.map +1 -1
- package/Rendering/objectRenderer.d.ts +1 -0
- package/Rendering/objectRenderer.js +14 -0
- package/Rendering/objectRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js +2 -2
- package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/bumpVertex.js +1 -1
- package/Shaders/ShadersInclude/bumpVertex.js.map +1 -1
- package/Shaders/ShadersInclude/bumpVertexDeclaration.js +1 -1
- package/Shaders/ShadersInclude/bumpVertexDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/hdrFilteringFunctions.js +5 -1
- package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js +2 -2
- package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js +1 -1
- package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -1
- package/Shaders/ShadersInclude/openpbrVertexDeclaration.js +6 -0
- package/Shaders/ShadersInclude/openpbrVertexDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockFinalLitComponents.js +11 -1
- package/Shaders/ShadersInclude/pbrBlockFinalLitComponents.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockNormalFinal.js +9 -0
- package/Shaders/ShadersInclude/pbrBlockNormalFinal.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflectance.js +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflectance.js.map +1 -1
- package/Shaders/ShadersInclude/pbrClusteredLightingFunctions.js +1 -1
- package/Shaders/ShadersInclude/pbrClusteredLightingFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js +7 -1
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -0
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrIBLFunctions.js +12 -0
- package/Shaders/ShadersInclude/pbrIBLFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrUboDeclaration.js +1 -1
- package/Shaders/ShadersInclude/pbrUboDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js +3 -0
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js.map +1 -1
- package/Shaders/geometry.vertex.js +6 -6
- package/Shaders/geometry.vertex.js.map +1 -1
- package/Shaders/gpuUpdateParticles.vertex.js +1 -1
- package/Shaders/gpuUpdateParticles.vertex.js.map +1 -1
- package/Shaders/lod.fragment.js +15 -2
- package/Shaders/lod.fragment.js.map +1 -1
- package/Shaders/lod3D.fragment.js +15 -2
- package/Shaders/lod3D.fragment.js.map +1 -1
- package/Shaders/lodCube.fragment.js +15 -2
- package/Shaders/lodCube.fragment.js.map +1 -1
- package/Shaders/openpbr.vertex.js +2 -0
- package/Shaders/openpbr.vertex.js.map +1 -1
- package/Shaders/pbr.fragment.js +12 -1
- package/Shaders/pbr.fragment.js.map +1 -1
- package/Shaders/pbr.vertex.js +2 -0
- package/Shaders/pbr.vertex.js.map +1 -1
- package/Shaders/textureMerger.fragment.js +28 -0
- package/Shaders/textureMerger.fragment.js.map +1 -1
- package/Shaders/textureProcessor.fragment.js +26 -4
- package/Shaders/textureProcessor.fragment.js.map +1 -1
- package/Shaders/volumetricLightScattering.fragment.js +1 -1
- package/Shaders/volumetricLightScattering.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/bumpFragmentMainFunctions.js +2 -2
- package/ShadersWGSL/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/bumpVertex.js +1 -1
- package/ShadersWGSL/ShadersInclude/bumpVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/bumpVertexDeclaration.js +1 -1
- package/ShadersWGSL/ShadersInclude/bumpVertexDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js +1 -1
- package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/helperFunctions.js +2 -2
- package/ShadersWGSL/ShadersInclude/helperFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/lightFragment.js +44 -2
- package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js +17 -3
- package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/lightVxUboDeclaration.js +12 -1
- package/ShadersWGSL/ShadersInclude/lightVxUboDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js +1 -1
- package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockFinalLitComponents.js +11 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockFinalLitComponents.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockNormalFinal.js +9 -0
- package/ShadersWGSL/ShadersInclude/pbrBlockNormalFinal.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectance.js +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflectance.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js +1 -1
- package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -0
- package/ShadersWGSL/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrIBLFunctions.js +8 -0
- package/ShadersWGSL/ShadersInclude/pbrIBLFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js +1 -1
- package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassVertex.js +2 -2
- package/ShadersWGSL/ShadersInclude/prePassVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js +1 -1
- package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/sceneUboDeclaration.js +3 -1
- package/ShadersWGSL/ShadersInclude/sceneUboDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/shadowsVertex.js +16 -0
- package/ShadersWGSL/ShadersInclude/shadowsVertex.js.map +1 -1
- package/ShadersWGSL/default.fragment.js +4 -4
- package/ShadersWGSL/default.fragment.js.map +1 -1
- package/ShadersWGSL/default.vertex.js +1 -1
- package/ShadersWGSL/default.vertex.js.map +1 -1
- package/ShadersWGSL/gaussianSplatting.vertex.js +3 -3
- package/ShadersWGSL/gaussianSplatting.vertex.js.map +1 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js +1 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
- package/ShadersWGSL/gsSortCount.compute.d.ts +5 -0
- package/ShadersWGSL/gsSortCount.compute.js +19 -0
- package/ShadersWGSL/gsSortCount.compute.js.map +1 -0
- package/ShadersWGSL/gsSortKeys.compute.d.ts +5 -0
- package/ShadersWGSL/gsSortKeys.compute.js +49 -0
- package/ShadersWGSL/gsSortKeys.compute.js.map +1 -0
- package/ShadersWGSL/gsSortOutput.compute.d.ts +5 -0
- package/ShadersWGSL/gsSortOutput.compute.js +28 -0
- package/ShadersWGSL/gsSortOutput.compute.js.map +1 -0
- package/ShadersWGSL/gsSortScanLocal.compute.d.ts +5 -0
- package/ShadersWGSL/gsSortScanLocal.compute.js +23 -0
- package/ShadersWGSL/gsSortScanLocal.compute.js.map +1 -0
- package/ShadersWGSL/gsSortScanSums.compute.d.ts +5 -0
- package/ShadersWGSL/gsSortScanSums.compute.js +19 -0
- package/ShadersWGSL/gsSortScanSums.compute.js.map +1 -0
- package/ShadersWGSL/gsSortScatter.compute.d.ts +5 -0
- package/ShadersWGSL/gsSortScatter.compute.js +33 -0
- package/ShadersWGSL/gsSortScatter.compute.js.map +1 -0
- package/ShadersWGSL/lod.fragment.js +14 -2
- package/ShadersWGSL/lod.fragment.js.map +1 -1
- package/ShadersWGSL/lod3D.fragment.js +14 -2
- package/ShadersWGSL/lod3D.fragment.js.map +1 -1
- package/ShadersWGSL/lodCube.fragment.js +14 -2
- package/ShadersWGSL/lodCube.fragment.js.map +1 -1
- package/ShadersWGSL/openpbr.vertex.js +3 -1
- package/ShadersWGSL/openpbr.vertex.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +11 -0
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.vertex.js +3 -1
- package/ShadersWGSL/pbr.vertex.js.map +1 -1
- package/ShadersWGSL/textureMerger.fragment.js +40 -4
- package/ShadersWGSL/textureMerger.fragment.js.map +1 -1
- package/ShadersWGSL/textureProcessor.fragment.js +26 -4
- package/ShadersWGSL/textureProcessor.fragment.js.map +1 -1
- package/Sprites/spriteRenderer.js +15 -5
- package/Sprites/spriteRenderer.js.map +1 -1
- package/package.json +1 -1
- package/scene.pure.d.ts +23 -1
- package/scene.pure.js +83 -1
- package/scene.pure.js.map +1 -1
|
@@ -57,6 +57,12 @@ export declare class ShadowDepthWrapper {
|
|
|
57
57
|
* @returns the effect to use to generate the depth map for the subMesh + shadow generator specified
|
|
58
58
|
*/
|
|
59
59
|
getEffect(subMesh: Nullable<SubMesh>, shadowGenerator: ShadowGenerator, passIdForDrawWrapper: number): Nullable<DrawWrapper>;
|
|
60
|
+
/**
|
|
61
|
+
* Invalidates cached vertex bindings for this submesh without releasing shadow draw resources.
|
|
62
|
+
* @param subMesh defines the submesh whose shadow draws must be invalidated
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
_invalidateVertexBuffers(subMesh: SubMesh): void;
|
|
60
66
|
/**
|
|
61
67
|
* Specifies that the submesh is ready to be used for depth rendering
|
|
62
68
|
* @param subMesh submesh to check
|
|
@@ -105,6 +105,23 @@ export class ShadowDepthWrapper {
|
|
|
105
105
|
}
|
|
106
106
|
return drawWrapper;
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Invalidates cached vertex bindings for this submesh without releasing shadow draw resources.
|
|
110
|
+
* @param subMesh defines the submesh whose shadow draws must be invalidated
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
_invalidateVertexBuffers(subMesh) {
|
|
114
|
+
const entries = this._subMeshToDepthWrapper.mm.get(subMesh);
|
|
115
|
+
if (!entries) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
for (const entry of entries.values()) {
|
|
119
|
+
entry.mainDrawWrapper.drawContext?._invalidateVertexBuffers?.();
|
|
120
|
+
for (const drawWrapper of entry.drawWrapper) {
|
|
121
|
+
drawWrapper?.drawContext?._invalidateVertexBuffers?.();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
108
125
|
/**
|
|
109
126
|
* Specifies that the submesh is ready to be used for depth rendering
|
|
110
127
|
* @param subMesh submesh to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadowDepthWrapper.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/shadowDepthWrapper.ts"],"names":[],"mappings":"AAKA,OAAO,EAA+B,MAAM,EAAE,MAAM,UAAU,CAAC;AAI/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAwBrD,MAAM,MAAM;IAAZ;QACa,OAAE,GAAG,IAAI,GAAG,EAAkB,CAAC;IAiB5C,CAAC;IAfG,GAAG,CAAC,CAAK,EAAE,CAAK;QACZ,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,SAA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{ type Observer } from \"../Misc/observable\";\r\nimport { type Nullable } from \"../types\";\r\nimport { type Scene } from \"../scene\";\r\nimport { type SubMesh } from \"../Meshes/subMesh\";\r\nimport { type Material } from \"./material\";\r\nimport { type IEffectCreationOptions, Effect } from \"./effect\";\r\nimport { type AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { type Node } from \"../node\";\r\nimport { type ShadowGenerator } from \"../Lights/Shadows/shadowGenerator\";\r\nimport { RandomGUID } from \"../Misc/guid\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\n/**\r\n * Options to be used when creating a shadow depth material\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface IIOptionShadowDepthMaterial {\r\n /** Variables in the vertex shader code that need to have their names remapped.\r\n * The format is: [\"var_name\", \"var_remapped_name\", \"var_name\", \"var_remapped_name\", ...]\r\n * \"var_name\" should be either: worldPos or vNormalW\r\n * So, if the variable holding the world position in your vertex shader is not named worldPos, you must tell the system\r\n * the name to use instead by using: [\"worldPos\", \"myWorldPosVar\"] assuming the variable is named myWorldPosVar in your code.\r\n * If the normal must also be remapped: [\"worldPos\", \"myWorldPosVar\", \"vNormalW\", \"myWorldNormal\"]\r\n */\r\n remappedVariables?: string[];\r\n\r\n /** Set standalone to true if the base material wrapped by ShadowDepthMaterial is not used for a regular object but for depth shadow generation only */\r\n standalone?: boolean;\r\n\r\n /** Set doNotInjectCode if the specific shadow map generation code is already implemented by the material. That will prevent this code to be injected twice by ShadowDepthWrapper */\r\n doNotInjectCode?: boolean;\r\n}\r\n\r\nclass MapMap<Ka, Kb, V> {\r\n readonly mm = new Map<Ka, Map<Kb, V>>();\r\n\r\n get(a: Ka, b: Kb): V | undefined {\r\n const m = this.mm.get(a);\r\n if (m !== undefined) {\r\n return m.get(b);\r\n }\r\n return undefined;\r\n }\r\n\r\n set(a: Ka, b: Kb, v: V): void {\r\n let m = this.mm.get(a);\r\n if (m === undefined) {\r\n this.mm.set(a, (m = new Map()));\r\n }\r\n m.set(b, v);\r\n }\r\n}\r\n\r\n/**\r\n * Class that can be used to wrap a base material to generate accurate shadows when using custom vertex/fragment code in the base material\r\n */\r\nexport class ShadowDepthWrapper {\r\n private _scene: Scene;\r\n private _options?: IIOptionShadowDepthMaterial;\r\n private _baseMaterial: Material;\r\n private _onEffectCreatedObserver: Nullable<Observer<{ effect: Effect; subMesh: Nullable<SubMesh> }>>;\r\n private _subMeshToEffect: Map<Nullable<SubMesh>, [Effect, number]>;\r\n private _subMeshToDepthWrapper: MapMap<\r\n Nullable<SubMesh>,\r\n ShadowGenerator,\r\n { drawWrapper: Array<Nullable<DrawWrapper>>; mainDrawWrapper: DrawWrapper; depthDefines: string; token: string }\r\n >; // key is (subMesh + shadowGenerator)\r\n private _meshes: Map<AbstractMesh, Nullable<Observer<Node>>>;\r\n\r\n /** Gets the standalone status of the wrapper */\r\n public get standalone(): boolean {\r\n return this._options?.standalone ?? false;\r\n }\r\n\r\n /** Gets the base material the wrapper is built upon */\r\n public get baseMaterial(): Material {\r\n return this._baseMaterial;\r\n }\r\n\r\n /** Gets the doNotInjectCode status of the wrapper */\r\n public get doNotInjectCode(): boolean {\r\n return this._options?.doNotInjectCode ?? false;\r\n }\r\n\r\n /**\r\n * Instantiate a new shadow depth wrapper.\r\n * It works by injecting some specific code in the vertex/fragment shaders of the base material and is used by a shadow generator to\r\n * generate the shadow depth map. For more information, please refer to the documentation:\r\n * https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\r\n * @param baseMaterial Material to wrap\r\n * @param scene Define the scene the material belongs to\r\n * @param options Options used to create the wrapper\r\n */\r\n constructor(baseMaterial: Material, scene?: Scene, options?: IIOptionShadowDepthMaterial) {\r\n this._baseMaterial = baseMaterial;\r\n this._scene = scene ?? <Scene>EngineStore.LastCreatedScene;\r\n this._options = options;\r\n\r\n this._subMeshToEffect = new Map();\r\n this._subMeshToDepthWrapper = new MapMap();\r\n this._meshes = new Map();\r\n\r\n // Register for onEffectCreated to store the effect of the base material when it is (re)generated. This effect will be used\r\n // to create the depth effect later on\r\n this._onEffectCreatedObserver = this._baseMaterial.onEffectCreatedObservable.add((params: { effect: Effect; subMesh: Nullable<SubMesh> }) => {\r\n const mesh = params.subMesh?.getMesh();\r\n\r\n if (mesh && !this._meshes.has(mesh)) {\r\n // Register for mesh onDispose to clean up our internal maps when a mesh is disposed\r\n this._meshes.set(\r\n mesh,\r\n mesh.onDisposeObservable.add((mesh: Node) => {\r\n const iterator = this._subMeshToEffect.keys();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const subMesh = key.value;\r\n if (subMesh?.getMesh() === (mesh as AbstractMesh)) {\r\n this._subMeshToEffect.delete(subMesh);\r\n this._deleteDepthWrapperEffect(subMesh);\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n if (this._subMeshToEffect.get(params.subMesh)?.[0] !== params.effect) {\r\n this._subMeshToEffect.set(params.subMesh, [params.effect, this._scene.getEngine().currentRenderPassId]);\r\n this._deleteDepthWrapperEffect(params.subMesh);\r\n }\r\n });\r\n }\r\n\r\n private _deleteDepthWrapperEffect(subMesh: Nullable<SubMesh>): void {\r\n const depthWrapperEntries = this._subMeshToDepthWrapper.mm.get(subMesh);\r\n if (depthWrapperEntries) {\r\n // find and release the previous depth effect\r\n depthWrapperEntries.forEach((depthWrapper) => {\r\n depthWrapper.mainDrawWrapper.effect?.dispose();\r\n });\r\n this._subMeshToDepthWrapper.mm.delete(subMesh); // trigger a depth effect recreation\r\n }\r\n }\r\n\r\n /**\r\n * Gets the effect to use to generate the depth map\r\n * @param subMesh subMesh to get the effect for\r\n * @param shadowGenerator shadow generator to get the effect for\r\n * @param passIdForDrawWrapper Id of the pass for which the effect from the draw wrapper must be retrieved from\r\n * @returns the effect to use to generate the depth map for the subMesh + shadow generator specified\r\n */\r\n public getEffect(subMesh: Nullable<SubMesh>, shadowGenerator: ShadowGenerator, passIdForDrawWrapper: number): Nullable<DrawWrapper> {\r\n const entry = this._subMeshToDepthWrapper.mm.get(subMesh)?.get(shadowGenerator);\r\n if (!entry) {\r\n return null;\r\n }\r\n let drawWrapper = entry.drawWrapper[passIdForDrawWrapper];\r\n if (!drawWrapper) {\r\n drawWrapper = entry.drawWrapper[passIdForDrawWrapper] = new DrawWrapper(this._scene.getEngine());\r\n drawWrapper.setEffect(entry.mainDrawWrapper.effect, entry.mainDrawWrapper.defines);\r\n }\r\n\r\n return drawWrapper;\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used for depth rendering\r\n * @param subMesh submesh to check\r\n * @param defines the list of defines to take into account when checking the effect\r\n * @param shadowGenerator combined with subMesh, it defines the effect to check\r\n * @param useInstances specifies that instances should be used\r\n * @param passIdForDrawWrapper Id of the pass for which the draw wrapper should be created\r\n * @returns a boolean indicating that the submesh is ready or not\r\n */\r\n public isReadyForSubMesh(subMesh: SubMesh, defines: string[], shadowGenerator: ShadowGenerator, useInstances: boolean, passIdForDrawWrapper: number): boolean {\r\n if (this.standalone) {\r\n // will ensure the effect is (re)created for the base material\r\n if (!this._baseMaterial.isReadyForSubMesh(subMesh.getMesh(), subMesh, useInstances)) {\r\n return false;\r\n }\r\n }\r\n\r\n return this._makeEffect(subMesh, defines, shadowGenerator, passIdForDrawWrapper)?.isReady() ?? false;\r\n }\r\n\r\n /**\r\n * Disposes the resources\r\n */\r\n public dispose(): void {\r\n this._baseMaterial.onEffectCreatedObservable.remove(this._onEffectCreatedObserver);\r\n this._onEffectCreatedObserver = null;\r\n\r\n const iterator = this._meshes.entries();\r\n for (let entry = iterator.next(); entry.done !== true; entry = iterator.next()) {\r\n const [mesh, observer] = entry.value;\r\n\r\n mesh.onDisposeObservable.remove(observer);\r\n }\r\n }\r\n\r\n private _makeEffect(subMesh: SubMesh, defines: string[], shadowGenerator: ShadowGenerator, passIdForDrawWrapper: number): Nullable<Effect> {\r\n const engine = this._scene.getEngine();\r\n const origEffectAndRenderPassId = this._subMeshToEffect.get(subMesh);\r\n\r\n if (!origEffectAndRenderPassId) {\r\n return null;\r\n }\r\n\r\n const [origEffect, origRenderPassId] = origEffectAndRenderPassId;\r\n\r\n if (!origEffect.isReady()) {\r\n return null;\r\n }\r\n\r\n let params = this._subMeshToDepthWrapper.get(subMesh, shadowGenerator);\r\n if (!params) {\r\n const mainDrawWrapper = new DrawWrapper(engine);\r\n const originalDefines = subMesh._getDrawWrapper(origRenderPassId)?.defines;\r\n mainDrawWrapper.defines = typeof originalDefines === \"string\" ? null : (originalDefines ?? null);\r\n\r\n params = {\r\n drawWrapper: [],\r\n mainDrawWrapper,\r\n depthDefines: \"\",\r\n token: RandomGUID(),\r\n };\r\n params.drawWrapper[passIdForDrawWrapper] = mainDrawWrapper;\r\n this._subMeshToDepthWrapper.set(subMesh, shadowGenerator, params);\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (params.mainDrawWrapper.effect) {\r\n if (join === params.depthDefines) {\r\n // we already created the depth effect and it is still up to date for this submesh + shadow generator\r\n return params.mainDrawWrapper.effect;\r\n }\r\n }\r\n\r\n params.depthDefines = join;\r\n\r\n const uniforms = origEffect.getUniformNames().slice();\r\n\r\n // the depth effect is either out of date or has not been created yet\r\n let vertexCode = origEffect.vertexSourceCodeBeforeMigration,\r\n fragmentCode = origEffect.fragmentSourceCodeBeforeMigration;\r\n\r\n if (!vertexCode && !fragmentCode) {\r\n return null;\r\n }\r\n\r\n if (!this.doNotInjectCode) {\r\n // Declare the shadow map includes\r\n const vertexNormalBiasCode =\r\n this._options && this._options.remappedVariables\r\n ? `#include<shadowMapVertexNormalBias>(${this._options.remappedVariables.join(\",\")})`\r\n : `#include<shadowMapVertexNormalBias>`,\r\n vertexMetricCode =\r\n this._options && this._options.remappedVariables\r\n ? `#include<shadowMapVertexMetric>(${this._options.remappedVariables.join(\",\")})`\r\n : `#include<shadowMapVertexMetric>`,\r\n fragmentSoftTransparentShadow =\r\n this._options && this._options.remappedVariables\r\n ? `#include<shadowMapFragmentSoftTransparentShadow>(${this._options.remappedVariables.join(\",\")})`\r\n : `#include<shadowMapFragmentSoftTransparentShadow>`,\r\n fragmentBlockCode = `#include<shadowMapFragment>`,\r\n vertexExtraDeclartion = `#include<shadowMapVertexExtraDeclaration>`;\r\n\r\n // vertex code\r\n if (origEffect.shaderLanguage === ShaderLanguage.GLSL) {\r\n vertexCode = vertexCode.replace(/void\\s+?main/g, `\\n${vertexExtraDeclartion}\\nvoid main`);\r\n } else {\r\n vertexCode = vertexCode.replace(/@vertex/g, `\\n${vertexExtraDeclartion}\\n@vertex`);\r\n }\r\n vertexCode = vertexCode.replace(/#define SHADOWDEPTH_NORMALBIAS|#define CUSTOM_VERTEX_UPDATE_WORLDPOS/g, vertexNormalBiasCode);\r\n\r\n if (vertexCode.indexOf(\"#define SHADOWDEPTH_METRIC\") !== -1) {\r\n vertexCode = vertexCode.replace(/#define SHADOWDEPTH_METRIC/g, vertexMetricCode);\r\n } else {\r\n vertexCode = vertexCode.replace(/}\\s*$/g, vertexMetricCode + \"\\n}\");\r\n }\r\n vertexCode = vertexCode.replace(/#define SHADER_NAME.*?\\n|out vec4 glFragColor;\\n/g, \"\");\r\n\r\n // fragment code\r\n const hasLocationForSoftTransparentShadow =\r\n fragmentCode.indexOf(\"#define SHADOWDEPTH_SOFTTRANSPARENTSHADOW\") >= 0 || fragmentCode.indexOf(\"#define CUSTOM_FRAGMENT_BEFORE_FOG\") >= 0;\r\n const hasLocationForFragment = fragmentCode.indexOf(\"#define SHADOWDEPTH_FRAGMENT\") !== -1;\r\n\r\n let fragmentCodeToInjectAtEnd = \"\";\r\n\r\n if (!hasLocationForSoftTransparentShadow) {\r\n fragmentCodeToInjectAtEnd = fragmentSoftTransparentShadow + \"\\n\";\r\n } else {\r\n fragmentCode = fragmentCode.replace(/#define SHADOWDEPTH_SOFTTRANSPARENTSHADOW|#define CUSTOM_FRAGMENT_BEFORE_FOG/g, fragmentSoftTransparentShadow);\r\n }\r\n\r\n fragmentCode = fragmentCode.replace(/void\\s+?main/g, Effect.IncludesShadersStore[\"shadowMapFragmentExtraDeclaration\"] + \"\\nvoid main\");\r\n\r\n if (hasLocationForFragment) {\r\n fragmentCode = fragmentCode.replace(/#define SHADOWDEPTH_FRAGMENT/g, fragmentBlockCode);\r\n } else {\r\n fragmentCodeToInjectAtEnd += fragmentBlockCode + \"\\n\";\r\n }\r\n if (fragmentCodeToInjectAtEnd) {\r\n fragmentCode = fragmentCode.replace(/}\\s*$/g, fragmentCodeToInjectAtEnd + \"}\");\r\n }\r\n\r\n uniforms.push(\"biasAndScaleSM\", \"depthValuesSM\", \"lightDataSM\", \"softTransparentShadowSM\");\r\n }\r\n\r\n params.mainDrawWrapper.effect = engine.createEffect(\r\n {\r\n vertexSource: vertexCode,\r\n fragmentSource: fragmentCode,\r\n vertexToken: params.token,\r\n fragmentToken: params.token,\r\n },\r\n <IEffectCreationOptions>{\r\n attributes: origEffect.getAttributesNames(),\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: origEffect.getUniformBuffersNames(),\r\n samplers: origEffect.getSamplers(),\r\n defines: join + \"\\n\" + origEffect.defines.replace(\"#define SHADOWS\", \"\").replace(/#define SHADOW\\d/g, \"\"),\r\n indexParameters: origEffect.getIndexParameters(),\r\n shaderLanguage: origEffect.shaderLanguage,\r\n },\r\n engine\r\n );\r\n\r\n for (let id = 0; id < params.drawWrapper.length; ++id) {\r\n if (id !== passIdForDrawWrapper) {\r\n params.drawWrapper[id]?.setEffect(params.mainDrawWrapper.effect, params.mainDrawWrapper.defines);\r\n }\r\n }\r\n return params.mainDrawWrapper.effect;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"shadowDepthWrapper.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/shadowDepthWrapper.ts"],"names":[],"mappings":"AAKA,OAAO,EAA+B,MAAM,EAAE,MAAM,UAAU,CAAC;AAI/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC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AU,EAAE,UAAU,CAAC,kBAAkB,EAAE;YAC3C,aAAa,EAAE,QAAQ;YACvB,mBAAmB,EAAE,UAAU,CAAC,sBAAsB,EAAE;YACxD,QAAQ,EAAE,UAAU,CAAC,WAAW,EAAE;YAClC,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;YACzG,eAAe,EAAE,UAAU,CAAC,kBAAkB,EAAE;YAChD,cAAc,EAAE,UAAU,CAAC,cAAc;SAC5C,EACD,MAAM,CACT,CAAC;QAEF,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;YACpD,IAAI,EAAE,KAAK,oBAAoB,EAAE,CAAC;gBAC9B,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YACrG,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC;IACzC,CAAC;CACJ","sourcesContent":["import { type Observer } from \"../Misc/observable\";\r\nimport { type Nullable } from \"../types\";\r\nimport { type Scene } from \"../scene\";\r\nimport { type SubMesh } from \"../Meshes/subMesh\";\r\nimport { type Material } from \"./material\";\r\nimport { type IEffectCreationOptions, Effect } from \"./effect\";\r\nimport { type AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { type Node } from \"../node\";\r\nimport { type ShadowGenerator } from \"../Lights/Shadows/shadowGenerator\";\r\nimport { RandomGUID } from \"../Misc/guid\";\r\nimport { DrawWrapper } from \"./drawWrapper\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\n\r\n/**\r\n * Options to be used when creating a shadow depth material\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface IIOptionShadowDepthMaterial {\r\n /** Variables in the vertex shader code that need to have their names remapped.\r\n * The format is: [\"var_name\", \"var_remapped_name\", \"var_name\", \"var_remapped_name\", ...]\r\n * \"var_name\" should be either: worldPos or vNormalW\r\n * So, if the variable holding the world position in your vertex shader is not named worldPos, you must tell the system\r\n * the name to use instead by using: [\"worldPos\", \"myWorldPosVar\"] assuming the variable is named myWorldPosVar in your code.\r\n * If the normal must also be remapped: [\"worldPos\", \"myWorldPosVar\", \"vNormalW\", \"myWorldNormal\"]\r\n */\r\n remappedVariables?: string[];\r\n\r\n /** Set standalone to true if the base material wrapped by ShadowDepthMaterial is not used for a regular object but for depth shadow generation only */\r\n standalone?: boolean;\r\n\r\n /** Set doNotInjectCode if the specific shadow map generation code is already implemented by the material. That will prevent this code to be injected twice by ShadowDepthWrapper */\r\n doNotInjectCode?: boolean;\r\n}\r\n\r\nclass MapMap<Ka, Kb, V> {\r\n readonly mm = new Map<Ka, Map<Kb, V>>();\r\n\r\n get(a: Ka, b: Kb): V | undefined {\r\n const m = this.mm.get(a);\r\n if (m !== undefined) {\r\n return m.get(b);\r\n }\r\n return undefined;\r\n }\r\n\r\n set(a: Ka, b: Kb, v: V): void {\r\n let m = this.mm.get(a);\r\n if (m === undefined) {\r\n this.mm.set(a, (m = new Map()));\r\n }\r\n m.set(b, v);\r\n }\r\n}\r\n\r\n/**\r\n * Class that can be used to wrap a base material to generate accurate shadows when using custom vertex/fragment code in the base material\r\n */\r\nexport class ShadowDepthWrapper {\r\n private _scene: Scene;\r\n private _options?: IIOptionShadowDepthMaterial;\r\n private _baseMaterial: Material;\r\n private _onEffectCreatedObserver: Nullable<Observer<{ effect: Effect; subMesh: Nullable<SubMesh> }>>;\r\n private _subMeshToEffect: Map<Nullable<SubMesh>, [Effect, number]>;\r\n private _subMeshToDepthWrapper: MapMap<\r\n Nullable<SubMesh>,\r\n ShadowGenerator,\r\n { drawWrapper: Array<Nullable<DrawWrapper>>; mainDrawWrapper: DrawWrapper; depthDefines: string; token: string }\r\n >; // key is (subMesh + shadowGenerator)\r\n private _meshes: Map<AbstractMesh, Nullable<Observer<Node>>>;\r\n\r\n /** Gets the standalone status of the wrapper */\r\n public get standalone(): boolean {\r\n return this._options?.standalone ?? false;\r\n }\r\n\r\n /** Gets the base material the wrapper is built upon */\r\n public get baseMaterial(): Material {\r\n return this._baseMaterial;\r\n }\r\n\r\n /** Gets the doNotInjectCode status of the wrapper */\r\n public get doNotInjectCode(): boolean {\r\n return this._options?.doNotInjectCode ?? false;\r\n }\r\n\r\n /**\r\n * Instantiate a new shadow depth wrapper.\r\n * It works by injecting some specific code in the vertex/fragment shaders of the base material and is used by a shadow generator to\r\n * generate the shadow depth map. For more information, please refer to the documentation:\r\n * https://doc.babylonjs.com/features/featuresDeepDive/lights/shadows\r\n * @param baseMaterial Material to wrap\r\n * @param scene Define the scene the material belongs to\r\n * @param options Options used to create the wrapper\r\n */\r\n constructor(baseMaterial: Material, scene?: Scene, options?: IIOptionShadowDepthMaterial) {\r\n this._baseMaterial = baseMaterial;\r\n this._scene = scene ?? <Scene>EngineStore.LastCreatedScene;\r\n this._options = options;\r\n\r\n this._subMeshToEffect = new Map();\r\n this._subMeshToDepthWrapper = new MapMap();\r\n this._meshes = new Map();\r\n\r\n // Register for onEffectCreated to store the effect of the base material when it is (re)generated. This effect will be used\r\n // to create the depth effect later on\r\n this._onEffectCreatedObserver = this._baseMaterial.onEffectCreatedObservable.add((params: { effect: Effect; subMesh: Nullable<SubMesh> }) => {\r\n const mesh = params.subMesh?.getMesh();\r\n\r\n if (mesh && !this._meshes.has(mesh)) {\r\n // Register for mesh onDispose to clean up our internal maps when a mesh is disposed\r\n this._meshes.set(\r\n mesh,\r\n mesh.onDisposeObservable.add((mesh: Node) => {\r\n const iterator = this._subMeshToEffect.keys();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const subMesh = key.value;\r\n if (subMesh?.getMesh() === (mesh as AbstractMesh)) {\r\n this._subMeshToEffect.delete(subMesh);\r\n this._deleteDepthWrapperEffect(subMesh);\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n if (this._subMeshToEffect.get(params.subMesh)?.[0] !== params.effect) {\r\n this._subMeshToEffect.set(params.subMesh, [params.effect, this._scene.getEngine().currentRenderPassId]);\r\n this._deleteDepthWrapperEffect(params.subMesh);\r\n }\r\n });\r\n }\r\n\r\n private _deleteDepthWrapperEffect(subMesh: Nullable<SubMesh>): void {\r\n const depthWrapperEntries = this._subMeshToDepthWrapper.mm.get(subMesh);\r\n if (depthWrapperEntries) {\r\n // find and release the previous depth effect\r\n depthWrapperEntries.forEach((depthWrapper) => {\r\n depthWrapper.mainDrawWrapper.effect?.dispose();\r\n });\r\n this._subMeshToDepthWrapper.mm.delete(subMesh); // trigger a depth effect recreation\r\n }\r\n }\r\n\r\n /**\r\n * Gets the effect to use to generate the depth map\r\n * @param subMesh subMesh to get the effect for\r\n * @param shadowGenerator shadow generator to get the effect for\r\n * @param passIdForDrawWrapper Id of the pass for which the effect from the draw wrapper must be retrieved from\r\n * @returns the effect to use to generate the depth map for the subMesh + shadow generator specified\r\n */\r\n public getEffect(subMesh: Nullable<SubMesh>, shadowGenerator: ShadowGenerator, passIdForDrawWrapper: number): Nullable<DrawWrapper> {\r\n const entry = this._subMeshToDepthWrapper.mm.get(subMesh)?.get(shadowGenerator);\r\n if (!entry) {\r\n return null;\r\n }\r\n let drawWrapper = entry.drawWrapper[passIdForDrawWrapper];\r\n if (!drawWrapper) {\r\n drawWrapper = entry.drawWrapper[passIdForDrawWrapper] = new DrawWrapper(this._scene.getEngine());\r\n drawWrapper.setEffect(entry.mainDrawWrapper.effect, entry.mainDrawWrapper.defines);\r\n }\r\n\r\n return drawWrapper;\r\n }\r\n\r\n /**\r\n * Invalidates cached vertex bindings for this submesh without releasing shadow draw resources.\r\n * @param subMesh defines the submesh whose shadow draws must be invalidated\r\n * @internal\r\n */\r\n public _invalidateVertexBuffers(subMesh: SubMesh): void {\r\n const entries = this._subMeshToDepthWrapper.mm.get(subMesh);\r\n if (!entries) {\r\n return;\r\n }\r\n\r\n for (const entry of entries.values()) {\r\n entry.mainDrawWrapper.drawContext?._invalidateVertexBuffers?.();\r\n for (const drawWrapper of entry.drawWrapper) {\r\n drawWrapper?.drawContext?._invalidateVertexBuffers?.();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Specifies that the submesh is ready to be used for depth rendering\r\n * @param subMesh submesh to check\r\n * @param defines the list of defines to take into account when checking the effect\r\n * @param shadowGenerator combined with subMesh, it defines the effect to check\r\n * @param useInstances specifies that instances should be used\r\n * @param passIdForDrawWrapper Id of the pass for which the draw wrapper should be created\r\n * @returns a boolean indicating that the submesh is ready or not\r\n */\r\n public isReadyForSubMesh(subMesh: SubMesh, defines: string[], shadowGenerator: ShadowGenerator, useInstances: boolean, passIdForDrawWrapper: number): boolean {\r\n if (this.standalone) {\r\n // will ensure the effect is (re)created for the base material\r\n if (!this._baseMaterial.isReadyForSubMesh(subMesh.getMesh(), subMesh, useInstances)) {\r\n return false;\r\n }\r\n }\r\n\r\n return this._makeEffect(subMesh, defines, shadowGenerator, passIdForDrawWrapper)?.isReady() ?? false;\r\n }\r\n\r\n /**\r\n * Disposes the resources\r\n */\r\n public dispose(): void {\r\n this._baseMaterial.onEffectCreatedObservable.remove(this._onEffectCreatedObserver);\r\n this._onEffectCreatedObserver = null;\r\n\r\n const iterator = this._meshes.entries();\r\n for (let entry = iterator.next(); entry.done !== true; entry = iterator.next()) {\r\n const [mesh, observer] = entry.value;\r\n\r\n mesh.onDisposeObservable.remove(observer);\r\n }\r\n }\r\n\r\n private _makeEffect(subMesh: SubMesh, defines: string[], shadowGenerator: ShadowGenerator, passIdForDrawWrapper: number): Nullable<Effect> {\r\n const engine = this._scene.getEngine();\r\n const origEffectAndRenderPassId = this._subMeshToEffect.get(subMesh);\r\n\r\n if (!origEffectAndRenderPassId) {\r\n return null;\r\n }\r\n\r\n const [origEffect, origRenderPassId] = origEffectAndRenderPassId;\r\n\r\n if (!origEffect.isReady()) {\r\n return null;\r\n }\r\n\r\n let params = this._subMeshToDepthWrapper.get(subMesh, shadowGenerator);\r\n if (!params) {\r\n const mainDrawWrapper = new DrawWrapper(engine);\r\n const originalDefines = subMesh._getDrawWrapper(origRenderPassId)?.defines;\r\n mainDrawWrapper.defines = typeof originalDefines === \"string\" ? null : (originalDefines ?? null);\r\n\r\n params = {\r\n drawWrapper: [],\r\n mainDrawWrapper,\r\n depthDefines: \"\",\r\n token: RandomGUID(),\r\n };\r\n params.drawWrapper[passIdForDrawWrapper] = mainDrawWrapper;\r\n this._subMeshToDepthWrapper.set(subMesh, shadowGenerator, params);\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (params.mainDrawWrapper.effect) {\r\n if (join === params.depthDefines) {\r\n // we already created the depth effect and it is still up to date for this submesh + shadow generator\r\n return params.mainDrawWrapper.effect;\r\n }\r\n }\r\n\r\n params.depthDefines = join;\r\n\r\n const uniforms = origEffect.getUniformNames().slice();\r\n\r\n // the depth effect is either out of date or has not been created yet\r\n let vertexCode = origEffect.vertexSourceCodeBeforeMigration,\r\n fragmentCode = origEffect.fragmentSourceCodeBeforeMigration;\r\n\r\n if (!vertexCode && !fragmentCode) {\r\n return null;\r\n }\r\n\r\n if (!this.doNotInjectCode) {\r\n // Declare the shadow map includes\r\n const vertexNormalBiasCode =\r\n this._options && this._options.remappedVariables\r\n ? `#include<shadowMapVertexNormalBias>(${this._options.remappedVariables.join(\",\")})`\r\n : `#include<shadowMapVertexNormalBias>`,\r\n vertexMetricCode =\r\n this._options && this._options.remappedVariables\r\n ? `#include<shadowMapVertexMetric>(${this._options.remappedVariables.join(\",\")})`\r\n : `#include<shadowMapVertexMetric>`,\r\n fragmentSoftTransparentShadow =\r\n this._options && this._options.remappedVariables\r\n ? `#include<shadowMapFragmentSoftTransparentShadow>(${this._options.remappedVariables.join(\",\")})`\r\n : `#include<shadowMapFragmentSoftTransparentShadow>`,\r\n fragmentBlockCode = `#include<shadowMapFragment>`,\r\n vertexExtraDeclartion = `#include<shadowMapVertexExtraDeclaration>`;\r\n\r\n // vertex code\r\n if (origEffect.shaderLanguage === ShaderLanguage.GLSL) {\r\n vertexCode = vertexCode.replace(/void\\s+?main/g, `\\n${vertexExtraDeclartion}\\nvoid main`);\r\n } else {\r\n vertexCode = vertexCode.replace(/@vertex/g, `\\n${vertexExtraDeclartion}\\n@vertex`);\r\n }\r\n vertexCode = vertexCode.replace(/#define SHADOWDEPTH_NORMALBIAS|#define CUSTOM_VERTEX_UPDATE_WORLDPOS/g, vertexNormalBiasCode);\r\n\r\n if (vertexCode.indexOf(\"#define SHADOWDEPTH_METRIC\") !== -1) {\r\n vertexCode = vertexCode.replace(/#define SHADOWDEPTH_METRIC/g, vertexMetricCode);\r\n } else {\r\n vertexCode = vertexCode.replace(/}\\s*$/g, vertexMetricCode + \"\\n}\");\r\n }\r\n vertexCode = vertexCode.replace(/#define SHADER_NAME.*?\\n|out vec4 glFragColor;\\n/g, \"\");\r\n\r\n // fragment code\r\n const hasLocationForSoftTransparentShadow =\r\n fragmentCode.indexOf(\"#define SHADOWDEPTH_SOFTTRANSPARENTSHADOW\") >= 0 || fragmentCode.indexOf(\"#define CUSTOM_FRAGMENT_BEFORE_FOG\") >= 0;\r\n const hasLocationForFragment = fragmentCode.indexOf(\"#define SHADOWDEPTH_FRAGMENT\") !== -1;\r\n\r\n let fragmentCodeToInjectAtEnd = \"\";\r\n\r\n if (!hasLocationForSoftTransparentShadow) {\r\n fragmentCodeToInjectAtEnd = fragmentSoftTransparentShadow + \"\\n\";\r\n } else {\r\n fragmentCode = fragmentCode.replace(/#define SHADOWDEPTH_SOFTTRANSPARENTSHADOW|#define CUSTOM_FRAGMENT_BEFORE_FOG/g, fragmentSoftTransparentShadow);\r\n }\r\n\r\n fragmentCode = fragmentCode.replace(/void\\s+?main/g, Effect.IncludesShadersStore[\"shadowMapFragmentExtraDeclaration\"] + \"\\nvoid main\");\r\n\r\n if (hasLocationForFragment) {\r\n fragmentCode = fragmentCode.replace(/#define SHADOWDEPTH_FRAGMENT/g, fragmentBlockCode);\r\n } else {\r\n fragmentCodeToInjectAtEnd += fragmentBlockCode + \"\\n\";\r\n }\r\n if (fragmentCodeToInjectAtEnd) {\r\n fragmentCode = fragmentCode.replace(/}\\s*$/g, fragmentCodeToInjectAtEnd + \"}\");\r\n }\r\n\r\n uniforms.push(\"biasAndScaleSM\", \"depthValuesSM\", \"lightDataSM\", \"softTransparentShadowSM\");\r\n }\r\n\r\n params.mainDrawWrapper.effect = engine.createEffect(\r\n {\r\n vertexSource: vertexCode,\r\n fragmentSource: fragmentCode,\r\n vertexToken: params.token,\r\n fragmentToken: params.token,\r\n },\r\n <IEffectCreationOptions>{\r\n attributes: origEffect.getAttributesNames(),\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: origEffect.getUniformBuffersNames(),\r\n samplers: origEffect.getSamplers(),\r\n defines: join + \"\\n\" + origEffect.defines.replace(\"#define SHADOWS\", \"\").replace(/#define SHADOW\\d/g, \"\"),\r\n indexParameters: origEffect.getIndexParameters(),\r\n shaderLanguage: origEffect.shaderLanguage,\r\n },\r\n engine\r\n );\r\n\r\n for (let id = 0; id < params.drawWrapper.length; ++id) {\r\n if (id !== passIdForDrawWrapper) {\r\n params.drawWrapper[id]?.setEffect(params.mainDrawWrapper.effect, params.mainDrawWrapper.defines);\r\n }\r\n }\r\n return params.mainDrawWrapper.effect;\r\n }\r\n}\r\n"]}
|
|
@@ -52,6 +52,20 @@ export declare abstract class DracoCodec implements IDisposable {
|
|
|
52
52
|
protected _modulePromise?: Promise<{
|
|
53
53
|
module: unknown; /** DecoderModule | EncoderModule */
|
|
54
54
|
}>;
|
|
55
|
+
/**
|
|
56
|
+
* When true, this codec is backed by a synchronous native implementation
|
|
57
|
+
* (e.g. Babylon Native's NativeDraco plugin) and no WebAssembly worker/module
|
|
58
|
+
* is set up. Subclasses that support native encoding/decoding set this via
|
|
59
|
+
* {@link _isNativeAvailable}.
|
|
60
|
+
*/
|
|
61
|
+
protected _useNativeCodec: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Returns true if a synchronous native codec is available and should be used
|
|
64
|
+
* instead of the WebAssembly/JavaScript module. Defaults to false; overridden
|
|
65
|
+
* by codecs that have a native implementation.
|
|
66
|
+
* @returns Whether a native implementation is available
|
|
67
|
+
*/
|
|
68
|
+
protected _isNativeAvailable(): boolean;
|
|
55
69
|
/**
|
|
56
70
|
* Checks if the default codec JS module is in scope.
|
|
57
71
|
*/
|
|
@@ -23,11 +23,33 @@ export function _IsConfigurationAvailable(config) {
|
|
|
23
23
|
* @internal
|
|
24
24
|
*/
|
|
25
25
|
export class DracoCodec {
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if a synchronous native codec is available and should be used
|
|
28
|
+
* instead of the WebAssembly/JavaScript module. Defaults to false; overridden
|
|
29
|
+
* by codecs that have a native implementation.
|
|
30
|
+
* @returns Whether a native implementation is available
|
|
31
|
+
*/
|
|
32
|
+
_isNativeAvailable() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
26
35
|
/**
|
|
27
36
|
* Constructor
|
|
28
37
|
* @param configuration The configuration for the DracoCodec instance.
|
|
29
38
|
*/
|
|
30
39
|
constructor(configuration) {
|
|
40
|
+
/**
|
|
41
|
+
* When true, this codec is backed by a synchronous native implementation
|
|
42
|
+
* (e.g. Babylon Native's NativeDraco plugin) and no WebAssembly worker/module
|
|
43
|
+
* is set up. Subclasses that support native encoding/decoding set this via
|
|
44
|
+
* {@link _isNativeAvailable}.
|
|
45
|
+
*/
|
|
46
|
+
this._useNativeCodec = false;
|
|
47
|
+
// If a synchronous native codec is available (e.g. Babylon Native's NativeDraco plugin) and no
|
|
48
|
+
// worker pool or JS module was injected, use it and skip all WebAssembly worker/module setup.
|
|
49
|
+
if (!configuration.workerPool && !configuration.jsModule && this._isNativeAvailable()) {
|
|
50
|
+
this._useNativeCodec = true;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
31
53
|
// check if the codec binary and worker pool was injected
|
|
32
54
|
// Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available
|
|
33
55
|
if (configuration.workerPool) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dracoCodec.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAmB,MAAM,uBAAuB,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AA4C/D;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACjC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC;QAClE,OAAO,CAAC,CAAC;IACb,CAAC;IAED,+DAA+D;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,mBAAmB,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAgC;IACtE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,OAAO,WAAW,KAAK,QAAQ,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;IACpI,6BAA6B;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,OAAgB,UAAU;IAsB5B;;;OAGG;IACH,YAAY,aAAuC;QAC/C,yDAAyD;QACzD,8GAA8G;QAC9G,IAAI,aAAa,CAAC,UAAU,EAAE,CAAC;YAC3B,8BAA8B;YAC9B,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,OAAO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C;YAC1B,OAAO;QACX,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,mFAAmF;YACnF,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;gBACxC,UAAU,CAAC,OAAO,EAAE,CAAC;YACzB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC;QAC/B,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["import { Tools } from \"../../Misc/tools.pure\";\r\nimport { AutoReleaseWorkerPool, type WorkerPool } from \"../../Misc/workerPool\";\r\nimport { type IDisposable } from \"../../scene\";\r\nimport { initializeWebWorker } from \"./dracoCompressionWorker\";\r\n\r\n/**\r\n * Configuration for using a Draco codec.\r\n */\r\nexport interface IDracoCodecConfiguration {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n\r\n /**\r\n * Optional worker pool to use for async encoding/decoding.\r\n * If provided, the worker pool will be used as is: no Draco scripts will be loaded, and numWorkers will be ignored.\r\n */\r\n workerPool?: WorkerPool;\r\n\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The codec module if already available.\r\n */\r\n jsModule?: unknown /* DracoDecoderModule | DracoEncoderModule */;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _IsConfigurationAvailable(config: IDracoCodecConfiguration): boolean {\r\n return !!((config.wasmUrl && (config.wasmBinary || config.wasmBinaryUrl) && typeof WebAssembly === \"object\") || config.fallbackUrl);\r\n // TODO: Account for jsModule\r\n}\r\n\r\n/**\r\n * Base class for a Draco codec.\r\n * @internal\r\n */\r\nexport abstract class DracoCodec implements IDisposable {\r\n protected _workerPoolPromise?: Promise<WorkerPool>;\r\n protected _modulePromise?: Promise<{ module: unknown /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Checks if the default codec JS module is in scope.\r\n */\r\n protected abstract _isModuleAvailable(): boolean;\r\n\r\n /**\r\n * Creates the JS Module for the corresponding wasm.\r\n */\r\n protected abstract _createModuleAsync(\r\n wasmBinary?: ArrayBuffer,\r\n jsModule?: unknown /** DracoDecoderModule | DracoEncoderModule */\r\n ): Promise<{ module: unknown /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Returns the worker content.\r\n */\r\n protected abstract _getWorkerContent(): string;\r\n\r\n /**\r\n * Constructor\r\n * @param configuration The configuration for the DracoCodec instance.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration) {\r\n // check if the codec binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (configuration.workerPool) {\r\n // Set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(configuration.workerPool);\r\n return;\r\n }\r\n\r\n // to avoid making big changes to the code here, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = configuration.wasmBinary;\r\n const numberOfWorkers = configuration.numWorkers ?? _GetDefaultNumWorkers();\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || !configuration.jsModule;\r\n // code maintained here for back-compat with no changes\r\n\r\n const codecInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n configuration.wasmUrl && configuration.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided\r\n ? Promise.resolve(wasmBinaryProvided)\r\n : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(configuration.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n // If using workers, initialize a worker pool with either the wasm or url?\r\n if (useWorkers) {\r\n // eslint-disable-next-line github/no-then\r\n this._workerPoolPromise = codecInfo.wasmBinaryPromise.then((wasmBinary) => {\r\n const workerContent = this._getWorkerContent();\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async\r\n return new AutoReleaseWorkerPool(numberOfWorkers, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, wasmBinary, codecInfo.url);\r\n });\r\n });\r\n } else {\r\n // eslint-disable-next-line github/no-then\r\n this._modulePromise = codecInfo.wasmBinaryPromise.then(async (wasmBinary) => {\r\n if (!this._isModuleAvailable()) {\r\n if (!configuration.jsModule) {\r\n if (!codecInfo.url) {\r\n throw new Error(\"Draco codec module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(codecInfo.url);\r\n }\r\n }\r\n return await this._createModuleAsync(wasmBinary as ArrayBuffer, configuration.jsModule);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure the draco codec is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._modulePromise) {\r\n await this._modulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises, github/no-then\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._modulePromise;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"dracoCodec.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAmB,MAAM,uBAAuB,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AA4C/D;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACjC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC;QAClE,OAAO,CAAC,CAAC;IACb,CAAC;IAED,+DAA+D;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,mBAAmB,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAgC;IACtE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,OAAO,WAAW,KAAK,QAAQ,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;IACpI,6BAA6B;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,OAAgB,UAAU;IAY5B;;;;;OAKG;IACO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C,CAAC,CAAC;wBAC3D,CAAC;wBACD,MAAM,KAAK,CAAC,sBAAsB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;oBACtD,CAAC;gBACL,CAAC;gBACD,OAAO,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAyB,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC5F,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,cAAc;QACvB,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,kBAAkB,CAAC;YAC9B,OAAO;QACX,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,cAAc,CAAC;YAC1B,OAAO;QACX,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,mFAAmF;YACnF,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;gBACxC,UAAU,CAAC,OAAO,EAAE,CAAC;YACzB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC;QAC/B,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["import { Tools } from \"../../Misc/tools.pure\";\r\nimport { AutoReleaseWorkerPool, type WorkerPool } from \"../../Misc/workerPool\";\r\nimport { type IDisposable } from \"../../scene\";\r\nimport { initializeWebWorker } from \"./dracoCompressionWorker\";\r\n\r\n/**\r\n * Configuration for using a Draco codec.\r\n */\r\nexport interface IDracoCodecConfiguration {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n\r\n /**\r\n * Optional worker pool to use for async encoding/decoding.\r\n * If provided, the worker pool will be used as is: no Draco scripts will be loaded, and numWorkers will be ignored.\r\n */\r\n workerPool?: WorkerPool;\r\n\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The codec module if already available.\r\n */\r\n jsModule?: unknown /* DracoDecoderModule | DracoEncoderModule */;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _IsConfigurationAvailable(config: IDracoCodecConfiguration): boolean {\r\n return !!((config.wasmUrl && (config.wasmBinary || config.wasmBinaryUrl) && typeof WebAssembly === \"object\") || config.fallbackUrl);\r\n // TODO: Account for jsModule\r\n}\r\n\r\n/**\r\n * Base class for a Draco codec.\r\n * @internal\r\n */\r\nexport abstract class DracoCodec implements IDisposable {\r\n protected _workerPoolPromise?: Promise<WorkerPool>;\r\n protected _modulePromise?: Promise<{ module: unknown /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * When true, this codec is backed by a synchronous native implementation\r\n * (e.g. Babylon Native's NativeDraco plugin) and no WebAssembly worker/module\r\n * is set up. Subclasses that support native encoding/decoding set this via\r\n * {@link _isNativeAvailable}.\r\n */\r\n protected _useNativeCodec = false;\r\n\r\n /**\r\n * Returns true if a synchronous native codec is available and should be used\r\n * instead of the WebAssembly/JavaScript module. Defaults to false; overridden\r\n * by codecs that have a native implementation.\r\n * @returns Whether a native implementation is available\r\n */\r\n protected _isNativeAvailable(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Checks if the default codec JS module is in scope.\r\n */\r\n protected abstract _isModuleAvailable(): boolean;\r\n\r\n /**\r\n * Creates the JS Module for the corresponding wasm.\r\n */\r\n protected abstract _createModuleAsync(\r\n wasmBinary?: ArrayBuffer,\r\n jsModule?: unknown /** DracoDecoderModule | DracoEncoderModule */\r\n ): Promise<{ module: unknown /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Returns the worker content.\r\n */\r\n protected abstract _getWorkerContent(): string;\r\n\r\n /**\r\n * Constructor\r\n * @param configuration The configuration for the DracoCodec instance.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration) {\r\n // If a synchronous native codec is available (e.g. Babylon Native's NativeDraco plugin) and no\r\n // worker pool or JS module was injected, use it and skip all WebAssembly worker/module setup.\r\n if (!configuration.workerPool && !configuration.jsModule && this._isNativeAvailable()) {\r\n this._useNativeCodec = true;\r\n return;\r\n }\r\n\r\n // check if the codec binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (configuration.workerPool) {\r\n // Set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(configuration.workerPool);\r\n return;\r\n }\r\n\r\n // to avoid making big changes to the code here, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = configuration.wasmBinary;\r\n const numberOfWorkers = configuration.numWorkers ?? _GetDefaultNumWorkers();\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || !configuration.jsModule;\r\n // code maintained here for back-compat with no changes\r\n\r\n const codecInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n configuration.wasmUrl && configuration.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided\r\n ? Promise.resolve(wasmBinaryProvided)\r\n : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(configuration.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n // If using workers, initialize a worker pool with either the wasm or url?\r\n if (useWorkers) {\r\n // eslint-disable-next-line github/no-then\r\n this._workerPoolPromise = codecInfo.wasmBinaryPromise.then((wasmBinary) => {\r\n const workerContent = this._getWorkerContent();\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async\r\n return new AutoReleaseWorkerPool(numberOfWorkers, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, wasmBinary, codecInfo.url);\r\n });\r\n });\r\n } else {\r\n // eslint-disable-next-line github/no-then\r\n this._modulePromise = codecInfo.wasmBinaryPromise.then(async (wasmBinary) => {\r\n if (!this._isModuleAvailable()) {\r\n if (!configuration.jsModule) {\r\n if (!codecInfo.url) {\r\n throw new Error(\"Draco codec module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(codecInfo.url);\r\n }\r\n }\r\n return await this._createModuleAsync(wasmBinary as ArrayBuffer, configuration.jsModule);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure the draco codec is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._modulePromise) {\r\n await this._modulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises, github/no-then\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._modulePromise;\r\n }\r\n}\r\n"]}
|
|
@@ -57,6 +57,7 @@ export declare class DracoDecoder extends DracoCodec {
|
|
|
57
57
|
*/
|
|
58
58
|
static ResetDefault(skipDispose?: boolean): void;
|
|
59
59
|
protected _isModuleAvailable(): boolean;
|
|
60
|
+
protected _isNativeAvailable(): boolean;
|
|
60
61
|
protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{
|
|
61
62
|
module: unknown; /** DecoderModule */
|
|
62
63
|
}>;
|
|
@@ -62,6 +62,9 @@ export class DracoDecoder extends DracoCodec {
|
|
|
62
62
|
_isModuleAvailable() {
|
|
63
63
|
return typeof DracoDecoderModule !== "undefined";
|
|
64
64
|
}
|
|
65
|
+
_isNativeAvailable() {
|
|
66
|
+
return typeof _native !== "undefined" && !!_native.decodeDracoMesh;
|
|
67
|
+
}
|
|
65
68
|
async _createModuleAsync(wasmBinary, jsModule /** DracoDecoderModule */) {
|
|
66
69
|
const module = await (jsModule || DracoDecoderModule)({ wasmBinary });
|
|
67
70
|
return { module };
|
|
@@ -97,6 +100,30 @@ export class DracoDecoder extends DracoCodec {
|
|
|
97
100
|
return normalized;
|
|
98
101
|
}
|
|
99
102
|
};
|
|
103
|
+
// Native decode path: NativeDraco decodes synchronously and returns the same
|
|
104
|
+
// { indices, attributes, totalVertices } shape as the WASM worker/module paths.
|
|
105
|
+
if (this._useNativeCodec) {
|
|
106
|
+
try {
|
|
107
|
+
const result = _native.decodeDracoMesh(dataView, attributes);
|
|
108
|
+
const resultAttributes = [];
|
|
109
|
+
for (const attribute of result.attributes) {
|
|
110
|
+
resultAttributes.push({
|
|
111
|
+
kind: attribute.kind,
|
|
112
|
+
data: attribute.data,
|
|
113
|
+
size: attribute.size,
|
|
114
|
+
byteOffset: attribute.byteOffset,
|
|
115
|
+
byteStride: attribute.byteStride,
|
|
116
|
+
normalized: applyGltfNormalizedOverride(attribute.kind, attribute.normalized),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return Promise.resolve({ indices: result.indices ?? undefined, attributes: resultAttributes, totalVertices: result.totalVertices });
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
// Keep the async contract: callers handle failures via the returned promise.
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
124
|
+
return Promise.reject(e);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
100
127
|
if (this._workerPoolPromise) {
|
|
101
128
|
// eslint-disable-next-line github/no-then
|
|
102
129
|
return this._workerPoolPromise.then(async (workerPool) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dracoDecoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AACpG,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAK7E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAcxC;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,OAAO,yBAAyB,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACxE,CAAC;IAGD;;OAEG;IACI,MAAM,KAAK,OAAO;QACrB,YAAY,CAAC,QAAQ,KAArB,YAAY,CAAC,QAAQ,GAAK,IAAI,YAAY,EAAE,EAAC;QAC7C,OAAO,YAAY,CAAC,QAAQ,CAA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6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;IAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;IAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;CAC/D,CAAC;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { DracoDecoderModule } from \"draco3dgltf\";\r\nimport { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { Tools } from \"../../Misc/tools.pure\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { type BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport { type Scene } from \"../../scene\";\r\nimport { type Nullable } from \"../../types\";\r\nimport { DecodeMesh, DecoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport { type IAttributeData, type MeshData, type DecoderMessage } from \"./dracoDecoder.types\";\r\n\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\n/**\r\n * @experimental This class is an experimental version of `DracoCompression` and is subject to change.\r\n *\r\n * Draco Decoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco decoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js cdn https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoDecoder.DefaultConfiguration = {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoDecoder.DefaultAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoDecoder object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoDecoder.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n */\r\nexport class DracoDecoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoDecoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the decoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoDecoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoDecoder> = null;\r\n /**\r\n * Default instance for the DracoDecoder.\r\n */\r\n public static get Default(): DracoDecoder {\r\n DracoDecoder._Default ??= new DracoDecoder();\r\n return DracoDecoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoDecoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoDecoder._Default) {\r\n if (!skipDispose) {\r\n DracoDecoder._Default.dispose();\r\n }\r\n DracoDecoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoDecoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{ module: unknown /** DecoderModule */ }> {\r\n const module = await ((jsModule as DracoDecoderModule) || DracoDecoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${DecodeMesh}(${DecoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco decoder.\r\n * @param configuration Optional override of the configuration for the DracoDecoder. If not provided, defaults to {@link DracoDecoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoDecoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView of the compressed Draco data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._workerPoolPromise.then(async (workerPool) => {\r\n return await new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<DecoderMessage>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const numPoints = DecodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco: Decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView of the Draco compressed data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean },\r\n boundingInfo: Nullable<BoundingInfo>\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (boundingInfo) {\r\n geometry._boundingInfo = boundingInfo;\r\n geometry.useBoundingInfoFromGeometry = true;\r\n }\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"dracoDecoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AACpG,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAQ7E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAcxC;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,OAAO,yBAAyB,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACxE,CAAC;IAGD;;OAEG;IACI,MAAM,KAAK,OAAO;QACrB,YAAY,CAAC,QAAQ,KAArB,YAAY,CAAC,QAAQ,GAAK,IAAI,YAAY,EAAE,EAAC;QAC7C,OAAO,YAAY,CAAC,QAAQ,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,YAAY,CAA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igurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { Tools } from \"../../Misc/tools.pure\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { type BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport { type Scene } from \"../../scene\";\r\nimport { type Nullable } from \"../../types\";\r\nimport { DecodeMesh, DecoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport { type IAttributeData, type MeshData, type DecoderMessage } from \"./dracoDecoder.types\";\r\nimport { type INative } from \"../../Engines/Native/nativeInterfaces\";\r\n\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare const _native: INative;\r\n\r\n/**\r\n * @experimental This class is an experimental version of `DracoCompression` and is subject to change.\r\n *\r\n * Draco Decoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco decoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js cdn https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoDecoder.DefaultConfiguration = {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoDecoder.DefaultAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoDecoder object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoDecoder.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n */\r\nexport class DracoDecoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoDecoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the decoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoDecoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoDecoder> = null;\r\n /**\r\n * Default instance for the DracoDecoder.\r\n */\r\n public static get Default(): DracoDecoder {\r\n DracoDecoder._Default ??= new DracoDecoder();\r\n return DracoDecoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoDecoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoDecoder._Default) {\r\n if (!skipDispose) {\r\n DracoDecoder._Default.dispose();\r\n }\r\n DracoDecoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoDecoderModule !== \"undefined\";\r\n }\r\n\r\n protected override _isNativeAvailable(): boolean {\r\n return typeof _native !== \"undefined\" && !!_native.decodeDracoMesh;\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{ module: unknown /** DecoderModule */ }> {\r\n const module = await ((jsModule as DracoDecoderModule) || DracoDecoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${DecodeMesh}(${DecoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco decoder.\r\n * @param configuration Optional override of the configuration for the DracoDecoder. If not provided, defaults to {@link DracoDecoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoDecoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView of the compressed Draco data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n // Native decode path: NativeDraco decodes synchronously and returns the same\r\n // { indices, attributes, totalVertices } shape as the WASM worker/module paths.\r\n if (this._useNativeCodec) {\r\n try {\r\n const result = _native.decodeDracoMesh!(dataView, attributes);\r\n const resultAttributes: Array<IAttributeData> = [];\r\n for (const attribute of result.attributes) {\r\n resultAttributes.push({\r\n kind: attribute.kind,\r\n data: attribute.data,\r\n size: attribute.size,\r\n byteOffset: attribute.byteOffset,\r\n byteStride: attribute.byteStride,\r\n normalized: applyGltfNormalizedOverride(attribute.kind, attribute.normalized),\r\n });\r\n }\r\n return Promise.resolve<MeshData>({ indices: result.indices ?? undefined, attributes: resultAttributes, totalVertices: result.totalVertices });\r\n } catch (e) {\r\n // Keep the async contract: callers handle failures via the returned promise.\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n return Promise.reject(e);\r\n }\r\n }\r\n\r\n if (this._workerPoolPromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._workerPoolPromise.then(async (workerPool) => {\r\n return await new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<DecoderMessage>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const numPoints = DecodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco: Decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView of the Draco compressed data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean },\r\n boundingInfo: Nullable<BoundingInfo>\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (boundingInfo) {\r\n geometry._boundingInfo = boundingInfo;\r\n geometry.useBoundingInfoFromGeometry = true;\r\n }\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n}\r\n"]}
|
|
@@ -76,6 +76,7 @@ export declare class DracoEncoder extends DracoCodec {
|
|
|
76
76
|
*/
|
|
77
77
|
static ResetDefault(skipDispose?: boolean): void;
|
|
78
78
|
protected _isModuleAvailable(): boolean;
|
|
79
|
+
protected _isNativeAvailable(): boolean;
|
|
79
80
|
protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoEncoderModule */): Promise<{
|
|
80
81
|
module: unknown; /** EncoderModule */
|
|
81
82
|
}>;
|
|
@@ -148,6 +148,9 @@ export class DracoEncoder extends DracoCodec {
|
|
|
148
148
|
_isModuleAvailable() {
|
|
149
149
|
return typeof DracoEncoderModule !== "undefined";
|
|
150
150
|
}
|
|
151
|
+
_isNativeAvailable() {
|
|
152
|
+
return typeof _native !== "undefined" && !!_native.encodeDracoMesh;
|
|
153
|
+
}
|
|
151
154
|
async _createModuleAsync(wasmBinary, jsModule /** DracoEncoderModule */) {
|
|
152
155
|
const module = await (jsModule || DracoEncoderModule)({ wasmBinary });
|
|
153
156
|
return { module };
|
|
@@ -167,6 +170,11 @@ export class DracoEncoder extends DracoCodec {
|
|
|
167
170
|
*/
|
|
168
171
|
async _encodeAsync(attributes, indices, options) {
|
|
169
172
|
const mergedOptions = options ? deepMerge(DracoEncoder.DefaultEncoderOptions, options) : DracoEncoder.DefaultEncoderOptions;
|
|
173
|
+
// Native encode path: NativeDraco encodes synchronously and returns the same
|
|
174
|
+
// { data, attributeIds } shape as the WASM worker/module paths.
|
|
175
|
+
if (this._useNativeCodec) {
|
|
176
|
+
return _native.encodeDracoMesh(attributes, indices, mergedOptions);
|
|
177
|
+
}
|
|
170
178
|
if (this._workerPoolPromise) {
|
|
171
179
|
const workerPool = await this._workerPoolPromise;
|
|
172
180
|
return await new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dracoEncoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AAEpG,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC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BAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;QAEjF,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;;AAzJD;;;;;;GAMG;AACW,iCAAoB,GAA6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,gCAAgC;IAChE,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,qBAAqB;IAC3D,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,mBAAmB;CAC1D,CAAC;AAEF;;GAEG;AACW,kCAAqB,GAAG,qBAAqB,CAAC;AAS3C,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { type EncoderMessage, type IDracoAttributeData, type IDracoEncodedMeshData, type IDracoEncoderOptions, type DracoAttributeName } from \"./dracoEncoder.types\";\r\nimport { EncodeMesh, EncoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport { Tools } from \"../../Misc/tools.pure\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { type Nullable } from \"../../types\";\r\nimport { Mesh } from \"../mesh.pure\";\r\nimport { type Geometry } from \"../geometry\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { deepMerge } from \"../../Misc/deepMerger\";\r\nimport { type EncoderModule } from \"draco3d\";\r\nimport { AreIndices32Bits, GetTypedArrayData } from \"core/Buffers/bufferUtils\";\r\n\r\n// Missing type from types/draco3d. Do not use in public scope; UMD tests will fail because of EncoderModule.\r\ntype DracoEncoderModule = (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ndeclare let DracoEncoderModule: DracoEncoderModule;\r\n\r\n/**\r\n * Map the Babylon.js attribute kind to the Draco attribute kind, defined by the `GeometryAttributeType` enum.\r\n * @internal\r\n */\r\nfunction GetDracoAttributeName(kind: string): DracoAttributeName {\r\n if (kind === VertexBuffer.PositionKind) {\r\n return \"POSITION\";\r\n } else if (kind === VertexBuffer.NormalKind) {\r\n return \"NORMAL\";\r\n } else if (kind === VertexBuffer.ColorKind) {\r\n return \"COLOR\";\r\n } else if (kind.startsWith(VertexBuffer.UVKind)) {\r\n return \"TEX_COORD\";\r\n }\r\n return \"GENERIC\";\r\n}\r\n\r\n/**\r\n * Get the indices for the geometry, if present. Eventually used as\r\n * `AddFacesToMesh(mesh: Mesh, numFaces: number, faces: Uint16Array | Uint32Array)`;\r\n * where `numFaces = indices.length / 3` and `faces = indices`.\r\n * @internal\r\n */\r\nfunction PrepareIndicesForDraco(input: Mesh | Geometry): Nullable<Uint32Array | Uint16Array> {\r\n let indices = input.getIndices(undefined, true);\r\n\r\n // Convert number[] and Int32Array types, if needed\r\n if (indices && !(indices instanceof Uint32Array) && !(indices instanceof Uint16Array)) {\r\n indices = (AreIndices32Bits(indices, indices.length) ? Uint32Array : Uint16Array).from(indices);\r\n }\r\n\r\n return indices;\r\n}\r\n\r\n/**\r\n * Get relevant information about the geometry's vertex attributes for Draco encoding. Eventually used for each attribute as\r\n * `AddFloatAttribute(mesh: Mesh, attribute: number, count: number, itemSize: number, array: TypedArray)`\r\n * where `attribute = EncoderModule[<dracoAttribute>]`, `itemSize = <size>`, `array = <data>`, and count is the number of position vertices.\r\n * @internal\r\n */\r\nfunction PrepareAttributesForDraco(input: Mesh | Geometry, excludedAttributes?: string[]): Array<IDracoAttributeData> {\r\n const attributes: Array<IDracoAttributeData> = [];\r\n\r\n for (const kind of input.getVerticesDataKinds()) {\r\n if (excludedAttributes?.includes(kind)) {\r\n if (kind === VertexBuffer.PositionKind) {\r\n throw new Error(\"Draco: Cannot exclude position attribute from encoding.\");\r\n }\r\n continue;\r\n }\r\n\r\n // Convert number[] to typed array, if needed.\r\n const vertexBuffer = input.getVertexBuffer(kind)!;\r\n const size = vertexBuffer.getSize();\r\n const data = GetTypedArrayData(vertexBuffer.getData()!, size, vertexBuffer.type, vertexBuffer.byteOffset, vertexBuffer.byteStride, input.getTotalVertices(), true);\r\n attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: size, data: data });\r\n }\r\n\r\n return attributes;\r\n}\r\n\r\nconst DefaultEncoderOptions: IDracoEncoderOptions = {\r\n decodeSpeed: 5,\r\n encodeSpeed: 5,\r\n method: \"MESH_EDGEBREAKER_ENCODING\",\r\n quantizationBits: {\r\n POSITION: 14,\r\n NORMAL: 10,\r\n COLOR: 8,\r\n TEX_COORD: 12,\r\n GENERIC: 12,\r\n },\r\n};\r\n\r\n/**\r\n * @experimental This class is subject to change.\r\n *\r\n * Draco Encoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco encoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco encoder files from the Babylon.js cdn https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoEncoder.DefaultConfiguration = {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The encoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.\r\n *\r\n * To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * ```\r\n *\r\n * Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.\r\n *\r\n * Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,\r\n * when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.\r\n * You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);\r\n * ```\r\n *\r\n * By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:\r\n * ```javascript\r\n * var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };\r\n * var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);\r\n * ```\r\n */\r\nexport class DracoEncoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoEncoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_encoder.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_encoder.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_encoder_wasm_wrapper.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_encoder.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_encoder.js`,\r\n };\r\n\r\n /**\r\n * DefaultEncoderOptions\r\n */\r\n public static DefaultEncoderOptions = DefaultEncoderOptions;\r\n\r\n /**\r\n * Returns true if the encoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoEncoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoEncoder> = null;\r\n /**\r\n * Default instance for the DracoEncoder.\r\n */\r\n public static get Default(): DracoEncoder {\r\n DracoEncoder._Default ??= new DracoEncoder();\r\n return DracoEncoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoEncoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoEncoder._Default) {\r\n if (!skipDispose) {\r\n DracoEncoder._Default.dispose();\r\n }\r\n DracoEncoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoEncoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoEncoderModule */): Promise<{ module: unknown /** EncoderModule */ }> {\r\n const module = await ((jsModule as DracoEncoderModule) || DracoEncoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${EncodeMesh}(${EncoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco encoder.\r\n * @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoEncoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public async _encodeAsync(\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options?: IDracoEncoderOptions\r\n ): Promise<IDracoEncodedMeshData> {\r\n const mergedOptions = options ? deepMerge(DracoEncoder.DefaultEncoderOptions, options) : DracoEncoder.DefaultEncoderOptions;\r\n\r\n if (this._workerPoolPromise) {\r\n const workerPool = await this._workerPoolPromise;\r\n return await new Promise<IDracoEncodedMeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent<EncoderMessage>) => {\r\n if (message.data.id === \"encodeMeshSuccess\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(message.data.encodedMeshData);\r\n onComplete();\r\n } else if (message.data.id === \"encodeMeshError\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(new Error(message.data.errorMessage));\r\n onComplete();\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // Build the transfer list. No need to copy, as the data was copied in previous steps.\r\n const transferList = [];\r\n for (const attribute of attributes) {\r\n transferList.push(attribute.data.buffer);\r\n }\r\n if (indices) {\r\n transferList.push(indices.buffer);\r\n }\r\n\r\n worker.postMessage({ id: \"encodeMesh\", attributes: attributes, indices: indices, options: mergedOptions }, transferList);\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n const encoder = await this._modulePromise;\r\n return EncodeMesh(encoder.module, attributes, indices, mergedOptions);\r\n }\r\n\r\n throw new Error(\"Draco: Encoder module is not available\");\r\n }\r\n\r\n /**\r\n * Encodes a mesh or geometry into a Draco-encoded mesh data.\r\n * @param input the mesh or geometry to encode\r\n * @param options options for the encoding\r\n * @returns a promise that resolves to the newly-encoded data\r\n */\r\n public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<IDracoEncodedMeshData> {\r\n const verticesCount = input.getTotalVertices();\r\n if (verticesCount == 0) {\r\n throw new Error(\"Draco: Cannot encode geometry with no vertices.\");\r\n }\r\n\r\n // Prepare parameters for encoding\r\n if (input instanceof Mesh && input.morphTargetManager && options?.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n Logger.Warn(\"Draco: Cannot use EDGEBREAKER encoding method with morph targets. Falling back to SEQUENTIAL method.\");\r\n options.method = \"MESH_SEQUENTIAL_ENCODING\";\r\n }\r\n\r\n const indices = PrepareIndicesForDraco(input);\r\n const attributes = PrepareAttributesForDraco(input, options?.excludedAttributes);\r\n\r\n return await this._encodeAsync(attributes, indices, options);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"dracoEncoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AAEpG,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAU/E;;;GAGG;AACH,SAAS,qBAAqB,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,YAAY,CAAC,YAAY,EAAE,CAAC;QACrC,OAAO,UAAU,CAAC;IACtB,CAAC;SAAM,IAAI,IAAI,KAAK,YAAY,CAAC,UAAU,EAAE,CAAC;QAC1C,OAAO,QAAQ,CAAC;IACpB,CAAC;SAAM,IAAI,IAAI,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;QACzC,OAAO,OAAO,CAAC;IACnB,CAAC;SAAM,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,SAAS,sBAAsB,CAAC,KAAsB;IAClD,IAAI,OAAO,G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AC,cAAc,mBAAmB;CAC1D,CAAC;AAEF;;GAEG;AACW,kCAAqB,GAAG,qBAAqB,CAAC;AAS3C,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { type EncoderMessage, type IDracoAttributeData, type IDracoEncodedMeshData, type IDracoEncoderOptions, type DracoAttributeName } from \"./dracoEncoder.types\";\r\nimport { EncodeMesh, EncoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport { Tools } from \"../../Misc/tools.pure\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { type Nullable } from \"../../types\";\r\nimport { Mesh } from \"../mesh.pure\";\r\nimport { type Geometry } from \"../geometry\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { deepMerge } from \"../../Misc/deepMerger\";\r\nimport { type EncoderModule } from \"draco3d\";\r\nimport { AreIndices32Bits, GetTypedArrayData } from \"core/Buffers/bufferUtils\";\r\nimport { type INative } from \"../../Engines/Native/nativeInterfaces\";\r\n\r\n// Missing type from types/draco3d. Do not use in public scope; UMD tests will fail because of EncoderModule.\r\ntype DracoEncoderModule = (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ndeclare let DracoEncoderModule: DracoEncoderModule;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare const _native: INative;\r\n\r\n/**\r\n * Map the Babylon.js attribute kind to the Draco attribute kind, defined by the `GeometryAttributeType` enum.\r\n * @internal\r\n */\r\nfunction GetDracoAttributeName(kind: string): DracoAttributeName {\r\n if (kind === VertexBuffer.PositionKind) {\r\n return \"POSITION\";\r\n } else if (kind === VertexBuffer.NormalKind) {\r\n return \"NORMAL\";\r\n } else if (kind === VertexBuffer.ColorKind) {\r\n return \"COLOR\";\r\n } else if (kind.startsWith(VertexBuffer.UVKind)) {\r\n return \"TEX_COORD\";\r\n }\r\n return \"GENERIC\";\r\n}\r\n\r\n/**\r\n * Get the indices for the geometry, if present. Eventually used as\r\n * `AddFacesToMesh(mesh: Mesh, numFaces: number, faces: Uint16Array | Uint32Array)`;\r\n * where `numFaces = indices.length / 3` and `faces = indices`.\r\n * @internal\r\n */\r\nfunction PrepareIndicesForDraco(input: Mesh | Geometry): Nullable<Uint32Array | Uint16Array> {\r\n let indices = input.getIndices(undefined, true);\r\n\r\n // Convert number[] and Int32Array types, if needed\r\n if (indices && !(indices instanceof Uint32Array) && !(indices instanceof Uint16Array)) {\r\n indices = (AreIndices32Bits(indices, indices.length) ? Uint32Array : Uint16Array).from(indices);\r\n }\r\n\r\n return indices;\r\n}\r\n\r\n/**\r\n * Get relevant information about the geometry's vertex attributes for Draco encoding. Eventually used for each attribute as\r\n * `AddFloatAttribute(mesh: Mesh, attribute: number, count: number, itemSize: number, array: TypedArray)`\r\n * where `attribute = EncoderModule[<dracoAttribute>]`, `itemSize = <size>`, `array = <data>`, and count is the number of position vertices.\r\n * @internal\r\n */\r\nfunction PrepareAttributesForDraco(input: Mesh | Geometry, excludedAttributes?: string[]): Array<IDracoAttributeData> {\r\n const attributes: Array<IDracoAttributeData> = [];\r\n\r\n for (const kind of input.getVerticesDataKinds()) {\r\n if (excludedAttributes?.includes(kind)) {\r\n if (kind === VertexBuffer.PositionKind) {\r\n throw new Error(\"Draco: Cannot exclude position attribute from encoding.\");\r\n }\r\n continue;\r\n }\r\n\r\n // Convert number[] to typed array, if needed.\r\n const vertexBuffer = input.getVertexBuffer(kind)!;\r\n const size = vertexBuffer.getSize();\r\n const data = GetTypedArrayData(vertexBuffer.getData()!, size, vertexBuffer.type, vertexBuffer.byteOffset, vertexBuffer.byteStride, input.getTotalVertices(), true);\r\n attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: size, data: data });\r\n }\r\n\r\n return attributes;\r\n}\r\n\r\nconst DefaultEncoderOptions: IDracoEncoderOptions = {\r\n decodeSpeed: 5,\r\n encodeSpeed: 5,\r\n method: \"MESH_EDGEBREAKER_ENCODING\",\r\n quantizationBits: {\r\n POSITION: 14,\r\n NORMAL: 10,\r\n COLOR: 8,\r\n TEX_COORD: 12,\r\n GENERIC: 12,\r\n },\r\n};\r\n\r\n/**\r\n * @experimental This class is subject to change.\r\n *\r\n * Draco Encoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco encoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco encoder files from the Babylon.js cdn https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoEncoder.DefaultConfiguration = {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The encoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.\r\n *\r\n * To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * ```\r\n *\r\n * Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.\r\n *\r\n * Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,\r\n * when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.\r\n * You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);\r\n * ```\r\n *\r\n * By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:\r\n * ```javascript\r\n * var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };\r\n * var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);\r\n * ```\r\n */\r\nexport class DracoEncoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoEncoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_encoder.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_encoder.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_encoder_wasm_wrapper.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_encoder.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_encoder.js`,\r\n };\r\n\r\n /**\r\n * DefaultEncoderOptions\r\n */\r\n public static DefaultEncoderOptions = DefaultEncoderOptions;\r\n\r\n /**\r\n * Returns true if the encoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoEncoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoEncoder> = null;\r\n /**\r\n * Default instance for the DracoEncoder.\r\n */\r\n public static get Default(): DracoEncoder {\r\n DracoEncoder._Default ??= new DracoEncoder();\r\n return DracoEncoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoEncoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoEncoder._Default) {\r\n if (!skipDispose) {\r\n DracoEncoder._Default.dispose();\r\n }\r\n DracoEncoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoEncoderModule !== \"undefined\";\r\n }\r\n\r\n protected override _isNativeAvailable(): boolean {\r\n return typeof _native !== \"undefined\" && !!_native.encodeDracoMesh;\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoEncoderModule */): Promise<{ module: unknown /** EncoderModule */ }> {\r\n const module = await ((jsModule as DracoEncoderModule) || DracoEncoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${EncodeMesh}(${EncoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco encoder.\r\n * @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoEncoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public async _encodeAsync(\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options?: IDracoEncoderOptions\r\n ): Promise<IDracoEncodedMeshData> {\r\n const mergedOptions = options ? deepMerge(DracoEncoder.DefaultEncoderOptions, options) : DracoEncoder.DefaultEncoderOptions;\r\n\r\n // Native encode path: NativeDraco encodes synchronously and returns the same\r\n // { data, attributeIds } shape as the WASM worker/module paths.\r\n if (this._useNativeCodec) {\r\n return _native.encodeDracoMesh!(attributes, indices, mergedOptions);\r\n }\r\n\r\n if (this._workerPoolPromise) {\r\n const workerPool = await this._workerPoolPromise;\r\n return await new Promise<IDracoEncodedMeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent<EncoderMessage>) => {\r\n if (message.data.id === \"encodeMeshSuccess\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(message.data.encodedMeshData);\r\n onComplete();\r\n } else if (message.data.id === \"encodeMeshError\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(new Error(message.data.errorMessage));\r\n onComplete();\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // Build the transfer list. No need to copy, as the data was copied in previous steps.\r\n const transferList = [];\r\n for (const attribute of attributes) {\r\n transferList.push(attribute.data.buffer);\r\n }\r\n if (indices) {\r\n transferList.push(indices.buffer);\r\n }\r\n\r\n worker.postMessage({ id: \"encodeMesh\", attributes: attributes, indices: indices, options: mergedOptions }, transferList);\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n const encoder = await this._modulePromise;\r\n return EncodeMesh(encoder.module, attributes, indices, mergedOptions);\r\n }\r\n\r\n throw new Error(\"Draco: Encoder module is not available\");\r\n }\r\n\r\n /**\r\n * Encodes a mesh or geometry into a Draco-encoded mesh data.\r\n * @param input the mesh or geometry to encode\r\n * @param options options for the encoding\r\n * @returns a promise that resolves to the newly-encoded data\r\n */\r\n public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<IDracoEncodedMeshData> {\r\n const verticesCount = input.getTotalVertices();\r\n if (verticesCount == 0) {\r\n throw new Error(\"Draco: Cannot encode geometry with no vertices.\");\r\n }\r\n\r\n // Prepare parameters for encoding\r\n if (input instanceof Mesh && input.morphTargetManager && options?.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n Logger.Warn(\"Draco: Cannot use EDGEBREAKER encoding method with morph targets. Falling back to SEQUENTIAL method.\");\r\n options.method = \"MESH_SEQUENTIAL_ENCODING\";\r\n }\r\n\r\n const indices = PrepareIndicesForDraco(input);\r\n const attributes = PrepareAttributesForDraco(input, options?.excludedAttributes);\r\n\r\n return await this._encodeAsync(attributes, indices, options);\r\n }\r\n}\r\n"]}
|
|
@@ -37,6 +37,7 @@ export interface IMeshoptCompressionConfiguration {
|
|
|
37
37
|
*/
|
|
38
38
|
export declare class MeshoptCompression implements IDisposable {
|
|
39
39
|
private _decoderModulePromise?;
|
|
40
|
+
private readonly _useNativeDecoder;
|
|
40
41
|
/**
|
|
41
42
|
* The configuration. Defaults to the following:
|
|
42
43
|
* ```javascript
|
|
@@ -37,6 +37,12 @@ export class MeshoptCompression {
|
|
|
37
37
|
* Constructor
|
|
38
38
|
*/
|
|
39
39
|
constructor() {
|
|
40
|
+
this._useNativeDecoder = typeof _native !== "undefined" && !!_native.decodeMeshopt;
|
|
41
|
+
// When the native meshopt decoder is available (Babylon Native), skip
|
|
42
|
+
// loading the WebAssembly module entirely and decode synchronously.
|
|
43
|
+
if (this._useNativeDecoder) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
40
46
|
const decoder = MeshoptCompression.Configuration.decoder;
|
|
41
47
|
// eslint-disable-next-line github/no-then
|
|
42
48
|
this._decoderModulePromise = Tools.LoadBabylonScriptAsync(decoder.url).then(() => {
|
|
@@ -61,6 +67,9 @@ export class MeshoptCompression {
|
|
|
61
67
|
* @returns a Promise<Uint8Array> that resolves to the decoded data
|
|
62
68
|
*/
|
|
63
69
|
async decodeGltfBufferAsync(source, count, stride, mode, filter) {
|
|
70
|
+
if (this._useNativeDecoder) {
|
|
71
|
+
return _native.decodeMeshopt(source, count, stride, mode, filter);
|
|
72
|
+
}
|
|
64
73
|
await this._decoderModulePromise;
|
|
65
74
|
if (NumberOfWorkers === 0) {
|
|
66
75
|
MeshoptDecoder.useWorkers(1);
|