@loaders.gl/tile-converter 3.1.0-beta.2 → 3.1.1

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 (153) hide show
  1. package/dist/bundle.js +2413 -1590
  2. package/dist/converter.min.js +20 -20
  3. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +429 -189
  4. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  5. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +306 -209
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  7. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +8 -4
  8. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  9. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +13 -13
  10. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  11. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +51 -32
  12. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  13. package/dist/es5/bundle.js +1 -1
  14. package/dist/es5/bundle.js.map +1 -1
  15. package/dist/es5/deps-installer/deps-installer.js +61 -17
  16. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +55 -16
  18. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  19. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +33 -9
  20. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  21. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +103 -93
  22. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  24. package/dist/es5/i3s-converter/helpers/geometry-converter.js +547 -336
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/node-debug.js +27 -31
  27. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/node-pages.js +209 -101
  29. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  30. package/dist/es5/i3s-converter/i3s-converter.js +1645 -700
  31. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/json-templates/layers.js +213 -177
  33. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  34. package/dist/es5/i3s-converter/json-templates/metadata.js +24 -20
  35. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  36. package/dist/es5/i3s-converter/json-templates/node.js +92 -74
  37. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  38. package/dist/es5/i3s-converter/json-templates/scene-server.js +34 -28
  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 +162 -107
  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 -2
  43. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  44. package/dist/es5/i3s-converter/types.js +2 -0
  45. package/dist/es5/i3s-converter/types.js.map +1 -0
  46. package/dist/es5/i3s-server/app.js +6 -6
  47. package/dist/es5/i3s-server/app.js.map +1 -1
  48. package/dist/es5/i3s-server/controllers/index-controller.js +60 -20
  49. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  50. package/dist/es5/i3s-server/routes/index.js +41 -14
  51. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  52. package/dist/es5/index.js +4 -4
  53. package/dist/es5/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  54. package/dist/es5/lib/utils/compress-util.js +345 -123
  55. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  56. package/dist/es5/lib/utils/file-utils.js +98 -20
  57. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  58. package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
  59. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  60. package/dist/es5/lib/utils/statistic-utills.js +152 -41
  61. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  62. package/dist/es5/pgm-loader.js +31 -4
  63. package/dist/es5/pgm-loader.js.map +1 -1
  64. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +7 -6
  65. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  66. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +7 -0
  67. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  68. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  69. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -1
  70. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  71. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +12 -9
  72. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  73. package/dist/esm/deps-installer/deps-installer.js +2 -6
  74. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  75. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +35 -3
  76. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  77. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +2 -2
  78. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  79. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  80. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  81. package/dist/esm/i3s-converter/helpers/geometry-converter.js +50 -16
  82. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  83. package/dist/esm/i3s-converter/helpers/node-debug.js +2 -4
  84. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  85. package/dist/esm/i3s-converter/helpers/node-pages.js +15 -4
  86. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  87. package/dist/esm/i3s-converter/i3s-converter.js +147 -62
  88. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/json-templates/layers.js +37 -27
  90. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
  91. package/dist/esm/i3s-converter/json-templates/metadata.js +2 -2
  92. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  93. package/dist/esm/i3s-converter/json-templates/node.js +16 -12
  94. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
  95. package/dist/esm/i3s-converter/json-templates/scene-server.js +2 -2
  96. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  97. package/dist/esm/i3s-converter/json-templates/shared-resources.js +19 -14
  98. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  99. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  100. package/dist/esm/i3s-converter/types.js +2 -0
  101. package/dist/esm/i3s-converter/types.js.map +1 -0
  102. package/dist/esm/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  103. package/dist/esm/pgm-loader.js +3 -3
  104. package/dist/esm/pgm-loader.js.map +1 -1
  105. package/package.json +16 -14
  106. package/src/3d-tiles-converter/3d-tiles-converter.ts +21 -20
  107. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +19 -2
  108. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  109. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  110. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  111. package/src/deps-installer/deps-installer.js +2 -2
  112. package/src/i3s-converter/helpers/coordinate-converter.ts +62 -9
  113. package/src/i3s-converter/helpers/{create-scene-server-path.js → create-scene-server-path.ts} +2 -2
  114. package/src/i3s-converter/helpers/{geometry-attributes.js → geometry-attributes.ts} +4 -4
  115. package/src/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  116. package/src/i3s-converter/helpers/geometry-converter.js +63 -13
  117. package/src/i3s-converter/helpers/{node-debug.js → node-debug.ts} +3 -2
  118. package/src/i3s-converter/helpers/{node-pages.js → node-pages.ts} +41 -26
  119. package/src/i3s-converter/i3s-converter.ts +204 -133
  120. package/src/i3s-converter/json-templates/{layers.js → layers.ts} +29 -27
  121. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  122. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  123. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  124. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +14 -14
  125. package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  126. package/src/i3s-converter/types.ts +14 -0
  127. package/src/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  128. package/src/pgm-loader.ts +2 -2
  129. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  130. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  131. package/dist/es5/i3s-converter/helpers/node-pages.d.ts +0 -144
  132. package/dist/es5/lib/geoid-height-model.d.ts +0 -41
  133. package/dist/es5/lib/geoid-height-model.js +0 -149
  134. package/dist/es5/lib/geoid-height-model.js.map +0 -1
  135. package/dist/es5/lib/pgm-parser.d.ts +0 -14
  136. package/dist/es5/lib/pgm-parser.js +0 -192
  137. package/dist/es5/lib/pgm-parser.js.map +0 -1
  138. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  139. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  140. package/dist/esm/i3s-converter/helpers/node-pages.d.ts +0 -144
  141. package/dist/esm/lib/geoid-height-model.d.ts +0 -41
  142. package/dist/esm/lib/geoid-height-model.js +0 -140
  143. package/dist/esm/lib/geoid-height-model.js.map +0 -1
  144. package/dist/esm/lib/pgm-parser.d.ts +0 -14
  145. package/dist/esm/lib/pgm-parser.js +0 -183
  146. package/dist/esm/lib/pgm-parser.js.map +0 -1
  147. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  148. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  149. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  150. package/src/lib/geoid-height-model.d.ts +0 -41
  151. package/src/lib/geoid-height-model.js +0 -239
  152. package/src/lib/pgm-parser.d.ts +0 -14
  153. package/src/lib/pgm-parser.js +0 -179
