@loaders.gl/tile-converter 3.2.7 → 3.3.0-alpha.3

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 (77) hide show
  1. package/dist/3d-tiles-attributes-worker.js +3 -3
  2. package/dist/3d-tiles-attributes-worker.js.map +1 -1
  3. package/dist/converter-cli.js +30 -7
  4. package/dist/converter.min.js +1 -1
  5. package/dist/dist.min.js +1105 -621
  6. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  7. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  8. package/dist/es5/converter-cli.js +42 -12
  9. package/dist/es5/converter-cli.js.map +1 -1
  10. package/dist/es5/i3s-attributes-worker.js +1 -1
  11. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  12. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +146 -0
  13. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  14. package/dist/es5/i3s-converter/helpers/feature-attributes.js +60 -0
  15. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
  16. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +39 -7
  17. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  18. package/dist/es5/i3s-converter/helpers/geometry-converter.js +177 -59
  19. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  20. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +15 -1
  21. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  22. package/dist/es5/i3s-converter/i3s-converter.js +50 -51
  23. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  24. package/dist/es5/lib/utils/write-queue.js +3 -5
  25. package/dist/es5/lib/utils/write-queue.js.map +1 -1
  26. package/dist/es5/pgm-loader.js +1 -1
  27. package/dist/es5/pgm-loader.js.map +1 -1
  28. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  29. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
  30. package/dist/esm/converter-cli.js +37 -7
  31. package/dist/esm/converter-cli.js.map +1 -1
  32. package/dist/esm/i3s-attributes-worker.js +1 -1
  33. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  34. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +128 -0
  35. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  36. package/dist/esm/i3s-converter/helpers/feature-attributes.js +34 -0
  37. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
  38. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +23 -7
  39. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  40. package/dist/esm/i3s-converter/helpers/geometry-converter.js +145 -38
  41. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  42. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +15 -1
  43. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  44. package/dist/esm/i3s-converter/i3s-converter.js +21 -27
  45. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  46. package/dist/esm/lib/utils/write-queue.js +3 -5
  47. package/dist/esm/lib/utils/write-queue.js.map +1 -1
  48. package/dist/esm/pgm-loader.js +1 -1
  49. package/dist/esm/pgm-loader.js.map +1 -1
  50. package/dist/i3s-attributes-worker.js +3 -3
  51. package/dist/i3s-attributes-worker.js.map +3 -3
  52. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +12 -0
  53. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
  54. package/dist/i3s-converter/helpers/batch-ids-extensions.js +138 -0
  55. package/dist/i3s-converter/helpers/feature-attributes.d.ts +24 -0
  56. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
  57. package/dist/i3s-converter/helpers/feature-attributes.js +55 -0
  58. package/dist/i3s-converter/helpers/geometry-attributes.js +26 -7
  59. package/dist/i3s-converter/helpers/geometry-converter.d.ts +9 -2
  60. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  61. package/dist/i3s-converter/helpers/geometry-converter.js +140 -44
  62. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  63. package/dist/i3s-converter/helpers/gltf-attributes.js +13 -0
  64. package/dist/i3s-converter/i3s-converter.d.ts +7 -14
  65. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  66. package/dist/i3s-converter/i3s-converter.js +44 -35
  67. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  68. package/dist/lib/utils/write-queue.js +3 -4
  69. package/package.json +15 -15
  70. package/src/converter-cli.ts +33 -7
  71. package/src/i3s-converter/helpers/batch-ids-extensions.ts +199 -0
  72. package/src/i3s-converter/helpers/feature-attributes.ts +65 -0
  73. package/src/i3s-converter/helpers/geometry-attributes.ts +30 -7
  74. package/src/i3s-converter/helpers/geometry-converter.ts +187 -48
  75. package/src/i3s-converter/helpers/gltf-attributes.ts +15 -0
  76. package/src/i3s-converter/i3s-converter.ts +38 -41
  77. package/src/lib/utils/write-queue.ts +7 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-converter.ts"],"names":["Vector3","Matrix4","Vector4","Ellipsoid","DracoWriterWorker","assert","encode","concatenateArrayBuffers","concatenateTypedArrays","md5","generateAttributes","createBoundingVolumesFromGeometry","prepareDataForAttributesConversion","DEFAULT_ROUGHNESS_FACTOR","DEFAULT_METALLIC_FACTOR","VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","scratchVector","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","workerSource","useCartesianPositions","materialAndTextureList","convertMaterials","gltf","materials","dataForAttributesConversion","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","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","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","attributesData","gltfMaterials","nodes","cartesianModelMatrix","attributesMap","Map","featureIndicesGroups","convertNodes","attrKey","keys","delete","reduce","acc","value","concat","matrix","node","convertNode","getCompositeTransformationMatrix","transformationMatrix","nodeMatrix","rotation","scale","translation","multiplyRight","translate","rotateXYZ","mesh","convertMesh","children","primitive","primitives","outputAttributes","transformVertexArray","vertices","POSITION","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","convertAlphaMode","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfAlphaMode","i3sResources","materialDefinitionInfos","gltfMaterial","materialDefinitionInfo","textureDefinitionInfo","convertGLTFMaterialToI3sSharedResources","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","params","toArray","renderMode","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","dracoWorkerSoure","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","options","reuseWorkers","_nodeWorkers","method","orderedFeatureIndices","fillIndex","startIndex","endIndex"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,OAA1B,QAAwC,eAAxC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAEA,SAAQC,iBAAR,QAAgC,mBAAhC;AACA,SAAQC,MAAR,EAAgBC,MAAhB,QAA6B,kBAA7B;AACA,SAAQC,uBAAR,EAAiCC,sBAAjC,QAA8D,0BAA9D;AACA,OAAOC,GAAP,MAAgB,KAAhB;AACA,SAAQC,kBAAR,QAAiC,uBAAjC;AACA,SAAQC,iCAAR,QAAgD,wBAAhD;AAuBA,SAAQC,kCAAR,QAAiD,mBAAjD;AAGA,MAAMC,wBAAwB,GAAG,CAAjC;AACA,MAAMC,uBAAuB,GAAG,CAAhC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,oBAAoB,GAAG,CAA7B;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from '@loaders.gl/draco';\nimport {assert, encode} 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';\nimport {\n ConvertedAttributes,\n I3SConvertedResources,\n I3SMaterialWithTexture,\n SharedResourcesArrays\n} from '../types';\nimport {B3DMContent} from '@loaders.gl/3d-tiles';\nimport {GLTFMaterialPostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';\nimport {\n AttributeStorageInfo,\n I3SMaterialDefinition,\n MaterialDefinitionInfo,\n TextureDefinitionInfo\n} from '@loaders.gl/i3s';\nimport {TypedArray} from '@loaders.gl/schema';\nimport {Geoid} from '@math.gl/geoid';\nimport {\n GLTFAccessorPostprocessed,\n GLTFMeshPostprocessed,\n GLTFTexturePostprocessed\n} from 'modules/gltf/src/lib/types/gltf-types';\nimport {B3DMAttributesData /*transformI3SAttributesOnWorker */} from '../../i3s-attributes-worker';\nimport {prepareDataForAttributesConversion} from './gltf-attributes';\n\n// Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md\nconst DEFAULT_ROUGHNESS_FACTOR = 1;\nconst DEFAULT_METALLIC_FACTOR = 1;\n\nconst VALUES_PER_VERTEX = 3;\nconst VALUES_PER_TEX_COORD = 2;\nconst VALUES_PER_COLOR_ELEMENT = 4;\n\nconst STRING_TYPE = 'string';\nconst SHORT_INT_TYPE = 'Int32';\nconst DOUBLE_TYPE = 'Float64';\nconst OBJECT_ID_TYPE = 'Oid32';\n/*\n * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.\n * _BATCHID - Default attribute name which includes batch info.\n * BATCHID - Legacy attribute name which includes batch info.\n */\nconst BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];\n\nlet scratchVector = new Vector3();\n\n/**\n * Convert binary data from b3dm file to i3s resources\n *\n * @param tileContent - 3d tile content\n * @param nodeId - target nodeId. If a few nodes will be created - ids will be nodeId+n where n - index in the resulting array\n * @param featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes\n * @param attributeStorageInfo - attributes metadata from 3DSceneLayer json\n * @param draco - is converter should create draco compressed geometry\n * @param generateBoundingVolumes - is converter should create accurate bounding voulmes from geometry attributes\n * @param geoidHeightModel - model to convert elevation from elipsoidal to geoid\n * @returns Array of node resources to create one or more i3s nodes\n */\nexport default async function convertB3dmToI3sGeometry(\n tileContent: B3DMContent,\n nodeId: number,\n featuresHashArray: string[],\n attributeStorageInfo: AttributeStorageInfo[] | undefined,\n draco: boolean,\n generateBoundingVolumes: boolean,\n geoidHeightModel: Geoid,\n workerSource: {[key: string]: string}\n) {\n const useCartesianPositions = generateBoundingVolumes;\n const materialAndTextureList: I3SMaterialWithTexture[] = convertMaterials(\n tileContent.gltf?.materials\n );\n\n const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent);\n\n const convertedAttributesMap: Map<string, ConvertedAttributes> = await convertAttributes(\n dataForAttributesConversion,\n useCartesianPositions\n );\n // TODO uncomment it when worker will be published on CDN.\n /*\n const convertedAttributesMap: Map<string, ConvertedAttributes> =\n await transformI3SAttributesOnWorker(dataForAttributesConversion, {\n useCartesianPositions,\n source: workerSource.I3SAttributes\n });\n */\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: I3SConvertedResources[] = [];\n let nodesCounter = nodeId;\n let {materials = []} = tileContent.gltf || {materials: []};\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 if (!convertedAttributes) {\n continue;\n }\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 workerSource\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 - geometry attributes map\n * @param geoidHeightModel - geoid height model to convert elevation from elipsoidal to geoid\n */\nfunction _generateBoundingVolumesFromGeometry(\n convertedAttributesMap: Map<string, ConvertedAttributes>,\n geoidHeightModel: Geoid\n) {\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\n/**\n *\n * @param params\n * @param params.convertedAttributes - Converted geometry attributes\n * @param params.material - I3S PBR-like material definition\n * @param params.texture - texture content\n * @param params.tileContent - B3DM decoded content\n * @param params.nodeId - new node ID\n * @param params.featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes\n * @param params.attributesStorageInfo - attributes metadata from 3DSceneLayer json\n * @param params.draco - is converter should create draco compressed geometry\n * @returns Array of I3S node resources\n */\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco,\n workerSource\n}: {\n convertedAttributes: ConvertedAttributes;\n material: I3SMaterialDefinition;\n texture?: {};\n tileContent: B3DMContent;\n nodeId: number;\n featuresHashArray: string[];\n attributeStorageInfo?: AttributeStorageInfo[];\n draco: boolean;\n workerSource: {[key: string]: string};\n}): Promise<I3SConvertedResources> {\n const boundingVolumes = convertedAttributes.boundingVolumes;\n const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;\n const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =\n generateAttributes(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 ? generateCompressedGeometry(\n vertexCount,\n convertedAttributes,\n {\n positions,\n normals,\n texCoords: texture ? texCoords : new Float32Array(0),\n colors,\n featureIds,\n faceRange\n },\n workerSource.draco\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.gltf?.materials || [], 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 tileContent - 3d tile content\n * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.\n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @returns map of converted geometry attributes\n */\nexport async function convertAttributes(\n attributesData: B3DMAttributesData,\n useCartesianPositions: boolean\n): Promise<Map<string, ConvertedAttributes>> {\n const {gltfMaterials, nodes, cartographicOrigin, cartesianModelMatrix} = attributesData;\n const attributesMap = new Map<string, ConvertedAttributes>();\n\n for (const material of gltfMaterials || [{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 featureIndicesGroups: [],\n featureIndices: [],\n boundingVolumes: null\n });\n }\n\n convertNodes(\n nodes,\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions\n );\n\n for (const attrKey of attributesMap.keys()) {\n const attributes = attributesMap.get(attrKey);\n if (!attributes) {\n continue;\n }\n if (attributes.positions.length === 0) {\n attributesMap.delete(attrKey);\n continue; // eslint-disable-line no-continue\n }\n if (attributes.featureIndicesGroups) {\n attributes.featureIndices = attributes.featureIndicesGroups.reduce((acc, value) =>\n acc.concat(value)\n );\n delete attributes.featureIndicesGroups;\n }\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 nodes - gltf nodes array\n * @param tileContent - 3d tile content\n * @param attributesMap - for recursive concatenation of attributes\n * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.\n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @param matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns {void}\n */\nfunction convertNodes(\n nodes: GLTFNodePostprocessed[],\n cartographicOrigin: Vector3,\n cartesianModelMatrix: Matrix4,\n attributesMap: Map<string, ConvertedAttributes>,\n useCartesianPositions: boolean,\n matrix: Matrix4 = 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(\n node,\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions,\n matrix\n );\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 (translation) {\n transformationMatrix = transformationMatrix.translate(translation);\n }\n\n if (rotation) {\n transformationMatrix = transformationMatrix.rotateXYZ(rotation);\n }\n\n if (scale) {\n transformationMatrix = transformationMatrix.scale(scale);\n }\n\n return transformationMatrix;\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param 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 useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.\n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n */\nfunction convertNode(\n node: GLTFNodePostprocessed,\n cartographicOrigin: Vector3,\n cartesianModelMatrix: Matrix4,\n attributesMap: Map<string, ConvertedAttributes>,\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(\n mesh,\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions,\n transformationMatrix\n );\n }\n\n convertNodes(\n node.children || [],\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions,\n transformationMatrix\n );\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param mesh - gltf node\n * @param content - 3d tile content\n * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets. \n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @param attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n \n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n */\nfunction convertMesh(\n mesh: GLTFMeshPostprocessed,\n cartographicOrigin: Vector3,\n cartesianModelMatrix: Matrix4,\n attributesMap: Map<string, ConvertedAttributes>,\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: ConvertedAttributes | null | undefined = 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 if (!outputAttributes) {\n continue;\n }\n outputAttributes.positions = concatenateTypedArrays(\n outputAttributes.positions,\n transformVertexArray({\n vertices: attributes.POSITION.value,\n cartographicOrigin,\n 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,\n 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.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];\n outputAttributes.featureIndicesGroups.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 args\n * @param args.vertices - gltf primitive POSITION or NORMAL attribute\n * @param args.cartographicOrigin - cartographic origin coordinates\n * @param args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param args.indices - gltf primitive indices\n * @param args.attributeSpecificTransformation - function to do attribute - specific transformations\n * @param args.useCartesianPositions - use coordinates as it is.\n * @returns {Float32Array}\n */\nfunction transformVertexArray(args: {\n vertices: Float32Array;\n cartographicOrigin: number[];\n cartesianModelMatrix: number[];\n nodeMatrix: Matrix4;\n indices: Uint8Array;\n attributeSpecificTransformation: Function;\n useCartesianPositions: boolean;\n}) {\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\n/**\n * Trasform positions vector with the attribute specific transformations\n * @param vertexVector - source positions vector to transform\n * @param calleeArgs\n * @param calleeArgs.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param calleeArgs.cartographicOrigin - cartographic origin coordinates\n * @param calleeArgs.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param calleeArgs.useCartesianPositions - use coordinates as it is.\n * @returns transformed positions vector\n */\nfunction transformVertexPositions(vertexVector, calleeArgs): number[] {\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\n/**\n * Trasform normals vector with the attribute specific transformations\n * @param vertexVector - source normals vector to transform\n * @param calleeArgs\n * @param calleeArgs.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param calleeArgs.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns transformed normals vector\n */\nfunction transformVertexNormals(vertexVector, calleeArgs): number[] {\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 texCoords - gltf primitive TEXCOORD_0 attribute\n * @param indices - gltf primitive indices\n * @returns flattened texture coordinates\n */\nfunction flattenTexCoords(texCoords: Float32Array, indices: Uint8Array): Float32Array {\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 colorsAttribute - gltf primitive COLOR_0 attribute\n * @param indices - gltf primitive indices\n * @returns flattened colors attribute\n */\nfunction flattenColors(\n colorsAttribute: GLTFAccessorPostprocessed,\n indices: Uint8Array\n): Uint8Array {\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 batchedIds - gltf primitive\n * @param indices - gltf primitive indices\n * @returns flattened batch ids\n */\nfunction flattenBatchIds(batchedIds: number[], indices: Uint8Array): number[] {\n if (!batchedIds.length || !indices.length) {\n return [];\n }\n const newBatchIds: number[] = [];\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/**\n * Return batchIds based on possible attribute names for different kind of maps.\n * @param attributes - the gltf primitive attributes\n * @returns batch ids attribute\n */\nfunction getBatchIdsByAttributeName(attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n}): number[] {\n let batchIds: number[] = [];\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\n/**\n * Convert GLTF material to I3S material definitions and textures\n * @param sourceMaterials Source GLTF materials\n * @returns Array of Couples I3SMaterialDefinition + texture content\n */\nfunction convertMaterials(\n sourceMaterials: GLTFMaterialPostprocessed[] = []\n): I3SMaterialWithTexture[] {\n const result: I3SMaterialWithTexture[] = [];\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 sourceMaterial - material object\n * @returns I3S material definition and texture\n */\nfunction convertMaterial(sourceMaterial: GLTFMaterialPostprocessed): I3SMaterialWithTexture {\n const material: I3SMaterialDefinition = {\n doubleSided: sourceMaterial.doubleSided,\n emissiveFactor: sourceMaterial.emissiveFactor?.map((c) => Math.round(c * 255)) as [\n number,\n number,\n number\n ],\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: convertAlphaMode(sourceMaterial.alphaMode),\n pbrMetallicRoughness: {\n roughnessFactor:\n sourceMaterial?.pbrMetallicRoughness?.roughnessFactor || DEFAULT_ROUGHNESS_FACTOR,\n metallicFactor:\n sourceMaterial?.pbrMetallicRoughness?.metallicFactor || DEFAULT_METALLIC_FACTOR\n }\n };\n\n let texture;\n if (sourceMaterial?.pbrMetallicRoughness?.baseColorTexture) {\n texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n } else if (sourceMaterial.emissiveTexture) {\n texture = sourceMaterial.emissiveTexture.texture.source;\n // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n }\n\n if (!texture) {\n // Should use default baseColorFactor if it is not present in source material\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness\n const baseColorFactor = sourceMaterial?.pbrMetallicRoughness?.baseColorFactor;\n material.pbrMetallicRoughness.baseColorFactor =\n ((baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) as [\n number,\n number,\n number,\n number\n ]) || undefined;\n }\n\n return {material, texture};\n}\n\n/**\n * Converts from `alphaMode` material property from GLTF to I3S format\n * @param gltfAlphaMode Gltf material `alphaMode` property\n * @returns I3SMaterialDefinition.alphaMode property\n */\nfunction convertAlphaMode(\n gltfAlphaMode?: 'OPAQUE' | 'MASK' | 'BLEND' | string\n): 'opaque' | 'mask' | 'blend' {\n switch (gltfAlphaMode) {\n case 'OPAQUE':\n return 'opaque';\n case 'MASK':\n return 'mask';\n case 'BLEND':\n return 'blend';\n default:\n return 'opaque';\n }\n}\n\n/**\n * Form default I3SMaterialDefinition\n * @returns I3S material definition\n */\nfunction getDefaultMaterial(): I3SMaterialDefinition {\n return {\n alphaMode: 'opaque',\n pbrMetallicRoughness: {\n metallicFactor: 1,\n roughnessFactor: 1\n }\n };\n}\n\n/**\n * Form \"sharedResources\" from gltf materials array\n * @param gltfMaterials - GLTF materials array\n * @param nodeId - I3S node ID\n * @returns {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(\n gltfMaterials: GLTFMaterialPostprocessed[],\n nodeId: number\n): SharedResourcesArrays {\n const i3sResources: SharedResourcesArrays = {};\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 gltfMaterial - gltf material data\n * @param nodeId - I3S node ID\n * @returns - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data\n */\nfunction convertGLTFMaterialToI3sSharedResources(\n gltfMaterial: GLTFMaterialPostprocessed,\n nodeId: number\n): {\n materialDefinitionInfo: MaterialDefinitionInfo;\n textureDefinitionInfo: TextureDefinitionInfo | null;\n} {\n const texture =\n gltfMaterial?.pbrMetallicRoughness?.baseColorTexture || gltfMaterial.emissiveTexture;\n let textureDefinitionInfo: TextureDefinitionInfo | null = 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(\n colorFactor || [1, 1, 1, 1],\n metallicFactor\n ),\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 baseColorFactor - RGBA color in 0..1 format\n * @param metallicFactor - \"metallicFactor\" attribute of gltf material object\n * @returns material definition info for I3S shared resource\n */\nfunction extractSharedResourcesMaterialInfo(\n baseColorFactor: number[],\n metallicFactor: number = 1\n): MaterialDefinitionInfo {\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 params: {\n diffuse: diffuse.toArray(),\n specular: specular.toArray(),\n renderMode: 'solid'\n }\n };\n}\n\n/**\n * Form \"textureDefinition\" which is part of \"sharedResouces\"\n * @param texture - texture image info\n * @param nodeId - I3S node ID\n * @returns texture definition infor for shared resource\n */\nfunction extractSharedResourcesTextureInfo(\n texture: GLTFTexturePostprocessed,\n nodeId: number\n): TextureDefinitionInfo {\n return {\n encoding: texture?.source?.mimeType ? [texture.source.mimeType] : undefined,\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/**\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 texture - texture image info\n * @param nodeId - I3S node ID\n * @returns calculate image ID according to the spec\n */\nfunction generateImageId(texture: GLTFTexturePostprocessed, 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 featureIds\n * @param featureIndices\n * @param featuresHashArray\n * @param batchTable\n * @returns {void}\n */\nfunction makeFeatureIdsUnique(\n featureIds: number[],\n featureIndices: number[],\n featuresHashArray: string[],\n batchTable: {[key: string]: any}\n) {\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: ArrayBuffer[] = [];\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: ArrayBuffer | null = 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 if (attributeBuffer) {\n attributeBuffers.push(attributeBuffer);\n }\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): ArrayBuffer {\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): ArrayBuffer {\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): ArrayBuffer {\n const stringCountArray = new Uint32Array([batchAttributes.length]);\n let totalNumberOfBytes = 0;\n const stringSizesArray = new Uint32Array(batchAttributes.length);\n const stringBufferArray: ArrayBuffer[] = [];\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 - get rid of this argument here\n * @param {Object} attributes - geometry attributes to compress\n * @param {string} dracoWorkerSoure - draco worker source code\n * @returns {Promise<object>} - COmpressed geometry.\n */\nasync function generateCompressedGeometry(\n vertexCount,\n convertedAttributes,\n attributes,\n dracoWorkerSoure\n) {\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: TypedArray;\n normals: TypedArray;\n colors: TypedArray;\n 'feature-index': TypedArray;\n texCoords?: TypedArray;\n } = {\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 encode({attributes: compressedAttributes, indices}, DracoWriterWorker, {\n ...DracoWriterWorker.options,\n source: dracoWorkerSoure,\n reuseWorkers: true,\n _nodeWorkers: true,\n draco: {\n method: 'MESH_SEQUENTIAL_ENCODING',\n attributesMetadata\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.ts"],"names":["Vector3","Matrix4","Vector4","Ellipsoid","DracoWriterWorker","assert","encode","concatenateArrayBuffers","concatenateTypedArrays","md5","generateAttributes","createBoundingVolumesFromGeometry","prepareDataForAttributesConversion","handleBatchIdsExtensions","checkPropertiesLength","flattenPropertyTableByFeatureIds","DEFAULT_ROUGHNESS_FACTOR","DEFAULT_METALLIC_FACTOR","VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","EXT_FEATURE_METADATA","EXT_MESH_FEATURES","scratchVector","convertB3dmToI3sGeometry","tileContent","nodeId","propertyTable","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","workerSource","useCartesianPositions","materialAndTextureList","convertMaterials","gltf","materials","dataForAttributesConversion","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","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","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","fileBuffer","Uint8Array","buffer","ArrayBuffer","compressedGeometry","generateCompressedGeometry","Float32Array","convertPropertyTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesData","gltfMaterials","nodes","cartesianModelMatrix","attributesMap","Map","featureIndicesGroups","convertNodes","attrKey","keys","delete","reduce","acc","value","concat","matrix","node","convertNode","getCompositeTransformationMatrix","transformationMatrix","nodeMatrix","rotation","scale","translation","multiplyRight","translate","rotateXYZ","mesh","images","convertMesh","children","primitive","primitives","outputAttributes","transformVertexArray","vertices","POSITION","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIds","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","convertAlphaMode","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfAlphaMode","i3sResources","materialDefinitionInfos","gltfMaterial","materialDefinitionInfo","textureDefinitionInfo","convertGLTFMaterialToI3sSharedResources","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","params","toArray","renderMode","encoding","mimeType","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","needFlattenPropertyTable","properties","propertyTableWithObjectIds","OBJECTID","propertyName","type","getAttributeType","attributeBuffer","generateAttributeBuffer","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","dracoWorkerSoure","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","options","reuseWorkers","_nodeWorkers","method","orderedFeatureIndices","fillIndex","startIndex","endIndex","getPropertyTable","sourceTile","content","extensionName","extension","getPropertyTableExtension","console","warn","getPropertyTableFromExtFeatureMetadata","extensionsWithPropertyTables","extensionsUsed","extensionItem","extensions","featureTextures","featureTables","firstFeatureTableName","Object","featureTable"],"mappings":"AAIA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,OAA1B,QAAwC,eAAxC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAEA,SAAQC,iBAAR,QAAgC,mBAAhC;AACA,SAAQC,MAAR,EAAgBC,MAAhB,QAA6B,kBAA7B;AAEA,SAAQC,uBAAR,EAAiCC,sBAAjC,QAA8D,0BAA9D;AACA,OAAOC,GAAP,MAAgB,KAAhB;AACA,SAAQC,kBAAR,QAAiC,uBAAjC;AACA,SAAQC,iCAAR,QAAgD,wBAAhD;AAsBA,SAAQC,kCAAR,QAAiD,mBAAjD;AACA,SAAQC,wBAAR,QAAuC,wBAAvC;AACA,SAAQC,qBAAR,EAA+BC,gCAA/B,QAAsE,sBAAtE;AAGA,MAAMC,wBAAwB,GAAG,CAAjC;AACA,MAAMC,uBAAuB,GAAG,CAAhC;AAEA,MAAMC,iB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GA,SAAS,CAAEU,aAAX,CAAyBC,qBAAzB,CAArB;AACA,YAAMlS,aAAa,GAAG,EAAtB;;AAEA,WAAK,MAAMuO,YAAX,IAA2B6D,YAAY,CAAChE,UAAxC,EAAoD;AAClDpO,QAAAA,aAAa,CAACuO,YAAD,CAAb,GAA8B6D,YAAY,CAAChE,UAAb,CAAwBG,YAAxB,EAAsCrC,IAApE;AACD;;AAED,aAAOlM,aAAP;AACD;AACF;;AAEDyR,EAAAA,OAAO,CAACC,IAAR,CAAa,kEAAb;AACA,SAAO,IAAP;AACD","sourcesContent":["import type {Image, MeshPrimitive} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';\nimport type {B3DMContent, FeatureTableJson} from '@loaders.gl/3d-tiles';\nimport type {GLTF_EXT_feature_metadata} from '@loaders.gl/gltf';\n\nimport {Vector3, Matrix4, Vector4} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nimport {DracoWriterWorker} from '@loaders.gl/draco';\nimport {assert, encode} from '@loaders.gl/core';\nimport {Tile3D} from '@loaders.gl/tiles';\nimport {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';\nimport md5 from 'md5';\nimport {generateAttributes} from './geometry-attributes';\nimport {createBoundingVolumesFromGeometry} from './coordinate-converter';\nimport {\n ConvertedAttributes,\n I3SConvertedResources,\n I3SMaterialWithTexture,\n SharedResourcesArrays\n} from '../types';\nimport {GLTFMaterialPostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';\nimport {\n AttributeStorageInfo,\n I3SMaterialDefinition,\n MaterialDefinitionInfo,\n TextureDefinitionInfo\n} from '@loaders.gl/i3s';\nimport {TypedArray} from '@loaders.gl/schema';\nimport {Geoid} from '@math.gl/geoid';\nimport {\n GLTFAccessorPostprocessed,\n GLTFMeshPostprocessed,\n GLTFTexturePostprocessed\n} from 'modules/gltf/src/lib/types/gltf-types';\nimport {B3DMAttributesData /*transformI3SAttributesOnWorker */} from '../../i3s-attributes-worker';\nimport {prepareDataForAttributesConversion} from './gltf-attributes';\nimport {handleBatchIdsExtensions} from './batch-ids-extensions';\nimport {checkPropertiesLength, flattenPropertyTableByFeatureIds} from './feature-attributes';\n\n// Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md\nconst DEFAULT_ROUGHNESS_FACTOR = 1;\nconst DEFAULT_METALLIC_FACTOR = 1;\n\nconst VALUES_PER_VERTEX = 3;\nconst VALUES_PER_TEX_COORD = 2;\nconst VALUES_PER_COLOR_ELEMENT = 4;\n\nconst STRING_TYPE = 'string';\nconst SHORT_INT_TYPE = 'Int32';\nconst DOUBLE_TYPE = 'Float64';\nconst OBJECT_ID_TYPE = 'Oid32';\n/*\n * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.\n * _BATCHID - Default attribute name which includes batch info.\n * BATCHID - Legacy attribute name which includes batch info.\n */\nconst BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];\n\nconst EXT_FEATURE_METADATA = 'EXT_feature_metadata';\nconst EXT_MESH_FEATURES = 'EXT_mesh_features';\n\nlet scratchVector = new Vector3();\n\n/**\n * Convert binary data from b3dm file to i3s resources\n *\n * @param tileContent - 3d tile content\n * @param nodeId - target nodeId. If a few nodes will be created - ids will be nodeId+n where n - index in the resulting array\n * @param featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes\n * @param attributeStorageInfo - attributes metadata from 3DSceneLayer json\n * @param draco - is converter should create draco compressed geometry\n * @param generateBoundingVolumes - is converter should create accurate bounding voulmes from geometry attributes\n * @param geoidHeightModel - model to convert elevation from elipsoidal to geoid\n * @returns Array of node resources to create one or more i3s nodes\n */\nexport default async function convertB3dmToI3sGeometry(\n tileContent: B3DMContent,\n nodeId: number,\n propertyTable: FeatureTableJson | null,\n featuresHashArray: string[],\n attributeStorageInfo: AttributeStorageInfo[] | undefined,\n draco: boolean,\n generateBoundingVolumes: boolean,\n geoidHeightModel: Geoid,\n workerSource: {[key: string]: string}\n) {\n const useCartesianPositions = generateBoundingVolumes;\n const materialAndTextureList: I3SMaterialWithTexture[] = convertMaterials(\n tileContent.gltf?.materials\n );\n\n const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent);\n\n const convertedAttributesMap: Map<string, ConvertedAttributes> = await convertAttributes(\n dataForAttributesConversion,\n useCartesianPositions\n );\n // TODO uncomment it when worker will be published on CDN.\n /*\n const convertedAttributesMap: Map<string, ConvertedAttributes> =\n await transformI3SAttributesOnWorker(dataForAttributesConversion, {\n useCartesianPositions,\n source: workerSource.I3SAttributes\n });\n */\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: I3SConvertedResources[] = [];\n let nodesCounter = nodeId;\n let {materials = []} = tileContent.gltf || {materials: []};\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 if (!convertedAttributes) {\n continue;\n }\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 propertyTable,\n attributeStorageInfo,\n draco,\n workerSource\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 - geometry attributes map\n * @param geoidHeightModel - geoid height model to convert elevation from elipsoidal to geoid\n */\nfunction _generateBoundingVolumesFromGeometry(\n convertedAttributesMap: Map<string, ConvertedAttributes>,\n geoidHeightModel: Geoid\n) {\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\n/**\n *\n * @param params\n * @param params.convertedAttributes - Converted geometry attributes\n * @param params.material - I3S PBR-like material definition\n * @param params.texture - texture content\n * @param params.tileContent - B3DM decoded content\n * @param params.nodeId - new node ID\n * @param params.featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes\n * @param params.attributesStorageInfo - attributes metadata from 3DSceneLayer json\n * @param params.draco - is converter should create draco compressed geometry\n * @returns Array of I3S node resources\n */\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n propertyTable,\n attributeStorageInfo,\n draco,\n workerSource\n}: {\n convertedAttributes: ConvertedAttributes;\n material: I3SMaterialDefinition;\n texture?: {};\n tileContent: B3DMContent;\n nodeId: number;\n featuresHashArray: string[];\n propertyTable: FeatureTableJson | null;\n attributeStorageInfo?: AttributeStorageInfo[];\n draco: boolean;\n workerSource: {[key: string]: string};\n}): Promise<I3SConvertedResources> {\n const boundingVolumes = convertedAttributes.boundingVolumes;\n const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;\n const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =\n generateAttributes(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 ? generateCompressedGeometry(\n vertexCount,\n convertedAttributes,\n {\n positions,\n normals,\n texCoords: texture ? texCoords : new Float32Array(0),\n colors,\n featureIds,\n faceRange\n },\n workerSource.draco\n )\n : null;\n\n let attributes: ArrayBuffer[] = [];\n\n if (attributeStorageInfo && propertyTable) {\n attributes = convertPropertyTableToAttributeBuffers(\n featureIds,\n propertyTable,\n attributeStorageInfo\n );\n }\n\n return {\n geometry: fileBuffer,\n compressedGeometry,\n texture,\n sharedResources: getSharedResources(tileContent.gltf?.materials || [], 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 tileContent - 3d tile content\n * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.\n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @returns map of converted geometry attributes\n */\nexport async function convertAttributes(\n attributesData: B3DMAttributesData,\n useCartesianPositions: boolean\n): Promise<Map<string, ConvertedAttributes>> {\n const {gltfMaterials, nodes, cartographicOrigin, cartesianModelMatrix} = attributesData;\n const attributesMap = new Map<string, ConvertedAttributes>();\n\n for (const material of gltfMaterials || [{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 featureIndicesGroups: [],\n featureIndices: [],\n boundingVolumes: null\n });\n }\n\n convertNodes(\n nodes,\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions\n );\n\n for (const attrKey of attributesMap.keys()) {\n const attributes = attributesMap.get(attrKey);\n if (!attributes) {\n continue;\n }\n if (attributes.positions.length === 0) {\n attributesMap.delete(attrKey);\n continue; // eslint-disable-line no-continue\n }\n if (attributes.featureIndicesGroups) {\n attributes.featureIndices = attributes.featureIndicesGroups.reduce((acc, value) =>\n acc.concat(value)\n );\n delete attributes.featureIndicesGroups;\n }\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 nodes - gltf nodes array\n * @param tileContent - 3d tile content\n * @param attributesMap - for recursive concatenation of attributes\n * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.\n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @param matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns {void}\n */\nfunction convertNodes(\n nodes: GLTFNodePostprocessed[],\n cartographicOrigin: Vector3,\n cartesianModelMatrix: Matrix4,\n attributesMap: Map<string, ConvertedAttributes>,\n useCartesianPositions: boolean,\n matrix: Matrix4 = 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(\n node,\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions,\n matrix\n );\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 (translation) {\n transformationMatrix = transformationMatrix.translate(translation);\n }\n\n if (rotation) {\n transformationMatrix = transformationMatrix.rotateXYZ(rotation);\n }\n\n if (scale) {\n transformationMatrix = transformationMatrix.scale(scale);\n }\n\n return transformationMatrix;\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param 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 useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.\n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n */\nfunction convertNode(\n node: GLTFNodePostprocessed,\n cartographicOrigin: Vector3,\n cartesianModelMatrix: Matrix4,\n attributesMap: Map<string, ConvertedAttributes>,\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 const images = node.images;\n\n if (mesh) {\n convertMesh(\n mesh,\n images,\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions,\n transformationMatrix\n );\n }\n\n convertNodes(\n node.children || [],\n cartographicOrigin,\n cartesianModelMatrix,\n attributesMap,\n useCartesianPositions,\n transformationMatrix\n );\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param mesh - gltf node\n * @param content - 3d tile content\n * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets. \n * Cartesian coordinates will be required for creating bounding voulmest from geometry positions\n * @param attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n \n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n */\nfunction convertMesh(\n mesh: GLTFMeshPostprocessed,\n images: Image[],\n cartographicOrigin: Vector3,\n cartesianModelMatrix: Matrix4,\n attributesMap: Map<string, ConvertedAttributes>,\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: ConvertedAttributes | null | undefined = 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 if (!outputAttributes) {\n continue;\n }\n outputAttributes.positions = concatenateTypedArrays(\n outputAttributes.positions,\n transformVertexArray({\n vertices: attributes.POSITION.value,\n cartographicOrigin,\n 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,\n 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.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];\n outputAttributes.featureIndicesGroups.push(\n flattenBatchIds(getBatchIds(attributes, primitive, images), primitive.indices?.value)\n );\n }\n}\n\n/**\n * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format\n * @param args\n * @param args.vertices - gltf primitive POSITION or NORMAL attribute\n * @param args.cartographicOrigin - cartographic origin coordinates\n * @param args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param args.indices - gltf primitive indices\n * @param args.attributeSpecificTransformation - function to do attribute - specific transformations\n * @param args.useCartesianPositions - use coordinates as it is.\n * @returns {Float32Array}\n */\nfunction transformVertexArray(args: {\n vertices: Float32Array;\n cartographicOrigin: number[];\n cartesianModelMatrix: number[];\n nodeMatrix: Matrix4;\n indices: Uint8Array;\n attributeSpecificTransformation: Function;\n useCartesianPositions: boolean;\n}) {\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\n/**\n * Trasform positions vector with the attribute specific transformations\n * @param vertexVector - source positions vector to transform\n * @param calleeArgs\n * @param calleeArgs.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param calleeArgs.cartographicOrigin - cartographic origin coordinates\n * @param calleeArgs.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param calleeArgs.useCartesianPositions - use coordinates as it is.\n * @returns transformed positions vector\n */\nfunction transformVertexPositions(vertexVector, calleeArgs): number[] {\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\n/**\n * Trasform normals vector with the attribute specific transformations\n * @param vertexVector - source normals vector to transform\n * @param calleeArgs\n * @param calleeArgs.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param calleeArgs.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns transformed normals vector\n */\nfunction transformVertexNormals(vertexVector, calleeArgs): number[] {\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 texCoords - gltf primitive TEXCOORD_0 attribute\n * @param indices - gltf primitive indices\n * @returns flattened texture coordinates\n */\nfunction flattenTexCoords(texCoords: Float32Array, indices: Uint8Array): Float32Array {\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 colorsAttribute - gltf primitive COLOR_0 attribute\n * @param indices - gltf primitive indices\n * @returns flattened colors attribute\n */\nfunction flattenColors(\n colorsAttribute: GLTFAccessorPostprocessed,\n indices: Uint8Array\n): Uint8Array {\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 batchedIds - gltf primitive\n * @param indices - gltf primitive indices\n * @returns flattened batch ids\n */\nfunction flattenBatchIds(batchedIds: number[], indices: Uint8Array): number[] {\n if (!batchedIds.length || !indices.length) {\n return [];\n }\n const newBatchIds: number[] = [];\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/**\n * Get batchIds for featureIds creation\n * @param attributes\n * @param primitive\n * @param textures\n */\nfunction getBatchIds(\n attributes: {\n [key: string]: GLTFAccessorPostprocessed;\n },\n primitive: MeshPrimitive,\n images: Image[]\n): number[] {\n const batchIds: number[] = handleBatchIdsExtensions(attributes, primitive, images);\n\n if (batchIds.length) {\n return batchIds;\n }\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 return attributes[possibleBatchIdAttributeName].value;\n }\n }\n\n return [];\n}\n\n/**\n * Convert GLTF material to I3S material definitions and textures\n * @param sourceMaterials Source GLTF materials\n * @returns Array of Couples I3SMaterialDefinition + texture content\n */\nfunction convertMaterials(\n sourceMaterials: GLTFMaterialPostprocessed[] = []\n): I3SMaterialWithTexture[] {\n const result: I3SMaterialWithTexture[] = [];\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 sourceMaterial - material object\n * @returns I3S material definition and texture\n */\nfunction convertMaterial(sourceMaterial: GLTFMaterialPostprocessed): I3SMaterialWithTexture {\n const material: I3SMaterialDefinition = {\n doubleSided: sourceMaterial.doubleSided,\n emissiveFactor: sourceMaterial.emissiveFactor?.map((c) => Math.round(c * 255)) as [\n number,\n number,\n number\n ],\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: convertAlphaMode(sourceMaterial.alphaMode),\n pbrMetallicRoughness: {\n roughnessFactor:\n sourceMaterial?.pbrMetallicRoughness?.roughnessFactor || DEFAULT_ROUGHNESS_FACTOR,\n metallicFactor:\n sourceMaterial?.pbrMetallicRoughness?.metallicFactor || DEFAULT_METALLIC_FACTOR\n }\n };\n\n let texture;\n if (sourceMaterial?.pbrMetallicRoughness?.baseColorTexture) {\n texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n } else if (sourceMaterial.emissiveTexture) {\n texture = sourceMaterial.emissiveTexture.texture.source;\n // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n }\n\n if (!texture) {\n // Should use default baseColorFactor if it is not present in source material\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness\n const baseColorFactor = sourceMaterial?.pbrMetallicRoughness?.baseColorFactor;\n material.pbrMetallicRoughness.baseColorFactor =\n ((baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) as [\n number,\n number,\n number,\n number\n ]) || undefined;\n }\n\n return {material, texture};\n}\n\n/**\n * Converts from `alphaMode` material property from GLTF to I3S format\n * @param gltfAlphaMode Gltf material `alphaMode` property\n * @returns I3SMaterialDefinition.alphaMode property\n */\nfunction convertAlphaMode(\n gltfAlphaMode?: 'OPAQUE' | 'MASK' | 'BLEND' | string\n): 'opaque' | 'mask' | 'blend' {\n switch (gltfAlphaMode) {\n case 'OPAQUE':\n return 'opaque';\n case 'MASK':\n return 'mask';\n case 'BLEND':\n return 'blend';\n default:\n return 'opaque';\n }\n}\n\n/**\n * Form default I3SMaterialDefinition\n * @returns I3S material definition\n */\nfunction getDefaultMaterial(): I3SMaterialDefinition {\n return {\n alphaMode: 'opaque',\n pbrMetallicRoughness: {\n metallicFactor: 1,\n roughnessFactor: 1\n }\n };\n}\n\n/**\n * Form \"sharedResources\" from gltf materials array\n * @param gltfMaterials - GLTF materials array\n * @param nodeId - I3S node ID\n * @returns {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(\n gltfMaterials: GLTFMaterialPostprocessed[],\n nodeId: number\n): SharedResourcesArrays {\n const i3sResources: SharedResourcesArrays = {};\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 gltfMaterial - gltf material data\n * @param nodeId - I3S node ID\n * @returns - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data\n */\nfunction convertGLTFMaterialToI3sSharedResources(\n gltfMaterial: GLTFMaterialPostprocessed,\n nodeId: number\n): {\n materialDefinitionInfo: MaterialDefinitionInfo;\n textureDefinitionInfo: TextureDefinitionInfo | null;\n} {\n const texture =\n gltfMaterial?.pbrMetallicRoughness?.baseColorTexture || gltfMaterial.emissiveTexture;\n let textureDefinitionInfo: TextureDefinitionInfo | null = 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(\n colorFactor || [1, 1, 1, 1],\n metallicFactor\n ),\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 baseColorFactor - RGBA color in 0..1 format\n * @param metallicFactor - \"metallicFactor\" attribute of gltf material object\n * @returns material definition info for I3S shared resource\n */\nfunction extractSharedResourcesMaterialInfo(\n baseColorFactor: number[],\n metallicFactor: number = 1\n): MaterialDefinitionInfo {\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 params: {\n diffuse: diffuse.toArray(),\n specular: specular.toArray(),\n renderMode: 'solid'\n }\n };\n}\n\n/**\n * Form \"textureDefinition\" which is part of \"sharedResouces\"\n * @param texture - texture image info\n * @param nodeId - I3S node ID\n * @returns texture definition infor for shared resource\n */\nfunction extractSharedResourcesTextureInfo(\n texture: GLTFTexturePostprocessed,\n nodeId: number\n): TextureDefinitionInfo {\n return {\n encoding: texture?.source?.mimeType ? [texture.source.mimeType] : undefined,\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/**\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 texture - texture image info\n * @param nodeId - I3S node ID\n * @returns calculate image ID according to the spec\n */\nfunction generateImageId(texture: GLTFTexturePostprocessed, 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 featureIds\n * @param featureIndices\n * @param featuresHashArray\n * @param batchTable\n * @returns {void}\n */\nfunction makeFeatureIdsUnique(\n featureIds: number[],\n featureIndices: number[],\n featuresHashArray: string[],\n batchTable: {[key: string]: any}\n) {\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 property table data to attribute buffers.\n * @param {Object} propertyTable - table with metadata for particular feature.\n * @param {Array} featureIds\n * @param {Array} attributeStorageInfo\n * @returns {Array} - Array of file buffers.\n */\nfunction convertPropertyTableToAttributeBuffers(\n featureIds: number[],\n propertyTable: FeatureTableJson,\n attributeStorageInfo: AttributeStorageInfo[]\n) {\n const attributeBuffers: ArrayBuffer[] = [];\n\n const needFlattenPropertyTable = checkPropertiesLength(featureIds, propertyTable);\n const properties = needFlattenPropertyTable\n ? flattenPropertyTableByFeatureIds(featureIds, propertyTable)\n : propertyTable;\n\n const propertyTableWithObjectIds = {\n OBJECTID: featureIds,\n ...properties\n };\n\n for (const propertyName in propertyTableWithObjectIds) {\n const type = getAttributeType(propertyName, attributeStorageInfo);\n const value = propertyTableWithObjectIds[propertyName];\n const attributeBuffer = generateAttributeBuffer(type, value);\n\n attributeBuffers.push(attributeBuffer);\n }\n\n return attributeBuffers;\n}\n\n/**\n * Generates attribute buffer based on attribute type\n * @param type\n * @param value\n */\nfunction generateAttributeBuffer(type: string, value: any): ArrayBuffer {\n let attributeBuffer: ArrayBuffer;\n\n switch (type) {\n case OBJECT_ID_TYPE:\n case SHORT_INT_TYPE:\n attributeBuffer = generateShortIntegerAttributeBuffer(value);\n break;\n case DOUBLE_TYPE:\n attributeBuffer = generateDoubleAttributeBuffer(value);\n break;\n case STRING_TYPE:\n attributeBuffer = generateStringAttributeBuffer(value);\n break;\n default:\n attributeBuffer = generateStringAttributeBuffer(value);\n }\n\n return attributeBuffer;\n}\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): ArrayBuffer {\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): ArrayBuffer {\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): ArrayBuffer {\n const stringCountArray = new Uint32Array([batchAttributes.length]);\n let totalNumberOfBytes = 0;\n const stringSizesArray = new Uint32Array(batchAttributes.length);\n const stringBufferArray: ArrayBuffer[] = [];\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 - get rid of this argument here\n * @param {Object} attributes - geometry attributes to compress\n * @param {string} dracoWorkerSoure - draco worker source code\n * @returns {Promise<object>} - COmpressed geometry.\n */\nasync function generateCompressedGeometry(\n vertexCount,\n convertedAttributes,\n attributes,\n dracoWorkerSoure\n) {\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: TypedArray;\n normals: TypedArray;\n colors: TypedArray;\n 'feature-index': TypedArray;\n texCoords?: TypedArray;\n } = {\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 encode({attributes: compressedAttributes, indices}, DracoWriterWorker, {\n ...DracoWriterWorker.options,\n source: dracoWorkerSoure,\n reuseWorkers: true,\n _nodeWorkers: true,\n draco: {\n method: 'MESH_SEQUENTIAL_ENCODING',\n attributesMetadata\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\n/**\n * Find property table in tile\n * For example it can be batchTable for b3dm files or property table in gLTF extension.\n * @param sourceTile\n */\nexport function getPropertyTable(sourceTile: Tile3D): FeatureTableJson | null {\n const batchTableJson = sourceTile?.content?.batchTableJson;\n\n if (batchTableJson) {\n return batchTableJson;\n }\n\n const {extensionName, extension} = getPropertyTableExtension(sourceTile);\n\n switch (extensionName) {\n case EXT_MESH_FEATURES: {\n console.warn('The I3S converter does not yet support the EXT_mesh_features extension');\n return null;\n }\n case EXT_FEATURE_METADATA: {\n return getPropertyTableFromExtFeatureMetadata(extension);\n }\n default:\n return null;\n }\n}\n\n/**\n * Check extensions which can be with property table inside.\n * @param sourceTile\n */\nfunction getPropertyTableExtension(sourceTile: Tile3D) {\n const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];\n const extensionsUsed = sourceTile?.content?.gltf?.extensionsUsed;\n\n if (!extensionsUsed) {\n return {extensionName: null, extension: null};\n }\n\n let extensionName: string = '';\n\n for (const extensionItem of sourceTile?.content?.gltf?.extensionsUsed) {\n if (extensionsWithPropertyTables.includes(extensionItem)) {\n extensionName = extensionItem;\n break;\n }\n }\n\n const extension = sourceTile?.content?.gltf?.extensions?.[extensionName];\n\n return {extensionName, extension};\n}\n\n/**\n * Handle EXT_feature_metadata to get property table\n * @param extension\n * TODO add EXT_feature_metadata feature textures support.\n */\nfunction getPropertyTableFromExtFeatureMetadata(\n extension: GLTF_EXT_feature_metadata\n): FeatureTableJson | null {\n if (extension?.featureTextures) {\n console.warn(\n 'The I3S converter does not yet support the EXT_feature_metadata feature textures'\n );\n return null;\n }\n\n if (extension?.featureTables) {\n /**\n * Take only first feature table to generate attributes storage info object.\n * TODO: Think about getting data from all feature tables?\n * It can be tricky just because 3dTiles is able to have multiple featureId attributes and multiple feature tables.\n * In I3S we should decide which featureIds attribute will be passed to geometry data.\n */\n const firstFeatureTableName = Object.keys(extension.featureTables)?.[0];\n\n if (firstFeatureTableName) {\n const featureTable = extension?.featureTables[firstFeatureTableName];\n const propertyTable = {};\n\n for (const propertyName in featureTable.properties) {\n propertyTable[propertyName] = featureTable.properties[propertyName].data;\n }\n\n return propertyTable;\n }\n }\n\n console.warn(\"The I3S converter couldn't handle EXT_feature_metadata extension\");\n return null;\n}\n"],"file":"geometry-converter.js"}
