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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +78 -0
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +9 -7
  4. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +78 -18
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  7. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +19 -9
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  9. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +4 -7
  10. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  11. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  12. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  13. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  14. package/dist/3d-tiles-converter/helpers/texture-atlas.js +1 -1
  15. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  16. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  17. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  18. package/dist/3d-tiles-converter/json-templates/tileset.js +12 -9
  19. package/dist/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  20. package/dist/bundle.d.ts +2 -0
  21. package/dist/bundle.d.ts.map +1 -0
  22. package/dist/converter.min.js +22 -22
  23. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  24. package/dist/deps-installer/deps-installer.js +2 -6
  25. package/dist/deps-installer/deps-installer.js.map +1 -1
  26. package/dist/dist.min.js +86527 -0
  27. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
  28. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  29. package/dist/i3s-converter/helpers/coordinate-converter.js +35 -3
  30. package/dist/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  31. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  32. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  33. package/dist/i3s-converter/helpers/create-scene-server-path.js +2 -2
  34. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  35. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +23 -0
  36. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  37. package/dist/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  38. package/dist/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  39. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  40. package/dist/i3s-converter/helpers/geometry-converter.js +88 -42
  41. package/dist/i3s-converter/helpers/geometry-converter.js.map +1 -1
  42. package/dist/i3s-converter/helpers/node-debug.d.ts +2 -0
  43. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  44. package/dist/i3s-converter/helpers/node-debug.js +2 -4
  45. package/dist/i3s-converter/helpers/node-debug.js.map +1 -1
  46. package/dist/i3s-converter/helpers/node-pages.d.ts +83 -111
  47. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  48. package/dist/i3s-converter/helpers/node-pages.js +15 -4
  49. package/dist/i3s-converter/helpers/node-pages.js.map +1 -1
  50. package/dist/i3s-converter/i3s-converter.d.ts +320 -0
  51. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  52. package/dist/i3s-converter/i3s-converter.js +158 -65
  53. package/dist/i3s-converter/i3s-converter.js.map +1 -1
  54. package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
  55. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  56. package/dist/i3s-converter/json-templates/layers.js +37 -27
  57. package/dist/i3s-converter/json-templates/layers.js.map +1 -1
  58. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  59. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  60. package/dist/i3s-converter/json-templates/metadata.js +2 -2
  61. package/dist/i3s-converter/json-templates/metadata.js.map +1 -1
  62. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  63. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  64. package/dist/i3s-converter/json-templates/node.js +16 -12
  65. package/dist/i3s-converter/json-templates/node.js.map +1 -1
  66. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  67. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  68. package/dist/i3s-converter/json-templates/scene-server.js +2 -2
  69. package/dist/i3s-converter/json-templates/scene-server.js.map +1 -1
  70. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  71. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  72. package/dist/i3s-converter/json-templates/shared-resources.js +19 -14
  73. package/dist/i3s-converter/json-templates/shared-resources.js.map +1 -1
  74. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  75. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  76. package/dist/i3s-converter/json-templates/store.js.map +1 -1
  77. package/dist/i3s-converter/types.d.ts +14 -0
  78. package/dist/i3s-converter/types.d.ts.map +1 -0
  79. package/dist/i3s-converter/types.js +2 -0
  80. package/dist/i3s-converter/types.js.map +1 -0
  81. package/dist/i3s-server/app.d.ts +3 -0
  82. package/dist/i3s-server/app.d.ts.map +1 -0
  83. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  84. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  85. package/dist/i3s-server/routes/index.d.ts +3 -0
  86. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  87. package/dist/index.d.ts +5 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  90. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  91. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  92. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  93. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  94. package/dist/pgm-loader.d.ts +6 -0
  95. package/dist/pgm-loader.d.ts.map +1 -0
  96. package/dist/pgm-loader.js +3 -3
  97. package/dist/pgm-loader.js.map +1 -1
  98. package/package.json +21 -19
  99. package/src/3d-tiles-converter/3d-tiles-converter.ts +25 -21
  100. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +35 -11
  101. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  102. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  103. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  104. package/src/deps-installer/deps-installer.js +2 -2
  105. package/src/i3s-converter/helpers/coordinate-converter.ts +62 -9
  106. package/src/i3s-converter/helpers/{create-scene-server-path.js → create-scene-server-path.ts} +2 -2
  107. package/src/i3s-converter/helpers/{geometry-attributes.js → geometry-attributes.ts} +4 -4
  108. package/src/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  109. package/src/i3s-converter/helpers/geometry-converter.js +110 -33
  110. package/src/i3s-converter/helpers/{node-debug.js → node-debug.ts} +3 -2
  111. package/src/i3s-converter/helpers/{node-pages.js → node-pages.ts} +41 -26
  112. package/src/i3s-converter/i3s-converter.ts +214 -136
  113. package/src/i3s-converter/json-templates/{layers.js → layers.ts} +29 -27
  114. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  115. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  116. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  117. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +14 -14
  118. package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  119. package/src/i3s-converter/types.ts +14 -0
  120. package/src/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  121. package/src/pgm-loader.ts +2 -2
  122. package/dist/lib/geoid-height-model.d.ts +0 -41
  123. package/dist/lib/geoid-height-model.js +0 -140
  124. package/dist/lib/geoid-height-model.js.map +0 -1
  125. package/dist/lib/pgm-parser.d.ts +0 -14
  126. package/dist/lib/pgm-parser.js +0 -183
  127. package/dist/lib/pgm-parser.js.map +0 -1
  128. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  129. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  130. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  131. package/src/lib/geoid-height-model.d.ts +0 -41
  132. package/src/lib/geoid-height-model.js +0 -239
  133. package/src/lib/pgm-parser.d.ts +0 -14
  134. package/src/lib/pgm-parser.js +0 -179
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/i3s-converter/helpers/geometry-converter.js"],"names":["Vector3","Matrix4","Vector4","Ellipsoid","DracoWriter","encode","assert","concatenateArrayBuffers","concatenateTypedArrays","md5","generateAttributes","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","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","has","push","material","getDefaultMaterial","result","nodesCounter","materials","gltf","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","vertexCount","positions","triangleCount","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","set","fileBuffer","Uint8Array","buffer","ArrayBuffer","compressedGeometry","generateCompressedGeometry","Float32Array","attributes","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","attrKey","keys","delete","index","reduce","acc","value","concat","matrix","node","convertNode","nodeMatrix","compositeMatrix","multiplyRight","mesh","convertMesh","children","content","primitive","primitives","outputAttributes","transformVertexArray","vertices","POSITION","cartographicOrigin","cartesianModelMatrix","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIdsByAttributeName","args","newVertices","coordIndex","vertex","subarray","vertexVector","Array","from","x","y","z","calleeArgs","transform","WGS84","cartesianToCartographic","subtract","transformAsVector","newTexCoords","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","materialDefinitionInfo","textureDefinitionInfo","convertGLTFMaterialToI3sSharedResources","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","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","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","method","orderedFeatureIndices","fillIndex","startIndex","endIndex","fill"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,OAA1B,QAAwC,eAAxC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAEA,SAAQC,WAAR,QAA0B,mBAA1B;AACA,SAAQC,MAAR,EAAgBC,MAAhB,QAA6B,kBAA7B;AACA,SAAQC,uBAAR,EAAiCC,sBAAjC,QAA8D,0BAA9D;AACA,OAAOC,GAAP,MAAgB,KAAhB;AACA,SAAQC,kBAAR,QAAiC,uBAAjC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,oBAAoB,GAAG,CAA7B;AACA,MAAMC,wBAAwB,GAAG,CAAjC;AAEA,MAAMC,WAAW,GAAG,QAApB;AACA,MAAMC,cAAc,GAAG,OAAvB;AACA,MAAMC,WAAW,GAAG,SAApB;AACA,MAAMC,cAAc,GAAG,OAAvB;AAMA,MAAMC,mCAAmC,GAAG,CAAC,oBAAD,EAAuB,UAAvB,EAAmC,SAAnC,CAA5C;AAEA,eAAe,eAAeC,wBAAf,CACbC,WADa,EAEbC,MAFa,EAGbC,iBAHa,EAIbC,oBAJa,EAKbC,KALa,EAMb;AACA,QAAMC,sBAAsB,GAAGC,gBAAgB,CAACN,WAAD,CAA/C;AACA,QAAMO,sBAAsB,GAAGC,iBAAiB,CAACR,WAAD,CAAhD;;A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ACX,MAAtC,EAA8C+C,KAAK,IAAI,CAAvD,EAA0D;AACxD,UAAMwL,QAAQ,GAAG,CAAC5N,SAAS,CAACoC,KAAD,CAAT,GAAmB,CAApB,IAAyBzE,iBAA1C;AAEA8P,IAAAA,qBAAqB,CAACI,IAAtB,CAA2BH,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';\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\nexport default async function convertB3dmToI3sGeometry(\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n) {\n const materialAndTextureList = convertMaterials(tileContent);\n const convertedAttributesMap = convertAttributes(tileContent);\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 === 0) {\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\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n}) {\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 };\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) {\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 });\n }\n\n const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;\n convertNodes(nodes, tileContent, attributesMap);\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 const vertexCount = attributes.positions.length / VALUES_PER_VERTEX;\n if (!attributes.colors.length) {\n attributes.colors = new Uint8Array(vertexCount * VALUES_PER_COLOR_ELEMENT);\n for (let index = 0; index < attributes.colors.length; index += 4) {\n attributes.colors.set([255, 255, 255, 255], index);\n }\n }\n if (!attributes.texCoords.length) {\n attributes.texCoords = new Float32Array(vertexCount * VALUES_PER_TEX_COORD);\n for (let index = 0; index < attributes.texCoords.length; index += 2) {\n attributes.texCoords.set([1, 1], index);\n }\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 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, matrix);\n }\n }\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 matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n const nodeMatrix = node.matrix;\n const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;\n\n const mesh = node.mesh;\n if (mesh) {\n convertMesh(mesh, tileContent, attributesMap, compositeMatrix);\n }\n\n convertNodes(node.children, tileContent, attributesMap, compositeMatrix);\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 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 })\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 })\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 * @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} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transform(nodeMatrix);\n }\n\n vertexVector = vertexVector.transform(cartesianModelMatrix);\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 if (!texCoords) {\n return new Float32Array(0);\n }\n const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);\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 if (!colorsAttribute) {\n return new Uint8Array(0);\n }\n const components = colorsAttribute.components;\n const colors = colorsAttribute.value;\n const newColors = new Uint8Array(indices.length * components);\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":["Vector3","Matrix4","Vector4","Ellipsoid","DracoWriter","encode","assert","concatenateArrayBuffers","concatenateTypedArrays","md5","generateAttributes","createBoundingVolumesFromGeometry","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","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","useCartesianPositions","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","materials","gltf","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","attributes","values","boundingVolumes","positions","cartographicOrigin","obb","center","index","vertex","subarray","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","compressedGeometry","generateCompressedGeometry","Float32Array","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","attrKey","keys","delete","reduce","acc","value","concat","matrix","node","convertNode","getCompositeTransformationMatrix","transformationMatrix","nodeMatrix","rotation","scale","translation","multiplyRight","rotateXYZ","translate","mesh","convertMesh","children","content","primitive","primitives","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","materialDefinitionInfo","textureDefinitionInfo","convertGLTFMaterialToI3sSharedResources","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","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","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","method","orderedFeatureIndices","fillIndex","startIndex","endIndex"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,OAA1B,QAAwC,eAAxC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAEA,SAAQC,WAAR,QAA0B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AU,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"}
@@ -0,0 +1,2 @@
1
+ export declare function validateNodeBoundingVolumes(node: any): never[];
2
+ //# sourceMappingURL=node-debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-debug.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/node-debug.ts"],"names":[],"mappings":"AAMA,wBAAgB,2BAA2B,CAAC,IAAI,KAAA,WAU/C"}
@@ -4,7 +4,7 @@ import { Vector3 } from '@math.gl/core';
4
4
  import { Ellipsoid } from '@math.gl/geospatial';
5
5
  export function validateNodeBoundingVolumes(node) {
6
6
  if (!node.parentNode.obb || !node.parentNode.mbs) {
7
- return null;
7
+ return [];
8
8
  }
9
9
 
10
10
  const tileWarnings = [];
@@ -53,9 +53,7 @@ function createBoundingBoxFromTileObb(obb) {
53
53
  function getTileObbVertices(node) {
54
54
  const geometry = new CubeGeometry();
55
55
  const halfSize = node.obb.halfSize;
56
- const {
57
- attributes
58
- } = geometry;
56
+ const attributes = geometry.getAttributes();
59
57
  const positions = new Float32Array(attributes.POSITION.value);
60
58
  const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);
61
59
  let vertices = [];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/i3s-converter/helpers/node-debug.js"],"names":["OrientedBoundingBox","BoundingSphere","CubeGeometry","Vector3","Ellipsoid","validateNodeBoundingVolumes","node","parentNode","obb","mbs","tileWarnings","validateObb","validateMbs","parentObb","createBoundingBoxFromTileObb","tileVertices","getTileObbVertices","isTileObbInsideParentObb","isAllVerticesInsideBoundingVolume","title","id","push","tileMbs","createBoundingSphereFromTileMbs","parentMbs","distanceBetweenCenters","center","distanceTo","radius","halfSize","quaternion","fromCenterHalfSizeQuaternion","geometry","attributes","positions","Float32Array","POSITION","value","obbCenterCartesian","WGS84","cartographicToCartesian","vertices","i","length","positionsVector","rotatedPositions","transformByQuaternion","add","concat","boundingVolume","isVerticesInsideObb","index","point","cartographicPoint","cartesianToCartographic","distance"],"mappings":"AAAA,SAAQA,mBAAR,EAA6BC,cAA7B,QAAkD,kBAAlD;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AACA,SAAQC,OAAR,QAAsB,eAAtB;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAGA,OAAO,SAASC,2BAAT,CAAqCC,IAArC,EAA2C;AAChD,MAAI,CAACA,IAAI,CAACC,UAAL,CAAgBC,GAAjB,IAAwB,CAACF,IAAI,CAACC,UAAL,CAAgBE,GAA7C,EAAkD;AAChD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AgB,GAAGD,eAAe,CACrCE,qBADsB,CACAxC,IAAI,CAACE,GAAL,CAASsB,UADT,EAEtBiB,GAFsB,CAElBT,kBAFkB,CAAzB;AAGAG,IAAAA,QAAQ,GAAGA,QAAQ,CAACO,MAAT,CAAgBH,gBAAhB,CAAX;AACD;;AAED,SAAOJ,QAAP;AACD;;AAED,SAASvB,iCAAT,CAA2C+B,cAA3C,EAA2Df,SAA3D,EAAsE;AACpE,MAAIgB,mBAAmB,GAAG,IAA1B;;AAEA,OAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGjB,SAAS,CAACS,MAAV,GAAmB,CAA/C,EAAkDQ,KAAK,IAAI,CAA3D,EAA8D;AAC5D,UAAMC,KAAK,GAAG,CAAClB,SAAS,CAACiB,KAAD,CAAV,EAAmBjB,SAAS,CAACiB,KAAK,GAAG,CAAT,CAA5B,EAAyCjB,SAAS,CAACiB,KAAK,GAAG,CAAT,CAAlD,CAAd;AACA,UAAME,iBAAiB,GAAGjD,SAAS,CAACmC,KAAV,CAAgBe,uBAAhB,CAAwCF,KAAxC,CAA1B;AAEA,UAAMG,QAAQ,GAAGN,cAAc,CAACtB,UAAf,CAA0B0B,iBAA1B,CAAjB;;AAEA,QAAIE,QAAQ,GAAG,CAAf,EAAkB;AAChBL,MAAAA,mBAAmB,GAAG,KAAtB;AACA;AACD;AACF;;AAED,SAAOA,mBAAP;AACD","sourcesContent":["import {OrientedBoundingBox, BoundingSphere} from '@math.gl/culling';\nimport {CubeGeometry} from '@luma.gl/engine';\nimport {Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\n// TODO Unite Tile validation logic in i3s-17-and-debug with this code.\nexport function validateNodeBoundingVolumes(node) {\n if (!node.parentNode.obb || !node.parentNode.mbs) {\n return null;\n }\n const tileWarnings = [];\n\n validateObb(tileWarnings, node);\n validateMbs(tileWarnings, node);\n\n return tileWarnings;\n}\n\nfunction validateObb(tileWarnings, node) {\n const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);\n const tileVertices = getTileObbVertices(node);\n const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);\n\n if (isTileObbInsideParentObb) {\n return;\n }\n\n const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile OBB`;\n tileWarnings.push(title);\n}\n\nfunction validateMbs(tileWarnings, node) {\n const tileMbs = createBoundingSphereFromTileMbs(node.mbs);\n const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);\n const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);\n\n if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {\n const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile MBS`;\n tileWarnings.push(title);\n }\n}\n\nfunction createBoundingSphereFromTileMbs(mbs) {\n return new BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);\n}\n\nfunction createBoundingBoxFromTileObb(obb) {\n const {center, halfSize, quaternion} = obb;\n return new OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);\n}\n\n// TODO check if Obb generates properly\nfunction getTileObbVertices(node) {\n const geometry = new CubeGeometry();\n const halfSize = node.obb.halfSize;\n const {attributes} = geometry;\n const positions = new Float32Array(attributes.POSITION.value);\n const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);\n\n let vertices = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n const positionsVector = new Vector3(\n (positions[i] *= halfSize[0]),\n (positions[i + 1] *= halfSize[1]),\n (positions[i + 2] *= halfSize[2])\n );\n const rotatedPositions = positionsVector\n .transformByQuaternion(node.obb.quaternion)\n .add(obbCenterCartesian);\n vertices = vertices.concat(rotatedPositions);\n }\n\n return vertices;\n}\n\nfunction isAllVerticesInsideBoundingVolume(boundingVolume, positions) {\n let isVerticesInsideObb = true;\n\n for (let index = 0; index < positions.length / 3; index += 3) {\n const point = [positions[index], positions[index + 1], positions[index + 2]];\n const cartographicPoint = Ellipsoid.WGS84.cartesianToCartographic(point);\n\n const distance = boundingVolume.distanceTo(cartographicPoint);\n\n if (distance > 0) {\n isVerticesInsideObb = false;\n break;\n }\n }\n\n return isVerticesInsideObb;\n}\n"],"file":"node-debug.js"}
1
+ {"version":3,"sources":["../../../src/i3s-converter/helpers/node-debug.ts"],"names":["OrientedBoundingBox","BoundingSphere","CubeGeometry","Vector3","Ellipsoid","validateNodeBoundingVolumes","node","parentNode","obb","mbs","tileWarnings","validateObb","validateMbs","parentObb","createBoundingBoxFromTileObb","tileVertices","getTileObbVertices","isTileObbInsideParentObb","isAllVerticesInsideBoundingVolume","title","id","push","tileMbs","createBoundingSphereFromTileMbs","parentMbs","distanceBetweenCenters","center","distanceTo","radius","halfSize","quaternion","fromCenterHalfSizeQuaternion","geometry","attributes","getAttributes","positions","Float32Array","POSITION","value","obbCenterCartesian","WGS84","cartographicToCartesian","vertices","i","length","positionsVector","rotatedPositions","transformByQuaternion","add","concat","boundingVolume","isVerticesInsideObb","index","point","cartographicPoint","cartesianToCartographic","distance"],"mappings":"AAAA,SAAQA,mBAAR,EAA6BC,cAA7B,QAAkD,kBAAlD;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AACA,SAAQC,OAAR,QAAsB,eAAtB;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAGA,OAAO,SAASC,2BAAT,CAAqCC,IAArC,EAA2C;AAChD,MAAI,CAACA,IAAI,CAACC,UAAL,CAAgBC,GAAjB,IAAwB,CAACF,IAAI,CAACC,UAAL,CAAgBE,GAA7C,EAAkD;AAChD,WAAO,EAAP;AACD;;AACD,QAAMC,YAAY,GAAG,EAArB;AAEAC,EAAAA,WAAW,CAACD,YAAD,EAAeJ,IAAf,CAAX;AACAM,EAAAA,WAAW,CAACF,YAAD,EAAeJ,IAAf,CAAX;AAEA,SAAOI,YAAP;AACD;;AAED,SAASC,WAAT,CAAqBD,YAArB,EAAmCJ,IAAnC,EAAyC;AACvC,Q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,CAA2CgC,cAA3C,EAA2Df,SAA3D,EAAsE;AACpE,MAAIgB,mBAAmB,GAAG,IAA1B;;AAEA,OAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGjB,SAAS,CAACS,MAAV,GAAmB,CAA/C,EAAkDQ,KAAK,IAAI,CAA3D,EAA8D;AAC5D,UAAMC,KAAK,GAAG,CAAClB,SAAS,CAACiB,KAAD,CAAV,EAAmBjB,SAAS,CAACiB,KAAK,GAAG,CAAT,CAA5B,EAAyCjB,SAAS,CAACiB,KAAK,GAAG,CAAT,CAAlD,CAAd;AACA,UAAME,iBAAiB,GAAGlD,SAAS,CAACoC,KAAV,CAAgBe,uBAAhB,CAAwCF,KAAxC,CAA1B;AAEA,UAAMG,QAAQ,GAAGN,cAAc,CAACvB,UAAf,CAA0B2B,iBAA1B,CAAjB;;AAEA,QAAIE,QAAQ,GAAG,CAAf,EAAkB;AAChBL,MAAAA,mBAAmB,GAAG,KAAtB;AACA;AACD;AACF;;AAED,SAAOA,mBAAP;AACD","sourcesContent":["import {OrientedBoundingBox, BoundingSphere} from '@math.gl/culling';\nimport {CubeGeometry} from '@luma.gl/engine';\nimport {Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\n// TODO Unite Tile validation logic in i3s-17-and-debug with this code.\nexport function validateNodeBoundingVolumes(node) {\n if (!node.parentNode.obb || !node.parentNode.mbs) {\n return [];\n }\n const tileWarnings = [];\n\n validateObb(tileWarnings, node);\n validateMbs(tileWarnings, node);\n\n return tileWarnings;\n}\n\nfunction validateObb(tileWarnings, node) {\n const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);\n const tileVertices = getTileObbVertices(node);\n const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);\n\n if (isTileObbInsideParentObb) {\n return;\n }\n\n const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile OBB`;\n tileWarnings.push(title);\n}\n\nfunction validateMbs(tileWarnings, node) {\n const tileMbs = createBoundingSphereFromTileMbs(node.mbs);\n const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);\n const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);\n\n if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {\n const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile MBS`;\n tileWarnings.push(title);\n }\n}\n\nfunction createBoundingSphereFromTileMbs(mbs) {\n return new BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);\n}\n\nfunction createBoundingBoxFromTileObb(obb) {\n const {center, halfSize, quaternion} = obb;\n return new OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);\n}\n\n// TODO check if Obb generates properly\nfunction getTileObbVertices(node) {\n const geometry = new CubeGeometry();\n const halfSize = node.obb.halfSize;\n const attributes = geometry.getAttributes();\n const positions = new Float32Array(attributes.POSITION.value);\n const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);\n\n let vertices = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n const positionsVector = new Vector3(\n (positions[i] *= halfSize[0]),\n (positions[i + 1] *= halfSize[1]),\n (positions[i + 2] *= halfSize[2])\n );\n const rotatedPositions = positionsVector\n .transformByQuaternion(node.obb.quaternion)\n .add(obbCenterCartesian);\n // @ts-expect-error\n vertices = vertices.concat(rotatedPositions);\n }\n\n return vertices;\n}\n\nfunction isAllVerticesInsideBoundingVolume(boundingVolume, positions) {\n let isVerticesInsideObb = true;\n\n for (let index = 0; index < positions.length / 3; index += 3) {\n const point = [positions[index], positions[index + 1], positions[index + 2]];\n const cartographicPoint = Ellipsoid.WGS84.cartesianToCartographic(point);\n\n const distance = boundingVolume.distanceTo(cartographicPoint);\n\n if (distance > 0) {\n isVerticesInsideObb = false;\n break;\n }\n }\n\n return isVerticesInsideObb;\n}\n"],"file":"node-debug.js"}
@@ -1,28 +1,9 @@
1
- /**
2
- * Represents one page node
3
- * {@link https://github.com/Esri/i3s-spec/blob/master/docs/1.7/node.cmn.md}
4
- */
5
- export type PageNodeType = {
6
- lodThreshold: number;
7
- obb: any;
8
- children: any[];
9
- mesh?: {
10
- geometry: {
11
- resource?: number;
12
- definition?: number;
13
- };
14
- material?: {
15
- resource?: number;
16
- definition?: number;
17
- };
18
- };
19
- };
20
-
1
+ import { NodeInPage } from '@loaders.gl/i3s';
21
2
  /**
22
3
  * class NodePages - wrapper of nodePages array
23
4
  *
24
5
  * @example
25
- * import writeFile from './helpers/write-file';
6
+ * import {writeFile} from './helpers/write-file';
26
7
  *
27
8
  * // create an instance of the class
28
9
  * const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);
@@ -51,94 +32,85 @@ export type PageNodeType = {
51
32
  * await this.nodePages.save(layers0path);
52
33
  */
53
34
  export default class NodePages {
54
- readonly nodesPerPage: number;
55
- readonly nodesCounter: number;
56
- readonly writeFile: any;
57
- readonly nodePages: {nodes: PageNodeType[]}[];
58
-
59
- /**
60
- * @constructs
61
- * Create a nodePages instance.
62
- * @param writeFileFunc - function to save one nodePage into a file
63
- * @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met
64
- */
65
- constructor(writeFileFunc, nodesPerPage);
66
-
67
- /**
68
- * Setup function to save node pages
69
- * @param func - function which should be used to save node pages
70
- */
71
- useWriteFunction(func: Function): void;
72
-
73
- /**
74
- * Get the node by its end-to-end index
75
- * @param id - end-to-end index of the node
76
- * @return the node object
77
- */
78
- getNodeById(id: number): object;
79
-
80
- /**
81
- * Add a child id into the parent node.children array
82
- * @param parentId - end-to-end parent node index
83
- * @param childId - end-to-end child node index
84
- */
85
- addChildRelation(parentId: number, childId: number): void;
86
-
87
- /**
88
- * Update resource index in node.mesh object
89
- * @param {object} node - node object
90
- */
91
- updateResourceInMesh(node: object): void;
92
-
93
- /**
94
- * Update material in node.mesh object by node id
95
- * @param id - end-to-end index of the node
96
- * @param materialId - id from scene layer materialDefinitions
97
- */
98
- updateMaterialByNodeId(id: number, materialId: number);
99
-
100
- /**
101
- * Update vertexCount in node.mesh.geometry object by node id
102
- * @param id - end-to-end index of the node
103
- * @param vertexCount - vertex count for particular node
104
- */
105
- updateVertexCountByNodeId(id: number, vertexCount: number);
106
-
107
- /**
108
- * Update resource in node.mesh.attribute object by node id
109
- * @param id - end-to-end index of the node
110
- */
111
- updateNodeAttributeByNodeId(id: number);
112
-
113
- /**
114
- * Update featureCount in node.mesh.geometry object by node id
115
- * @param id - end-to-end index of the node
116
- * @param featureCount - features count of the node
117
- */
118
- updateFeatureCountByNodeId(id: number, featureCount: number);
119
-
120
- /**
121
- * Update texelCountHint in node.mesh.material object by node id
122
- * @param id - end-to-end index of the node
123
- * @param texelCountHint - texelCountHint of particular node
124
- */
125
- updateTexelCountHintByNodeId(id: number, texelCountHint: number);
126
-
127
- /**
128
- * Put new node in nodePages array
129
- * @param node - node object
130
- * @param parentId - index of parent node
131
- * @return
132
- */
133
- push(node: PageNodeType, parentId?: number): number;
134
-
135
- /**
136
- * Save all the node pages
137
- * Run this method when all nodes is pushed in nodePages
138
- * @param {string} layers0path - path of layer
139
- * @param {Object} fileMap - fileMap which keep info for slpk archive
140
- * @param {boolean} slpk
141
- * @return {promise}
142
- */
143
- save(layers0path: string, fileMap: Object, slpk: boolean): Promise<void>;
35
+ readonly nodesPerPage: number;
36
+ nodesCounter: number;
37
+ writeFile: Function;
38
+ readonly nodePages: {
39
+ nodes: NodeInPage[];
40
+ }[];
41
+ /**
42
+ * @constructs
43
+ * Create a nodePages instance.
44
+ * @param writeFileFunc - function to save one nodePage into a file
45
+ * @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met
46
+ */
47
+ constructor(writeFileFunc: any, nodesPerPage: any);
48
+ /**
49
+ * Setup function to save node pages
50
+ * @param func - function which should be used to save node pages
51
+ */
52
+ useWriteFunction(func: Function): void;
53
+ /**
54
+ * Get the node by its end-to-end index
55
+ * @param id - end-to-end index of the node
56
+ * @return the node object
57
+ */
58
+ getNodeById(id: number): NodeInPage;
59
+ /**
60
+ * Update material in node.mesh object by node id
61
+ * @param id - end-to-end index of the node
62
+ * @param materialId - id from scene layer materialDefinitions
63
+ */
64
+ updateMaterialByNodeId(id: number, materialId: number): void;
65
+ /**
66
+ * Update vertexCount in node.mesh.geometry object by node id
67
+ * @param id - end-to-end index of the node
68
+ * @param vertexCount - vertex count for particular node
69
+ */
70
+ updateVertexCountByNodeId(id: number, vertexCount: number): void;
71
+ /**
72
+ * Update resource in node.mesh.attribute object by node id
73
+ * @param id - end-to-end index of the node
74
+ */
75
+ updateNodeAttributeByNodeId(id: number): void;
76
+ /**
77
+ * Update featureCount in node.mesh.geometry object by node id
78
+ * @param id - end-to-end index of the node
79
+ * @param featureCount - features count of the node
80
+ */
81
+ updateFeatureCountByNodeId(id: number, featureCount: number): void;
82
+ /**
83
+ * Update texelCountHint in node.mesh.material object by node id
84
+ * @param id - end-to-end index of the node
85
+ * @param texelCountHint - texelCountHint of particular node
86
+ */
87
+ updateTexelCountHintByNodeId(id: number, texelCountHint: number): void;
88
+ /**
89
+ * Add a child id into the parent node.children array
90
+ * @param parentId - end-to-end parent node index
91
+ * @param childId - end-to-end child node index
92
+ */
93
+ addChildRelation(parentId: number | undefined, childId: number): void;
94
+ /**
95
+ * Update resource index in node.mesh object
96
+ * @param node - node object
97
+ */
98
+ updateResourceInMesh(node: NodeInPage): void;
99
+ /**
100
+ * Put new node in nodePages array
101
+ * @param node - node object
102
+ * @param parentId - index of parent node
103
+ * @return
104
+ */
105
+ push(node: NodeInPage, parentId?: number): number;
106
+ /**
107
+ * Save all the node pages
108
+ * Run this method when all nodes is pushed in nodePages
109
+ * @param {string} layers0Path - path of layer
110
+ * @param {Object} fileMap - fileMap which keep info for slpk archive
111
+ * @param {boolean} slpk
112
+ * @return {promise}
113
+ */
114
+ save(layers0Path: string, fileMap: Object, slpk?: boolean): Promise<void>;
144
115
  }
116
+ //# sourceMappingURL=node-pages.d.ts.map
@@ -0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