declare const _default: "\n/**\n * Interfaces from the KHR_draco_mesh_compression extension\n */\nlet draco;\nlet dracoPromise;\nlet decoderPromises = {};\nconst self = this;\nonerror = e => {\n console.log('here worker error', e);\n};\n\nonmessage = e => {\n switch (e.data.type) {\n case 'init':\n dracoPromise = init(e.data);\n return;\n case 'buffer':\n if (!decoderPromises[e.data.bufferId]) {\n decoderPromises[e.data.bufferId] = getDraco().then(() => {\n return addBuffer(draco, e.data);\n });\n }\n return;\n case 'decoder':\n return getDecoder(e.data.bufferId).then(decoder => {\n self.postMessage({ data: decoder.getSchemaData(e.data), type: 'decoder' });\n });\n case 'destroy':\n return getDecoder(e.data.bufferId).then(decoder => {\n decoder.dracoDestroy();\n decoderPromises[e.data.bufferId] = undefined\n });\n }\n};\n\nfunction getDraco() {\n if (!dracoPromise) {\n throw Error('init first please');\n }\n return dracoPromise;\n}\n\nfunction getDecoder(bufferId) {\n const decoderPromise = decoderPromises[bufferId];\n if (!decoderPromise) {\n throw Error('update buffer before decoder please');\n }\n return decoderPromise;\n}\n\nfunction addBuffer(draco, { schema, buffer }) {\n const decoderBuffer = new draco.DecoderBuffer();\n decoderBuffer.Init(new Int8Array(buffer), buffer.byteLength);\n\n // Create a buffer to hold the encoded data.\n const decoder = new draco.Decoder();\n\n return decodeGeometry(schema, draco, decoder, decoderBuffer);\n}\n\nfunction init() {\n // Create the Draco decoder.\n return new Promise(resolve => {\n DracoDecoderModule({\n onModuleLoaded: dracoInstance => {\n // Module is Promise-like. Wrap before resolving to avoid loop.\n draco = dracoInstance;\n resolve();\n },\n });\n });\n}\n\nfunction decodeGeometry(schema, draco, decoder, decoderBuffer) {\n let dracoGeometry;\n let decodingStatus;\n const { attributes } = schema;\n const geometryType = decoder.GetEncodedGeometryType(decoderBuffer);\n if (geometryType === draco.TRIANGULAR_MESH) {\n dracoGeometry = new draco.Mesh();\n decodingStatus = decoder.DecodeBufferToMesh(decoderBuffer, dracoGeometry);\n } else {\n throw new Error('DRACODecoder worker: Unexpected geometry type.');\n }\n\n if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {\n throw new Error('DRACODecoder worker: Decoding failed: ' + decodingStatus.error_msg());\n }\n\n // draco.destroy(dracoGeometry);\n // return geometry;\n return {\n getSchemaData: params => {\n let res;\n if (params.isIndice) {\n res = decodeIndice({\n geometryType,\n draco,\n decoder,\n dracoGeometry,\n indexType: params.attributeType,\n });\n } else {\n res = getDracoAccessorData({\n ...params,\n attributeID: attributes[params.attributeName],\n decoder,\n draco,\n dracoGeometry,\n });\n }\n\n res.attributeName = params.attributeName;\n return res;\n },\n dracoDestroy: () => {\n draco.destroy(dracoGeometry);\n draco.destroy(decoderBuffer);\n draco.destroy(decoder);\n },\n };\n}\n\nconst getDracoAccessorData = ({\n draco,\n decoder,\n dracoGeometry,\n attributeName,\n attributeType,\n useUniqueIDs,\n attributeID,\n}) => {\n let attribute;\n\n // A Draco file may be created with default vertex attributes, whose attribute IDs\n // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,\n // a Draco file may contain a custom set of attributes, identified by known unique\n // IDs. glTF files always do the latter, and .drc files typically do the former.\n if (useUniqueIDs) {\n attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);\n } else {\n attributeID = decoder.GetAttributeId(dracoGeometry, draco[attributeID]);\n if (attributeID === -1) {\n return null;\n }\n attribute = decoder.GetAttribute(dracoGeometry, attributeID);\n }\n\n return decodeAttribute(draco, decoder, dracoGeometry, attributeType, attribute);\n};\n\nfunction decodeAttribute(draco, decoder, geometry, attributeType, attribute) {\n let ptr;\n let array;\n let dataSize;\n const componentsNum = attribute.num_components();\n const pointsNum = geometry.num_points();\n const valuesNum = pointsNum * componentsNum;\n\n attributeType = self[attributeType];\n\n switch (attributeType) {\n case Uint8Array:\n ptr = draco._malloc(valuesNum);\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, draco.DT_UINT8, valuesNum, ptr);\n array = new Uint8Array(draco.HEAPU8.buffer, ptr, valuesNum).slice();\n draco._free(ptr);\n break;\n\n case Int8Array:\n ptr = draco._malloc(valuesNum);\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, draco.DT_INT8, valuesNum, ptr);\n array = new Int8Array(draco.HEAP8.buffer, ptr, valuesNum).slice();\n draco._free(ptr);\n break;\n\n case Uint16Array:\n dataSize = valuesNum * 2;\n ptr = draco._malloc(dataSize);\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, draco.DT_UINT16, dataSize, ptr);\n array = new Uint16Array(draco.HEAPU16.buffer, ptr, valuesNum).slice();\n draco._free(ptr);\n break;\n\n case Int16Array:\n dataSize = valuesNum * 2;\n ptr = draco._malloc(dataSize);\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, draco.DT_INT16, dataSize, ptr);\n array = new Int16Array(draco.HEAP16.buffer, ptr, valuesNum).slice();\n draco._free(ptr);\n break;\n\n case Uint32Array:\n dataSize = valuesNum * 4;\n ptr = draco._malloc(dataSize);\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, draco.DT_UINT32, dataSize, ptr);\n array = new Uint32Array(draco.HEAPU32.buffer, ptr, valuesNum).slice();\n draco._free(ptr);\n break;\n\n case Int32Array:\n dataSize = valuesNum * 4;\n ptr = draco._malloc(dataSize);\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, draco.DT_INT32, dataSize, ptr);\n array = new Int32Array(draco.HEAP32.buffer, ptr, valuesNum).slice();\n draco._free(ptr);\n break;\n\n case Float32Array:\n dataSize = valuesNum * 4;\n ptr = draco._malloc(dataSize);\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, draco.DT_FLOAT32, dataSize, ptr);\n array = new Float32Array(draco.HEAPF32.buffer, ptr, valuesNum).slice();\n draco._free(ptr);\n break;\n\n default:\n throw new Error('DRACODecoder: Unexpected type for attribute.');\n }\n\n return { array: array, itemSize: componentsNum };\n}\n\nfunction decodeIndice({ geometryType, draco, dracoGeometry, indexType, decoder }) {\n if (geometryType === draco.TRIANGULAR_MESH) {\n // Generate mesh faces.\n const numFaces = dracoGeometry.num_faces();\n const numIndices = numFaces * 3;\n let dataSize;\n let ptr;\n let index;\n indexType = self[indexType];\n switch (indexType) {\n case Uint32Array:\n dataSize = numIndices * 4;\n ptr = draco._malloc(dataSize);\n decoder.GetTrianglesUInt32Array(dracoGeometry, dataSize, ptr);\n index = new Uint32Array(draco.HEAPU32.buffer, ptr, numIndices).slice();\n draco._free(ptr);\n break;\n case Uint16Array:\n dataSize = numIndices * 2;\n ptr = draco._malloc(dataSize);\n decoder.GetTrianglesUInt16Array(dracoGeometry, dataSize, ptr);\n index = new Uint16Array(draco.HEAPU16.buffer, ptr, numIndices).slice();\n draco._free(ptr);\n break;\n default:\n throw new Error('DRACODecoder: Unexpected index type.');\n }\n return { array: index, itemSize: 1 };\n }\n return {};\n}\n"; export default _default;