@@ -1 +1 @@
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"],"mapp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A,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
+ {"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","loadOptions","i3s","coordinateSystem","COORDINATE_SYSTEM","LNGLAT_OFFSETS","rootNode","root","header","obb","mbs","rootTile","boundingVolume","box","geometricError","children","_addChildren","tileset","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","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;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAEA,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,iBAAqBN,OAArB;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,GAAR,CAAY,qBAAZ;AAXF;AAAA,uBAYgC,gBAAKJ,WAAL,EAAkBK,oBAAlB,CAZhC;;AAAA;AAYE,qBAAKZ,gBAZP;AAaEU,gBAAAA,OAAO,CAACC,GAAR,CAAY,6BAAZ;AAb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ACAY,gBAAAA,OAAO,CAACC,GAAR,mBAA8B0F,SAA9B,EAAyC,QAAzC;AACA3F,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, 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';\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\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 public 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 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\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: FeatureAttribute | null = 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: 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"],"file":"3d-tiles-converter.js"}
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.default = void 0;
7
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
+
8
20
  var _core = require("@loaders.gl/core");
9
21
 
10
22
  var _gltf = require("@loaders.gl/gltf");
@@ -19,251 +31,336 @@ var _geospatial = require("@math.gl/geospatial");
19
31
 
20
32
  var _textureAtlas = require("./texture-atlas");
