@babylonjs/core 7.44.0 → 7.45.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/Debug/debugLayer.d.ts +4 -0
- package/Debug/debugLayer.js +9 -0
- package/Debug/debugLayer.js.map +1 -1
- package/Engines/Extensions/engine.renderTarget.js +2 -4
- package/Engines/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTarget.js +2 -4
- package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/abstractEngine.d.ts +19 -1
- package/Engines/abstractEngine.js +48 -9
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.d.ts +1 -1
- package/Engines/engine.js +2 -20
- package/Engines/engine.js.map +1 -1
- package/Engines/renderTargetWrapper.js +2 -2
- package/Engines/renderTargetWrapper.js.map +1 -1
- package/Engines/thinEngine.js +1 -5
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +1 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.d.ts +16 -12
- package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js +63 -27
- package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.d.ts +72 -0
- package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.js +197 -0
- package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.js.map +1 -0
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.d.ts +4 -0
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +9 -0
- package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
- package/FrameGraph/Node/Blocks/index.d.ts +1 -0
- package/FrameGraph/Node/Blocks/index.js +1 -0
- package/FrameGraph/Node/Blocks/index.js.map +1 -1
- package/FrameGraph/Node/Types/nodeRenderGraphTypes.d.ts +4 -2
- package/FrameGraph/Node/Types/nodeRenderGraphTypes.js +2 -0
- package/FrameGraph/Node/Types/nodeRenderGraphTypes.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraph.d.ts +3 -2
- package/FrameGraph/Node/nodeRenderGraph.js +4 -3
- package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraphBlock.js +4 -4
- package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.d.ts +8 -0
- package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.js +10 -0
- package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.js.map +1 -1
- package/FrameGraph/Node/nodeRenderGraphConnectionPointCustomObject.d.ts +21 -0
- package/FrameGraph/Node/nodeRenderGraphConnectionPointCustomObject.js +31 -0
- package/FrameGraph/Node/nodeRenderGraphConnectionPointCustomObject.js.map +1 -0
- package/FrameGraph/Passes/pass.d.ts +1 -0
- package/FrameGraph/Passes/pass.js +4 -1
- package/FrameGraph/Passes/pass.js.map +1 -1
- package/FrameGraph/Tasks/Layers/baseLayerTask.d.ts +81 -0
- package/FrameGraph/Tasks/Layers/baseLayerTask.js +304 -0
- package/FrameGraph/Tasks/Layers/baseLayerTask.js.map +1 -0
- package/FrameGraph/Tasks/Layers/glowLayerTask.d.ts +3 -40
- package/FrameGraph/Tasks/Layers/glowLayerTask.js +4 -158
- package/FrameGraph/Tasks/Layers/glowLayerTask.js.map +1 -1
- package/FrameGraph/Tasks/Layers/highlightLayerTask.d.ts +21 -0
- package/FrameGraph/Tasks/Layers/highlightLayerTask.js +32 -0
- package/FrameGraph/Tasks/Layers/highlightLayerTask.js.map +1 -0
- package/FrameGraph/Tasks/Misc/executeTask.d.ts +2 -2
- package/FrameGraph/Tasks/Misc/executeTask.js +1 -0
- package/FrameGraph/Tasks/Misc/executeTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js +1 -1
- package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/bloomTask.js +1 -1
- package/FrameGraph/Tasks/PostProcesses/bloomTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js +5 -4
- package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js +5 -4
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js +2 -4
- package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js.map +1 -1
- package/FrameGraph/Tasks/PostProcesses/postProcessTask.js +4 -2
- package/FrameGraph/Tasks/PostProcesses/postProcessTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +2 -2
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js +1 -0
- package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.d.ts +2 -2
- package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js +1 -0
- package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js.map +1 -1
- package/FrameGraph/Tasks/Texture/clearTextureTask.d.ts +2 -2
- package/FrameGraph/Tasks/Texture/clearTextureTask.js +1 -0
- package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
- package/FrameGraph/Tasks/Texture/copyToTextureTask.js +1 -1
- package/FrameGraph/Tasks/Texture/copyToTextureTask.js.map +1 -1
- package/FrameGraph/frameGraph.d.ts +8 -2
- package/FrameGraph/frameGraph.js +31 -5
- package/FrameGraph/frameGraph.js.map +1 -1
- package/FrameGraph/frameGraphRenderContext.d.ts +10 -0
- package/FrameGraph/frameGraphRenderContext.js +14 -0
- package/FrameGraph/frameGraphRenderContext.js.map +1 -1
- package/FrameGraph/frameGraphTask.d.ts +3 -2
- package/FrameGraph/frameGraphTask.js +12 -2
- package/FrameGraph/frameGraphTask.js.map +1 -1
- package/FrameGraph/frameGraphTypes.d.ts +4 -0
- package/FrameGraph/frameGraphTypes.js.map +1 -1
- package/FrameGraph/index.d.ts +1 -0
- package/FrameGraph/index.js +1 -0
- package/FrameGraph/index.js.map +1 -1
- package/Helpers/environmentHelper.js +7 -6
- package/Helpers/environmentHelper.js.map +1 -1
- package/Layers/effectLayer.d.ts +1 -1
- package/Layers/effectLayer.js.map +1 -1
- package/Layers/glowLayer.d.ts +2 -14
- package/Layers/glowLayer.js +34 -36
- package/Layers/glowLayer.js.map +1 -1
- package/Layers/highlightLayer.d.ts +13 -74
- package/Layers/highlightLayer.js +123 -309
- package/Layers/highlightLayer.js.map +1 -1
- package/Layers/index.d.ts +1 -0
- package/Layers/index.js +1 -0
- package/Layers/index.js.map +1 -1
- package/Layers/thinEffectLayer.d.ts +55 -2
- package/Layers/thinEffectLayer.js +66 -0
- package/Layers/thinEffectLayer.js.map +1 -1
- package/Layers/thinGlowLayer.d.ts +3 -6
- package/Layers/thinGlowLayer.js +4 -1
- package/Layers/thinGlowLayer.js.map +1 -1
- package/Layers/thinHighlightLayer.d.ts +197 -0
- package/Layers/thinHighlightLayer.js +417 -0
- package/Layers/thinHighlightLayer.js.map +1 -0
- package/Materials/Node/nodeMaterial.js +2 -1
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBRDFConfiguration.d.ts +14 -0
- package/Materials/PBR/pbrBRDFConfiguration.js +19 -0
- package/Materials/PBR/pbrBRDFConfiguration.js.map +1 -1
- package/Materials/effect.d.ts +5 -0
- package/Materials/effect.js +15 -0
- package/Materials/effect.js.map +1 -1
- package/Meshes/Compression/dracoCompression.d.ts +4 -2
- package/Meshes/Compression/dracoCompression.js +24 -11
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Compression/dracoCompressionWorker.js +4 -4
- package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.d.ts +5 -1
- package/Meshes/Compression/dracoEncoder.js +23 -17
- package/Meshes/Compression/dracoEncoder.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.types.d.ts +4 -4
- package/Meshes/Compression/dracoEncoder.types.js.map +1 -1
- package/Meshes/Compression/meshoptCompression.js +17 -2
- package/Meshes/Compression/meshoptCompression.js.map +1 -1
- package/Meshes/Compression/test/integration/draco.test.d.ts +1 -0
- package/Meshes/Compression/test/integration/draco.test.js +30 -0
- package/Meshes/Compression/test/integration/draco.test.js.map +1 -0
- package/Meshes/csg.js +4 -0
- package/Meshes/csg.js.map +1 -1
- package/Meshes/transformNode.d.ts +4 -1
- package/Meshes/transformNode.js +4 -1
- package/Meshes/transformNode.js.map +1 -1
- package/Misc/copyTextureToTexture.js +1 -1
- package/Misc/copyTextureToTexture.js.map +1 -1
- package/Misc/error.d.ts +6 -0
- package/Misc/error.js +10 -0
- package/Misc/error.js.map +1 -1
- package/Misc/screenshotTools.js +58 -5
- package/Misc/screenshotTools.js.map +1 -1
- package/Misc/tools.d.ts +21 -1
- package/Misc/tools.js +33 -0
- package/Misc/tools.js.map +1 -1
- package/Particles/particleHelper.js +2 -1
- package/Particles/particleHelper.js.map +1 -1
- package/Particles/particleSystemSet.d.ts +1 -0
- package/Particles/particleSystemSet.js +1 -0
- package/Particles/particleSystemSet.js.map +1 -1
- package/Particles/webgl2ParticleSystem.d.ts +1 -1
- package/Particles/webgl2ParticleSystem.js +1 -2
- package/Particles/webgl2ParticleSystem.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +2 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
- package/Rendering/depthRenderer.js +1 -1
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/objectRenderer.d.ts +5 -3
- package/Rendering/objectRenderer.js +5 -3
- package/Rendering/objectRenderer.js.map +1 -1
- package/Rendering/renderingManager.d.ts +4 -0
- package/Rendering/renderingManager.js +1 -0
- package/Rendering/renderingManager.js.map +1 -1
- package/Shaders/ShadersInclude/intersectionFunctions.d.ts +5 -0
- package/Shaders/ShadersInclude/intersectionFunctions.js +14 -0
- package/Shaders/ShadersInclude/intersectionFunctions.js.map +1 -0
- package/Shaders/ShadersInclude/pbrBlockReflection.js +7 -1
- package/Shaders/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/Shaders/background.fragment.d.ts +1 -0
- package/Shaders/background.fragment.js +3 -5
- package/Shaders/background.fragment.js.map +1 -1
- package/Shaders/gaussianSplatting.vertex.d.ts +1 -0
- package/Shaders/gaussianSplatting.vertex.js +3 -1
- package/Shaders/gaussianSplatting.vertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/intersectionFunctions.d.ts +5 -0
- package/ShadersWGSL/ShadersInclude/intersectionFunctions.js +14 -0
- package/ShadersWGSL/ShadersInclude/intersectionFunctions.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js +7 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/ShadersWGSL/background.fragment.d.ts +1 -0
- package/ShadersWGSL/background.fragment.js +3 -5
- package/ShadersWGSL/background.fragment.js.map +1 -1
- package/ShadersWGSL/glowMapGeneration.fragment.js +1 -2
- package/ShadersWGSL/glowMapGeneration.fragment.js.map +1 -1
- package/ShadersWGSL/layer.fragment.js +1 -2
- package/ShadersWGSL/layer.fragment.js.map +1 -1
- package/XR/features/WebXRHandTracking.js +8 -7
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +4 -0
- package/types.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAA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AC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,2CAA2C;QAC3C,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,CAAC,WAAW,CAAC;gBACf,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;aACjB,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,iDAAiD;YACjD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,WAAW,CACd;gBACI,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,KAAK;aACpB,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACN,CAAC;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from \"./dracoEncoder.types\";\r\nimport type { DecoderMessage } from \"./dracoDecoder.types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status, DecoderModule, EncoderModule, MeshBuilder, Encoder, DracoInt8Array } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoEncoderModule: (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: InitDoneMessage | DecoderMessage | EncoderMessage, transfer?: ArrayBufferLike[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function EncodeMesh(\r\n module: unknown /** EncoderModule */,\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options: IDracoEncoderOptions\r\n): Nullable<IDracoEncodedMeshData> {\r\n const encoderModule = module as EncoderModule;\r\n let encoder: Nullable<Encoder> = null;\r\n let meshBuilder: Nullable<MeshBuilder> = null;\r\n let mesh: Nullable<Mesh> = null;\r\n let encodedNativeBuffer: Nullable<DracoInt8Array> = null;\r\n const attributeIDs: Record<string, number> = {}; // Babylon kind -> Draco unique id\r\n\r\n // Double-check that at least a position attribute is provided\r\n const positionAttribute = attributes.find((a) => a.babylonAttribute === \"position\");\r\n if (!positionAttribute) {\r\n throw new Error(\"Position attribute is required for Draco encoding\");\r\n }\r\n\r\n // If no indices are provided, assume mesh is unindexed. Let's generate them, since Draco meshes require them.\r\n // TODO: This may be the POINT_CLOUD case, but need to investigate. Should work for now-- just less efficient.\r\n if (!indices) {\r\n // Assume position attribute is the largest attribute.\r\n const positionVerticesCount = positionAttribute.data.length / positionAttribute.size;\r\n indices = new (positionVerticesCount > 65535 ? Uint32Array : Uint16Array)(positionVerticesCount);\r\n for (let i = 0; i < positionVerticesCount; i++) {\r\n indices[i] = i;\r\n }\r\n }\r\n\r\n try {\r\n encoder = new encoderModule.Encoder();\r\n meshBuilder = new encoderModule.MeshBuilder();\r\n mesh = new encoderModule.Mesh();\r\n\r\n // Add the faces\r\n meshBuilder.AddFacesToMesh(mesh, indices.length / 3, indices);\r\n\r\n // Add the attributes\r\n for (const attribute of attributes) {\r\n const verticesCount = attribute.data.length / attribute.size;\r\n attributeIDs[attribute.babylonAttribute] = meshBuilder.AddFloatAttribute(mesh, encoderModule[attribute.dracoAttribute], verticesCount, attribute.size, attribute.data);\r\n if (options.quantizationBits && options.quantizationBits[attribute.dracoAttribute]) {\r\n encoder.SetAttributeQuantization(encoderModule[attribute.dracoAttribute], options.quantizationBits[attribute.dracoAttribute]);\r\n }\r\n }\r\n\r\n // Set the options\r\n if (options.method) {\r\n encoder.SetEncodingMethod(encoderModule[options.method]);\r\n }\r\n if (options.encodeSpeed !== undefined && options.decodeSpeed !== undefined) {\r\n encoder.SetSpeedOptions(options.encodeSpeed, options.decodeSpeed);\r\n }\r\n\r\n // Encode to native buffer\r\n encodedNativeBuffer = new encoderModule.DracoInt8Array() as DracoInt8Array;\r\n const encodedLength = encoder.EncodeMeshToDracoBuffer(mesh, encodedNativeBuffer);\r\n if (encodedLength <= 0) {\r\n throw new Error(\"Draco encoding failed.\");\r\n }\r\n\r\n // Copy the native buffer data to worker heap\r\n const encodedData = new Int8Array(encodedLength);\r\n for (let i = 0; i < encodedLength; i++) {\r\n encodedData[i] = encodedNativeBuffer.GetValue(i);\r\n }\r\n\r\n return { data: encodedData, attributeIDs: attributeIDs };\r\n } finally {\r\n if (mesh) {\r\n encoderModule.destroy(mesh);\r\n }\r\n if (meshBuilder) {\r\n encoderModule.destroy(meshBuilder);\r\n }\r\n if (encoder) {\r\n encoderModule.destroy(encoder);\r\n }\r\n if (encodedNativeBuffer) {\r\n encoderModule.destroy(encodedNativeBuffer);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function EncoderWorkerFunction(): void {\r\n let encoderPromise: PromiseLike<EncoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initEncoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n encoderPromise = DracoEncoderModule(initEncoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"encodeMesh\": {\r\n if (!encoderPromise) {\r\n throw new Error(\"Draco encoder module is not available\");\r\n }\r\n encoderPromise.then((encoder) => {\r\n const result = EncodeMesh(encoder, message.attributes, message.indices, message.options);\r\n postMessage({ id: \"encodeMeshDone\", encodedMeshData: result }, result ? [result.data.buffer] : undefined);\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function DecodeMesh(\r\n module: unknown /** DecoderModule */,\r\n data: Int8Array,\r\n attributeIDs: Record<string, number> | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n const decoderModule = module as DecoderModule;\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder();\r\n\r\n buffer = new decoderModule.DecoderBuffer();\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh as Mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud as PointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any /** Attribute */) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n // this cast seems to be needed because of an issue with typescript, as all constructors do have the ptr and numValues arguments.\r\n const data = new (info.typedArrayConstructor as Float32ArrayConstructor)(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributeIDs) {\r\n for (const kind in attributeIDs) {\r\n const id = attributeIDs[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: Record<string, number> = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function DecoderWorkerFunction(): void {\r\n let decoderPromise: PromiseLike<DecoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initDecoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n decoderPromise = DracoDecoderModule(initDecoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = DecodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, size, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n// For backwards compatibility\r\nexport { DecoderWorkerFunction as workerFunction };\r\n\r\n/**\r\n * Initializes a worker that was created for the draco agent pool\r\n * @param worker The worker to initialize\r\n * @param wasmBinary The wasm binary to load into the worker\r\n * @param moduleUrl The url to the draco decoder module (optional)\r\n * @returns A promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, wasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return new Promise<Worker>((resolve, reject) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<InitDoneMessage>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // Load with either JS-only or WASM version\r\n if (!wasmBinary) {\r\n worker.postMessage({\r\n id: \"init\",\r\n url: moduleUrl,\r\n });\r\n } else {\r\n // clone the array buffer to make it transferable\r\n const clone = wasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n [clone]\r\n );\r\n }\r\n // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers\r\n });\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"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M,CAAC,CAAC;YACpB,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,2CAA2C;QAC3C,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,CAAC,WAAW,CAAC;gBACf,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;aACjB,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,iDAAiD;YACjD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,WAAW,CACd;gBACI,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,KAAK;aACpB,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACN,CAAC;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from \"./dracoEncoder.types\";\r\nimport type { DecoderMessage } from \"./dracoDecoder.types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status, DecoderModule, EncoderModule, MeshBuilder, Encoder, DracoInt8Array } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoEncoderModule: (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: InitDoneMessage | DecoderMessage | EncoderMessage, transfer?: ArrayBufferLike[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function EncodeMesh(\r\n module: unknown /** EncoderModule */,\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options: IDracoEncoderOptions\r\n): Nullable<IDracoEncodedMeshData> {\r\n const encoderModule = module as EncoderModule;\r\n let encoder: Nullable<Encoder> = null;\r\n let meshBuilder: Nullable<MeshBuilder> = null;\r\n let mesh: Nullable<Mesh> = null;\r\n let encodedNativeBuffer: Nullable<DracoInt8Array> = null;\r\n const attributeIDs: Record<string, number> = {}; // Babylon kind -> Draco unique id\r\n\r\n // Double-check that at least a position attribute is provided\r\n const positionAttribute = attributes.find((a) => a.dracoName === \"POSITION\");\r\n if (!positionAttribute) {\r\n throw new Error(\"Position attribute is required for Draco encoding\");\r\n }\r\n\r\n // If no indices are provided, assume mesh is unindexed. Let's generate them, since Draco meshes require them.\r\n // TODO: This may be the POINT_CLOUD case, but need to investigate. Should work for now-- just less efficient.\r\n if (!indices) {\r\n // Assume position attribute is the largest attribute.\r\n const positionVerticesCount = positionAttribute.data.length / positionAttribute.size;\r\n indices = new (positionVerticesCount > 65535 ? Uint32Array : Uint16Array)(positionVerticesCount);\r\n for (let i = 0; i < positionVerticesCount; i++) {\r\n indices[i] = i;\r\n }\r\n }\r\n\r\n try {\r\n encoder = new encoderModule.Encoder();\r\n meshBuilder = new encoderModule.MeshBuilder();\r\n mesh = new encoderModule.Mesh();\r\n\r\n // Add the faces\r\n meshBuilder.AddFacesToMesh(mesh, indices.length / 3, indices);\r\n\r\n // Add the attributes\r\n for (const attribute of attributes) {\r\n const verticesCount = attribute.data.length / attribute.size;\r\n attributeIDs[attribute.kind] = meshBuilder.AddFloatAttribute(mesh, encoderModule[attribute.dracoName], verticesCount, attribute.size, attribute.data);\r\n if (options.quantizationBits && options.quantizationBits[attribute.dracoName]) {\r\n encoder.SetAttributeQuantization(encoderModule[attribute.dracoName], options.quantizationBits[attribute.dracoName]);\r\n }\r\n }\r\n\r\n // Set the options\r\n if (options.method) {\r\n encoder.SetEncodingMethod(encoderModule[options.method]);\r\n }\r\n if (options.encodeSpeed !== undefined && options.decodeSpeed !== undefined) {\r\n encoder.SetSpeedOptions(options.encodeSpeed, options.decodeSpeed);\r\n }\r\n\r\n // Encode to native buffer\r\n encodedNativeBuffer = new encoderModule.DracoInt8Array() as DracoInt8Array;\r\n const encodedLength = encoder.EncodeMeshToDracoBuffer(mesh, encodedNativeBuffer);\r\n if (encodedLength <= 0) {\r\n throw new Error(\"Draco encoding failed.\");\r\n }\r\n\r\n // Copy the native buffer data to worker heap\r\n const encodedData = new Int8Array(encodedLength);\r\n for (let i = 0; i < encodedLength; i++) {\r\n encodedData[i] = encodedNativeBuffer.GetValue(i);\r\n }\r\n\r\n return { data: encodedData, attributeIDs: attributeIDs };\r\n } finally {\r\n if (mesh) {\r\n encoderModule.destroy(mesh);\r\n }\r\n if (meshBuilder) {\r\n encoderModule.destroy(meshBuilder);\r\n }\r\n if (encoder) {\r\n encoderModule.destroy(encoder);\r\n }\r\n if (encodedNativeBuffer) {\r\n encoderModule.destroy(encodedNativeBuffer);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function EncoderWorkerFunction(): void {\r\n let encoderPromise: PromiseLike<EncoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initEncoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n encoderPromise = DracoEncoderModule(initEncoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"encodeMesh\": {\r\n if (!encoderPromise) {\r\n throw new Error(\"Draco encoder module is not available\");\r\n }\r\n encoderPromise.then((encoder) => {\r\n const result = EncodeMesh(encoder, message.attributes, message.indices, message.options);\r\n postMessage({ id: \"encodeMeshDone\", encodedMeshData: result }, result ? [result.data.buffer] : undefined);\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function DecodeMesh(\r\n module: unknown /** DecoderModule */,\r\n data: Int8Array,\r\n attributeIDs: Record<string, number> | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n const decoderModule = module as DecoderModule;\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder();\r\n\r\n buffer = new decoderModule.DecoderBuffer();\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh as Mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud as PointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any /** Attribute */) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n // this cast seems to be needed because of an issue with typescript, as all constructors do have the ptr and numValues arguments.\r\n const data = new (info.typedArrayConstructor as Float32ArrayConstructor)(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributeIDs) {\r\n for (const kind in attributeIDs) {\r\n const id = attributeIDs[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: Record<string, number> = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function DecoderWorkerFunction(): void {\r\n let decoderPromise: PromiseLike<DecoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initDecoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n decoderPromise = DracoDecoderModule(initDecoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = DecodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, size, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n// For backwards compatibility\r\nexport { DecoderWorkerFunction as workerFunction };\r\n\r\n/**\r\n * Initializes a worker that was created for the draco agent pool\r\n * @param worker The worker to initialize\r\n * @param wasmBinary The wasm binary to load into the worker\r\n * @param moduleUrl The url to the draco decoder module (optional)\r\n * @returns A promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, wasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return new Promise<Worker>((resolve, reject) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<InitDoneMessage>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // Load with either JS-only or WASM version\r\n if (!wasmBinary) {\r\n worker.postMessage({\r\n id: \"init\",\r\n url: moduleUrl,\r\n });\r\n } else {\r\n // clone the array buffer to make it transferable\r\n const clone = wasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n [clone]\r\n );\r\n }\r\n // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers\r\n });\r\n}\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DracoCodec, type IDracoCodecConfiguration } from "./dracoCodec";
|
|
2
|
-
import type { IDracoEncodedMeshData, IDracoEncoderOptions } from "./dracoEncoder.types";
|
|
2
|
+
import type { IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from "./dracoEncoder.types";
|
|
3
3
|
import type { Nullable } from "../../types";
|
|
4
4
|
import { Mesh } from "../mesh";
|
|
5
5
|
import type { Geometry } from "../geometry";
|
|
@@ -81,6 +81,10 @@ export declare class DracoEncoder extends DracoCodec {
|
|
|
81
81
|
* @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.
|
|
82
82
|
*/
|
|
83
83
|
constructor(configuration?: IDracoCodecConfiguration);
|
|
84
|
+
/**
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
_encodeAsync(attributes: Array<IDracoAttributeData>, indices: Nullable<Uint16Array | Uint32Array>, options?: IDracoEncoderOptions): Promise<Nullable<IDracoEncodedMeshData>>;
|
|
84
88
|
/**
|
|
85
89
|
* Encodes a mesh or geometry into a Draco-encoded mesh data.
|
|
86
90
|
* @param input the mesh or geometry to encode
|
|
@@ -59,7 +59,7 @@ function PrepareAttributesForDraco(input, excludedAttributes) {
|
|
|
59
59
|
if (!(data instanceof Float32Array)) {
|
|
60
60
|
data = Float32Array.from(data);
|
|
61
61
|
}
|
|
62
|
-
attributes.push({
|
|
62
|
+
attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: input.getVertexBuffer(kind).getSize(), data: data });
|
|
63
63
|
}
|
|
64
64
|
return attributes;
|
|
65
65
|
}
|
|
@@ -164,24 +164,10 @@ export class DracoEncoder extends DracoCodec {
|
|
|
164
164
|
super(configuration);
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
-
*
|
|
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
|
|
167
|
+
* @internal
|
|
171
168
|
*/
|
|
172
|
-
async
|
|
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
|
|
169
|
+
async _encodeAsync(attributes, indices, options) {
|
|
178
170
|
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
171
|
if (this._workerPoolPromise) {
|
|
186
172
|
const workerPool = await this._workerPoolPromise;
|
|
187
173
|
return new Promise((resolve, reject) => {
|
|
@@ -222,6 +208,26 @@ export class DracoEncoder extends DracoCodec {
|
|
|
222
208
|
}
|
|
223
209
|
throw new Error("Draco encoder module is not available");
|
|
224
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Encodes a mesh or geometry into a Draco-encoded mesh data.
|
|
213
|
+
* @param input the mesh or geometry to encode
|
|
214
|
+
* @param options options for the encoding
|
|
215
|
+
* @returns a promise that resolves to the newly-encoded data
|
|
216
|
+
*/
|
|
217
|
+
async encodeMeshAsync(input, options) {
|
|
218
|
+
const verticesCount = input.getTotalVertices();
|
|
219
|
+
if (verticesCount == 0) {
|
|
220
|
+
throw new Error("Cannot compress geometry with Draco. There are no vertices.");
|
|
221
|
+
}
|
|
222
|
+
// Prepare parameters for encoding
|
|
223
|
+
if (input instanceof Mesh && input.morphTargetManager && options?.method === "MESH_EDGEBREAKER_ENCODING") {
|
|
224
|
+
Logger.Warn("Cannot use Draco EDGEBREAKER method with morph targets. Falling back to SEQUENTIAL method.");
|
|
225
|
+
options.method = "MESH_SEQUENTIAL_ENCODING";
|
|
226
|
+
}
|
|
227
|
+
const indices = PrepareIndicesForDraco(input);
|
|
228
|
+
const attributes = PrepareAttributesForDraco(input, options?.excludedAttributes);
|
|
229
|
+
return this._encodeAsync(attributes, indices, options);
|
|
230
|
+
}
|
|
225
231
|
}
|
|
226
232
|
/**
|
|
227
233
|
* Default configuration for the DracoEncoder. Defaults to the following:
|
|
@@ -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,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,qCAAiC;AAQ5D;;;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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EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,YAAY,CAAC,CAAC;gBAC7H,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;YAC1C,OAAO,UAAU,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"]}
|
|
1
|
+
{"version":3,"file":"dracoEncoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/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G,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAG,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;QAEjF,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;;AAhJD;;;;;;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({ kind: kind, dracoName: 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 * @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<Nullable<IDracoEncodedMeshData>> {\r\n const mergedOptions = options ? deepMerge(DefaultEncoderOptions, options) : DefaultEncoderOptions;\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 /**\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 if (input instanceof Mesh && input.morphTargetManager && options?.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n Logger.Warn(\"Cannot use Draco EDGEBREAKER 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 this._encodeAsync(attributes, indices, options);\r\n }\r\n}\r\n"]}
|
|
@@ -38,13 +38,13 @@ export interface IDracoEncoderOptions {
|
|
|
38
38
|
*/
|
|
39
39
|
export interface IDracoAttributeData {
|
|
40
40
|
/**
|
|
41
|
-
* The
|
|
41
|
+
* The kind of the attribute.
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
kind: string;
|
|
44
44
|
/**
|
|
45
|
-
* The Draco
|
|
45
|
+
* The Draco name for the kind of the attribute.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
dracoName: DracoAttributeName;
|
|
48
48
|
/**
|
|
49
49
|
* The size of the attribute.
|
|
50
50
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dracoEncoder.types.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoEncoder.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Nullable } from \"core/types\";\n\n/**\n * The available Draco attribute names.\n */\nexport type DracoAttributeName = \"POSITION\" | \"NORMAL\" | \"COLOR\" | \"TEX_COORD\" | \"GENERIC\";\n\n/**\n * Draco encoding method (from EncoderMethod enum in `draco_encoder.ts`).\n */\nexport type DracoEncoderMethod = \"MESH_SEQUENTIAL_ENCODING\" | \"MESH_EDGEBREAKER_ENCODING\";\n\n/**\n * Options for a particular encoding.\n */\nexport interface IDracoEncoderOptions {\n /**\n * Tune how fast decoding should be (0 = fastest but least compressed, 10 = slowest but most compressed).\n */\n decodeSpeed?: number;\n /**\n * Tune how fast encoding should be (0 = fastest but least compressed, 10 = slowest but most compressed).\n */\n encodeSpeed?: number;\n /**\n * The method to use for encoding the data (EDGEBREAKER or SEQUENTIAL). Defaults to EDGEBREAKER, if possible.\n */\n method?: DracoEncoderMethod;\n /**\n * The number of bits to use for each DRACO attribute kind.\n */\n quantizationBits?: Record<DracoAttributeName, number>;\n /**\n * The list of BABYLON attribute kinds to skip exporting, if present. Defaults to none.\n */\n excludedAttributes?: string[];\n}\n\n/**\n * Encoder parameter carrying Babylon attribute data.\n * @internal\n */\nexport interface IDracoAttributeData {\n /**\n * The
|
|
1
|
+
{"version":3,"file":"dracoEncoder.types.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoEncoder.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Nullable } from \"core/types\";\n\n/**\n * The available Draco attribute names.\n */\nexport type DracoAttributeName = \"POSITION\" | \"NORMAL\" | \"COLOR\" | \"TEX_COORD\" | \"GENERIC\";\n\n/**\n * Draco encoding method (from EncoderMethod enum in `draco_encoder.ts`).\n */\nexport type DracoEncoderMethod = \"MESH_SEQUENTIAL_ENCODING\" | \"MESH_EDGEBREAKER_ENCODING\";\n\n/**\n * Options for a particular encoding.\n */\nexport interface IDracoEncoderOptions {\n /**\n * Tune how fast decoding should be (0 = fastest but least compressed, 10 = slowest but most compressed).\n */\n decodeSpeed?: number;\n /**\n * Tune how fast encoding should be (0 = fastest but least compressed, 10 = slowest but most compressed).\n */\n encodeSpeed?: number;\n /**\n * The method to use for encoding the data (EDGEBREAKER or SEQUENTIAL). Defaults to EDGEBREAKER, if possible.\n */\n method?: DracoEncoderMethod;\n /**\n * The number of bits to use for each DRACO attribute kind.\n */\n quantizationBits?: Record<DracoAttributeName, number>;\n /**\n * The list of BABYLON attribute kinds to skip exporting, if present. Defaults to none.\n */\n excludedAttributes?: string[];\n}\n\n/**\n * Encoder parameter carrying Babylon attribute data.\n * @internal\n */\nexport interface IDracoAttributeData {\n /**\n * The kind of the attribute.\n */\n kind: string;\n /**\n * The Draco name for the kind of the attribute.\n */\n dracoName: DracoAttributeName;\n /**\n * The size of the attribute.\n */\n size: number;\n /**\n * The buffer view of the attribute.\n */\n data: Float32Array;\n}\n\n/**\n * Encoded Draco mesh data.\n * @internal\n */\nexport interface IDracoEncodedMeshData {\n /**\n * The encoded data.\n */\n data: Int8Array;\n /**\n * A map of Babylon vertex attributes to their Draco unique ids in the encoded data.\n */\n attributeIDs: Record<string, number>;\n}\n\n/**\n * @internal\n */\ninterface EncodeDoneMessage {\n id: \"encodeMeshDone\";\n encodedMeshData: Nullable<IDracoEncodedMeshData>;\n}\n\n/**\n * @internal\n */\nexport type EncoderMessage = EncodeDoneMessage;\n"]}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Tools } from "../../Misc/tools.js";
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3
|
+
let NumberOfWorkers = 0;
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
|
+
let WorkerTimeout = null;
|
|
2
6
|
/**
|
|
3
7
|
* Meshopt compression (https://github.com/zeux/meshoptimizer)
|
|
4
8
|
*
|
|
@@ -59,9 +63,20 @@ export class MeshoptCompression {
|
|
|
59
63
|
*/
|
|
60
64
|
decodeGltfBufferAsync(source, count, stride, mode, filter) {
|
|
61
65
|
return this._decoderModulePromise.then(async () => {
|
|
62
|
-
|
|
66
|
+
if (NumberOfWorkers === 0) {
|
|
67
|
+
MeshoptDecoder.useWorkers(1);
|
|
68
|
+
NumberOfWorkers = 1;
|
|
69
|
+
}
|
|
63
70
|
const result = await MeshoptDecoder.decodeGltfBufferAsync(count, stride, source, mode, filter);
|
|
64
|
-
|
|
71
|
+
// a simple debounce to avoid switching back and forth between workers and no workers while decoding
|
|
72
|
+
if (WorkerTimeout !== null) {
|
|
73
|
+
clearTimeout(WorkerTimeout);
|
|
74
|
+
}
|
|
75
|
+
WorkerTimeout = setTimeout(() => {
|
|
76
|
+
MeshoptDecoder.useWorkers(0);
|
|
77
|
+
NumberOfWorkers = 0;
|
|
78
|
+
WorkerTimeout = null;
|
|
79
|
+
}, 1000);
|
|
65
80
|
return result;
|
|
66
81
|
});
|
|
67
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meshoptCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/meshoptCompression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"meshoptCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/meshoptCompression.ts"],"names":[],"mappings":"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AAI,aAAa,KAAK,IAAI,EAAE,CAAC;gBACzB,YAAY,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;YACD,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBAC7B,eAAe,GAAG,CAAC,CAAC;gBACpB,aAAa,GAAG,IAAI,CAAC;YACzB,CAAC,EAAE,IAAI,CAAC,CAAC;YACT,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;;AA1ED;;;;;;;GAOG;AACW,gCAAa,GAAqC;IAC5D,OAAO,EAAE;QACL,GAAG,EAAE,GAAG,KAAK,CAAC,cAAc,qBAAqB;KACpD;CACJ,CAAC;AAEa,2BAAQ,GAAiC,IAAI,CAAC","sourcesContent":["import { Tools } from \"../../Misc/tools\";\r\nimport type { IDisposable } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let MeshoptDecoder: any;\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet NumberOfWorkers = 0;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet WorkerTimeout: Nullable<ReturnType<typeof setTimeout>> = null;\r\n\r\n/**\r\n * Configuration for meshoptimizer compression\r\n */\r\nexport interface IMeshoptCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the meshopt decoder library.\r\n */\r\n url: string;\r\n };\r\n}\r\n\r\n/**\r\n * Meshopt compression (https://github.com/zeux/meshoptimizer)\r\n *\r\n * This class wraps the meshopt library from https://github.com/zeux/meshoptimizer/tree/master/js.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the meshopt files on the Babylon.js preview CDN (e.g. https://preview.babylonjs.com/meshopt_decoder.js).\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * MeshoptCompression.Configuration = {\r\n * decoder: {\r\n * url: \"<url to the meshopt decoder library>\"\r\n * }\r\n * };\r\n * ```\r\n */\r\nexport class MeshoptCompression implements IDisposable {\r\n private _decoderModulePromise?: Promise<any>;\r\n\r\n /**\r\n * The configuration. Defaults to the following:\r\n * ```javascript\r\n * decoder: {\r\n * url: \"https://cdn.babylonjs.com/meshopt_decoder.js\"\r\n * }\r\n * ```\r\n */\r\n public static Configuration: IMeshoptCompressionConfiguration = {\r\n decoder: {\r\n url: `${Tools._DefaultCdnUrl}/meshopt_decoder.js`,\r\n },\r\n };\r\n\r\n private static _Default: Nullable<MeshoptCompression> = null;\r\n\r\n /**\r\n * Default instance for the meshoptimizer object.\r\n */\r\n public static get Default(): MeshoptCompression {\r\n if (!MeshoptCompression._Default) {\r\n MeshoptCompression._Default = new MeshoptCompression();\r\n }\r\n\r\n return MeshoptCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n */\r\n constructor() {\r\n const decoder = MeshoptCompression.Configuration.decoder;\r\n\r\n this._decoderModulePromise = Tools.LoadBabylonScriptAsync(decoder.url).then(() => {\r\n // Wait for WebAssembly compilation before resolving promise\r\n return MeshoptDecoder.ready;\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 delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Decode meshopt data.\r\n * @see https://github.com/zeux/meshoptimizer/tree/master/js#decoder\r\n * @param source The input data.\r\n * @param count The number of elements.\r\n * @param stride The stride in bytes.\r\n * @param mode The compression mode.\r\n * @param filter The compression filter.\r\n * @returns a Promise<Uint8Array> that resolves to the decoded data\r\n */\r\n public decodeGltfBufferAsync(source: Uint8Array, count: number, stride: number, mode: \"ATTRIBUTES\" | \"TRIANGLES\" | \"INDICES\", filter?: string): Promise<Uint8Array> {\r\n return this._decoderModulePromise!.then(async () => {\r\n if (NumberOfWorkers === 0) {\r\n MeshoptDecoder.useWorkers(1);\r\n NumberOfWorkers = 1;\r\n }\r\n const result = await MeshoptDecoder.decodeGltfBufferAsync(count, stride, source, mode, filter);\r\n // a simple debounce to avoid switching back and forth between workers and no workers while decoding\r\n if (WorkerTimeout !== null) {\r\n clearTimeout(WorkerTimeout);\r\n }\r\n WorkerTimeout = setTimeout(() => {\r\n MeshoptDecoder.useWorkers(0);\r\n NumberOfWorkers = 0;\r\n WorkerTimeout = null;\r\n }, 1000);\r\n return result;\r\n });\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DracoDecoder } from "../../dracoDecoder.js";
|
|
2
|
+
import { DracoCompression } from "../../dracoCompression.js";
|
|
3
|
+
describe("Draco Mesh Compression tests", () => {
|
|
4
|
+
describe("DracoDecoder's configuration is affected by updates to DracoCompression's", () => {
|
|
5
|
+
const originalConfig = { ...DracoDecoder.DefaultConfiguration };
|
|
6
|
+
const testUrl = "testUrl";
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
expect(DracoDecoder.DefaultConfiguration.fallbackUrl).toBe(testUrl);
|
|
9
|
+
expect(DracoDecoder.DefaultConfiguration.fallbackUrl).toBe(DracoCompression.Configuration.decoder.fallbackUrl);
|
|
10
|
+
expect(DracoDecoder.DefaultConfiguration).toBe(DracoCompression.Configuration.decoder);
|
|
11
|
+
DracoDecoder.DefaultConfiguration = originalConfig;
|
|
12
|
+
});
|
|
13
|
+
it("updates via DracoCompression.Configuration.decoder.fallbackUrl", () => {
|
|
14
|
+
DracoCompression.Configuration.decoder.fallbackUrl = testUrl;
|
|
15
|
+
});
|
|
16
|
+
it("updates via DracoCompression.Configuration.decoder", () => {
|
|
17
|
+
DracoCompression.Configuration.decoder = {
|
|
18
|
+
fallbackUrl: testUrl,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
it("updates via DracoCompression.Configuration", () => {
|
|
22
|
+
DracoCompression.Configuration = {
|
|
23
|
+
decoder: {
|
|
24
|
+
fallbackUrl: testUrl,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=draco.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draco.test.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Meshes/Compression/test/integration/draco.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC1C,QAAQ,CAAC,2EAA2E,EAAE,GAAG,EAAE;QACvF,MAAM,cAAc,GAA6B,EAAE,GAAG,YAAY,CAAC,oBAAoB,EAAE,CAAC;QAC1F,MAAM,OAAO,GAAG,SAAS,CAAC;QAE1B,SAAS,CAAC,GAAG,EAAE;YACX,MAAM,CAAC,YAAY,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpE,MAAM,CAAC,YAAY,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC/G,MAAM,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACvF,YAAY,CAAC,oBAAoB,GAAG,cAAc,CAAC;QACvD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;YACtE,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC;QACjE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;YAC1D,gBAAgB,CAAC,aAAa,CAAC,OAAO,GAAG;gBACrC,WAAW,EAAE,OAAO;aACvB,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YAClD,gBAAgB,CAAC,aAAa,GAAG;gBAC7B,OAAO,EAAE;oBACL,WAAW,EAAE,OAAO;iBACvB;aACJ,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { DracoDecoder } from \"../../dracoDecoder\";\nimport type { IDracoCodecConfiguration } from \"../../dracoCodec\";\nimport { DracoCompression } from \"../../dracoCompression\";\n\ndescribe(\"Draco Mesh Compression tests\", () => {\n describe(\"DracoDecoder's configuration is affected by updates to DracoCompression's\", () => {\n const originalConfig: IDracoCodecConfiguration = { ...DracoDecoder.DefaultConfiguration };\n const testUrl = \"testUrl\";\n\n afterEach(() => {\n expect(DracoDecoder.DefaultConfiguration.fallbackUrl).toBe(testUrl);\n expect(DracoDecoder.DefaultConfiguration.fallbackUrl).toBe(DracoCompression.Configuration.decoder.fallbackUrl);\n expect(DracoDecoder.DefaultConfiguration).toBe(DracoCompression.Configuration.decoder);\n DracoDecoder.DefaultConfiguration = originalConfig;\n });\n\n it(\"updates via DracoCompression.Configuration.decoder.fallbackUrl\", () => {\n DracoCompression.Configuration.decoder.fallbackUrl = testUrl;\n });\n\n it(\"updates via DracoCompression.Configuration.decoder\", () => {\n DracoCompression.Configuration.decoder = {\n fallbackUrl: testUrl,\n };\n });\n\n it(\"updates via DracoCompression.Configuration\", () => {\n DracoCompression.Configuration = {\n decoder: {\n fallbackUrl: testUrl,\n },\n };\n });\n });\n});\n"]}
|
package/Meshes/csg.js
CHANGED
|
@@ -470,6 +470,10 @@ export class CSG {
|
|
|
470
470
|
throw "BABYLON.CSG: Mesh has no normals";
|
|
471
471
|
}
|
|
472
472
|
const subMeshes = mesh.subMeshes;
|
|
473
|
+
if (!subMeshes) {
|
|
474
|
+
// eslint-disable-next-line no-throw-literal
|
|
475
|
+
throw "BABYLON.CSG: Mesh has no submeshes";
|
|
476
|
+
}
|
|
473
477
|
for (let sm = 0, sml = subMeshes.length; sm < sml; sm++) {
|
|
474
478
|
for (let i = subMeshes[sm].indexStart, il = subMeshes[sm].indexCount + subMeshes[sm].indexStart; i < il; i += 3) {
|
|
475
479
|
vertices = [];
|