@loaders.gl/draco 3.1.0-alpha.4 → 3.1.0-alpha.5

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.
Files changed (45) hide show
  1. package/dist/bundle.d.ts +1 -0
  2. package/dist/dist.min.js +1 -1
  3. package/dist/dist.min.js.map +1 -1
  4. package/dist/draco-loader.d.ts +27 -0
  5. package/dist/draco-worker.js +1 -1
  6. package/dist/draco-worker.js.map +1 -1
  7. package/dist/draco-writer.d.ts +7 -0
  8. package/dist/draco3d/draco3d-types.d.ts +294 -0
  9. package/dist/es5/bundle.js +1 -1
  10. package/dist/es5/bundle.js.map +1 -1
  11. package/dist/es5/draco-loader.js +4 -8
  12. package/dist/es5/draco-loader.js.map +1 -1
  13. package/dist/es5/draco-writer.js +13 -46
  14. package/dist/es5/draco-writer.js.map +1 -1
  15. package/dist/es5/draco3d/draco3d-types.js +4 -4
  16. package/dist/es5/index.js +16 -51
  17. package/dist/es5/index.js.map +1 -1
  18. package/dist/es5/lib/draco-builder.js +244 -292
  19. package/dist/es5/lib/draco-builder.js.map +1 -1
  20. package/dist/es5/lib/draco-module-loader.js +65 -198
  21. package/dist/es5/lib/draco-module-loader.js.map +1 -1
  22. package/dist/es5/lib/draco-parser.js +308 -372
  23. package/dist/es5/lib/draco-parser.js.map +1 -1
  24. package/dist/es5/lib/utils/get-draco-schema.js +15 -15
  25. package/dist/es5/lib/utils/get-draco-schema.js.map +1 -1
  26. package/dist/es5/lib/utils/version.js +1 -1
  27. package/dist/es5/lib/utils/version.js.map +1 -1
  28. package/dist/esm/lib/draco-builder.js +4 -6
  29. package/dist/esm/lib/draco-builder.js.map +1 -1
  30. package/dist/esm/lib/draco-module-loader.js +4 -4
  31. package/dist/esm/lib/draco-module-loader.js.map +1 -1
  32. package/dist/esm/lib/draco-parser.js +2 -2
  33. package/dist/esm/lib/draco-parser.js.map +1 -1
  34. package/dist/esm/lib/utils/get-draco-schema.js +1 -1
  35. package/dist/esm/lib/utils/get-draco-schema.js.map +1 -1
  36. package/dist/esm/lib/utils/version.js +1 -1
  37. package/dist/index.d.ts +28 -0
  38. package/dist/lib/draco-builder.d.ts +106 -0
  39. package/dist/lib/draco-module-loader.d.ts +2 -0
  40. package/dist/lib/draco-parser.d.ts +136 -0
  41. package/dist/lib/draco-types.d.ts +58 -0
  42. package/dist/lib/utils/get-draco-schema.d.ts +7 -0
  43. package/dist/lib/utils/version.d.ts +1 -0
  44. package/dist/workers/draco-worker.d.ts +1 -0
  45. package/package.json +7 -6
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/draco-parser.ts"],"names":["getMeshBoundingBox","getDracoSchema","GEOMETRY_TYPE","TRIANGULAR_MESH","POINT_CLOUD","DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP","POSITION","NORMAL","COLOR","TEX_COORD","DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP","Int8Array","Uint8Array","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","INDEX_ITEM_SIZE","DracoParser","constructor","draco","decoder","Decoder","metadataQuerier","MetadataQuerier","destroy","parseSync","arrayBuffer","options","buffer","DecoderBuffer","Init","byteLength","_disableAttributeTransforms","geometry_type","GetEncodedGeometryType","dracoGeometry","Mesh","PointCloud","dracoStatus","DecodeBufferToMesh","DecodeBufferToPointCloud","Error","ok","ptr","message","error_msg","loaderData","_getDracoLoaderData","geometry","_getMeshData","boundingBox","attributes","schema","indices","data","loader","header","vertexCount","num_points","metadata","_getTopLevelMetadata","_getDracoAttributes","num_attributes","num_faces","dracoAttributes","attributeId","dracoAttribute","GetAttribute","_getAttributeMetadata","unique_id","attribute_type","data_type","num_components","byte_offset","byte_stride","normalized","attribute_index","quantization","_getQuantizationTransform","quantization_transform","octahedron","_getOctahedronTransform","octahedron_transform","_getMeshAttributes","positionAttribute","topology","mode","value","_getTriangleStripIndices","size","_getTriangleListIndices","loaderAttribute","Object","values","attributeName","_deduceAttributeName","name","_getAttributeValues","byteOffset","byteStride","numFaces","numIndices","_malloc","GetTrianglesUInt32Array","HEAPF32","slice","_free","dracoArray","DracoInt32Array","GetTriangleStripsFromMesh","getUint32Array","attribute","TypedArrayCtor","numComponents","numPoints","numValues","BYTES_PER_ELEMENT","dataType","getDracoDataType","GetAttributeDataArrayForAllPoints","uniqueId","attributeUniqueId","entries","extraAttributes","thisAttributeType","dracoAttributeConstant","attributeType","entryName","attributeNameEntry","string","dracoMetadata","GetMetadata","_getDracoMetadata","GetAttributeMetadata","result","numEntries","NumEntries","entryIndex","GetEntryName","_getDracoMetadataField","GetIntEntryArray","intArray","getInt32Array","int","GetIntEntry","GetStringEntry","double","GetDoubleEntry","quantizedAttributes","octahedronAttributes","skipAttributes","dracoAttributeName","SkipAttributeTransform","skip","map","type","includes","transform","AttributeQuantizationTransform","InitFromAttribute","quantization_bits","range","min_values","i","min_value","DT_FLOAT32","DT_INT8","DT_INT16","DT_INT32","DT_UINT8","DT_UINT16","DT_UINT32","DT_INVALID","GetValue"],"mappings":";AA2BA,SAAQA,kBAAR,QAAiC,oBAAjC;AACA,SAAQC,cAAR,QAA6B,0BAA7B;AAmBA,MAAMC,aAAa,GAAG;AACpBC,EAAAA,eAAe,EAAE,CADG;AAEpBC,EAAAA,WAAW,EAAE;AAFO,CAAtB;AAMA,MAAMC,gCAAgC,GAAG;AACvCC,EAAAA,QAAQ,EAAE,UAD6B;AAEvCC,EAAAA,MAAM,EAAE,QAF+B;AAGvCC,EAAAA,KAAK,EAAE,SAHgC;AAIvCC,EAAAA,SAAS,EAAE;AAJ4B,CAAzC;AAOA,MAAMC,kCAAkC,GAAG;AACzC,KAAGC,SADsC;AAEzC,KAAGC,UAFsC;AAGzC,KAAGC,UAHsC;AAIzC,KAAGC,WAJsC;AAKzC,KAAGC,UALsC;AAMzC,KAAGC,WANsC;AAOzC,KAAGC;AAPsC,CAA3C;AAUA,MAAMC,eAAe,GAAG,CAAxB;AAEA,eAAe,MAAMC,WAAN,CAAkB;AAM/BC,EAA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/schema';\n\n// Draco types (input)\nimport type {\n Draco3D,\n Decoder,\n Mesh,\n PointCloud,\n PointAttribute,\n Metadata,\n MetadataQuerier,\n DracoInt32Array,\n draco_DataType\n} from '../draco3d/draco3d-types';\n\n// Parsed data types (output)\nimport type {\n DracoMesh,\n DracoLoaderData,\n DracoAttribute,\n DracoMetadataEntry,\n DracoQuantizationTransform,\n DracoOctahedronTransform\n} from './draco-types';\n\nimport {getMeshBoundingBox} from '@loaders.gl/schema';\nimport {getDracoSchema} from './utils/get-draco-schema';\n\n/**\n * @param topology - How triangle indices should be generated (mesh only)\n * @param attributeNameEntry\n * @param extraAttributes\n * @param quantizedAttributes\n * @param octahedronAttributes\n */\nexport type DracoParseOptions = {\n topology?: 'triangle-list' | 'triangle-strip';\n attributeNameEntry?: string;\n extraAttributes?: {[uniqueId: string]: number};\n quantizedAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];\n octahedronAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];\n};\n\n// @ts-ignore\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst GEOMETRY_TYPE = {\n TRIANGULAR_MESH: 0,\n POINT_CLOUD: 1\n};\n\n// Native Draco attribute names to GLTF attribute names.\nconst DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {\n POSITION: 'POSITION',\n NORMAL: 'NORMAL',\n COLOR: 'COLOR_0',\n TEX_COORD: 'TEXCOORD_0'\n};\n\nconst DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {\n 1: Int8Array,\n 2: Uint8Array,\n 3: Int16Array,\n 4: Uint16Array,\n 5: Int32Array,\n 6: Uint32Array,\n 9: Float32Array\n};\n\nconst INDEX_ITEM_SIZE = 4;\n\nexport default class DracoParser {\n draco: Draco3D;\n decoder: Decoder;\n metadataQuerier: MetadataQuerier;\n\n // draco - the draco decoder, either import `draco3d` or load dynamically\n constructor(draco: Draco3D) {\n this.draco = draco;\n this.decoder = new this.draco.Decoder();\n this.metadataQuerier = new this.draco.MetadataQuerier();\n }\n\n /**\n * Destroy draco resources\n */\n destroy(): void {\n this.draco.destroy(this.decoder);\n this.draco.destroy(this.metadataQuerier);\n }\n\n /**\n * NOTE: caller must call `destroyGeometry` on the return value after using it\n * @param arrayBuffer\n * @param options\n */\n parseSync(arrayBuffer: ArrayBuffer, options: DracoParseOptions = {}): DracoMesh {\n const buffer = new this.draco.DecoderBuffer();\n buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);\n\n this._disableAttributeTransforms(options);\n\n const geometry_type = this.decoder.GetEncodedGeometryType(buffer);\n const dracoGeometry =\n geometry_type === this.draco.TRIANGULAR_MESH\n ? new this.draco.Mesh()\n : new this.draco.PointCloud();\n\n try {\n let dracoStatus;\n switch (geometry_type) {\n case this.draco.TRIANGULAR_MESH:\n dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry as Mesh);\n break;\n\n case this.draco.POINT_CLOUD:\n dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);\n break;\n\n default:\n throw new Error('DRACO: Unknown geometry type.');\n }\n\n if (!dracoStatus.ok() || !dracoGeometry.ptr) {\n const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`;\n // console.error(message);\n throw new Error(message);\n }\n\n const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);\n\n const geometry = this._getMeshData(dracoGeometry, loaderData, options);\n\n const boundingBox = getMeshBoundingBox(geometry.attributes);\n\n const schema = getDracoSchema(geometry.attributes, loaderData, geometry.indices);\n\n const data: DracoMesh = {\n loader: 'draco',\n loaderData,\n header: {\n vertexCount: dracoGeometry.num_points(),\n boundingBox\n },\n ...geometry,\n schema\n };\n return data;\n } finally {\n this.draco.destroy(buffer);\n if (dracoGeometry) {\n this.draco.destroy(dracoGeometry);\n }\n }\n }\n\n // Draco specific \"loader data\"\n\n /**\n * Extract\n * @param dracoGeometry\n * @param geometry_type\n * @param options\n * @returns\n */\n _getDracoLoaderData(\n dracoGeometry: Mesh | PointCloud,\n geometry_type,\n options: DracoParseOptions\n ): DracoLoaderData {\n const metadata = this._getTopLevelMetadata(dracoGeometry);\n const attributes = this._getDracoAttributes(dracoGeometry, options);\n\n return {\n geometry_type,\n num_attributes: dracoGeometry.num_attributes(),\n num_points: dracoGeometry.num_points(),\n num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,\n metadata,\n attributes\n };\n }\n\n /**\n * Extract all draco provided information and metadata for each attribute\n * @param dracoGeometry\n * @param options\n * @returns\n */\n _getDracoAttributes(\n dracoGeometry: Mesh | PointCloud,\n options: DracoParseOptions\n ): {[unique_id: number]: DracoAttribute} {\n const dracoAttributes: {[unique_id: number]: DracoAttribute} = {};\n\n for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {\n // Note: Draco docs do not seem clear on `GetAttribute` ids just being a zero-based index,\n // but it does seems to work this way\n const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);\n\n const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);\n\n dracoAttributes[dracoAttribute.unique_id()] = {\n unique_id: dracoAttribute.unique_id(),\n attribute_type: dracoAttribute.attribute_type(),\n data_type: dracoAttribute.data_type(),\n num_components: dracoAttribute.num_components(),\n\n byte_offset: dracoAttribute.byte_offset(),\n byte_stride: dracoAttribute.byte_stride(),\n normalized: dracoAttribute.normalized(),\n attribute_index: attributeId,\n\n metadata\n };\n\n // Add transformation parameters for any attributes app wants untransformed\n const quantization = this._getQuantizationTransform(dracoAttribute, options);\n if (quantization) {\n dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;\n }\n\n const octahedron = this._getOctahedronTransform(dracoAttribute, options);\n if (octahedron) {\n dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;\n }\n }\n\n return dracoAttributes;\n }\n\n /**\n * Get standard loaders.gl mesh category data\n * Extracts the geometry from draco\n * @param dracoGeometry\n * @param options\n */\n _getMeshData(\n dracoGeometry: Mesh | PointCloud,\n loaderData: DracoLoaderData,\n options: DracoParseOptions\n ): MeshGeometry {\n const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);\n\n const positionAttribute = attributes.POSITION;\n if (!positionAttribute) {\n throw new Error('DRACO: No position attribute found.');\n }\n\n // For meshes, we need indices to define the faces.\n if (dracoGeometry instanceof this.draco.Mesh) {\n switch (options.topology) {\n case 'triangle-strip':\n return {\n topology: 'triangle-strip',\n mode: 4, // GL.TRIANGLES\n attributes,\n indices: {\n value: this._getTriangleStripIndices(dracoGeometry),\n size: 1\n }\n };\n case 'triangle-list':\n default:\n return {\n topology: 'triangle-list',\n mode: 5, // GL.TRIANGLE_STRIP\n attributes,\n indices: {\n value: this._getTriangleListIndices(dracoGeometry),\n size: 1\n }\n };\n }\n }\n\n // PointCloud - must come last as Mesh inherits from PointCloud\n return {\n topology: 'point-list',\n mode: 0, // GL.POINTS\n attributes\n };\n }\n\n _getMeshAttributes(\n loaderData: DracoLoaderData,\n dracoGeometry: Mesh | PointCloud,\n options: DracoParseOptions\n ): {[attributeName: string]: MeshAttribute} {\n const attributes: {[key: string]: MeshAttribute} = {};\n\n for (const loaderAttribute of Object.values(loaderData.attributes)) {\n const attributeName = this._deduceAttributeName(loaderAttribute, options);\n loaderAttribute.name = attributeName;\n const {value, size} = this._getAttributeValues(dracoGeometry, loaderAttribute);\n attributes[attributeName] = {\n value,\n size,\n byteOffset: loaderAttribute.byte_offset,\n byteStride: loaderAttribute.byte_stride,\n normalized: loaderAttribute.normalized\n };\n }\n\n return attributes;\n }\n\n // MESH INDICES EXTRACTION\n\n /**\n * For meshes, we need indices to define the faces.\n * @param dracoGeometry\n */\n _getTriangleListIndices(dracoGeometry: Mesh) {\n // Example on how to retrieve mesh and attributes.\n const numFaces = dracoGeometry.num_faces();\n const numIndices = numFaces * 3;\n const byteLength = numIndices * INDEX_ITEM_SIZE;\n\n const ptr = this.draco._malloc(byteLength);\n try {\n this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);\n return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();\n } finally {\n this.draco._free(ptr);\n }\n }\n\n /**\n * For meshes, we need indices to define the faces.\n * @param dracoGeometry\n */\n _getTriangleStripIndices(dracoGeometry: Mesh) {\n const dracoArray = new this.draco.DracoInt32Array();\n try {\n /* const numStrips = */ this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);\n return getUint32Array(dracoArray);\n } finally {\n this.draco.destroy(dracoArray);\n }\n }\n\n /**\n *\n * @param dracoGeometry\n * @param dracoAttribute\n * @param attributeName\n */\n _getAttributeValues(\n dracoGeometry: Mesh | PointCloud,\n attribute: DracoAttribute\n ): {value: TypedArray; size: number} {\n const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];\n const numComponents = attribute.num_components;\n const numPoints = dracoGeometry.num_points();\n const numValues = numPoints * numComponents;\n\n const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;\n const dataType = getDracoDataType(this.draco, TypedArrayCtor);\n\n let value: TypedArray;\n\n const ptr = this.draco._malloc(byteLength);\n try {\n const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);\n this.decoder.GetAttributeDataArrayForAllPoints(\n dracoGeometry,\n dracoAttribute,\n dataType,\n byteLength,\n ptr\n );\n value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();\n } finally {\n this.draco._free(ptr);\n }\n\n return {value, size: numComponents};\n }\n\n // Attribute names\n\n /** \n * DRACO does not store attribute names - We need to deduce an attribute name\n * for each attribute\n _getAttributeNames(\n dracoGeometry: Mesh | PointCloud,\n options: DracoParseOptions\n ): {[unique_id: number]: string} {\n const attributeNames: {[unique_id: number]: string} = {};\n for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {\n const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);\n const attributeName = this._deduceAttributeName(dracoAttribute, options);\n attributeNames[attributeName] = attributeName;\n }\n return attributeNames;\n }\n */\n\n /**\n * Deduce an attribute name.\n * @note DRACO does not save attribute names, just general type (POSITION, COLOR)\n * to help optimize compression. We generate GLTF compatible names for the Draco-recognized\n * types\n * @param attributeData\n */\n _deduceAttributeName(attribute: DracoAttribute, options: DracoParseOptions): string {\n // Deduce name based on application provided map\n const uniqueId = attribute.unique_id;\n for (const [attributeName, attributeUniqueId] of Object.entries(\n options.extraAttributes || {}\n )) {\n if (attributeUniqueId === uniqueId) {\n return attributeName;\n }\n }\n\n // Deduce name based on attribute type\n const thisAttributeType = attribute.attribute_type;\n for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {\n const attributeType = this.draco[dracoAttributeConstant];\n if (attributeType === thisAttributeType) {\n // TODO - Return unique names if there multiple attributes per type\n // (e.g. multiple TEX_COORDS or COLORS)\n return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];\n }\n }\n\n // Look up in metadata\n // TODO - shouldn't this have priority?\n const entryName = options.attributeNameEntry || 'name';\n if (attribute.metadata[entryName]) {\n return attribute.metadata[entryName].string;\n }\n\n // Attribute of \"GENERIC\" type, we need to assign some name\n return `CUSTOM_ATTRIBUTE_${uniqueId}`;\n }\n\n // METADATA EXTRACTION\n\n /** Get top level metadata */\n _getTopLevelMetadata(dracoGeometry: Mesh | PointCloud) {\n const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);\n return this._getDracoMetadata(dracoMetadata);\n }\n\n /** Get per attribute metadata */\n _getAttributeMetadata(dracoGeometry: Mesh | PointCloud, attributeId: number) {\n const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);\n return this._getDracoMetadata(dracoMetadata);\n }\n\n /**\n * Extract metadata field values\n * @param dracoMetadata\n * @returns\n */\n _getDracoMetadata(dracoMetadata: Metadata): {[entry: string]: DracoMetadataEntry} {\n // The not so wonderful world of undocumented Draco APIs :(\n if (!dracoMetadata || !dracoMetadata.ptr) {\n return {};\n }\n const result = {};\n const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);\n for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {\n const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);\n result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);\n }\n return result;\n }\n\n /**\n * Extracts possible values for one metadata entry by name\n * @param dracoMetadata\n * @param entryName\n */\n _getDracoMetadataField(dracoMetadata: Metadata, entryName: string): DracoMetadataEntry {\n const dracoArray = new this.draco.DracoInt32Array();\n try {\n // Draco metadata fields can hold int32 arrays\n this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);\n const intArray = getInt32Array(dracoArray);\n return {\n int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),\n string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),\n double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),\n intArray\n };\n } finally {\n this.draco.destroy(dracoArray);\n }\n }\n\n // QUANTIZED ATTRIBUTE SUPPORT (NO DECOMPRESSION)\n\n /** Skip transforms for specific attribute types */\n _disableAttributeTransforms(options: DracoParseOptions) {\n const {quantizedAttributes = [], octahedronAttributes = []} = options;\n const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];\n for (const dracoAttributeName of skipAttributes) {\n this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);\n }\n }\n\n /**\n * Extract (and apply?) Position Transform\n * @todo not used\n */\n _getQuantizationTransform(\n dracoAttribute: PointAttribute,\n options: DracoParseOptions\n ): DracoQuantizationTransform | null {\n const {quantizedAttributes = []} = options;\n const attribute_type = dracoAttribute.attribute_type();\n const skip = quantizedAttributes.map((type) => this.decoder[type]).includes(attribute_type);\n if (skip) {\n const transform = new this.draco.AttributeQuantizationTransform();\n try {\n if (transform.InitFromAttribute(dracoAttribute)) {\n return {\n quantization_bits: transform.quantization_bits(),\n range: transform.range(),\n min_values: new Float32Array([1, 2, 3]).map((i) => transform.min_value(i))\n };\n }\n } finally {\n this.draco.destroy(transform);\n }\n }\n return null;\n }\n\n _getOctahedronTransform(\n dracoAttribute: PointAttribute,\n options: DracoParseOptions\n ): DracoOctahedronTransform | null {\n const {octahedronAttributes = []} = options;\n const attribute_type = dracoAttribute.attribute_type();\n const octahedron = octahedronAttributes\n .map((type) => this.decoder[type])\n .includes(attribute_type);\n if (octahedron) {\n const transform = new this.draco.AttributeQuantizationTransform();\n try {\n if (transform.InitFromAttribute(dracoAttribute)) {\n return {\n quantization_bits: transform.quantization_bits()\n };\n }\n } finally {\n this.draco.destroy(transform);\n }\n }\n return null;\n }\n\n // HELPERS\n}\n\n/**\n * Get draco specific data type by TypedArray constructor type\n * @param attributeType\n * @returns draco specific data type\n */\nfunction getDracoDataType(draco: Draco3D, attributeType: any): draco_DataType {\n switch (attributeType) {\n case Float32Array:\n return draco.DT_FLOAT32;\n case Int8Array:\n return draco.DT_INT8;\n case Int16Array:\n return draco.DT_INT16;\n case Int32Array:\n return draco.DT_INT32;\n case Uint8Array:\n return draco.DT_UINT8;\n case Uint16Array:\n return draco.DT_UINT16;\n case Uint32Array:\n return draco.DT_UINT32;\n default:\n return draco.DT_INVALID;\n }\n}\n\n/**\n * Copy a Draco int32 array into a JS typed array\n */\nfunction getInt32Array(dracoArray: DracoInt32Array): Int32Array {\n const numValues = dracoArray.size();\n const intArray = new Int32Array(numValues);\n for (let i = 0; i < numValues; i++) {\n intArray[i] = dracoArray.GetValue(i);\n }\n return intArray;\n}\n\n/**\n * Copy a Draco int32 array into a JS typed array\n */\nfunction getUint32Array(dracoArray: DracoInt32Array): Int32Array {\n const numValues = dracoArray.size();\n const intArray = new Int32Array(numValues);\n for (let i = 0; i < numValues; i++) {\n intArray[i] = dracoArray.GetValue(i);\n }\n return intArray;\n}\n"],"file":"draco-parser.js"}
1
+ {"version":3,"sources":["../../../src/lib/draco-parser.ts"],"names":["getMeshBoundingBox","getDracoSchema","GEOMETRY_TYPE","TRIANGULAR_MESH","POINT_CLOUD","DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP","POSITION","NORMAL","COLOR","TEX_COORD","DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP","Int8Array","Uint8Array","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","INDEX_ITEM_SIZE","DracoParser","constructor","draco","decoder","Decoder","metadataQuerier","MetadataQuerier","destroy","parseSync","arrayBuffer","options","buffer","DecoderBuffer","Init","byteLength","_disableAttributeTransforms","geometry_type","GetEncodedGeometryType","dracoGeometry","Mesh","PointCloud","dracoStatus","DecodeBufferToMesh","DecodeBufferToPointCloud","Error","ok","ptr","message","error_msg","loaderData","_getDracoLoaderData","geometry","_getMeshData","boundingBox","attributes","schema","indices","data","loader","header","vertexCount","num_points","metadata","_getTopLevelMetadata","_getDracoAttributes","num_attributes","num_faces","dracoAttributes","attributeId","dracoAttribute","GetAttribute","_getAttributeMetadata","unique_id","attribute_type","data_type","num_components","byte_offset","byte_stride","normalized","attribute_index","quantization","_getQuantizationTransform","quantization_transform","octahedron","_getOctahedronTransform","octahedron_transform","_getMeshAttributes","positionAttribute","topology","mode","value","_getTriangleStripIndices","size","_getTriangleListIndices","loaderAttribute","Object","values","attributeName","_deduceAttributeName","name","_getAttributeValues","byteOffset","byteStride","numFaces","numIndices","_malloc","GetTrianglesUInt32Array","HEAPF32","slice","_free","dracoArray","DracoInt32Array","GetTriangleStripsFromMesh","getUint32Array","attribute","TypedArrayCtor","numComponents","numPoints","numValues","BYTES_PER_ELEMENT","dataType","getDracoDataType","GetAttributeDataArrayForAllPoints","uniqueId","attributeUniqueId","entries","extraAttributes","thisAttributeType","dracoAttributeConstant","attributeType","entryName","attributeNameEntry","string","dracoMetadata","GetMetadata","_getDracoMetadata","GetAttributeMetadata","result","numEntries","NumEntries","entryIndex","GetEntryName","_getDracoMetadataField","GetIntEntryArray","intArray","getInt32Array","int","GetIntEntry","GetStringEntry","double","GetDoubleEntry","quantizedAttributes","octahedronAttributes","skipAttributes","dracoAttributeName","SkipAttributeTransform","skip","map","type","includes","transform","AttributeQuantizationTransform","InitFromAttribute","quantization_bits","range","min_values","i","min_value","DT_FLOAT32","DT_INT8","DT_INT16","DT_INT32","DT_UINT8","DT_UINT16","DT_UINT32","DT_INVALID","GetValue"],"mappings":";AA2BA,SAAQA,kBAAR,QAAiC,oBAAjC;AACA,SAAQC,cAAR,QAA6B,0BAA7B;AAmBA,MAAMC,aAAa,GAAG;AACpBC,EAAAA,eAAe,EAAE,CADG;AAEpBC,EAAAA,WAAW,EAAE;AAFO,CAAtB;AAMA,MAAMC,gCAAgC,GAAG;AACvCC,EAAAA,QAAQ,EAAE,UAD6B;AAEvCC,EAAAA,MAAM,EAAE,QAF+B;AAGvCC,EAAAA,KAAK,EAAE,SAHgC;AAIvCC,EAAAA,SAAS,EAAE;AAJ4B,CAAzC;AAOA,MAAMC,kCAAkC,GAAG;AACzC,KAAGC,SADsC;AAEzC,KAAGC,UAFsC;AAGzC,KAAGC,UAHsC;AAIzC,KAAGC,WAJsC;AAKzC,KAAGC,UALsC;AAMzC,KAAGC,WANsC;AAOzC,KAAGC;AAPsC,CAA3C;AAUA,MAAMC,eAAe,GAAG,CAAxB;AAEA,eAAe,MAAMC,WAAN,CAAkB;AAM/BC,EAAAA,WAAW,CAACC,KAAD,EAAiB;AAAA;;AAAA;;AAAA;;AAC1B,SAAKA,KAAL,GAAaA,KAAb;AACA,SAAKC,OAAL,GAAe,IAAI,KAAKD,KAAL,CAAWE,OAAf,EAAf;AACA,SAAKC,eAAL,GAAuB,IAAI,KAAKH,KAAL,CAAWI,eAAf,EAAvB;AACD;;AAKDC,EAAAA,OAAO,GAAS;AACd,SAAKL,KAAL,CAAWK,OAAX,CAAmB,KAAKJ,OAAxB;AACA,SAAKD,KAAL,CAAWK,OAAX,CAAmB,KAAKF,eAAxB;AACD;;AAODG,EAAAA,SAAS,CAACC,WAAD,EAA2BC,OAA0B,GAAG,EAAxD,EAAuE;AAC9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D,QAAMQ,SAAS,GAAGR,UAAU,CAAClB,IAAX,EAAlB;AACA,QAAMoD,QAAQ,GAAG,IAAIhI,UAAJ,CAAesG,SAAf,CAAjB;;AACA,OAAK,IAAIgD,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGhD,SAApB,EAA+BgD,CAAC,EAAhC,EAAoC;AAClCtB,IAAAA,QAAQ,CAACsB,CAAD,CAAR,GAAcxD,UAAU,CAACkE,QAAX,CAAoBV,CAApB,CAAd;AACD;;AACD,SAAOtB,QAAP;AACD;;AAKD,SAAS/B,cAAT,CAAwBH,UAAxB,EAAiE;AAC/D,QAAMQ,SAAS,GAAGR,UAAU,CAAClB,IAAX,EAAlB;AACA,QAAMoD,QAAQ,GAAG,IAAIhI,UAAJ,CAAesG,SAAf,CAAjB;;AACA,OAAK,IAAIgD,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGhD,SAApB,EAA+BgD,CAAC,EAAhC,EAAoC;AAClCtB,IAAAA,QAAQ,CAACsB,CAAD,CAAR,GAAcxD,UAAU,CAACkE,QAAX,CAAoBV,CAApB,CAAd;AACD;;AACD,SAAOtB,QAAP;AACD","sourcesContent":["/* eslint-disable camelcase */\n\nimport type {TypedArray, MeshAttribute, MeshGeometry} from '@loaders.gl/schema';\n\n// Draco types (input)\nimport type {\n Draco3D,\n Decoder,\n Mesh,\n PointCloud,\n PointAttribute,\n Metadata,\n MetadataQuerier,\n DracoInt32Array,\n draco_DataType\n} from '../draco3d/draco3d-types';\n\n// Parsed data types (output)\nimport type {\n DracoMesh,\n DracoLoaderData,\n DracoAttribute,\n DracoMetadataEntry,\n DracoQuantizationTransform,\n DracoOctahedronTransform\n} from './draco-types';\n\nimport {getMeshBoundingBox} from '@loaders.gl/schema';\nimport {getDracoSchema} from './utils/get-draco-schema';\n\n/**\n * @param topology - How triangle indices should be generated (mesh only)\n * @param attributeNameEntry\n * @param extraAttributes\n * @param quantizedAttributes\n * @param octahedronAttributes\n */\nexport type DracoParseOptions = {\n topology?: 'triangle-list' | 'triangle-strip';\n attributeNameEntry?: string;\n extraAttributes?: {[uniqueId: string]: number};\n quantizedAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];\n octahedronAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];\n};\n\n// @ts-ignore\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst GEOMETRY_TYPE = {\n TRIANGULAR_MESH: 0,\n POINT_CLOUD: 1\n};\n\n// Native Draco attribute names to GLTF attribute names.\nconst DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {\n POSITION: 'POSITION',\n NORMAL: 'NORMAL',\n COLOR: 'COLOR_0',\n TEX_COORD: 'TEXCOORD_0'\n};\n\nconst DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {\n 1: Int8Array,\n 2: Uint8Array,\n 3: Int16Array,\n 4: Uint16Array,\n 5: Int32Array,\n 6: Uint32Array,\n 9: Float32Array\n};\n\nconst INDEX_ITEM_SIZE = 4;\n\nexport default class DracoParser {\n draco: Draco3D;\n decoder: Decoder;\n metadataQuerier: MetadataQuerier;\n\n // draco - the draco decoder, either import `draco3d` or load dynamically\n constructor(draco: Draco3D) {\n this.draco = draco;\n this.decoder = new this.draco.Decoder();\n this.metadataQuerier = new this.draco.MetadataQuerier();\n }\n\n /**\n * Destroy draco resources\n */\n destroy(): void {\n this.draco.destroy(this.decoder);\n this.draco.destroy(this.metadataQuerier);\n }\n\n /**\n * NOTE: caller must call `destroyGeometry` on the return value after using it\n * @param arrayBuffer\n * @param options\n */\n parseSync(arrayBuffer: ArrayBuffer, options: DracoParseOptions = {}): DracoMesh {\n const buffer = new this.draco.DecoderBuffer();\n buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);\n\n this._disableAttributeTransforms(options);\n\n const geometry_type = this.decoder.GetEncodedGeometryType(buffer);\n const dracoGeometry =\n geometry_type === this.draco.TRIANGULAR_MESH\n ? new this.draco.Mesh()\n : new this.draco.PointCloud();\n\n try {\n let dracoStatus;\n switch (geometry_type) {\n case this.draco.TRIANGULAR_MESH:\n dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry as Mesh);\n break;\n\n case this.draco.POINT_CLOUD:\n dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);\n break;\n\n default:\n throw new Error('DRACO: Unknown geometry type.');\n }\n\n if (!dracoStatus.ok() || !dracoGeometry.ptr) {\n const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`;\n // console.error(message);\n throw new Error(message);\n }\n\n const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);\n\n const geometry = this._getMeshData(dracoGeometry, loaderData, options);\n\n const boundingBox = getMeshBoundingBox(geometry.attributes);\n\n const schema = getDracoSchema(geometry.attributes, loaderData, geometry.indices);\n\n const data: DracoMesh = {\n loader: 'draco',\n loaderData,\n header: {\n vertexCount: dracoGeometry.num_points(),\n boundingBox\n },\n ...geometry,\n schema\n };\n return data;\n } finally {\n this.draco.destroy(buffer);\n if (dracoGeometry) {\n this.draco.destroy(dracoGeometry);\n }\n }\n }\n\n // Draco specific \"loader data\"\n\n /**\n * Extract\n * @param dracoGeometry\n * @param geometry_type\n * @param options\n * @returns\n */\n _getDracoLoaderData(\n dracoGeometry: Mesh | PointCloud,\n geometry_type,\n options: DracoParseOptions\n ): DracoLoaderData {\n const metadata = this._getTopLevelMetadata(dracoGeometry);\n const attributes = this._getDracoAttributes(dracoGeometry, options);\n\n return {\n geometry_type,\n num_attributes: dracoGeometry.num_attributes(),\n num_points: dracoGeometry.num_points(),\n num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,\n metadata,\n attributes\n };\n }\n\n /**\n * Extract all draco provided information and metadata for each attribute\n * @param dracoGeometry\n * @param options\n * @returns\n */\n _getDracoAttributes(\n dracoGeometry: Mesh | PointCloud,\n options: DracoParseOptions\n ): {[unique_id: number]: DracoAttribute} {\n const dracoAttributes: {[unique_id: number]: DracoAttribute} = {};\n\n for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {\n // Note: Draco docs do not seem clear on `GetAttribute` ids just being a zero-based index,\n // but it does seems to work this way\n const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);\n\n const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);\n\n dracoAttributes[dracoAttribute.unique_id()] = {\n unique_id: dracoAttribute.unique_id(),\n attribute_type: dracoAttribute.attribute_type(),\n data_type: dracoAttribute.data_type(),\n num_components: dracoAttribute.num_components(),\n\n byte_offset: dracoAttribute.byte_offset(),\n byte_stride: dracoAttribute.byte_stride(),\n normalized: dracoAttribute.normalized(),\n attribute_index: attributeId,\n\n metadata\n };\n\n // Add transformation parameters for any attributes app wants untransformed\n const quantization = this._getQuantizationTransform(dracoAttribute, options);\n if (quantization) {\n dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;\n }\n\n const octahedron = this._getOctahedronTransform(dracoAttribute, options);\n if (octahedron) {\n dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;\n }\n }\n\n return dracoAttributes;\n }\n\n /**\n * Get standard loaders.gl mesh category data\n * Extracts the geometry from draco\n * @param dracoGeometry\n * @param options\n */\n _getMeshData(\n dracoGeometry: Mesh | PointCloud,\n loaderData: DracoLoaderData,\n options: DracoParseOptions\n ): MeshGeometry {\n const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);\n\n const positionAttribute = attributes.POSITION;\n if (!positionAttribute) {\n throw new Error('DRACO: No position attribute found.');\n }\n\n // For meshes, we need indices to define the faces.\n if (dracoGeometry instanceof this.draco.Mesh) {\n switch (options.topology) {\n case 'triangle-strip':\n return {\n topology: 'triangle-strip',\n mode: 4, // GL.TRIANGLES\n attributes,\n indices: {\n value: this._getTriangleStripIndices(dracoGeometry),\n size: 1\n }\n };\n case 'triangle-list':\n default:\n return {\n topology: 'triangle-list',\n mode: 5, // GL.TRIANGLE_STRIP\n attributes,\n indices: {\n value: this._getTriangleListIndices(dracoGeometry),\n size: 1\n }\n };\n }\n }\n\n // PointCloud - must come last as Mesh inherits from PointCloud\n return {\n topology: 'point-list',\n mode: 0, // GL.POINTS\n attributes\n };\n }\n\n _getMeshAttributes(\n loaderData: DracoLoaderData,\n dracoGeometry: Mesh | PointCloud,\n options: DracoParseOptions\n ): {[attributeName: string]: MeshAttribute} {\n const attributes: {[key: string]: MeshAttribute} = {};\n\n for (const loaderAttribute of Object.values(loaderData.attributes)) {\n const attributeName = this._deduceAttributeName(loaderAttribute, options);\n loaderAttribute.name = attributeName;\n const {value, size} = this._getAttributeValues(dracoGeometry, loaderAttribute);\n attributes[attributeName] = {\n value,\n size,\n byteOffset: loaderAttribute.byte_offset,\n byteStride: loaderAttribute.byte_stride,\n normalized: loaderAttribute.normalized\n };\n }\n\n return attributes;\n }\n\n // MESH INDICES EXTRACTION\n\n /**\n * For meshes, we need indices to define the faces.\n * @param dracoGeometry\n */\n _getTriangleListIndices(dracoGeometry: Mesh) {\n // Example on how to retrieve mesh and attributes.\n const numFaces = dracoGeometry.num_faces();\n const numIndices = numFaces * 3;\n const byteLength = numIndices * INDEX_ITEM_SIZE;\n\n const ptr = this.draco._malloc(byteLength);\n try {\n this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);\n return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();\n } finally {\n this.draco._free(ptr);\n }\n }\n\n /**\n * For meshes, we need indices to define the faces.\n * @param dracoGeometry\n */\n _getTriangleStripIndices(dracoGeometry: Mesh) {\n const dracoArray = new this.draco.DracoInt32Array();\n try {\n /* const numStrips = */ this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);\n return getUint32Array(dracoArray);\n } finally {\n this.draco.destroy(dracoArray);\n }\n }\n\n /**\n *\n * @param dracoGeometry\n * @param dracoAttribute\n * @param attributeName\n */\n _getAttributeValues(\n dracoGeometry: Mesh | PointCloud,\n attribute: DracoAttribute\n ): {value: TypedArray; size: number} {\n const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];\n const numComponents = attribute.num_components;\n const numPoints = dracoGeometry.num_points();\n const numValues = numPoints * numComponents;\n\n const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;\n const dataType = getDracoDataType(this.draco, TypedArrayCtor);\n\n let value: TypedArray;\n\n const ptr = this.draco._malloc(byteLength);\n try {\n const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);\n this.decoder.GetAttributeDataArrayForAllPoints(\n dracoGeometry,\n dracoAttribute,\n dataType,\n byteLength,\n ptr\n );\n value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();\n } finally {\n this.draco._free(ptr);\n }\n\n return {value, size: numComponents};\n }\n\n // Attribute names\n\n /** \n * DRACO does not store attribute names - We need to deduce an attribute name\n * for each attribute\n _getAttributeNames(\n dracoGeometry: Mesh | PointCloud,\n options: DracoParseOptions\n ): {[unique_id: number]: string} {\n const attributeNames: {[unique_id: number]: string} = {};\n for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {\n const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);\n const attributeName = this._deduceAttributeName(dracoAttribute, options);\n attributeNames[attributeName] = attributeName;\n }\n return attributeNames;\n }\n */\n\n /**\n * Deduce an attribute name.\n * @note DRACO does not save attribute names, just general type (POSITION, COLOR)\n * to help optimize compression. We generate GLTF compatible names for the Draco-recognized\n * types\n * @param attributeData\n */\n _deduceAttributeName(attribute: DracoAttribute, options: DracoParseOptions): string {\n // Deduce name based on application provided map\n const uniqueId = attribute.unique_id;\n for (const [attributeName, attributeUniqueId] of Object.entries(\n options.extraAttributes || {}\n )) {\n if (attributeUniqueId === uniqueId) {\n return attributeName;\n }\n }\n\n // Deduce name based on attribute type\n const thisAttributeType = attribute.attribute_type;\n for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {\n const attributeType = this.draco[dracoAttributeConstant];\n if (attributeType === thisAttributeType) {\n // TODO - Return unique names if there multiple attributes per type\n // (e.g. multiple TEX_COORDS or COLORS)\n return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];\n }\n }\n\n // Look up in metadata\n // TODO - shouldn't this have priority?\n const entryName = options.attributeNameEntry || 'name';\n if (attribute.metadata[entryName]) {\n return attribute.metadata[entryName].string;\n }\n\n // Attribute of \"GENERIC\" type, we need to assign some name\n return `CUSTOM_ATTRIBUTE_${uniqueId}`;\n }\n\n // METADATA EXTRACTION\n\n /** Get top level metadata */\n _getTopLevelMetadata(dracoGeometry: Mesh | PointCloud) {\n const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);\n return this._getDracoMetadata(dracoMetadata);\n }\n\n /** Get per attribute metadata */\n _getAttributeMetadata(dracoGeometry: Mesh | PointCloud, attributeId: number) {\n const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);\n return this._getDracoMetadata(dracoMetadata);\n }\n\n /**\n * Extract metadata field values\n * @param dracoMetadata\n * @returns\n */\n _getDracoMetadata(dracoMetadata: Metadata): {[entry: string]: DracoMetadataEntry} {\n // The not so wonderful world of undocumented Draco APIs :(\n if (!dracoMetadata || !dracoMetadata.ptr) {\n return {};\n }\n const result = {};\n const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);\n for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {\n const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);\n result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);\n }\n return result;\n }\n\n /**\n * Extracts possible values for one metadata entry by name\n * @param dracoMetadata\n * @param entryName\n */\n _getDracoMetadataField(dracoMetadata: Metadata, entryName: string): DracoMetadataEntry {\n const dracoArray = new this.draco.DracoInt32Array();\n try {\n // Draco metadata fields can hold int32 arrays\n this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);\n const intArray = getInt32Array(dracoArray);\n return {\n int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),\n string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),\n double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),\n intArray\n };\n } finally {\n this.draco.destroy(dracoArray);\n }\n }\n\n // QUANTIZED ATTRIBUTE SUPPORT (NO DECOMPRESSION)\n\n /** Skip transforms for specific attribute types */\n _disableAttributeTransforms(options: DracoParseOptions) {\n const {quantizedAttributes = [], octahedronAttributes = []} = options;\n const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];\n for (const dracoAttributeName of skipAttributes) {\n this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);\n }\n }\n\n /**\n * Extract (and apply?) Position Transform\n * @todo not used\n */\n _getQuantizationTransform(\n dracoAttribute: PointAttribute,\n options: DracoParseOptions\n ): DracoQuantizationTransform | null {\n const {quantizedAttributes = []} = options;\n const attribute_type = dracoAttribute.attribute_type();\n const skip = quantizedAttributes.map((type) => this.decoder[type]).includes(attribute_type);\n if (skip) {\n const transform = new this.draco.AttributeQuantizationTransform();\n try {\n if (transform.InitFromAttribute(dracoAttribute)) {\n return {\n quantization_bits: transform.quantization_bits(),\n range: transform.range(),\n min_values: new Float32Array([1, 2, 3]).map((i) => transform.min_value(i))\n };\n }\n } finally {\n this.draco.destroy(transform);\n }\n }\n return null;\n }\n\n _getOctahedronTransform(\n dracoAttribute: PointAttribute,\n options: DracoParseOptions\n ): DracoOctahedronTransform | null {\n const {octahedronAttributes = []} = options;\n const attribute_type = dracoAttribute.attribute_type();\n const octahedron = octahedronAttributes\n .map((type) => this.decoder[type])\n .includes(attribute_type);\n if (octahedron) {\n const transform = new this.draco.AttributeQuantizationTransform();\n try {\n if (transform.InitFromAttribute(dracoAttribute)) {\n return {\n quantization_bits: transform.quantization_bits()\n };\n }\n } finally {\n this.draco.destroy(transform);\n }\n }\n return null;\n }\n\n // HELPERS\n}\n\n/**\n * Get draco specific data type by TypedArray constructor type\n * @param attributeType\n * @returns draco specific data type\n */\nfunction getDracoDataType(draco: Draco3D, attributeType: any): draco_DataType {\n switch (attributeType) {\n case Float32Array:\n return draco.DT_FLOAT32;\n case Int8Array:\n return draco.DT_INT8;\n case Int16Array:\n return draco.DT_INT16;\n case Int32Array:\n return draco.DT_INT32;\n case Uint8Array:\n return draco.DT_UINT8;\n case Uint16Array:\n return draco.DT_UINT16;\n case Uint32Array:\n return draco.DT_UINT32;\n default:\n return draco.DT_INVALID;\n }\n}\n\n/**\n * Copy a Draco int32 array into a JS typed array\n */\nfunction getInt32Array(dracoArray: DracoInt32Array): Int32Array {\n const numValues = dracoArray.size();\n const intArray = new Int32Array(numValues);\n for (let i = 0; i < numValues; i++) {\n intArray[i] = dracoArray.GetValue(i);\n }\n return intArray;\n}\n\n/**\n * Copy a Draco int32 array into a JS typed array\n */\nfunction getUint32Array(dracoArray: DracoInt32Array): Int32Array {\n const numValues = dracoArray.size();\n const intArray = new Int32Array(numValues);\n for (let i = 0; i < numValues; i++) {\n intArray[i] = dracoArray.GetValue(i);\n }\n return intArray;\n}\n"],"file":"draco-parser.js"}
@@ -40,7 +40,7 @@ function makeMetadata(metadata) {
40
40
  const metadataMap = new Map();
41
41
 
42
42
  for (const key in metadata) {
43
- metadataMap.set(`${key}.string`, JSON.stringify(metadata[key]));
43
+ metadataMap.set("".concat(key, ".string"), JSON.stringify(metadata[key]));
44
44
  }
45
45
 
46
46
  return metadataMap;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/get-draco-schema.ts"],"names":["deduceMeshField","Schema","getDracoSchema","attributes","loaderData","indices","metadataMap","makeMetadata","metadata","fields","namedLoaderDataAttributes","transformAttributesLoaderData","attributeName","attribute","field","getArrowFieldFromAttribute","push","indicesField","result","key","dracoAttribute","name","undefined","Map","set","JSON","stringify"],"mappings":"AAAA,SAAQA,eAAR,QAA6C,oBAA7C;AACA,SAAQC,MAAR,QAA4B,oBAA5B;AAIA,OAAO,S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SAASP,YAAT,CAAsBC,QAAtB,EAA0F;AACxF,QAAMF,WAAW,GAAG,IAAIiB,GAAJ,EAApB;;AACA,OAAK,MAAMJ,GAAX,IAAkBX,QAAlB,EAA4B;AAC1BF,IAAAA,WAAW,CAACkB,GAAZ,CAAiB,GAAEL,GAAI,SAAvB,EAAiCM,IAAI,CAACC,SAAL,CAAelB,QAAQ,CAACW,GAAD,CAAvB,CAAjC;AACD;;AACD,SAAOb,WAAP;AACD","sourcesContent":["import {deduceMeshField, MeshAttribute} from '@loaders.gl/schema';\nimport {Schema, Field} from '@loaders.gl/schema';\nimport type {DracoAttribute, DracoLoaderData, DracoMetadataEntry} from '../draco-types';\n\n/** Extract an arrow-like schema from a Draco mesh */\nexport function getDracoSchema(\n attributes: {[attributeName: string]: MeshAttribute},\n loaderData: DracoLoaderData,\n indices?: MeshAttribute\n): Schema {\n const metadataMap = makeMetadata(loaderData.metadata);\n const fields: Field[] = [];\n const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes);\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const field = getArrowFieldFromAttribute(\n attributeName,\n attribute,\n namedLoaderDataAttributes[attributeName]\n );\n fields.push(field);\n }\n if (indices) {\n const indicesField = getArrowFieldFromAttribute('indices', indices);\n fields.push(indicesField);\n }\n return new Schema(fields, metadataMap);\n}\n\nfunction transformAttributesLoaderData(loaderData: {[key: number]: DracoAttribute}): {\n [attributeName: string]: DracoAttribute;\n} {\n const result: {[attributeName: string]: DracoAttribute} = {};\n for (const key in loaderData) {\n const dracoAttribute = loaderData[key];\n result[dracoAttribute.name || 'undefined'] = dracoAttribute;\n }\n return result;\n}\n\nfunction getArrowFieldFromAttribute(\n attributeName: string,\n attribute: MeshAttribute,\n loaderData?: DracoAttribute\n): Field {\n const metadataMap = loaderData ? makeMetadata(loaderData.metadata) : undefined;\n const field = deduceMeshField(attributeName, attribute, metadataMap);\n return field;\n}\n\nfunction makeMetadata(metadata: {[key: string]: DracoMetadataEntry}): Map<string, string> {\n const metadataMap = new Map();\n for (const key in metadata) {\n metadataMap.set(`${key}.string`, JSON.stringify(metadata[key]));\n }\n return metadataMap;\n}\n"],"file":"get-draco-schema.js"}
