@loaders.gl/draco 3.1.0-alpha.3 → 4.0.0-alpha.4

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.
@@ -81,8 +81,7 @@ export default class DracoBuilder {
81
81
  throw new Error('Draco encoding failed.');
82
82
  }
83
83
 
84
- this.log(`DRACO encoded ${dracoPointCloud.num_points()} points
85
- with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);
84
+ this.log("DRACO encoded ".concat(dracoPointCloud.num_points(), " points\n with ").concat(dracoPointCloud.num_attributes(), " attributes into ").concat(encodedLen, " bytes"));
86
85
  return dracoInt8ArrayToArrayBuffer(dracoData);
87
86
  } finally {
88
87
  this.destroyEncodedObject(dracoData);
@@ -110,8 +109,7 @@ export default class DracoBuilder {
110
109
  throw new Error('Draco encoding failed.');
111
110
  }
112
111
 
113
- this.log(`DRACO encoded ${dracoMesh.num_points()} points
114
- with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);
112
+ this.log("DRACO encoded ".concat(dracoMesh.num_points(), " points\n with ").concat(dracoMesh.num_attributes(), " attributes into ").concat(encodedLen, " bytes"));
115
113
  return dracoInt8ArrayToArrayBuffer(dracoData);
116
114
  } finally {
117
115
  this.destroyEncodedObject(dracoData);
@@ -215,12 +213,12 @@ export default class DracoBuilder {
215
213
 
216
214
  if (type === 'indices') {
217
215
  const numFaces = attribute.length / 3;
218
- this.log(`Adding attribute ${attributeName}, size ${numFaces}`);
216
+ this.log("Adding attribute ".concat(attributeName, ", size ").concat(numFaces));
219
217
  this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);
220
218
  return -1;
221
219
  }
222
220
 
223
- this.log(`Adding attribute ${attributeName}, size ${size}`);
221
+ this.log("Adding attribute ".concat(attributeName, ", size ").concat(size));
224
222
  const builder = this.dracoMeshBuilder;
225
223
  const {
226
224
  buffer
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/draco-builder.ts"],"names":["GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","noop","DracoBuilder","constructor","draco","dracoEncoder","Encoder","dracoMeshBuilder","MeshBuilder","dracoMetadataBuilder","MetadataBuilder","destroy","destroyEncodedObject","object","encodeSync","mesh","options","log","_setOptions","pointcloud","_encodePointCloud","_encodeMesh","_getAttributesFromMesh","attributes","indices","dracoPointCloud","PointCloud","metadata","_addGeometryMetadata","_createDracoPointCloud","dracoData","DracoInt8Array","encodedLen","EncodePointCloudToDracoBuffer","Error","num_points","num_attributes","dracoInt8ArrayToArrayBuffer","dracoMesh","Mesh","_createDracoMesh","EncodeMeshToDracoBuffer","SetSpeedOptions","speed","dracoMethod","method","SetEncodingMethod","attribute","quantization","bits","dracoPosition","SetAttributeQuantization","optionalMetadata","attributesMetadata","positions","_getPositionAttribute","vertexCount","length","attributeName","uniqueId","_addAttributeToMesh","_addAttributeMetadata","name","error","ArrayBuffer","isView","type","_getDracoAttributeType","size","numFaces","AddFacesToMesh","builder","buffer","Int8Array","AddInt8Attribute","Int16Array","AddInt16Attribute","Int32Array","AddInt32Attribute","Uint8Array","Uint8ClampedArray","AddUInt8Attribute","Uint16Array","AddUInt16Attribute","Uint32Array","AddUInt32Attribute","Float32Array","AddFloatAttribute","toLowerCase","COLOR","TEX_COORD","GENERIC","dracoType","dracoGeometry","dracoMetadata","Metadata","_populateDracoMetadata","AddMetadata","uniqueAttributeId","dracoAttributeMetadata","SetMetadataForAttribute","key","value","getEntries","Math","trunc","AddIntEntry","AddDoubleEntry","AddIntEntryArray","AddStringEntry","byteLength","outputBuffer","outputData","i","GetValue","container","hasEntriesFunc","entries","hasOwnProperty","Object"],"mappings":";AA8BA,MAAMA,gCAAgC,GAAG;AACvCC,EAAAA,QAAQ,EAAE,UAD6B;AAEvCC,EAAAA,MAAM,EAAE,QAF+B;AAGvCC,EAAAA,OAAO,EAAE,OAH8B;AAIvCC,EAAAA,UAAU,EAAE;AAJ2B,CAA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CAA0BoG,cAA1B,CAAyCf,aAAzC,EAAwDO,GAAxD,EAA6DC,KAA7D;AAfJ;AAiBD;AACF;;AAlY+B;;AA2YlC,SAASjE,2BAAT,CAAqCP,SAArC,EAAgE;AAC9D,QAAMgF,UAAU,GAAGhF,SAAS,CAACsC,IAAV,EAAnB;AACA,QAAM2C,YAAY,GAAG,IAAI/C,WAAJ,CAAgB8C,UAAhB,CAArB;AACA,QAAME,UAAU,GAAG,IAAIvC,SAAJ,CAAcsC,YAAd,CAAnB;;AACA,OAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,UAApB,EAAgC,EAAEG,CAAlC,EAAqC;AACnCD,IAAAA,UAAU,CAACC,CAAD,CAAV,GAAgBnF,SAAS,CAACoF,QAAV,CAAmBD,CAAnB,CAAhB;AACD;;AACD,SAAOF,YAAP;AACD;;AAGD,SAASR,UAAT,CAAoBY,SAApB,EAA+B;AAC7B,QAAMC,cAAc,GAAGD,SAAS,CAACE,OAAV,IAAqB,CAACF,SAAS,CAACG,cAAV,CAAyB,SAAzB,CAA7C;AACA,SAAOF,cAAc,GAAGD,SAAS,CAACE,OAAV,EAAH,GAAyBE,MAAM,CAACF,OAAP,CAAeF,SAAf,CAA9C;AACD","sourcesContent":["/* eslint-disable camelcase */\n// This code is inspired by example code in the DRACO repository\nimport type {\n Draco3D,\n DracoInt8Array,\n Encoder,\n Mesh,\n MeshBuilder,\n PointCloud,\n Metadata,\n MetadataBuilder,\n draco_GeometryAttribute_Type\n} from '../draco3d/draco3d-types';\n\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {DracoMesh} from './draco-types';\n\nexport type DracoBuildOptions = {\n pointcloud?: boolean;\n metadata?: {[key: string]: string};\n attributesMetadata?: {};\n log?: any;\n\n // draco encoding options\n speed?: [number, number];\n method?: string;\n quantization?: {[attributeName: string]: number};\n};\n\n// Native Draco attribute names to GLTF attribute names.\nconst GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {\n POSITION: 'POSITION',\n NORMAL: 'NORMAL',\n COLOR_0: 'COLOR',\n TEXCOORD_0: 'TEX_COORD'\n};\n\nconst noop = () => {};\n\nexport default class DracoBuilder {\n draco: Draco3D;\n dracoEncoder: Encoder;\n dracoMeshBuilder: MeshBuilder;\n dracoMetadataBuilder: MetadataBuilder;\n log: any;\n\n // draco - the draco decoder, either import `draco3d` or load dynamically\n constructor(draco: Draco3D) {\n this.draco = draco;\n this.dracoEncoder = new this.draco.Encoder();\n this.dracoMeshBuilder = new this.draco.MeshBuilder();\n this.dracoMetadataBuilder = new this.draco.MetadataBuilder();\n }\n\n destroy(): void {\n this.destroyEncodedObject(this.dracoMeshBuilder);\n this.destroyEncodedObject(this.dracoEncoder);\n this.destroyEncodedObject(this.dracoMetadataBuilder);\n // @ts-ignore\n this.dracoMeshBuilder = null;\n // @ts-ignore\n this.dracoEncoder = null;\n // @ts-ignore\n this.draco = null;\n }\n\n // TBD - when does this need to be called?\n destroyEncodedObject(object): void {\n if (object) {\n this.draco.destroy(object);\n }\n }\n\n /**\n * Encode mesh or point cloud\n * @param mesh =({})\n * @param options\n */\n encodeSync(mesh: DracoMesh, options: DracoBuildOptions = {}): ArrayBuffer {\n this.log = noop; // TODO\n this._setOptions(options);\n\n return options.pointcloud\n ? this._encodePointCloud(mesh, options)\n : this._encodeMesh(mesh, options);\n }\n\n // PRIVATE\n\n _getAttributesFromMesh(mesh: DracoMesh) {\n // TODO - Change the encodePointCloud interface instead?\n const attributes = {...mesh, ...mesh.attributes};\n // Fold indices into the attributes\n if (mesh.indices) {\n attributes.indices = mesh.indices;\n }\n return attributes;\n }\n\n _encodePointCloud(pointcloud: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoPointCloud = new this.draco.PointCloud();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoPointCloud, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(pointcloud);\n\n // Build a `DracoPointCloud` from the input data\n this._createDracoPointCloud(dracoPointCloud, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(\n dracoPointCloud,\n false,\n dracoData\n );\n\n if (!(encodedLen > 0)) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoPointCloud.num_points()} points\n with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoPointCloud);\n }\n }\n\n _encodeMesh(mesh: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoMesh = new this.draco.Mesh();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoMesh, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(mesh);\n\n // Build a `DracoMesh` from the input data\n this._createDracoMesh(dracoMesh, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);\n if (encodedLen <= 0) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoMesh.num_points()} points\n with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoMesh);\n }\n }\n\n /**\n * Set encoding options.\n * @param {{speed?: any; method?: any; quantization?: any;}} options\n */\n _setOptions(options: DracoBuildOptions): void {\n if ('speed' in options) {\n // @ts-ignore\n this.dracoEncoder.SetSpeedOptions(...options.speed);\n }\n if ('method' in options) {\n const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];\n // assert(dracoMethod)\n this.dracoEncoder.SetEncodingMethod(dracoMethod);\n }\n if ('quantization' in options) {\n for (const attribute in options.quantization) {\n const bits = options.quantization[attribute];\n const dracoPosition = this.draco[attribute];\n this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);\n }\n }\n }\n\n /**\n * @param {Mesh} dracoMesh\n * @param {object} attributes\n * @returns {Mesh}\n */\n _createDracoMesh(dracoMesh: Mesh, attributes, options: DracoBuildOptions): Mesh {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);\n\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoMesh, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoMesh);\n throw error;\n }\n\n return dracoMesh;\n }\n\n /**\n * @param {} dracoPointCloud\n * @param {object} attributes\n */\n _createDracoPointCloud(\n dracoPointCloud: PointCloud,\n attributes: object,\n options: DracoBuildOptions\n ): PointCloud {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(\n dracoPointCloud,\n attributeName,\n attribute,\n vertexCount\n );\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoPointCloud, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoPointCloud);\n throw error;\n }\n\n return dracoPointCloud;\n }\n\n /**\n * @param mesh\n * @param attributeName\n * @param attribute\n * @param vertexCount\n */\n _addAttributeToMesh(\n mesh: PointCloud,\n attributeName: string,\n attribute: TypedArray,\n vertexCount: number\n ) {\n if (!ArrayBuffer.isView(attribute)) {\n return -1;\n }\n\n const type = this._getDracoAttributeType(attributeName);\n // @ts-ignore TODO/fix types\n const size = attribute.length / vertexCount;\n\n if (type === 'indices') {\n // @ts-ignore TODO/fix types\n const numFaces = attribute.length / 3;\n this.log(`Adding attribute ${attributeName}, size ${numFaces}`);\n\n // @ts-ignore assumes mesh is a Mesh, not a point cloud\n this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);\n return -1;\n }\n\n this.log(`Adding attribute ${attributeName}, size ${size}`);\n\n const builder = this.dracoMeshBuilder;\n const {buffer} = attribute;\n\n switch (attribute.constructor) {\n case Int8Array:\n return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));\n\n case Int16Array:\n return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));\n\n case Int32Array:\n return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));\n case Uint8Array:\n case Uint8ClampedArray:\n return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));\n\n case Uint16Array:\n return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));\n\n case Uint32Array:\n return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));\n\n case Float32Array:\n default:\n return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));\n }\n }\n\n /**\n * DRACO can compress attributes of know type better\n * TODO - expose an attribute type map?\n * @param attributeName\n */\n _getDracoAttributeType(attributeName: string): draco_GeometryAttribute_Type | 'indices' {\n switch (attributeName.toLowerCase()) {\n case 'indices':\n return 'indices';\n case 'position':\n case 'positions':\n case 'vertices':\n return this.draco.POSITION;\n case 'normal':\n case 'normals':\n return this.draco.NORMAL;\n case 'color':\n case 'colors':\n return this.draco.COLOR;\n case 'texcoord':\n case 'texcoords':\n return this.draco.TEX_COORD;\n default:\n return this.draco.GENERIC;\n }\n }\n\n _getPositionAttribute(attributes) {\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const dracoType = this._getDracoAttributeType(attributeName);\n if (dracoType === this.draco.POSITION) {\n return attribute;\n }\n }\n return null;\n }\n\n /**\n * Add metadata for the geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param metadata\n */\n _addGeometryMetadata(dracoGeometry: PointCloud, metadata: {[key: string]: string}) {\n const dracoMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoMetadata, metadata);\n this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);\n }\n\n /**\n * Add metadata for an attribute to geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param uniqueAttributeId\n * @param metadata\n */\n _addAttributeMetadata(\n dracoGeometry: PointCloud,\n uniqueAttributeId: number,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n // Note: Draco JS IDL doesn't seem to expose draco.AttributeMetadata, however it seems to\n // create such objects automatically from draco.Metadata object.\n const dracoAttributeMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoAttributeMetadata, metadata);\n // Draco3d doc note: Directly add attribute metadata to geometry.\n // You can do this without explicitly adding |GeometryMetadata| to mesh.\n this.dracoMeshBuilder.SetMetadataForAttribute(\n dracoGeometry,\n uniqueAttributeId,\n dracoAttributeMetadata\n );\n }\n\n /**\n * Add contents of object or map to a WASM Draco Metadata Object\n * @param dracoMetadata - WASM Draco Object\n * @param metadata\n */\n _populateDracoMetadata(\n dracoMetadata: Metadata,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n for (const [key, value] of getEntries(metadata)) {\n switch (typeof value) {\n case 'number':\n if (Math.trunc(value) === value) {\n this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);\n } else {\n this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);\n }\n break;\n case 'object':\n if (value instanceof Int32Array) {\n this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);\n }\n break;\n case 'string':\n default:\n this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);\n }\n }\n }\n}\n\n// HELPER FUNCTIONS\n\n/**\n * Copy encoded data to buffer\n * @param dracoData\n */\nfunction dracoInt8ArrayToArrayBuffer(dracoData: DracoInt8Array) {\n const byteLength = dracoData.size();\n const outputBuffer = new ArrayBuffer(byteLength);\n const outputData = new Int8Array(outputBuffer);\n for (let i = 0; i < byteLength; ++i) {\n outputData[i] = dracoData.GetValue(i);\n }\n return outputBuffer;\n}\n\n/** Enable iteration over either an object or a map */\nfunction getEntries(container) {\n const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');\n return hasEntriesFunc ? container.entries() : Object.entries(container);\n}\n"],"file":"draco-builder.js"}
1
+ {"version":3,"sources":["../../src/lib/draco-builder.ts"],"names":["GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","noop","DracoBuilder","constructor","draco","dracoEncoder","Encoder","dracoMeshBuilder","MeshBuilder","dracoMetadataBuilder","MetadataBuilder","destroy","destroyEncodedObject","object","encodeSync","mesh","options","log","_setOptions","pointcloud","_encodePointCloud","_encodeMesh","_getAttributesFromMesh","attributes","indices","dracoPointCloud","PointCloud","metadata","_addGeometryMetadata","_createDracoPointCloud","dracoData","DracoInt8Array","encodedLen","EncodePointCloudToDracoBuffer","Error","num_points","num_attributes","dracoInt8ArrayToArrayBuffer","dracoMesh","Mesh","_createDracoMesh","EncodeMeshToDracoBuffer","SetSpeedOptions","speed","dracoMethod","method","SetEncodingMethod","attribute","quantization","bits","dracoPosition","SetAttributeQuantization","optionalMetadata","attributesMetadata","positions","_getPositionAttribute","vertexCount","length","attributeName","uniqueId","_addAttributeToMesh","_addAttributeMetadata","name","error","ArrayBuffer","isView","type","_getDracoAttributeType","size","numFaces","AddFacesToMesh","builder","buffer","Int8Array","AddInt8Attribute","Int16Array","AddInt16Attribute","Int32Array","AddInt32Attribute","Uint8Array","Uint8ClampedArray","AddUInt8Attribute","Uint16Array","AddUInt16Attribute","Uint32Array","AddUInt32Attribute","Float32Array","AddFloatAttribute","toLowerCase","COLOR","TEX_COORD","GENERIC","dracoType","dracoGeometry","dracoMetadata","Metadata","_populateDracoMetadata","AddMetadata","uniqueAttributeId","dracoAttributeMetadata","SetMetadataForAttribute","key","value","getEntries","Math","trunc","AddIntEntry","AddDoubleEntry","AddIntEntryArray","AddStringEntry","byteLength","outputBuffer","outputData","i","GetValue","container","hasEntriesFunc","entries","hasOwnProperty","Object"],"mappings":";AA8BA,MAAMA,gCAAgC,GAAG;AACvCC,EAAAA,QAAQ,EAAE,UAD6B;AAEvCC,EAAAA,MAAM,EAAE,QAF+B;AAGvCC,EAAAA,OAAO,EAAE,OAH8B;AAIvCC,EAAAA,UAAU,EAAE;AAJ2B,CAAzC;;AAOA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAEA,eAAe,MAAMC,YAAN,CAAmB;AAQhCC,EAAAA,WAAW,CAACC,KAAD,EAAiB;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAC1B,SAAKA,KAAL,GAAaA,KAAb;AACA,SAAKC,YAAL,GAAoB,IAAI,KAAKD,KAAL,CAAWE,OAAf,EAApB;AACA,SAAKC,gBAAL,GAAwB,IAAI,KAAKH,KAAL,CAAWI,WAAf,EAAxB;AACA,SAAKC,oBAAL,GAA4B,IAAI,KAAKL,KAAL,CAAWM,eAAf,EAA5B;AACD;;AAEDC,EAAAA,OAAO,GAAS;AACd,SAAKC,oBAAL,CAA0B,KAAKL,gBAA/B;AACA,SAAKK,oBAAL,CAA0B,KAAKP,YAA/B;AACA,SAAKO,oBAAL,CAA0B,KAAKH,oBAA/B;AAEA,SAAKF,gBAAL,GAAwB,IAAxB;AAEA,SAAKF,YAAL,GAAoB,IAApB;AAEA,SAAKD,KAAL,GAAa,IAAb;AACD;;AAGDQ,EAAAA,oBAAoB,CAACC,MAAD,EAAe;AACjC,QAAIA,MAAJ,EAAY;AACV,WAAKT,KAAL,CAAW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n// This code is inspired by example code in the DRACO repository\nimport type {\n Draco3D,\n DracoInt8Array,\n Encoder,\n Mesh,\n MeshBuilder,\n PointCloud,\n Metadata,\n MetadataBuilder,\n draco_GeometryAttribute_Type\n} from '../draco3d/draco3d-types';\n\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {DracoMesh} from './draco-types';\n\nexport type DracoBuildOptions = {\n pointcloud?: boolean;\n metadata?: {[key: string]: string};\n attributesMetadata?: {};\n log?: any;\n\n // draco encoding options\n speed?: [number, number];\n method?: string;\n quantization?: {[attributeName: string]: number};\n};\n\n// Native Draco attribute names to GLTF attribute names.\nconst GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {\n POSITION: 'POSITION',\n NORMAL: 'NORMAL',\n COLOR_0: 'COLOR',\n TEXCOORD_0: 'TEX_COORD'\n};\n\nconst noop = () => {};\n\nexport default class DracoBuilder {\n draco: Draco3D;\n dracoEncoder: Encoder;\n dracoMeshBuilder: MeshBuilder;\n dracoMetadataBuilder: MetadataBuilder;\n log: any;\n\n // draco - the draco decoder, either import `draco3d` or load dynamically\n constructor(draco: Draco3D) {\n this.draco = draco;\n this.dracoEncoder = new this.draco.Encoder();\n this.dracoMeshBuilder = new this.draco.MeshBuilder();\n this.dracoMetadataBuilder = new this.draco.MetadataBuilder();\n }\n\n destroy(): void {\n this.destroyEncodedObject(this.dracoMeshBuilder);\n this.destroyEncodedObject(this.dracoEncoder);\n this.destroyEncodedObject(this.dracoMetadataBuilder);\n // @ts-ignore\n this.dracoMeshBuilder = null;\n // @ts-ignore\n this.dracoEncoder = null;\n // @ts-ignore\n this.draco = null;\n }\n\n // TBD - when does this need to be called?\n destroyEncodedObject(object): void {\n if (object) {\n this.draco.destroy(object);\n }\n }\n\n /**\n * Encode mesh or point cloud\n * @param mesh =({})\n * @param options\n */\n encodeSync(mesh: DracoMesh, options: DracoBuildOptions = {}): ArrayBuffer {\n this.log = noop; // TODO\n this._setOptions(options);\n\n return options.pointcloud\n ? this._encodePointCloud(mesh, options)\n : this._encodeMesh(mesh, options);\n }\n\n // PRIVATE\n\n _getAttributesFromMesh(mesh: DracoMesh) {\n // TODO - Change the encodePointCloud interface instead?\n const attributes = {...mesh, ...mesh.attributes};\n // Fold indices into the attributes\n if (mesh.indices) {\n attributes.indices = mesh.indices;\n }\n return attributes;\n }\n\n _encodePointCloud(pointcloud: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoPointCloud = new this.draco.PointCloud();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoPointCloud, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(pointcloud);\n\n // Build a `DracoPointCloud` from the input data\n this._createDracoPointCloud(dracoPointCloud, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(\n dracoPointCloud,\n false,\n dracoData\n );\n\n if (!(encodedLen > 0)) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoPointCloud.num_points()} points\n with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoPointCloud);\n }\n }\n\n _encodeMesh(mesh: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoMesh = new this.draco.Mesh();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoMesh, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(mesh);\n\n // Build a `DracoMesh` from the input data\n this._createDracoMesh(dracoMesh, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);\n if (encodedLen <= 0) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoMesh.num_points()} points\n with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoMesh);\n }\n }\n\n /**\n * Set encoding options.\n * @param {{speed?: any; method?: any; quantization?: any;}} options\n */\n _setOptions(options: DracoBuildOptions): void {\n if ('speed' in options) {\n // @ts-ignore\n this.dracoEncoder.SetSpeedOptions(...options.speed);\n }\n if ('method' in options) {\n const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];\n // assert(dracoMethod)\n this.dracoEncoder.SetEncodingMethod(dracoMethod);\n }\n if ('quantization' in options) {\n for (const attribute in options.quantization) {\n const bits = options.quantization[attribute];\n const dracoPosition = this.draco[attribute];\n this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);\n }\n }\n }\n\n /**\n * @param {Mesh} dracoMesh\n * @param {object} attributes\n * @returns {Mesh}\n */\n _createDracoMesh(dracoMesh: Mesh, attributes, options: DracoBuildOptions): Mesh {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);\n\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoMesh, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoMesh);\n throw error;\n }\n\n return dracoMesh;\n }\n\n /**\n * @param {} dracoPointCloud\n * @param {object} attributes\n */\n _createDracoPointCloud(\n dracoPointCloud: PointCloud,\n attributes: object,\n options: DracoBuildOptions\n ): PointCloud {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(\n dracoPointCloud,\n attributeName,\n attribute,\n vertexCount\n );\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoPointCloud, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoPointCloud);\n throw error;\n }\n\n return dracoPointCloud;\n }\n\n /**\n * @param mesh\n * @param attributeName\n * @param attribute\n * @param vertexCount\n */\n _addAttributeToMesh(\n mesh: PointCloud,\n attributeName: string,\n attribute: TypedArray,\n vertexCount: number\n ) {\n if (!ArrayBuffer.isView(attribute)) {\n return -1;\n }\n\n const type = this._getDracoAttributeType(attributeName);\n // @ts-ignore TODO/fix types\n const size = attribute.length / vertexCount;\n\n if (type === 'indices') {\n // @ts-ignore TODO/fix types\n const numFaces = attribute.length / 3;\n this.log(`Adding attribute ${attributeName}, size ${numFaces}`);\n\n // @ts-ignore assumes mesh is a Mesh, not a point cloud\n this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);\n return -1;\n }\n\n this.log(`Adding attribute ${attributeName}, size ${size}`);\n\n const builder = this.dracoMeshBuilder;\n const {buffer} = attribute;\n\n switch (attribute.constructor) {\n case Int8Array:\n return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));\n\n case Int16Array:\n return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));\n\n case Int32Array:\n return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));\n case Uint8Array:\n case Uint8ClampedArray:\n return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));\n\n case Uint16Array:\n return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));\n\n case Uint32Array:\n return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));\n\n case Float32Array:\n default:\n return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));\n }\n }\n\n /**\n * DRACO can compress attributes of know type better\n * TODO - expose an attribute type map?\n * @param attributeName\n */\n _getDracoAttributeType(attributeName: string): draco_GeometryAttribute_Type | 'indices' {\n switch (attributeName.toLowerCase()) {\n case 'indices':\n return 'indices';\n case 'position':\n case 'positions':\n case 'vertices':\n return this.draco.POSITION;\n case 'normal':\n case 'normals':\n return this.draco.NORMAL;\n case 'color':\n case 'colors':\n return this.draco.COLOR;\n case 'texcoord':\n case 'texcoords':\n return this.draco.TEX_COORD;\n default:\n return this.draco.GENERIC;\n }\n }\n\n _getPositionAttribute(attributes) {\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const dracoType = this._getDracoAttributeType(attributeName);\n if (dracoType === this.draco.POSITION) {\n return attribute;\n }\n }\n return null;\n }\n\n /**\n * Add metadata for the geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param metadata\n */\n _addGeometryMetadata(dracoGeometry: PointCloud, metadata: {[key: string]: string}) {\n const dracoMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoMetadata, metadata);\n this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);\n }\n\n /**\n * Add metadata for an attribute to geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param uniqueAttributeId\n * @param metadata\n */\n _addAttributeMetadata(\n dracoGeometry: PointCloud,\n uniqueAttributeId: number,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n // Note: Draco JS IDL doesn't seem to expose draco.AttributeMetadata, however it seems to\n // create such objects automatically from draco.Metadata object.\n const dracoAttributeMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoAttributeMetadata, metadata);\n // Draco3d doc note: Directly add attribute metadata to geometry.\n // You can do this without explicitly adding |GeometryMetadata| to mesh.\n this.dracoMeshBuilder.SetMetadataForAttribute(\n dracoGeometry,\n uniqueAttributeId,\n dracoAttributeMetadata\n );\n }\n\n /**\n * Add contents of object or map to a WASM Draco Metadata Object\n * @param dracoMetadata - WASM Draco Object\n * @param metadata\n */\n _populateDracoMetadata(\n dracoMetadata: Metadata,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n for (const [key, value] of getEntries(metadata)) {\n switch (typeof value) {\n case 'number':\n if (Math.trunc(value) === value) {\n this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);\n } else {\n this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);\n }\n break;\n case 'object':\n if (value instanceof Int32Array) {\n this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);\n }\n break;\n case 'string':\n default:\n this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);\n }\n }\n }\n}\n\n// HELPER FUNCTIONS\n\n/**\n * Copy encoded data to buffer\n * @param dracoData\n */\nfunction dracoInt8ArrayToArrayBuffer(dracoData: DracoInt8Array) {\n const byteLength = dracoData.size();\n const outputBuffer = new ArrayBuffer(byteLength);\n const outputData = new Int8Array(outputBuffer);\n for (let i = 0; i < byteLength; ++i) {\n outputData[i] = dracoData.GetValue(i);\n }\n return outputBuffer;\n}\n\n/** Enable iteration over either an object or a map */\nfunction getEntries(container) {\n const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');\n return hasEntriesFunc ? container.entries() : Object.entries(container);\n}\n"],"file":"draco-builder.js"}
@@ -1,9 +1,9 @@
1
1
  import { loadLibrary } from '@loaders.gl/worker-utils';
2
2
  const DRACO_VERSION = '1.4.1';
3
- const DRACO_JS_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.js`;
4
- const DRACO_WASM_WRAPPER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_wasm_wrapper.js`;
5
- const DRACO_WASM_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.wasm`;
6
- const DRACO_ENCODER_URL = `https://raw.githubusercontent.com/google/draco/${DRACO_VERSION}/javascript/draco_encoder.js`;
3
+ const DRACO_JS_DECODER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_decoder.js");
4
+ const DRACO_WASM_WRAPPER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_wasm_wrapper.js");
5
+ const DRACO_WASM_DECODER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_decoder.wasm");
6
+ const DRACO_ENCODER_URL = "https://raw.githubusercontent.com/google/draco/".concat(DRACO_VERSION, "/javascript/draco_encoder.js");
7
7
  let loadDecoderPromise;
8
8
  let loadEncoderPromise;
9
9
  export async function loadDracoDecoderModule(options) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/draco-module-loader.ts"],"names":["loadLibrary","DRACO_VERSION","DRACO_JS_DECODER_URL","DRACO_WASM_WRAPPER_URL","DRACO_WASM_DECODER_URL","DRACO_ENCODER_URL","loadDecoderPromise","loadEncoderPromise","loadDracoDecoderModule","options","modules","draco3d","createDecoderModule","then","draco","loadDracoDecoder","loadDracoEncoderModule","createEncoderModule","loadDracoEncoder","DracoDecoderModule","wasmBinary","decoderType","Promise","all","globalThis","initializeDracoDecoder","resolve","onModuleLoaded","DracoEncoderModule"],"mappings":"AAIA,SAAQA,WAAR,QAA0B,0BAA1B;AAEA,MAAMC,aAAa,GAAG,OAAtB;AACA,MAAMC,oBAAoB,GAAI,oDAAmDD,aAAc,mBAA/F;AACA,MAAME,sBAAsB,GAAI,oDAAmDF,aAAc,wBAAjG;AACA,MAAMG,sBAAsB,GAAI,oDAAmDH,aAAc,qBAAjG;AAEA,MAAMI,iBAAiB,GAAI,kDAAiDJ,aAAc,8BAA1F;AAEA,IAAIK,kBAAJ;AACA,IAAIC,kBAAJ;AAEA,OAAO,eAAeC,sBAAf,CAAsCC,OAAtC,EAA+C;AACpD,QAAMC,OAAO,GAAGD,O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,sBAAD,EAAyB,OAAzB,EAAkCM,OAAlC,CADkC,EAEnD,MAAMT,WAAW,CAACI,sBAAD,EAAyB,OAAzB,EAAkCK,OAAlC,CAFkC,CAAZ,CAAzC;AAPJ;;AAcAU,EAAAA,kBAAkB,GAAGA,kBAAkB,IAAIK,UAAU,CAACL,kBAAtD;AACA,SAAO,MAAMM,sBAAsB,CAACN,kBAAD,EAAqBC,UAArB,CAAnC;AACD;;AAED,SAASK,sBAAT,CAAgCN,kBAAhC,EAAoDC,UAApD,EAAgE;AAC9D,QAAMX,OAA2B,GAAG,EAApC;;AACA,MAAIW,UAAJ,EAAgB;AACdX,IAAAA,OAAO,CAACW,UAAR,GAAqBA,UAArB;AACD;;AAED,SAAO,IAAIE,OAAJ,CAAaI,OAAD,IAAa;AAC9BP,IAAAA,kBAAkB,CAAC,EACjB,GAAGV,OADc;AAEjBkB,MAAAA,cAAc,EAAGb,KAAD,IAAWY,OAAO,CAAC;AAACZ,QAAAA;AAAD,OAAD;AAFjB,KAAD,CAAlB;AAID,GALM,CAAP;AAMD;;AAID,eAAeI,gBAAf,CAAgCT,OAAhC,EAAyC;AACvC,MAAImB,kBAAkB,GAAG,MAAM5B,WAAW,CAACK,iBAAD,EAAoB,OAApB,EAA6BI,OAA7B,CAA1C;AAEAmB,EAAAA,kBAAkB,GAAGA,kBAAkB,IAAIJ,UAAU,CAACI,kBAAtD;AAEA,SAAO,IAAIN,OAAJ,CAAaI,OAAD,IAAa;AAC9BE,IAAAA,kBAAkB,CAAC;AACjBD,MAAAA,cAAc,EAAGb,KAAD,IAAWY,OAAO,CAAC;AAACZ,QAAAA;AAAD,OAAD;AADjB,KAAD,CAAlB;AAGD,GAJM,CAAP;AAKD","sourcesContent":["// Dynamic DRACO module loading inspired by THREE.DRACOLoader\n// https://github.com/mrdoob/three.js/blob/398c4f39ebdb8b23eefd4a7a5ec49ec0c96c7462/examples/jsm/loaders/DRACOLoader.js\n// by Don McCurdy / https://www.donmccurdy.com / MIT license\n\nimport {loadLibrary} from '@loaders.gl/worker-utils';\n\nconst DRACO_VERSION = '1.4.1';\nconst DRACO_JS_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.js`;\nconst DRACO_WASM_WRAPPER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_wasm_wrapper.js`;\nconst DRACO_WASM_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.wasm`;\n\nconst DRACO_ENCODER_URL = `https://raw.githubusercontent.com/google/draco/${DRACO_VERSION}/javascript/draco_encoder.js`;\n\nlet loadDecoderPromise;\nlet loadEncoderPromise;\n\nexport async function loadDracoDecoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadDecoderPromise =\n loadDecoderPromise ||\n modules.draco3d.createDecoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);\n }\n return await loadDecoderPromise;\n}\n\nexport async function loadDracoEncoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadEncoderPromise =\n loadEncoderPromise ||\n modules.draco3d.createEncoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);\n }\n return await loadEncoderPromise;\n}\n\n// DRACO DECODER LOADING\n\nasync function loadDracoDecoder(options) {\n let DracoDecoderModule;\n let wasmBinary;\n switch (options.draco && options.draco.decoderType) {\n case 'js':\n DracoDecoderModule = await loadLibrary(DRACO_JS_DECODER_URL, 'draco', options);\n break;\n\n case 'wasm':\n default:\n [DracoDecoderModule, wasmBinary] = await Promise.all([\n await loadLibrary(DRACO_WASM_WRAPPER_URL, 'draco', options),\n await loadLibrary(DRACO_WASM_DECODER_URL, 'draco', options)\n ]);\n }\n // Depends on how import happened...\n // @ts-ignore\n DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;\n return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);\n}\n\nfunction initializeDracoDecoder(DracoDecoderModule, wasmBinary) {\n const options: {wasmBinary?: any} = {};\n if (wasmBinary) {\n options.wasmBinary = wasmBinary;\n }\n\n return new Promise((resolve) => {\n DracoDecoderModule({\n ...options,\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n\n// ENCODER\n\nasync function loadDracoEncoder(options) {\n let DracoEncoderModule = await loadLibrary(DRACO_ENCODER_URL, 'draco', options);\n // @ts-ignore\n DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;\n\n return new Promise((resolve) => {\n DracoEncoderModule({\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n"],"file":"draco-module-loader.js"}
1
+ {"version":3,"sources":["../../src/lib/draco-module-loader.ts"],"names":["loadLibrary","DRACO_VERSION","DRACO_JS_DECODER_URL","DRACO_WASM_WRAPPER_URL","DRACO_WASM_DECODER_URL","DRACO_ENCODER_URL","loadDecoderPromise","loadEncoderPromise","loadDracoDecoderModule","options","modules","draco3d","createDecoderModule","then","draco","loadDracoDecoder","loadDracoEncoderModule","createEncoderModule","loadDracoEncoder","DracoDecoderModule","wasmBinary","decoderType","Promise","all","globalThis","initializeDracoDecoder","resolve","onModuleLoaded","DracoEncoderModule"],"mappings":"AAIA,SAAQA,WAAR,QAA0B,0BAA1B;AAEA,MAAMC,aAAa,GAAG,OAAtB;AACA,MAAMC,oBAAoB,8DAAuDD,aAAvD,sBAA1B;AACA,MAAME,sBAAsB,8DAAuDF,aAAvD,2BAA5B;AACA,MAAMG,sBAAsB,8DAAuDH,aAAvD,wBAA5B;AAEA,MAAMI,iBAAiB,4DAAqDJ,aAArD,iCAAvB;AAEA,IAAIK,kBAAJ;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39ebdb8b23eefd4a7a5ec49ec0c96c7462/examples/jsm/loaders/DRACOLoader.js\n// by Don McCurdy / https://www.donmccurdy.com / MIT license\n\nimport {loadLibrary} from '@loaders.gl/worker-utils';\n\nconst DRACO_VERSION = '1.4.1';\nconst DRACO_JS_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.js`;\nconst DRACO_WASM_WRAPPER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_wasm_wrapper.js`;\nconst DRACO_WASM_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_VERSION}/draco_decoder.wasm`;\n\nconst DRACO_ENCODER_URL = `https://raw.githubusercontent.com/google/draco/${DRACO_VERSION}/javascript/draco_encoder.js`;\n\nlet loadDecoderPromise;\nlet loadEncoderPromise;\n\nexport async function loadDracoDecoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadDecoderPromise =\n loadDecoderPromise ||\n modules.draco3d.createDecoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);\n }\n return await loadDecoderPromise;\n}\n\nexport async function loadDracoEncoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadEncoderPromise =\n loadEncoderPromise ||\n modules.draco3d.createEncoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);\n }\n return await loadEncoderPromise;\n}\n\n// DRACO DECODER LOADING\n\nasync function loadDracoDecoder(options) {\n let DracoDecoderModule;\n let wasmBinary;\n switch (options.draco && options.draco.decoderType) {\n case 'js':\n DracoDecoderModule = await loadLibrary(DRACO_JS_DECODER_URL, 'draco', options);\n break;\n\n case 'wasm':\n default:\n [DracoDecoderModule, wasmBinary] = await Promise.all([\n await loadLibrary(DRACO_WASM_WRAPPER_URL, 'draco', options),\n await loadLibrary(DRACO_WASM_DECODER_URL, 'draco', options)\n ]);\n }\n // Depends on how import happened...\n // @ts-ignore\n DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;\n return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);\n}\n\nfunction initializeDracoDecoder(DracoDecoderModule, wasmBinary) {\n const options: {wasmBinary?: any} = {};\n if (wasmBinary) {\n options.wasmBinary = wasmBinary;\n }\n\n return new Promise((resolve) => {\n DracoDecoderModule({\n ...options,\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n\n// ENCODER\n\nasync function loadDracoEncoder(options) {\n let DracoEncoderModule = await loadLibrary(DRACO_ENCODER_URL, 'draco', options);\n // @ts-ignore\n DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;\n\n return new Promise((resolve) => {\n DracoEncoderModule({\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n"],"file":"draco-module-loader.js"}
@@ -65,7 +65,7 @@ export default class DracoParser {
65
65
  }
