@loaders.gl/tile-converter 3.0.13 → 3.0.14
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.
- package/dist/dist.es5.min.js +3 -3
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +11 -11
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +422 -184
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +299 -202
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +8 -4
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +17 -7
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +65 -17
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +16 -16
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +33 -9
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +103 -93
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +505 -344
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +26 -30
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +203 -102
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +1510 -680
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js +25 -15
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +21 -12
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +4 -2
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +55 -15
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js +4 -2
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-server/app.js +6 -6
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +60 -20
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +41 -14
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +4 -4
- package/dist/es5/lib/geoid-height-model.js +114 -100
- package/dist/es5/lib/geoid-height-model.js.map +1 -1
- package/dist/es5/lib/pgm-parser.js +122 -68
- package/dist/es5/lib/pgm-parser.js.map +1 -1
- package/dist/es5/lib/utils/compress-util.js +345 -123
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +98 -20
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +152 -41
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/pgm-loader.js +5 -3
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +11 -3
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/scripts/converter.js +134 -71
- package/package.json +14 -14
- package/src/i3s-converter/i3s-converter.ts +10 -3
|
@@ -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","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","i3s","loadOptions","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,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EAA+B;AAC7B,aAAOZ,SAAS,CAACY,eAAV,CAA0BC,SAAjC;AACD,KAFD,MAEO,IAAIb,SAAS,CAACc,SAAd,EAAyB;AAC9B,aAAO,OAAP;AACD;;AACD,WAAO,EAAP;AACD;;AAMOL,EAAAA,oBAAoB,CAACH,cAAD,EAA2C;AACrE,SAAK,IAAIR,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGQ,cAAc,CAACP,MAA3C,EAAmDD,KAAK,EAAxD,EAA4D;AAC1D,YAAMiB,eAAe,GAAGT,cAAc,CAACR,KAAD,CAAtC;;AAEA,WAAK,MAAMkB,GAAX,IAAkBD,eAAlB,EAAmC;AACjCA,QAAAA,eAAe,CAACC,GAAD,CAAf,GAAuBC,KAAK,CAACC,IAAN,CAAWH,eAAe,CAACC,GAAD,CAA1B,CAAvB;AACD;AACF;AACF;;AAM8B,QAAjB/D,iBAAiB,CAACkE,MAAD,EAIb;AAChB,UAAMC,SAAS,GAAG,MAAM,yCAAmBD,MAAnB,CAAxB;;AACA,UAAME,IAAI,GAAG3F,iBAAQC,MAAR,CAAe,KAAKX,mBAApB,CAAb;;AACA,UAAMsG,cAAc,GAAG,oCAAcD,IAAd,CAAvB;AAEAzF,IAAAA,OAAO,CAACC,GAAR;AACAD,IAAAA,OAAO,CAACC,GAAR,gCAAoCnB,GAApC;AACAkB,IAAAA,OAAO,CAACC,GAAR,kCAAsCyF,cAAtC;AACA1F,IAAAA,OAAO,CAACC,GAAR,mBAA8B,KAAKd,aAAnC;AACAa,IAAAA,OAAO,CAACC,GAAR,mBAA8BuF,SAA9B,EAAyC,QAAzC;AACAxF,IAAAA,OAAO,CAACC,GAAR;AACD;;AApQmC","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","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,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KAAK,EAAxD,EAA4D;AAC1D,YAAMiB,eAAe,GAAGP,cAAc,CAACV,KAAD,CAAtC;;AAEA,aAAK,IAAMkB,GAAX,IAAkBD,eAAlB,EAAmC;AACjCA,UAAAA,eAAe,CAACC,GAAD,CAAf,GAAuBC,KAAK,CAACC,IAAN,CAAWH,eAAe,CAACC,GAAD,CAA1B,CAAvB;AACD;AACF;AACF;;;;yFAMD,kBAAgCG,MAAhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAK0B,yCAAmBA,MAAnB,CAL1B;;AAAA;AAKQC,gBAAAA,SALR;AAMQC,gBAAAA,IANR,GAMe3F,iBAAQC,MAAR,CAAe,KAAKV,mBAApB,CANf;AAOQqG,gBAAAA,cAPR,GAOyB,oCAAcD,IAAd,CAPzB;AASEzF,gBAAAA,OAAO,CAACC,GAAR;AACAD,gBAAAA,OAAO,CAACC,GAAR,gCAAoCjB,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,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 _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
|
+
|
|
8
20
|
var _core = require("@loaders.gl/core");
|
|
9
21
|
|
|
10
22
|
var _gltf = require("@loaders.gl/gltf");
|
|
@@ -15,240 +27,325 @@ var _images = require("@loaders.gl/images");
|
|
|
15
27
|
|
|
16
28
|
var _core2 = require("@math.gl/core");
|
|
17
29
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class B3dmConverter {
|
|
21
|
-
async convert(i3sTile, attributes = null) {
|
|
22
|
-
this.i3sTile = i3sTile;
|
|
23
|
-
const gltf = await this.buildGltf(i3sTile);
|
|
24
|
-
const b3dm = (0, _core.encodeSync)({
|
|
25
|
-
gltfEncoded: new Uint8Array(gltf),
|
|
26
|
-
type: 'b3dm',
|
|
27
|
-
featuresLength: this._getFeaturesLength(attributes),
|
|
28
|
-
batchTable: attributes
|
|
29
|
-
}, _dTiles.Tile3DWriter);
|
|
30
|
-
return b3dm;
|
|
31
|
-
}
|
|
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; }
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
attributes,
|
|
37
|
-
indices: originalIndices,
|
|
38
|
-
cartesianOrigin
|
|
39
|
-
} = i3sTile.content;
|
|
40
|
-
const gltfBuilder = new _gltf.GLTFScenegraph();
|
|
41
|
-
const textureIndex = await this._addI3sTextureToGltf(i3sTile, gltfBuilder);
|
|
42
|
-
|
|
43
|
-
const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
|
|
44
|
-
|
|
45
|
-
const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
|
|
46
|
-
const positions = attributes.positions;
|
|
47
|
-
const positionsValue = positions.value;
|
|
48
|
-
attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin);
|
|
49
|
-
|
|
50
|
-
if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
|
|
51
|
-
delete attributes.normals;
|
|
52
|
-
}
|
|
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; }
|
|
33
|
+
|
|
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]);
|
|
53
35
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
attributes,
|
|
58
|
-
indices,
|
|
59
|
-
material: materialIndex
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
|
|
63
|
-
|
|
64
|
-
const nodeIndex = gltfBuilder.addNode({
|
|
65
|
-
meshIndex,
|
|
66
|
-
matrix: transformMatrix
|
|
67
|
-
});
|
|
68
|
-
const sceneIndex = gltfBuilder.addScene({
|
|
69
|
-
nodeIndices: [nodeIndex]
|
|
70
|
-
});
|
|
71
|
-
gltfBuilder.setDefaultScene(sceneIndex);
|
|
72
|
-
gltfBuilder.createBinaryChunk();
|
|
73
|
-
const gltfBuffer = (0, _core.encodeSync)(gltfBuilder.gltf, _gltf.GLTFWriter);
|
|
74
|
-
return gltfBuffer;
|
|
36
|
+
var B3dmConverter = function () {
|
|
37
|
+
function B3dmConverter() {
|
|
38
|
+
(0, _classCallCheck2.default)(this, B3dmConverter);
|
|
75
39
|
}
|
|
76
40
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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);
|
|
86
78
|
}
|
|
87
|
-
} = i3sTile;
|
|
88
|
-
let textureIndex = null;
|
|
89
|
-
let selectedTexture = texture;
|
|
90
79
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
}
|
|
105
139
|
|
|
106
|
-
|
|
107
|
-
|
|
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
|
+
}
|
|
108
191
|
|
|
109
|
-
|
|
110
|
-
|
|
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);
|
|
205
|
+
}
|
|
111
206
|
|
|
112
|
-
|
|
113
|
-
const vertex = positionsValue.subarray(index, index + 3);
|
|
114
|
-
const originVector = new _core2.Vector3(cartesianOrigin);
|
|
115
|
-
let vertexVector = new _core2.Vector3(Array.from(vertex));
|
|
116
|
-
vertexVector = vertexVector.subtract(originVector);
|
|
117
|
-
newPositionsValue.set(vertexVector, index);
|
|
207
|
+
return newPositionsValue;
|
|
118
208
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
_generateBatchId(faceRanges) {
|
|
130
|
-
const batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;
|
|
131
|
-
const batchId = new Float32Array(batchIdArraySize);
|
|
132
|
-
let rangeIndex = 0;
|
|
133
|
-
let currentBatchId = 0;
|
|
134
|
-
|
|
135
|
-
for (let index = 0; index < faceRanges.length / 2; index++) {
|
|
136
|
-
const fromIndex = faceRanges[rangeIndex] * 3;
|
|
137
|
-
const untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;
|
|
138
|
-
batchId.fill(currentBatchId, fromIndex, untilPosition);
|
|
139
|
-
rangeIndex += 2;
|
|
140
|
-
currentBatchId += 1;
|
|
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;
|
|
141
215
|
}
|
|
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
|
+
}
|
|
142
231
|
|
|
143
|
-
|
|
144
|
-
|
|
232
|
+
return batchId;
|
|
233
|
+
}
|
|
234
|
+
}, {
|
|
235
|
+
key: "_generateSynteticIndices",
|
|
236
|
+
value: function _generateSynteticIndices(vertexCount) {
|
|
237
|
+
var result = new Uint32Array(vertexCount);
|
|
145
238
|
|
|
146
|
-
|
|
147
|
-
|
|
239
|
+
for (var index = 0; index < vertexCount; index++) {
|
|
240
|
+
result.set([index], index);
|
|
241
|
+
}
|
|
148
242
|
|
|
149
|
-
|
|
150
|
-
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
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
|
+
}
|
|
151
259
|
}
|
|
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
|
+
};
|
|
152
274
|
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
}
|
|
155
283
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
case 'jpg':
|
|
159
|
-
return 'image/jpeg';
|
|
284
|
+
return material;
|
|
285
|
+
}
|
|
160
286
|
|
|
161
|
-
|
|
162
|
-
|
|
287
|
+
if (textureIndex !== null) {
|
|
288
|
+
material = this._setGltfTexture(material, textureIndex);
|
|
289
|
+
}
|
|
163
290
|
|
|
164
|
-
|
|
165
|
-
console.warn("Unexpected texture format in I3S: ".concat(format));
|
|
166
|
-
return 'image/jpeg';
|
|
291
|
+
return material;
|
|
167
292
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
material = {
|
|
175
|
-
alphaMode: 'OPAQUE',
|
|
176
|
-
doubleSided: false,
|
|
177
|
-
pbrMetallicRoughness: {
|
|
178
|
-
metallicFactor: 0,
|
|
179
|
-
roughnessFactor: 1
|
|
180
|
-
}
|
|
181
|
-
};
|
|
293
|
+
}, {
|
|
294
|
+
key: "_setGltfTexture",
|
|
295
|
+
value: function _setGltfTexture(materialDefinition, textureIndex) {
|
|
296
|
+
var material = _objectSpread(_objectSpread({}, materialDefinition), {}, {
|
|
297
|
+
pbrMetallicRoughness: _objectSpread({}, materialDefinition.pbrMetallicRoughness)
|
|
298
|
+
});
|
|
182
299
|
|
|
183
|
-
if (
|
|
300
|
+
if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture) {
|
|
184
301
|
material.pbrMetallicRoughness.baseColorTexture = {
|
|
185
302
|
index: textureIndex,
|
|
186
303
|
texCoord: 0
|
|
187
304
|
};
|
|
188
|
-
} else {
|
|
189
|
-
material.
|
|
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
|
+
};
|
|
190
325
|
}
|
|
191
326
|
|
|
192
327
|
return material;
|
|
193
328
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return material;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
_setGltfTexture(materialDefinition, textureIndex) {
|
|
203
|
-
const material = { ...materialDefinition,
|
|
204
|
-
pbrMetallicRoughness: { ...materialDefinition.pbrMetallicRoughness
|
|
329
|
+
}, {
|
|
330
|
+
key: "_getFeaturesLength",
|
|
331
|
+
value: function _getFeaturesLength(attributes) {
|
|
332
|
+
if (!attributes) {
|
|
333
|
+
return 0;
|
|
205
334
|
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture) {
|
|
209
|
-
material.pbrMetallicRoughness.baseColorTexture = {
|
|
210
|
-
index: textureIndex,
|
|
211
|
-
texCoord: 0
|
|
212
|
-
};
|
|
213
|
-
} else if (materialDefinition.emissiveTexture) {
|
|
214
|
-
material.emissiveTexture = {
|
|
215
|
-
index: textureIndex,
|
|
216
|
-
texCoord: 0
|
|
217
|
-
};
|
|
218
|
-
} else if (materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
219
|
-
material.pbrMetallicRoughness.metallicRoughnessTexture = {
|
|
220
|
-
index: textureIndex,
|
|
221
|
-
texCoord: 0
|
|
222
|
-
};
|
|
223
|
-
} else if (materialDefinition.normalTexture) {
|
|
224
|
-
material.normalTexture = {
|
|
225
|
-
index: textureIndex,
|
|
226
|
-
texCoord: 0
|
|
227
|
-
};
|
|
228
|
-
} else if (materialDefinition.occlusionTexture) {
|
|
229
|
-
material.occlusionTexture = {
|
|
230
|
-
index: textureIndex,
|
|
231
|
-
texCoord: 0
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return material;
|
|
236
|
-
}
|
|
237
335
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return 0;
|
|
336
|
+
var firstKey = Object.keys(attributes)[0];
|
|
337
|
+
return attributes[firstKey].length;
|
|
241
338
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
}
|
|
339
|
+
}, {
|
|
340
|
+
key: "_checkNormals",
|
|
341
|
+
value: function _checkNormals(normals) {
|
|
342
|
+
return normals.find(function (value) {
|
|
343
|
+
return value;
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}]);
|
|
347
|
+
return B3dmConverter;
|
|
348
|
+
}();
|
|
252
349
|
|
|
253
350
|
exports.default = B3dmConverter;
|
|
254
351
|
//# sourceMappingURL=b3dm-converter.js.map
|