1
+ {"version":3,"sources":["../../../../src/lib/utils/get-draco-schema.ts"],"names":["deduceMeshField","Schema","getDracoSchema","attributes","loaderData","indices","metadataMap","makeMetadata","metadata","fields","namedLoaderDataAttributes","transformAttributesLoaderData","attributeName","attribute","field","getArrowFieldFromAttribute","push","indicesField","result","key","dracoAttribute","name","undefined","Map","set","JSON","stringify"],"mappings":"AAAA,SAAQA,eAAR,QAA6C,oBAA7C;AACA,SAAQC,MAAR,QAA4B,oBAA5B;AAIA,OAAO,SAASC,cAAT,CACLC,UADK,EAELC,UAFK,EAGLC,OAHK,EAIG;AACR,QAAMC,WAAW,GAAGC,YAAY,CAACH,UAAU,CAACI,QAAZ,CAAhC;AACA,QAAMC,MAAe,GAAG,EAAxB;AACA,QAAMC,yBAAyB,GAAGC,6BAA6B,CAACP,UAAU,CAACD,UAAZ,CAA/D;;AACA,OAAK,MAAMS,aAAX,IAA4BT,UAA5B,EAAwC;AACtC,UAAMU,SAAS,GAAGV,UAAU,CAACS,aAAD,CAA5B;AACA,UAAME,KAAK,GAAGC,0BAA0B,CACtCH,aADsC,EAEtCC,SAFsC,EAGtCH,yBAAyB,CAACE,aAAD,CAHa,CAAxC;AAKAH,IAAAA,MAAM,CAACO,IAAP,CAAYF,KAAZ;AACD;;AACD,MAAIT,OAAJ,EAAa;AACX,UAAMY,YAAY,GAAGF,0BAA0B,CAAC,SAAD,EAAYV,OAAZ,CAA/C;AACAI,IAAAA,MAAM,CAACO,IAAP,CAAYC,YAAZ;AACD;;AACD,SAAO,IAAIhB,MAAJ,CAAWQ,MAAX,EAAmBH,WAAnB,CAAP;AACD;;AAED,SAASK,6BAAT,CAAuCP,UAAvC,EAEE;AACA,QAAMc,MAAiD,GAAG,EAA1D;;AACA,OAAK,MAAMC,GAAX,IAAkBf,UAAlB,EAA8B;AAC5B,UAAMgB,cAAc,GAAGhB,UAAU,CAACe,GAAD,CAAjC;AACAD,IAAAA,MAAM,CAACE,cAAc,CAACC,IAAf,IAAuB,WAAxB,CAAN,GAA6CD,cAA7C;AACD;;AACD,SAAOF,MAAP;AACD;;AAED,SAASH,0BAAT,CACEH,aADF,EAEEC,SAFF,EAGET,UAHF,EAIS;AACP,QAAME,WAAW,GAAGF,UAAU,GAAGG,YAAY,CAACH,UAAU,CAACI,QAAZ,CAAf,GAAuCc,SAArE;AACA,QAAMR,KAAK,GAAGd,eAAe,CAACY,aAAD,EAAgBC,SAAhB,EAA2BP,WAA3B,CAA7B;AACA,SAAOQ,KAAP;AACD;;AAED,SAASP,YAAT,CAAsBC,QAAtB,EAA0F;AACxF,QAAMF,WAAW,GAAG,IAAIiB,GAAJ,EAApB;;AACA,OAAK,MAAMJ,GAAX,IAAkBX,QAAlB,EAA4B;AAC1BF,IAAAA,WAAW,CAACkB,GAAZ,WAAmBL,GAAnB,cAAiCM,IAAI,CAACC,SAAL,CAAelB,QAAQ,CAACW,GAAD,CAAvB,CAAjC;AACD;;AACD,SAAOb,WAAP;AACD","sourcesContent":["import {deduceMeshField, MeshAttribute} from '@loaders.gl/schema';\nimport {Schema, Field} from '@loaders.gl/schema';\nimport type {DracoAttribute, DracoLoaderData, DracoMetadataEntry} from '../draco-types';\n\n/** Extract an arrow-like schema from a Draco mesh */\nexport function getDracoSchema(\n attributes: {[attributeName: string]: MeshAttribute},\n loaderData: DracoLoaderData,\n indices?: MeshAttribute\n): Schema {\n const metadataMap = makeMetadata(loaderData.metadata);\n const fields: Field[] = [];\n const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes);\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const field = getArrowFieldFromAttribute(\n attributeName,\n attribute,\n namedLoaderDataAttributes[attributeName]\n );\n fields.push(field);\n }\n if (indices) {\n const indicesField = getArrowFieldFromAttribute('indices', indices);\n fields.push(indicesField);\n }\n return new Schema(fields, metadataMap);\n}\n\nfunction transformAttributesLoaderData(loaderData: {[key: number]: DracoAttribute}): {\n [attributeName: string]: DracoAttribute;\n} {\n const result: {[attributeName: string]: DracoAttribute} = {};\n for (const key in loaderData) {\n const dracoAttribute = loaderData[key];\n result[dracoAttribute.name || 'undefined'] = dracoAttribute;\n }\n return result;\n}\n\nfunction getArrowFieldFromAttribute(\n attributeName: string,\n attribute: MeshAttribute,\n loaderData?: DracoAttribute\n): Field {\n const metadataMap = loaderData ? makeMetadata(loaderData.metadata) : undefined;\n const field = deduceMeshField(attributeName, attribute, metadataMap);\n return field;\n}\n\nfunction makeMetadata(metadata: {[key: string]: DracoMetadataEntry}): Map<string, string> {\n const metadataMap = new Map();\n for (const key in metadata) {\n metadataMap.set(`${key}.string`, JSON.stringify(metadata[key]));\n }\n return metadataMap;\n}\n"],"file":"get-draco-schema.js"}
@@ -1,2 +1,2 @@
1
- export const VERSION = typeof "3.1.0-alpha.4" !== 'undefined' ? "3.1.0-alpha.4" : 'latest';
1
+ export const VERSION = typeof "3.1.0-alpha.5" !== 'undefined' ? "3.1.0-alpha.5" : 'latest';
2
2
  //# sourceMappingURL=version.js.map