66
66
 
67
67
  if (!dracoStatus.ok() || !dracoGeometry.ptr) {
68
- const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`;
68
+ const message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());
69
69
  throw new Error(message);
70
70
  }
71
71
 
@@ -290,7 +290,7 @@ export default class DracoParser {
290
290
  return attribute.metadata[entryName].string;
291
291
  }
292
292
 
293
- return `CUSTOM_ATTRIBUTE_${uniqueId}`;
293
+ return "CUSTOM_ATTRIBUTE_".concat(uniqueId);
294
294
  }
295
295
 
296
296
  _getTopLevelMetadata(dracoGeometry) {
@@ -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,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;AAC9E,UAAMC,MAAM,GAAG,IAAI,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,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"}
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,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AAIhI,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,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,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,EAEL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B,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.3" !== 'undefined' ? "3.1.0-alpha.3" : 'latest';
1
+ export const VERSION = typeof "4.0.0-alpha.4" !== 'undefined' ? "4.0.0-alpha.4" : 'latest';
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/draco",
3
- "version": "3.1.0-alpha.3",
3
+ "version": "4.0.0-alpha.4",
4
4
  "description": "Framework-independent loader and writer for Draco compressed meshes and point clouds",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,15 +33,15 @@
33
33
  ],
34
34
  "scripts": {
35
35
  "pre-build": "npm run build-bundle && npm run build-worker",
36
- "build-bundle": "webpack --config ../../scripts/webpack/bundle.js",
37
- "build-worker": "webpack --entry ./src/workers/draco-worker.ts --output ./dist/draco-worker.js --config ../../scripts/webpack/worker.js"
36
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
37
+ "build-worker": "esbuild src/workers/draco-worker.ts --bundle --outfile=dist/draco-worker.js"
38
38
  },
39
39
  "dependencies": {
40
40
  "@babel/runtime": "^7.3.1",
41
- "@loaders.gl/loader-utils": "3.1.0-alpha.3",
42
- "@loaders.gl/schema": "3.1.0-alpha.3",
43
- "@loaders.gl/worker-utils": "3.1.0-alpha.3",
41
+ "@loaders.gl/loader-utils": "4.0.0-alpha.4",
42
+ "@loaders.gl/schema": "4.0.0-alpha.4",
43
+ "@loaders.gl/worker-utils": "4.0.0-alpha.4",
44
44
  "draco3d": "1.4.1"
45
45
  },
46
- "gitHead": "68e1c443d1b63aa2515436a7411ed0a029b42c15"
46
+ "gitHead": "53026061b3c8871f7e96d3a5826125cc6613bddc"
47
47
  }
package/dist/dist.min.js DELETED
@@ -1,2 +0,0 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=3)}([function(t,e,r){"use strict";(function(t,n){r.d(e,"a",(function(){return o})),r.d(e,"b",(function(){return a})),r.d(e,"c",(function(){return s}));const i={self:"undefined"!=typeof self&&self,window:"undefined"!=typeof window&&window,global:void 0!==t&&t,document:"undefined"!=typeof document&&document},o=i.global||i.self||i.window||{},a="object"!=typeof n||"[object process]"!==String(n)||n.browser,s="function"==typeof importScripts,c=("undefined"!=typeof window&&window.orientation,void 0!==n&&n.version&&/v([0-9]*)/.exec(n.version));c&&parseFloat(c[1])}).call(this,r(5),r(6))},function(t,e){},,function(t,e,r){const n=r(7);globalThis.loaders=globalThis.loaders||{},t.exports=Object.assign(globalThis.loaders,n)},,function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e){var r,n,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function s(t){if(r===setTimeout)return setTimeout(t,0);if((r===o||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:o}catch(t){r=o}try{n="function"==typeof clearTimeout?clearTimeout:a}catch(t){n=a}}();var c,d=[],u=!1,l=-1;function h(){u&&c&&(u=!1,c.length?d=c.concat(d):l=-1,d.length&&f())}function f(){if(!u){var t=s(h);u=!0;for(var e=d.length;e;){for(c=d,d=[];++l<e;)c&&c[l].run();l=-1,e=d.length}c=null,u=!1,function(t){if(n===clearTimeout)return clearTimeout(t);if((n===a||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(t);try{n(t)}catch(e){try{return n.call(null,t)}catch(e){return n.call(this,t)}}}(t)}}function y(t,e){this.fun=t,this.array=e}function m(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];d.push(new y(t,e)),1!==d.length||u||s(f)},y.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.prependListener=m,i.prependOnceListener=m,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(t,e,r){"use strict";r.r(e),r.d(e,"DracoWriter",(function(){return Z})),r.d(e,"DracoWorkerLoader",(function(){return n})),r.d(e,"DracoLoader",(function(){return tt})),r.d(e,"_TypecheckDracoLoader",(function(){return et}));const n={name:"Draco",id:"draco",module:"draco",shapes:["mesh"],version:"3.1.0-alpha.3",worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:{draco:{decoderType:"object"==typeof WebAssembly?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}}};function i(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}class o{constructor(t,e){i(this,"fields",void 0),i(this,"metadata",void 0),function(t,e){if(!t)throw new Error(e||"loader assertion failed.")}(Array.isArray(t)),function(t){const e={};for(const r of t)e[r.name]&&console.warn("Schema: duplicated field name",r.name,r),e[r.name]=!0}(t),this.fields=t,this.metadata=e||new Map}compareTo(t){if(this.metadata!==t.metadata)return!1;if(this.fields.length!==t.fields.length)return!1;for(let e=0;e<this.fields.length;++e)if(!this.fields[e].compareTo(t.fields[e]))return!1;return!0}select(...t){const e=Object.create(null);for(const r of t)e[r]=!0;const r=this.fields.filter(t=>e[t.name]);return new o(r,this.metadata)}selectAt(...t){const e=t.map(t=>this.fields[t]).filter(Boolean);return new o(e,this.metadata)}assign(t){let e,r=this.metadata;if(t instanceof o){const n=t;e=n.fields,r=a(a(new Map,this.metadata),n.metadata)}else e=t;const n=Object.create(null);for(const t of this.fields)n[t.name]=t;for(const t of e)n[t.name]=t;const i=Object.values(n);return new o(i,r)}}function a(t,e){return new Map([...t||new Map,...e||new Map])}function s(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}class c{constructor(t,e,r=!1,n=new Map){s(this,"name",void 0),s(this,"type",void 0),s(this,"nullable",void 0),s(this,"metadata",void 0),this.name=t,this.type=e,this.nullable=r,this.metadata=n}get typeId(){return this.type&&this.type.typeId}clone(){return new c(this.name,this.type,this.nullable,this.metadata)}compareTo(t){return this.name===t.name&&this.type===t.type&&this.nullable===t.nullable&&this.metadata===t.metadata}toString(){return`${this.type}${this.nullable?", nullable":""}${this.metadata?", metadata: "+this.metadata:""}`}}let d,u,l,h,f,y,m,p,b;function w(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}!function(t){t[t.NONE=0]="NONE",t[t.Null=1]="Null",t[t.Int=2]="Int",t[t.Float=3]="Float",t[t.Binary=4]="Binary",t[t.Utf8=5]="Utf8",t[t.Bool=6]="Bool",t[t.Decimal=7]="Decimal",t[t.Date=8]="Date",t[t.Time=9]="Time",t[t.Timestamp=10]="Timestamp",t[t.Interval=11]="Interval",t[t.List=12]="List",t[t.Struct=13]="Struct",t[t.Union=14]="Union",t[t.FixedSizeBinary=15]="FixedSizeBinary",t[t.FixedSizeList=16]="FixedSizeList",t[t.Map=17]="Map",t[t.Dictionary=-1]="Dictionary",t[t.Int8=-2]="Int8",t[t.Int16=-3]="Int16",t[t.Int32=-4]="Int32",t[t.Int64=-5]="Int64",t[t.Uint8=-6]="Uint8",t[t.Uint16=-7]="Uint16",t[t.Uint32=-8]="Uint32",t[t.Uint64=-9]="Uint64",t[t.Float16=-10]="Float16",t[t.Float32=-11]="Float32",t[t.Float64=-12]="Float64",t[t.DateDay=-13]="DateDay",t[t.DateMillisecond=-14]="DateMillisecond",t[t.TimestampSecond=-15]="TimestampSecond",t[t.TimestampMillisecond=-16]="TimestampMillisecond",t[t.TimestampMicrosecond=-17]="TimestampMicrosecond",t[t.TimestampNanosecond=-18]="TimestampNanosecond",t[t.TimeSecond=-19]="TimeSecond",t[t.TimeMillisecond=-20]="TimeMillisecond",t[t.TimeMicrosecond=-21]="TimeMicrosecond",t[t.TimeNanosecond=-22]="TimeNanosecond",t[t.DenseUnion=-23]="DenseUnion",t[t.SparseUnion=-24]="SparseUnion",t[t.IntervalDayTime=-25]="IntervalDayTime",t[t.IntervalYearMonth=-26]="IntervalYearMonth"}(d||(d={}));class g{static isNull(t){return t&&t.typeId===d.Null}static isInt(t){return t&&t.typeId===d.Int}static isFloat(t){return t&&t.typeId===d.Float}static isBinary(t){return t&&t.typeId===d.Binary}static isUtf8(t){return t&&t.typeId===d.Utf8}static isBool(t){return t&&t.typeId===d.Bool}static isDecimal(t){return t&&t.typeId===d.Decimal}static isDate(t){return t&&t.typeId===d.Date}static isTime(t){return t&&t.typeId===d.Time}static isTimestamp(t){return t&&t.typeId===d.Timestamp}static isInterval(t){return t&&t.typeId===d.Interval}static isList(t){return t&&t.typeId===d.List}static isStruct(t){return t&&t.typeId===d.Struct}static isUnion(t){return t&&t.typeId===d.Union}static isFixedSizeBinary(t){return t&&t.typeId===d.FixedSizeBinary}static isFixedSizeList(t){return t&&t.typeId===d.FixedSizeList}static isMap(t){return t&&t.typeId===d.Map}static isDictionary(t){return t&&t.typeId===d.Dictionary}get typeId(){return d.NONE}compareTo(t){return this===t}}Symbol.toStringTag;Symbol.toStringTag;u=Symbol.toStringTag;class _ extends g{constructor(t,e){super(),w(this,"isSigned",void 0),w(this,"bitWidth",void 0),this.isSigned=t,this.bitWidth=e}get typeId(){return d.Int}get[u](){return"Int"}toString(){return`${this.isSigned?"I":"Ui"}nt${this.bitWidth}`}}class A extends _{constructor(){super(!0,8)}}class T extends _{constructor(){super(!0,16)}}class I extends _{constructor(){super(!0,32)}}class M extends _{constructor(){super(!1,8)}}class S extends _{constructor(){super(!1,16)}}class O extends _{constructor(){super(!1,32)}}const D=32,v=64;l=Symbol.toStringTag;class E extends g{constructor(t){super(),w(this,"precision",void 0),this.precision=t}get typeId(){return d.Float}get[l](){return"Float"}toString(){return"Float"+this.precision}}class N extends E{constructor(){super(D)}}class F extends E{constructor(){super(v)}}Symbol.toStringTag;Symbol.toStringTag;h=Symbol.toStringTag;f=Symbol.toStringTag;y=Symbol.toStringTag;m=Symbol.toStringTag;p=Symbol.toStringTag;class U extends g{constructor(t,e){super(),w(this,"listSize",void 0),w(this,"children",void 0),this.listSize=t,this.children=[e]}get typeId(){return d.FixedSizeList}get valueType(){return this.children[0].type}get valueField(){return this.children[0]}get[p](){return"FixedSizeList"}toString(){return`FixedSizeList[${this.listSize}]<${this.valueType}>`}}b=Symbol.toStringTag;function x(t,e,r){const n=function(t){switch(t.constructor){case Int8Array:return new A;case Uint8Array:return new M;case Int16Array:return new T;case Uint16Array:return new S;case Int32Array:return new I;case Uint32Array:return new O;case Float32Array:return new N;case Float64Array:return new F;default:throw new Error("array type not supported")}}(e.value),i=r||function(t){const e=new Map;"byteOffset"in t&&e.set("byteOffset",t.byteOffset.toString(10));"byteStride"in t&&e.set("byteStride",t.byteStride.toString(10));"normalized"in t&&e.set("normalized",t.normalized.toString());return e}(e);return new c(t,new U(e.size,new c("value",n)),!1,i)}function z(t,e,r){return x(t,e,r?L(r.metadata):void 0)}function L(t){const e=new Map;for(const r in t)e.set(r+".string",JSON.stringify(t[r]));return e}function j(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}const B={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},P={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array};class C{constructor(t){j(this,"draco",void 0),j(this,"decoder",void 0),j(this,"metadataQuerier",void 0),this.draco=t,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(t,e={}){const r=new this.draco.DecoderBuffer;r.Init(new Int8Array(t),t.byteLength),this._disableAttributeTransforms(e);const n=this.decoder.GetEncodedGeometryType(r),i=n===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let t;switch(n){case this.draco.TRIANGULAR_MESH:t=this.decoder.DecodeBufferToMesh(r,i);break;case this.draco.POINT_CLOUD:t=this.decoder.DecodeBufferToPointCloud(r,i);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!t.ok()||!i.ptr){const e="DRACO decompression failed: "+t.error_msg();throw new Error(e)}const a=this._getDracoLoaderData(i,n,e),s=this._getMeshData(i,a,e),c=function(t){let e=1/0,r=1/0,n=1/0,i=-1/0,o=-1/0,a=-1/0;const s=t.POSITION?t.POSITION.value:[],c=s&&s.length;for(let t=0;t<c;t+=3){const c=s[t],d=s[t+1],u=s[t+2];e=c<e?c:e,r=d<r?d:r,n=u<n?u:n,i=c>i?c:i,o=d>o?d:o,a=u>a?u:a}return[[e,r,n],[i,o,a]]}(s.attributes),d=function(t,e,r){const n=L(e.metadata),i=[],a=function(t){const e={};for(const r in t){const n=t[r];e[n.name||"undefined"]=n}return e}(e.attributes);for(const e in t){const r=z(e,t[e],a[e]);i.push(r)}if(r){const t=z("indices",r);i.push(t)}return new o(i,n)}(s.attributes,a,s.indices);return{loader:"draco",loaderData:a,header:{vertexCount:i.num_points(),boundingBox:c},...s,schema:d}}finally{this.draco.destroy(r),i&&this.draco.destroy(i)}}_getDracoLoaderData(t,e,r){const n=this._getTopLevelMetadata(t),i=this._getDracoAttributes(t,r);return{geometry_type:e,num_attributes:t.num_attributes(),num_points:t.num_points(),num_faces:t instanceof this.draco.Mesh?t.num_faces():0,metadata:n,attributes:i}}_getDracoAttributes(t,e){const r={};for(let n=0;n<t.num_attributes();n++){const i=this.decoder.GetAttribute(t,n),o=this._getAttributeMetadata(t,n);r[i.unique_id()]={unique_id:i.unique_id(),attribute_type:i.attribute_type(),data_type:i.data_type(),num_components:i.num_components(),byte_offset:i.byte_offset(),byte_stride:i.byte_stride(),normalized:i.normalized(),attribute_index:n,metadata:o};const a=this._getQuantizationTransform(i,e);a&&(r[i.unique_id()].quantization_transform=a);const s=this._getOctahedronTransform(i,e);s&&(r[i.unique_id()].octahedron_transform=s)}return r}_getMeshData(t,e,r){const n=this._getMeshAttributes(e,t,r);if(!n.POSITION)throw new Error("DRACO: No position attribute found.");if(t instanceof this.draco.Mesh)switch(r.topology){case"triangle-strip":return{topology:"triangle-strip",mode:4,attributes:n,indices:{value:this._getTriangleStripIndices(t),size:1}};case"triangle-list":default:return{topology:"triangle-list",mode:5,attributes:n,indices:{value:this._getTriangleListIndices(t),size:1}}}return{topology:"point-list",mode:0,attributes:n}}_getMeshAttributes(t,e,r){const n={};for(const i of Object.values(t.attributes)){const t=this._deduceAttributeName(i,r);i.name=t;const{value:o,size:a}=this._getAttributeValues(e,i);n[t]={value:o,size:a,byteOffset:i.byte_offset,byteStride:i.byte_stride,normalized:i.normalized}}return n}_getTriangleListIndices(t){const e=3*t.num_faces(),r=4*e,n=this.draco._malloc(r);try{return this.decoder.GetTrianglesUInt32Array(t,r,n),new Uint32Array(this.draco.HEAPF32.buffer,n,e).slice()}finally{this.draco._free(n)}}_getTriangleStripIndices(t){const e=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(t,e),function(t){const e=t.size(),r=new Int32Array(e);for(let n=0;n<e;n++)r[n]=t.GetValue(n);return r}(e)}finally{this.draco.destroy(e)}}_getAttributeValues(t,e){const r=P[e.data_type],n=e.num_components,i=t.num_points()*n,o=i*r.BYTES_PER_ELEMENT,a=function(t,e){switch(e){case Float32Array:return t.DT_FLOAT32;case Int8Array:return t.DT_INT8;case Int16Array:return t.DT_INT16;case Int32Array:return t.DT_INT32;case Uint8Array:return t.DT_UINT8;case Uint16Array:return t.DT_UINT16;case Uint32Array:return t.DT_UINT32;default:return t.DT_INVALID}}(this.draco,r);let s;const c=this.draco._malloc(o);try{const n=this.decoder.GetAttribute(t,e.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(t,n,a,o,c),s=new r(this.draco.HEAPF32.buffer,c,i).slice()}finally{this.draco._free(c)}return{value:s,size:n}}_deduceAttributeName(t,e){const r=t.unique_id;for(const[t,n]of Object.entries(e.extraAttributes||{}))if(n===r)return t;const n=t.attribute_type;for(const t in B){if(this.draco[t]===n)return B[t]}const i=e.attributeNameEntry||"name";return t.metadata[i]?t.metadata[i].string:"CUSTOM_ATTRIBUTE_"+r}_getTopLevelMetadata(t){const e=this.decoder.GetMetadata(t);return this._getDracoMetadata(e)}_getAttributeMetadata(t,e){const r=this.decoder.GetAttributeMetadata(t,e);return this._getDracoMetadata(r)}_getDracoMetadata(t){if(!t||!t.ptr)return{};const e={},r=this.metadataQuerier.NumEntries(t);for(let n=0;n<r;n++){const r=this.metadataQuerier.GetEntryName(t,n);e[r]=this._getDracoMetadataField(t,r)}return e}_getDracoMetadataField(t,e){const r=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(t,e,r);const n=function(t){const e=t.size(),r=new Int32Array(e);for(let n=0;n<e;n++)r[n]=t.GetValue(n);return r}(r);return{int:this.metadataQuerier.GetIntEntry(t,e),string:this.metadataQuerier.GetStringEntry(t,e),double:this.metadataQuerier.GetDoubleEntry(t,e),intArray:n}}finally{this.draco.destroy(r)}}_disableAttributeTransforms(t){const{quantizedAttributes:e=[],octahedronAttributes:r=[]}=t,n=[...e,...r];for(const t of n)this.decoder.SkipAttributeTransform(this.draco[t])}_getQuantizationTransform(t,e){const{quantizedAttributes:r=[]}=e,n=t.attribute_type();if(r.map(t=>this.decoder[t]).includes(n)){const e=new this.draco.AttributeQuantizationTransform;try{if(e.InitFromAttribute(t))return{quantization_bits:e.quantization_bits(),range:e.range(),min_values:new Float32Array([1,2,3]).map(t=>e.min_value(t))}}finally{this.draco.destroy(e)}}return null}_getOctahedronTransform(t,e){const{octahedronAttributes:r=[]}=e,n=t.attribute_type();if(r.map(t=>this.decoder[t]).includes(n)){const e=new this.draco.AttributeQuantizationTransform;try{if(e.InitFromAttribute(t))return{quantization_bits:e.quantization_bits()}}finally{this.draco.destroy(e)}}return null}}var R=r(0),G=r(1);const $={};async function q(t,e=null,r={}){return e&&(t=function(t,e,r){if(t.startsWith("http"))return t;const n=r.modules||{};if(n[t])return n[t];if(!R.b)return`modules/${e}/dist/libs/${t}`;if(r.CDN)return function(t,e){if(!t)throw new Error(e||"loaders.gl assertion failed.")}(r.CDN.startsWith("http")),`${r.CDN}/${e}@3.1.0-alpha.3/dist/libs/${t}`;if(R.c)return"../src/libs/"+t;return`modules/${e}/src/libs/${t}`}(t,e,r)),$[t]=$[t]||async function(t){if(t.endsWith("wasm")){const e=await fetch(t);return await e.arrayBuffer()}if(!R.b)return G.requireFromFile&&await G.requireFromFile(t);if(R.c)return importScripts(t);const e=await fetch(t);return function(t,e){if(!R.b)return G.requireFromString&&G.requireFromString(t,e);if(R.c)return eval.call(R.a,t),null;const r=document.createElement("script");r.id=e;try{r.appendChild(document.createTextNode(t))}catch(e){r.text=t}return document.body.appendChild(r),null}(await e.text(),t)}(t),await $[t]}let Q,k;async function W(t){const e=t.modules||{};return Q=e.draco3d?Q||e.draco3d.createDecoderModule({}).then(t=>({draco:t})):Q||async function(t){let e,r;switch(t.draco&&t.draco.decoderType){case"js":e=await q("https://www.gstatic.com/draco/versioned/decoders/1.4.1/draco_decoder.js","draco",t);break;case"wasm":default:[e,r]=await Promise.all([await q("https://www.gstatic.com/draco/versioned/decoders/1.4.1/draco_wasm_wrapper.js","draco",t),await q("https://www.gstatic.com/draco/versioned/decoders/1.4.1/draco_decoder.wasm","draco",t)])}return e=e||globalThis.DracoDecoderModule,await function(t,e){const r={};e&&(r.wasmBinary=e);return new Promise(e=>{t({...r,onModuleLoaded:t=>e({draco:t})})})}(e,r)}(t),await Q}async function V(t){const e=t.modules||{};return k=e.draco3d?k||e.draco3d.createEncoderModule({}).then(t=>({draco:t})):k||async function(t){let e=await q("https://raw.githubusercontent.com/google/draco/1.4.1/javascript/draco_encoder.js","draco",t);return e=e||globalThis.DracoEncoderModule,new Promise(t=>{e({onModuleLoaded:e=>t({draco:e})})})}(t),await k}function H(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}const X={POSITION:"POSITION",NORMAL:"NORMAL",COLOR_0:"COLOR",TEXCOORD_0:"TEX_COORD"},Y=()=>{};class J{constructor(t){H(this,"draco",void 0),H(this,"dracoEncoder",void 0),H(this,"dracoMeshBuilder",void 0),H(this,"dracoMetadataBuilder",void 0),H(this,"log",void 0),this.draco=t,this.dracoEncoder=new this.draco.Encoder,this.dracoMeshBuilder=new this.draco.MeshBuilder,this.dracoMetadataBuilder=new this.draco.MetadataBuilder}destroy(){this.destroyEncodedObject(this.dracoMeshBuilder),this.destroyEncodedObject(this.dracoEncoder),this.destroyEncodedObject(this.dracoMetadataBuilder),this.dracoMeshBuilder=null,this.dracoEncoder=null,this.draco=null}destroyEncodedObject(t){t&&this.draco.destroy(t)}encodeSync(t,e={}){return this.log=Y,this._setOptions(e),e.pointcloud?this._encodePointCloud(t,e):this._encodeMesh(t,e)}_getAttributesFromMesh(t){const e={...t,...t.attributes};return t.indices&&(e.indices=t.indices),e}_encodePointCloud(t,e){const r=new this.draco.PointCloud;e.metadata&&this._addGeometryMetadata(r,e.metadata);const n=this._getAttributesFromMesh(t);this._createDracoPointCloud(r,n,e);const i=new this.draco.DracoInt8Array;try{const t=this.dracoEncoder.EncodePointCloudToDracoBuffer(r,!1,i);if(!(t>0))throw new Error("Draco encoding failed.");return this.log(`DRACO encoded ${r.num_points()} points\n with ${r.num_attributes()} attributes into ${t} bytes`),K(i)}finally{this.destroyEncodedObject(i),this.destroyEncodedObject(r)}}_encodeMesh(t,e){const r=new this.draco.Mesh;e.metadata&&this._addGeometryMetadata(r,e.metadata);const n=this._getAttributesFromMesh(t);this._createDracoMesh(r,n,e);const i=new this.draco.DracoInt8Array;try{const t=this.dracoEncoder.EncodeMeshToDracoBuffer(r,i);if(t<=0)throw new Error("Draco encoding failed.");return this.log(`DRACO encoded ${r.num_points()} points\n with ${r.num_attributes()} attributes into ${t} bytes`),K(i)}finally{this.destroyEncodedObject(i),this.destroyEncodedObject(r)}}_setOptions(t){if("speed"in t&&this.dracoEncoder.SetSpeedOptions(...t.speed),"method"in t){const e=this.draco[t.method||"MESH_SEQUENTIAL_ENCODING"];this.dracoEncoder.SetEncodingMethod(e)}if("quantization"in t)for(const e in t.quantization){const r=t.quantization[e],n=this.draco[e];this.dracoEncoder.SetAttributeQuantization(n,r)}}_createDracoMesh(t,e,r){const n=r.attributesMetadata||{};try{const r=this._getPositionAttribute(e);if(!r)throw new Error("positions");const i=r.length/3;for(let r in e){const o=e[r];r=X[r]||r;const a=this._addAttributeToMesh(t,r,o,i);-1!==a&&this._addAttributeMetadata(t,a,{name:r,...n[r]||{}})}}catch(e){throw this.destroyEncodedObject(t),e}return t}_createDracoPointCloud(t,e,r){const n=r.attributesMetadata||{};try{const r=this._getPositionAttribute(e);if(!r)throw new Error("positions");const i=r.length/3;for(let r in e){const o=e[r];r=X[r]||r;const a=this._addAttributeToMesh(t,r,o,i);-1!==a&&this._addAttributeMetadata(t,a,{name:r,...n[r]||{}})}}catch(e){throw this.destroyEncodedObject(t),e}return t}_addAttributeToMesh(t,e,r,n){if(!ArrayBuffer.isView(r))return-1;const i=this._getDracoAttributeType(e),o=r.length/n;if("indices"===i){const n=r.length/3;return this.log(`Adding attribute ${e}, size ${n}`),this.dracoMeshBuilder.AddFacesToMesh(t,n,r),-1}this.log(`Adding attribute ${e}, size ${o}`);const a=this.dracoMeshBuilder,{buffer:s}=r;switch(r.constructor){case Int8Array:return a.AddInt8Attribute(t,i,n,o,new Int8Array(s));case Int16Array:return a.AddInt16Attribute(t,i,n,o,new Int16Array(s));case Int32Array:return a.AddInt32Attribute(t,i,n,o,new Int32Array(s));case Uint8Array:case Uint8ClampedArray:return a.AddUInt8Attribute(t,i,n,o,new Uint8Array(s));case Uint16Array:return a.AddUInt16Attribute(t,i,n,o,new Uint16Array(s));case Uint32Array:return a.AddUInt32Attribute(t,i,n,o,new Uint32Array(s));case Float32Array:default:return a.AddFloatAttribute(t,i,n,o,new Float32Array(s))}}_getDracoAttributeType(t){switch(t.toLowerCase()){case"indices":return"indices";case"position":case"positions":case"vertices":return this.draco.POSITION;case"normal":case"normals":return this.draco.NORMAL;case"color":case"colors":return this.draco.COLOR;case"texcoord":case"texcoords":return this.draco.TEX_COORD;default:return this.draco.GENERIC}}_getPositionAttribute(t){for(const e in t){const r=t[e];if(this._getDracoAttributeType(e)===this.draco.POSITION)return r}return null}_addGeometryMetadata(t,e){const r=new this.draco.Metadata;this._populateDracoMetadata(r,e),this.dracoMeshBuilder.AddMetadata(t,r)}_addAttributeMetadata(t,e,r){const n=new this.draco.Metadata;this._populateDracoMetadata(n,r),this.dracoMeshBuilder.SetMetadataForAttribute(t,e,n)}_populateDracoMetadata(t,e){for(const[n,i]of(r=e).entries&&!r.hasOwnProperty("entries")?r.entries():Object.entries(r))switch(typeof i){case"number":Math.trunc(i)===i?this.dracoMetadataBuilder.AddIntEntry(t,n,i):this.dracoMetadataBuilder.AddDoubleEntry(t,n,i);break;case"object":i instanceof Int32Array&&this.dracoMetadataBuilder.AddIntEntryArray(t,n,i,i.length);break;case"string":default:this.dracoMetadataBuilder.AddStringEntry(t,n,i)}var r}}function K(t){const e=t.size(),r=new ArrayBuffer(e),n=new Int8Array(r);for(let r=0;r<e;++r)n[r]=t.GetValue(r);return r}const Z={name:"DRACO",id:"draco",module:"draco",version:"3.1.0-alpha.3",extensions:["drc"],encode:async function(t,e={}){const{draco:r}=await V(e),n=new J(r);try{return n.encodeSync(t,e.draco)}finally{n.destroy()}},options:{draco:{pointcloud:!1,attributeNameEntry:"name"}}};const tt={...n,parse:async function(t,e){const{draco:r}=await W(e),n=new C(r);try{return n.parseSync(t,null==e?void 0:e.draco)}finally{n.destroy()}}};const et=tt}])}));
2
- //# sourceMappingURL=dist.min.js.map