1 line
21 KiB
Plaintext
1 line
21 KiB
Plaintext
|
{"version":3,"file":"decodeDraco.js","sources":["../../../../Source/WorkersES6/decodeDraco.js"],"sourcesContent":["/* global require */\nimport ComponentDatatype from \"../Core/ComponentDatatype.js\";\nimport defined from \"../Core/defined.js\";\nimport IndexDatatype from \"../Core/IndexDatatype.js\";\nimport RuntimeError from \"../Core/RuntimeError.js\";\nimport createTaskProcessorWorker from \"./createTaskProcessorWorker.js\";\n\nlet draco;\n\nfunction decodeIndexArray(dracoGeometry, dracoDecoder) {\n const numPoints = dracoGeometry.num_points();\n const numFaces = dracoGeometry.num_faces();\n const faceIndices = new draco.DracoInt32Array();\n const numIndices = numFaces * 3;\n const indexArray = IndexDatatype.createTypedArray(numPoints, numIndices);\n\n let offset = 0;\n for (let i = 0; i < numFaces; ++i) {\n dracoDecoder.GetFaceFromMesh(dracoGeometry, i, faceIndices);\n\n indexArray[offset + 0] = faceIndices.GetValue(0);\n indexArray[offset + 1] = faceIndices.GetValue(1);\n indexArray[offset + 2] = faceIndices.GetValue(2);\n offset += 3;\n }\n\n draco.destroy(faceIndices);\n\n return {\n typedArray: indexArray,\n numberOfIndices: numIndices,\n };\n}\n\nfunction decodeQuantizedDracoTypedArray(\n dracoGeometry,\n dracoDecoder,\n dracoAttribute,\n quantization,\n vertexArrayLength\n) {\n let vertexArray;\n let attributeData;\n if (quantization.quantizationBits <= 8) {\n attributeData = new draco.DracoUInt8Array();\n vertexArray = new Uint8Array(vertexArrayLength);\n dracoDecoder.GetAttributeUInt8ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attributeData\n );\n } else {\n attributeData = new draco.DracoUInt16Array();\n vertexArray = new Uint16Array(vertexArrayLength);\n dracoDecoder.GetAttributeUInt16ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attributeData\n );\n }\n\n for (let i = 0; i < vertexArrayLength; ++i) {\n vertexArray[i] = attributeData.GetValue(i);\n }\n\n draco.destroy(attributeData);\n return vertexArray;\n}\n\nfunction decodeDracoTypedArray(\n dracoGeometry,\n dracoDecoder,\n dracoAttribute,\n vertexArrayLength\n) {\n let vertexArray;\n let attributeData;\n\n // Some attribute types are casted down to 32 bit since Draco only returns 32 bit values\n switch (dracoAttribute.data_type()) {\n case 1:\n case 11: // DT_INT8 or DT_BOOL\n attributeData = new draco.DracoInt8Array();\n vertexArray = new Int8Array(vertexArrayLength);\n dracoDecoder.GetAttributeInt8ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attributeData\n );\n break;\n case 2: // DT_UINT8\n attributeData = new draco.DracoUInt8Array();\n vertexArray = new Uint8Array(vertexArrayLength);\n dracoDecoder.GetAttributeUInt8ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attributeData\n );\n break;\n case 3: // DT_INT16\n attributeData = new draco.DracoInt16Array();\n vertexArray = new Int16Array(vertexArrayLength);\n dracoDecoder.GetAttributeInt16ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attributeData\n );\n break;\n case 4: // DT_UINT16\n attributeData = new draco.DracoUInt16Array();\n vertexArray = new Uint16Array(vertexArrayLength);\n dracoDecoder.GetAttributeUInt16ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attributeData\n );\n break;\n case 5:\n case 7: // DT_INT32 or DT_INT64\n attributeData = new draco.DracoInt32Array();\n vertexArray = new Int32Array(vertexArrayLength);\n dracoDecoder.GetAttributeInt32ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attributeData\n );\n break;\n case 6:\n case 8: // DT_UINT32 or DT_UINT64\n attributeData = new draco.DracoUInt32Array();\n vertexArray = new Uint32Array(vertexArrayLength);\n dracoDecoder.GetAttributeUInt32ForAllPoints(\n dracoGeometry,\n dracoAttribute,\n attribute
|