@babylonjs/core 7.42.0 → 7.44.0
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/Actions/actionEvent.d.ts +4 -4
- package/Animations/animation.js +1 -1
- package/Animations/animation.js.map +1 -1
- package/Buffers/bufferUtils.d.ts +8 -1
- package/Buffers/bufferUtils.js +15 -0
- package/Buffers/bufferUtils.js.map +1 -1
- package/Culling/Helper/boundingInfoHelper.d.ts +2 -9
- package/Culling/Helper/boundingInfoHelper.js +2 -9
- package/Culling/Helper/boundingInfoHelper.js.map +1 -1
- package/Culling/Helper/computeShaderBoundingHelper.js +3 -4
- package/Culling/Helper/computeShaderBoundingHelper.js.map +1 -1
- package/Culling/Helper/transformFeedbackBoundingHelper.js +27 -64
- package/Culling/Helper/transformFeedbackBoundingHelper.js.map +1 -1
- package/Engines/Extensions/engine.multiRender.js +3 -2
- package/Engines/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheRenderPipeline.d.ts +1 -0
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js +5 -0
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureManager.js +6 -1
- package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.d.ts +5 -2
- package/FlowGraph/flowGraphConnection.d.ts +1 -1
- package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.d.ts +64 -0
- package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js +147 -0
- package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.d.ts +42 -0
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js +78 -0
- package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.d.ts +2 -17
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js +3 -45
- package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.d.ts +2 -17
- package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js +3 -44
- package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.d.ts +3 -19
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js +3 -49
- package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.d.ts +47 -0
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js +65 -0
- package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +0 -15
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.d.ts +4 -0
- package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js +9 -0
- package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.d.ts +1 -6
- package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js +0 -13
- package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js +0 -1
- package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/index.d.ts +2 -0
- package/FrameGraph/Node/Blocks/index.js +2 -0
- package/FrameGraph/Node/Blocks/index.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraphBlock.js +17 -0
- package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
- package/FrameGraph/Passes/renderPass.d.ts +0 -8
- package/FrameGraph/Passes/renderPass.js +0 -10
- package/FrameGraph/Passes/renderPass.js.map +1 -1
- package/FrameGraph/Tasks/Layers/glowLayerTask.d.ts +57 -0
- package/FrameGraph/Tasks/Layers/glowLayerTask.js +173 -0
- package/FrameGraph/Tasks/Layers/glowLayerTask.js.map +1 -0
- package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js +1 -1
- package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/bloomTask.js +7 -0
- package/FrameGraph/Tasks/PostProcesses/bloomTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js +1 -1
- package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js +1 -1
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js +5 -5
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldTask.js +12 -4
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/passTask.d.ts +29 -0
- package/FrameGraph/Tasks/PostProcesses/passTask.js +31 -0
- package/FrameGraph/Tasks/PostProcesses/passTask.js.map +1 -0
- package/FrameGraph/Tasks/PostProcesses/postProcessTask.js +1 -1
- package/FrameGraph/Tasks/PostProcesses/postProcessTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +0 -8
- package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +1 -17
- package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/geometryRendererTask.js +3 -0
- package/FrameGraph/Tasks/Rendering/geometryRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +4 -6
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js +20 -22
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +7 -1
- package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +21 -5
- package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js +4 -6
- package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Texture/copyToTextureTask.js +1 -1
- package/FrameGraph/Tasks/Texture/copyToTextureTask.js.map +1 -1
- package/FrameGraph/frameGraph.js +22 -11
- package/FrameGraph/frameGraph.js.map +1 -1
- package/FrameGraph/frameGraphRenderContext.d.ts +2 -1
- package/FrameGraph/frameGraphRenderContext.js +2 -1
- package/FrameGraph/frameGraphRenderContext.js.map +1 -1
- package/FrameGraph/frameGraphTask.d.ts +11 -1
- package/FrameGraph/frameGraphTask.js +8 -0
- package/FrameGraph/frameGraphTask.js.map +1 -1
- package/FrameGraph/frameGraphTextureManager.d.ts +9 -3
- package/FrameGraph/frameGraphTextureManager.js +10 -4
- package/FrameGraph/frameGraphTextureManager.js.map +1 -1
- package/FrameGraph/index.d.ts +2 -0
- package/FrameGraph/index.js +2 -0
- package/FrameGraph/index.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js +10 -0
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Inputs/scene.inputManager.js +2 -2
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Layers/effectLayer.d.ts +32 -33
- package/Layers/effectLayer.js +144 -530
- package/Layers/effectLayer.js.map +1 -1
- package/Layers/glowLayer.d.ts +14 -41
- package/Layers/glowLayer.js +92 -178
- package/Layers/glowLayer.js.map +1 -1
- package/Layers/highlightLayer.d.ts +0 -1
- package/Layers/highlightLayer.js +0 -1
- package/Layers/highlightLayer.js.map +1 -1
- package/Layers/index.d.ts +2 -0
- package/Layers/index.js +2 -0
- package/Layers/index.js.map +1 -1
- package/Layers/thinEffectLayer.d.ts +230 -0
- package/Layers/thinEffectLayer.js +734 -0
- package/Layers/thinEffectLayer.js.map +1 -0
- package/Layers/thinGlowLayer.d.ts +141 -0
- package/Layers/thinGlowLayer.js +292 -0
- package/Layers/thinGlowLayer.js.map +1 -0
- package/Lights/Shadows/shadowGenerator.js +40 -19
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Materials/GreasedLine/greasedLinePluginMaterial.d.ts +6 -2
- package/Materials/GreasedLine/greasedLinePluginMaterial.js +8 -2
- package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
- package/Materials/GreasedLine/greasedLinePluginMaterialShadersGLSL.js +17 -11
- package/Materials/GreasedLine/greasedLinePluginMaterialShadersGLSL.js.map +1 -1
- package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js +29 -15
- package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js.map +1 -1
- package/Materials/GreasedLine/greasedLineSimpleMaterial.d.ts +1 -0
- package/Materials/GreasedLine/greasedLineSimpleMaterial.js +1 -0
- package/Materials/GreasedLine/greasedLineSimpleMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Input/inputBlock.js +34 -2
- package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js +1 -3
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +3 -3
- package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +34 -24
- package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +14 -2
- package/Materials/Node/nodeMaterial.js +19 -5
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +5 -0
- package/Materials/PBR/pbrBaseMaterial.js +6 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/Filtering/hdrFiltering.js +1 -0
- package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +69 -0
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +187 -0
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -0
- package/Materials/Textures/hdrCubeTexture.d.ts +5 -1
- package/Materials/Textures/hdrCubeTexture.js +29 -3
- package/Materials/Textures/hdrCubeTexture.js.map +1 -1
- package/Materials/Textures/index.d.ts +4 -0
- package/Materials/Textures/index.js +4 -0
- package/Materials/Textures/index.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.d.ts +12 -0
- package/Materials/Textures/renderTargetTexture.js +29 -8
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/materialHelper.functions.d.ts +17 -1
- package/Materials/materialHelper.functions.js +76 -4
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/shaderMaterial.d.ts +5 -4
- package/Materials/shaderMaterial.js +28 -51
- package/Materials/shaderMaterial.js.map +1 -1
- package/Materials/standardMaterial.d.ts +6 -2
- package/Materials/standardMaterial.js +5 -2
- package/Materials/standardMaterial.js.map +1 -1
- package/Meshes/Builders/greasedLineBuilder.d.ts +1 -1
- package/Meshes/Builders/planeBuilder.js +2 -2
- package/Meshes/Builders/planeBuilder.js.map +1 -1
- package/Meshes/Compression/dracoCodec.d.ts +4 -4
- package/Meshes/Compression/dracoCodec.js.map +1 -1
- package/Meshes/Compression/dracoCompression.d.ts +1 -1
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Compression/dracoCompressionWorker.d.ts +16 -30
- package/Meshes/Compression/dracoCompressionWorker.js +128 -22
- package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
- package/Meshes/Compression/dracoDecoder.d.ts +4 -9
- package/Meshes/Compression/dracoDecoder.js +5 -5
- package/Meshes/Compression/dracoDecoder.js.map +1 -1
- package/Meshes/Compression/dracoDecoder.types.d.ts +52 -0
- package/Meshes/Compression/dracoDecoder.types.js +2 -0
- package/Meshes/Compression/dracoDecoder.types.js.map +1 -0
- package/Meshes/Compression/dracoEncoder.d.ts +91 -0
- package/Meshes/Compression/dracoEncoder.js +239 -0
- package/Meshes/Compression/dracoEncoder.js.map +1 -0
- package/Meshes/Compression/dracoEncoder.types.d.ts +82 -0
- package/Meshes/Compression/dracoEncoder.types.js +2 -0
- package/Meshes/Compression/dracoEncoder.types.js.map +1 -0
- package/Meshes/Compression/index.d.ts +1 -0
- package/Meshes/Compression/index.js +1 -0
- package/Meshes/Compression/index.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +92 -2
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +308 -32
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineBaseMesh.js +4 -1
- package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
- package/Meshes/Node/Blocks/Textures/geometryTextureBlock.d.ts +1 -1
- package/Meshes/abstractMesh.d.ts +1 -2
- package/Meshes/abstractMesh.js +1 -2
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/linesMesh.js +2 -2
- package/Meshes/linesMesh.js.map +1 -1
- package/Meshes/mesh.d.ts +32 -5
- package/Meshes/mesh.js +56 -29
- package/Meshes/mesh.js.map +1 -1
- package/Meshes/subMesh.js +16 -3
- package/Meshes/subMesh.js.map +1 -1
- package/Meshes/transformNode.js +2 -0
- package/Meshes/transformNode.js.map +1 -1
- package/Misc/decorators.serialization.js +2 -0
- package/Misc/decorators.serialization.js.map +1 -1
- package/Misc/fileTools.js +14 -7
- package/Misc/fileTools.js.map +1 -1
- package/Misc/greasedLineTools.d.ts +1 -1
- package/Misc/logger.d.ts +2 -1
- package/Misc/logger.js +2 -1
- package/Misc/logger.js.map +1 -1
- package/Morph/morphTargetManager.d.ts +21 -0
- package/Morph/morphTargetManager.js +37 -2
- package/Morph/morphTargetManager.js.map +1 -1
- package/Particles/pointsCloudSystem.d.ts +3 -3
- package/Physics/v2/Plugins/havokPlugin.d.ts +2 -2
- package/PostProcesses/index.d.ts +1 -0
- package/PostProcesses/index.js +1 -0
- package/PostProcesses/index.js.map +1 -1
- package/PostProcesses/passPostProcess.d.ts +2 -3
- package/PostProcesses/passPostProcess.js +36 -48
- package/PostProcesses/passPostProcess.js.map +1 -1
- package/PostProcesses/thinPassPostProcess.d.ts +48 -0
- package/PostProcesses/thinPassPostProcess.js +113 -0
- package/PostProcesses/thinPassPostProcess.js.map +1 -0
- package/PostProcesses/volumetricLightScatteringPostProcess.js +15 -16
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
- package/Rendering/depthRenderer.js +13 -15
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +13 -15
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/iblCdfGenerator.d.ts +13 -5
- package/Rendering/iblCdfGenerator.js +67 -10
- package/Rendering/iblCdfGenerator.js.map +1 -1
- package/Rendering/objectRenderer.d.ts +9 -2
- package/Rendering/objectRenderer.js +44 -7
- package/Rendering/objectRenderer.js.map +1 -1
- package/Rendering/outlineRenderer.js +13 -15
- package/Rendering/outlineRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/gaussianSplatting.js +6 -6
- package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/Shaders/ShadersInclude/morphTargetsVertex.js +16 -4
- package/Shaders/ShadersInclude/morphTargetsVertex.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflection.js +13 -8
- package/Shaders/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/Shaders/gaussianSplatting.vertex.js +2 -1
- package/Shaders/gaussianSplatting.vertex.js.map +1 -1
- package/Shaders/hdrIrradianceFiltering.fragment.d.ts +9 -0
- package/Shaders/hdrIrradianceFiltering.fragment.js +25 -0
- package/Shaders/hdrIrradianceFiltering.fragment.js.map +1 -0
- package/Shaders/hdrIrradianceFiltering.vertex.d.ts +5 -0
- package/Shaders/hdrIrradianceFiltering.vertex.js +15 -0
- package/Shaders/hdrIrradianceFiltering.vertex.js.map +1 -0
- package/Shaders/pbr.fragment.js +1 -3
- package/Shaders/pbr.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js +17 -5
- package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js +13 -8
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/ShadersWGSL/greasedLine.fragment.js +9 -3
- package/ShadersWGSL/greasedLine.fragment.js.map +1 -1
- package/ShadersWGSL/greasedLine.vertex.js +12 -2
- package/ShadersWGSL/greasedLine.vertex.js.map +1 -1
- package/ShadersWGSL/hdrIrradianceFiltering.fragment.d.ts +9 -0
- package/ShadersWGSL/hdrIrradianceFiltering.fragment.js +26 -0
- package/ShadersWGSL/hdrIrradianceFiltering.fragment.js.map +1 -0
- package/ShadersWGSL/hdrIrradianceFiltering.vertex.d.ts +5 -0
- package/ShadersWGSL/hdrIrradianceFiltering.vertex.js +16 -0
- package/ShadersWGSL/hdrIrradianceFiltering.vertex.js.map +1 -0
- package/ShadersWGSL/outline.fragment.js +1 -1
- package/ShadersWGSL/outline.fragment.js.map +1 -1
- package/ShadersWGSL/passCube.fragment.js +1 -1
- package/ShadersWGSL/passCube.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +1 -3
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/XR/features/WebXRDepthSensing.d.ts +24 -2
- package/XR/features/WebXRDepthSensing.js +320 -26
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/assetContainer.d.ts +43 -0
- package/assetContainer.js +67 -0
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +19 -8
- package/scene.js.map +1 -1
|
@@ -3,12 +3,7 @@ import { Geometry } from "../geometry";
|
|
|
3
3
|
import type { BoundingInfo } from "../../Culling/boundingInfo";
|
|
4
4
|
import type { Scene } from "../../scene";
|
|
5
5
|
import type { Nullable } from "../../types";
|
|
6
|
-
import type {
|
|
7
|
-
export interface MeshData {
|
|
8
|
-
indices?: Uint16Array | Uint32Array;
|
|
9
|
-
attributes: Array<AttributeData>;
|
|
10
|
-
totalVertices: number;
|
|
11
|
-
}
|
|
6
|
+
import type { MeshData } from "./dracoDecoder.types";
|
|
12
7
|
/**
|
|
13
8
|
* @experimental This class is an experimental version of `DracoCompression` and is subject to change.
|
|
14
9
|
*
|
|
@@ -16,7 +11,7 @@ export interface MeshData {
|
|
|
16
11
|
*
|
|
17
12
|
* This class wraps the Draco decoder module.
|
|
18
13
|
*
|
|
19
|
-
* By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js
|
|
14
|
+
* 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.
|
|
20
15
|
*
|
|
21
16
|
* To update the configuration, use the following code:
|
|
22
17
|
* ```javascript
|
|
@@ -62,8 +57,8 @@ export declare class DracoDecoder extends DracoCodec {
|
|
|
62
57
|
*/
|
|
63
58
|
static ResetDefault(skipDispose?: boolean): void;
|
|
64
59
|
protected _isModuleAvailable(): boolean;
|
|
65
|
-
protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?:
|
|
66
|
-
module:
|
|
60
|
+
protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{
|
|
61
|
+
module: unknown; /** DecoderModule */
|
|
67
62
|
}>;
|
|
68
63
|
protected _getWorkerContent(): string;
|
|
69
64
|
/**
|
|
@@ -3,7 +3,7 @@ import { Tools } from "../../Misc/tools.js";
|
|
|
3
3
|
import { Geometry } from "../geometry.js";
|
|
4
4
|
import { VertexBuffer } from "../buffer.js";
|
|
5
5
|
import { Logger } from "../../Misc/logger.js";
|
|
6
|
-
import {
|
|
6
|
+
import { DecodeMesh, DecoderWorkerFunction } from "./dracoCompressionWorker.js";
|
|
7
7
|
/**
|
|
8
8
|
* @experimental This class is an experimental version of `DracoCompression` and is subject to change.
|
|
9
9
|
*
|
|
@@ -11,7 +11,7 @@ import { decodeMesh, workerFunction } from "./dracoCompressionWorker.js";
|
|
|
11
11
|
*
|
|
12
12
|
* This class wraps the Draco decoder module.
|
|
13
13
|
*
|
|
14
|
-
* By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js
|
|
14
|
+
* 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.
|
|
15
15
|
*
|
|
16
16
|
* To update the configuration, use the following code:
|
|
17
17
|
* ```javascript
|
|
@@ -62,12 +62,12 @@ export class DracoDecoder extends DracoCodec {
|
|
|
62
62
|
_isModuleAvailable() {
|
|
63
63
|
return typeof DracoDecoderModule !== "undefined";
|
|
64
64
|
}
|
|
65
|
-
async _createModuleAsync(wasmBinary, jsModule) {
|
|
65
|
+
async _createModuleAsync(wasmBinary, jsModule /** DracoDecoderModule */) {
|
|
66
66
|
const module = await (jsModule || DracoDecoderModule)({ wasmBinary });
|
|
67
67
|
return { module };
|
|
68
68
|
}
|
|
69
69
|
_getWorkerContent() {
|
|
70
|
-
return `${
|
|
70
|
+
return `${DecodeMesh}(${DecoderWorkerFunction})()`;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Creates a new Draco decoder.
|
|
@@ -147,7 +147,7 @@ export class DracoDecoder extends DracoCodec {
|
|
|
147
147
|
return this._modulePromise.then((decoder) => {
|
|
148
148
|
let resultIndices = null;
|
|
149
149
|
const resultAttributes = [];
|
|
150
|
-
const numPoints =
|
|
150
|
+
const numPoints = DecodeMesh(decoder.module, dataView, attributes, (indices) => {
|
|
151
151
|
resultIndices = indices;
|
|
152
152
|
}, (kind, data, size, byteOffset, byteStride, normalized) => {
|
|
153
153
|
resultAttributes.push({
|
|
@@ -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,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,OAAO,CAAC,CAAC;QAC1C,CAAC;QACD,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC1C,QAAQ,CAAC,iBAAiB,CACtB,IAAI,YAAY,CACZ,KAAK,CAAC,SAAS,EAAE,EACjB,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,IAAI,EACd,KAAK,EACL,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,IAAI,EACd,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,IAAI,CACP,EACD,QAAQ,CAAC,aAAa,CACzB,CAAC;QACN,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;;AA1PD;;;;;;GAMG;AACW,iCAAoB,GAA6B;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\";\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, workerFunction } from \"./dracoCompressionWorker\";\r\nimport type { AttributeData, Message } from \"./dracoCompressionWorker\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\nexport interface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\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 preview cdn https://preview.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?: any): Promise<{ module: any /** 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}(${workerFunction})()`;\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 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 return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\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 return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\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,kBAAkB,CAAC;AACzC,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,CAA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ACd,KAAK,EACL,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,IAAI,EACd,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,IAAI,CACP,EACD,QAAQ,CAAC,aAAa,CACzB,CAAC;QACN,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;;AA1PD;;;;;;GAMG;AACW,iCAAoB,GAA6B;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\";\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 { AttributeData, MeshData, DecoderMessage } from \"./dracoDecoder.types\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\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 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 return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\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 return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\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"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decoded Draco mesh data.
|
|
3
|
+
*/
|
|
4
|
+
export interface MeshData {
|
|
5
|
+
/**
|
|
6
|
+
* The indices of the mesh. Point clouds will not have indices.
|
|
7
|
+
*/
|
|
8
|
+
indices?: Uint16Array | Uint32Array;
|
|
9
|
+
/**
|
|
10
|
+
* The attributes of the mesh.
|
|
11
|
+
*/
|
|
12
|
+
attributes: Array<AttributeData>;
|
|
13
|
+
/**
|
|
14
|
+
* The total number of vertices in the mesh.
|
|
15
|
+
*/
|
|
16
|
+
totalVertices: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export interface AttributeData {
|
|
22
|
+
kind: string;
|
|
23
|
+
data: ArrayBufferView;
|
|
24
|
+
size: number;
|
|
25
|
+
byteOffset: number;
|
|
26
|
+
byteStride: number;
|
|
27
|
+
normalized: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export interface DecodeMeshDoneMessage {
|
|
33
|
+
id: "decodeMeshDone";
|
|
34
|
+
totalVertices: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export interface IndicesMessage {
|
|
40
|
+
id: "indices";
|
|
41
|
+
data: Uint16Array | Uint32Array;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export interface AttributeMessage extends AttributeData {
|
|
47
|
+
id: "attribute";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export type DecoderMessage = DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dracoDecoder.types.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Decoded Draco mesh data.\n */\nexport interface MeshData {\n /**\n * The indices of the mesh. Point clouds will not have indices.\n */\n indices?: Uint16Array | Uint32Array;\n /**\n * The attributes of the mesh.\n */\n attributes: Array<AttributeData>;\n /**\n * The total number of vertices in the mesh.\n */\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface AttributeData {\n kind: string;\n data: ArrayBufferView;\n size: number;\n byteOffset: number;\n byteStride: number;\n normalized: boolean;\n}\n\n/**\n * @internal\n */\nexport interface DecodeMeshDoneMessage {\n id: \"decodeMeshDone\";\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface IndicesMessage {\n id: \"indices\";\n data: Uint16Array | Uint32Array;\n}\n\n/**\n * @internal\n */\nexport interface AttributeMessage extends AttributeData {\n id: \"attribute\";\n}\n\n/**\n * @internal\n */\nexport type DecoderMessage = DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { DracoCodec, type IDracoCodecConfiguration } from "./dracoCodec";
|
|
2
|
+
import type { IDracoEncodedMeshData, IDracoEncoderOptions } from "./dracoEncoder.types";
|
|
3
|
+
import type { Nullable } from "../../types";
|
|
4
|
+
import { Mesh } from "../mesh";
|
|
5
|
+
import type { Geometry } from "../geometry";
|
|
6
|
+
/**
|
|
7
|
+
* @experimental This class is subject to change.
|
|
8
|
+
*
|
|
9
|
+
* Draco Encoder (https://google.github.io/draco/)
|
|
10
|
+
*
|
|
11
|
+
* This class wraps the Draco encoder module.
|
|
12
|
+
*
|
|
13
|
+
* 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.
|
|
14
|
+
*
|
|
15
|
+
* To update the configuration, use the following code:
|
|
16
|
+
* ```javascript
|
|
17
|
+
* DracoEncoder.DefaultConfiguration = {
|
|
18
|
+
* wasmUrl: "<url to the WebAssembly library>",
|
|
19
|
+
* wasmBinaryUrl: "<url to the WebAssembly binary>",
|
|
20
|
+
* fallbackUrl: "<url to the fallback JavaScript library>",
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* 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.
|
|
25
|
+
* Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.
|
|
26
|
+
* Use `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.
|
|
27
|
+
*
|
|
28
|
+
* To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:
|
|
29
|
+
* ```javascript
|
|
30
|
+
* var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.
|
|
34
|
+
*
|
|
35
|
+
* Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,
|
|
36
|
+
* when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.
|
|
37
|
+
* You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,
|
|
38
|
+
* ```javascript
|
|
39
|
+
* var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);
|
|
40
|
+
* var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:
|
|
44
|
+
* ```javascript
|
|
45
|
+
* var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };
|
|
46
|
+
* var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class DracoEncoder extends DracoCodec {
|
|
50
|
+
/**
|
|
51
|
+
* Default configuration for the DracoEncoder. Defaults to the following:
|
|
52
|
+
* - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.
|
|
53
|
+
* - wasmUrl: `"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js"`
|
|
54
|
+
* - wasmBinaryUrl: `"https://cdn.babylonjs.com/draco_encoder.wasm"`
|
|
55
|
+
* - fallbackUrl: `"https://cdn.babylonjs.com/draco_encoder.js"`
|
|
56
|
+
*/
|
|
57
|
+
static DefaultConfiguration: IDracoCodecConfiguration;
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if the encoder's `DefaultConfiguration` is available.
|
|
60
|
+
*/
|
|
61
|
+
static get DefaultAvailable(): boolean;
|
|
62
|
+
protected static _Default: Nullable<DracoEncoder>;
|
|
63
|
+
/**
|
|
64
|
+
* Default instance for the DracoEncoder.
|
|
65
|
+
*/
|
|
66
|
+
static get Default(): DracoEncoder;
|
|
67
|
+
/**
|
|
68
|
+
* Reset the default DracoEncoder object to null and disposing the removed default instance.
|
|
69
|
+
* Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,
|
|
70
|
+
* unless the static worker pool is no longer needed.
|
|
71
|
+
* @param skipDispose set to true to not dispose the removed default instance
|
|
72
|
+
*/
|
|
73
|
+
static ResetDefault(skipDispose?: boolean): void;
|
|
74
|
+
protected _isModuleAvailable(): boolean;
|
|
75
|
+
protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoEncoderModule */): Promise<{
|
|
76
|
+
module: unknown; /** EncoderModule */
|
|
77
|
+
}>;
|
|
78
|
+
protected _getWorkerContent(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new Draco encoder.
|
|
81
|
+
* @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.
|
|
82
|
+
*/
|
|
83
|
+
constructor(configuration?: IDracoCodecConfiguration);
|
|
84
|
+
/**
|
|
85
|
+
* Encodes a mesh or geometry into a Draco-encoded mesh data.
|
|
86
|
+
* @param input the mesh or geometry to encode
|
|
87
|
+
* @param options options for the encoding
|
|
88
|
+
* @returns a promise that resolves to the newly-encoded data
|
|
89
|
+
*/
|
|
90
|
+
encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<Nullable<IDracoEncodedMeshData>>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { _IsConfigurationAvailable, DracoCodec } from "./dracoCodec.js";
|
|
2
|
+
import { EncodeMesh, EncoderWorkerFunction } from "./dracoCompressionWorker.js";
|
|
3
|
+
import { Tools } from "../../Misc/tools.js";
|
|
4
|
+
import { VertexBuffer } from "../buffer.js";
|
|
5
|
+
import { Mesh } from "../mesh.js";
|
|
6
|
+
import { Logger } from "../../Misc/logger.js";
|
|
7
|
+
import { deepMerge } from "../../Misc/deepMerger.js";
|
|
8
|
+
import { AreIndices32Bits } from "../../Buffers/bufferUtils.js";
|
|
9
|
+
/**
|
|
10
|
+
* Map the Babylon.js attribute kind to the Draco attribute kind, defined by the `GeometryAttributeType` enum.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
function GetDracoAttributeName(kind) {
|
|
14
|
+
if (kind === VertexBuffer.PositionKind) {
|
|
15
|
+
return "POSITION";
|
|
16
|
+
}
|
|
17
|
+
else if (kind === VertexBuffer.NormalKind) {
|
|
18
|
+
return "NORMAL";
|
|
19
|
+
}
|
|
20
|
+
else if (kind === VertexBuffer.ColorKind) {
|
|
21
|
+
return "COLOR";
|
|
22
|
+
}
|
|
23
|
+
else if (kind.startsWith(VertexBuffer.UVKind)) {
|
|
24
|
+
return "TEX_COORD";
|
|
25
|
+
}
|
|
26
|
+
return "GENERIC";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the indices for the geometry, if present. Eventually used as
|
|
30
|
+
* `AddFacesToMesh(mesh: Mesh, numFaces: number, faces: Uint16Array | Uint32Array)`;
|
|
31
|
+
* where `numFaces = indices.length / 3` and `faces = indices`.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
function PrepareIndicesForDraco(input) {
|
|
35
|
+
let indices = input.getIndices();
|
|
36
|
+
// Convert number[] and Int32Array types, if needed
|
|
37
|
+
if (indices && !(indices instanceof Uint32Array) && !(indices instanceof Uint16Array)) {
|
|
38
|
+
indices = (AreIndices32Bits(indices, indices.length) ? Uint32Array : Uint16Array).from(indices);
|
|
39
|
+
}
|
|
40
|
+
return indices;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get relevant information about the geometry's vertex attributes for Draco encoding. Eventually used for each attribute as
|
|
44
|
+
* `AddFloatAttribute(mesh: Mesh, attribute: number, count: number, itemSize: number, array: TypedArray)`
|
|
45
|
+
* where `attribute = EncoderModule[<dracoAttribute>]`, `itemSize = <size>`, `array = <data>`, and count is the number of position vertices.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
function PrepareAttributesForDraco(input, excludedAttributes) {
|
|
49
|
+
const attributes = [];
|
|
50
|
+
for (const kind of input.getVerticesDataKinds()) {
|
|
51
|
+
if (excludedAttributes?.includes(kind)) {
|
|
52
|
+
if (kind === VertexBuffer.PositionKind) {
|
|
53
|
+
throw new Error("Cannot exclude position attribute from Draco encoding.");
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
// Convert number[] to typed array, if needed
|
|
58
|
+
let data = input.getVerticesData(kind);
|
|
59
|
+
if (!(data instanceof Float32Array)) {
|
|
60
|
+
data = Float32Array.from(data);
|
|
61
|
+
}
|
|
62
|
+
attributes.push({ babylonAttribute: kind, dracoAttribute: GetDracoAttributeName(kind), size: input.getVertexBuffer(kind).getSize(), data: data });
|
|
63
|
+
}
|
|
64
|
+
return attributes;
|
|
65
|
+
}
|
|
66
|
+
const DefaultEncoderOptions = {
|
|
67
|
+
decodeSpeed: 5,
|
|
68
|
+
encodeSpeed: 5,
|
|
69
|
+
method: "MESH_EDGEBREAKER_ENCODING",
|
|
70
|
+
quantizationBits: {
|
|
71
|
+
POSITION: 14,
|
|
72
|
+
NORMAL: 10,
|
|
73
|
+
COLOR: 8,
|
|
74
|
+
TEX_COORD: 12,
|
|
75
|
+
GENERIC: 12,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* @experimental This class is subject to change.
|
|
80
|
+
*
|
|
81
|
+
* Draco Encoder (https://google.github.io/draco/)
|
|
82
|
+
*
|
|
83
|
+
* This class wraps the Draco encoder module.
|
|
84
|
+
*
|
|
85
|
+
* 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.
|
|
86
|
+
*
|
|
87
|
+
* To update the configuration, use the following code:
|
|
88
|
+
* ```javascript
|
|
89
|
+
* DracoEncoder.DefaultConfiguration = {
|
|
90
|
+
* wasmUrl: "<url to the WebAssembly library>",
|
|
91
|
+
* wasmBinaryUrl: "<url to the WebAssembly binary>",
|
|
92
|
+
* fallbackUrl: "<url to the fallback JavaScript library>",
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* 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.
|
|
97
|
+
* Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.
|
|
98
|
+
* Use `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.
|
|
99
|
+
*
|
|
100
|
+
* To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:
|
|
101
|
+
* ```javascript
|
|
102
|
+
* var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.
|
|
106
|
+
*
|
|
107
|
+
* Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,
|
|
108
|
+
* when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.
|
|
109
|
+
* You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,
|
|
110
|
+
* ```javascript
|
|
111
|
+
* var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);
|
|
112
|
+
* var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:
|
|
116
|
+
* ```javascript
|
|
117
|
+
* var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };
|
|
118
|
+
* var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export class DracoEncoder extends DracoCodec {
|
|
122
|
+
/**
|
|
123
|
+
* Returns true if the encoder's `DefaultConfiguration` is available.
|
|
124
|
+
*/
|
|
125
|
+
static get DefaultAvailable() {
|
|
126
|
+
return _IsConfigurationAvailable(DracoEncoder.DefaultConfiguration);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Default instance for the DracoEncoder.
|
|
130
|
+
*/
|
|
131
|
+
static get Default() {
|
|
132
|
+
DracoEncoder._Default ?? (DracoEncoder._Default = new DracoEncoder());
|
|
133
|
+
return DracoEncoder._Default;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Reset the default DracoEncoder object to null and disposing the removed default instance.
|
|
137
|
+
* Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,
|
|
138
|
+
* unless the static worker pool is no longer needed.
|
|
139
|
+
* @param skipDispose set to true to not dispose the removed default instance
|
|
140
|
+
*/
|
|
141
|
+
static ResetDefault(skipDispose) {
|
|
142
|
+
if (DracoEncoder._Default) {
|
|
143
|
+
if (!skipDispose) {
|
|
144
|
+
DracoEncoder._Default.dispose();
|
|
145
|
+
}
|
|
146
|
+
DracoEncoder._Default = null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
_isModuleAvailable() {
|
|
150
|
+
return typeof DracoEncoderModule !== "undefined";
|
|
151
|
+
}
|
|
152
|
+
async _createModuleAsync(wasmBinary, jsModule /** DracoEncoderModule */) {
|
|
153
|
+
const module = await (jsModule || DracoEncoderModule)({ wasmBinary });
|
|
154
|
+
return { module };
|
|
155
|
+
}
|
|
156
|
+
_getWorkerContent() {
|
|
157
|
+
return `${EncodeMesh}(${EncoderWorkerFunction})()`;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Creates a new Draco encoder.
|
|
161
|
+
* @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.
|
|
162
|
+
*/
|
|
163
|
+
constructor(configuration = DracoEncoder.DefaultConfiguration) {
|
|
164
|
+
super(configuration);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Encodes a mesh or geometry into a Draco-encoded mesh data.
|
|
168
|
+
* @param input the mesh or geometry to encode
|
|
169
|
+
* @param options options for the encoding
|
|
170
|
+
* @returns a promise that resolves to the newly-encoded data
|
|
171
|
+
*/
|
|
172
|
+
async encodeMeshAsync(input, options) {
|
|
173
|
+
const verticesCount = input.getTotalVertices();
|
|
174
|
+
if (verticesCount == 0) {
|
|
175
|
+
throw new Error("Cannot compress geometry with Draco. There are no vertices.");
|
|
176
|
+
}
|
|
177
|
+
// Prepare parameters for encoding
|
|
178
|
+
const mergedOptions = options ? deepMerge(DefaultEncoderOptions, options) : DefaultEncoderOptions;
|
|
179
|
+
if (input instanceof Mesh && input.morphTargetManager && mergedOptions.method === "MESH_EDGEBREAKER_ENCODING") {
|
|
180
|
+
Logger.Warn("Cannot use Draco EDGEBREAKER method with morph targets. Falling back to SEQUENTIAL method.");
|
|
181
|
+
mergedOptions.method = "MESH_SEQUENTIAL_ENCODING";
|
|
182
|
+
}
|
|
183
|
+
let indices = PrepareIndicesForDraco(input);
|
|
184
|
+
const attributes = PrepareAttributesForDraco(input, mergedOptions.excludedAttributes);
|
|
185
|
+
if (this._workerPoolPromise) {
|
|
186
|
+
const workerPool = await this._workerPoolPromise;
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
workerPool.push((worker, onComplete) => {
|
|
189
|
+
const onError = (error) => {
|
|
190
|
+
worker.removeEventListener("error", onError);
|
|
191
|
+
worker.removeEventListener("message", onMessage);
|
|
192
|
+
reject(error);
|
|
193
|
+
onComplete();
|
|
194
|
+
};
|
|
195
|
+
const onMessage = (message) => {
|
|
196
|
+
if (message.data.id === "encodeMeshDone") {
|
|
197
|
+
worker.removeEventListener("error", onError);
|
|
198
|
+
worker.removeEventListener("message", onMessage);
|
|
199
|
+
resolve(message.data.encodedMeshData);
|
|
200
|
+
onComplete();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
worker.addEventListener("error", onError);
|
|
204
|
+
worker.addEventListener("message", onMessage);
|
|
205
|
+
// Manually create copies of our attribute data and add them to the transfer list to ensure we only copy the ArrayBuffer data we need.
|
|
206
|
+
const transferList = [];
|
|
207
|
+
attributes.forEach((attribute) => {
|
|
208
|
+
attribute.data = attribute.data.slice();
|
|
209
|
+
transferList.push(attribute.data.buffer);
|
|
210
|
+
});
|
|
211
|
+
if (indices) {
|
|
212
|
+
indices = indices.slice();
|
|
213
|
+
transferList.push(indices.buffer);
|
|
214
|
+
}
|
|
215
|
+
worker.postMessage({ id: "encodeMesh", attributes: attributes, indices: indices, options: mergedOptions }, transferList);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
if (this._modulePromise) {
|
|
220
|
+
const encoder = await this._modulePromise;
|
|
221
|
+
return EncodeMesh(encoder.module, attributes, indices, mergedOptions);
|
|
222
|
+
}
|
|
223
|
+
throw new Error("Draco encoder module is not available");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Default configuration for the DracoEncoder. Defaults to the following:
|
|
228
|
+
* - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.
|
|
229
|
+
* - wasmUrl: `"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js"`
|
|
230
|
+
* - wasmBinaryUrl: `"https://cdn.babylonjs.com/draco_encoder.wasm"`
|
|
231
|
+
* - fallbackUrl: `"https://cdn.babylonjs.com/draco_encoder.js"`
|
|
232
|
+
*/
|
|
233
|
+
DracoEncoder.DefaultConfiguration = {
|
|
234
|
+
wasmUrl: `${Tools._DefaultCdnUrl}/draco_encoder_wasm_wrapper.js`,
|
|
235
|
+
wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_encoder.wasm`,
|
|
236
|
+
fallbackUrl: `${Tools._DefaultCdnUrl}/draco_encoder.js`,
|
|
237
|
+
};
|
|
238
|
+
DracoEncoder._Default = null;
|
|
239
|
+
//# sourceMappingURL=d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AU,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC7D,CAAC;;AApID;;;;;;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;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions, DracoAttributeName } from \"./dracoEncoder.types\";\r\nimport { EncodeMesh, EncoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Mesh } from \"../mesh\";\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 } 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\n// eslint-disable-next-line @typescript-eslint/naming-convention\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();\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(\"Cannot exclude position attribute from Draco encoding.\");\r\n }\r\n continue;\r\n }\r\n\r\n // Convert number[] to typed array, if needed\r\n let data = input.getVerticesData(kind)!;\r\n if (!(data instanceof Float32Array)) {\r\n data = Float32Array.from(data!);\r\n }\r\n attributes.push({ babylonAttribute: kind, dracoAttribute: GetDracoAttributeName(kind), size: input.getVertexBuffer(kind)!.getSize(), 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 * 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 * 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<Nullable<IDracoEncodedMeshData>> {\r\n const verticesCount = input.getTotalVertices();\r\n if (verticesCount == 0) {\r\n throw new Error(\"Cannot compress geometry with Draco. There are no vertices.\");\r\n }\r\n\r\n // Prepare parameters for encoding\r\n const mergedOptions = options ? deepMerge(DefaultEncoderOptions, options) : DefaultEncoderOptions;\r\n if (input instanceof Mesh && input.morphTargetManager && mergedOptions.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n Logger.Warn(\"Cannot use Draco EDGEBREAKER method with morph targets. Falling back to SEQUENTIAL method.\");\r\n mergedOptions.method = \"MESH_SEQUENTIAL_ENCODING\";\r\n }\r\n\r\n let indices = PrepareIndicesForDraco(input);\r\n const attributes = PrepareAttributesForDraco(input, mergedOptions.excludedAttributes);\r\n\r\n if (this._workerPoolPromise) {\r\n const workerPool = await this._workerPoolPromise;\r\n return new Promise<Nullable<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 reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent<EncoderMessage>) => {\r\n if (message.data.id === \"encodeMeshDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(message.data.encodedMeshData);\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 // Manually create copies of our attribute data and add them to the transfer list to ensure we only copy the ArrayBuffer data we need.\r\n const transferList = [];\r\n attributes.forEach((attribute) => {\r\n attribute.data = attribute.data.slice();\r\n transferList.push(attribute.data.buffer);\r\n });\r\n if (indices) {\r\n indices = indices.slice();\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"]}
|