@@ -0,0 +1,28 @@
1
+ import type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ import type { DracoMesh, DracoLoaderData } from './lib/draco-types';
3
+ import type { DracoLoaderOptions } from './draco-loader';
4
+ import { DracoLoader as DracoWorkerLoader } from './draco-loader';
5
+ export type { DracoMesh, DracoLoaderData };
6
+ export type { DracoWriterOptions } from './draco-writer';
7
+ export { DracoWriter } from './draco-writer';
8
+ export type { DracoLoaderOptions };
9
+ export { DracoWorkerLoader };
10
+ /**
11
+ * Loader for Draco3D compressed geometries
12
+ */
13
+ export declare const DracoLoader: {
14
+ parse: typeof parse;
15
+ name: string;
16
+ id: string;
17
+ module: string;
18
+ shapes: string[];
19
+ version: any;
20
+ worker: boolean;
21
+ extensions: string[];
22
+ mimeTypes: string[];
23
+ binary: boolean;
24
+ tests: string[];
25
+ options: DracoLoaderOptions;
26
+ };
27
+ declare function parse(arrayBuffer: ArrayBuffer, options?: DracoLoaderOptions): Promise<DracoMesh>;
28
+ export declare const _TypecheckDracoLoader: LoaderWithParser;
@@ -0,0 +1,106 @@
1
+ import type { Draco3D, Encoder, Mesh, MeshBuilder, PointCloud, Metadata, MetadataBuilder, draco_GeometryAttribute_Type } from '../draco3d/draco3d-types';
2
+ import type { TypedArray } from '@loaders.gl/schema';
3
+ import type { DracoMesh } from './draco-types';
4
+ export declare type DracoBuildOptions = {
5
+ pointcloud?: boolean;
6
+ metadata?: {
7
+ [key: string]: string;
8
+ };
9
+ attributesMetadata?: {};
10
+ log?: any;
11
+ speed?: [number, number];
12
+ method?: string;
13
+ quantization?: {
14
+ [attributeName: string]: number;
15
+ };
16
+ };
17
+ export default class DracoBuilder {
18
+ draco: Draco3D;
19
+ dracoEncoder: Encoder;
20
+ dracoMeshBuilder: MeshBuilder;
21
+ dracoMetadataBuilder: MetadataBuilder;
22
+ log: any;
23
+ constructor(draco: Draco3D);
24
+ destroy(): void;
25
+ destroyEncodedObject(object: any): void;
26
+ /**
27
+ * Encode mesh or point cloud
28
+ * @param mesh =({})
29
+ * @param options
30
+ */
31
+ encodeSync(mesh: DracoMesh, options?: DracoBuildOptions): ArrayBuffer;
32
+ _getAttributesFromMesh(mesh: DracoMesh): {
33
+ attributes: {
34
+ [attributeName: string]: import("@loaders.gl/schema").MeshAttribute;
35
+ };
36
+ indices?: import("@loaders.gl/schema").MeshAttribute | undefined;
37
+ topology: "triangle-list" | "triangle-strip" | "point-list";
38
+ mode: number;
39
+ loader: "draco";
40
+ loaderData: {
41
+ [key: string]: any;
42
+ } & import("./draco-types").DracoLoaderData;
43
+ header?: {
44
+ vertexCount: number;
45
+ boundingBox?: [number[], number[]] | undefined;
46
+ } | undefined;
47
+ schema: import("@loaders.gl/schema").Schema;
48
+ };
49
+ _encodePointCloud(pointcloud: DracoMesh, options: DracoBuildOptions): ArrayBuffer;
50
+ _encodeMesh(mesh: DracoMesh, options: DracoBuildOptions): ArrayBuffer;
51
+ /**
52
+ * Set encoding options.
53
+ * @param {{speed?: any; method?: any; quantization?: any;}} options
54
+ */
55
+ _setOptions(options: DracoBuildOptions): void;
56
+ /**
57
+ * @param {Mesh} dracoMesh
58
+ * @param {object} attributes
59
+ * @returns {Mesh}
60
+ */
61
+ _createDracoMesh(dracoMesh: Mesh, attributes: any, options: DracoBuildOptions): Mesh;
62
+ /**
63
+ * @param {} dracoPointCloud
64
+ * @param {object} attributes
65
+ */
66
+ _createDracoPointCloud(dracoPointCloud: PointCloud, attributes: object, options: DracoBuildOptions): PointCloud;
67
+ /**
68
+ * @param mesh
69
+ * @param attributeName
70
+ * @param attribute
71
+ * @param vertexCount
72
+ */
73
+ _addAttributeToMesh(mesh: PointCloud, attributeName: string, attribute: TypedArray, vertexCount: number): any;
74
+ /**
75
+ * DRACO can compress attributes of know type better
76
+ * TODO - expose an attribute type map?
77
+ * @param attributeName
78
+ */
79
+ _getDracoAttributeType(attributeName: string): draco_GeometryAttribute_Type | 'indices';
80
+ _getPositionAttribute(attributes: any): any;
81
+ /**
82
+ * Add metadata for the geometry.
83
+ * @param dracoGeometry - WASM Draco Object
84
+ * @param metadata
85
+ */
86
+ _addGeometryMetadata(dracoGeometry: PointCloud, metadata: {
87
+ [key: string]: string;
88
+ }): void;
89
+ /**
90
+ * Add metadata for an attribute to geometry.
91
+ * @param dracoGeometry - WASM Draco Object
92
+ * @param uniqueAttributeId
93
+ * @param metadata
94
+ */
95
+ _addAttributeMetadata(dracoGeometry: PointCloud, uniqueAttributeId: number, metadata: Map<string, string> | {
96
+ [key: string]: string;
97
+ }): void;
98
+ /**
99
+ * Add contents of object or map to a WASM Draco Metadata Object
100
+ * @param dracoMetadata - WASM Draco Object
101
+ * @param metadata
102
+ */
103
+ _populateDracoMetadata(dracoMetadata: Metadata, metadata: Map<string, string> | {
104
+ [key: string]: string;
105
+ }): void;
106
+ }
@@ -0,0 +1,2 @@
1
+ export declare function loadDracoDecoderModule(options: any): Promise<any>;
2
+ export declare function loadDracoEncoderModule(options: any): Promise<any>;
@@ -0,0 +1,136 @@
1
+ import type { TypedArray, MeshAttribute, MeshGeometry } from '@loaders.gl/schema';
2
+ import type { Draco3D, Decoder, Mesh, PointCloud, PointAttribute, Metadata, MetadataQuerier } from '../draco3d/draco3d-types';
3
+ import type { DracoMesh, DracoLoaderData, DracoAttribute, DracoMetadataEntry, DracoQuantizationTransform, DracoOctahedronTransform } from './draco-types';
4
+ /**
5
+ * @param topology - How triangle indices should be generated (mesh only)
6
+ * @param attributeNameEntry
7
+ * @param extraAttributes
8
+ * @param quantizedAttributes
9
+ * @param octahedronAttributes
10
+ */
11
+ export declare type DracoParseOptions = {
12
+ topology?: 'triangle-list' | 'triangle-strip';
13
+ attributeNameEntry?: string;
14
+ extraAttributes?: {
15
+ [uniqueId: string]: number;
16
+ };
17
+ quantizedAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];
18
+ octahedronAttributes?: ('POSITION' | 'NORMAL' | 'COLOR' | 'TEX_COORD' | 'GENERIC')[];
19
+ };
20
+ export default class DracoParser {
21
+ draco: Draco3D;
22
+ decoder: Decoder;
23
+ metadataQuerier: MetadataQuerier;
24
+ constructor(draco: Draco3D);
25
+ /**
26
+ * Destroy draco resources
27
+ */
28
+ destroy(): void;
29
+ /**
30
+ * NOTE: caller must call `destroyGeometry` on the return value after using it
31
+ * @param arrayBuffer
32
+ * @param options
33
+ */
34
+ parseSync(arrayBuffer: ArrayBuffer, options?: DracoParseOptions): DracoMesh;
35
+ /**
36
+ * Extract
37
+ * @param dracoGeometry
38
+ * @param geometry_type
39
+ * @param options
40
+ * @returns
41
+ */
42
+ _getDracoLoaderData(dracoGeometry: Mesh | PointCloud, geometry_type: any, options: DracoParseOptions): DracoLoaderData;
43
+ /**
44
+ * Extract all draco provided information and metadata for each attribute
45
+ * @param dracoGeometry
46
+ * @param options
47
+ * @returns
48
+ */
49
+ _getDracoAttributes(dracoGeometry: Mesh | PointCloud, options: DracoParseOptions): {
50
+ [unique_id: number]: DracoAttribute;
51
+ };
52
+ /**
53
+ * Get standard loaders.gl mesh category data
54
+ * Extracts the geometry from draco
55
+ * @param dracoGeometry
56
+ * @param options
57
+ */
58
+ _getMeshData(dracoGeometry: Mesh | PointCloud, loaderData: DracoLoaderData, options: DracoParseOptions): MeshGeometry;
59
+ _getMeshAttributes(loaderData: DracoLoaderData, dracoGeometry: Mesh | PointCloud, options: DracoParseOptions): {
60
+ [attributeName: string]: MeshAttribute;
61
+ };
62
+ /**
63
+ * For meshes, we need indices to define the faces.
64
+ * @param dracoGeometry
65
+ */
66
+ _getTriangleListIndices(dracoGeometry: Mesh): Uint32Array;
67
+ /**
68
+ * For meshes, we need indices to define the faces.
69
+ * @param dracoGeometry
70
+ */
71
+ _getTriangleStripIndices(dracoGeometry: Mesh): Int32Array;
72
+ /**
73
+ *
74
+ * @param dracoGeometry
75
+ * @param dracoAttribute
76
+ * @param attributeName
77
+ */
78
+ _getAttributeValues(dracoGeometry: Mesh | PointCloud, attribute: DracoAttribute): {
79
+ value: TypedArray;
80
+ size: number;
81
+ };
82
+ /**
83
+ * DRACO does not store attribute names - We need to deduce an attribute name
84
+ * for each attribute
85
+ _getAttributeNames(
86
+ dracoGeometry: Mesh | PointCloud,
87
+ options: DracoParseOptions
88
+ ): {[unique_id: number]: string} {
89
+ const attributeNames: {[unique_id: number]: string} = {};
90
+ for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
91
+ const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
92
+ const attributeName = this._deduceAttributeName(dracoAttribute, options);
93
+ attributeNames[attributeName] = attributeName;
94
+ }
95
+ return attributeNames;
96
+ }
97
+ */
98
+ /**
99
+ * Deduce an attribute name.
100
+ * @note DRACO does not save attribute names, just general type (POSITION, COLOR)
101
+ * to help optimize compression. We generate GLTF compatible names for the Draco-recognized
102
+ * types
103
+ * @param attributeData
104
+ */
105
+ _deduceAttributeName(attribute: DracoAttribute, options: DracoParseOptions): string;
106
+ /** Get top level metadata */
107
+ _getTopLevelMetadata(dracoGeometry: Mesh | PointCloud): {
108
+ [entry: string]: DracoMetadataEntry;
109
+ };
110
+ /** Get per attribute metadata */
111
+ _getAttributeMetadata(dracoGeometry: Mesh | PointCloud, attributeId: number): {
112
+ [entry: string]: DracoMetadataEntry;
113
+ };
114
+ /**
115
+ * Extract metadata field values
116
+ * @param dracoMetadata
117
+ * @returns
118
+ */
119
+ _getDracoMetadata(dracoMetadata: Metadata): {
120
+ [entry: string]: DracoMetadataEntry;
121
+ };
122
+ /**
123
+ * Extracts possible values for one metadata entry by name
124
+ * @param dracoMetadata
125
+ * @param entryName
126
+ */
127
+ _getDracoMetadataField(dracoMetadata: Metadata, entryName: string): DracoMetadataEntry;
128
+ /** Skip transforms for specific attribute types */
129
+ _disableAttributeTransforms(options: DracoParseOptions): void;
130
+ /**
131
+ * Extract (and apply?) Position Transform
132
+ * @todo not used
133
+ */
134
+ _getQuantizationTransform(dracoAttribute: PointAttribute, options: DracoParseOptions): DracoQuantizationTransform | null;
135
+ _getOctahedronTransform(dracoAttribute: PointAttribute, options: DracoParseOptions): DracoOctahedronTransform | null;
136
+ }
@@ -0,0 +1,58 @@
1
+ import { Mesh } from '@loaders.gl/schema';
2
+ export declare type DracoMetadataEntry = {
3
+ int: number;
4
+ string: string;
5
+ double: number;
6
+ intArray: Int32Array;
7
+ };
8
+ /** For attributes that have not been fully decompressed */
9
+ export declare type DracoQuantizationTransform = {
10
+ quantization_bits?: number;
11
+ range?: number;
12
+ min_values?: Float32Array;
13
+ };
14
+ /** For attributes that have not been fully decompressed */
15
+ export declare type DracoOctahedronTransform = {
16
+ quantization_bits?: number;
17
+ };
18
+ /** Draco attribute fields */
19
+ export declare type DracoAttribute = {
20
+ unique_id: number;
21
+ num_components: number;
22
+ attribute_type: number;
23
+ data_type: number;
24
+ byte_offset: number;
25
+ byte_stride: number;
26
+ normalized: boolean;
27
+ name?: string;
28
+ quantization_transform?: DracoQuantizationTransform;
29
+ octahedron_transform?: DracoOctahedronTransform;
30
+ metadata: {
31
+ [key: string]: DracoMetadataEntry;
32
+ };
33
+ attribute_index: number;
34
+ };
35
+ /**
36
+ * Draco format specific data
37
+ * The `data.loaderData` field will have this layout when `data.loader === 'draco'`.
38
+ * @todo Metadata should also be available in normalized form in a standard `Schema`.
39
+ */
40
+ export declare type DracoLoaderData = {
41
+ geometry_type: number;
42
+ num_attributes: number;
43
+ num_points: number;
44
+ num_faces: number;
45
+ metadata: {
46
+ [entry: string]: DracoMetadataEntry;
47
+ };
48
+ attributes: {
49
+ [unique_id: number]: DracoAttribute;
50
+ };
51
+ };
52
+ /**
53
+ * loaders.gl Mesh with Draco specific data
54
+ */
55
+ export declare type DracoMesh = Mesh & {
56
+ loader: 'draco';
57
+ loaderData: DracoLoaderData;
58
+ };
@@ -0,0 +1,7 @@
1
+ import { MeshAttribute } from '@loaders.gl/schema';
2
+ import { Schema } from '@loaders.gl/schema';
3
+ import type { DracoLoaderData } from '../draco-types';
4
+ /** Extract an arrow-like schema from a Draco mesh */
5
+ export declare function getDracoSchema(attributes: {
6
+ [attributeName: string]: MeshAttribute;
7
+ }, loaderData: DracoLoaderData, indices?: MeshAttribute): Schema;
@@ -0,0 +1 @@
1
+ export declare const VERSION: any;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/draco",
3
- "version": "3.1.0-alpha.4",
3
+ "version": "3.1.0-alpha.5",
4
4
  "description": "Framework-independent loader and writer for Draco compressed meshes and point clouds",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -19,7 +19,7 @@