@@ -11,12 +11,25 @@ function getB3DMAttributesWithoutBufferView(attributes) {
11
11
  }
12
12
 
13
13
  export function prepareDataForAttributesConversion(tileContent) {
14
- var _tileContent$gltf, _tileContent$gltf$mat, _tileContent$gltf2, _tileContent$gltf2$sc, _tileContent$gltf3, _tileContent$gltf3$sc, _tileContent$gltf3$sc2, _tileContent$gltf4;
14
+ var _tileContent$gltf, _tileContent$gltf$mat, _tileContent$gltf2, _tileContent$gltf2$sc, _tileContent$gltf3, _tileContent$gltf3$sc, _tileContent$gltf3$sc2, _tileContent$gltf4, _tileContent$gltf5, _tileContent$gltf5$im;
15
15
 
16
16
  const gltfMaterials = (_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : (_tileContent$gltf$mat = _tileContent$gltf.materials) === null || _tileContent$gltf$mat === void 0 ? void 0 : _tileContent$gltf$mat.map(material => ({
17
17
  id: material.id
18
18
  }));
19
19
  let nodes = ((_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : (_tileContent$gltf2$sc = _tileContent$gltf2.scene) === null || _tileContent$gltf2$sc === void 0 ? void 0 : _tileContent$gltf2$sc.nodes) || ((_tileContent$gltf3 = tileContent.gltf) === null || _tileContent$gltf3 === void 0 ? void 0 : (_tileContent$gltf3$sc = _tileContent$gltf3.scenes) === null || _tileContent$gltf3$sc === void 0 ? void 0 : (_tileContent$gltf3$sc2 = _tileContent$gltf3$sc[0]) === null || _tileContent$gltf3$sc2 === void 0 ? void 0 : _tileContent$gltf3$sc2.nodes) || ((_tileContent$gltf4 = tileContent.gltf) === null || _tileContent$gltf4 === void 0 ? void 0 : _tileContent$gltf4.nodes) || [];
20
+ const images = ((_tileContent$gltf5 = tileContent.gltf) === null || _tileContent$gltf5 === void 0 ? void 0 : (_tileContent$gltf5$im = _tileContent$gltf5.images) === null || _tileContent$gltf5$im === void 0 ? void 0 : _tileContent$gltf5$im.map(imageObject => {
21
+ var _imageObject$image, _imageObject$image2, _imageObject$image3;
22
+
23
+ const data = imageObject !== null && imageObject !== void 0 && (_imageObject$image = imageObject.image) !== null && _imageObject$image !== void 0 && _imageObject$image.compressed ? null : imageObject === null || imageObject === void 0 ? void 0 : (_imageObject$image2 = imageObject.image) === null || _imageObject$image2 === void 0 ? void 0 : _imageObject$image2.data.subarray();
24
+ return {
25
+ data,
26
+ compressed: Boolean(imageObject === null || imageObject === void 0 ? void 0 : (_imageObject$image3 = imageObject.image) === null || _imageObject$image3 === void 0 ? void 0 : _imageObject$image3.compressed),
27
+ height: imageObject.image.height,
28
+ width: imageObject.image.width,
29
+ components: imageObject.image.components,
30
+ mimeType: imageObject.mimeType
31
+ };
32
+ })) || [];
20
33
  const prepearedNodes = nodes.map(node => {
21
34
  var _node$mesh;
22
35
 
@@ -25,6 +38,7 @@ export function prepareDataForAttributesConversion(tileContent) {
25
38
  }
26
39
 
27
40
  return { ...node,
41
+ images,
28
42
  mesh: { ...node.mesh,
29
43
  primitives: (_node$mesh = node.mesh) === null || _node$mesh === void 0 ? void 0 : _node$mesh.primitives.map(primitive => {
30
44
  var _primitive$indices, _primitive$material;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/gltf-attributes.ts"],"names":["getB3DMAttributesWithoutBufferView","attributes","attributesWithoutBufferView","attributeName","value","prepareDataForAttributesConversion","tileContent","gltfMaterials","gltf","materials","map","material","id","nodes","scene","scenes","prepearedNodes","node","mesh","primitives","primitive","indices","cartographicOrigin","cartesianModelMatrix"],"mappings":"AAYA,SAASA,kCAAT,CAA4CC,UAA5C,EAA4F;AAC1F,QAAMC,2BAA2B,GAAG,EAApC;;AAEA,OAAK,MAAMC,aAAX,IAA4BF,UAA5B,EAAwC;AACtCC,IAAAA,2BAA2B,CAACC,aAAD,CAA3B,GAA6C;AAC3CC,MAAAA,KAAK,EAAEH,UAAU,CAACE,aAAD,CAAV,CAA0BC;AADU,KAA7C;AAGD;;AAED,SAAOF,2BAAP;AACD;;AAOD,OAAO,SAASG,kCAAT,CAA4CC,WAA5C,EAA0F;AAAA;;AAC/F,QAAMC,aAAa,wBAAGD,WAAW,CAACE,IAAf,+EAAG,kBAAkBC,SAArB,0DAAG,sBAA6BC,GAA7B,CAAkCC,QAAD,KAAe;AAACC,IAAAA,EAAE,EAAED,QAAQ,CAACC;AAAd,GAAf,CAAjC,CAAtB;AACA,MAAIC,KAAK,GACP,uBAAAP,WAAW,CAACE,IAAZ,mGAAkBM,KAAlB,gFAAyBD,KAAzB,4BACAP,WAAW,CAACE,IADZ,gFACA,mBAAkBO,MADlB,oFACA,sBAA2B,CAA3B,CADA,2DACA,uBAA+BF,KAD/B,4BAEAP,WAAW,CAACE,IAFZ,uDAEA,mBAAkBK,KAFlB,KAGA,EAJF;AAMA,QAAMG,cAAc,GAAGH,KAAK,CAACH,GAAN,CAAWO,IAAD,IAAU;AAAA;;AACzC,QAAI,CAACA,IAAI,CAACC,IAAV,EAAgB;AACd,aAAOD,IAAP;AACD;;AAED,WAAO,EACL,GAAGA,IADE;AAELC,MAAAA,IAAI,EAAE,EACJ,GAAGD,IAAI,CAACC,IADJ;AAEJC,QAAAA,UAAU,gBAAEF,IAAI,CAACC,IAAP,+CAAE,WAAWC,UAAX,CAAsBT,GAAtB,CAA2BU,SAAD;AAAA;;AAAA,iBAAgB,EACpD,GAAGA,SADiD;AAEpDC,YAAAA,OAAO,EAAE;AAACjB,cAAAA,KAAK,EAAEgB,SAAF,aAAEA,SAAF,6CAAEA,SAAS,CAAEC,OAAb,uDAAE,mBAAoBjB;AAA5B,aAF2C;AAGpDH,YAAAA,UAAU,EAAED,kCAAkC,CAACoB,SAAS,CAACnB,UAAX,CAHM;AAIpDU,YAAAA,QAAQ,EAAE;AACRC,cAAAA,EAAE,EAAEQ,SAAF,aAAEA,SAAF,8CAAEA,SAAS,CAAET,QAAb,wDAAE,oBAAqBC;AADjB;AAJ0C,WAAhB;AAAA,SAA1B;AAFR;AAFD,KAAP;AAcD,GAnBsB,CAAvB;AAqBA,QAAMU,kBAAkB,GAAGhB,WAAW,CAACgB,kBAAvC;AACA,QAAMC,oBAAoB,GAAGjB,WAAW,CAACiB,oBAAzC;AAEA,SAAO;AACLhB,IAAAA,aADK;AAELM,IAAAA,KAAK,EAAEG,cAFF;AAGLM,IAAAA,kBAHK;AAILC,IAAAA;AAJK,GAAP;AAMD","sourcesContent":["import type {B3DMContent} from '@loaders.gl/3d-tiles';\nimport type {Accessor} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';\nimport type {B3DMAttributesData} from '../../i3s-attributes-worker';\n\ntype AttributesObject = {\n [k: string]: Accessor;\n};\n\n/**\n * Keep only values for B3DM attributes to pass data to worker thread.\n * @param attributes\n */\nfunction getB3DMAttributesWithoutBufferView(attributes: AttributesObject): AttributesObject {\n const attributesWithoutBufferView = {};\n\n for (const attributeName in attributes) {\n attributesWithoutBufferView[attributeName] = {\n value: attributes[attributeName].value\n };\n }\n\n return attributesWithoutBufferView;\n}\n\n/**\n * Prepare attributes for conversion to avoid binary data breaking in worker thread.\n * @param tileContent\n * @returns\n */\nexport function prepareDataForAttributesConversion(tileContent: B3DMContent): B3DMAttributesData {\n const gltfMaterials = tileContent.gltf?.materials?.map((material) => ({id: material.id}));\n let nodes =\n tileContent.gltf?.scene?.nodes ||\n tileContent.gltf?.scenes?.[0]?.nodes ||\n tileContent.gltf?.nodes ||\n [];\n\n const prepearedNodes = nodes.map((node) => {\n if (!node.mesh) {\n return node;\n }\n\n return {\n ...node,\n mesh: {\n ...node.mesh,\n primitives: node.mesh?.primitives.map((primitive) => ({\n ...primitive,\n indices: {value: primitive?.indices?.value},\n attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),\n material: {\n id: primitive?.material?.id\n }\n }))\n }\n };\n });\n\n const cartographicOrigin = tileContent.cartographicOrigin;\n const cartesianModelMatrix = tileContent.cartesianModelMatrix;\n\n return {\n gltfMaterials,\n nodes: prepearedNodes,\n cartographicOrigin,\n cartesianModelMatrix\n };\n}\n"],"file":"gltf-attributes.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/gltf-attributes.ts"],"names":["getB3DMAttributesWithoutBufferView","attributes","attributesWithoutBufferView","attributeName","value","prepareDataForAttributesConversion","tileContent","gltfMaterials","gltf","materials","map","material","id","nodes","scene","scenes","images","imageObject","data","image","compressed","subarray","Boolean","height","width","components","mimeType","prepearedNodes","node","mesh","primitives","primitive","indices","cartographicOrigin","cartesianModelMatrix"],"mappings":"AAYA,SAASA,kCAAT,CAA4CC,UAA5C,EAA4F;AAC1F,QAAMC,2BAA2B,GAAG,EAApC;;AAEA,OAAK,MAAMC,aAAX,IAA4BF,UAA5B,EAAwC;AACtCC,IAAAA,2BAA2B,CAACC,aAAD,CAA3B,GAA6C;AAC3CC,MAAAA,KAAK,EAAEH,UAAU,CAACE,aAAD,CAAV,CAA0BC;AADU,KAA7C;AAGD;;AAED,SAAOF,2BAAP;AACD;;AAOD,OAAO,SAASG,kCAAT,CAA4CC,WAA5C,EAA0F;AAAA;;AAC/F,QAAMC,aAAa,wBAAGD,WAAW,CAACE,IAAf,+EAAG,kBAAkBC,SAArB,0DAAG,sBAA6BC,GAA7B,CAAkCC,QAAD,KAAe;AAACC,IAAAA,EAAE,EAAED,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AAE,EACJ,GAAGD,IAAI,CAACC,IADJ;AAEJC,QAAAA,UAAU,gBAAEF,IAAI,CAACC,IAAP,+CAAE,WAAWC,UAAX,CAAsBpB,GAAtB,CAA2BqB,SAAD;AAAA;;AAAA,iBAAgB,EACpD,GAAGA,SADiD;AAEpDC,YAAAA,OAAO,EAAE;AAAC5B,cAAAA,KAAK,EAAE2B,SAAF,aAAEA,SAAF,6CAAEA,SAAS,CAAEC,OAAb,uDAAE,mBAAoB5B;AAA5B,aAF2C;AAGpDH,YAAAA,UAAU,EAAED,kCAAkC,CAAC+B,SAAS,CAAC9B,UAAX,CAHM;AAIpDU,YAAAA,QAAQ,EAAE;AACRC,cAAAA,EAAE,EAAEmB,SAAF,aAAEA,SAAF,8CAAEA,SAAS,CAAEpB,QAAb,wDAAE,oBAAqBC;AADjB;AAJ0C,WAAhB;AAAA,SAA1B;AAFR;AAHD,KAAP;AAeD,GApBsB,CAAvB;AAsBA,QAAMqB,kBAAkB,GAAG3B,WAAW,CAAC2B,kBAAvC;AACA,QAAMC,oBAAoB,GAAG5B,WAAW,CAAC4B,oBAAzC;AAEA,SAAO;AACL3B,IAAAA,aADK;AAELM,IAAAA,KAAK,EAAEc,cAFF;AAGLM,IAAAA,kBAHK;AAILC,IAAAA;AAJK,GAAP;AAMD","sourcesContent":["import type {B3DMContent} from '@loaders.gl/3d-tiles';\nimport type {Accessor} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';\nimport type {B3DMAttributesData} from '../../i3s-attributes-worker';\n\ntype AttributesObject = {\n [k: string]: Accessor;\n};\n\n/**\n * Keep only values for B3DM attributes to pass data to worker thread.\n * @param attributes\n */\nfunction getB3DMAttributesWithoutBufferView(attributes: AttributesObject): AttributesObject {\n const attributesWithoutBufferView = {};\n\n for (const attributeName in attributes) {\n attributesWithoutBufferView[attributeName] = {\n value: attributes[attributeName].value\n };\n }\n\n return attributesWithoutBufferView;\n}\n\n/**\n * Prepare attributes for conversion to avoid binary data breaking in worker thread.\n * @param tileContent\n * @returns\n */\nexport function prepareDataForAttributesConversion(tileContent: B3DMContent): B3DMAttributesData {\n const gltfMaterials = tileContent.gltf?.materials?.map((material) => ({id: material.id}));\n let nodes =\n tileContent.gltf?.scene?.nodes ||\n tileContent.gltf?.scenes?.[0]?.nodes ||\n tileContent.gltf?.nodes ||\n [];\n\n const images =\n tileContent.gltf?.images?.map((imageObject) => {\n // Need data only for uncompressed images because we can't get batchIds from compressed textures.\n const data = imageObject?.image?.compressed ? null : imageObject?.image?.data.subarray();\n return {\n data,\n compressed: Boolean(imageObject?.image?.compressed),\n height: imageObject.image.height,\n width: imageObject.image.width,\n components: imageObject.image.components,\n mimeType: imageObject.mimeType\n };\n }) || [];\n\n const prepearedNodes = nodes.map((node) => {\n if (!node.mesh) {\n return node;\n }\n\n return {\n ...node,\n images,\n mesh: {\n ...node.mesh,\n primitives: node.mesh?.primitives.map((primitive) => ({\n ...primitive,\n indices: {value: primitive?.indices?.value},\n attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),\n material: {\n id: primitive?.material?.id\n }\n }))\n }\n };\n });\n\n const cartographicOrigin = tileContent.cartographicOrigin;\n const cartesianModelMatrix = tileContent.cartesianModelMatrix;\n\n return {\n gltfMaterials,\n nodes: prepearedNodes,\n cartographicOrigin,\n cartesianModelMatrix\n };\n}\n"],"file":"gltf-attributes.js"}
@@ -14,7 +14,7 @@ import NodePages from './helpers/node-pages';
14
14
  import { writeFile, removeDir, writeFileForSlpk } from '../lib/utils/file-utils';
15
15
  import { compressWithChildProcess } from '../lib/utils/compress-util';
16
16
  import { calculateFilesSize, timeConverter } from '../lib/utils/statistic-utills';
17
- import convertB3dmToI3sGeometry from './helpers/geometry-converter';
17
+ import convertB3dmToI3sGeometry, { getPropertyTable } from './helpers/geometry-converter';
18
18
  import { createBoundingVolumes, convertBoundingVolumeToI3SFullExtent } from './helpers/coordinate-converter';
19
19
  import { createSceneServerPath } from './helpers/create-scene-server-path';
20
20
  import { convertGeometricErrorToScreenThreshold } from '../lib/utils/lod-conversion-utils';
@@ -419,7 +419,7 @@ export default class I3SConverter {
419
419
  }
420
420
 
421
421
  async _createNode(parentTile, sourceTile, parentId, level) {
422
- var _sourceTile$content;
422
+ var _this$layers, _this$layers$attribut;
423
423
 
424
424
  if (this.validate) {
425
425
  this._checkAddRefinementTypeForTile(sourceTile);
@@ -428,13 +428,13 @@ export default class I3SConverter {
428
428
  await this._updateTilesetOptions();
429
429
  await this.sourceTileset._loadTile(sourceTile);
430
430
  let boundingVolumes = createBoundingVolumes(sourceTile, this.geoidHeightModel);
431
- const batchTable = sourceTile === null || sourceTile === void 0 ? void 0 : (_sourceTile$content = sourceTile.content) === null || _sourceTile$content === void 0 ? void 0 : _sourceTile$content.batchTableJson;
431
+ const propertyTable = getPropertyTable(sourceTile);
432
432
 
433
- if (batchTable) {
434
- this._convertAttributeStorageInfo(sourceTile.content);
433
+ if (propertyTable && !((_this$layers = this.layers0) !== null && _this$layers !== void 0 && (_this$layers$attribut = _this$layers.attributeStorageInfo) !== null && _this$layers$attribut !== void 0 && _this$layers$attribut.length)) {
434
+ this._convertPropertyTableToNodeAttributes(propertyTable);
435
435
  }
436
436
 
437
- const resourcesData = await this._convertResources(sourceTile);
437
+ const resourcesData = await this._convertResources(sourceTile, propertyTable);
438
438
  const nodes = [];
439
439
  const nodesInPage = [];
440
440
  const emptyResources = {
@@ -491,24 +491,14 @@ export default class I3SConverter {
491
491
  return nodes;
492
492
  }
493
493
 
494
- _convertAttributeStorageInfo(sourceTileContent) {
495
- var _this$layers, _this$layers$attribut;
496
-
497
- const batchTable = sourceTileContent && sourceTileContent.batchTableJson;
498
-
499
- if (batchTable && !((_this$layers = this.layers0) !== null && _this$layers !== void 0 && (_this$layers$attribut = _this$layers.attributeStorageInfo) !== null && _this$layers$attribut !== void 0 && _this$layers$attribut.length)) {
500
- this._convertBatchTableInfoToNodeAttributes(batchTable);
501
- }
502
- }
503
-
504
- async _convertResources(sourceTile) {
494
+ async _convertResources(sourceTile, propertyTable) {
505
495
  var _this$layers2;
506
496
 
507
497
  if (!this.isContentSupported(sourceTile)) {
508
498
  return null;
509
499
  }
510
500
 
511
- const resourcesData = await convertB3dmToI3sGeometry(sourceTile.content, Number(this.nodePages.nodesCounter), this.featuresHashArray, (_this$layers2 = this.layers0) === null || _this$layers2 === void 0 ? void 0 : _this$layers2.attributeStorageInfo, this.options.draco, this.generateBoundingVolumes, this.geoidHeightModel, this.workerSource);
501
+ const resourcesData = await convertB3dmToI3sGeometry(sourceTile.content, Number(this.nodePages.nodesCounter), propertyTable, this.featuresHashArray, (_this$layers2 = this.layers0) === null || _this$layers2 === void 0 ? void 0 : _this$layers2.attributeStorageInfo, this.options.draco, this.generateBoundingVolumes, this.geoidHeightModel, this.workerSource);
512
502
  return resourcesData;
513
503
  }
514
504
 
@@ -715,7 +705,11 @@ export default class I3SConverter {
715
705
  name: '1',
716
706
  format: 'ktx2'
717
707
  });
718
- const ktx2TextureData = encode(texture.image, KTX2BasisWriterWorker, { ...KTX2BasisWriterWorker.options,
708
+ const copyArrayBuffer = texture.image.data.subarray();
709
+ const arrayToEncode = new Uint8Array(copyArrayBuffer);
710
+ const ktx2TextureData = encode({ ...texture.image,
711
+ data: arrayToEncode
712
+ }, KTX2BasisWriterWorker, { ...KTX2BasisWriterWorker.options,
719
713
  source: this.workerSource.ktx2,
720
714
  reuseWorkers: true,
721
715
  _nodeWorkers: true
@@ -916,15 +910,15 @@ export default class I3SConverter {
916
910
  };
917
911
  }
918
912
 
919
- _convertBatchTableInfoToNodeAttributes(batchTable) {
913
+ _convertPropertyTableToNodeAttributes(propertyTable) {
920
914
  let attributeIndex = 0;
921
- const batchTableWithObjectId = {
915
+ const propertyTableWithObjectId = {
922
916
  OBJECTID: [0],
923
- ...batchTable
917
+ ...propertyTable
924
918
  };
925
919
 
926
- for (const key in batchTableWithObjectId) {
927
- const firstAttribute = batchTableWithObjectId[key][0];
920
+ for (const key in propertyTableWithObjectId) {
921
+ const firstAttribute = propertyTableWithObjectId[key][0];
928
922
  const attributeType = this.getAttributeType(key, firstAttribute);
929
923
 
930
924
  const storageAttribute = this._createdStorageAttribute(attributeIndex, key, attributeType);
@@ -933,7 +927,7 @@ export default class I3SConverter {
933
927
 
934
928
  const fieldAttribute = this._createFieldAttribute(key, fieldAttributeType);
935
929
 
936
- const popupInfo = this._createPopupInfo(batchTableWithObjectId);
930
+ const popupInfo = this._createPopupInfo(propertyTableWithObjectId);
937
931
 
938
932
  this.layers0.attributeStorageInfo.push(storageAttribute);
939
933
  this.layers0.fields.push(fieldAttribute);
@@ -962,14 +956,14 @@ export default class I3SConverter {
962
956
  }
963
957
  }
964
958
 
965
- _createPopupInfo(batchTable) {
959
+ _createPopupInfo(propertyTable) {
966
960
  const title = '{OBJECTID}';
967
961
  const mediaInfos = [];
968
962
  const fieldInfos = [];
969
963
  const popupElements = [];
970
964
  const expressionInfos = [];
971
965
 
972
- for (const key in batchTable) {
966
+ for (const key in propertyTable) {
973
967
  fieldInfos.push({
974
968
  fieldName: key,
975
969
  visible: true,