@loaders.gl/tile-converter 3.1.0-alpha.4 → 3.1.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/bin/converter.js +1 -1
  2. package/dist/bundle.js +86025 -0
  3. package/dist/converter.min.js +292 -0
  4. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +189 -421
  5. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +214 -296
  7. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  8. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +4 -8
  9. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  10. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +40 -0
  11. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  12. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +7 -17
  13. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  14. package/dist/es5/bundle.js +1 -1
  15. package/dist/es5/bundle.js.map +1 -1
  16. package/dist/es5/deps-installer/deps-installer.js +17 -65
  17. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  18. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +16 -16
  19. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  20. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +9 -33
  21. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  22. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +93 -103
  23. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  24. package/dist/es5/i3s-converter/helpers/geometry-converter.js +348 -511
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/node-debug.js +30 -26
  27. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/node-pages.js +102 -203
  29. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  30. package/dist/es5/i3s-converter/i3s-converter.js +701 -1501
  31. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/json-templates/layers.js +15 -25
  33. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  34. package/dist/es5/i3s-converter/json-templates/metadata.js +2 -2
  35. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  36. package/dist/es5/i3s-converter/json-templates/node.js +12 -21
  37. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  38. package/dist/es5/i3s-converter/json-templates/scene-server.js +3 -5
  39. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  40. package/dist/es5/i3s-converter/json-templates/shared-resources.js +15 -55
  41. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  42. package/dist/es5/i3s-converter/json-templates/store.js +4 -6
  43. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  44. package/dist/es5/i3s-server/app.js +6 -6
  45. package/dist/es5/i3s-server/app.js.map +1 -1
  46. package/dist/es5/i3s-server/controllers/index-controller.js +20 -60
  47. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  48. package/dist/es5/i3s-server/routes/index.js +14 -41
  49. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  50. package/dist/es5/index.js +4 -4
  51. package/dist/es5/lib/geoid-height-model.js +100 -114
  52. package/dist/es5/lib/geoid-height-model.js.map +1 -1
  53. package/dist/es5/lib/pgm-parser.js +68 -122
  54. package/dist/es5/lib/pgm-parser.js.map +1 -1
  55. package/dist/es5/lib/utils/compress-util.js +123 -345
  56. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  57. package/dist/es5/lib/utils/file-utils.js +20 -98
  58. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  59. package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
  60. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  61. package/dist/es5/lib/utils/statistic-utills.js +41 -152
  62. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  63. package/dist/es5/pgm-loader.js +3 -5
  64. package/dist/es5/pgm-loader.js.map +1 -1
  65. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +19 -13
  66. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  67. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +19 -8
  68. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  69. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
  70. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
  71. package/dist/esm/i3s-converter/helpers/geometry-converter.js +29 -31
  72. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  73. package/dist/esm/i3s-converter/helpers/node-debug.js +2 -2
  74. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  75. package/dist/esm/i3s-converter/helpers/node-pages.js +2 -2
  76. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  77. package/dist/esm/i3s-converter/i3s-converter.js +50 -31
  78. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  79. package/dist/esm/i3s-converter/json-templates/metadata.js +1 -1
  80. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  81. package/dist/esm/i3s-converter/json-templates/scene-server.js +1 -1
  82. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  83. package/dist/esm/i3s-converter/json-templates/shared-resources.js +2 -2
  84. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  85. package/dist/esm/i3s-converter/json-templates/store.js +2 -2
  86. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  87. package/dist/esm/i3s-server/controllers/index-controller.js +2 -2
  88. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
  89. package/dist/esm/lib/utils/compress-util.js +13 -13
  90. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  91. package/dist/esm/lib/utils/file-utils.js +1 -1
  92. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  93. package/dist/esm/lib/utils/statistic-utills.js +5 -5
  94. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  95. package/dist/esm/pgm-loader.js +1 -1
  96. package/dist/esm/pgm-loader.js.map +1 -1
  97. package/package.json +22 -19
  98. package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
  99. package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
  100. package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
  101. package/src/i3s-converter/helpers/geometry-converter.js +21 -22
  102. package/src/i3s-converter/i3s-converter.ts +32 -7
  103. package/src/i3s-converter/json-templates/metadata.js +1 -1
  104. package/src/i3s-converter/json-templates/scene-server.js +1 -1
  105. package/src/i3s-converter/json-templates/store.js +2 -2
  106. package/src/i3s-server/controllers/index-controller.js +1 -1
  107. package/dist/dist.min.js +0 -94
  108. package/dist/dist.min.js.map +0 -1
  109. package/dist/scripts/converter.js +0 -274
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/3d-tiles-converter/3d-tiles-converter.ts"],"names":["I3S","Tiles3DConverter","options","tilesetPath","vertexCounter","conversionStartTime","geoidHeightModel","sourceTileset","attributeStorageInfo","inputUrl","outputPath","tilesetName","maxDepth","egmFilePath","process","hrtime","console","log","PGMLoader","I3SLoader","sourceTilesetJson","Tileset3D","root","header","obb","mbs","rootTile","boundingVolume","box","geometricError","children","_addChildren","tileset","tilesetTemplate","JSON","stringify","_finishConversion","slpk","parentSourceNode","parentNode","level","childNodeInfo","_loadChildNode","sourceChild","push","contentUrl","_loadTile","content","vertexCount","attributes","_loadChildAttributes","child","B3dmConverter","convert","b3dm","uri","id","Uint8Array","unloadContent","nodePages","nodePagesTile","formTileFromNodePages","loader","nodeUrl","_relativeUrlToFullUrl","url","href","i3s","loadOptions","isTileHeader","loadContent","Tile3D","baseUrl","relativeUrl","resultArray","split","relativeUrlArray","folder","slice","join","promises","attributeUrls","index","length","attribute","attributeName","name","attributeType","_getAttributeType","I3SAttributeLoader","Promise","all","attributesList","_replaceNestedArrays","Object","assign","attributeValues","valueType","objectIds","attributeObject","key","Array","from","params","filesSize","diff","conversionTime"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAGA,IAAMA,GAAG,GAAG,KAAZ;;IAKqBC,gB;AASnB,8BAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACZ,SAAKC,OAAL,GAAe,EAAf;AACA,SAAKC,WAAL,GAAmB,EAAnB;AACA,SAAKC,aAAL,GAAqB,CAArB;AACA,SAAKC,mBAAL,GAA2B,CAAC,CAAD,EAAI,CAAJ,CAA3B;AACA,SAAKC,gBAAL,GAAwB,IAAxB;AACA,SAAKC,aAAL,GAAqB,IAArB;AACA,SAAKC,oBAAL,GAA4B,IAA5B;AACD;;;;;+EAWD,iBAAsBN,OAAtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAOSO,gBAAAA,QAPT,GAOqEP,OAPrE,CAOSO,QAPT,EAOmBC,UAPnB,GAOqER,OAPrE,CAOmBQ,UAPnB,EAO+BC,WAP/B,GAOqET,OAPrE,CAO+BS,WAP/B,EAO4CC,QAP5C,GAOqEV,OAPrE,CAO4CU,QAP5C,EAOsDC,WAPtD,GAOqEX,OAPrE,CAOsDW,WAPtD;AAQE,qBAAKR,mBAAL,GAA2BS,iBAAQC,MAAR,EAA3B;AACA,qBAAKb,OAAL,GAAe;AAACU,kBAAAA,QAAQ,EAARA;AAAD,iBAAf;AAEAI,gBAAAA,OAAO,CAACC,GA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jB,GAApC;AACAgB,gBAAAA,OAAO,CAACC,GAAR,kCAAsCyF,cAAtC;AACA1F,gBAAAA,OAAO,CAACC,GAAR,mBAA8B,KAAKb,aAAnC;AACAY,gBAAAA,OAAO,CAACC,GAAR,mBAA8BuF,SAA9B,EAAyC,QAAzC;AACAxF,gBAAAA,OAAO,CAACC,GAAR;;AAdF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O","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 {load} from '@loaders.gl/core';\nimport {I3SLoader, I3SAttributeLoader} from '@loaders.gl/i3s';\nimport {Tileset3D, Tile3D} from '@loaders.gl/tiles';\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 {GeoidHeightModel} from '../lib/geoid-height-model';\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: GeoidHeightModel;\n sourceTileset: Tileset3D;\n attributeStorageInfo: AttributeStorageInfo;\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 }\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 private async convert(options: {\n inputUrl: string;\n outputPath: string;\n tilesetName: string;\n maxDepth: number;\n egmFilePath: string;\n }): Promise<any> {\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 const sourceTilesetJson = await load(inputUrl, I3SLoader, {});\n this.sourceTileset = new Tileset3D(sourceTilesetJson, {});\n\n if (!this.sourceTileset.root.header.obb) {\n this.sourceTileset.root.header.obb = createObbFromMbs(this.sourceTileset.root.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(this.sourceTileset.root.header.obb, this.geoidHeightModel)\n },\n geometricError: convertScreenThresholdToGeometricError(this.sourceTileset.root),\n children: []\n };\n\n await this._addChildren(this.sourceTileset.root, 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\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 attributes = null;\n if (this.attributeStorageInfo) {\n attributes = 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 b3dm = await new B3dmConverter().convert(sourceChild, attributes);\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 = [];\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"],"file":"3d-tiles-converter.js"}
1
+ {"version":3,"sources":["../../../src/3d-tiles-converter/3d-tiles-converter.ts"],"names":["I3S","Tiles3DConverter","constructor","options","tilesetPath","vertexCounter","conversionStartTime","geoidHeightModel","sourceTileset","attributeStorageInfo","convert","inputUrl","outputPath","tilesetName","maxDepth","egmFilePath","process","hrtime","console","log","PGMLoader","sourceTilesetJson","I3SLoader","Tileset3D","loadOptions","i3s","coordinateSystem","COORDINATE_SYSTEM","LNGLAT_OFFSETS","root","header","obb","mbs","e","rootTile","boundingVolume","box","geometricError","children","_addChildren","tileset","tilesetTemplate","JSON","stringify","_finishConversion","slpk","parentSourceNode","parentNode","level","childNodeInfo","sourceChild","_loadChildNode","push","contentUrl","_loadTile","content","vertexCount","attributes","_loadChildAttributes","child","b3dm","B3dmConverter","uri","id","Uint8Array","unloadContent","nodePages","nodePagesTile","formTileFromNodePages","loader","nodeUrl","_relativeUrlToFullUrl","url","href","isTileHeader","loadContent","Tile3D","baseUrl","relativeUrl","resultArray","split","relativeUrlArray","folder","slice","join","promises","attributeUrls","index","length","attribute","attributeName","name","attributeType","_getAttributeType","I3SAttributeLoader","attributesList","Promise","all","_replaceNestedArrays","Object","assign","attributeValues","valueType","objectIds","attributeObject","key","Array","from","params","filesSize","diff","conversionTime"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA,MAAMA,GAAG,GAAG,KAAZ;;AAKe,MAAMC,gBAAN,CAAuB;AASpCC,EAAAA,WAAW,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACZ,SAAKC,OAAL,GAAe,EAAf;AACA,SAAKC,WAAL,GAAmB,EAAnB;AACA,SAAKC,aAAL,GAAqB,CAArB;AACA,SAAKC,mBAAL,GAA2B,CAAC,CAAD,EAAI,CAAJ,CAA3B;AACA,SAAKC,gBAAL,GAAwB,IAAxB;AACA,SAAKC,aAAL,GAAqB,IAArB;AACA,SAAKC,oBAAL,GAA4B,IAA5B;AACD;;AAWoB,QAAPC,OAAO,CAACP,OAAD,EAMJ;AACf,UAAM;AAACQ,MAAAA,QAAD;AAAWC,MAAAA,UAAX;AAAuBC,MAAAA,WAAvB;AAAoCC,MAAAA,QAApC;AAA8CC,MAAAA;AAA9C,QAA6DZ,OAAnE;AACA,SAAKG,mBAAL,GAA2BU,iBAAQC,MAAR,EAA3B;AACA,SAAKd,OAAL,GAAe;AAACW,MAAAA;AAAD,KAAf;AAEAI,IAAAA,OAAO,CAACC,GAAR,CAAY,qBAAZ;AACA,SAAKZ,gBAAL,GAAwB,MAAM,gBAAKQ,WAAL,EAAkBK,oBAAlB,CAA9B;AACAF,IAAAA,OAAO,CAACC,GAAR,CAAY,6BAAZ;AAEA,UAAME,iBAAiB,GAAG,MAAM,gBAAKV,QAAL,EAAeW,cAAf,EAA0B,EAA1B,CAAhC;AACA,SAAKd,aAAL,GAAqB,IAAIe,gBAAJ,CAAcF,iBAAd,EAAiC;AACpDG,MAAAA,WAAW,EAAE;AA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cAAc,GAAG,oCAAcD,IAAd,CAAvB;AAEA5F,IAAAA,OAAO,CAACC,GAAR;AACAD,IAAAA,OAAO,CAACC,GAAR,gCAAoCnB,GAApC;AACAkB,IAAAA,OAAO,CAACC,GAAR,kCAAsC4F,cAAtC;AACA7F,IAAAA,OAAO,CAACC,GAAR,mBAA8B,KAAKd,aAAnC;AACAa,IAAAA,OAAO,CAACC,GAAR,mBAA8B0F,SAA9B,EAAyC,QAAzC;AACA3F,IAAAA,OAAO,CAACC,GAAR;AACD;;AAtQmC","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 {load} from '@loaders.gl/core';\nimport {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';\nimport {Tileset3D, Tile3D} from '@loaders.gl/tiles';\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 {GeoidHeightModel} from '../lib/geoid-height-model';\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: GeoidHeightModel;\n sourceTileset: Tileset3D;\n attributeStorageInfo: AttributeStorageInfo;\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 }\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 private async convert(options: {\n inputUrl: string;\n outputPath: string;\n tilesetName: string;\n maxDepth: number;\n egmFilePath: string;\n }): Promise<any> {\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 const sourceTilesetJson = await load(inputUrl, I3SLoader, {});\n this.sourceTileset = new Tileset3D(sourceTilesetJson, {\n loadOptions: {i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS}}\n });\n\n if (!this.sourceTileset.root.header.obb) {\n this.sourceTileset.root.header.obb = createObbFromMbs(this.sourceTileset.root.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(this.sourceTileset.root.header.obb, this.geoidHeightModel)\n },\n geometricError: convertScreenThresholdToGeometricError(this.sourceTileset.root),\n children: []\n };\n\n await this._addChildren(this.sourceTileset.root, 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\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 attributes = null;\n if (this.attributeStorageInfo) {\n attributes = 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 b3dm = await new B3dmConverter().convert(sourceChild, attributes);\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 = [];\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"],"file":"3d-tiles-converter.js"}
@@ -1,22 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = void 0;
9
7
 
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
-
18
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
19
-
20
8
  var _core = require("@loaders.gl/core");
21
9
 
22
10
  var _gltf = require("@loaders.gl/gltf");
@@ -27,325 +15,255 @@ var _images = require("@loaders.gl/images");
27
15
 
28
16
  var _core2 = require("@math.gl/core");
29
17
 
30
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
18
+ var _geospatial = require("@math.gl/geospatial");
31
19
 
32
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
20
+ var _textureAtlas = require("./texture-atlas");
33
21
 
34
- var Z_UP_TO_Y_UP_MATRIX = new _core2.Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
22
+ const Z_UP_TO_Y_UP_MATRIX = new _core2.Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
23
+ const scratchVector = new _core2.Vector3();
35
24
 
36
- var B3dmConverter = function () {
37
- function B3dmConverter() {
38
- (0, _classCallCheck2.default)(this, B3dmConverter);
25
+ class B3dmConverter {
26
+ async convert(i3sTile, attributes = null) {
27
+ this.i3sTile = i3sTile;
28
+ const gltf = await this.buildGltf(i3sTile);
29
+ const b3dm = (0, _core.encodeSync)({
30
+ gltfEncoded: new Uint8Array(gltf),
31
+ type: 'b3dm',
32
+ featuresLength: this._getFeaturesLength(attributes),
33
+ batchTable: attributes
34
+ }, _dTiles.Tile3DWriter);
35
+ return b3dm;
39
36
  }
40
37
 
41
- (0, _createClass2.default)(B3dmConverter, [{
42
- key: "convert",
43
- value: function () {
44
- var _convert = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(i3sTile) {
45
- var attributes,
46
- gltf,
47
- b3dm,
48
- _args = arguments;
49
- return _regenerator.default.wrap(function _callee$(_context) {
50
- while (1) {
51
- switch (_context.prev = _context.next) {
52
- case 0:
53
- attributes = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
54
- this.i3sTile = i3sTile;
55
- _context.next = 4;
56
- return this.buildGltf(i3sTile);
57
-
58
- case 4:
59
- gltf = _context.sent;
60
- b3dm = (0, _core.encodeSync)({
61
- gltfEncoded: new Uint8Array(gltf),
62
- type: 'b3dm',
63
- featuresLength: this._getFeaturesLength(attributes),
64
- batchTable: attributes
65
- }, _dTiles.Tile3DWriter);
66
- return _context.abrupt("return", b3dm);
67
-
68
- case 7:
69
- case "end":
70
- return _context.stop();
71
- }
72
- }
73
- }, _callee, this);
74
- }));
75
-
76
- function convert(_x) {
77
- return _convert.apply(this, arguments);
78
- }
38
+ async buildGltf(i3sTile) {
39
+ const {
40
+ material,
41
+ attributes,
42
+ indices: originalIndices,
43
+ cartesianOrigin,
44
+ cartographicOrigin,
45
+ modelMatrix
46
+ } = i3sTile.content;
47
+ const gltfBuilder = new _gltf.GLTFScenegraph();
48
+ const textureIndex = await this._addI3sTextureToGltf(i3sTile, gltfBuilder);
49
+
50
+ const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
51
+
52
+ const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
53
+ const positions = attributes.positions;
54
+ const positionsValue = positions.value;
55
+
56
+ if (attributes.uvRegions && attributes.texCoords) {
57
+ attributes.texCoords.value = (0, _textureAtlas.convertTextureAtlas)(attributes.texCoords.value, attributes.uvRegions.value);
58
+ }
79
59
 
80
- return convert;
81
- }()
82
- }, {
83
- key: "buildGltf",
84
- value: function () {
85
- var _buildGltf = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(i3sTile) {
86
- var _i3sTile$content, material, attributes, originalIndices, cartesianOrigin, gltfBuilder, textureIndex, pbrMaterialInfo, materialIndex, positions, positionsValue, indices, meshIndex, transformMatrix, nodeIndex, sceneIndex, gltfBuffer;
87
-
88
- return _regenerator.default.wrap(function _callee2$(_context2) {
89
- while (1) {
90
- switch (_context2.prev = _context2.next) {
91
- case 0:
92
- _i3sTile$content = i3sTile.content, material = _i3sTile$content.material, attributes = _i3sTile$content.attributes, originalIndices = _i3sTile$content.indices, cartesianOrigin = _i3sTile$content.cartesianOrigin;
93
- gltfBuilder = new _gltf.GLTFScenegraph();
94
- _context2.next = 4;
95
- return this._addI3sTextureToGltf(i3sTile, gltfBuilder);
96
-
97
- case 4:
98
- textureIndex = _context2.sent;
99
- pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
100
- materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
101
- positions = attributes.positions;
102
- positionsValue = positions.value;
103
- attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin);
104
-
105
- if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
106
- delete attributes.normals;
107
- }
108
-
109
- indices = originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);
110
- meshIndex = gltfBuilder.addMesh({
111
- attributes: attributes,
112
- indices: indices,
113
- material: materialIndex
114
- });
115
- transformMatrix = this._generateTransformMatrix(cartesianOrigin);
116
- nodeIndex = gltfBuilder.addNode({
117
- meshIndex: meshIndex,
118
- matrix: transformMatrix
119
- });
120
- sceneIndex = gltfBuilder.addScene({
121
- nodeIndices: [nodeIndex]
122
- });
123
- gltfBuilder.setDefaultScene(sceneIndex);
124
- gltfBuilder.createBinaryChunk();
125
- gltfBuffer = (0, _core.encodeSync)(gltfBuilder.gltf, _gltf.GLTFWriter);
126
- return _context2.abrupt("return", gltfBuffer);
127
-
128
- case 20:
129
- case "end":
130
- return _context2.stop();
131
- }
132
- }
133
- }, _callee2, this);
134
- }));
135
-
136
- function buildGltf(_x2) {
137
- return _buildGltf.apply(this, arguments);
138
- }
60
+ attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
139
61
 
140
- return buildGltf;
141
- }()
142
- }, {
143
- key: "_addI3sTextureToGltf",
144
- value: function () {
145
- var _addI3sTextureToGltf2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(i3sTile, gltfBuilder) {
146
- var _i3sTile$content2, texture, material, attributes, textureFormat, textureIndex, selectedTexture, mimeType, imageBuffer, imageIndex;
147
-
148
- return _regenerator.default.wrap(function _callee3$(_context3) {
149
- while (1) {
150
- switch (_context3.prev = _context3.next) {
151
- case 0:
152
- _i3sTile$content2 = i3sTile.content, texture = _i3sTile$content2.texture, material = _i3sTile$content2.material, attributes = _i3sTile$content2.attributes, textureFormat = i3sTile.header.textureFormat;
153
- textureIndex = null;
154
- selectedTexture = texture;
155
-
156
- if (!texture && material) {
157
- selectedTexture = material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture && material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
158
- }
159
-
160
- if (!selectedTexture) {
161
- _context3.next = 12;
162
- break;
163
- }
164
-
165
- mimeType = this._deduceMimeTypeFromFormat(textureFormat);
166
- _context3.next = 8;
167
- return (0, _core.encode)(selectedTexture, _images.ImageWriter);
168
-
169
- case 8:
170
- imageBuffer = _context3.sent;
171
- imageIndex = gltfBuilder.addImage(imageBuffer, mimeType);
172
- textureIndex = gltfBuilder.addTexture({
173
- imageIndex: imageIndex
174
- });
175
- delete attributes.colors;
176
-
177
- case 12:
178
- return _context3.abrupt("return", textureIndex);
179
-
180
- case 13:
181
- case "end":
182
- return _context3.stop();
183
- }
184
- }
185
- }, _callee3, this);
186
- }));
187
-
188
- function _addI3sTextureToGltf(_x3, _x4) {
189
- return _addI3sTextureToGltf2.apply(this, arguments);
190
- }
62
+ if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
63
+ delete attributes.normals;
64
+ }
191
65
 
192
- return _addI3sTextureToGltf;
193
- }()
194
- }, {
195
- key: "_normalizePositions",
196
- value: function _normalizePositions(positionsValue, cartesianOrigin) {
197
- var newPositionsValue = new Float32Array(positionsValue.length);
198
-
199
- for (var index = 0; index < positionsValue.length; index += 3) {
200
- var vertex = positionsValue.subarray(index, index + 3);
201
- var originVector = new _core2.Vector3(cartesianOrigin);
202
- var vertexVector = new _core2.Vector3(Array.from(vertex));
203
- vertexVector = vertexVector.subtract(originVector);
204
- newPositionsValue.set(vertexVector, index);
66
+ const indices = originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);
67
+
68
+ const meshIndex = gltfBuilder.addMesh({
69
+ attributes,
70
+ indices,
71
+ material: materialIndex
72
+ });
73
+
74
+ const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
75
+
76
+ const nodeIndex = gltfBuilder.addNode({
77
+ meshIndex,
78
+ matrix: transformMatrix
79
+ });
80
+ const sceneIndex = gltfBuilder.addScene({
81
+ nodeIndices: [nodeIndex]
82
+ });
83
+ gltfBuilder.setDefaultScene(sceneIndex);
84
+ gltfBuilder.createBinaryChunk();
85
+ const gltfBuffer = (0, _core.encodeSync)(gltfBuilder.gltf, _gltf.GLTFWriter);
86
+ return gltfBuffer;
87
+ }
88
+
89
+ async _addI3sTextureToGltf(i3sTile, gltfBuilder) {
90
+ const {
91
+ content: {
92
+ texture,
93
+ material,
94
+ attributes
95
+ },
96
+ header: {
97
+ textureFormat
205
98
  }
99
+ } = i3sTile;
100
+ let textureIndex = null;
101
+ let selectedTexture = texture;
206
102
 
207
- return newPositionsValue;
103
+ if (!texture && material) {
104
+ selectedTexture = material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture && material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
208
105
  }
209
- }, {
210
- key: "_generateTransformMatrix",
211
- value: function _generateTransformMatrix(cartesianOrigin) {
212
- var translateOriginMatrix = new _core2.Matrix4().translate(cartesianOrigin);
213
- var result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
214
- return result;
106
+
107
+ if (selectedTexture) {
108
+ const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
109
+
110
+ const imageBuffer = await (0, _core.encode)(selectedTexture, _images.ImageWriter);
111
+ const imageIndex = gltfBuilder.addImage(imageBuffer, mimeType);
112
+ textureIndex = gltfBuilder.addTexture({
113
+ imageIndex
114
+ });
115
+ delete attributes.colors;
215
116
  }
216
- }, {
217
- key: "_generateBatchId",
218
- value: function _generateBatchId(faceRanges) {
219
- var batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;
220
- var batchId = new Float32Array(batchIdArraySize);
221
- var rangeIndex = 0;
222
- var currentBatchId = 0;
223
-
224
- for (var index = 0; index < faceRanges.length / 2; index++) {
225
- var fromIndex = faceRanges[rangeIndex] * 3;
226
- var untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;
227
- batchId.fill(currentBatchId, fromIndex, untilPosition);
228
- rangeIndex += 2;
229
- currentBatchId += 1;
230
- }
231
117
 
232
- return batchId;
118
+ return textureIndex;
119
+ }
120
+
121
+ _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
122
+ const newPositionsValue = new Float32Array(positionsValue.length);
123
+
124
+ for (let index = 0; index < positionsValue.length; index += 3) {
125
+ const vertex = positionsValue.subarray(index, index + 3);
126
+ const cartesianOriginVector = new _core2.Vector3(cartesianOrigin);
127
+ let vertexVector = new _core2.Vector3(Array.from(vertex)).transform(modelMatrix).add(cartographicOrigin);
128
+
129
+ _geospatial.Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
130
+
131
+ vertexVector = scratchVector.subtract(cartesianOriginVector);
132
+ newPositionsValue.set(vertexVector, index);
233
133
  }
234
- }, {
235
- key: "_generateSynteticIndices",
236
- value: function _generateSynteticIndices(vertexCount) {
237
- var result = new Uint32Array(vertexCount);
238
134
 
239
- for (var index = 0; index < vertexCount; index++) {
240
- result.set([index], index);
241
- }
135
+ return newPositionsValue;
136
+ }
137
+
138
+ _generateTransformMatrix(cartesianOrigin) {
139
+ const translateOriginMatrix = new _core2.Matrix4().translate(cartesianOrigin);
140
+ const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
141
+ return result;
142
+ }
242
143
 
243
- return result;
144
+ _generateBatchId(faceRanges) {
145
+ const batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;
146
+ const batchId = new Float32Array(batchIdArraySize);
147
+ let rangeIndex = 0;
148
+ let currentBatchId = 0;
149
+
150
+ for (let index = 0; index < faceRanges.length / 2; index++) {
151
+ const fromIndex = faceRanges[rangeIndex] * 3;
152
+ const untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;
153
+ batchId.fill(currentBatchId, fromIndex, untilPosition);
154
+ rangeIndex += 2;
155
+ currentBatchId += 1;
244
156
  }
245
- }, {
246
- key: "_deduceMimeTypeFromFormat",
247
- value: function _deduceMimeTypeFromFormat(format) {
248
- switch (format) {
249
- case 'jpg':
250
- return 'image/jpeg';
251
-
252
- case 'png':
253
- return 'image/png';
254
-
255
- default:
256
- console.warn("Unexpected texture format in I3S: ".concat(format));
257
- return 'image/jpeg';
258
- }
157
+
158
+ return batchId;
159
+ }
160
+
161
+ _generateSynteticIndices(vertexCount) {
162
+ const result = new Uint32Array(vertexCount);
163
+
164
+ for (let index = 0; index < vertexCount; index++) {
165
+ result.set([index], index);
259
166
  }
260
- }, {
261
- key: "_convertI3sMaterialToGltfMaterial",
262
- value: function _convertI3sMaterialToGltfMaterial(material, textureIndex) {
263
- var isTextureIndexExists = textureIndex !== null;
264
-
265
- if (!material) {
266
- material = {
267
- alphaMode: 'OPAQUE',
268
- doubleSided: false,
269
- pbrMetallicRoughness: {
270
- metallicFactor: 0,
271
- roughnessFactor: 1
272
- }
273
- };
274
167
 
275
- if (isTextureIndexExists) {
276
- material.pbrMetallicRoughness.baseColorTexture = {
277
- index: textureIndex,
278
- texCoord: 0
279
- };
280
- } else {
281
- material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
282
- }
168
+ return result;
169
+ }
283
170
 
284
- return material;
285
- }
171
+ _deduceMimeTypeFromFormat(format) {
172
+ switch (format) {
173
+ case 'jpg':
174
+ return 'image/jpeg';
286
175
 
287
- if (textureIndex !== null) {
288
- material = this._setGltfTexture(material, textureIndex);
289
- }
176
+ case 'png':
177
+ return 'image/png';
290
178
 
291
- return material;
179
+ default:
180
+ console.warn("Unexpected texture format in I3S: ".concat(format));
181
+ return 'image/jpeg';
292
182
  }
293
- }, {
294
- key: "_setGltfTexture",
295
- value: function _setGltfTexture(materialDefinition, textureIndex) {
296
- var material = _objectSpread(_objectSpread({}, materialDefinition), {}, {
297
- pbrMetallicRoughness: _objectSpread({}, materialDefinition.pbrMetallicRoughness)
298
- });
183
+ }
184
+
185
+ _convertI3sMaterialToGltfMaterial(material, textureIndex) {
186
+ const isTextureIndexExists = textureIndex !== null;
299
187
 
300
- if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture) {
188
+ if (!material) {
189
+ material = {
190
+ alphaMode: 'OPAQUE',
191
+ doubleSided: false,
192
+ pbrMetallicRoughness: {
193
+ metallicFactor: 0,
194
+ roughnessFactor: 1
195
+ }
196
+ };
197
+
198
+ if (isTextureIndexExists) {
301
199
  material.pbrMetallicRoughness.baseColorTexture = {
302
200
  index: textureIndex,
303
201
  texCoord: 0
304
202
  };
305
- } else if (materialDefinition.emissiveTexture) {
306
- material.emissiveTexture = {
307
- index: textureIndex,
308
- texCoord: 0
309
- };
310
- } else if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
311
- material.pbrMetallicRoughness.metallicRoughnessTexture = {
312
- index: textureIndex,
313
- texCoord: 0
314
- };
315
- } else if (materialDefinition.normalTexture) {
316
- material.normalTexture = {
317
- index: textureIndex,
318
- texCoord: 0
319
- };
320
- } else if (materialDefinition.occlusionTexture) {
321
- material.occlusionTexture = {
322
- index: textureIndex,
323
- texCoord: 0
324
- };
203
+ } else {
204
+ material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
325
205
  }
326
206
 
327
207
  return material;
328
208
  }
329
- }, {
330
- key: "_getFeaturesLength",
331
- value: function _getFeaturesLength(attributes) {
332
- if (!attributes) {
333
- return 0;
334
- }
335
209
 
336
- var firstKey = Object.keys(attributes)[0];
337
- return attributes[firstKey].length;
210
+ if (textureIndex !== null) {
211
+ material = this._setGltfTexture(material, textureIndex);
338
212
  }
339
- }, {
340
- key: "_checkNormals",
341
- value: function _checkNormals(normals) {
342
- return normals.find(function (value) {
343
- return value;
344
- });
213
+
214
+ return material;
215
+ }
216
+
217
+ _setGltfTexture(materialDefinition, textureIndex) {
218
+ const material = { ...materialDefinition,
219
+ pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness
220
+ }
221
+ };
222
+
223
+ if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture) {
224
+ material.pbrMetallicRoughness.baseColorTexture = {
225
+ index: textureIndex,
226
+ texCoord: 0
227
+ };
228
+ } else if (materialDefinition.emissiveTexture) {
229
+ material.emissiveTexture = {
230
+ index: textureIndex,
231
+ texCoord: 0
232
+ };
233
+ } else if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
234
+ material.pbrMetallicRoughness.metallicRoughnessTexture = {
235
+ index: textureIndex,
236
+ texCoord: 0
237
+ };
238
+ } else if (materialDefinition.normalTexture) {
239
+ material.normalTexture = {
240
+ index: textureIndex,
241
+ texCoord: 0
242
+ };
243
+ } else if (materialDefinition.occlusionTexture) {
244
+ material.occlusionTexture = {
245
+ index: textureIndex,
246
+ texCoord: 0
247
+ };
345
248
  }
346
- }]);
347
- return B3dmConverter;
348
- }();
249
+
250
+ return material;
251
+ }
252
+
253
+ _getFeaturesLength(attributes) {
254
+ if (!attributes) {
255
+ return 0;
256
+ }
257
+
258
+ const firstKey = Object.keys(attributes)[0];
259
+ return firstKey ? attributes[firstKey].length : 0;
260
+ }
261
+
262
+ _checkNormals(normals) {
263
+ return normals.find(value => value);
264
+ }
265
+
266
+ }
349
267
 
350
268
  exports.default = B3dmConverter;
351
269
  //# sourceMappingURL=b3dm-converter.js.map