@babylonjs/core 7.48.0 → 7.48.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Buffers/bufferUtils.d.ts +6 -0
- package/Buffers/bufferUtils.js.map +1 -1
- package/Cameras/camera.d.ts +1 -1
- package/Cameras/camera.js +1 -1
- package/Cameras/camera.js.map +1 -1
- package/DeviceInput/webDeviceInputSystem.d.ts +2 -0
- package/DeviceInput/webDeviceInputSystem.js +29 -13
- package/DeviceInput/webDeviceInputSystem.js.map +1 -1
- package/Engines/Extensions/engine.rawTexture.js +4 -0
- package/Engines/Extensions/engine.rawTexture.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/nativeEngine.js +2 -2
- package/Engines/nativeEngine.js.map +1 -1
- package/Loading/sceneLoader.d.ts +61 -5
- package/Loading/sceneLoader.js +156 -63
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Textures/Filtering/hdrFiltering.d.ts +1 -3
- package/Materials/Textures/Filtering/hdrFiltering.js +8 -18
- package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +1 -3
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +11 -27
- package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -1
- package/Materials/effect.d.ts +5 -0
- package/Materials/effect.js +9 -0
- package/Materials/effect.js.map +1 -1
- package/Meshes/Compression/dracoCompressionWorker.js +14 -1
- package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.js +8 -11
- package/Meshes/Compression/dracoEncoder.js.map +1 -1
- package/Meshes/Compression/dracoEncoder.types.d.ts +2 -1
- package/Meshes/Compression/dracoEncoder.types.js.map +1 -1
- package/Misc/dumpTools.js +5 -0
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/environmentTextureTools.d.ts +77 -13
- package/Misc/environmentTextureTools.js +205 -68
- package/Misc/environmentTextureTools.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAoBA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,MAAe,CAAC,oBAAoB,EACpC,UAAsC,EACtC,OAA4C,EAC5C,OAA6B;IAE7B,MAAM,aAAa,GAAG,MAAuB,CAAC;IAC9C,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,WAAW,GAA0B,IAAI,CAAC;IAC9C,IAAI,IAAI,GAAmB,IAAI,CAAC;IAChC,IAAI,mBAAmB,GAA6B,IAAI,CAAC;IACzD,MAAM,YAAY,GAA2B,EAAE,CAAC,CAAC,kCAAkC;IAEnF,8DAA8D;IAC9D,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC;IAC7E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACzE,CAAC;IAED,8GAA8G;IAC9G,8GAA8G;IAC9G,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,sDAAsD;QACtD,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC;QACrF,OAAO,GAAG,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC;QACjG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,qBAAqB,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;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UAAU,EAAE,CAAC;gBAC/B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,CAAC,MAAM,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, TypedArray } 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\nimport type { TypedArrayConstructor } from \"core/Buffers\";\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: Record<number, { typedArrayConstructor: TypedArrayConstructor; heap: TypedArray }> = {\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 const data = new info.typedArrayConstructor(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"],"names":[],"mappings":"AAoBA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,MAAe,CAAC,oBAAoB,EACpC,UAAsC,EACtC,OAA4C,EAC5C,OAA6B;IAE7B,MAAM,aAAa,GAAG,MAAuB,CAAC;IAC9C,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,WAAW,GAA0B,IAAI,CAAC;IAC9C,IAAI,IAAI,GAAmB,IAAI,CAAC;IAChC,IAAI,mBAAmB,GAA6B,IAAI,CAAC;IACzD,MAAM,YAAY,GAA2B,EAAE,CAAC,CAAC,kCAAkC;IAEnF,8DAA8D;IAC9D,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC;IAC7E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACzE,CAAC;IAED,8GAA8G;IAC9G,8GAA8G;IAC9G,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,sDAAsD;QACtD,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC;QACrF,OAAO,GAAG,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC;QACjG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,qBAAqB,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,OAAO,CAAC,CAAC,CAAC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E,KAAK;aACpB,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACN,CAAC;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable, TypedArray } 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\nimport type { TypedArrayConstructor, VertexDataTypedArray } from \"core/Buffers\";\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 const addAttributeMap = new Map<\r\n Function,\r\n (builder: MeshBuilder, mesh: Mesh, attr: any, count: number, size: number, data: Exclude<VertexDataTypedArray, Uint8ClampedArray>) => number\r\n >([\r\n [Float32Array, (mb, m, a, c, s, d) => mb.AddFloatAttribute(m, a, c, s, d)],\r\n [Uint32Array, (mb, m, a, c, s, d) => mb.AddUInt32Attribute(m, a, c, s, d)],\r\n [Uint16Array, (mb, m, a, c, s, d) => mb.AddUInt16Attribute(m, a, c, s, d)],\r\n [Uint8Array, (mb, m, a, c, s, d) => mb.AddUInt8Attribute(m, a, c, s, d)],\r\n [Int32Array, (mb, m, a, c, s, d) => mb.AddInt32Attribute(m, a, c, s, d)],\r\n [Int16Array, (mb, m, a, c, s, d) => mb.AddInt16Attribute(m, a, c, s, d)],\r\n [Int8Array, (mb, m, a, c, s, d) => mb.AddInt8Attribute(m, a, c, s, d)],\r\n ]);\r\n\r\n // Add the attributes\r\n for (const attribute of attributes) {\r\n if (attribute.data instanceof Uint8ClampedArray) {\r\n attribute.data = new Uint8Array(attribute.data); // Draco does not support Uint8ClampedArray\r\n }\r\n const addAttribute = addAttributeMap.get(attribute.data.constructor)!;\r\n const verticesCount = attribute.data.length / attribute.size;\r\n attributeIDs[attribute.kind] = addAttribute(meshBuilder, 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();\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: Record<number, { typedArrayConstructor: TypedArrayConstructor; heap: TypedArray }> = {\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 const data = new info.typedArrayConstructor(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"]}
|
|
@@ -5,7 +5,7 @@ import { VertexBuffer } from "../buffer.js";
|
|
|
5
5
|
import { Mesh } from "../mesh.js";
|
|
6
6
|
import { Logger } from "../../Misc/logger.js";
|
|
7
7
|
import { deepMerge } from "../../Misc/deepMerger.js";
|
|
8
|
-
import { AreIndices32Bits } from "../../Buffers/bufferUtils.js";
|
|
8
|
+
import { AreIndices32Bits, GetTypedArrayData } from "../../Buffers/bufferUtils.js";
|
|
9
9
|
/**
|
|
10
10
|
* Map the Babylon.js attribute kind to the Draco attribute kind, defined by the `GeometryAttributeType` enum.
|
|
11
11
|
* @internal
|
|
@@ -32,7 +32,7 @@ function GetDracoAttributeName(kind) {
|
|
|
32
32
|
* @internal
|
|
33
33
|
*/
|
|
34
34
|
function PrepareIndicesForDraco(input) {
|
|
35
|
-
let indices = input.getIndices();
|
|
35
|
+
let indices = input.getIndices(undefined, true);
|
|
36
36
|
// Convert number[] and Int32Array types, if needed
|
|
37
37
|
if (indices && !(indices instanceof Uint32Array) && !(indices instanceof Uint16Array)) {
|
|
38
38
|
indices = (AreIndices32Bits(indices, indices.length) ? Uint32Array : Uint16Array).from(indices);
|
|
@@ -54,12 +54,11 @@ function PrepareAttributesForDraco(input, excludedAttributes) {
|
|
|
54
54
|
}
|
|
55
55
|
continue;
|
|
56
56
|
}
|
|
57
|
-
// Convert number[] to typed array, if needed
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: input.getVertexBuffer(kind).getSize(), data: data });
|
|
57
|
+
// Convert number[] to typed array, if needed.
|
|
58
|
+
const vertexBuffer = input.getVertexBuffer(kind);
|
|
59
|
+
const size = vertexBuffer.getSize();
|
|
60
|
+
const data = GetTypedArrayData(vertexBuffer.getData(), size, vertexBuffer.type, vertexBuffer.byteOffset, vertexBuffer.byteStride, vertexBuffer.normalized, input.getTotalVertices(), true);
|
|
61
|
+
attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: size, data: data });
|
|
63
62
|
}
|
|
64
63
|
return attributes;
|
|
65
64
|
}
|
|
@@ -188,14 +187,12 @@ export class DracoEncoder extends DracoCodec {
|
|
|
188
187
|
};
|
|
189
188
|
worker.addEventListener("error", onError);
|
|
190
189
|
worker.addEventListener("message", onMessage);
|
|
191
|
-
//
|
|
190
|
+
// Build the transfer list. No need to copy, as the data was copied in previous steps.
|
|
192
191
|
const transferList = [];
|
|
193
192
|
attributes.forEach((attribute) => {
|
|
194
|
-
attribute.data = attribute.data.slice();
|
|
195
193
|
transferList.push(attribute.data.buffer);
|
|
196
194
|
});
|
|
197
195
|
if (indices) {
|
|
198
|
-
indices = indices.slice();
|
|
199
196
|
transferList.push(indices.buffer);
|
|
200
197
|
}
|
|
201
198
|
worker.postMessage({ id: "encodeMesh", attributes: attributes, indices: indices, options: mergedOptions }, transferList);
|
|
@@ -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,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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"]}
|
|
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,iBAAiB,EAAE,qCAAiC;AAQ/E;;;GAGG;AACH,SAAS,qBAAqB,C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Configuration } 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, GetTypedArrayData } from \"core/Buffers/bufferUtils\";\r\n\r\n// Missing type from types/draco3d. Do not use in public scope; UMD tests will fail because of EncoderModule.\r\ntype DracoEncoderModule = (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\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(undefined, true);\r\n\r\n // Convert number[] and Int32Array types, if needed\r\n if (indices && !(indices instanceof Uint32Array) && !(indices instanceof Uint16Array)) {\r\n indices = (AreIndices32Bits(indices, indices.length) ? Uint32Array : Uint16Array).from(indices);\r\n }\r\n\r\n return indices;\r\n}\r\n\r\n/**\r\n * Get relevant information about the geometry's vertex attributes for Draco encoding. Eventually used for each attribute as\r\n * `AddFloatAttribute(mesh: Mesh, attribute: number, count: number, itemSize: number, array: TypedArray)`\r\n * where `attribute = EncoderModule[<dracoAttribute>]`, `itemSize = <size>`, `array = <data>`, and count is the number of position vertices.\r\n * @internal\r\n */\r\nfunction PrepareAttributesForDraco(input: Mesh | Geometry, excludedAttributes?: string[]): Array<IDracoAttributeData> {\r\n const attributes: Array<IDracoAttributeData> = [];\r\n\r\n for (const kind of input.getVerticesDataKinds()) {\r\n if (excludedAttributes?.includes(kind)) {\r\n if (kind === VertexBuffer.PositionKind) {\r\n throw new Error(\"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 const vertexBuffer = input.getVertexBuffer(kind)!;\r\n const size = vertexBuffer.getSize();\r\n const data = GetTypedArrayData(\r\n vertexBuffer.getData()!,\r\n size,\r\n vertexBuffer.type,\r\n vertexBuffer.byteOffset,\r\n vertexBuffer.byteStride,\r\n vertexBuffer.normalized,\r\n input.getTotalVertices(),\r\n true\r\n );\r\n attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: size, data: data });\r\n }\r\n\r\n return attributes;\r\n}\r\n\r\nconst DefaultEncoderOptions: IDracoEncoderOptions = {\r\n decodeSpeed: 5,\r\n encodeSpeed: 5,\r\n method: \"MESH_EDGEBREAKER_ENCODING\",\r\n quantizationBits: {\r\n POSITION: 14,\r\n NORMAL: 10,\r\n COLOR: 8,\r\n TEX_COORD: 12,\r\n GENERIC: 12,\r\n },\r\n};\r\n\r\n/**\r\n * @experimental This class is subject to change.\r\n *\r\n * Draco Encoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco encoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco encoder files from the Babylon.js cdn https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoEncoder.DefaultConfiguration = {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The encoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.\r\n *\r\n * To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * ```\r\n *\r\n * Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.\r\n *\r\n * Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,\r\n * when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.\r\n * You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);\r\n * ```\r\n *\r\n * By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:\r\n * ```javascript\r\n * var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };\r\n * var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);\r\n * ```\r\n */\r\nexport class DracoEncoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoEncoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_encoder.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_encoder.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_encoder_wasm_wrapper.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_encoder.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_encoder.js`,\r\n };\r\n\r\n /**\r\n * 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 // Build the transfer list. No need to copy, as the data was copied in previous steps.\r\n const transferList = [];\r\n attributes.forEach((attribute) => {\r\n transferList.push(attribute.data.buffer);\r\n });\r\n if (indices) {\r\n transferList.push(indices.buffer);\r\n }\r\n\r\n worker.postMessage({ id: \"encodeMesh\", attributes: attributes, indices: indices, options: mergedOptions }, transferList);\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n const encoder = await this._modulePromise;\r\n return EncodeMesh(encoder.module, attributes, indices, mergedOptions);\r\n }\r\n\r\n throw new Error(\"Draco encoder module is not available\");\r\n }\r\n\r\n /**\r\n * Encodes a mesh or geometry into a Draco-encoded mesh data.\r\n * @param input the mesh or geometry to encode\r\n * @param options options for the encoding\r\n * @returns a promise that resolves to the newly-encoded data\r\n */\r\n public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<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"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VertexDataTypedArray } from "../../Buffers/bufferUtils.js";
|
|
1
2
|
import type { Nullable } from "../../types.js";
|
|
2
3
|
/**
|
|
3
4
|
* The available Draco attribute names.
|
|
@@ -52,7 +53,7 @@ export interface IDracoAttributeData {
|
|
|
52
53
|
/**
|
|
53
54
|
* The buffer view of the attribute.
|
|
54
55
|
*/
|
|
55
|
-
data:
|
|
56
|
+
data: VertexDataTypedArray;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* Encoded Draco mesh data.
|
|
@@ -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 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:
|
|
1
|
+
{"version":3,"file":"dracoEncoder.types.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoEncoder.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { VertexDataTypedArray } from \"core/Buffers/bufferUtils\";\nimport 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: VertexDataTypedArray;\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"]}
|
package/Misc/dumpTools.js
CHANGED
|
@@ -21,11 +21,16 @@ async function _CreateDumpRenderer() {
|
|
|
21
21
|
};
|
|
22
22
|
import("../Engines/thinEngine.js")
|
|
23
23
|
.then(({ ThinEngine: thinEngineClass }) => {
|
|
24
|
+
const engineInstanceCount = EngineStore.Instances.length;
|
|
24
25
|
try {
|
|
25
26
|
canvas = new OffscreenCanvas(100, 100); // will be resized later
|
|
26
27
|
engine = new thinEngineClass(canvas, false, options);
|
|
27
28
|
}
|
|
28
29
|
catch (e) {
|
|
30
|
+
if (engineInstanceCount < EngineStore.Instances.length) {
|
|
31
|
+
// The engine was created by another instance, let's use it
|
|
32
|
+
EngineStore.Instances.pop()?.dispose();
|
|
33
|
+
}
|
|
29
34
|
// The browser either does not support OffscreenCanvas or WebGL context in OffscreenCanvas, fallback on a regular canvas
|
|
30
35
|
canvas = document.createElement("canvas");
|
|
31
36
|
engine = new thinEngineClass(canvas, false, options);
|
package/Misc/dumpTools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dumpTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/dumpTools.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AASrD,IAAI,gBAA2C,CAAC;AAEhD,IAAI,cAAc,GAAoC,IAAI,CAAC;AAE3D,KAAK,UAAU,mBAAmB;IAC9B,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,cAAc,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC7C,IAAI,MAA2C,CAAC;YAChD,IAAI,MAAM,GAAyB,IAAI,CAAC;YACxC,MAAM,OAAO,GAAG;gBACZ,qBAAqB,EAAE,IAAI;gBAC3B,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,IAAI;gBACX,kBAAkB,EAAE,KAAK;gBACzB,SAAS,EAAE,KAAK;gBAChB,4BAA4B,EAAE,KAAK;aACtC,CA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AE,CAAC;YAClC,eAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACnC,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACrC,CAAC,CAAC,CAAC;IACP,CAAC;IACD,cAAc,GAAG,IAAI,CAAC;IACtB,gBAAgB,GAAG,IAAI,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,gEAAgE;IAChE,QAAQ;IACR,gEAAgE;IAChE,aAAa;IACb,gEAAgE;IAChE,eAAe;IACf,gEAAgE;IAChE,OAAO;CACV,CAAC;AAEF;;;;;GAKG;AACH,MAAM,eAAe,GAAG,GAAG,EAAE;IACzB,+BAA+B;IAC/B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,KAAK,CAAC,eAAe,GAAG,eAAe,CAAC;AAC5C,CAAC,CAAC;AAEF,eAAe,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { _WarnImport } from \"./devTools\";\r\n\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectRenderer, EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Clamp } from \"../Maths/math.scalar.functions\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\ntype DumpToolsEngine = {\r\n canvas: HTMLCanvasElement | OffscreenCanvas;\r\n engine: ThinEngine;\r\n renderer: EffectRenderer;\r\n wrapper: EffectWrapper;\r\n};\r\n\r\nlet _dumpToolsEngine: Nullable<DumpToolsEngine>;\r\n\r\nlet _enginePromise: Promise<DumpToolsEngine> | null = null;\r\n\r\nasync function _CreateDumpRenderer(): Promise<DumpToolsEngine> {\r\n if (!_enginePromise) {\r\n _enginePromise = new Promise((resolve, reject) => {\r\n let canvas: HTMLCanvasElement | OffscreenCanvas;\r\n let engine: Nullable<ThinEngine> = null;\r\n const options = {\r\n preserveDrawingBuffer: true,\r\n depth: false,\r\n stencil: false,\r\n alpha: true,\r\n premultipliedAlpha: false,\r\n antialias: false,\r\n failIfMajorPerformanceCaveat: false,\r\n };\r\n import(\"../Engines/thinEngine\")\r\n .then(({ ThinEngine: thinEngineClass }) => {\r\n try {\r\n canvas = new OffscreenCanvas(100, 100); // will be resized later\r\n engine = new thinEngineClass(canvas, false, options);\r\n } catch (e) {\r\n // The browser either does not support OffscreenCanvas or WebGL context in OffscreenCanvas, fallback on a regular canvas\r\n canvas = document.createElement(\"canvas\");\r\n engine = new thinEngineClass(canvas, false, options);\r\n }\r\n // remove this engine from the list of instances to avoid using it for other purposes\r\n EngineStore.Instances.pop();\r\n // However, make sure to dispose it when no other engines are left\r\n EngineStore.OnEnginesDisposedObservable.add((e) => {\r\n // guaranteed to run when no other instances are left\r\n // only dispose if it's not the current engine\r\n if (engine && e !== engine && !engine.isDisposed && EngineStore.Instances.length === 0) {\r\n // Dump the engine and the associated resources\r\n Dispose();\r\n }\r\n });\r\n engine.getCaps().parallelShaderCompile = undefined;\r\n const renderer = new EffectRenderer(engine);\r\n import(\"../Shaders/pass.fragment\").then(({ passPixelShader }) => {\r\n if (!engine) {\r\n reject(\"Engine is not defined\");\r\n return;\r\n }\r\n const wrapper = new EffectWrapper({\r\n engine,\r\n name: passPixelShader.name,\r\n fragmentShader: passPixelShader.shader,\r\n samplerNames: [\"textureSampler\"],\r\n });\r\n _dumpToolsEngine = {\r\n canvas,\r\n engine,\r\n renderer,\r\n wrapper,\r\n };\r\n resolve(_dumpToolsEngine);\r\n });\r\n })\r\n .catch(reject);\r\n });\r\n }\r\n return await _enginePromise;\r\n}\r\n\r\n/**\r\n * Dumps the current bound framebuffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param engine defines the hosting engine\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a void promise\r\n */\r\nexport async function DumpFramebuffer(\r\n width: number,\r\n height: number,\r\n engine: AbstractEngine,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n quality?: number\r\n) {\r\n // Read the contents of the framebuffer\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n\r\n const data = new Uint8Array(bufferView.buffer);\r\n\r\n DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n}\r\n\r\n/**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a promise that resolve to the final data\r\n */\r\nexport function DumpDataAsync(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n): Promise<string | ArrayBuffer> {\r\n return new Promise((resolve) => {\r\n DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);\r\n });\r\n}\r\n\r\n/**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\nexport function DumpData(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n successCallback?: (data: string | ArrayBuffer) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n): void {\r\n _CreateDumpRenderer().then((renderer) => {\r\n renderer.engine.setSize(width, height, true);\r\n\r\n // Convert if data are float32\r\n if (data instanceof Float32Array) {\r\n const data2 = new Uint8Array(data.length);\r\n let n = data.length;\r\n while (n--) {\r\n const v = data[n];\r\n data2[n] = Math.round(Clamp(v) * 255);\r\n }\r\n data = data2;\r\n }\r\n\r\n // Create the image\r\n const texture = renderer.engine.createRawTexture(data, width, height, Constants.TEXTUREFORMAT_RGBA, false, !invertY, Constants.TEXTURE_NEAREST_NEAREST);\r\n\r\n renderer.renderer.setViewport();\r\n renderer.renderer.applyEffectWrapper(renderer.wrapper);\r\n renderer.wrapper.effect._bindTexture(\"textureSampler\", texture);\r\n renderer.renderer.draw();\r\n\r\n if (toArrayBuffer) {\r\n Tools.ToBlob(\r\n renderer.canvas,\r\n (blob) => {\r\n const fileReader = new FileReader();\r\n fileReader.onload = (event: any) => {\r\n const arrayBuffer = event.target!.result as ArrayBuffer;\r\n if (successCallback) {\r\n successCallback(arrayBuffer);\r\n }\r\n };\r\n fileReader.readAsArrayBuffer(blob!);\r\n },\r\n mimeType,\r\n quality\r\n );\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);\r\n }\r\n\r\n texture.dispose();\r\n });\r\n}\r\n\r\n/**\r\n * Dispose the dump tools associated resources\r\n */\r\nexport function Dispose() {\r\n if (_dumpToolsEngine) {\r\n _dumpToolsEngine.wrapper.dispose();\r\n _dumpToolsEngine.renderer.dispose();\r\n _dumpToolsEngine.engine.dispose();\r\n } else {\r\n // in cases where the engine is not yet created, we need to wait for it to dispose it\r\n _enginePromise?.then((dumpToolsEngine) => {\r\n dumpToolsEngine.wrapper.dispose();\r\n dumpToolsEngine.renderer.dispose();\r\n dumpToolsEngine.engine.dispose();\r\n });\r\n }\r\n _enginePromise = null;\r\n _dumpToolsEngine = null;\r\n}\r\n\r\n/**\r\n * Object containing a set of static utilities functions to dump data from a canvas\r\n * @deprecated use functions\r\n */\r\nexport const DumpTools = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpData,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpDataAsync,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpFramebuffer,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n Dispose,\r\n};\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n // References the dependencies.\r\n Tools.DumpData = DumpData;\r\n Tools.DumpDataAsync = DumpDataAsync;\r\n Tools.DumpFramebuffer = DumpFramebuffer;\r\n};\r\n\r\ninitSideEffects();\r\n"]}
|
|
1
|
+
{"version":3,"file":"dumpTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/dumpTools.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,KAAK,EAA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AACH,MAAM,eAAe,GAAG,GAAG,EAAE;IACzB,+BAA+B;IAC/B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,KAAK,CAAC,eAAe,GAAG,eAAe,CAAC;AAC5C,CAAC,CAAC;AAEF,eAAe,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { _WarnImport } from \"./devTools\";\r\n\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectRenderer, EffectWrapper } from \"../Materials/effectRenderer\";\r\nimport { Tools } from \"./tools\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Clamp } from \"../Maths/math.scalar.functions\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\ntype DumpToolsEngine = {\r\n canvas: HTMLCanvasElement | OffscreenCanvas;\r\n engine: ThinEngine;\r\n renderer: EffectRenderer;\r\n wrapper: EffectWrapper;\r\n};\r\n\r\nlet _dumpToolsEngine: Nullable<DumpToolsEngine>;\r\n\r\nlet _enginePromise: Promise<DumpToolsEngine> | null = null;\r\n\r\nasync function _CreateDumpRenderer(): Promise<DumpToolsEngine> {\r\n if (!_enginePromise) {\r\n _enginePromise = new Promise((resolve, reject) => {\r\n let canvas: HTMLCanvasElement | OffscreenCanvas;\r\n let engine: Nullable<ThinEngine> = null;\r\n const options = {\r\n preserveDrawingBuffer: true,\r\n depth: false,\r\n stencil: false,\r\n alpha: true,\r\n premultipliedAlpha: false,\r\n antialias: false,\r\n failIfMajorPerformanceCaveat: false,\r\n };\r\n import(\"../Engines/thinEngine\")\r\n .then(({ ThinEngine: thinEngineClass }) => {\r\n const engineInstanceCount = EngineStore.Instances.length;\r\n try {\r\n canvas = new OffscreenCanvas(100, 100); // will be resized later\r\n engine = new thinEngineClass(canvas, false, options);\r\n } catch (e) {\r\n if (engineInstanceCount < EngineStore.Instances.length) {\r\n // The engine was created by another instance, let's use it\r\n EngineStore.Instances.pop()?.dispose();\r\n }\r\n // The browser either does not support OffscreenCanvas or WebGL context in OffscreenCanvas, fallback on a regular canvas\r\n canvas = document.createElement(\"canvas\");\r\n engine = new thinEngineClass(canvas, false, options);\r\n }\r\n // remove this engine from the list of instances to avoid using it for other purposes\r\n EngineStore.Instances.pop();\r\n // However, make sure to dispose it when no other engines are left\r\n EngineStore.OnEnginesDisposedObservable.add((e) => {\r\n // guaranteed to run when no other instances are left\r\n // only dispose if it's not the current engine\r\n if (engine && e !== engine && !engine.isDisposed && EngineStore.Instances.length === 0) {\r\n // Dump the engine and the associated resources\r\n Dispose();\r\n }\r\n });\r\n engine.getCaps().parallelShaderCompile = undefined;\r\n const renderer = new EffectRenderer(engine);\r\n import(\"../Shaders/pass.fragment\").then(({ passPixelShader }) => {\r\n if (!engine) {\r\n reject(\"Engine is not defined\");\r\n return;\r\n }\r\n const wrapper = new EffectWrapper({\r\n engine,\r\n name: passPixelShader.name,\r\n fragmentShader: passPixelShader.shader,\r\n samplerNames: [\"textureSampler\"],\r\n });\r\n _dumpToolsEngine = {\r\n canvas,\r\n engine,\r\n renderer,\r\n wrapper,\r\n };\r\n resolve(_dumpToolsEngine);\r\n });\r\n })\r\n .catch(reject);\r\n });\r\n }\r\n return await _enginePromise;\r\n}\r\n\r\n/**\r\n * Dumps the current bound framebuffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param engine defines the hosting engine\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a void promise\r\n */\r\nexport async function DumpFramebuffer(\r\n width: number,\r\n height: number,\r\n engine: AbstractEngine,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n quality?: number\r\n) {\r\n // Read the contents of the framebuffer\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n\r\n const data = new Uint8Array(bufferView.buffer);\r\n\r\n DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n}\r\n\r\n/**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns a promise that resolve to the final data\r\n */\r\nexport function DumpDataAsync(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n): Promise<string | ArrayBuffer> {\r\n return new Promise((resolve) => {\r\n DumpData(width, height, data, (result) => resolve(result), mimeType, fileName, invertY, toArrayBuffer, quality);\r\n });\r\n}\r\n\r\n/**\r\n * Dumps an array buffer\r\n * @param width defines the rendering width\r\n * @param height defines the rendering height\r\n * @param data the data array\r\n * @param successCallback defines the callback triggered once the data are available\r\n * @param mimeType defines the mime type of the result\r\n * @param fileName defines the filename to download. If present, the result will automatically be downloaded\r\n * @param invertY true to invert the picture in the Y dimension\r\n * @param toArrayBuffer true to convert the data to an ArrayBuffer (encoded as `mimeType`) instead of a base64 string\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\nexport function DumpData(\r\n width: number,\r\n height: number,\r\n data: ArrayBufferView,\r\n successCallback?: (data: string | ArrayBuffer) => void,\r\n mimeType = \"image/png\",\r\n fileName?: string,\r\n invertY = false,\r\n toArrayBuffer = false,\r\n quality?: number\r\n): void {\r\n _CreateDumpRenderer().then((renderer) => {\r\n renderer.engine.setSize(width, height, true);\r\n\r\n // Convert if data are float32\r\n if (data instanceof Float32Array) {\r\n const data2 = new Uint8Array(data.length);\r\n let n = data.length;\r\n while (n--) {\r\n const v = data[n];\r\n data2[n] = Math.round(Clamp(v) * 255);\r\n }\r\n data = data2;\r\n }\r\n\r\n // Create the image\r\n const texture = renderer.engine.createRawTexture(data, width, height, Constants.TEXTUREFORMAT_RGBA, false, !invertY, Constants.TEXTURE_NEAREST_NEAREST);\r\n\r\n renderer.renderer.setViewport();\r\n renderer.renderer.applyEffectWrapper(renderer.wrapper);\r\n renderer.wrapper.effect._bindTexture(\"textureSampler\", texture);\r\n renderer.renderer.draw();\r\n\r\n if (toArrayBuffer) {\r\n Tools.ToBlob(\r\n renderer.canvas,\r\n (blob) => {\r\n const fileReader = new FileReader();\r\n fileReader.onload = (event: any) => {\r\n const arrayBuffer = event.target!.result as ArrayBuffer;\r\n if (successCallback) {\r\n successCallback(arrayBuffer);\r\n }\r\n };\r\n fileReader.readAsArrayBuffer(blob!);\r\n },\r\n mimeType,\r\n quality\r\n );\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(renderer.canvas, successCallback, mimeType, fileName, quality);\r\n }\r\n\r\n texture.dispose();\r\n });\r\n}\r\n\r\n/**\r\n * Dispose the dump tools associated resources\r\n */\r\nexport function Dispose() {\r\n if (_dumpToolsEngine) {\r\n _dumpToolsEngine.wrapper.dispose();\r\n _dumpToolsEngine.renderer.dispose();\r\n _dumpToolsEngine.engine.dispose();\r\n } else {\r\n // in cases where the engine is not yet created, we need to wait for it to dispose it\r\n _enginePromise?.then((dumpToolsEngine) => {\r\n dumpToolsEngine.wrapper.dispose();\r\n dumpToolsEngine.renderer.dispose();\r\n dumpToolsEngine.engine.dispose();\r\n });\r\n }\r\n _enginePromise = null;\r\n _dumpToolsEngine = null;\r\n}\r\n\r\n/**\r\n * Object containing a set of static utilities functions to dump data from a canvas\r\n * @deprecated use functions\r\n */\r\nexport const DumpTools = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpData,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpDataAsync,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n DumpFramebuffer,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n Dispose,\r\n};\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n // References the dependencies.\r\n Tools.DumpData = DumpData;\r\n Tools.DumpDataAsync = DumpDataAsync;\r\n Tools.DumpFramebuffer = DumpFramebuffer;\r\n};\r\n\r\ninitSideEffects();\r\n"]}
|
|
@@ -22,11 +22,11 @@ interface EnvironmentTextureInfoV1 {
|
|
|
22
22
|
/**
|
|
23
23
|
* Irradiance information stored in the file.
|
|
24
24
|
*/
|
|
25
|
-
irradiance:
|
|
25
|
+
irradiance: Nullable<EnvironmentTextureIrradianceInfoV1>;
|
|
26
26
|
/**
|
|
27
27
|
* Specular information stored in the file.
|
|
28
28
|
*/
|
|
29
|
-
specular:
|
|
29
|
+
specular: EnvironmentTextureSpecularInfoV1;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* v2 of EnvironmentTextureInfo
|
|
@@ -43,15 +43,19 @@ interface EnvironmentTextureInfoV2 {
|
|
|
43
43
|
/**
|
|
44
44
|
* Irradiance information stored in the file.
|
|
45
45
|
*/
|
|
46
|
-
irradiance:
|
|
46
|
+
irradiance: Nullable<EnvironmentTextureIrradianceInfoV1>;
|
|
47
47
|
/**
|
|
48
48
|
* Specular information stored in the file.
|
|
49
49
|
*/
|
|
50
|
-
specular:
|
|
50
|
+
specular: EnvironmentTextureSpecularInfoV1;
|
|
51
51
|
/**
|
|
52
52
|
* The mime type used to encode the image data.
|
|
53
53
|
*/
|
|
54
54
|
imageType: string;
|
|
55
|
+
/**
|
|
56
|
+
* Defines where the specular Payload is located. It is a runtime value only not stored in the file.
|
|
57
|
+
*/
|
|
58
|
+
binaryDataPosition?: number;
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* Defines One Image in the file. It requires only the position in the file
|
|
@@ -68,14 +72,24 @@ interface BufferImageData {
|
|
|
68
72
|
position: number;
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
71
|
-
* Defines the
|
|
75
|
+
* Defines the diffuse data enclosed in the file.
|
|
72
76
|
* This corresponds to the version 1 of the data.
|
|
73
77
|
*/
|
|
74
|
-
export interface
|
|
78
|
+
export interface EnvironmentTextureIrradianceTextureInfoV1 {
|
|
75
79
|
/**
|
|
76
|
-
*
|
|
80
|
+
* Size of the texture faces.
|
|
77
81
|
*/
|
|
78
|
-
|
|
82
|
+
size: number;
|
|
83
|
+
/**
|
|
84
|
+
* This contains all the images data needed to reconstruct the cubemap.
|
|
85
|
+
*/
|
|
86
|
+
faces: Array<BufferImageData>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Defines the specular data enclosed in the file.
|
|
90
|
+
* This corresponds to the version 1 of the data.
|
|
91
|
+
*/
|
|
92
|
+
export interface EnvironmentTextureSpecularInfoV1 {
|
|
79
93
|
/**
|
|
80
94
|
* This contains all the images data needed to reconstruct the cubemap.
|
|
81
95
|
*/
|
|
@@ -85,6 +99,21 @@ export interface EnvironmentTextureSpecularInfoV1 {
|
|
|
85
99
|
*/
|
|
86
100
|
lodGenerationScale: number;
|
|
87
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Defines the required storage to save the environment irradiance information.
|
|
104
|
+
*/
|
|
105
|
+
interface EnvironmentTextureIrradianceInfoV1 {
|
|
106
|
+
x: Array<number>;
|
|
107
|
+
y: Array<number>;
|
|
108
|
+
z: Array<number>;
|
|
109
|
+
xx: Array<number>;
|
|
110
|
+
yy: Array<number>;
|
|
111
|
+
zz: Array<number>;
|
|
112
|
+
yz: Array<number>;
|
|
113
|
+
zx: Array<number>;
|
|
114
|
+
xy: Array<number>;
|
|
115
|
+
irradianceTexture?: EnvironmentTextureIrradianceTextureInfoV1 | undefined;
|
|
116
|
+
}
|
|
88
117
|
/**
|
|
89
118
|
* Options for creating environment textures
|
|
90
119
|
*/
|
|
@@ -97,6 +126,10 @@ export interface CreateEnvTextureOptions {
|
|
|
97
126
|
* the image quality of encoded WebP images.
|
|
98
127
|
*/
|
|
99
128
|
imageQuality?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Disables the generation of irradiance texture even if present on the source.
|
|
131
|
+
*/
|
|
132
|
+
disableIrradianceTexture?: boolean;
|
|
100
133
|
}
|
|
101
134
|
/**
|
|
102
135
|
* Gets the environment info from an env file.
|
|
@@ -126,7 +159,14 @@ export declare function CreateEnvTextureAsync(texture: BaseTexture, options?: Cr
|
|
|
126
159
|
* @param info parameters that determine what views will be created for accessing the underlying buffer
|
|
127
160
|
* @returns the views described by info providing access to the underlying buffer
|
|
128
161
|
*/
|
|
129
|
-
export declare function
|
|
162
|
+
export declare function CreateRadianceImageDataArrayBufferViews(data: ArrayBufferView, info: EnvironmentTextureInfo): Array<Array<ArrayBufferView>>;
|
|
163
|
+
/**
|
|
164
|
+
* Creates the ArrayBufferViews used for initializing environment texture image data.
|
|
165
|
+
* @param data the image data
|
|
166
|
+
* @param info parameters that determine what views will be created for accessing the underlying buffer
|
|
167
|
+
* @returns the views described by info providing access to the underlying buffer
|
|
168
|
+
*/
|
|
169
|
+
export declare function CreateIrradianceImageDataArrayBufferViews(data: ArrayBufferView, info: EnvironmentTextureInfo): Array<ArrayBufferView>;
|
|
130
170
|
/**
|
|
131
171
|
* Uploads the texture info contained in the env file to the GPU.
|
|
132
172
|
* @param texture defines the internal texture to upload to
|
|
@@ -134,7 +174,7 @@ export declare function CreateImageDataArrayBufferViews(data: ArrayBufferView, i
|
|
|
134
174
|
* @param info defines the texture info retrieved through the GetEnvInfo method
|
|
135
175
|
* @returns a promise
|
|
136
176
|
*/
|
|
137
|
-
export declare function UploadEnvLevelsAsync(texture: InternalTexture, data: ArrayBufferView, info: EnvironmentTextureInfo): Promise<void>;
|
|
177
|
+
export declare function UploadEnvLevelsAsync(texture: InternalTexture, data: ArrayBufferView, info: EnvironmentTextureInfo): Promise<void[]>;
|
|
138
178
|
/**
|
|
139
179
|
* Uploads the levels of image data to the GPU.
|
|
140
180
|
* @param texture defines the internal texture to upload to
|
|
@@ -142,7 +182,16 @@ export declare function UploadEnvLevelsAsync(texture: InternalTexture, data: Arr
|
|
|
142
182
|
* @param imageType the mime type of the image data
|
|
143
183
|
* @returns a promise
|
|
144
184
|
*/
|
|
145
|
-
export declare function
|
|
185
|
+
export declare function UploadRadianceLevelsAsync(texture: InternalTexture, imageData: ArrayBufferView[][], imageType?: string): Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Uploads the levels of image data to the GPU.
|
|
188
|
+
* @param mainTexture defines the internal texture to upload to
|
|
189
|
+
* @param imageData defines the array buffer views of image data [mipmap][face]
|
|
190
|
+
* @param size defines the size of the texture faces
|
|
191
|
+
* @param imageType the mime type of the image data
|
|
192
|
+
* @returns a promise
|
|
193
|
+
*/
|
|
194
|
+
export declare function UploadIrradianceLevelsAsync(mainTexture: InternalTexture, imageData: ArrayBufferView[], size: number, imageType?: string): Promise<void>;
|
|
146
195
|
/**
|
|
147
196
|
* Uploads spherical polynomials information to the texture.
|
|
148
197
|
* @param texture defines the texture we are trying to upload the information to
|
|
@@ -180,7 +229,14 @@ export declare const EnvironmentTextureTools: {
|
|
|
180
229
|
* @param info parameters that determine what views will be created for accessing the underlying buffer
|
|
181
230
|
* @returns the views described by info providing access to the underlying buffer
|
|
182
231
|
*/
|
|
183
|
-
|
|
232
|
+
CreateRadianceImageDataArrayBufferViews: typeof CreateRadianceImageDataArrayBufferViews;
|
|
233
|
+
/**
|
|
234
|
+
* Creates the ArrayBufferViews used for initializing environment texture image data.
|
|
235
|
+
* @param data the image data
|
|
236
|
+
* @param info parameters that determine what views will be created for accessing the underlying buffer
|
|
237
|
+
* @returns the views described by info providing access to the underlying buffer
|
|
238
|
+
*/
|
|
239
|
+
CreateIrradianceImageDataArrayBufferViews: typeof CreateIrradianceImageDataArrayBufferViews;
|
|
184
240
|
/**
|
|
185
241
|
* Uploads the texture info contained in the env file to the GPU.
|
|
186
242
|
* @param texture defines the internal texture to upload to
|
|
@@ -196,7 +252,15 @@ export declare const EnvironmentTextureTools: {
|
|
|
196
252
|
* @param imageType the mime type of the image data
|
|
197
253
|
* @returns a promise
|
|
198
254
|
*/
|
|
199
|
-
|
|
255
|
+
UploadRadianceLevelsAsync: typeof UploadRadianceLevelsAsync;
|
|
256
|
+
/**
|
|
257
|
+
* Uploads the levels of image data to the GPU.
|
|
258
|
+
* @param texture defines the internal texture to upload to
|
|
259
|
+
* @param imageData defines the array buffer views of image data [mipmap][face]
|
|
260
|
+
* @param imageType the mime type of the image data
|
|
261
|
+
* @returns a promise
|
|
262
|
+
*/
|
|
263
|
+
UploadIrradianceLevelsAsync: typeof UploadIrradianceLevelsAsync;
|
|
200
264
|
/**
|
|
201
265
|
* Uploads spherical polynomials information to the texture.
|
|
202
266
|
* @param texture defines the texture we are trying to upload the information to
|