21
33
 
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();
24
-
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;
36
- }
34
+ 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; }
37
35
 
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
- }
36
+ 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; }
59
37
 
60
- attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
38
+ 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]);
39
+ var scratchVector = new _core2.Vector3();
61
40
 
62
- if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
63
- delete attributes.normals;
64
- }
65
-
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;
41
+ var B3dmConverter = function () {
42
+ function B3dmConverter() {
43
+ (0, _classCallCheck2.default)(this, B3dmConverter);
44
+ (0, _defineProperty2.default)(this, "rtcCenter", void 0);
45
+ (0, _defineProperty2.default)(this, "i3sTile", void 0);
87
46
  }
88
47
 
89
- async _addI3sTextureToGltf(i3sTile, gltfBuilder) {
90
- const {
91
- content: {
92
- texture,
93
- material,
94
- attributes
95
- },
96
- header: {
97
- textureFormat
48
+ (0, _createClass2.default)(B3dmConverter, [{
49
+ key: "convert",
50
+ value: function () {
51
+ var _convert = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(i3sTile) {
52
+ var attributes,
53
+ gltf,
54
+ b3dm,
55
+ _args = arguments;
56
+ return _regenerator.default.wrap(function _callee$(_context) {
57
+ while (1) {
58
+ switch (_context.prev = _context.next) {
59
+ case 0:
60
+ attributes = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
61
+ this.i3sTile = i3sTile;
62
+ _context.next = 4;
63
+ return this.buildGltf(i3sTile);
64
+
65
+ case 4:
66
+ gltf = _context.sent;
67
+ b3dm = (0, _core.encodeSync)({
68
+ gltfEncoded: new Uint8Array(gltf),
69
+ type: 'b3dm',
70
+ featuresLength: this._getFeaturesLength(attributes),
71
+ batchTable: attributes
72
+ }, _dTiles.Tile3DWriter);
73
+ return _context.abrupt("return", b3dm);
74
+
75
+ case 7:
76
+ case "end":
77
+ return _context.stop();
78
+ }
79
+ }
80
+ }, _callee, this);
81
+ }));
82
+
83
+ function convert(_x) {
84
+ return _convert.apply(this, arguments);
98
85
  }
99
- } = i3sTile;
100
- let textureIndex = null;
101
- let selectedTexture = texture;
102
-
103
- if (!texture && material) {
104
- selectedTexture = material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture && material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
105
- }
106
86
 
107
- if (selectedTexture) {
108
- const mimeType = this._deduceMimeTypeFromFormat(textureFormat);
87
+ return convert;
88
+ }()
89
+ }, {
90
+ key: "buildGltf",
91
+ value: function () {
92
+ var _buildGltf = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(i3sTile) {
93
+ var _i3sTile$content, material, attributes, originalIndices, cartesianOrigin, cartographicOrigin, modelMatrix, gltfBuilder, textureIndex, pbrMaterialInfo, materialIndex, positions, positionsValue, indices, meshIndex, transformMatrix, nodeIndex, sceneIndex, gltfBuffer;
94
+
95
+ return _regenerator.default.wrap(function _callee2$(_context2) {
96
+ while (1) {
97
+ switch (_context2.prev = _context2.next) {
98
+ case 0:
99
+ _i3sTile$content = i3sTile.content, material = _i3sTile$content.material, attributes = _i3sTile$content.attributes, originalIndices = _i3sTile$content.indices, cartesianOrigin = _i3sTile$content.cartesianOrigin, cartographicOrigin = _i3sTile$content.cartographicOrigin, modelMatrix = _i3sTile$content.modelMatrix;
100
+ gltfBuilder = new _gltf.GLTFScenegraph();
101
+ _context2.next = 4;
102
+ return this._addI3sTextureToGltf(i3sTile, gltfBuilder);
103
+
104
+ case 4:
105
+ textureIndex = _context2.sent;
106
+ pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
107
+ materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
108
+ positions = attributes.positions;
109
+ positionsValue = positions.value;
110
+
111
+ if (attributes.uvRegions && attributes.texCoords) {
112
+ attributes.texCoords.value = (0, _textureAtlas.convertTextureAtlas)(attributes.texCoords.value, attributes.uvRegions.value);
113
+ }
114
+
115
+ attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
116
+
117
+ if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
118
+ delete attributes.normals;
119
+ }
120
+
121
+ indices = originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);
122
+ meshIndex = gltfBuilder.addMesh({
123
+ attributes: attributes,
124
+ indices: indices,
125
+ material: materialIndex
126
+ });
127
+ transformMatrix = this._generateTransformMatrix(cartesianOrigin);
128
+ nodeIndex = gltfBuilder.addNode({
129
+ meshIndex: meshIndex,
130
+ matrix: transformMatrix
131
+ });
132
+ sceneIndex = gltfBuilder.addScene({
133
+ nodeIndices: [nodeIndex]
134
+ });
135
+ gltfBuilder.setDefaultScene(sceneIndex);
136
+ gltfBuilder.createBinaryChunk();
137
+ gltfBuffer = (0, _core.encodeSync)(gltfBuilder.gltf, _gltf.GLTFWriter);
138
+ return _context2.abrupt("return", gltfBuffer);
139
+
140
+ case 21:
141
+ case "end":
142
+ return _context2.stop();
143
+ }
144
+ }
145
+ }, _callee2, this);
146
+ }));
147
+
148
+ function buildGltf(_x2) {
149
+ return _buildGltf.apply(this, arguments);
150
+ }
109
151
 
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;
116
- }
152
+ return buildGltf;
153
+ }()
154
+ }, {
155
+ key: "_addI3sTextureToGltf",
156
+ value: function () {
157
+ var _addI3sTextureToGltf2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(i3sTile, gltfBuilder) {
158
+ var _i3sTile$content2, texture, material, attributes, textureFormat, textureIndex, selectedTexture, mimeType, imageBuffer, imageIndex;
159
+
160
+ return _regenerator.default.wrap(function _callee3$(_context3) {
161
+ while (1) {
162
+ switch (_context3.prev = _context3.next) {
163
+ case 0:
164
+ _i3sTile$content2 = i3sTile.content, texture = _i3sTile$content2.texture, material = _i3sTile$content2.material, attributes = _i3sTile$content2.attributes, textureFormat = i3sTile.header.textureFormat;
165
+ textureIndex = null;
166
+ selectedTexture = texture;
167
+
168
+ if (!texture && material) {
169
+ selectedTexture = material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture && material.pbrMetallicRoughness.baseColorTexture.texture.source.image;
170
+ }
171
+
172
+ if (!selectedTexture) {
173
+ _context3.next = 12;
174
+ break;
175
+ }
176
+
177
+ mimeType = this._deduceMimeTypeFromFormat(textureFormat);
178
+ _context3.next = 8;
179
+ return (0, _core.encode)(selectedTexture, _images.ImageWriter);
180
+
181
+ case 8:
182
+ imageBuffer = _context3.sent;
183
+ imageIndex = gltfBuilder.addImage(imageBuffer, mimeType);
184
+ textureIndex = gltfBuilder.addTexture({
185
+ imageIndex: imageIndex
186
+ });
187
+ delete attributes.colors;
188
+
189
+ case 12:
190
+ return _context3.abrupt("return", textureIndex);
191
+
192
+ case 13:
193
+ case "end":
194
+ return _context3.stop();
195
+ }
196
+ }
197
+ }, _callee3, this);
198
+ }));
199
+
200
+ function _addI3sTextureToGltf(_x3, _x4) {
201
+ return _addI3sTextureToGltf2.apply(this, arguments);
202
+ }
117
203
 
