@loaders.gl/tile-converter 3.1.4 → 3.1.8
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/converter.min.js +21 -21
- package/dist/dist.min.js +1446 -239
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +18 -9
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +78 -35
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +12 -10
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +15 -7
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-pages.js +2 -7
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +3 -3
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/package.json +15 -15
- package/src/i3s-converter/helpers/geometry-converter.js +13 -7
- package/src/i3s-converter/helpers/node-pages.ts +6 -6
- package/src/i3s-converter/i3s-converter.ts +3 -3
|
@@ -39,6 +39,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
39
39
|
|
|
40
40
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
41
41
|
|
|
42
|
+
var DEFAULT_ROUGHNESS_FACTOR = 1;
|
|
43
|
+
var DEFAULT_METALLIC_FACTOR = 1;
|
|
42
44
|
var VALUES_PER_VERTEX = 3;
|
|
43
45
|
var VALUES_PER_TEX_COORD = 2;
|
|
44
46
|
var VALUES_PER_COLOR_ELEMENT = 4;
|
|
@@ -573,6 +575,8 @@ function convertMaterials(tileContent) {
|
|
|
573
575
|
}
|
|
574
576
|
|
|
575
577
|
function convertMaterial(sourceMaterial) {
|
|
578
|
+
var _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
|
|
579
|
+
|
|
576
580
|
var material = {
|
|
577
581
|
doubleSided: sourceMaterial.doubleSided,
|
|
578
582
|
emissiveFactor: sourceMaterial.emissiveFactor.map(function (c) {
|
|
@@ -580,13 +584,13 @@ function convertMaterial(sourceMaterial) {
|
|
|
580
584
|
}),
|
|
581
585
|
alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),
|
|
582
586
|
pbrMetallicRoughness: {
|
|
583
|
-
roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,
|
|
584
|
-
metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor
|
|
587
|
+
roughnessFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe === void 0 ? void 0 : _sourceMaterial$pbrMe.roughnessFactor) || DEFAULT_ROUGHNESS_FACTOR,
|
|
588
|
+
metallicFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe2 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe2 === void 0 ? void 0 : _sourceMaterial$pbrMe2.metallicFactor) || DEFAULT_METALLIC_FACTOR
|
|
585
589
|
}
|
|
586
590
|
};
|
|
587
591
|
var texture;
|
|
588
592
|
|
|
589
|
-
if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {
|
|
593
|
+
if (sourceMaterial !== null && sourceMaterial !== void 0 && (_sourceMaterial$pbrMe3 = sourceMaterial.pbrMetallicRoughness) !== null && _sourceMaterial$pbrMe3 !== void 0 && _sourceMaterial$pbrMe3.baseColorTexture) {
|
|
590
594
|
texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
|
|
591
595
|
material.pbrMetallicRoughness.baseColorTexture = {
|
|
592
596
|
textureSetDefinitionId: 0
|
|
@@ -599,7 +603,9 @@ function convertMaterial(sourceMaterial) {
|
|
|
599
603
|
}
|
|
600
604
|
|
|
601
605
|
if (!texture) {
|
|
602
|
-
var
|
|
606
|
+
var _sourceMaterial$pbrMe4;
|
|
607
|
+
|
|
608
|
+
var baseColorFactor = sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe4 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe4 === void 0 ? void 0 : _sourceMaterial$pbrMe4.baseColorFactor;
|
|
603
609
|
material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(function (c) {
|
|
604
610
|
return Math.round(c * 255);
|
|
605
611
|
}) || undefined;
|
|
@@ -656,16 +662,19 @@ function getSharedResources(tileContent, nodeId) {
|
|
|
656
662
|
}
|
|
657
663
|
|
|
658
664
|
function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
659
|
-
var
|
|
665
|
+
var _gltfMaterial$pbrMeta;
|
|
666
|
+
|
|
667
|
+
var texture = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : (_gltfMaterial$pbrMeta = gltfMaterial.pbrMetallicRoughness) === null || _gltfMaterial$pbrMeta === void 0 ? void 0 : _gltfMaterial$pbrMeta.baseColorTexture) || gltfMaterial.emissiveTexture;
|
|
660
668
|
var textureDefinitionInfo = null;
|
|
661
669
|
|
|
662
670
|
if (texture) {
|
|
663
671
|
textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
|
|
664
672
|
}
|
|
665
673
|
|
|
666
|
-
var
|
|
667
|
-
baseColorFactor =
|
|
668
|
-
metallicFactor =
|
|
674
|
+
var _ref2 = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : gltfMaterial.pbrMetallicRoughness) || {},
|
|
675
|
+
baseColorFactor = _ref2.baseColorFactor,
|
|
676
|
+
metallicFactor = _ref2.metallicFactor;
|
|
677
|
+
|
|
669
678
|
var colorFactor = baseColorFactor;
|
|
670
679
|
|
|
671
680
|
if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
|
|
@@ -680,7 +689,7 @@ function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
|
680
689
|
}
|
|
681
690
|
|
|
682
691
|
function extractSharedResourcesMaterialInfo(baseColorFactor) {
|
|
683
|
-
var metallicFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
|
692
|
+
var metallicFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
684
693
|
var matDielectricColorComponent = 0.04 / 255;
|
|
685
694
|
var black = new _core.Vector4(0, 0, 0, 1);
|
|
686
695
|
var unitVector = new _core.Vector4(1, 1, 1, 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-converter.js"],"names":["VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","scratchVector","Vector3","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","useCartesianPositions","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","gltf","materials","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","values","attributes","boundingVolumes","positions","cartographicOrigin","obb","center","index","vertex","subarray","Ellipsoid","WGS84","cartesianToCartographic","Array","from","getHeight","subtract","set","vertexCount","triangleCount","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","fileBuffer","Uint8Array","buffer","ArrayBuffer","generateCompressedGeometry","Float32Array","compressedGeometry","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","keys","attrKey","delete","reduce","acc","value","concat","matrix","Matrix4","node","convertNode","getCompositeTransformationMatrix","transformationMatrix","nodeMatrix","rotation","scale","translation","multiplyRight","rotateXYZ","translate","mesh","convertMesh","children","content","primitives","primitive","outputAttributes","transformVertexArray","vertices","POSITION","cartesianModelMatrix","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIdsByAttributeName","args","newVertices","coordIndex","vertexVector","x","y","z","calleeArgs","transform","transformAsVector","newTexCoords","fill","texCoord","colorsAttribute","components","newColors","colorIndex","color","colorUint8","j","batchedIds","newBatchIds","batchIds","possibleBatchIdAttributeName","sourceMaterials","convertMaterial","doubleSided","emissiveFactor","map","c","Math","round","alphaMode","toLowerCase","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfMaterials","i3sResources","materialDefinitionInfos","gltfMaterial","convertGLTFMaterialToI3sSharedResources","materialDefinitionInfo","textureDefinitionInfo","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","Vector4","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","toArray","encoding","mimeType","images","generateImageId","size","image","width","data","height","levelCountOfTexture","indexOfLevel","indexOfTextureInStore","zerosCount","toString","rightHalf","repeat","shiftedLevelCountOfTexture","shiftedIndexOfLevel","shiftedWidth","shiftedHeight","leftHalf","imageId","BigInt","batchTable","replaceMap","getFeaturesReplaceMap","replaceIndicesByUnique","featureMap","oldFeatureId","uniqueFeatureId","getOrCreateUniqueFeatureId","generateStringFromBatchTableByIndex","str","key","batchTableStr","hash","includes","indexOf","indicesArray","attributeBuffers","batchTableWithFeatureIds","OBJECTID","type","getAttributeType","attributeBuffer","generateShortIntegerAttributeBuffer","generateDoubleAttributeBuffer","generateStringAttributeBuffer","attribute","find","attr","name","attributeValues","valueType","count","valuesArray","padding","Float64Array","batchAttributes","stringCountArray","totalNumberOfBytes","stringSizesArray","stringBufferArray","currentString","String","currentStringBuffer","Buffer","currentStringSize","totalBytes","concatenateArrayBuffers","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","DracoWriter","method","orderedFeatureIndices","fillIndex","startIndex","endIndex"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAEA,IAAMA,iBAAiB,GAAG,CAA1B;AACA,IAAMC,oBAAoB,GAAG,CAA7B;AACA,IAAMC,wBAAwB,GAAG,CAAjC;AAEA,IAAMC,WAAW,GAAG,QAApB;AACA,IAAMC,cAAc,GAAG,OAAvB;AACA,IAAMC,WAAW,GAAG,SAApB;AACA,IAAMC,cAAc,GAAG,OAAvB;AAMA,IAAMC,mCAAmC,GAAG,CAAC,oBAAD,EAAuB,UAAvB,EAAmC,SAAnC,CAA5C;AAEA,IAAIC,aAAa,GAAG,IAAIC,aAAJ,EAApB;;SAE8BC,wB;;;;;wFAAf,iBACbC,WADa,EAEbC,MAFa,EAGbC,iBAHa,EAIbC,oBAJa,EAKbC,KALa,EAMbC,uBANa,EAObC,gBAPa;AAAA;;AAAA;AAAA;AAAA;AAAA;AASPC,YAAAA,qBATO,GASiBF,uBATjB;AAUPG,YAAAA,sBAVO,GAUkBC,gBAAgB,CAACT,WAAD,CAVlC;AAWPU,YAAAA,sBAXO,GAWkBC,iBAAiB,CAACX,WAAD,EAAcO,qBAAd,CAXnC;;AAab,gBAAIF,uBAAJ,EAA6B;AAC3BO,cAAAA,oCAAoC,CAACF,sBAAD,EAAyBJ,gBAAzB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B7B;AAAA,2BAgCaa,UAhCb;AAAA;AAAA,mBAiCU,mBAAO;AAACjC,cAAAA,UAAU,EAAEuO,oBAAb;AAAmCtJ,cAAAA,OAAO,EAAPA;AAAnC,aAAP,EAAoDyJ,kBAApD,EAAiE;AACrEpQ,cAAAA,KAAK,EAAE;AACLqQ,gBAAAA,MAAM,EAAE,0BADH;AAELH,gBAAAA,kBAAkB,EAAlBA;AAFK;AAD8D,aAAjE,CAjCV;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAgDA,SAASF,6BAAT,CAAuCD,YAAvC,EAAqDlN,SAArD,EAAgE;AAC9D,MAAMyN,qBAAqB,GAAG,IAAI/M,WAAJ,CAAgBwM,YAAY,CAAC9O,MAA7B,CAA9B;AACA,MAAIsP,SAAS,GAAG,CAAhB;AACA,MAAIC,UAAU,GAAG,CAAjB;;AAEA,OAAK,IAAIxO,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGa,SAAS,CAAC5B,MAAtC,EAA8Ce,KAAK,IAAI,CAAvD,EAA0D;AACxD,QAAMyO,QAAQ,GAAG,CAAC5N,SAAS,CAACb,KAAD,CAAT,GAAmB,CAApB,IAAyB/C,iBAA1C;AAEAqR,IAAAA,qBAAqB,CAACrI,IAAtB,CAA2BsI,SAA3B,EAAsCC,UAAtC,EAAkDC,QAAlD;AAEAF,IAAAA,SAAS;AACTC,IAAAA,UAAU,GAAGC,QAAQ,GAAG,CAAxB;AACD;;AAED,SAAOH,qBAAP;AACD","sourcesContent":["import {Vector3, Matrix4, Vector4} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nimport {DracoWriter} from '@loaders.gl/draco';\nimport {encode, assert} from '@loaders.gl/core';\nimport {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';\nimport md5 from 'md5';\nimport {generateAttributes} from './geometry-attributes';\nimport {createBoundingVolumesFromGeometry} from './coordinate-converter';\n\nconst VALUES_PER_VERTEX = 3;\nconst VALUES_PER_TEX_COORD = 2;\nconst VALUES_PER_COLOR_ELEMENT = 4;\n\nconst STRING_TYPE = 'string';\nconst SHORT_INT_TYPE = 'Int32';\nconst DOUBLE_TYPE = 'Float64';\nconst OBJECT_ID_TYPE = 'Oid32';\n/*\n * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.\n * _BATCHID - Default attribute name which includes batch info.\n * BATCHID - Legacy attribute name which includes batch info.\n */\nconst BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];\n\nlet scratchVector = new Vector3();\n\nexport default async function convertB3dmToI3sGeometry(\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco,\n generateBoundingVolumes,\n geoidHeightModel\n) {\n const useCartesianPositions = generateBoundingVolumes;\n const materialAndTextureList = convertMaterials(tileContent);\n const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);\n\n if (generateBoundingVolumes) {\n _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);\n }\n\n if (convertedAttributesMap.has('default')) {\n materialAndTextureList.push({\n material: getDefaultMaterial()\n });\n }\n\n const result = [];\n let nodesCounter = nodeId;\n let {materials = []} = tileContent.gltf;\n if (!materials?.length) {\n materials.push({id: 'default'});\n }\n for (let i = 0; i < materials.length; i++) {\n const sourceMaterial = materials[i];\n if (!convertedAttributesMap.has(sourceMaterial.id)) {\n continue; // eslint-disable-line no-continue\n }\n const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);\n const {material, texture} = materialAndTextureList[i];\n result.push(\n await _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId: nodesCounter,\n featuresHashArray,\n attributeStorageInfo,\n draco\n })\n );\n nodesCounter++;\n }\n\n if (!result.length) {\n return null;\n }\n return result;\n}\n\n/**\n * Create bounding volumes based on positions\n * @param convertedAttributesMap\n * @param geoidHeightModel\n */\nfunction _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {\n for (const attributes of convertedAttributesMap.values()) {\n const boundingVolumes = createBoundingVolumesFromGeometry(\n attributes.positions,\n geoidHeightModel\n );\n\n attributes.boundingVolumes = boundingVolumes;\n const cartographicOrigin = boundingVolumes.obb.center;\n\n for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {\n const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);\n Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);\n scratchVector[2] =\n scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);\n scratchVector = scratchVector.subtract(cartographicOrigin);\n attributes.positions.set(scratchVector, index);\n }\n }\n}\n\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n}) {\n const boundingVolumes = convertedAttributes.boundingVolumes;\n const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;\n const triangleCount = vertexCount / 3;\n const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =\n generateAttributes({triangleCount, ...convertedAttributes});\n\n if (tileContent.batchTableJson) {\n makeFeatureIdsUnique(\n featureIds,\n convertedAttributes.featureIndices,\n featuresHashArray,\n tileContent.batchTableJson\n );\n }\n\n const header = new Uint32Array(2);\n const typedFeatureIds = generateBigUint64Array(featureIds);\n\n header.set([vertexCount, featureCount], 0);\n const fileBuffer = new Uint8Array(\n concatenateArrayBuffers(\n header.buffer,\n positions.buffer,\n normals.buffer,\n texture ? texCoords.buffer : new ArrayBuffer(0),\n colors.buffer,\n typedFeatureIds.buffer,\n faceRange.buffer\n )\n );\n const compressedGeometry = draco\n ? await generateCompressedGeometry(vertexCount, convertedAttributes, {\n positions,\n normals,\n texCoords: texture ? texCoords : new Float32Array(0),\n colors,\n featureIds,\n faceRange\n })\n : null;\n\n const attributes = convertBatchTableToAttributeBuffers(\n tileContent.batchTableJson,\n featureIds,\n attributeStorageInfo\n );\n\n return {\n geometry: fileBuffer,\n compressedGeometry,\n texture,\n sharedResources: getSharedResources(tileContent, nodeId),\n meshMaterial: material,\n vertexCount,\n attributes,\n featureCount,\n boundingVolumes\n };\n}\n\n/**\n * Convert attributes from the gltf nodes tree to i3s plain geometry\n * @param {Object} tileContent - 3d tile content\n * @returns {Map}\n * Map<{\n * positions: Float32Array,\n * normals: Float32Array,\n * colors: Uint8Array,\n * texCoords: Float32Array\n * }>\n * @todo implement colors support (if applicable for gltf format)\n */\nfunction convertAttributes(tileContent, useCartesianPositions) {\n const attributesMap = new Map();\n\n for (const material of tileContent.gltf.materials || [{id: 'default'}]) {\n attributesMap.set(material.id, {\n positions: new Float32Array(0),\n normals: new Float32Array(0),\n texCoords: new Float32Array(0),\n colors: new Uint8Array(0),\n featureIndices: [],\n boundingVolumes: null\n });\n }\n\n const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;\n convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);\n\n for (const attrKey of attributesMap.keys()) {\n const attributes = attributesMap.get(attrKey);\n if (attributes.positions.length === 0) {\n attributesMap.delete(attrKey);\n continue; // eslint-disable-line no-continue\n }\n attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));\n }\n\n return attributesMap;\n}\n\n/**\n * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.\n * The goal is applying tranformation matrix for all children. Functions \"convertNodes\" and \"convertNode\" work together recursively.\n * @param {Object[]} nodes - gltf nodes array\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: UInt8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns {void}\n */\nfunction convertNodes(\n nodes,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n if (nodes) {\n for (const node of nodes) {\n convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);\n }\n }\n}\n\n/**\n * Generate transformation matrix for node\n * Aapply all gltf transformations to initial transformation matrix.\n * @param node\n * @param matrix\n */\nfunction getCompositeTransformationMatrix(node, matrix) {\n let transformationMatrix = matrix;\n\n const {matrix: nodeMatrix, rotation, scale, translation} = node;\n\n if (nodeMatrix) {\n transformationMatrix = matrix.multiplyRight(nodeMatrix);\n }\n\n if (rotation) {\n transformationMatrix = transformationMatrix.rotateXYZ(rotation);\n }\n\n if (scale) {\n transformationMatrix = transformationMatrix.scale(scale);\n }\n\n if (translation) {\n transformationMatrix = transformationMatrix.translate(translation);\n }\n\n return transformationMatrix;\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} node - gltf node\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertNode(\n node,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n const transformationMatrix = getCompositeTransformationMatrix(node, matrix);\n\n const mesh = node.mesh;\n if (mesh) {\n convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);\n }\n\n convertNodes(\n node.children,\n tileContent,\n attributesMap,\n useCartesianPositions,\n transformationMatrix\n );\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} mesh - gltf node\n * @param {Object} content - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertMesh(\n mesh,\n content,\n attributesMap,\n useCartesianPositions = false,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n for (const primitive of mesh.primitives) {\n let outputAttributes = null;\n if (primitive.material) {\n outputAttributes = attributesMap.get(primitive.material.id);\n } else if (attributesMap.has('default')) {\n outputAttributes = attributesMap.get('default');\n }\n assert(outputAttributes !== null, 'Primitive - material mapping failed');\n const attributes = primitive.attributes;\n\n outputAttributes.positions = concatenateTypedArrays(\n outputAttributes.positions,\n transformVertexArray({\n vertices: attributes.POSITION.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexPositions,\n useCartesianPositions\n })\n );\n outputAttributes.normals = concatenateTypedArrays(\n outputAttributes.normals,\n transformVertexArray({\n vertices: attributes.NORMAL && attributes.NORMAL.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexNormals,\n useCartesianPositions: false\n })\n );\n outputAttributes.texCoords = concatenateTypedArrays(\n outputAttributes.texCoords,\n flattenTexCoords(\n attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value,\n primitive.indices.value\n )\n );\n\n outputAttributes.colors = concatenateTypedArrays(\n outputAttributes.colors,\n flattenColors(attributes.COLOR_0, primitive.indices.value)\n );\n\n outputAttributes.featureIndices.push(\n flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value)\n );\n }\n}\n\n/**\n * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format\n * @param {object} args - source tile (3DTile)\n * @param {Float32Array} args.vertices - gltf primitive POSITION or NORMAL attribute\n * @param {Object} args.cartographicOrigin - cartographic origin coordinates\n * @param {Object} args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param {Matrix4} args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param {Uint8Array} args.indices - gltf primitive indices\n * @param {Function} args.attributeSpecificTransformation - function to do attribute - specific transformations\n * @param {Boolean} args.useCartesianPositions - use coordinates as it is.\n * @returns {Float32Array}\n */\nfunction transformVertexArray(args) {\n const {vertices, indices, attributeSpecificTransformation} = args;\n const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);\n if (!vertices) {\n return newVertices;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_VERTEX;\n const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);\n let vertexVector = new Vector3(Array.from(vertex));\n\n vertexVector = attributeSpecificTransformation(vertexVector, args);\n\n newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;\n newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;\n newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;\n }\n return newVertices;\n}\n\nfunction transformVertexPositions(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, cartographicOrigin, nodeMatrix, useCartesianPositions} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transform(nodeMatrix);\n }\n\n vertexVector = vertexVector.transform(cartesianModelMatrix);\n\n if (useCartesianPositions) {\n return vertexVector;\n }\n\n Ellipsoid.WGS84.cartesianToCartographic(\n [vertexVector[0], vertexVector[1], vertexVector[2]],\n vertexVector\n );\n vertexVector = vertexVector.subtract(cartographicOrigin);\n return vertexVector;\n}\n\nfunction transformVertexNormals(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, nodeMatrix} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transformAsVector(nodeMatrix);\n }\n\n vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);\n return vertexVector;\n}\n\n/**\n * Convert uv0 (texture coordinates) from coords based on indices to plain arrays, compatible with i3s\n * @param {Float32Array} texCoords - gltf primitive TEXCOORD_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Float32Array}\n */\nfunction flattenTexCoords(texCoords, indices) {\n const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);\n if (!texCoords) {\n // We need dummy UV0s because it is required in 1.6\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.6/vertexAttribute.cmn.md\n newTexCoords.fill(1);\n return newTexCoords;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_TEX_COORD;\n const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);\n newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];\n newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];\n }\n return newTexCoords;\n}\n\n/**\n * Convert color from COLOR_0 based on indices to plain arrays, compatible with i3s\n * @param {object} colorsAttribute - gltf primitive COLOR_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Uint8Array}\n */\nfunction flattenColors(colorsAttribute, indices) {\n const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;\n const newColors = new Uint8Array(indices.length * components);\n if (!colorsAttribute) {\n // Vertex color multiplies by material color so it must be normalized 1 by default\n newColors.fill(255);\n return newColors;\n }\n const colors = colorsAttribute.value;\n for (let i = 0; i < indices.length; i++) {\n const colorIndex = indices[i] * components;\n const color = colors.subarray(colorIndex, colorIndex + components);\n const colorUint8 = new Uint8Array(components);\n for (let j = 0; j < color.length; j++) {\n colorUint8[j] = color[j] * 255;\n }\n newColors.set(colorUint8, i * components);\n }\n return newColors;\n}\n\n/**\n * Flatten batchedIds list based on indices to right ordered array, compatible with i3s\n * @param {Array} batchedIds - gltf primitive\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Array}\n */\nfunction flattenBatchIds(batchedIds, indices) {\n if (!batchedIds.length || !indices.length) {\n return [];\n }\n const newBatchIds = [];\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i];\n newBatchIds.push(batchedIds[coordIndex]);\n }\n return newBatchIds;\n}\n/**\n * Return batchIds based on possible attribute names for different kind of maps.\n * @param {Object} attributes {attributeName: Float32Array}\n * @returns {Array}\n */\nfunction getBatchIdsByAttributeName(attributes) {\n let batchIds = [];\n\n for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {\n const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];\n if (\n attributes[possibleBatchIdAttributeName] &&\n attributes[possibleBatchIdAttributeName].value\n ) {\n batchIds = attributes[possibleBatchIdAttributeName].value;\n break;\n }\n }\n\n return batchIds;\n}\n\nfunction convertMaterials(tileContent) {\n const result = [];\n const sourceMaterials = tileContent.gltf.materials || [];\n for (const sourceMaterial of sourceMaterials) {\n result.push(convertMaterial(sourceMaterial));\n }\n return result;\n}\n\n/**\n * Convert texture and material from gltf 2.0 material object\n * @param {Object} sourceMaterial - material object\n * @returns {Object}\n */\nfunction convertMaterial(sourceMaterial) {\n const material = {\n doubleSided: sourceMaterial.doubleSided,\n emissiveFactor: sourceMaterial.emissiveFactor.map((c) => Math.round(c * 255)),\n // It is in upper case in GLTF: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#alpha-coverage\n // But it is in lower case in I3S: https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md\n alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),\n pbrMetallicRoughness: {\n roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,\n metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor\n }\n };\n\n let texture;\n if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {\n texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n } else if (sourceMaterial.emissiveTexture) {\n texture = sourceMaterial.emissiveTexture.texture.source;\n // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n }\n\n if (!texture) {\n // Should use default baseColorFactor if it is not present in source material\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness\n const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;\n material.pbrMetallicRoughness.baseColorFactor =\n (baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) || undefined;\n }\n\n return {material, texture};\n}\n\nfunction getDefaultMaterial() {\n return {\n alphaMode: 'opaque',\n pbrMetallicRoughness: {}\n };\n}\n\n/**\n * Form \"sharedResources\" from gltf materials array\n * @param {Object} tileContent - 3d tile content\n * @returns {Object} {materialDefinitionInfos: Object[], textureDefinitionInfos: Object[]} -\n * 2 arrays in format of i3s sharedResources data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/sharedResource.cmn.md\n */\nfunction getSharedResources(tileContent, nodeId) {\n const gltfMaterials = tileContent.gltf.materials;\n const i3sResources = {};\n\n if (!gltfMaterials || !gltfMaterials.length) {\n return i3sResources;\n }\n\n i3sResources.materialDefinitionInfos = [];\n for (const gltfMaterial of gltfMaterials) {\n const {materialDefinitionInfo, textureDefinitionInfo} = convertGLTFMaterialToI3sSharedResources(\n gltfMaterial,\n nodeId\n );\n i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);\n if (textureDefinitionInfo) {\n i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];\n i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);\n }\n }\n return i3sResources;\n}\n\n/**\n * Convert gltf material into I3S sharedResources data\n * @param {Object} gltfMaterial - gltf material data\n * @returns {Object} - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data\n */\nfunction convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {\n const texture =\n gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;\n let textureDefinitionInfo = null;\n if (texture) {\n textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);\n }\n const {baseColorFactor, metallicFactor} = gltfMaterial.pbrMetallicRoughness;\n let colorFactor = baseColorFactor;\n // If alpha channel is 0 try to get emissive factor from gltf material.\n if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {\n colorFactor = gltfMaterial.emissiveFactor;\n colorFactor[3] = colorFactor[3] || 1;\n }\n\n return {\n materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),\n textureDefinitionInfo\n };\n}\n\n/**\n * Form \"materialDefinition\" which is part of \"sharedResouces\"\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materials\n * See formulas in appendix \"Appendix B: BRDF Implementation\":\n * const dielectricSpecular = rgb(0.04, 0.04, 0.04)\n * const black = rgb(0, 0, 0)\n * cdiff = lerp(baseColor.rgb * (1 - dielectricSpecular.r), black, metallic)\n * F0 = lerp(dieletricSpecular, baseColor.rgb, metallic)\n *\n * Assumption: F0 - specular in i3s (\"specular reflection\" <-> \"reflectance value at normal incidence\")\n * cdiff - diffuse in i3s (\"Diffuse color\" <-> \"'c' diffuse\" (c means color?))\n * @param {number[]} baseColorFactor - RGBA color in 0..1 format\n * @param {number} metallicFactor - \"metallicFactor\" attribute of gltf material object\n * @returns {Object}\n */\nfunction extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {\n const matDielectricColorComponent = 0.04 / 255; // Color from rgb (255) to 0..1 resolution\n // All color resolutions are 0..1\n const black = new Vector4(0, 0, 0, 1);\n const unitVector = new Vector4(1, 1, 1, 1);\n const dielectricSpecular = new Vector4(\n matDielectricColorComponent,\n matDielectricColorComponent,\n matDielectricColorComponent,\n 0\n );\n const baseColorVector = new Vector4(baseColorFactor);\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material\n // Formulas for Cdiff & F0\n const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);\n const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);\n dielectricSpecular[3] = 1;\n const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);\n return {\n diffuse: diffuse.toArray(),\n specular: specular.toArray()\n };\n}\n\n/**\n * Form \"textureDefinition\" which is part of \"sharedResouces\"\n * @param {Object} texture - texture image info\n * @returns {Object}\n */\nfunction extractSharedResourcesTextureInfo(texture, nodeId) {\n return {\n encoding: [texture.source.mimeType],\n images: [\n {\n // 'i3s' has just size which is width of the image. Images are supposed to be square.\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md\n id: generateImageId(texture, nodeId),\n size: texture.source.image.width,\n length: [texture.source.image.data.length]\n }\n ]\n };\n}\n/*\n * Formula for counting imageId:\n * https://github.com/Esri/i3s-spec/blob/0a6366a9249b831db8436c322f8d27521e86cf07/format/Indexed%203d%20Scene%20Layer%20Format%20Specification.md#generating-image-ids\n * @param {Object} texture - texture image info\n * @returns {string}\n */\nfunction generateImageId(texture, nodeId) {\n const {width, height} = texture.source.image;\n const levelCountOfTexture = 1;\n const indexOfLevel = 0;\n const indexOfTextureInStore = nodeId + 1;\n\n const zerosCount = 32 - indexOfTextureInStore.toString(2).length;\n const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));\n\n const shiftedLevelCountOfTexture = levelCountOfTexture << 28;\n const shiftedIndexOfLevel = indexOfLevel << 24;\n const shiftedWidth = (width - 1) << 12;\n const shiftedHeight = (height - 1) << 0;\n\n const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;\n const imageId = BigInt(`0b${leftHalf.toString(2)}${rightHalf}`);\n return imageId.toString();\n}\n\n/**\n * Make all feature ids unique through all nodes in layout.\n * @param {Array} featureIds\n * @param {Array} featureIndices\n * @param {Array} featuresHashArray\n * @param {Object} batchTable\n * @returns {void}\n */\nfunction makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {\n const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);\n replaceIndicesByUnique(featureIndices, replaceMap);\n replaceIndicesByUnique(featureIds, replaceMap);\n}\n\n/**\n * Generate replace map to make featureIds unique.\n * @param {Array} featureIds\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Object}\n */\nfunction getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {\n const featureMap = {};\n\n for (let index = 0; index < featureIds.length; index++) {\n const oldFeatureId = featureIds[index];\n const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);\n featureMap[oldFeatureId.toString()] = uniqueFeatureId;\n }\n\n return featureMap;\n}\n\n/**\n * Generates string for unique batch id creation.\n * @param {Object} batchTable\n * @param {Number} index\n * @returns {String}\n */\nfunction generateStringFromBatchTableByIndex(batchTable, index) {\n let str = '';\n for (const key in batchTable) {\n str += batchTable[key][index];\n }\n return str;\n}\n\n/**\n * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.\n * @param {Number} index\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Number}\n */\nfunction getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {\n const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);\n const hash = md5(batchTableStr);\n\n if (featuresHashArray.includes(hash)) {\n return featuresHashArray.indexOf(hash);\n }\n return featuresHashArray.push(hash) - 1;\n}\n\n/**\n * Do replacement of indices for making them unique through all nodes.\n * @param {Array} indicesArray\n * @param {Object} featureMap\n * @returns {void}\n */\nfunction replaceIndicesByUnique(indicesArray, featureMap) {\n for (let index = 0; index < indicesArray.length; index++) {\n indicesArray[index] = featureMap[indicesArray[index]];\n }\n}\n\n/**\n * Convert batch table data to attribute buffers.\n * @param {Object} batchTable - table with metadata for particular feature.\n * @param {Array} featureIds\n * @param {Array} attributeStorageInfo\n * @returns {Array} - Array of file buffers.\n */\nfunction convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {\n const attributeBuffers = [];\n\n if (batchTable) {\n const batchTableWithFeatureIds = {\n OBJECTID: featureIds,\n ...batchTable\n };\n\n for (const key in batchTableWithFeatureIds) {\n const type = getAttributeType(key, attributeStorageInfo);\n\n let attributeBuffer = null;\n\n switch (type) {\n case OBJECT_ID_TYPE:\n case SHORT_INT_TYPE:\n attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case DOUBLE_TYPE:\n attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case STRING_TYPE:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n default:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n }\n\n attributeBuffers.push(attributeBuffer);\n }\n }\n\n return attributeBuffers;\n}\n/**\n * Return attribute type.\n * @param {String} key\n * @param {Array} attributeStorageInfo\n * @returns {String} attribute type.\n */\nfunction getAttributeType(key, attributeStorageInfo) {\n const attribute = attributeStorageInfo.find((attr) => attr.name === key);\n return attribute.attributeValues.valueType;\n}\n\n/**\n * Convert short integer to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateShortIntegerAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const valuesArray = new Uint32Array(featureIds);\n return concatenateArrayBuffers(count.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert double to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateDoubleAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const padding = new Uint8Array(4);\n const valuesArray = new Float64Array(featureIds);\n\n return concatenateArrayBuffers(count.buffer, padding.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert batch table attributes to array buffer with batch table data.\n * @param {Array} batchAttributes\n * @returns {ArrayBuffer} - Buffer with batch table data.\n */\nfunction generateStringAttributeBuffer(batchAttributes) {\n const stringCountArray = new Uint32Array([batchAttributes.length]);\n let totalNumberOfBytes = 0;\n const stringSizesArray = new Uint32Array(batchAttributes.length);\n const stringBufferArray = [];\n\n for (let index = 0; index < batchAttributes.length; index++) {\n const currentString = `${String(batchAttributes[index])}\\0`;\n const currentStringBuffer = Buffer.from(currentString);\n const currentStringSize = currentStringBuffer.length;\n totalNumberOfBytes += currentStringSize;\n stringSizesArray[index] = currentStringSize;\n stringBufferArray.push(currentStringBuffer);\n }\n\n const totalBytes = new Uint32Array([totalNumberOfBytes]);\n\n return concatenateArrayBuffers(\n stringCountArray.buffer,\n totalBytes.buffer,\n stringSizesArray.buffer,\n ...stringBufferArray\n );\n}\n\n/**\n * Convert featureIds to BigUint64Array.\n * @param {Array} featureIds\n * @returns {BigUint64Array} - Array of feature ids in BigUint64 format.\n */\nfunction generateBigUint64Array(featureIds) {\n const typedFeatureIds = new BigUint64Array(featureIds.length);\n for (let index = 0; index < featureIds.length; index++) {\n typedFeatureIds[index] = BigInt(featureIds[index]);\n }\n return typedFeatureIds;\n}\n\n/**\n * Generates draco compressed geometry\n * @param {Number} vertexCount\n * @param {Object} convertedAttributes\n * @returns {Promise<object>} - COmpressed geometry.\n */\nasync function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {\n const {positions, normals, texCoords, colors, featureIds, faceRange} = attributes;\n const indices = new Uint32Array(vertexCount);\n\n for (let index = 0; index < indices.length; index++) {\n indices.set([index], index);\n }\n\n const featureIndices = new Uint32Array(\n convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount\n );\n\n const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);\n\n const compressedAttributes = {\n positions,\n normals,\n colors,\n 'feature-index': featureIndex\n };\n\n if (texCoords.length) {\n compressedAttributes.texCoords = texCoords;\n }\n\n const attributesMetadata = {\n 'feature-index': {\n 'i3s-attribute-type': 'feature-index',\n 'i3s-feature-ids': new Int32Array(featureIds)\n }\n };\n\n return new Uint8Array(\n await encode({attributes: compressedAttributes, indices}, DracoWriter, {\n draco: {\n method: 'MESH_SEQUENTIAL_ENCODING',\n attributesMetadata\n }\n })\n );\n}\n\n/**\n * Generates ordered feature indices based on face range\n * @param {Uint32Array} featureIndex\n * @param {Uint32Array} faceRange\n * @returns {Uint32Array}\n */\nfunction generateFeatureIndexAttribute(featureIndex, faceRange) {\n const orderedFeatureIndices = new Uint32Array(featureIndex.length);\n let fillIndex = 0;\n let startIndex = 0;\n\n for (let index = 1; index < faceRange.length; index += 2) {\n const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;\n\n orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);\n\n fillIndex++;\n startIndex = endIndex + 1;\n }\n\n return orderedFeatureIndices;\n}\n"],"file":"geometry-converter.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-converter.js"],"names":["DEFAULT_ROUGHNESS_FACTOR","DEFAULT_METALLIC_FACTOR","VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","scratchVector","Vector3","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","useCartesianPositions","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","gltf","materials","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","values","attributes","boundingVolumes","positions","cartographicOrigin","obb","center","index","vertex","subarray","Ellipsoid","WGS84","cartesianToCartographic","Array","from","getHeight","subtract","set","vertexCount","triangleCount","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","fileBuffer","Uint8Array","buffer","ArrayBuffer","generateCompressedGeometry","Float32Array","compressedGeometry","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","keys","attrKey","delete","reduce","acc","value","concat","matrix","Matrix4","node","convertNode","getCompositeTransformationMatrix","transformationMatrix","nodeMatrix","rotation","scale","translation","multiplyRight","rotateXYZ","translate","mesh","convertMesh","children","content","primitives","primitive","outputAttributes","transformVertexArray","vertices","POSITION","cartesianModelMatrix","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIdsByAttributeName","args","newVertices","coordIndex","vertexVector","x","y","z","calleeArgs","transform","transformAsVector","newTexCoords","fill","texCoord","colorsAttribute","components","newColors","colorIndex","color","colorUint8","j","batchedIds","newBatchIds","batchIds","possibleBatchIdAttributeName","sourceMaterials","convertMaterial","doubleSided","emissiveFactor","map","c","Math","round","alphaMode","toLowerCase","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfMaterials","i3sResources","materialDefinitionInfos","gltfMaterial","convertGLTFMaterialToI3sSharedResources","materialDefinitionInfo","textureDefinitionInfo","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","Vector4","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","toArray","encoding","mimeType","images","generateImageId","size","image","width","data","height","levelCountOfTexture","indexOfLevel","indexOfTextureInStore","zerosCount","toString","rightHalf","repeat","shiftedLevelCountOfTexture","shiftedIndexOfLevel","shiftedWidth","shiftedHeight","leftHalf","imageId","BigInt","batchTable","replaceMap","getFeaturesReplaceMap","replaceIndicesByUnique","featureMap","oldFeatureId","uniqueFeatureId","getOrCreateUniqueFeatureId","generateStringFromBatchTableByIndex","str","key","batchTableStr","hash","includes","indexOf","indicesArray","attributeBuffers","batchTableWithFeatureIds","OBJECTID","type","getAttributeType","attributeBuffer","generateShortIntegerAttributeBuffer","generateDoubleAttributeBuffer","generateStringAttributeBuffer","attribute","find","attr","name","attributeValues","valueType","count","valuesArray","padding","Float64Array","batchAttributes","stringCountArray","totalNumberOfBytes","stringSizesArray","stringBufferArray","currentString","String","currentStringBuffer","Buffer","currentStringSize","totalBytes","concatenateArrayBuffers","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","DracoWriter","method","orderedFeatureIndices","fillIndex","startIndex","endIndex"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAGA,IAAMA,wBAAwB,GAAG,CAAjC;AACA,IAAMC,uBAAuB,GAAG,CAAhC;AAEA,IAAMC,iBAAiB,GAAG,CAA1B;AACA,IAAMC,oBAAoB,GAAG,CAA7B;AACA,IAAMC,wBAAwB,GAAG,CAAjC;AAEA,IAAMC,WAAW,GAAG,QAApB;AACA,IAAMC,cAAc,GAAG,OAAvB;AACA,IAAMC,WAAW,GAAG,SAApB;AACA,IAAMC,cAAc,GAAG,OAAvB;AAMA,IAAMC,mCAAmC,GAAG,CAAC,oBAAD,EAAuB,UAAvB,EAAmC,SAAnC,CAA5C;AAEA,IAAIC,aAAa,GAAG,IAAIC,aAAJ,EAApB;;SAE8BC,wB;;;;;wFAAf,iBACbC,WADa,EAEbC,MAFa,EAGbC,iBAHa,EAIbC,oBAJa,EAKbC,KALa,EAMbC,uBANa,EAObC,gBAPa;AAAA;;AAAA;AAAA;AAAA;AAAA;AASPC,YAAAA,qBATO,GASiBF,uBATjB;AAUPG,YAAAA,sBAVO,GAUkBC,gBAAgB,CAACT,WAAD,CAVlC;AAWPU,YAAAA,s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,CAApB,IAAyB/C,iBAA1C;AAEAqR,IAAAA,qBAAqB,CAACrI,IAAtB,CAA2BsI,SAA3B,EAAsCC,UAAtC,EAAkDC,QAAlD;AAEAF,IAAAA,SAAS;AACTC,IAAAA,UAAU,GAAGC,QAAQ,GAAG,CAAxB;AACD;;AAED,SAAOH,qBAAP;AACD","sourcesContent":["import {Vector3, Matrix4, Vector4} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nimport {DracoWriter} from '@loaders.gl/draco';\nimport {encode, assert} from '@loaders.gl/core';\nimport {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';\nimport md5 from 'md5';\nimport {generateAttributes} from './geometry-attributes';\nimport {createBoundingVolumesFromGeometry} from './coordinate-converter';\n\n// Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md\nconst DEFAULT_ROUGHNESS_FACTOR = 1;\nconst DEFAULT_METALLIC_FACTOR = 1;\n\nconst VALUES_PER_VERTEX = 3;\nconst VALUES_PER_TEX_COORD = 2;\nconst VALUES_PER_COLOR_ELEMENT = 4;\n\nconst STRING_TYPE = 'string';\nconst SHORT_INT_TYPE = 'Int32';\nconst DOUBLE_TYPE = 'Float64';\nconst OBJECT_ID_TYPE = 'Oid32';\n/*\n * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.\n * _BATCHID - Default attribute name which includes batch info.\n * BATCHID - Legacy attribute name which includes batch info.\n */\nconst BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];\n\nlet scratchVector = new Vector3();\n\nexport default async function convertB3dmToI3sGeometry(\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco,\n generateBoundingVolumes,\n geoidHeightModel\n) {\n const useCartesianPositions = generateBoundingVolumes;\n const materialAndTextureList = convertMaterials(tileContent);\n const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);\n\n if (generateBoundingVolumes) {\n _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);\n }\n\n if (convertedAttributesMap.has('default')) {\n materialAndTextureList.push({\n material: getDefaultMaterial()\n });\n }\n\n const result = [];\n let nodesCounter = nodeId;\n let {materials = []} = tileContent.gltf;\n if (!materials?.length) {\n materials.push({id: 'default'});\n }\n for (let i = 0; i < materials.length; i++) {\n const sourceMaterial = materials[i];\n if (!convertedAttributesMap.has(sourceMaterial.id)) {\n continue; // eslint-disable-line no-continue\n }\n const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);\n const {material, texture} = materialAndTextureList[i];\n result.push(\n await _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId: nodesCounter,\n featuresHashArray,\n attributeStorageInfo,\n draco\n })\n );\n nodesCounter++;\n }\n\n if (!result.length) {\n return null;\n }\n return result;\n}\n\n/**\n * Create bounding volumes based on positions\n * @param convertedAttributesMap\n * @param geoidHeightModel\n */\nfunction _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {\n for (const attributes of convertedAttributesMap.values()) {\n const boundingVolumes = createBoundingVolumesFromGeometry(\n attributes.positions,\n geoidHeightModel\n );\n\n attributes.boundingVolumes = boundingVolumes;\n const cartographicOrigin = boundingVolumes.obb.center;\n\n for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {\n const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);\n Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);\n scratchVector[2] =\n scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);\n scratchVector = scratchVector.subtract(cartographicOrigin);\n attributes.positions.set(scratchVector, index);\n }\n }\n}\n\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n}) {\n const boundingVolumes = convertedAttributes.boundingVolumes;\n const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;\n const triangleCount = vertexCount / 3;\n const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =\n generateAttributes({triangleCount, ...convertedAttributes});\n\n if (tileContent.batchTableJson) {\n makeFeatureIdsUnique(\n featureIds,\n convertedAttributes.featureIndices,\n featuresHashArray,\n tileContent.batchTableJson\n );\n }\n\n const header = new Uint32Array(2);\n const typedFeatureIds = generateBigUint64Array(featureIds);\n\n header.set([vertexCount, featureCount], 0);\n const fileBuffer = new Uint8Array(\n concatenateArrayBuffers(\n header.buffer,\n positions.buffer,\n normals.buffer,\n texture ? texCoords.buffer : new ArrayBuffer(0),\n colors.buffer,\n typedFeatureIds.buffer,\n faceRange.buffer\n )\n );\n const compressedGeometry = draco\n ? await generateCompressedGeometry(vertexCount, convertedAttributes, {\n positions,\n normals,\n texCoords: texture ? texCoords : new Float32Array(0),\n colors,\n featureIds,\n faceRange\n })\n : null;\n\n const attributes = convertBatchTableToAttributeBuffers(\n tileContent.batchTableJson,\n featureIds,\n attributeStorageInfo\n );\n\n return {\n geometry: fileBuffer,\n compressedGeometry,\n texture,\n sharedResources: getSharedResources(tileContent, nodeId),\n meshMaterial: material,\n vertexCount,\n attributes,\n featureCount,\n boundingVolumes\n };\n}\n\n/**\n * Convert attributes from the gltf nodes tree to i3s plain geometry\n * @param {Object} tileContent - 3d tile content\n * @returns {Map}\n * Map<{\n * positions: Float32Array,\n * normals: Float32Array,\n * colors: Uint8Array,\n * texCoords: Float32Array\n * }>\n * @todo implement colors support (if applicable for gltf format)\n */\nfunction convertAttributes(tileContent, useCartesianPositions) {\n const attributesMap = new Map();\n\n for (const material of tileContent.gltf.materials || [{id: 'default'}]) {\n attributesMap.set(material.id, {\n positions: new Float32Array(0),\n normals: new Float32Array(0),\n texCoords: new Float32Array(0),\n colors: new Uint8Array(0),\n featureIndices: [],\n boundingVolumes: null\n });\n }\n\n const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;\n convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);\n\n for (const attrKey of attributesMap.keys()) {\n const attributes = attributesMap.get(attrKey);\n if (attributes.positions.length === 0) {\n attributesMap.delete(attrKey);\n continue; // eslint-disable-line no-continue\n }\n attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));\n }\n\n return attributesMap;\n}\n\n/**\n * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.\n * The goal is applying tranformation matrix for all children. Functions \"convertNodes\" and \"convertNode\" work together recursively.\n * @param {Object[]} nodes - gltf nodes array\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: UInt8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns {void}\n */\nfunction convertNodes(\n nodes,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n if (nodes) {\n for (const node of nodes) {\n convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);\n }\n }\n}\n\n/**\n * Generate transformation matrix for node\n * Aapply all gltf transformations to initial transformation matrix.\n * @param node\n * @param matrix\n */\nfunction getCompositeTransformationMatrix(node, matrix) {\n let transformationMatrix = matrix;\n\n const {matrix: nodeMatrix, rotation, scale, translation} = node;\n\n if (nodeMatrix) {\n transformationMatrix = matrix.multiplyRight(nodeMatrix);\n }\n\n if (rotation) {\n transformationMatrix = transformationMatrix.rotateXYZ(rotation);\n }\n\n if (scale) {\n transformationMatrix = transformationMatrix.scale(scale);\n }\n\n if (translation) {\n transformationMatrix = transformationMatrix.translate(translation);\n }\n\n return transformationMatrix;\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} node - gltf node\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertNode(\n node,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n const transformationMatrix = getCompositeTransformationMatrix(node, matrix);\n\n const mesh = node.mesh;\n if (mesh) {\n convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);\n }\n\n convertNodes(\n node.children,\n tileContent,\n attributesMap,\n useCartesianPositions,\n transformationMatrix\n );\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} mesh - gltf node\n * @param {Object} content - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertMesh(\n mesh,\n content,\n attributesMap,\n useCartesianPositions = false,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n for (const primitive of mesh.primitives) {\n let outputAttributes = null;\n if (primitive.material) {\n outputAttributes = attributesMap.get(primitive.material.id);\n } else if (attributesMap.has('default')) {\n outputAttributes = attributesMap.get('default');\n }\n assert(outputAttributes !== null, 'Primitive - material mapping failed');\n const attributes = primitive.attributes;\n\n outputAttributes.positions = concatenateTypedArrays(\n outputAttributes.positions,\n transformVertexArray({\n vertices: attributes.POSITION.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexPositions,\n useCartesianPositions\n })\n );\n outputAttributes.normals = concatenateTypedArrays(\n outputAttributes.normals,\n transformVertexArray({\n vertices: attributes.NORMAL && attributes.NORMAL.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexNormals,\n useCartesianPositions: false\n })\n );\n outputAttributes.texCoords = concatenateTypedArrays(\n outputAttributes.texCoords,\n flattenTexCoords(\n attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value,\n primitive.indices.value\n )\n );\n\n outputAttributes.colors = concatenateTypedArrays(\n outputAttributes.colors,\n flattenColors(attributes.COLOR_0, primitive.indices.value)\n );\n\n outputAttributes.featureIndices.push(\n flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value)\n );\n }\n}\n\n/**\n * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format\n * @param {object} args - source tile (3DTile)\n * @param {Float32Array} args.vertices - gltf primitive POSITION or NORMAL attribute\n * @param {Object} args.cartographicOrigin - cartographic origin coordinates\n * @param {Object} args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param {Matrix4} args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param {Uint8Array} args.indices - gltf primitive indices\n * @param {Function} args.attributeSpecificTransformation - function to do attribute - specific transformations\n * @param {Boolean} args.useCartesianPositions - use coordinates as it is.\n * @returns {Float32Array}\n */\nfunction transformVertexArray(args) {\n const {vertices, indices, attributeSpecificTransformation} = args;\n const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);\n if (!vertices) {\n return newVertices;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_VERTEX;\n const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);\n let vertexVector = new Vector3(Array.from(vertex));\n\n vertexVector = attributeSpecificTransformation(vertexVector, args);\n\n newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;\n newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;\n newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;\n }\n return newVertices;\n}\n\nfunction transformVertexPositions(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, cartographicOrigin, nodeMatrix, useCartesianPositions} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transform(nodeMatrix);\n }\n\n vertexVector = vertexVector.transform(cartesianModelMatrix);\n\n if (useCartesianPositions) {\n return vertexVector;\n }\n\n Ellipsoid.WGS84.cartesianToCartographic(\n [vertexVector[0], vertexVector[1], vertexVector[2]],\n vertexVector\n );\n vertexVector = vertexVector.subtract(cartographicOrigin);\n return vertexVector;\n}\n\nfunction transformVertexNormals(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, nodeMatrix} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transformAsVector(nodeMatrix);\n }\n\n vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);\n return vertexVector;\n}\n\n/**\n * Convert uv0 (texture coordinates) from coords based on indices to plain arrays, compatible with i3s\n * @param {Float32Array} texCoords - gltf primitive TEXCOORD_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Float32Array}\n */\nfunction flattenTexCoords(texCoords, indices) {\n const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);\n if (!texCoords) {\n // We need dummy UV0s because it is required in 1.6\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.6/vertexAttribute.cmn.md\n newTexCoords.fill(1);\n return newTexCoords;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_TEX_COORD;\n const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);\n newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];\n newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];\n }\n return newTexCoords;\n}\n\n/**\n * Convert color from COLOR_0 based on indices to plain arrays, compatible with i3s\n * @param {object} colorsAttribute - gltf primitive COLOR_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Uint8Array}\n */\nfunction flattenColors(colorsAttribute, indices) {\n const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;\n const newColors = new Uint8Array(indices.length * components);\n if (!colorsAttribute) {\n // Vertex color multiplies by material color so it must be normalized 1 by default\n newColors.fill(255);\n return newColors;\n }\n const colors = colorsAttribute.value;\n for (let i = 0; i < indices.length; i++) {\n const colorIndex = indices[i] * components;\n const color = colors.subarray(colorIndex, colorIndex + components);\n const colorUint8 = new Uint8Array(components);\n for (let j = 0; j < color.length; j++) {\n colorUint8[j] = color[j] * 255;\n }\n newColors.set(colorUint8, i * components);\n }\n return newColors;\n}\n\n/**\n * Flatten batchedIds list based on indices to right ordered array, compatible with i3s\n * @param {Array} batchedIds - gltf primitive\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Array}\n */\nfunction flattenBatchIds(batchedIds, indices) {\n if (!batchedIds.length || !indices.length) {\n return [];\n }\n const newBatchIds = [];\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i];\n newBatchIds.push(batchedIds[coordIndex]);\n }\n return newBatchIds;\n}\n/**\n * Return batchIds based on possible attribute names for different kind of maps.\n * @param {Object} attributes {attributeName: Float32Array}\n * @returns {Array}\n */\nfunction getBatchIdsByAttributeName(attributes) {\n let batchIds = [];\n\n for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {\n const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];\n if (\n attributes[possibleBatchIdAttributeName] &&\n attributes[possibleBatchIdAttributeName].value\n ) {\n batchIds = attributes[possibleBatchIdAttributeName].value;\n break;\n }\n }\n\n return batchIds;\n}\n\nfunction convertMaterials(tileContent) {\n const result = [];\n const sourceMaterials = tileContent.gltf.materials || [];\n for (const sourceMaterial of sourceMaterials) {\n result.push(convertMaterial(sourceMaterial));\n }\n return result;\n}\n\n/**\n * Convert texture and material from gltf 2.0 material object\n * @param {Object} sourceMaterial - material object\n * @returns {Object}\n */\nfunction convertMaterial(sourceMaterial) {\n const material = {\n doubleSided: sourceMaterial.doubleSided,\n emissiveFactor: sourceMaterial.emissiveFactor.map((c) => Math.round(c * 255)),\n // It is in upper case in GLTF: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#alpha-coverage\n // But it is in lower case in I3S: https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md\n alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),\n pbrMetallicRoughness: {\n roughnessFactor:\n sourceMaterial?.pbrMetallicRoughness?.roughnessFactor || DEFAULT_ROUGHNESS_FACTOR,\n metallicFactor:\n sourceMaterial?.pbrMetallicRoughness?.metallicFactor || DEFAULT_METALLIC_FACTOR\n }\n };\n\n let texture;\n if (sourceMaterial?.pbrMetallicRoughness?.baseColorTexture) {\n texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n } else if (sourceMaterial.emissiveTexture) {\n texture = sourceMaterial.emissiveTexture.texture.source;\n // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n }\n\n if (!texture) {\n // Should use default baseColorFactor if it is not present in source material\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness\n const baseColorFactor = sourceMaterial?.pbrMetallicRoughness?.baseColorFactor;\n material.pbrMetallicRoughness.baseColorFactor =\n (baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) || undefined;\n }\n\n return {material, texture};\n}\n\nfunction getDefaultMaterial() {\n return {\n alphaMode: 'opaque',\n pbrMetallicRoughness: {}\n };\n}\n\n/**\n * Form \"sharedResources\" from gltf materials array\n * @param {Object} tileContent - 3d tile content\n * @returns {Object} {materialDefinitionInfos: Object[], textureDefinitionInfos: Object[]} -\n * 2 arrays in format of i3s sharedResources data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/sharedResource.cmn.md\n */\nfunction getSharedResources(tileContent, nodeId) {\n const gltfMaterials = tileContent.gltf.materials;\n const i3sResources = {};\n\n if (!gltfMaterials || !gltfMaterials.length) {\n return i3sResources;\n }\n\n i3sResources.materialDefinitionInfos = [];\n for (const gltfMaterial of gltfMaterials) {\n const {materialDefinitionInfo, textureDefinitionInfo} = convertGLTFMaterialToI3sSharedResources(\n gltfMaterial,\n nodeId\n );\n i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);\n if (textureDefinitionInfo) {\n i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];\n i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);\n }\n }\n return i3sResources;\n}\n\n/**\n * Convert gltf material into I3S sharedResources data\n * @param {Object} gltfMaterial - gltf material data\n * @returns {Object} - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data\n */\nfunction convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {\n const texture =\n gltfMaterial?.pbrMetallicRoughness?.baseColorTexture || gltfMaterial.emissiveTexture;\n let textureDefinitionInfo = null;\n if (texture) {\n textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);\n }\n const {baseColorFactor, metallicFactor} = gltfMaterial?.pbrMetallicRoughness || {};\n let colorFactor = baseColorFactor;\n // If alpha channel is 0 try to get emissive factor from gltf material.\n if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {\n colorFactor = gltfMaterial.emissiveFactor;\n colorFactor[3] = colorFactor[3] || 1;\n }\n\n return {\n materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),\n textureDefinitionInfo\n };\n}\n\n/**\n * Form \"materialDefinition\" which is part of \"sharedResouces\"\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materials\n * See formulas in appendix \"Appendix B: BRDF Implementation\":\n * const dielectricSpecular = rgb(0.04, 0.04, 0.04)\n * const black = rgb(0, 0, 0)\n * cdiff = lerp(baseColor.rgb * (1 - dielectricSpecular.r), black, metallic)\n * F0 = lerp(dieletricSpecular, baseColor.rgb, metallic)\n *\n * Assumption: F0 - specular in i3s (\"specular reflection\" <-> \"reflectance value at normal incidence\")\n * cdiff - diffuse in i3s (\"Diffuse color\" <-> \"'c' diffuse\" (c means color?))\n * @param {number[]} baseColorFactor - RGBA color in 0..1 format\n * @param {number} metallicFactor - \"metallicFactor\" attribute of gltf material object\n * @returns {Object}\n */\nfunction extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1) {\n const matDielectricColorComponent = 0.04 / 255; // Color from rgb (255) to 0..1 resolution\n // All color resolutions are 0..1\n const black = new Vector4(0, 0, 0, 1);\n const unitVector = new Vector4(1, 1, 1, 1);\n const dielectricSpecular = new Vector4(\n matDielectricColorComponent,\n matDielectricColorComponent,\n matDielectricColorComponent,\n 0\n );\n const baseColorVector = new Vector4(baseColorFactor);\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material\n // Formulas for Cdiff & F0\n const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);\n const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);\n dielectricSpecular[3] = 1;\n const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);\n return {\n diffuse: diffuse.toArray(),\n specular: specular.toArray()\n };\n}\n\n/**\n * Form \"textureDefinition\" which is part of \"sharedResouces\"\n * @param {Object} texture - texture image info\n * @returns {Object}\n */\nfunction extractSharedResourcesTextureInfo(texture, nodeId) {\n return {\n encoding: [texture.source.mimeType],\n images: [\n {\n // 'i3s' has just size which is width of the image. Images are supposed to be square.\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md\n id: generateImageId(texture, nodeId),\n size: texture.source.image.width,\n length: [texture.source.image.data.length]\n }\n ]\n };\n}\n/*\n * Formula for counting imageId:\n * https://github.com/Esri/i3s-spec/blob/0a6366a9249b831db8436c322f8d27521e86cf07/format/Indexed%203d%20Scene%20Layer%20Format%20Specification.md#generating-image-ids\n * @param {Object} texture - texture image info\n * @returns {string}\n */\nfunction generateImageId(texture, nodeId) {\n const {width, height} = texture.source.image;\n const levelCountOfTexture = 1;\n const indexOfLevel = 0;\n const indexOfTextureInStore = nodeId + 1;\n\n const zerosCount = 32 - indexOfTextureInStore.toString(2).length;\n const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));\n\n const shiftedLevelCountOfTexture = levelCountOfTexture << 28;\n const shiftedIndexOfLevel = indexOfLevel << 24;\n const shiftedWidth = (width - 1) << 12;\n const shiftedHeight = (height - 1) << 0;\n\n const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;\n const imageId = BigInt(`0b${leftHalf.toString(2)}${rightHalf}`);\n return imageId.toString();\n}\n\n/**\n * Make all feature ids unique through all nodes in layout.\n * @param {Array} featureIds\n * @param {Array} featureIndices\n * @param {Array} featuresHashArray\n * @param {Object} batchTable\n * @returns {void}\n */\nfunction makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {\n const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);\n replaceIndicesByUnique(featureIndices, replaceMap);\n replaceIndicesByUnique(featureIds, replaceMap);\n}\n\n/**\n * Generate replace map to make featureIds unique.\n * @param {Array} featureIds\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Object}\n */\nfunction getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {\n const featureMap = {};\n\n for (let index = 0; index < featureIds.length; index++) {\n const oldFeatureId = featureIds[index];\n const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);\n featureMap[oldFeatureId.toString()] = uniqueFeatureId;\n }\n\n return featureMap;\n}\n\n/**\n * Generates string for unique batch id creation.\n * @param {Object} batchTable\n * @param {Number} index\n * @returns {String}\n */\nfunction generateStringFromBatchTableByIndex(batchTable, index) {\n let str = '';\n for (const key in batchTable) {\n str += batchTable[key][index];\n }\n return str;\n}\n\n/**\n * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.\n * @param {Number} index\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Number}\n */\nfunction getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {\n const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);\n const hash = md5(batchTableStr);\n\n if (featuresHashArray.includes(hash)) {\n return featuresHashArray.indexOf(hash);\n }\n return featuresHashArray.push(hash) - 1;\n}\n\n/**\n * Do replacement of indices for making them unique through all nodes.\n * @param {Array} indicesArray\n * @param {Object} featureMap\n * @returns {void}\n */\nfunction replaceIndicesByUnique(indicesArray, featureMap) {\n for (let index = 0; index < indicesArray.length; index++) {\n indicesArray[index] = featureMap[indicesArray[index]];\n }\n}\n\n/**\n * Convert batch table data to attribute buffers.\n * @param {Object} batchTable - table with metadata for particular feature.\n * @param {Array} featureIds\n * @param {Array} attributeStorageInfo\n * @returns {Array} - Array of file buffers.\n */\nfunction convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {\n const attributeBuffers = [];\n\n if (batchTable) {\n const batchTableWithFeatureIds = {\n OBJECTID: featureIds,\n ...batchTable\n };\n\n for (const key in batchTableWithFeatureIds) {\n const type = getAttributeType(key, attributeStorageInfo);\n\n let attributeBuffer = null;\n\n switch (type) {\n case OBJECT_ID_TYPE:\n case SHORT_INT_TYPE:\n attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case DOUBLE_TYPE:\n attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case STRING_TYPE:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n default:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n }\n\n attributeBuffers.push(attributeBuffer);\n }\n }\n\n return attributeBuffers;\n}\n/**\n * Return attribute type.\n * @param {String} key\n * @param {Array} attributeStorageInfo\n * @returns {String} attribute type.\n */\nfunction getAttributeType(key, attributeStorageInfo) {\n const attribute = attributeStorageInfo.find((attr) => attr.name === key);\n return attribute.attributeValues.valueType;\n}\n\n/**\n * Convert short integer to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateShortIntegerAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const valuesArray = new Uint32Array(featureIds);\n return concatenateArrayBuffers(count.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert double to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateDoubleAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const padding = new Uint8Array(4);\n const valuesArray = new Float64Array(featureIds);\n\n return concatenateArrayBuffers(count.buffer, padding.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert batch table attributes to array buffer with batch table data.\n * @param {Array} batchAttributes\n * @returns {ArrayBuffer} - Buffer with batch table data.\n */\nfunction generateStringAttributeBuffer(batchAttributes) {\n const stringCountArray = new Uint32Array([batchAttributes.length]);\n let totalNumberOfBytes = 0;\n const stringSizesArray = new Uint32Array(batchAttributes.length);\n const stringBufferArray = [];\n\n for (let index = 0; index < batchAttributes.length; index++) {\n const currentString = `${String(batchAttributes[index])}\\0`;\n const currentStringBuffer = Buffer.from(currentString);\n const currentStringSize = currentStringBuffer.length;\n totalNumberOfBytes += currentStringSize;\n stringSizesArray[index] = currentStringSize;\n stringBufferArray.push(currentStringBuffer);\n }\n\n const totalBytes = new Uint32Array([totalNumberOfBytes]);\n\n return concatenateArrayBuffers(\n stringCountArray.buffer,\n totalBytes.buffer,\n stringSizesArray.buffer,\n ...stringBufferArray\n );\n}\n\n/**\n * Convert featureIds to BigUint64Array.\n * @param {Array} featureIds\n * @returns {BigUint64Array} - Array of feature ids in BigUint64 format.\n */\nfunction generateBigUint64Array(featureIds) {\n const typedFeatureIds = new BigUint64Array(featureIds.length);\n for (let index = 0; index < featureIds.length; index++) {\n typedFeatureIds[index] = BigInt(featureIds[index]);\n }\n return typedFeatureIds;\n}\n\n/**\n * Generates draco compressed geometry\n * @param {Number} vertexCount\n * @param {Object} convertedAttributes\n * @returns {Promise<object>} - COmpressed geometry.\n */\nasync function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {\n const {positions, normals, texCoords, colors, featureIds, faceRange} = attributes;\n const indices = new Uint32Array(vertexCount);\n\n for (let index = 0; index < indices.length; index++) {\n indices.set([index], index);\n }\n\n const featureIndices = new Uint32Array(\n convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount\n );\n\n const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);\n\n const compressedAttributes = {\n positions,\n normals,\n colors,\n 'feature-index': featureIndex\n };\n\n if (texCoords.length) {\n compressedAttributes.texCoords = texCoords;\n }\n\n const attributesMetadata = {\n 'feature-index': {\n 'i3s-attribute-type': 'feature-index',\n 'i3s-feature-ids': new Int32Array(featureIds)\n }\n };\n\n return new Uint8Array(\n await encode({attributes: compressedAttributes, indices}, DracoWriter, {\n draco: {\n method: 'MESH_SEQUENTIAL_ENCODING',\n attributesMetadata\n }\n })\n );\n}\n\n/**\n * Generates ordered feature indices based on face range\n * @param {Uint32Array} featureIndex\n * @param {Uint32Array} faceRange\n * @returns {Uint32Array}\n */\nfunction generateFeatureIndexAttribute(featureIndex, faceRange) {\n const orderedFeatureIndices = new Uint32Array(featureIndex.length);\n let fillIndex = 0;\n let startIndex = 0;\n\n for (let index = 1; index < faceRange.length; index += 2) {\n const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;\n\n orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);\n\n fillIndex++;\n startIndex = endIndex + 1;\n }\n\n return orderedFeatureIndices;\n}\n"],"file":"geometry-converter.js"}
|
|
@@ -157,7 +157,6 @@ var NodePages = function () {
|
|
|
157
157
|
value: function () {
|
|
158
158
|
var _save = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(layers0Path, fileMap) {
|
|
159
159
|
var slpk,
|
|
160
|
-
promises,
|
|
161
160
|
_iterator,
|
|
162
161
|
_step,
|
|
163
162
|
_step$value,
|
|
@@ -181,67 +180,111 @@ var NodePages = function () {
|
|
|
181
180
|
switch (_context.prev = _context.next) {
|
|
182
181
|
case 0:
|
|
183
182
|
slpk = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
|
|
184
|
-
promises = [];
|
|
185
183
|
|
|
186
184
|
if (!slpk) {
|
|
187
|
-
_context.next =
|
|
185
|
+
_context.next = 29;
|
|
188
186
|
break;
|
|
189
187
|
}
|
|
190
188
|
|
|
191
189
|
_iterator = _createForOfIteratorHelper(this.nodePages.entries());
|
|
190
|
+
_context.prev = 3;
|
|
192
191
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = "".concat(slpkPath, ".json.gz");
|
|
200
|
-
}
|
|
201
|
-
} catch (err) {
|
|
202
|
-
_iterator.e(err);
|
|
203
|
-
} finally {
|
|
204
|
-
_iterator.f();
|
|
192
|
+
_iterator.s();
|
|
193
|
+
|
|
194
|
+
case 5:
|
|
195
|
+
if ((_step = _iterator.n()).done) {
|
|
196
|
+
_context.next = 14;
|
|
197
|
+
break;
|
|
205
198
|
}
|
|
206
199
|
|
|
200
|
+
_step$value = (0, _slicedToArray2.default)(_step.value, 2), index = _step$value[0], nodePage = _step$value[1];
|
|
201
|
+
nodePageStr = JSON.stringify(nodePage);
|
|
202
|
+
slpkPath = (0, _path.join)(layers0Path, 'nodepages');
|
|
203
|
+
_context.next = 11;
|
|
204
|
+
return this.writeFile(slpkPath, nodePageStr, "".concat(index.toString(), ".json"));
|
|
205
|
+
|
|
206
|
+
case 11:
|
|
207
|
+
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = _context.sent;
|
|
208
|
+
|
|
209
|
+
case 12:
|
|
210
|
+
_context.next = 5;
|
|
211
|
+
break;
|
|
212
|
+
|
|
213
|
+
case 14:
|
|
214
|
+
_context.next = 19;
|
|
215
|
+
break;
|
|
216
|
+
|
|
217
|
+
case 16:
|
|
218
|
+
_context.prev = 16;
|
|
219
|
+
_context.t0 = _context["catch"](3);
|
|
220
|
+
|
|
221
|
+
_iterator.e(_context.t0);
|
|
222
|
+
|
|
223
|
+
case 19:
|
|
224
|
+
_context.prev = 19;
|
|
225
|
+
|
|
226
|
+
_iterator.f();
|
|
227
|
+
|
|
228
|
+
return _context.finish(19);
|
|
229
|
+
|
|
230
|
+
case 22:
|
|
207
231
|
metadata = (0, _jsonMapTransform.default)({
|
|
208
232
|
nodeCount: this.nodesCounter
|
|
209
233
|
}, (0, _metadata.METADATA)());
|
|
210
234
|
compress = false;
|
|
211
|
-
_context.next =
|
|
235
|
+
_context.next = 26;
|
|
212
236
|
return this.writeFile(layers0Path, JSON.stringify(metadata), 'metadata.json', compress);
|
|
213
237
|
|
|
214
|
-
case
|
|
238
|
+
case 26:
|
|
215
239
|
fileMap['metadata.json'] = _context.sent;
|
|
216
|
-
_context.next =
|
|
240
|
+
_context.next = 48;
|
|
217
241
|
break;
|
|
218
242
|
|
|
219
|
-
case
|
|
243
|
+
case 29:
|
|
220
244
|
_iterator2 = _createForOfIteratorHelper(this.nodePages.entries());
|
|
245
|
+
_context.prev = 30;
|
|
221
246
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
} catch (err) {
|
|
230
|
-
_iterator2.e(err);
|
|
231
|
-
} finally {
|
|
232
|
-
_iterator2.f();
|
|
247
|
+
_iterator2.s();
|
|
248
|
+
|
|
249
|
+
case 32:
|
|
250
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
251
|
+
_context.next = 40;
|
|
252
|
+
break;
|
|
233
253
|
}
|
|
234
254
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
255
|
+
_step2$value = (0, _slicedToArray2.default)(_step2.value, 2), _index = _step2$value[0], _nodePage = _step2$value[1];
|
|
256
|
+
_nodePageStr = JSON.stringify(_nodePage);
|
|
257
|
+
nodePagePath = (0, _path.join)(layers0Path, 'nodepages', _index.toString());
|
|
258
|
+
_context.next = 38;
|
|
259
|
+
return this.writeFile(nodePagePath, _nodePageStr);
|
|
238
260
|
|
|
239
|
-
case
|
|
261
|
+
case 38:
|
|
262
|
+
_context.next = 32;
|
|
263
|
+
break;
|
|
264
|
+
|
|
265
|
+
case 40:
|
|
266
|
+
_context.next = 45;
|
|
267
|
+
break;
|
|
268
|
+
|
|
269
|
+
case 42:
|
|
270
|
+
_context.prev = 42;
|
|
271
|
+
_context.t1 = _context["catch"](30);
|
|
272
|
+
|
|
273
|
+
_iterator2.e(_context.t1);
|
|
274
|
+
|
|
275
|
+
case 45:
|
|
276
|
+
_context.prev = 45;
|
|
277
|
+
|
|
278
|
+
_iterator2.f();
|
|
279
|
+
|
|
280
|
+
return _context.finish(45);
|
|
281
|
+
|
|
282
|
+
case 48:
|
|
240
283
|
case "end":
|
|
241
284
|
return _context.stop();
|
|
242
285
|
}
|
|
243
286
|
}
|
|
244
|
-
}, _callee, this);
|
|
287
|
+
}, _callee, this, [[3, 16, 19, 22], [30, 42, 45, 48]]);
|
|
245
288
|
}));
|
|
246
289
|
|
|
247
290
|
function save(_x, _x2) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/node-pages.ts"],"names":["NodePages","writeFileFunc","nodesPerPage","nodesCounter","nodePages","nodes","writeFile","func","id","pageIndex","Math","floor","nodeIndex","materialId","node","getNodeById","mesh","material","definition","resource","index","vertexCount","geometry","attribute","featureCount","texelCountHint","parentId","childId","undefined","parentNode","children","push","currentNodePage","length","addChildRelation","updateResourceInMesh","layers0Path","fileMap","slpk","promises","entries","nodePage","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","compress","nodePagePath","Promise","all"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;IAoCqBA,S;AAYnB,qBAAYC,aAAZ,EAA2BC,YAA3B,EAAyC;AAAA;AAAA;AAAA;AAAA;AAAA;AACvC,SAAKA,YAAL,GAAoBA,YAApB;AACA,SAAKC,YAAL,GAAoB,CAApB;AAEA,SAAKC,SAAL,GAAiB,CAAC,EAAD,CAAjB;AACA,SAAKA,SAAL,CAAe,CAAf,EAAkBC,KAAlB,GAA0B,EAA1B;AACA,SAAKC,SAAL,GAAiBL,aAAjB;AACD;;;;WAMD,0BAAiBM,IAAjB,EAAuC;AACrC,WAAKD,SAAL,GAAiBC,IAAjB;AACD;;;WAOD,qBAAYC,EAAZ,EAAoC;AAClC,UAAMC,SAAS,GAAGC,IAAI,CAACC,KAAL,CAAWH,EAAE,GAAG,KAAKN,YAArB,CAAlB;AACA,UAAMU,SAAS,GAAGJ,EAAE,GAAG,KAAKN,YAA5B;AACA,aAAO,KAAKE,SAAL,CAAeK,SAAf,EAA0BJ,KAA1B,CAAgCO,SAAhC,CAAP;AACD;;;WAOD,gCAAuBJ,EAAvB,EAAmCK,UAAnC,EAA6D;AAC3D,UAAMC,IAAI,GAAG,KAAKC,WAAL,CAAiBP,EAAjB,CAAb;;AACA,UAAI,CAACM,IAAI,CAACE,IAAV,EAAgB;AACd;AACD;;AACDF,MAAAA,IAAI,CAACE,IAAL,CAAUC,QAAV,GAAqB;AACnBC,QAAAA,UAAU,EAAEL,UADO;AAEnBM,QAAAA,QAAQ,EAAEL,IAAI,CAACM;AAFI,OAArB;AAID;;;WAOD,mCAA0BZ,EAA1B,EAAsCa,WAAtC,EAAiE;AAC/D,UAAMP,IAAI,GAAG,KAAK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Template} from '../json-templates/metadata';\nimport {NodeInPage} from '@loaders.gl/i3s';\n\n// @ts-nocheck\n/**\n * class NodePages - wrapper of nodePages array\n *\n * @example\n * import {writeFile} from './helpers/write-file';\n *\n * // create an instance of the class\n * const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);\n * ...\n * // push root node\n * const parentId = nodePages.push({\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: []\n });\n * ...\n * // push node with parent relation\n * const nodeInPage = {\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: [],\n mesh: {\n geometry: {\n definition: 0\n }\n }\n };\n * const nodeId = this.nodePages.push(nodeInPage, parentId);\n * ...\n * // save all the nodePages in the end of pushing all the nodes\n * await this.nodePages.save(layers0path);\n */\nexport default class NodePages {\n readonly nodesPerPage: number;\n nodesCounter: number;\n writeFile: Function;\n readonly nodePages: {nodes: NodeInPage[]}[];\n\n /**\n * @constructs\n * Create a nodePages instance.\n * @param writeFileFunc - function to save one nodePage into a file\n * @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met\n */\n constructor(writeFileFunc, nodesPerPage) {\n this.nodesPerPage = nodesPerPage;\n this.nodesCounter = 0;\n // @ts-expect-error\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n /**\n * Setup function to save node pages\n * @param func - function which should be used to save node pages\n */\n useWriteFunction(func: Function): void {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param id - end-to-end index of the node\n * @return the node object\n */\n getNodeById(id: number): NodeInPage {\n const pageIndex = Math.floor(id / this.nodesPerPage);\n const nodeIndex = id % this.nodesPerPage;\n return this.nodePages[pageIndex].nodes[nodeIndex];\n }\n\n /**\n * Update material in node.mesh object by node id\n * @param id - end-to-end index of the node\n * @param materialId - id from scene layer materialDefinitions\n */\n updateMaterialByNodeId(id: number, materialId: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.material = {\n definition: materialId,\n resource: node.index\n };\n }\n\n /**\n * Update vertexCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param vertexCount - vertex count for particular node\n */\n updateVertexCountByNodeId(id: number, vertexCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.vertexCount = vertexCount;\n }\n\n /**\n * Update resource in node.mesh.attribute object by node id\n * @param id - end-to-end index of the node\n */\n updateNodeAttributeByNodeId(id: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.attribute.resource = node.index;\n }\n\n /**\n * Update featureCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param featureCount - features count of the node\n */\n updateFeatureCountByNodeId(id: number, featureCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n /**\n * Update texelCountHint in node.mesh.material object by node id\n * @param id - end-to-end index of the node\n * @param texelCountHint - texelCountHint of particular node\n */\n updateTexelCountHintByNodeId(id: number, texelCountHint: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh || !node.mesh.material) {\n return;\n }\n node.mesh.material.texelCountHint = texelCountHint;\n }\n\n /**\n * Add a child id into the parent node.children array\n * @param parentId - end-to-end parent node index\n * @param childId - end-to-end child node index\n */\n addChildRelation(parentId: number | undefined, childId: number): void {\n if (parentId === null || parentId === undefined) {\n return;\n }\n const parentNode = this.getNodeById(parentId);\n parentNode.children?.push(childId);\n }\n\n /**\n * Update resource index in node.mesh object\n * @param node - node object\n */\n updateResourceInMesh(node: NodeInPage): void {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param node - node object\n * @param parentId - index of parent node\n * @return\n */\n push(node: NodeInPage, parentId?: number): number {\n let currentNodePage = this.nodePages[this.nodePages.length - 1];\n if (currentNodePage.nodes.length === this.nodesPerPage) {\n currentNodePage = {nodes: []};\n this.nodePages.push(currentNodePage);\n }\n node.index = this.nodesCounter++;\n currentNodePage.nodes.push(node);\n this.addChildRelation(parentId, node.index);\n this.updateResourceInMesh(node);\n return node.index;\n }\n\n /**\n * Save all the node pages\n * Run this method when all nodes is pushed in nodePages\n * @param {string} layers0Path - path of layer\n * @param {Object} fileMap - fileMap which keep info for slpk archive\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {\n const promises: Promise<any>[] = [];\n if (slpk) {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const slpkPath = join(layers0Path, 'nodepages');\n promises.push(this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`));\n fileMap[`nodePages/${index.toString()}.json.gz`] = `${slpkPath}.json.gz`;\n }\n const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate());\n const compress = false;\n fileMap['metadata.json'] = await this.writeFile(\n layers0Path,\n JSON.stringify(metadata),\n 'metadata.json',\n compress\n );\n } else {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const nodePagePath = join(layers0Path, 'nodepages', index.toString());\n promises.push(this.writeFile(nodePagePath, nodePageStr));\n }\n }\n\n await Promise.all(promises);\n }\n}\n"],"file":"node-pages.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/node-pages.ts"],"names":["NodePages","writeFileFunc","nodesPerPage","nodesCounter","nodePages","nodes","writeFile","func","id","pageIndex","Math","floor","nodeIndex","materialId","node","getNodeById","mesh","material","definition","resource","index","vertexCount","geometry","attribute","featureCount","texelCountHint","parentId","childId","undefined","parentNode","children","push","currentNodePage","length","addChildRelation","updateResourceInMesh","layers0Path","fileMap","slpk","entries","nodePage","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","compress","nodePagePath"],"mappings":";;;;;;;;;;;;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cjB,KAAK,CAACyB,QAAN,EAAd,cALb;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAWUC,gBAAAA,QAXV,GAWqB,+BAAU;AAACC,kBAAAA,SAAS,EAAE,KAAK5C;AAAjB,iBAAV,EAA0C,yBAA1C,CAXrB;AAYU6C,gBAAAA,QAZV,GAYqB,KAZrB;AAAA;AAAA,uBAaqC,KAAK1C,SAAL,CAC/B8B,WAD+B,EAE/BM,IAAI,CAACC,SAAL,CAAeG,QAAf,CAF+B,EAG/B,eAH+B,EAI/BE,QAJ+B,CAbrC;;AAAA;AAaIX,gBAAAA,OAAO,CAAC,eAAD,CAbX;AAAA;AAAA;;AAAA;AAAA,wDAoBoC,KAAKjC,SAAL,CAAemC,OAAf,EApBpC;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,8EAoBgBnB,MApBhB,oBAoBuBoB,SApBvB;AAqBYC,gBAAAA,YArBZ,GAqB0BC,IAAI,CAACC,SAAL,CAAeH,SAAf,CArB1B;AAsBYS,gBAAAA,YAtBZ,GAsB2B,gBAAKb,WAAL,EAAkB,WAAlB,EAA+BhB,MAAK,CAACyB,QAAN,EAA/B,CAtB3B;AAAA;AAAA,uBAuBY,KAAKvC,SAAL,CAAe2C,YAAf,EAA6BR,YAA7B,CAvBZ;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O","sourcesContent":["import {join} from 'path';\nimport transform from 'json-map-transform';\nimport {METADATA as metadataTemplate} from '../json-templates/metadata';\nimport {NodeInPage} from '@loaders.gl/i3s';\n\n// @ts-nocheck\n/**\n * class NodePages - wrapper of nodePages array\n *\n * @example\n * import {writeFile} from './helpers/write-file';\n *\n * // create an instance of the class\n * const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);\n * ...\n * // push root node\n * const parentId = nodePages.push({\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: []\n });\n * ...\n * // push node with parent relation\n * const nodeInPage = {\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: [],\n mesh: {\n geometry: {\n definition: 0\n }\n }\n };\n * const nodeId = this.nodePages.push(nodeInPage, parentId);\n * ...\n * // save all the nodePages in the end of pushing all the nodes\n * await this.nodePages.save(layers0path);\n */\nexport default class NodePages {\n readonly nodesPerPage: number;\n nodesCounter: number;\n writeFile: Function;\n readonly nodePages: {nodes: NodeInPage[]}[];\n\n /**\n * @constructs\n * Create a nodePages instance.\n * @param writeFileFunc - function to save one nodePage into a file\n * @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met\n */\n constructor(writeFileFunc, nodesPerPage) {\n this.nodesPerPage = nodesPerPage;\n this.nodesCounter = 0;\n // @ts-expect-error\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n /**\n * Setup function to save node pages\n * @param func - function which should be used to save node pages\n */\n useWriteFunction(func: Function): void {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param id - end-to-end index of the node\n * @return the node object\n */\n getNodeById(id: number): NodeInPage {\n const pageIndex = Math.floor(id / this.nodesPerPage);\n const nodeIndex = id % this.nodesPerPage;\n return this.nodePages[pageIndex].nodes[nodeIndex];\n }\n\n /**\n * Update material in node.mesh object by node id\n * @param id - end-to-end index of the node\n * @param materialId - id from scene layer materialDefinitions\n */\n updateMaterialByNodeId(id: number, materialId: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.material = {\n definition: materialId,\n resource: node.index\n };\n }\n\n /**\n * Update vertexCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param vertexCount - vertex count for particular node\n */\n updateVertexCountByNodeId(id: number, vertexCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.vertexCount = vertexCount;\n }\n\n /**\n * Update resource in node.mesh.attribute object by node id\n * @param id - end-to-end index of the node\n */\n updateNodeAttributeByNodeId(id: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.attribute.resource = node.index;\n }\n\n /**\n * Update featureCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param featureCount - features count of the node\n */\n updateFeatureCountByNodeId(id: number, featureCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n /**\n * Update texelCountHint in node.mesh.material object by node id\n * @param id - end-to-end index of the node\n * @param texelCountHint - texelCountHint of particular node\n */\n updateTexelCountHintByNodeId(id: number, texelCountHint: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh || !node.mesh.material) {\n return;\n }\n node.mesh.material.texelCountHint = texelCountHint;\n }\n\n /**\n * Add a child id into the parent node.children array\n * @param parentId - end-to-end parent node index\n * @param childId - end-to-end child node index\n */\n addChildRelation(parentId: number | undefined, childId: number): void {\n if (parentId === null || parentId === undefined) {\n return;\n }\n const parentNode = this.getNodeById(parentId);\n parentNode.children?.push(childId);\n }\n\n /**\n * Update resource index in node.mesh object\n * @param node - node object\n */\n updateResourceInMesh(node: NodeInPage): void {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param node - node object\n * @param parentId - index of parent node\n * @return\n */\n push(node: NodeInPage, parentId?: number): number {\n let currentNodePage = this.nodePages[this.nodePages.length - 1];\n if (currentNodePage.nodes.length === this.nodesPerPage) {\n currentNodePage = {nodes: []};\n this.nodePages.push(currentNodePage);\n }\n node.index = this.nodesCounter++;\n currentNodePage.nodes.push(node);\n this.addChildRelation(parentId, node.index);\n this.updateResourceInMesh(node);\n return node.index;\n }\n\n /**\n * Save all the node pages\n * Run this method when all nodes is pushed in nodePages\n * @param {string} layers0Path - path of layer\n * @param {Object} fileMap - fileMap which keep info for slpk archive\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {\n if (slpk) {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const slpkPath = join(layers0Path, 'nodepages');\n fileMap[`nodePages/${index.toString()}.json.gz`] = await this.writeFile(\n slpkPath,\n nodePageStr,\n `${index.toString()}.json`\n );\n }\n const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate());\n const compress = false;\n fileMap['metadata.json'] = await this.writeFile(\n layers0Path,\n JSON.stringify(metadata),\n 'metadata.json',\n compress\n );\n } else {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const nodePagePath = join(layers0Path, 'nodepages', index.toString());\n await this.writeFile(nodePagePath, nodePageStr);\n }\n }\n }\n}\n"],"file":"node-pages.js"}
|