@loaders.gl/tile-converter 3.3.0-alpha.3 → 3.3.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.
Files changed (88) hide show
  1. package/dist/3d-tiles-attributes-worker.js +1 -1
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +8 -0
  3. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  4. package/dist/3d-tiles-converter/3d-tiles-converter.js +57 -43
  5. package/dist/converter.min.js +21 -21
  6. package/dist/deps-installer/deps-installer.d.ts +5 -1
  7. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  8. package/dist/deps-installer/deps-installer.js +21 -1
  9. package/dist/dist.min.js +660 -1016
  10. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  11. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +115 -101
  12. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  13. package/dist/es5/deps-installer/deps-installer.js +70 -6
  14. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  15. package/dist/es5/i3s-attributes-worker.js +1 -1
  16. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +4 -0
  18. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  19. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  20. package/dist/es5/i3s-converter/helpers/feature-attributes.js +153 -0
  21. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  22. package/dist/es5/i3s-converter/helpers/geometry-converter.js +40 -44
  23. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  24. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +55 -36
  25. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/node-pages.js +10 -2
  27. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  28. package/dist/es5/i3s-converter/i3s-converter.js +364 -435
  29. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  30. package/dist/es5/pgm-loader.js +1 -1
  31. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  32. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +59 -44
  33. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  34. package/dist/esm/deps-installer/deps-installer.js +21 -2
  35. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  36. package/dist/esm/i3s-attributes-worker.js +1 -1
  37. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  38. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +4 -0
  39. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  40. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  41. package/dist/esm/i3s-converter/helpers/feature-attributes.js +138 -0
  42. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  43. package/dist/esm/i3s-converter/helpers/geometry-converter.js +19 -21
  44. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  45. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +55 -36
  46. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  47. package/dist/esm/i3s-converter/helpers/node-pages.js +9 -2
  48. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  49. package/dist/esm/i3s-converter/i3s-converter.js +93 -183
  50. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  51. package/dist/esm/pgm-loader.js +1 -1
  52. package/dist/i3s-attributes-worker.d.ts +5 -1
  53. package/dist/i3s-attributes-worker.d.ts.map +1 -1
  54. package/dist/i3s-attributes-worker.js +3 -3
  55. package/dist/i3s-attributes-worker.js.map +2 -2
  56. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +2 -3
  57. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  58. package/dist/i3s-converter/helpers/batch-ids-extensions.js +3 -0
  59. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +2 -2
  60. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  61. package/dist/i3s-converter/helpers/feature-attributes.d.ts +32 -0
  62. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  63. package/dist/i3s-converter/helpers/feature-attributes.js +162 -1
  64. package/dist/i3s-converter/helpers/geometry-converter.d.ts +5 -4
  65. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  66. package/dist/i3s-converter/helpers/geometry-converter.js +29 -27
  67. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  68. package/dist/i3s-converter/helpers/gltf-attributes.js +50 -30
  69. package/dist/i3s-converter/helpers/node-pages.d.ts +4 -0
  70. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  71. package/dist/i3s-converter/helpers/node-pages.js +9 -2
  72. package/dist/i3s-converter/i3s-converter.d.ts +24 -48
  73. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  74. package/dist/i3s-converter/i3s-converter.js +88 -186
  75. package/dist/i3s-converter/types.d.ts +4 -0
  76. package/dist/i3s-converter/types.d.ts.map +1 -1
  77. package/package.json +15 -15
  78. package/src/3d-tiles-converter/3d-tiles-converter.ts +71 -55
  79. package/src/deps-installer/deps-installer.ts +29 -2
  80. package/src/i3s-attributes-worker.ts +5 -1
  81. package/src/i3s-converter/helpers/batch-ids-extensions.ts +13 -6
  82. package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
  83. package/src/i3s-converter/helpers/feature-attributes.ts +182 -0
  84. package/src/i3s-converter/helpers/geometry-converter.ts +45 -36
  85. package/src/i3s-converter/helpers/gltf-attributes.ts +54 -33
  86. package/src/i3s-converter/helpers/node-pages.ts +10 -2
  87. package/src/i3s-converter/i3s-converter.ts +125 -210
  88. package/src/i3s-converter/types.ts +4 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/3d-tiles-converter/3d-tiles-converter.ts"],"names":["join","process","transform","fetchFile","getLoaderOptions","load","isBrowser","I3SLoader","I3SAttributeLoader","COORDINATE_SYSTEM","Tileset3D","Tile3D","PGMLoader","i3sObbTo3dTilesObb","convertScreenThresholdToGeometricError","writeFile","removeDir","calculateFilesSize","timeConverter","TILESET","tilesetTemplate","B3dmConverter","createObbFromMbs","Tile3dAttributesWorker","getWorkerURL","WorkerFarm","BROWSER_ERROR_MESSAGE","I3S","Tiles3DConverter","constructor","options","tilesetPath","vertexCounter","conversionStartTime","geoidHeightModel","sourceTileset","attributeStorageInfo","workerSource","convert","console","log","inputUrl","outputPath","tilesetName","maxDepth","egmFilePath","hrtime","loadWorkers","sourceTilesetJson","loadOptions","i3s","coordinateSystem","LNGLAT_OFFSETS","decodeTextures","tilesetInitializationPromise","rootNode","root","header","obb","mbs","e","rootTile","boundingVolume","box","geometricError","children","_addChildren","tileset","JSON","stringify","_finishConversion","slpk","workerFarm","getWorkerFarm","destroy","parentSourceNode","parentNode","level","childNodeInfo","sourceChild","_loadChildNode","push","contentUrl","_loadTile","content","vertexCount","featureAttributes","_loadChildAttributes","child","i3sAttributesData","tileContent","textureFormat","b3dm","uri","id","Uint8Array","unloadContent","nodePages","nodePagesTile","formTileFromNodePages","loader","nodeUrl","_relativeUrlToFullUrl","url","href","isTileHeader","loadContent","baseUrl","relativeUrl","resultArray","split","relativeUrlArray","folder","slice","promises","attributeUrls","index","length","attribute","attributeName","name","attributeType","_getAttributeType","attributesList","Promise","all","_replaceNestedArrays","Object","assign","attributeValues","valueType","objectIds","attributeObject","key","Array","from","params","filesSize","diff","conversionTime","tile3dAttributesWorkerUrl","sourceResponse","source","text","tile3dWorkerSource"],"mappings":";AAGA,SAAQA,IAAR,QAAmB,MAAnB;AACA,OAAOC,OAAP,MAAoB,SAApB;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AACA,SAAQC,SAAR,EAAmBC,gBAAnB,E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AACC,GAAR,mBAA8BiG,SAA9B,EAAyC,QAAzC;AACAlG,IAAAA,OAAO,CAACC,GAAR;AACD;;AAEwB,QAAXO,WAAW,GAAkB;AACzCR,IAAAA,OAAO,CAACC,GAAR;AACA,UAAMoG,yBAAyB,GAAGpH,YAAY,CAACD,sBAAD,EAAyB,EAAC,GAAGnB,gBAAgB;AAApB,KAAzB,CAA9C;AACA,UAAMyI,cAAc,GAAG,MAAM1I,SAAS,CAACyI,yBAAD,CAAtC;AACA,UAAME,MAAM,GAAG,MAAMD,cAAc,CAACE,IAAf,EAArB;AAEA,SAAK1G,YAAL,CAAkB2G,kBAAlB,GAAuCF,MAAvC;AACAvG,IAAAA,OAAO,CAACC,GAAR;AACD;;AAhTmC","sourcesContent":["import type {AttributeStorageInfo, FeatureAttribute, NodeReference} from '@loaders.gl/i3s';\nimport type {Node3D} from '@loaders.gl/3d-tiles';\n\nimport {join} from 'path';\nimport process from 'process';\nimport transform from 'json-map-transform';\nimport {fetchFile, getLoaderOptions, load, isBrowser} from '@loaders.gl/core';\nimport {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';\nimport {Tileset3D, Tile3D} from '@loaders.gl/tiles';\nimport {Geoid} from '@math.gl/geoid';\n\nimport {PGMLoader} from '../pgm-loader';\nimport {i3sObbTo3dTilesObb} from './helpers/i3s-obb-to-3d-tiles-obb';\nimport {convertScreenThresholdToGeometricError} from '../lib/utils/lod-conversion-utils';\nimport {writeFile, removeDir} from '../lib/utils/file-utils';\nimport {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';\nimport {TILESET as tilesetTemplate} from './json-templates/tileset';\nimport B3dmConverter from './helpers/b3dm-converter';\nimport {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';\nimport {\n I3SAttributesData,\n Tile3dAttributesWorker\n /*transform3DTilesAttributesOnWorker*/\n} from '../3d-tiles-attributes-worker';\nimport {getWorkerURL, WorkerFarm} from '@loaders.gl/worker-utils';\nimport {BROWSER_ERROR_MESSAGE} from '../constants';\n\nconst I3S = 'I3S';\n\n/**\n * Converter from i3s to 3d-tiles\n */\nexport default class Tiles3DConverter {\n options: any;\n tilesetPath: string;\n vertexCounter: number;\n conversionStartTime: [number, number];\n geoidHeightModel: Geoid | null;\n sourceTileset: Tileset3D | null;\n attributeStorageInfo: AttributeStorageInfo | null;\n workerSource: {[key: string]: string} = {};\n\n constructor() {\n this.options = {};\n this.tilesetPath = '';\n this.vertexCounter = 0;\n this.conversionStartTime = [0, 0];\n this.geoidHeightModel = null;\n this.sourceTileset = null;\n this.attributeStorageInfo = null;\n this.workerSource = {};\n }\n\n /**\n * Convert i3s format data to 3dTiles\n * @param options\n * @param options.inputUrl the url to read the tileset from\n * @param options.outputPath the output filename\n * @param options.tilesetName the output name of the tileset\n * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format\n * @param options.maxDepth The max tree depth of conversion\n */\n public async convert(options: {\n inputUrl: string;\n outputPath: string;\n tilesetName: string;\n maxDepth?: number;\n egmFilePath: string;\n }): Promise<any> {\n if (isBrowser) {\n console.log(BROWSER_ERROR_MESSAGE);\n return BROWSER_ERROR_MESSAGE;\n }\n const {inputUrl, outputPath, tilesetName, maxDepth, egmFilePath} = options;\n this.conversionStartTime = process.hrtime();\n this.options = {maxDepth};\n\n console.log('Loading egm file...'); // eslint-disable-line\n this.geoidHeightModel = await load(egmFilePath, PGMLoader);\n console.log('Loading egm file completed!'); // eslint-disable-line\n\n await this.loadWorkers();\n\n const sourceTilesetJson = await load(inputUrl, I3SLoader, {});\n\n this.sourceTileset = new Tileset3D(sourceTilesetJson, {\n loadOptions: {\n i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false}\n }\n });\n\n await this.sourceTileset.tilesetInitializationPromise;\n const rootNode = this.sourceTileset.root!;\n if (!rootNode.header.obb) {\n rootNode.header.obb = createObbFromMbs(rootNode.header.mbs);\n }\n\n this.tilesetPath = join(`${outputPath}`, `${tilesetName}`);\n this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;\n // Removing the tilesetPath needed to exclude erroneous files after conversion\n try {\n await removeDir(this.tilesetPath);\n } catch (e) {\n // do nothing\n }\n\n const rootTile: Node3D = {\n boundingVolume: {\n box: i3sObbTo3dTilesObb(rootNode.header.obb, this.geoidHeightModel)\n },\n geometricError: convertScreenThresholdToGeometricError(rootNode),\n children: []\n };\n\n await this._addChildren(rootNode, rootTile, 1);\n\n const tileset = transform({root: rootTile}, tilesetTemplate());\n await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');\n\n this._finishConversion({slpk: false, outputPath, tilesetName});\n\n // Clean up worker pools\n const workerFarm = WorkerFarm.getWorkerFarm({});\n workerFarm.destroy();\n }\n\n /**\n * The recursive function of traversal of a nodes tree\n * @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param parentNode object in resulting tileset\n * @param level a current level of a tree depth\n */\n private async _addChildren(\n parentSourceNode: Tile3D,\n parentNode: Node3D,\n level: number\n ): Promise<void> {\n if (this.options.maxDepth && level > this.options.maxDepth) {\n return;\n }\n for (const childNodeInfo of parentSourceNode.header.children || []) {\n const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);\n parentSourceNode.children.push(sourceChild);\n if (sourceChild.contentUrl) {\n await this.sourceTileset!._loadTile(sourceChild);\n this.vertexCounter += sourceChild.content.vertexCount;\n\n let featureAttributes: FeatureAttribute | null = null;\n if (this.attributeStorageInfo) {\n featureAttributes = await this._loadChildAttributes(\n sourceChild,\n this.attributeStorageInfo\n );\n }\n\n if (!sourceChild.header.obb) {\n sourceChild.header.obb = createObbFromMbs(sourceChild.header.mbs);\n }\n\n const boundingVolume = {\n box: i3sObbTo3dTilesObb(sourceChild.header.obb, this.geoidHeightModel)\n };\n const child: Node3D = {\n boundingVolume,\n geometricError: convertScreenThresholdToGeometricError(sourceChild),\n children: []\n };\n\n const i3sAttributesData: I3SAttributesData = {\n tileContent: sourceChild.content,\n textureFormat: sourceChild?.header?.textureFormat\n };\n\n // TODO Uncomment when 3d-tiles-attributes-worker will be published on CDN.\n // const b3dm = await transform3DTilesAttributesOnWorker(i3sAttributesData, {\n // source: this.workerSource.tile3dWorkerSource,\n // featureAttributes\n // });\n\n const b3dm = await new B3dmConverter().convert(i3sAttributesData, featureAttributes);\n\n child.content = {\n uri: `${sourceChild.id}.b3dm`,\n boundingVolume\n };\n await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);\n parentNode.children.push(child);\n\n sourceChild.unloadContent();\n await this._addChildren(sourceChild, child, level + 1);\n } else {\n await this._addChildren(sourceChild, parentNode, level + 1);\n }\n }\n }\n\n /**\n * Load a child node having information from the node header\n * @param parentNode a parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param childNodeInfo child information from 3DNodeIndexDocument\n * (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodeReference.cmn.md)\n */\n private async _loadChildNode(parentNode: Tile3D, childNodeInfo: NodeReference): Promise<Tile3D> {\n let header;\n if (this.sourceTileset!.tileset.nodePages) {\n console.log(`Node conversion: ${childNodeInfo.id}`); // eslint-disable-line no-console,no-undef\n header = await this.sourceTileset!.tileset.nodePagesTile.formTileFromNodePages(\n childNodeInfo.id\n );\n } else {\n const {loader} = this.sourceTileset!;\n const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href!);\n // load metadata\n const options = {\n i3s: {\n ...this.sourceTileset!.loadOptions,\n isTileHeader: true,\n loadContent: false\n }\n };\n\n console.log(`Node conversion: ${nodeUrl}`); // eslint-disable-line no-console,no-undef\n header = await load(nodeUrl, loader, options);\n }\n return new Tile3D(this.sourceTileset!, header, parentNode);\n }\n\n /**\n * Make an url of a resource from its relative url having the base url\n * @param baseUrl the base url. A resulting url will be related from this url\n * @param relativeUrl a realtive url of a resource\n */\n private _relativeUrlToFullUrl(baseUrl: string, relativeUrl: string): string {\n let resultArray = baseUrl.split('/');\n const relativeUrlArray = relativeUrl.split('/');\n for (const folder of relativeUrlArray) {\n switch (folder) {\n case '.':\n continue; // eslint-disable-line no-continue\n case '..':\n resultArray = resultArray.slice(0, -1);\n break;\n default:\n resultArray.push(folder);\n }\n }\n return resultArray.join('/');\n }\n\n /**\n * Do loading all attributes related to particular node.\n * @param sourceChild\n * @param attributeStorageInfo\n * @returns Promise of attributes object.\n */\n private async _loadChildAttributes(\n sourceChild: Tile3D,\n attributeStorageInfo: AttributeStorageInfo\n ): Promise<FeatureAttribute> {\n const promises: any[] = [];\n const {attributeUrls} = sourceChild.header;\n\n for (let index = 0; index < attributeUrls.length; index++) {\n const inputUrl = attributeUrls[index];\n const attribute = attributeStorageInfo[index];\n const options = {\n attributeName: attribute.name,\n attributeType: this._getAttributeType(attribute)\n };\n\n promises.push(load(inputUrl, I3SAttributeLoader, options));\n }\n const attributesList = await Promise.all(promises);\n this._replaceNestedArrays(attributesList);\n return Object.assign({}, ...attributesList);\n }\n\n /**\n * Returns attribute type for loading attributes\n * @param attribute\n * Workaround for I3S v1.6. There is no attribute.attributeValues.valueType field in attribute.\n * There is an 'Oid32' type if attribute has objectIds property.\n * Doc: https://github.com/Esri/i3s-spec/blob/master/docs/1.6/attributeStorageInfo.cmn.md\n */\n private _getAttributeType(attribute: AttributeStorageInfo): string {\n if (attribute.attributeValues) {\n return attribute.attributeValues.valueType;\n } else if (attribute.objectIds) {\n return 'Oid32';\n }\n return '';\n }\n\n /**\n * Make simple arrays from attribute typed arrays.\n * @param attributesList\n */\n private _replaceNestedArrays(attributesList: FeatureAttribute[]): void {\n for (let index = 0; index < attributesList.length; index++) {\n const attributeObject = attributesList[index];\n\n for (const key in attributeObject) {\n attributeObject[key] = Array.from(attributeObject[key]);\n }\n }\n }\n\n /**\n * Print statistics in the end of conversion\n * @param params - output files data\n */\n private async _finishConversion(params: {\n slpk: boolean;\n outputPath: string;\n tilesetName: string;\n }): Promise<void> {\n const filesSize = await calculateFilesSize(params);\n const diff = process.hrtime(this.conversionStartTime);\n const conversionTime = timeConverter(diff);\n\n console.log(`------------------------------------------------`); // eslint-disable-line\n console.log(`Finish conversion of ${I3S}`); // eslint-disable-line\n console.log(`Total conversion time: ${conversionTime}`); // eslint-disable-line\n console.log(`Vertex count: `, this.vertexCounter); // eslint-disable-line\n console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line\n console.log(`------------------------------------------------`); // eslint-disable-line\n }\n\n private async loadWorkers(): Promise<void> {\n console.log(`Loading workers source...`); // eslint-disable-line no-undef, no-console\n const tile3dAttributesWorkerUrl = getWorkerURL(Tile3dAttributesWorker, {...getLoaderOptions()});\n const sourceResponse = await fetchFile(tile3dAttributesWorkerUrl);\n const source = await sourceResponse.text();\n\n this.workerSource.tile3dWorkerSource = source;\n console.log(`Loading workers source completed!`); // eslint-disable-line no-undef, no-console\n }\n}\n"],"file":"3d-tiles-converter.js"}
1
+ {"version":3,"sources":["../../../src/3d-tiles-converter/3d-tiles-converter.ts"],"names":["join","process","transform","fetchFile","getLoaderOptions","load","isBrowser","I3SLoader","I3SAttributeLoader","COORDINATE_SYSTEM","Tileset3D","Tile3D","PGMLoader","i3sObbTo3dTilesObb","convertScreenThresholdToGeometricError","writeFile","removeDir","calculateFilesSize","timeConverter","TILESET","tilesetTemplate","createObbFromMbs","Tile3dAttributesWorker","transform3DTilesAttributesOnWorker","getWorkerURL","WorkerFarm","BROWSER_ERROR_MESSAGE","I3S","Tiles3DConverter","constructor","options","tilesetPath","vertexCounter","conversionStartTime","geoidHeightModel","sourceTileset","attributeStorageInfo","workerSource","convert","console","log","inputUrl","outputPath","tilesetName","maxDepth","egmFilePath","hrtime","loadWorkers","sourceTilesetJson","loadOptions","_nodeWorkers","reuseWorkers","workerUrl","i3s","coordinateSystem","LNGLAT_OFFSETS","decodeTextures","tilesetInitializationPromise","rootNode","root","header","obb","mbs","e","rootTile","boundingVolume","box","geometricError","children","_addChildren","tileset","JSON","stringify","_finishConversion","slpk","workerFarm","getWorkerFarm","destroy","convertChildNode","parentSourceNode","parentNode","level","childNodeInfo","sourceChild","_loadChildNode","push","contentUrl","_loadTile","content","vertexCount","featureAttributes","_loadChildAttributes","child","i3sAttributesData","tileContent","textureFormat","b3dm","source","tile3dWorkerSource","uri","id","Uint8Array","unloadContent","promises","Promise","all","nodePages","nodePagesTile","formTileFromNodePages","loader","nodeUrl","_relativeUrlToFullUrl","url","href","isTileHeader","loadContent","baseUrl","relativeUrl","resultArray","split","relativeUrlArray","folder","slice","attributeUrls","index","length","attribute","attributeName","name","attributeType","_getAttributeType","attributesList","_replaceNestedArrays","Object","assign","attributeValues","valueType","objectIds","attributeObject","key","Array","from","params","filesSize","diff","conversionTime","tile3dAttributesWorkerUrl","sourceResponse","text"],"mappings":";AAGA,SAAQA,IAAR,QAAmB,MAAnB;AACA,OAAOC,OAAP,MAAoB,SAApB;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AACA,SAAQC,SAAR,EAAmBC,gBAAnB,EAAqCC,IAArC,EAA2CC,SAA3C,QAA2D,kBAA3D;AACA,SAAQC,SAAR,EAAmBC,kBAAnB,EAAuCC,iBAAvC,QAA+D,iBAA/D;AACA,SAAQC,SAAR,EAAmBC,MAAnB,QAAgC,mBAAhC;AAGA,SAAQC,SAAR,QAAwB,eAAxB;AACA,SAAQC,kBAAR,QAAiC,mCAAjC;AACA,SAAQC,sCAAR,QAAqD,mCAArD;AACA,SAAQC,SAAR,EAAmBC,SAAnB,QAAmC,yBAAnC;AACA,SAAQC,kBAAR,EAA4BC,aAA5B,QAAgD,+BAAhD;AACA,SAAQC,OAAO,IAAIC,eAAnB,QAAyC,0BAAzC;AACA,SAAQC,gBAAR,QAA+B,+CAA/B;AACA,SAEEC,sBAFF,EAGEC,kCAHF,QAIO,+BAJP;AAKA,SAAQC,YAAR,EAAsBC,UAAtB,QAAuC,0BAAvC;AACA,SAAQC,qBAAR,QAAoC,cAApC;AAEA,MAAMC,GAAG,GAAG,KAAZ;AAKA,eAAe,MAAMC,gBAAN,CAAuB;A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YAAY,CAACF,sBAAD,EAAyB,EAAC,GAAGlB,gBAAgB;AAApB,KAAzB,CAA9C;AACA,UAAM+I,cAAc,GAAG,MAAMhJ,SAAS,CAAC+I,yBAAD,CAAtC;AACA,UAAMjD,MAAM,GAAG,MAAMkD,cAAc,CAACC,IAAf,EAArB;AAEA,SAAK/G,YAAL,CAAkB6D,kBAAlB,GAAuCD,MAAvC;AACA1D,IAAAA,OAAO,CAACC,GAAR;AACD;;AAjUmC","sourcesContent":["import type {AttributeStorageInfo, FeatureAttribute, NodeReference} from '@loaders.gl/i3s';\nimport type {Node3D} from '@loaders.gl/3d-tiles';\n\nimport {join} from 'path';\nimport process from 'process';\nimport transform from 'json-map-transform';\nimport {fetchFile, getLoaderOptions, load, isBrowser} from '@loaders.gl/core';\nimport {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';\nimport {Tileset3D, Tile3D} from '@loaders.gl/tiles';\nimport {Geoid} from '@math.gl/geoid';\n\nimport {PGMLoader} from '../pgm-loader';\nimport {i3sObbTo3dTilesObb} from './helpers/i3s-obb-to-3d-tiles-obb';\nimport {convertScreenThresholdToGeometricError} from '../lib/utils/lod-conversion-utils';\nimport {writeFile, removeDir} from '../lib/utils/file-utils';\nimport {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';\nimport {TILESET as tilesetTemplate} from './json-templates/tileset';\nimport {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';\nimport {\n I3SAttributesData,\n Tile3dAttributesWorker,\n transform3DTilesAttributesOnWorker\n} from '../3d-tiles-attributes-worker';\nimport {getWorkerURL, WorkerFarm} from '@loaders.gl/worker-utils';\nimport {BROWSER_ERROR_MESSAGE} from '../constants';\n\nconst I3S = 'I3S';\n\n/**\n * Converter from i3s to 3d-tiles\n */\nexport default class Tiles3DConverter {\n options: any;\n tilesetPath: string;\n vertexCounter: number;\n conversionStartTime: [number, number];\n geoidHeightModel: Geoid | null;\n sourceTileset: Tileset3D | null;\n attributeStorageInfo: AttributeStorageInfo | null;\n workerSource: {[key: string]: string} = {};\n\n constructor() {\n this.options = {};\n this.tilesetPath = '';\n this.vertexCounter = 0;\n this.conversionStartTime = [0, 0];\n this.geoidHeightModel = null;\n this.sourceTileset = null;\n this.attributeStorageInfo = null;\n this.workerSource = {};\n }\n\n /**\n * Convert i3s format data to 3dTiles\n * @param options\n * @param options.inputUrl the url to read the tileset from\n * @param options.outputPath the output filename\n * @param options.tilesetName the output name of the tileset\n * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format\n * @param options.maxDepth The max tree depth of conversion\n */\n public async convert(options: {\n inputUrl: string;\n outputPath: string;\n tilesetName: string;\n maxDepth?: number;\n egmFilePath: string;\n }): Promise<any> {\n if (isBrowser) {\n console.log(BROWSER_ERROR_MESSAGE);\n return BROWSER_ERROR_MESSAGE;\n }\n const {inputUrl, outputPath, tilesetName, maxDepth, egmFilePath} = options;\n this.conversionStartTime = process.hrtime();\n this.options = {maxDepth};\n\n console.log('Loading egm file...'); // eslint-disable-line\n this.geoidHeightModel = await load(egmFilePath, PGMLoader);\n console.log('Loading egm file completed!'); // eslint-disable-line\n\n await this.loadWorkers();\n\n const sourceTilesetJson = await load(inputUrl, I3SLoader, {});\n\n this.sourceTileset = new Tileset3D(sourceTilesetJson, {\n loadOptions: {\n _nodeWorkers: true,\n reuseWorkers: true,\n 'i3s-content-nodejs': {\n workerUrl: './modules/i3s/dist/i3s-content-nodejs-worker.js'\n },\n i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false}\n }\n });\n\n await this.sourceTileset.tilesetInitializationPromise;\n const rootNode = this.sourceTileset.root!;\n if (!rootNode.header.obb) {\n rootNode.header.obb = createObbFromMbs(rootNode.header.mbs);\n }\n\n this.tilesetPath = join(`${outputPath}`, `${tilesetName}`);\n this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;\n // Removing the tilesetPath needed to exclude erroneous files after conversion\n try {\n await removeDir(this.tilesetPath);\n } catch (e) {\n // do nothing\n }\n\n const rootTile: Node3D = {\n boundingVolume: {\n box: i3sObbTo3dTilesObb(rootNode.header.obb, this.geoidHeightModel)\n },\n geometricError: convertScreenThresholdToGeometricError(rootNode),\n children: []\n };\n\n await this._addChildren(rootNode, rootTile, 1);\n\n const tileset = transform({root: rootTile}, tilesetTemplate());\n await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');\n\n this._finishConversion({slpk: false, outputPath, tilesetName});\n\n // Clean up worker pools\n const workerFarm = WorkerFarm.getWorkerFarm({});\n workerFarm.destroy();\n }\n\n /**\n * Convert particular I3S Node\n * @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param parentNode object in resulting tileset\n * @param level a current level of a tree depth\n * @param childNodeInfo child node to convert\n */\n private async convertChildNode(\n parentSourceNode: Tile3D,\n parentNode: Node3D,\n level: number,\n childNodeInfo: NodeReference\n ): Promise<void> {\n const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);\n parentSourceNode.children.push(sourceChild);\n if (sourceChild.contentUrl) {\n await this.sourceTileset!._loadTile(sourceChild);\n this.vertexCounter += sourceChild.content.vertexCount;\n\n let featureAttributes: FeatureAttribute | null = null;\n if (this.attributeStorageInfo) {\n featureAttributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);\n }\n\n if (!sourceChild.header.obb) {\n sourceChild.header.obb = createObbFromMbs(sourceChild.header.mbs);\n }\n\n const boundingVolume = {\n box: i3sObbTo3dTilesObb(sourceChild.header.obb, this.geoidHeightModel)\n };\n const child: Node3D = {\n boundingVolume,\n geometricError: convertScreenThresholdToGeometricError(sourceChild),\n children: []\n };\n\n const i3sAttributesData: I3SAttributesData = {\n tileContent: sourceChild.content,\n textureFormat: sourceChild?.header?.textureFormat\n };\n\n const b3dm = await transform3DTilesAttributesOnWorker(i3sAttributesData, {\n source: this.workerSource.tile3dWorkerSource,\n featureAttributes\n });\n\n child.content = {\n uri: `${sourceChild.id}.b3dm`,\n boundingVolume\n };\n await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);\n parentNode.children.push(child);\n\n sourceChild.unloadContent();\n await this._addChildren(sourceChild, child, level + 1);\n } else {\n await this._addChildren(sourceChild, parentNode, level + 1);\n }\n }\n\n /**\n * The recursive function of traversal of a nodes tree\n * @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param parentNode object in resulting tileset\n * @param level a current level of a tree depth\n */\n private async _addChildren(\n parentSourceNode: Tile3D,\n parentNode: Node3D,\n level: number\n ): Promise<void> {\n if (this.options.maxDepth && level > this.options.maxDepth) {\n return;\n }\n const promises: Promise<void>[] = [];\n for (const childNodeInfo of parentSourceNode.header.children || []) {\n promises.push(this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo));\n }\n await Promise.all(promises);\n }\n\n /**\n * Load a child node having information from the node header\n * @param parentNode a parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param childNodeInfo child information from 3DNodeIndexDocument\n * (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodeReference.cmn.md)\n */\n private async _loadChildNode(parentNode: Tile3D, childNodeInfo: NodeReference): Promise<Tile3D> {\n let header;\n if (this.sourceTileset!.tileset.nodePages) {\n console.log(`Node conversion: ${childNodeInfo.id}`); // eslint-disable-line no-console,no-undef\n header = await this.sourceTileset!.tileset.nodePagesTile.formTileFromNodePages(\n childNodeInfo.id\n );\n } else {\n const {loader} = this.sourceTileset!;\n const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href!);\n // load metadata\n const options = {\n i3s: {\n ...this.sourceTileset!.loadOptions,\n isTileHeader: true,\n loadContent: false\n }\n };\n\n console.log(`Node conversion: ${nodeUrl}`); // eslint-disable-line no-console,no-undef\n header = await load(nodeUrl, loader, options);\n }\n return new Tile3D(this.sourceTileset!, header, parentNode);\n }\n\n /**\n * Make an url of a resource from its relative url having the base url\n * @param baseUrl the base url. A resulting url will be related from this url\n * @param relativeUrl a realtive url of a resource\n */\n private _relativeUrlToFullUrl(baseUrl: string, relativeUrl: string): string {\n let resultArray = baseUrl.split('/');\n const relativeUrlArray = relativeUrl.split('/');\n for (const folder of relativeUrlArray) {\n switch (folder) {\n case '.':\n continue; // eslint-disable-line no-continue\n case '..':\n resultArray = resultArray.slice(0, -1);\n break;\n default:\n resultArray.push(folder);\n }\n }\n return resultArray.join('/');\n }\n\n /**\n * Do loading all attributes related to particular node.\n * @param sourceChild\n * @param attributeStorageInfo\n * @returns Promise of attributes object.\n */\n private async _loadChildAttributes(\n sourceChild: Tile3D,\n attributeStorageInfo: AttributeStorageInfo\n ): Promise<FeatureAttribute> {\n const promises: any[] = [];\n const {attributeUrls} = sourceChild.header;\n\n for (let index = 0; index < attributeUrls.length; index++) {\n const inputUrl = attributeUrls[index];\n const attribute = attributeStorageInfo[index];\n const options = {\n attributeName: attribute.name,\n attributeType: this._getAttributeType(attribute)\n };\n\n promises.push(load(inputUrl, I3SAttributeLoader, options));\n }\n const attributesList = await Promise.all(promises);\n this._replaceNestedArrays(attributesList);\n return Object.assign({}, ...attributesList);\n }\n\n /**\n * Returns attribute type for loading attributes\n * @param attribute\n * Workaround for I3S v1.6. There is no attribute.attributeValues.valueType field in attribute.\n * There is an 'Oid32' type if attribute has objectIds property.\n * Doc: https://github.com/Esri/i3s-spec/blob/master/docs/1.6/attributeStorageInfo.cmn.md\n */\n private _getAttributeType(attribute: AttributeStorageInfo): string {\n if (attribute.attributeValues) {\n return attribute.attributeValues.valueType;\n } else if (attribute.objectIds) {\n return 'Oid32';\n }\n return '';\n }\n\n /**\n * Make simple arrays from attribute typed arrays.\n * @param attributesList\n */\n private _replaceNestedArrays(attributesList: FeatureAttribute[]): void {\n for (let index = 0; index < attributesList.length; index++) {\n const attributeObject = attributesList[index];\n\n for (const key in attributeObject) {\n attributeObject[key] = Array.from(attributeObject[key]);\n }\n }\n }\n\n /**\n * Print statistics in the end of conversion\n * @param params - output files data\n */\n private async _finishConversion(params: {\n slpk: boolean;\n outputPath: string;\n tilesetName: string;\n }): Promise<void> {\n const filesSize = await calculateFilesSize(params);\n const diff = process.hrtime(this.conversionStartTime);\n const conversionTime = timeConverter(diff);\n\n console.log(`------------------------------------------------`); // eslint-disable-line\n console.log(`Finish conversion of ${I3S}`); // eslint-disable-line\n console.log(`Total conversion time: ${conversionTime}`); // eslint-disable-line\n console.log(`Vertex count: `, this.vertexCounter); // eslint-disable-line\n console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line\n console.log(`------------------------------------------------`); // eslint-disable-line\n }\n\n private async loadWorkers(): Promise<void> {\n console.log(`Loading workers source...`); // eslint-disable-line no-undef, no-console\n const tile3dAttributesWorkerUrl = getWorkerURL(Tile3dAttributesWorker, {...getLoaderOptions()});\n const sourceResponse = await fetchFile(tile3dAttributesWorkerUrl);\n const source = await sourceResponse.text();\n\n this.workerSource.tile3dWorkerSource = source;\n console.log(`Loading workers source completed!`); // eslint-disable-line no-undef, no-console\n }\n}\n"],"file":"3d-tiles-converter.js"}
@@ -1,10 +1,11 @@
1
- import { load } from '@loaders.gl/core';
1
+ import { load, fetchFile } from '@loaders.gl/core';
2
2
  import { ZipLoader } from '@loaders.gl/zip';
3
3
  import { writeFile } from '../lib/utils/file-utils';
4
4
  import { join } from 'path';
5
+ const VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'beta';
5
6
  const PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';
6
7
  export class DepsInstaller {
7
- async install(path = '') {
8
+ async install(path = '', workersPath = '') {
8
9
  console.log('Installing "EGM2008-5" model...');
9
10
  const fileMap = await load(PGM_LINK, ZipLoader, {});
10
11
  let depsPath = process.cwd();
@@ -14,8 +15,26 @@ export class DepsInstaller {
14
15
  }
15
16
 
16
17
  await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');
18
+ console.log('Installing "I3S Content Loader worker"');
19
+ await this.installWorker('i3s', 'i3s-content-nodejs-worker.js', workersPath);
20
+ console.log('Installing "Draco Loader worker"');
21
+ await this.installWorker('draco', 'draco-nodejs-worker.js', workersPath);
22
+ console.log('Installing "Basis Loader worker"');
23
+ await this.installWorker('textures', 'basis-nodejs-worker.js', workersPath);
17
24
  console.log('All dependencies were installed succesfully.');
18
25
  }
19
26
 
27
+ async installWorker(module, name, extraPath) {
28
+ const fileResponse = await fetchFile("https://unpkg.com/@loaders.gl/".concat(module, "@").concat(VERSION, "/dist/").concat(name));
29
+ const fileData = await fileResponse.arrayBuffer();
30
+
31
+ if (!fileData) {
32
+ return;
33
+ }
34
+
35
+ const path = join(process.cwd(), extraPath, 'modules', module, 'dist');
36
+ await writeFile(path, fileData, name);
37
+ }
38
+
20
39
  }
21
40
  //# sourceMappingURL=deps-installer.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/deps-installer/deps-installer.ts"],"names":["load","ZipLoader","writeFile","join","PGM_LINK","DepsInstaller","install","path","console","log","fileMap","depsPath","process","cwd","Uint8Array"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,kBAAnB;AACA,SAAQC,SAAR,QAAwB,iBAAxB;AACA,SAAQC,SAAR,QAAwB,yBAAxB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAEA,MAAMC,QAAQ,GAAG,+EAAjB;AAQA,OAAO,MAAMC,aAAN,CAAoB;AAKZ,QAAPC,OAAO,CAACC,IAAY,GAAG,EAAhB,EAAmC;AAC9CC,IAAAA,OAAO,CAACC,GAAR,CAAY,iCAAZ;AACA,UAAMC,OAAO,GAAG,MAAMV,IAAI,CAACI,QAAD,EAAWH,SAAX,EAAsB,EAAtB,CAA1B;AAEA,QAAIU,QAAQ,GAAGC,OAAO,CAACC,GAAR,EAAf;;AACA,QAAIN,IAAJ,EAAU;AACRI,MAAAA,QAAQ,GAAGR,IAAI,CAACQ,QAAD,EAAWJ,IAAX,CAAf;AACD;;AAED,UAAML,SAAS,CAACS,QAAD,EAAW,IAAIG,UAAJ,CAAeJ,OAAO,CAAC,sBAAD,CAAtB,CAAX,EAA4D,eAA5D,CAAf;AAEAF,IAAAA,OAAO,CAACC,GAAR,CAAY,8CAAZ;AACD;;AAjBwB","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {ZipLoader} from '@loaders.gl/zip';\nimport {writeFile} from '../lib/utils/file-utils';\nimport {join} from 'path';\n\nconst PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';\n\n/**\n * Install external dependencies for converter:\n * * PGM file (implemented);\n * * Draco library (not implemented);\n * * 7z archiver (not implemented);\n */\nexport class DepsInstaller {\n /**\n * Run instalation\n * @param path destination folder\n */\n async install(path: string = ''): Promise<void> {\n console.log('Installing \"EGM2008-5\" model...'); // eslint-disable-line no-console\n const fileMap = await load(PGM_LINK, ZipLoader, {});\n\n let depsPath = process.cwd();\n if (path) {\n depsPath = join(depsPath, path);\n }\n\n await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');\n\n console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console\n }\n}\n"],"file":"deps-installer.js"}
1
+ {"version":3,"sources":["../../../src/deps-installer/deps-installer.ts"],"names":["load","fetchFile","ZipLoader","writeFile","join","VERSION","PGM_LINK","DepsInstaller","install","path","workersPath","console","log","fileMap","depsPath","process","cwd","Uint8Array","installWorker","module","name","extraPath","fileResponse","fileData","arrayBuffer"],"mappings":"AAAA,SAAQA,IAAR,EAAcC,SAAd,QAA8B,kBAA9B;AACA,SAAQC,SAAR,QAAwB,iBAAxB;AACA,SAAQC,SAAR,QAAwB,yBAAxB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAGA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,MAAnE;AAEA,MAAMC,QAAQ,GAAG,+EAAjB;AAQA,OAAO,MAAMC,aAAN,CAAoB;AAQZ,QAAPC,OAAO,CAACC,IAA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A8C,MAA9C,CAAjB;AACA,UAAMhB,SAAS,CAACM,IAAD,EAAOc,QAAP,EAAiBH,IAAjB,CAAf;AACD;;AAzCwB","sourcesContent":["import {load, fetchFile} from '@loaders.gl/core';\nimport {ZipLoader} from '@loaders.gl/zip';\nimport {writeFile} from '../lib/utils/file-utils';\nimport {join} from 'path';\n\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'beta';\n\nconst PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';\n\n/**\n * Install external dependencies for converter:\n * * PGM file (implemented);\n * * Draco library (not implemented);\n * * 7z archiver (not implemented);\n */\nexport class DepsInstaller {\n /**\n * Run instalation\n * @param path destination folder\n * @param workersPath destination folder for workers.\n * This path is '' by default and is not used by tile-converter.\n * It is used in tests to prevent rewriting actual workers during tests running\n */\n async install(path: string = '', workersPath: string = ''): Promise<void> {\n console.log('Installing \"EGM2008-5\" model...'); // eslint-disable-line no-console\n const fileMap = await load(PGM_LINK, ZipLoader, {});\n\n let depsPath = process.cwd();\n if (path) {\n depsPath = join(depsPath, path);\n }\n\n await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');\n\n console.log('Installing \"I3S Content Loader worker\"'); // eslint-disable-line no-console\n await this.installWorker('i3s', 'i3s-content-nodejs-worker.js', workersPath);\n\n console.log('Installing \"Draco Loader worker\"'); // eslint-disable-line no-console\n await this.installWorker('draco', 'draco-nodejs-worker.js', workersPath);\n\n console.log('Installing \"Basis Loader worker\"'); // eslint-disable-line no-console\n await this.installWorker('textures', 'basis-nodejs-worker.js', workersPath);\n\n console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console\n }\n\n private async installWorker(module: string, name: string, extraPath: string) {\n const fileResponse = await fetchFile(\n `https://unpkg.com/@loaders.gl/${module}@${VERSION}/dist/${name}`\n );\n const fileData = await fileResponse.arrayBuffer();\n if (!fileData) {\n return;\n }\n const path = join(process.cwd(), extraPath, 'modules', module, 'dist');\n await writeFile(path, fileData, name);\n }\n}\n"],"file":"deps-installer.js"}
@@ -1,5 +1,5 @@
1
1
  import { processOnWorker } from '@loaders.gl/worker-utils';
2
- const VERSION = typeof "3.3.0-alpha.3" !== 'undefined' ? "3.3.0-alpha.3" : 'latest';
2
+ const VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
3
3
  export const I3SAttributesWorker = {
4
4
  id: 'i3s-attributes',
5
5
  name: 'I3S Attributes Worker',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/i3s-attributes-worker.ts"],"names":["processOnWorker","VERSION","I3SAttributesWorker","id","name","module","version","options","useCartesianPositions","transformI3SAttributesOnWorker","attributesData","_typecheckI3SAttributesWorker"],"mappings":"AAIA,SAAQA,eAAR,QAA8B,0BAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAiBA,OAAO,MAAMC,mBAAmB,GAAG;AACjCC,EAAAA,EAAE,EAAE,gBAD6B;AAEjCC,EAAAA,IAAI,EAAE,uBAF2B;AAGjCC,EAAAA,MAAM,EAAE,gBAHyB;AAIjCC,EAAAA,OAAO,EAAEL,OAJwB;AAKjCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,qBAAqB,EAAE;AADhB;AALwB,CAA5B;AAaP,OAAO,SAASC,8BAAT,CACLC,cADK,EAELH,OAFK,EAGsC;AAC3C,SAAOP,eAAe,CAACE,mBAAD,EAAsBQ,cAAtB,EAAsCH,OAAtC,CAAtB;AACD;AAED,OAAO,MAAMI,6BAA2C,GAAGT,mBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {ConvertedAttributes} from './i3s-converter/types';\nimport type {Matrix4, Vector3} from '@math.gl/core';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type I3SAttributesWorkerOptions = {\n useCartesianPositions: boolean;\n source: string;\n};\n\nexport type B3DMAttributesData = {\n gltfMaterials?: {id: string}[];\n nodes: any;\n cartographicOrigin: Vector3;\n cartesianModelMatrix: Matrix4;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const I3SAttributesWorker = {\n id: 'i3s-attributes',\n name: 'I3S Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n useCartesianPositions: false\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transformI3SAttributesOnWorker(\n attributesData: B3DMAttributesData,\n options: I3SAttributesWorkerOptions\n): Promise<Map<string, ConvertedAttributes>> {\n return processOnWorker(I3SAttributesWorker, attributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = I3SAttributesWorker;\n"],"file":"i3s-attributes-worker.js"}
1
+ {"version":3,"sources":["../../src/i3s-attributes-worker.ts"],"names":["processOnWorker","VERSION","I3SAttributesWorker","id","name","module","version","options","useCartesianPositions","transformI3SAttributesOnWorker","attributesData","_typecheckI3SAttributesWorker"],"mappings":"AAKA,SAAQA,eAAR,QAA8B,0BAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAoBA,OAAO,MAAMC,mBAAmB,GAAG;AACjCC,EAAAA,EAAE,EAAE,gBAD6B;AAEjCC,EAAAA,IAAI,EAAE,uBAF2B;AAGjCC,EAAAA,MAAM,EAAE,gBAHyB;AAIjCC,EAAAA,OAAO,EAAEL,OAJwB;AAKjCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,qBAAqB,EAAE;AADhB;AALwB,CAA5B;AAaP,OAAO,SAASC,8BAAT,CACLC,cADK,EAELH,OAFK,EAGsC;AAC3C,SAAOP,eAAe,CAACE,mBAAD,EAAsBQ,cAAtB,EAAsCH,OAAtC,CAAtB;AACD;AAED,OAAO,MAAMI,6BAA2C,GAAGT,mBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {ConvertedAttributes} from './i3s-converter/types';\nimport type {Matrix4, Vector3} from '@math.gl/core';\nimport type {GLTFImagePostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type I3SAttributesWorkerOptions = {\n _nodeWorkers: boolean;\n reuseWorkers: boolean;\n useCartesianPositions: boolean;\n source: string;\n};\n\nexport type B3DMAttributesData = {\n gltfMaterials?: {id: string}[];\n nodes: GLTFNodePostprocessed[];\n images: GLTFImagePostprocessed[];\n cartographicOrigin: Vector3;\n cartesianModelMatrix: Matrix4;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const I3SAttributesWorker = {\n id: 'i3s-attributes',\n name: 'I3S Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n useCartesianPositions: false\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transformI3SAttributesOnWorker(\n attributesData: B3DMAttributesData,\n options: I3SAttributesWorkerOptions\n): Promise<Map<string, ConvertedAttributes>> {\n return processOnWorker(I3SAttributesWorker, attributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = I3SAttributesWorker;\n"],"file":"i3s-attributes-worker.js"}
@@ -88,6 +88,10 @@ function generateImplicitFeatureIds(featuresCount, constant = 0, divisor = 0) {
88
88
  function generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images) {
89
89
  var _featureIdTexture$fea3, _featureIdTexture$fea4, _featureIdTexture$fea5;
90
90
 
91
+ if (!(images !== null && images !== void 0 && images.length)) {
92
+ return [];
93
+ }
94
+
91
95
  const CHANNELS_MAP = {
92
96
  r: 0,
93
97
  g: 1,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"names":["EXT_MESH_FEATURES","EXT_FEATURE_METADATA","handleBatchIdsExtensions","attributes","primitive","images","extensions","extensionName","extensionData","Object","entries","handleExtFeatureMetadataExtension","console","warn","extFeatureMetadata","featureIdAttribute","featureIdAttributes","featureIds","attribute","batchIdsAttribute","value","hasOwnProperty","featuresCount","POSITIONS","length","generateImplicitFeatureIds","constant","divisor","featureIdTexture","featureIdTextures","textureAttributeIndex","texture","texCoord","textCoordAttribute","textureCoordinates","generateBatchIdsFromTexture","featureTexture","featureTextures","currentValue","devisorCounter","index","push","Array","fill","CHANNELS_MAP","r","g","b","a","textureIndex","featureChannel","channels","undefined","image","batchIds","compressed","u","v","tx","Math","min","emod","width","ty","height","offset","components","batchId","Uint8Array","data","mimeType","n"],"mappings":"AAOA,MAAMA,iBAAiB,GAAG,mBAA1B;AACA,MAAMC,oBAAoB,GAAG,sBAA7B;AAQA,OAAO,SAASC,wBAAT,CACLC,UADK,EAILC,SAJK,EAKLC,MALK,EAMK;AACV,QAAMC,UAAU,GAAGF,SAAH,aAAGA,SAAH,uBAAGA,SAAS,CAAEE,UAA9B;;AAEA,MAAI,CAACA,UAAL,EAAiB;AACf,WAAO,EAAP;AACD;;AAED,OAAK,MAAM,CAACC,aAAD,EAAgBC,aAAhB,CAAX,IAA6CC,MAAM,CAACC,OAAP,CAAeJ,UAAU,IAAI,EAA7B,CAA7C,EAA+E;AAC7E,YAAQC,aAAR;AACE,WAAKN,oBAAL;AACE,eAAOU,iCAAiC,CACtCR,UADsC,EAEtCK,aAFsC,EAGtCH,MAHsC,CAAxC;;AAKF,WAAKL,iBAAL;AACEY,QAAAA,OAAO,CAACC,IAAR,CAAa,kDAAb;AACA,eAAO,EAAP;;AACF;AACE,eAAO,EAAP;AAXJ;AAaD;;AAED,SAAO,EAAP;AACD;;AASD,SAASF,iCAAT,CACER,UADF,EA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J,GAAUJ,KAAK,CAACW,MAAjB,GAA2B,CAApC,EAAuCX,KAAK,CAACW,MAAN,GAAe,CAAtD,CAAX;AAEA,YAAMC,MAAM,GAAG,CAACF,EAAE,GAAGV,KAAK,CAACS,KAAX,GAAmBJ,EAApB,IAA0BL,KAAK,CAACa,UAAhC,GAA6Cf,QAA5D;AACA,YAAMgB,OAAO,GAAG,IAAIC,UAAJ,CAAef,KAAK,CAACgB,IAArB,EAA2BJ,MAA3B,CAAhB;AAEAX,MAAAA,QAAQ,CAACb,IAAT,CAAc0B,OAAd;AACD;AACF,GAbD,MAaO;AACLvD,IAAAA,OAAO,CAACC,IAAR,oCAAyCwC,KAAK,CAACiB,QAA/C;AACD;;AAED,SAAOhB,QAAP;AACD;;AAOD,SAASO,IAAT,CAAcU,CAAd,EAAiC;AAC/B,SAAO,CAAEA,CAAC,GAAG,CAAL,GAAU,CAAX,IAAgB,CAAvB;AACD","sourcesContent":["import type {GLTFAccessorPostprocessed} from 'modules/gltf/src/lib/types/gltf-types';\nimport type {Image, MeshPrimitive} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';\nimport type {\n GLTF_EXT_feature_metadata_attribute,\n GLTF_EXT_feature_metadata_primitive\n} from 'modules/gltf/src/lib/types/gltf-json-schema';\n\nconst EXT_MESH_FEATURES = 'EXT_mesh_features';\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\n/**\n * Getting batchIds from 3DTilesNext extensions.\n * @param attributes\n * @param primitive\n * @param textures\n */\nexport function handleBatchIdsExtensions(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n primitive: MeshPrimitive,\n images: Image[]\n): number[] {\n const extensions = primitive?.extensions;\n\n if (!extensions) {\n return [];\n }\n\n for (const [extensionName, extensionData] of Object.entries(extensions || {})) {\n switch (extensionName) {\n case EXT_FEATURE_METADATA:\n return handleExtFeatureMetadataExtension(\n attributes,\n extensionData as GLTF_EXT_feature_metadata_primitive,\n images\n );\n case EXT_MESH_FEATURES:\n console.warn('EXT_mesh_features extension is not supported yet');\n return [];\n default:\n return [];\n }\n }\n\n return [];\n}\n\n/**\n * Get batchIds from EXT_feature_metadata extension.\n * Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n * @param attributes\n * @param extFeatureMetadata\n * @param textures\n */\nfunction handleExtFeatureMetadataExtension(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n extFeatureMetadata: GLTF_EXT_feature_metadata_primitive,\n images: Image[]\n): number[] {\n // Take only first extension object to get batchIds attribute name.\n const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];\n\n if (featureIdAttribute?.featureIds?.attribute) {\n const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];\n return batchIdsAttribute.value;\n }\n\n if (\n featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&\n featureIdAttribute?.featureIds?.hasOwnProperty('divisor')\n ) {\n const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;\n return generateImplicitFeatureIds(\n featuresCount,\n featureIdAttribute.featureIds.constant,\n featureIdAttribute.featureIds.divisor\n );\n }\n\n // Take only first extension object to get batchIds attribute name.\n const featureIdTexture =\n extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];\n\n if (featureIdTexture) {\n const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;\n const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;\n const textureCoordinates = attributes[textCoordAttribute].value;\n return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);\n }\n\n // Take only first extension texture to get batchIds from the root EXT_feature_metadata object.\n const featureTexture =\n extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];\n\n /**\n * TODO need to get batchIds from root extension\n */\n if (featureTexture) {\n console.warn(\"EXT_feature_metadata doesn't yet support featureTextures in primitive\");\n return [];\n }\n\n return [];\n}\n\n/**\n * Generates implicit feature ids\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids\n * @param featuresCount\n * @param constant\n * @param devisor\n */\nfunction generateImplicitFeatureIds(\n featuresCount: number,\n constant: number = 0,\n divisor: number = 0\n): number[] {\n let featureIds: number[] = [];\n\n if (divisor > 0) {\n let currentValue = constant;\n let devisorCounter = divisor;\n\n for (let index = 0; index < featuresCount; index++) {\n featureIds.push(currentValue);\n\n devisorCounter -= 1;\n\n if (devisorCounter === 0) {\n currentValue++;\n devisorCounter = divisor;\n }\n }\n } else {\n featureIds = Array<number>(featuresCount).fill(constant, 0, featuresCount);\n }\n\n return featureIds;\n}\n\n/**\n * Get batchIds from texture.\n * @param primitive\n * @param featureIdTextures\n */\nfunction generateBatchIdsFromTexture(\n featureIdTexture: GLTF_EXT_feature_metadata_attribute,\n textureCoordinates: Float32Array,\n images: Image[]\n) {\n const CHANNELS_MAP = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n };\n\n const textureIndex = featureIdTexture?.featureIds?.texture?.index;\n const featureChannel = featureIdTexture?.featureIds?.channels;\n\n if (!featureChannel || textureIndex === undefined) {\n return [];\n }\n\n const image = images[textureIndex];\n const batchIds: number[] = [];\n const channels = CHANNELS_MAP[featureChannel];\n\n if (!image.compressed) {\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);\n const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);\n\n const offset = (ty * image.width + tx) * image.components + channels;\n const batchId = new Uint8Array(image.data)[offset];\n\n batchIds.push(batchId);\n }\n } else {\n console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);\n }\n\n return batchIds;\n}\n\n/**\n * Handle UVs if they are out of range [0,1].\n * @param n\n * @param m\n */\nfunction emod(n: number): number {\n return ((n % 1) + 1) % 1;\n}\n"],"file":"batch-ids-extensions.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"names":["EXT_MESH_FEATURES","EXT_FEATURE_METADATA","handleBatchIdsExtensions","attributes","primitive","images","extensions","extensionName","extensionData","Object","entries","handleExtFeatureMetadataExtension","console","warn","extFeatureMetadata","featureIdAttribute","featureIdAttributes","featureIds","attribute","batchIdsAttribute","value","hasOwnProperty","featuresCount","POSITIONS","length","generateImplicitFeatureIds","constant","divisor","featureIdTexture","featureIdTextures","textureAttributeIndex","texture","texCoord","textCoordAttribute","textureCoordinates","generateBatchIdsFromTexture","featureTexture","featureTextures","currentValue","devisorCounter","index","push","Array","fill","CHANNELS_MAP","r","g","b","a","textureIndex","featureChannel","channels","undefined","image","batchIds","compressed","u","v","tx","Math","min","emod","width","ty","height","offset","components","batchId","Uint8Array","data","mimeType","n"],"mappings":"AAUA,MAAMA,iBAAiB,GAAG,mBAA1B;AACA,MAAMC,oBAAoB,GAAG,sBAA7B;AAQA,OAAO,SAASC,wBAAT,CACLC,UADK,EAILC,SAJK,EAKLC,MALK,EAMK;AACV,QAAMC,UAAU,GAAGF,SAAH,aAAGA,SAAH,uBAAGA,SAAS,CAAEE,UAA9B;;AAEA,MAAI,CAACA,UAAL,EAAiB;AACf,WAAO,EAAP;AACD;;AAED,OAAK,MAAM,CAACC,aAAD,EAAgBC,aAAhB,CAAX,IAA6CC,MAAM,CAACC,OAAP,CAAeJ,UAAU,IAAI,EAA7B,CAA7C,EAA+E;AAC7E,YAAQC,aAAR;AACE,WAAKN,oBAAL;AACE,eAAOU,iCAAiC,CACtCR,UADsC,EAEtCK,aAFsC,EAGtCH,MAHsC,CAAxC;;AAKF,WAAKL,iBAAL;AACEY,QAAAA,OAAO,CAACC,IAAR,CAAa,kDAAb;AACA,eAAO,EAAP;;AACF;AACE,eAAO,EAAP;AAXJ;AAaD;;AAED,SAAO,EAAP;AACD;;AASD,SAASF,iCAAT,CACER,UADF,EAIEW,kBAJF,EAKET,MALF,EAMY;AAAA;;AAEV,QAAMU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J,IAAI,CAACC,GAAL,CAAUC,IAAI,CAACJ,CAAD,CAAJ,GAAUJ,KAAK,CAACW,MAAjB,GAA2B,CAApC,EAAuCX,KAAK,CAACW,MAAN,GAAe,CAAtD,CAAX;AAEA,YAAMC,MAAM,GAAG,CAACF,EAAE,GAAGV,KAAK,CAACS,KAAX,GAAmBJ,EAApB,IAA0BL,KAAK,CAACa,UAAhC,GAA6Cf,QAA5D;AACA,YAAMgB,OAAO,GAAG,IAAIC,UAAJ,CAAef,KAAK,CAACgB,IAArB,EAA2BJ,MAA3B,CAAhB;AAEAX,MAAAA,QAAQ,CAACb,IAAT,CAAc0B,OAAd;AACD;AACF,GAbD,MAaO;AACLvD,IAAAA,OAAO,CAACC,IAAR,oCAAyCwC,KAAK,CAACiB,QAA/C;AACD;;AAED,SAAOhB,QAAP;AACD;;AAOD,SAASO,IAAT,CAAcU,CAAd,EAAiC;AAC/B,SAAO,CAAEA,CAAC,GAAG,CAAL,GAAU,CAAX,IAAgB,CAAvB;AACD","sourcesContent":["import {\n GLTFAccessorPostprocessed,\n GLTFImagePostprocessed,\n GLTFMeshPrimitivePostprocessed\n} from '@loaders.gl/gltf';\nimport type {\n GLTF_EXT_feature_metadata_attribute,\n GLTF_EXT_feature_metadata_primitive\n} from 'modules/gltf/src/lib/types/gltf-json-schema';\n\nconst EXT_MESH_FEATURES = 'EXT_mesh_features';\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\n\n/**\n * Getting batchIds from 3DTilesNext extensions.\n * @param attributes\n * @param primitive\n * @param textures\n */\nexport function handleBatchIdsExtensions(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n primitive: GLTFMeshPrimitivePostprocessed,\n images: GLTFImagePostprocessed[]\n): number[] {\n const extensions = primitive?.extensions;\n\n if (!extensions) {\n return [];\n }\n\n for (const [extensionName, extensionData] of Object.entries(extensions || {})) {\n switch (extensionName) {\n case EXT_FEATURE_METADATA:\n return handleExtFeatureMetadataExtension(\n attributes,\n extensionData as GLTF_EXT_feature_metadata_primitive,\n images\n );\n case EXT_MESH_FEATURES:\n console.warn('EXT_mesh_features extension is not supported yet');\n return [];\n default:\n return [];\n }\n }\n\n return [];\n}\n\n/**\n * Get batchIds from EXT_feature_metadata extension.\n * Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n * @param attributes\n * @param extFeatureMetadata\n * @param textures\n */\nfunction handleExtFeatureMetadataExtension(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n extFeatureMetadata: GLTF_EXT_feature_metadata_primitive,\n images: GLTFImagePostprocessed[]\n): number[] {\n // Take only first extension object to get batchIds attribute name.\n const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];\n\n if (featureIdAttribute?.featureIds?.attribute) {\n const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];\n return batchIdsAttribute.value;\n }\n\n if (\n featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&\n featureIdAttribute?.featureIds?.hasOwnProperty('divisor')\n ) {\n const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;\n return generateImplicitFeatureIds(\n featuresCount,\n featureIdAttribute.featureIds.constant,\n featureIdAttribute.featureIds.divisor\n );\n }\n\n // Take only first extension object to get batchIds attribute name.\n const featureIdTexture =\n extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];\n\n if (featureIdTexture) {\n const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;\n const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;\n const textureCoordinates = attributes[textCoordAttribute].value;\n return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);\n }\n\n // Take only first extension texture to get batchIds from the root EXT_feature_metadata object.\n const featureTexture =\n extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];\n\n /**\n * TODO need to get batchIds from root extension\n */\n if (featureTexture) {\n console.warn(\"EXT_feature_metadata doesn't yet support featureTextures in primitive\");\n return [];\n }\n\n return [];\n}\n\n/**\n * Generates implicit feature ids\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids\n * @param featuresCount\n * @param constant\n * @param devisor\n */\nfunction generateImplicitFeatureIds(\n featuresCount: number,\n constant: number = 0,\n divisor: number = 0\n): number[] {\n let featureIds: number[] = [];\n\n if (divisor > 0) {\n let currentValue = constant;\n let devisorCounter = divisor;\n\n for (let index = 0; index < featuresCount; index++) {\n featureIds.push(currentValue);\n\n devisorCounter -= 1;\n\n if (devisorCounter === 0) {\n currentValue++;\n devisorCounter = divisor;\n }\n }\n } else {\n featureIds = Array<number>(featuresCount).fill(constant, 0, featuresCount);\n }\n\n return featureIds;\n}\n\n/**\n * Get batchIds from texture.\n * @param primitive\n * @param featureIdTextures\n */\nfunction generateBatchIdsFromTexture(\n featureIdTexture: GLTF_EXT_feature_metadata_attribute,\n textureCoordinates: Float32Array,\n images: GLTFImagePostprocessed[]\n) {\n if (!images?.length) {\n return [];\n }\n\n const CHANNELS_MAP = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n };\n\n const textureIndex = featureIdTexture?.featureIds?.texture?.index;\n const featureChannel = featureIdTexture?.featureIds?.channels;\n\n if (!featureChannel || textureIndex === undefined) {\n return [];\n }\n\n const image = images[textureIndex];\n const batchIds: number[] = [];\n const channels = CHANNELS_MAP[featureChannel];\n\n if (!image.compressed) {\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);\n const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);\n\n const offset = (ty * image.width + tx) * image.components + channels;\n const batchId = new Uint8Array(image.data)[offset];\n\n batchIds.push(batchId);\n }\n } else {\n console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);\n }\n\n return batchIds;\n}\n\n/**\n * Handle UVs if they are out of range [0,1].\n * @param n\n * @param m\n */\nfunction emod(n: number): number {\n return ((n % 1) + 1) % 1;\n}\n"],"file":"batch-ids-extensions.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["Matrix3","Quaternion","Vector3","Ellipsoid","OrientedBoundingBox","makeOrientedBoundingBoxFromPoints","makeBoundingSphereFromPoints","BoundingSphere","createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","WGS84","cartesianToCartographic","center","getHeight","len","fromMatrix3","normalize","mbs","obb","createBoundingVolumesFromGeometry","cartesianPositions","positionVectors","convertPositionsToVectors","geometryObb","geometryMbs","mbsCenter","obbCenter","positions","result","i","length","positionVector","push","convertBoundingVolumeToI3SFullExtent","sphere","getBoundingSphere","vertexMax","vertexMin","xmin","xmax","ymin","ymax","zmin","zmax","createObbFromMbs","halfAxex"],"mappings":"AAEA,SAAQA,OAAR,EAAiBC,UAAjB,EAA6BC,OAA7B,QAA2C,eAA3C;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SACEC,mBADF,EAEEC,iCAFF,EAGEC,4BAHF,EAIEC,cAJF,QAKO,kBALP;AAeA,OAAO,SAASC,qBAAT,CAA+BC,IAA/B,EAAiDC,gBAAjD,EAA2F;AAChG,MAAIC,MAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,UAAJ;AAEA,QAAMC,cAAc,GAAGL,IAAI,CAACK,cAA5B;AACA,QAAMC,kBAAkB,GAAGZ,SAAS,CAACa,KAAV,CAAgBC,uBAAhB,CACzBH,cAAc,CAACI,MADU,EAEzB,IAAIhB,OAAJ,EAFyB,CAA3B;AAIAa,EAAAA,kBAAkB,CAAC,CAAD,CAAlB,GACEA,kBAAkB,CAAC,CAAD,CAAlB,GACAL,gBAAgB,CAACS,SAAjB,CAA2BJ,kBAAkB,CAAC,CAAD,CAA7C,EAAkDA,kBAAkB,CAAC,CAAD,CAApE,CAFF;;AAGA,MA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AAC,CAAD,CAFV;AAGLI,IAAAA,IAAI,EAAEH,SAAS,CAAC,CAAD,CAHV;AAILI,IAAAA,IAAI,EAAEL,SAAS,CAAC,CAAD,CAJV;AAKLM,IAAAA,IAAI,EAAEL,SAAS,CAAC,CAAD,CALV;AAMLM,IAAAA,IAAI,EAAEP,SAAS,CAAC,CAAD;AANV,GAAP;AAQD;AAOD,OAAO,SAASQ,gBAAT,CAA0B3B,GAA1B,EAAyC;AAC9C,QAAMZ,MAAM,GAAGY,GAAG,CAAC,CAAD,CAAlB;AACA,QAAML,MAAM,GAAG,IAAIhB,OAAJ,CAAYqB,GAAG,CAAC,CAAD,CAAf,EAAoBA,GAAG,CAAC,CAAD,CAAvB,EAA4BA,GAAG,CAAC,CAAD,CAA/B,CAAf;AACA,QAAM4B,QAAQ,GAAG,IAAInD,OAAJ,CAAY,CAACW,MAAD,EAAS,CAAT,EAAY,CAAZ,EAAe,CAAf,EAAkBA,MAAlB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmCA,MAAnC,CAAZ,CAAjB;AACA,SAAO,IAAIP,mBAAJ,CAAwBc,MAAxB,EAAgCiC,QAAhC,CAAP;AACD","sourcesContent":["import type {BoundingVolumes, FullExtent, Mbs, Obb} from '@loaders.gl/i3s';\n\nimport {Matrix3, Quaternion, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {\n OrientedBoundingBox,\n makeOrientedBoundingBoxFromPoints,\n makeBoundingSphereFromPoints,\n BoundingSphere\n} from '@math.gl/culling';\nimport TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';\nimport {Geoid} from '@math.gl/geoid';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(tile: TileHeader, geoidHeightModel: Geoid): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Generates bounding volumes from geometry positions\n * @param cartesianPositions\n * @param geoidHeightModel\n */\nexport function createBoundingVolumesFromGeometry(\n cartesianPositions: Float32Array,\n geoidHeightModel: Geoid\n): {mbs: Mbs; obb: Obb} {\n const positionVectors = convertPositionsToVectors(cartesianPositions);\n\n const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);\n const geometryMbs = makeBoundingSphereFromPoints(positionVectors);\n\n let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());\n let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());\n\n mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);\n obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);\n\n return {\n mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],\n obb: {\n center: obbCenter,\n halfSize: geometryObb.halfSize,\n quaternion: geometryObb.quaternion\n }\n };\n}\n\n/**\n * Create array of posisitons where each vertex is vector\n * @param {array} positions\n * @returns {Vector3[]}\n */\nexport function convertPositionsToVectors(positions: Float32Array): Vector3[] {\n const result: Vector3[] = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.\n // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors\n const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);\n result.push(positionVector);\n }\n\n return result;\n}\n\n/**\n * Convert common coordinate to fullExtent https://github.com/Esri/i3s-spec/blob/master/docs/1.8/fullExtent.cmn.md\n * @param\n * @param boundingVolume\n * @returns - fullExtent object\n */\nexport function convertBoundingVolumeToI3SFullExtent(\n boundingVolume: OrientedBoundingBox | BoundingSphere\n): FullExtent {\n let sphere: BoundingSphere;\n if (boundingVolume instanceof BoundingSphere) {\n sphere = boundingVolume;\n } else {\n sphere = boundingVolume.getBoundingSphere();\n }\n const center: Vector3 = sphere.center;\n const radius: number = sphere.radius;\n const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] + radius, center[1] + radius, center[2] + radius),\n new Vector3()\n );\n const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] - radius, center[1] - radius, center[2] - radius),\n new Vector3()\n );\n\n return {\n xmin: vertexMin[0],\n xmax: vertexMax[0],\n ymin: vertexMin[1],\n ymax: vertexMax[1],\n zmin: vertexMin[2],\n zmax: vertexMax[2]\n };\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["Matrix3","Quaternion","Vector3","Ellipsoid","OrientedBoundingBox","makeOrientedBoundingBoxFromPoints","makeBoundingSphereFromPoints","BoundingSphere","createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","WGS84","cartesianToCartographic","center","getHeight","len","fromMatrix3","normalize","mbs","obb","createBoundingVolumesFromGeometry","cartesianPositions","positionVectors","convertPositionsToVectors","geometryObb","geometryMbs","mbsCenter","obbCenter","positions","result","i","length","positionVector","push","convertBoundingVolumeToI3SFullExtent","sphere","getBoundingSphere","vertexMax","vertexMin","xmin","xmax","ymin","ymax","zmin","zmax","createObbFromMbs","halfAxex"],"mappings":"AAEA,SAAQA,OAAR,EAAiBC,UAAjB,EAA6BC,OAA7B,QAA2C,eAA3C;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SACEC,mBADF,EAEEC,iCAFF,EAGEC,4BAHF,EAIEC,cAJF,QAKO,kBALP;AAeA,OAAO,SAASC,qBAAT,CAA+BC,IAA/B,EAA6CC,gBAA7C,EAAuF;AAC5F,MAAIC,MAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,UAAJ;AAEA,QAAMC,cAAc,GAAGL,IAAI,CAACK,cAA5B;AACA,QAAMC,kBAAkB,GAAGZ,SAAS,CAACa,KAAV,CAAgBC,uBAAhB,CACzBH,cAAc,CAACI,MADU,EAEzB,IAAIhB,OAAJ,EAFyB,CAA3B;AAIAa,EAAAA,kBAAkB,CAAC,CAAD,CAAlB,GACEA,kBAAkB,CAAC,CAAD,CAAlB,GACAL,gBAAgB,CAACS,SAAjB,CAA2BJ,kBAAkB,CAAC,CAAD,CAA7C,EAAkDA,kBAAkB,CAAC,CAAD,CAApE,CAFF;;AAGA,MAAID,cAAc,YAAYV,mBAA9B,EAAmD;AACjDQ,IAAAA,QAAQ,GAAGE,cAAc,CAACF,QAA1B;AACAD,IAAAA,MAAM,GAAG,IAAIT,OAAJ,CAAYU,QAAQ,CAAC,CAAD,CAApB,EAAyBA,QAAQ,CAAC,CAAD,CAAj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AI,EAAEP,SAAS,CAAC,CAAD;AANV,GAAP;AAQD;AAOD,OAAO,SAASQ,gBAAT,CAA0B3B,GAA1B,EAAyC;AAC9C,QAAMZ,MAAM,GAAGY,GAAG,CAAC,CAAD,CAAlB;AACA,QAAML,MAAM,GAAG,IAAIhB,OAAJ,CAAYqB,GAAG,CAAC,CAAD,CAAf,EAAoBA,GAAG,CAAC,CAAD,CAAvB,EAA4BA,GAAG,CAAC,CAAD,CAA/B,CAAf;AACA,QAAM4B,QAAQ,GAAG,IAAInD,OAAJ,CAAY,CAACW,MAAD,EAAS,CAAT,EAAY,CAAZ,EAAe,CAAf,EAAkBA,MAAlB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmCA,MAAnC,CAAZ,CAAjB;AACA,SAAO,IAAIP,mBAAJ,CAAwBc,MAAxB,EAAgCiC,QAAhC,CAAP;AACD","sourcesContent":["import type {BoundingVolumes, FullExtent, Mbs, Obb} from '@loaders.gl/i3s';\n\nimport {Matrix3, Quaternion, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {\n OrientedBoundingBox,\n makeOrientedBoundingBoxFromPoints,\n makeBoundingSphereFromPoints,\n BoundingSphere\n} from '@math.gl/culling';\nimport {Tile3D} from '@loaders.gl/tiles';\nimport {Geoid} from '@math.gl/geoid';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(tile: Tile3D, geoidHeightModel: Geoid): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Generates bounding volumes from geometry positions\n * @param cartesianPositions\n * @param geoidHeightModel\n */\nexport function createBoundingVolumesFromGeometry(\n cartesianPositions: Float32Array,\n geoidHeightModel: Geoid\n): {mbs: Mbs; obb: Obb} {\n const positionVectors = convertPositionsToVectors(cartesianPositions);\n\n const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);\n const geometryMbs = makeBoundingSphereFromPoints(positionVectors);\n\n let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());\n let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());\n\n mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);\n obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);\n\n return {\n mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],\n obb: {\n center: obbCenter,\n halfSize: geometryObb.halfSize,\n quaternion: geometryObb.quaternion\n }\n };\n}\n\n/**\n * Create array of posisitons where each vertex is vector\n * @param {array} positions\n * @returns {Vector3[]}\n */\nexport function convertPositionsToVectors(positions: Float32Array): Vector3[] {\n const result: Vector3[] = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.\n // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors\n const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);\n result.push(positionVector);\n }\n\n return result;\n}\n\n/**\n * Convert common coordinate to fullExtent https://github.com/Esri/i3s-spec/blob/master/docs/1.8/fullExtent.cmn.md\n * @param\n * @param boundingVolume\n * @returns - fullExtent object\n */\nexport function convertBoundingVolumeToI3SFullExtent(\n boundingVolume: OrientedBoundingBox | BoundingSphere\n): FullExtent {\n let sphere: BoundingSphere;\n if (boundingVolume instanceof BoundingSphere) {\n sphere = boundingVolume;\n } else {\n sphere = boundingVolume.getBoundingSphere();\n }\n const center: Vector3 = sphere.center;\n const radius: number = sphere.radius;\n const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] + radius, center[1] + radius, center[2] + radius),\n new Vector3()\n );\n const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(center[0] - radius, center[1] - radius, center[2] - radius),\n new Vector3()\n );\n\n return {\n xmin: vertexMin[0],\n xmax: vertexMax[0],\n ymin: vertexMin[1],\n ymax: vertexMax[1],\n zmin: vertexMin[2],\n zmax: vertexMax[2]\n };\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
@@ -31,4 +31,142 @@ export function checkPropertiesLength(featureIds, propertyTable) {
31
31
 
32
32
  return needFlatten;
33
33
  }
34
+ const STRING_TYPE = 'string';
35
+ const SHORT_INT_TYPE = 'Int32';
36
+ const DOUBLE_TYPE = 'double';
37
+ const OBJECT_ID_TYPE = 'OBJECTID';
38
+ export function getAttributeType(key, attribute) {
39
+ if (key === OBJECT_ID_TYPE) {
40
+ return OBJECT_ID_TYPE;
41
+ }
42
+
43
+ if (typeof attribute === STRING_TYPE) {
44
+ return STRING_TYPE;
45
+ } else if (typeof attribute === 'number') {
46
+ return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;
47
+ }
48
+
49
+ return STRING_TYPE;
50
+ }
51
+ export function createdStorageAttribute(attributeIndex, key, attributeType) {
52
+ const storageAttribute = {
53
+ key: "f_".concat(attributeIndex),
54
+ name: key,
55
+ ordering: ['attributeValues'],
56
+ header: [{
57
+ property: 'count',
58
+ valueType: 'UInt32'
59
+ }],
60
+ attributeValues: {
61
+ valueType: 'Int32',
62
+ valuesPerElement: 1
63
+ }
64
+ };
65
+
66
+ switch (attributeType) {
67
+ case OBJECT_ID_TYPE:
68
+ setupIdAttribute(storageAttribute);
69
+ break;
70
+
71
+ case STRING_TYPE:
72
+ setupStringAttribute(storageAttribute);
73
+ break;
74
+
75
+ case DOUBLE_TYPE:
76
+ setupDoubleAttribute(storageAttribute);
77
+ break;
78
+
79
+ case SHORT_INT_TYPE:
80
+ break;
81
+
82
+ default:
83
+ setupStringAttribute(storageAttribute);
84
+ }
85
+
86
+ return storageAttribute;
87
+ }
88
+ export function getFieldAttributeType(attributeType) {
89
+ switch (attributeType) {
90
+ case OBJECT_ID_TYPE:
91
+ return 'esriFieldTypeOID';
92
+
93
+ case STRING_TYPE:
94
+ return 'esriFieldTypeString';
95
+
96
+ case SHORT_INT_TYPE:
97
+ return 'esriFieldTypeInteger';
98
+
99
+ case DOUBLE_TYPE:
100
+ return 'esriFieldTypeDouble';
101
+
102
+ default:
103
+ return 'esriFieldTypeString';
104
+ }
105
+ }
106
+ export function createFieldAttribute(key, fieldAttributeType) {
107
+ return {
108
+ name: key,
109
+ type: fieldAttributeType,
110
+ alias: key
111
+ };
112
+ }
113
+ export function createPopupInfo(propertyTable) {
114
+ const title = '{OBJECTID}';
115
+ const mediaInfos = [];
116
+ const fieldInfos = [];
117
+ const popupElements = [];
118
+ const expressionInfos = [];
119
+
120
+ for (const key in propertyTable) {
121
+ fieldInfos.push({
122
+ fieldName: key,
123
+ visible: true,
124
+ isEditable: false,
125
+ label: key
126
+ });
127
+ }
128
+
129
+ popupElements.push({
130
+ fieldInfos,
131
+ type: 'fields'
132
+ });
133
+ return {
134
+ title,
135
+ mediaInfos,
136
+ popupElements,
137
+ fieldInfos,
138
+ expressionInfos
139
+ };
140
+ }
141
+
142
+ function setupStringAttribute(storageAttribute) {
143
+ storageAttribute.ordering.unshift('attributeByteCounts');
144
+ storageAttribute.header.push({
145
+ property: 'attributeValuesByteCount',
146
+ valueType: 'UInt32'
147
+ });
148
+ storageAttribute.attributeValues = {
149
+ valueType: 'String',
150
+ encoding: 'UTF-8',
151
+ valuesPerElement: 1
152
+ };
153
+ storageAttribute.attributeByteCounts = {
154
+ valueType: 'UInt32',
155
+ valuesPerElement: 1
156
+ };
157
+ }
158
+
159
+ function setupIdAttribute(storageAttribute) {
160
+ storageAttribute.attributeValues = {
161
+ valueType: 'Oid32',
162
+ valuesPerElement: 1
163
+ };
164
+ }
165
+
166
+ function setupDoubleAttribute(storageAttribute) {
167
+ storageAttribute.attributeValues = {
168
+ valueType: 'Float64',
169
+ valuesPerElement: 1
170
+ };
171
+ }
34
172
  //# sourceMappingURL=feature-attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/feature-attributes.ts"],"names":["flattenPropertyTableByFeatureIds","featureIds","propertyTable","resultPropertyTable","propertyName","properties","getPropertiesByFeatureIds","resultProperties","featureId","property","push","checkPropertiesLength","needFlatten","attribute","Object","values","length"],"mappings":"AAeA,OAAO,SAASA,gCAAT,CACLC,UADK,EAELC,aAFK,EAGa;AAClB,QAAMC,mBAAqC,GAAG,EAA9C;;AACA,OAAK,MAAMC,YAAX,IAA2BF,aAA3B,EAA0C;AACxC,UAAMG,UAAU,GAAGH,aAAa,CAACE,YAAD,CAAhC;AACAD,IAAAA,mBAAmB,CAACC,YAAD,CAAnB,GAAoCE,yBAAyB,CAACD,UAAD,EAAaJ,UAAb,CAA7D;AACD;;AAED,SAAOE,mBAAP;AACD;;AAOD,SAASG,yBAAT,CAAmCD,UAAnC,EAAsDJ,UAAtD,EAAmF;AACjF,QAAMM,gBAAqB,GAAG,EAA9B;;AAEA,OAAK,MAAMC,SAAX,IAAwBP,UAAxB,EAAoC;AAClC,UAAMQ,QAAQ,GAAGJ,UAAU,CAACG,SAAD,CAAV,IAAyB,IAA1C;AACAD,IAAAA,gBAAgB,CAACG,IAAjB,CAAsBD,QAAtB;AACD;;AAED,SAAOF,gBAAP;AACD;;AASD,OAAO,SAASI,qBAAT,CACLV,UADK,EAELC,aAFK,EAGI;AACT,MAAIU,WAAW,GAAG,KAAlB;;AAEA,OAAK,MAAMC,SAAX,IAAwBC,MAAM,CAACC,MAAP,CAAcb,aAAd,CAAxB,EAAsD;AACpD,QAAID,UAAU,CAACe,MAAX,KAAsBH,SAAS,CAACG,MAApC,EAA4C;AAC1CJ,MAAAA,WAAW,GAAG,IAAd;AACD;AACF;;AAED,SAAOA,WAAP;AACD","sourcesContent":["import type {FeatureTableJson} from '@loaders.gl/3d-tiles';\n\n/**\n * Takes attributes from property table based on featureIds.\n * If there is no property value for particular featureId (index) the property will be null.\n * Example:\n * Initial data:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']\n * Result:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'null']\n * @param featureIds\n * @param propertyTable\n */\nexport function flattenPropertyTableByFeatureIds(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): FeatureTableJson {\n const resultPropertyTable: FeatureTableJson = {};\n for (const propertyName in propertyTable) {\n const properties = propertyTable[propertyName];\n resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIds);\n }\n\n return resultPropertyTable;\n}\n\n/**\n * Getting properties by featureId index\n * @param properties\n * @param featureIds\n */\nfunction getPropertiesByFeatureIds(properties: any[], featureIds: number[]): any[] {\n const resultProperties: any = [];\n\n for (const featureId of featureIds) {\n const property = properties[featureId] || null;\n resultProperties.push(property);\n }\n\n return resultProperties;\n}\n\n/**\n * Check that all attributes in propertyTable have the same length as FeatureIds.\n * If there are differencies between lengths we should flatten property table based on exiesting featureIds.\n * @param featureIds\n * @param propertyTable\n * @returns\n */\nexport function checkPropertiesLength(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): boolean {\n let needFlatten = false;\n\n for (const attribute of Object.values(propertyTable)) {\n if (featureIds.length !== attribute.length) {\n needFlatten = true;\n }\n }\n\n return needFlatten;\n}\n"],"file":"feature-attributes.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/feature-attributes.ts"],"names":["flattenPropertyTableByFeatureIds","featureIds","propertyTable","resultPropertyTable","propertyName","properties","getPropertiesByFeatureIds","resultProperties","featureId","property","push","checkPropertiesLength","needFlatten","attribute","Object","values","length","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","getAttributeType","key","Number","isInteger","createdStorageAttribute","attributeIndex","attributeType","storageAttribute","name","ordering","header","valueType","attributeValues","valuesPerElement","setupIdAttribute","setupStringAttribute","setupDoubleAttribute","getFieldAttributeType","createFieldAttribute","fieldAttributeType","type","alias","createPopupInfo","title","mediaInfos","fieldInfos","popupElements","expressionInfos","fieldName","visible","isEditable","label","unshift","encoding","attributeByteCounts"],"mappings":"AAuBA,OAAO,SAASA,gCAAT,CACLC,UADK,EAELC,aAFK,EAGa;AAClB,QAAMC,mBAAqC,GAAG,EAA9C;;AACA,OAAK,MAAMC,YAAX,IAA2BF,aAA3B,EAA0C;AACxC,UAAMG,UAAU,GAAGH,aAAa,CAACE,YAAD,CAAhC;AACAD,IAAAA,mBAAmB,CAACC,YAAD,CAAnB,GAAoCE,yBAAyB,CAACD,UAAD,EAAaJ,UAAb,CAA7D;AACD;;AAED,SAAOE,mBAAP;AACD;;AAOD,SAASG,yBAAT,CAAmCD,UAAnC,EAAsDJ,UAAtD,EAAmF;AACjF,QAAMM,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AmC;AACjCD,IAAAA,SAAS,EAAE,SADsB;AAEjCE,IAAAA,gBAAgB,EAAE;AAFe,GAAnC;AAID","sourcesContent":["import type {FeatureTableJson} from '@loaders.gl/3d-tiles';\nimport {\n Attribute,\n AttributeStorageInfo,\n ESRIField,\n Field,\n FieldInfo,\n PopupInfo\n} from '@loaders.gl/i3s';\n\n/**\n * Takes attributes from property table based on featureIds.\n * If there is no property value for particular featureId (index) the property will be null.\n * Example:\n * Initial data:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']\n * Result:\n * OBJECTID: [0, 1, 5]\n * component: ['Windows', 'Frames', 'null']\n * @param featureIds\n * @param propertyTable\n */\nexport function flattenPropertyTableByFeatureIds(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): FeatureTableJson {\n const resultPropertyTable: FeatureTableJson = {};\n for (const propertyName in propertyTable) {\n const properties = propertyTable[propertyName];\n resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIds);\n }\n\n return resultPropertyTable;\n}\n\n/**\n * Getting properties by featureId index\n * @param properties\n * @param featureIds\n */\nfunction getPropertiesByFeatureIds(properties: any[], featureIds: number[]): any[] {\n const resultProperties: any = [];\n\n for (const featureId of featureIds) {\n const property = properties[featureId] || null;\n resultProperties.push(property);\n }\n\n return resultProperties;\n}\n\n/**\n * Check that all attributes in propertyTable have the same length as FeatureIds.\n * If there are differencies between lengths we should flatten property table based on exiesting featureIds.\n * @param featureIds\n * @param propertyTable\n * @returns\n */\nexport function checkPropertiesLength(\n featureIds: number[],\n propertyTable: FeatureTableJson\n): boolean {\n let needFlatten = false;\n\n for (const attribute of Object.values(propertyTable)) {\n if (featureIds.length !== attribute.length) {\n needFlatten = true;\n }\n }\n\n return needFlatten;\n}\n\n/** String data type name for feature attributes */\nconst STRING_TYPE = 'string';\n/** Integer data type name for feature attributes */\nconst SHORT_INT_TYPE = 'Int32';\n/** Double data type name for feature attributes */\nconst DOUBLE_TYPE = 'double';\n/** Type of attribute that is linked with feature ids */\nconst OBJECT_ID_TYPE = 'OBJECTID';\n/**\n * Get the attribute type for attributeStorageInfo https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md\n * @param key - attribute's key\n * @param attribute - attribute's type in propertyTable\n */\nexport function getAttributeType(key: string, attribute: string): string {\n if (key === OBJECT_ID_TYPE) {\n return OBJECT_ID_TYPE;\n }\n if (typeof attribute === STRING_TYPE) {\n return STRING_TYPE;\n } else if (typeof attribute === 'number') {\n return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;\n }\n return STRING_TYPE;\n}\n\n/**\n * Generate storage attribute for map segmentation.\n * @param attributeIndex - order index of attribute (f_0, f_1 ...).\n * @param key - attribute key from propertyTable.\n * @param attributeType - attribute type.\n * @return Updated storageAttribute.\n */\nexport function createdStorageAttribute(\n attributeIndex: number,\n key: string,\n attributeType: Attribute\n): AttributeStorageInfo {\n const storageAttribute = {\n key: `f_${attributeIndex}`,\n name: key,\n ordering: ['attributeValues'],\n header: [{property: 'count', valueType: 'UInt32'}],\n attributeValues: {valueType: 'Int32', valuesPerElement: 1}\n };\n\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n setupIdAttribute(storageAttribute);\n break;\n case STRING_TYPE:\n setupStringAttribute(storageAttribute);\n break;\n case DOUBLE_TYPE:\n setupDoubleAttribute(storageAttribute);\n break;\n case SHORT_INT_TYPE:\n break;\n default:\n setupStringAttribute(storageAttribute);\n }\n\n return storageAttribute;\n}\n\n/**\n * Find and return attribute type based on key form propertyTable.\n * @param attributeType\n */\nexport function getFieldAttributeType(attributeType: Attribute): ESRIField {\n switch (attributeType) {\n case OBJECT_ID_TYPE:\n return 'esriFieldTypeOID';\n case STRING_TYPE:\n return 'esriFieldTypeString';\n case SHORT_INT_TYPE:\n return 'esriFieldTypeInteger';\n case DOUBLE_TYPE:\n return 'esriFieldTypeDouble';\n default:\n return 'esriFieldTypeString';\n }\n}\n\n/**\n * Setup field attribute for map segmentation.\n * @param key - attribute for map segmentation.\n * @param fieldAttributeType - esri attribute type ('esriFieldTypeString' or 'esriFieldTypeOID').\n */\nexport function createFieldAttribute(key: string, fieldAttributeType: ESRIField): Field {\n return {\n name: key,\n type: fieldAttributeType,\n alias: key\n };\n}\n\n/**\n * Generate popup info to show metadata on the map.\n * @param propertyTable - table data with OBJECTID.\n * @return data for correct rendering of popup.\n */\nexport function createPopupInfo(propertyTable: FeatureTableJson): PopupInfo {\n const title = '{OBJECTID}';\n const mediaInfos = [];\n const fieldInfos: FieldInfo[] = [];\n const popupElements: {\n fieldInfos: FieldInfo[];\n type: string;\n }[] = [];\n const expressionInfos = [];\n\n for (const key in propertyTable) {\n fieldInfos.push({\n fieldName: key,\n visible: true,\n isEditable: false,\n label: key\n });\n }\n popupElements.push({\n fieldInfos,\n type: 'fields'\n });\n\n return {\n title,\n mediaInfos,\n popupElements,\n fieldInfos,\n expressionInfos\n };\n}\n\n/**\n * Setup storage attribute as string.\n * @param storageAttribute - attribute for map segmentation.\n */\nfunction setupStringAttribute(storageAttribute: AttributeStorageInfo): void {\n // @ts-expect-error\n storageAttribute.ordering.unshift('attributeByteCounts');\n storageAttribute.header.push({property: 'attributeValuesByteCount', valueType: 'UInt32'});\n storageAttribute.attributeValues = {\n valueType: 'String',\n encoding: 'UTF-8',\n valuesPerElement: 1\n };\n storageAttribute.attributeByteCounts = {\n valueType: 'UInt32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup Id attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupIdAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Oid32',\n valuesPerElement: 1\n };\n}\n\n/**\n * Setup double attribute for map segmentation.\n * @param storageAttribute - attribute for map segmentation .\n */\nfunction setupDoubleAttribute(storageAttribute: AttributeStorageInfo): void {\n storageAttribute.attributeValues = {\n valueType: 'Float64',\n valuesPerElement: 1\n };\n}\n"],"file":"feature-attributes.js"}