118
- return textureIndex;
119
- }
204
+ return _addI3sTextureToGltf;
205
+ }()
206
+ }, {
207
+ key: "_normalizePositions",
208
+ value: function _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
209
+ var newPositionsValue = new Float32Array(positionsValue.length);
120
210
 
121
- _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
122
- const newPositionsValue = new Float32Array(positionsValue.length);
211
+ for (var index = 0; index < positionsValue.length; index += 3) {
212
+ var vertex = positionsValue.subarray(index, index + 3);
213
+ var cartesianOriginVector = new _core2.Vector3(cartesianOrigin);
214
+ var vertexVector = new _core2.Vector3(Array.from(vertex)).transform(modelMatrix).add(cartographicOrigin);
123
215
 
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);
216
+ _geospatial.Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
128
217
 
129
- _geospatial.Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
218
+ vertexVector = scratchVector.subtract(cartesianOriginVector);
219
+ newPositionsValue.set(vertexVector, index);
220
+ }
130
221
 
131
- vertexVector = scratchVector.subtract(cartesianOriginVector);
132
- newPositionsValue.set(vertexVector, index);
222
+ return newPositionsValue;
133
223
  }
134
-
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
- }
143
-
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;
224
+ }, {
225
+ key: "_generateTransformMatrix",
226
+ value: function _generateTransformMatrix(cartesianOrigin) {
227
+ var translateOriginMatrix = new _core2.Matrix4().translate(cartesianOrigin);
228
+ var result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
229
+ return result;
156
230
  }
231
+ }, {
232
+ key: "_generateBatchId",
233
+ value: function _generateBatchId(faceRanges) {
234
+ var batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;
235
+ var batchId = new Float32Array(batchIdArraySize);
236
+ var rangeIndex = 0;
237
+ var currentBatchId = 0;
238
+
239
+ for (var index = 0; index < faceRanges.length / 2; index++) {
240
+ var fromIndex = faceRanges[rangeIndex] * 3;
241
+ var untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;
242
+ batchId.fill(currentBatchId, fromIndex, untilPosition);
243
+ rangeIndex += 2;
244
+ currentBatchId += 1;
245
+ }
157
246
 
158
- return batchId;
159
- }
247
+ return batchId;
248
+ }
249
+ }, {
250
+ key: "_generateSynteticIndices",
251
+ value: function _generateSynteticIndices(vertexCount) {
252
+ var result = new Uint32Array(vertexCount);
160
253
 
161
- _generateSynteticIndices(vertexCount) {
162
- const result = new Uint32Array(vertexCount);
254
+ for (var index = 0; index < vertexCount; index++) {
255
+ result.set([index], index);
256
+ }
163
257
 
164
- for (let index = 0; index < vertexCount; index++) {
165
- result.set([index], index);
258
+ return result;
259
+ }
260
+ }, {
261
+ key: "_deduceMimeTypeFromFormat",
262
+ value: function _deduceMimeTypeFromFormat(format) {
263
+ switch (format) {
264
+ case 'jpg':
265
+ return 'image/jpeg';
266
+
267
+ case 'png':
268
+ return 'image/png';
269
+
270
+ default:
271
+ console.warn("Unexpected texture format in I3S: ".concat(format));
272
+ return 'image/jpeg';
273
+ }
166
274
  }
275
+ }, {
276
+ key: "_convertI3sMaterialToGltfMaterial",
277
+ value: function _convertI3sMaterialToGltfMaterial(material, textureIndex) {
278
+ var isTextureIndexExists = textureIndex !== null;
279
+
280
+ if (!material) {
281
+ material = {
282
+ alphaMode: 'OPAQUE',
283
+ doubleSided: false,
284
+ pbrMetallicRoughness: {
285
+ metallicFactor: 0,
286
+ roughnessFactor: 1
287
+ }
288
+ };
167
289
 
168
- return result;
169
- }
290
+ if (isTextureIndexExists) {
291
+ material.pbrMetallicRoughness.baseColorTexture = {
292
+ index: textureIndex,
293
+ texCoord: 0
294
+ };
295
+ } else {
296
+ material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
297
+ }
170
298
 
171
- _deduceMimeTypeFromFormat(format) {
172
- switch (format) {
173
- case 'jpg':
174
- return 'image/jpeg';
299
+ return material;
300
+ }
175
301
 
176
- case 'png':
177
- return 'image/png';
302
+ if (textureIndex !== null) {
303
+ material = this._setGltfTexture(material, textureIndex);
304
+ }
178
305
 
179
- default:
180
- console.warn("Unexpected texture format in I3S: ".concat(format));
181
- return 'image/jpeg';
306
+ return material;
182
307
  }
183
- }
184
-
185
- _convertI3sMaterialToGltfMaterial(material, textureIndex) {
186
- const isTextureIndexExists = textureIndex !== null;
187
-
188
- if (!material) {
189
- material = {
190
- alphaMode: 'OPAQUE',
191
- doubleSided: false,
192
- pbrMetallicRoughness: {
193
- metallicFactor: 0,
194
- roughnessFactor: 1
195
- }
196
- };
308
+ }, {
309
+ key: "_setGltfTexture",
310
+ value: function _setGltfTexture(materialDefinition, textureIndex) {
311
+ var material = _objectSpread(_objectSpread({}, materialDefinition), {}, {
312
+ pbrMetallicRoughness: _objectSpread({}, materialDefinition.pbrMetallicRoughness)
313
+ });
197
314
 
198
- if (isTextureIndexExists) {
315
+ if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture) {
199
316
  material.pbrMetallicRoughness.baseColorTexture = {
200
317
  index: textureIndex,
201
318
  texCoord: 0
202
319
  };
203
- } else {
204
- material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];
320
+ } else if (materialDefinition.emissiveTexture) {
321
+ material.emissiveTexture = {
322
+ index: textureIndex,
323
+ texCoord: 0
324
+ };
325
+ } else if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
326
+ material.pbrMetallicRoughness.metallicRoughnessTexture = {
327
+ index: textureIndex,
328
+ texCoord: 0
329
+ };
330
+ } else if (materialDefinition.normalTexture) {
331
+ material.normalTexture = {
332
+ index: textureIndex,
333
+ texCoord: 0
334
+ };
335
+ } else if (materialDefinition.occlusionTexture) {
336
+ material.occlusionTexture = {
337
+ index: textureIndex,
338
+ texCoord: 0
339
+ };
205
340
  }
206
341
 
207
342
  return material;
208
343
  }
209
-
210
- if (textureIndex !== null) {
211
- material = this._setGltfTexture(material, textureIndex);
212
- }
213
-
214
- return material;
215
- }
216
-
217
- _setGltfTexture(materialDefinition, textureIndex) {
218
- const material = { ...materialDefinition,
219
- pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness
344
+ }, {
345
+ key: "_getFeaturesLength",
346
+ value: function _getFeaturesLength(attributes) {
347
+ if (!attributes) {
348
+ return 0;
220
349
  }
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
- };
248
- }
249
-
250
- return material;
251
- }
252
350
 
253
- _getFeaturesLength(attributes) {
254
- if (!attributes) {
255
- return 0;
351
+ var firstKey = Object.keys(attributes)[0];
352
+ return firstKey ? attributes[firstKey].length : 0;
256
353
  }
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
- }
354
+ }, {
355
+ key: "_checkNormals",
356
+ value: function _checkNormals(normals) {
357
+ return normals.find(function (value) {
358
+ return value;
359
+ });
360
+ }
361
+ }]);
362
+ return B3dmConverter;
363
+ }();
267
364
 
268
365
  exports.default = B3dmConverter;
269
366
  //# sourceMappingURL=b3dm-converter.js.map