19
19
  "draco3d",
20
20
  "draco"
21
21
  ],
22
- "types": "src/index.ts",
22
+ "types": "dist/index.d.ts",
23
23
  "main": "dist/es5/index.js",
24
24
  "module": "dist/esm/index.js",
25
25
  "sideEffects": false,
@@ -33,15 +33,16 @@
33
33
  ],
34
34
  "scripts": {
35
35
  "pre-build": "npm run build-bundle && npm run build-worker",
36
+ "post-build": "tsc",
36
37
  "build-bundle": "webpack --config ../../scripts/webpack/bundle.js",
37
38
  "build-worker": "webpack --entry ./src/workers/draco-worker.ts --output ./dist/draco-worker.js --config ../../scripts/webpack/worker.js"
38
39
  },
39
40
  "dependencies": {
40
41
  "@babel/runtime": "^7.3.1",
41
- "@loaders.gl/loader-utils": "3.1.0-alpha.4",
42
- "@loaders.gl/schema": "3.1.0-alpha.4",
43
- "@loaders.gl/worker-utils": "3.1.0-alpha.4",
42
+ "@loaders.gl/loader-utils": "3.1.0-alpha.5",
43
+ "@loaders.gl/schema": "3.1.0-alpha.5",
44
+ "@loaders.gl/worker-utils": "3.1.0-alpha.5",
44
45
  "draco3d": "1.4.1"
45
46
  },
46
- "gitHead": "e309784af37ef9f3640c7733c7851124c72e1fa3"
47
+ "gitHead": "352241dd910a8c6307a235dadbe154ca915b885b"
47
48
  }