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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +1 -1
  2. package/dist/3d-tiles-attributes-worker.js +2 -2
  3. package/dist/3d-tiles-attributes-worker.js.map +2 -2
  4. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +8 -0
  5. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  6. package/dist/3d-tiles-converter/3d-tiles-converter.js +57 -43
  7. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -5
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +21 -17
  10. package/dist/converter.min.js +21 -21
  11. package/dist/deps-installer/deps-installer.d.ts +5 -1
  12. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  13. package/dist/deps-installer/deps-installer.js +21 -1
  14. package/dist/dist.min.js +662 -1018
  15. package/dist/es5/3d-tiles-attributes-worker.js +2 -2
  16. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  17. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +115 -101
  18. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  19. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +27 -19
  20. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  21. package/dist/es5/deps-installer/deps-installer.js +70 -6
  22. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  23. package/dist/es5/i3s-attributes-worker.js +1 -1
  24. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  25. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +4 -0
  26. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  27. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/feature-attributes.js +153 -0
  29. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  30. package/dist/es5/i3s-converter/helpers/geometry-converter.js +40 -44
  31. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +55 -36
  33. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  34. package/dist/es5/i3s-converter/helpers/node-pages.js +10 -2
  35. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  36. package/dist/es5/i3s-converter/i3s-converter.js +364 -435
  37. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  38. package/dist/es5/pgm-loader.js +1 -1
  39. package/dist/es5/workers/3d-tiles-attributes-worker.js +1 -1
  40. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
  41. package/dist/esm/3d-tiles-attributes-worker.js +2 -2
  42. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
  43. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +59 -44
  44. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  45. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +25 -15
  46. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  47. package/dist/esm/deps-installer/deps-installer.js +21 -2
  48. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  49. package/dist/esm/i3s-attributes-worker.js +1 -1
  50. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  51. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +4 -0
  52. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  53. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  54. package/dist/esm/i3s-converter/helpers/feature-attributes.js +138 -0
  55. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  56. package/dist/esm/i3s-converter/helpers/geometry-converter.js +19 -21
  57. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  58. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +55 -36
  59. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  60. package/dist/esm/i3s-converter/helpers/node-pages.js +9 -2
  61. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  62. package/dist/esm/i3s-converter/i3s-converter.js +93 -183
  63. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  64. package/dist/esm/pgm-loader.js +1 -1
  65. package/dist/esm/workers/3d-tiles-attributes-worker.js +1 -1
  66. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -1
  67. package/dist/i3s-attributes-worker.d.ts +5 -1
  68. package/dist/i3s-attributes-worker.d.ts.map +1 -1
  69. package/dist/i3s-attributes-worker.js +3 -3
  70. package/dist/i3s-attributes-worker.js.map +2 -2
  71. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +2 -3
  72. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  73. package/dist/i3s-converter/helpers/batch-ids-extensions.js +3 -0
  74. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +2 -2
  75. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  76. package/dist/i3s-converter/helpers/feature-attributes.d.ts +32 -0
  77. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  78. package/dist/i3s-converter/helpers/feature-attributes.js +162 -1
  79. package/dist/i3s-converter/helpers/geometry-converter.d.ts +5 -4
  80. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  81. package/dist/i3s-converter/helpers/geometry-converter.js +29 -27
  82. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  83. package/dist/i3s-converter/helpers/gltf-attributes.js +50 -30
  84. package/dist/i3s-converter/helpers/node-pages.d.ts +4 -0
  85. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  86. package/dist/i3s-converter/helpers/node-pages.js +9 -2
  87. package/dist/i3s-converter/i3s-converter.d.ts +24 -48
  88. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  89. package/dist/i3s-converter/i3s-converter.js +88 -186
  90. package/dist/i3s-converter/types.d.ts +4 -0
  91. package/dist/i3s-converter/types.d.ts.map +1 -1
  92. package/dist/workers/3d-tiles-attributes-worker.js +1 -1
  93. package/package.json +15 -15
  94. package/src/3d-tiles-attributes-worker.ts +1 -1
  95. package/src/3d-tiles-converter/3d-tiles-converter.ts +71 -55
  96. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +25 -18
  97. package/src/deps-installer/deps-installer.ts +29 -2
  98. package/src/i3s-attributes-worker.ts +5 -1
  99. package/src/i3s-converter/helpers/batch-ids-extensions.ts +13 -6
  100. package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
  101. package/src/i3s-converter/helpers/feature-attributes.ts +182 -0
  102. package/src/i3s-converter/helpers/geometry-converter.ts +45 -36
  103. package/src/i3s-converter/helpers/gltf-attributes.ts +54 -33
  104. package/src/i3s-converter/helpers/node-pages.ts +10 -2
  105. package/src/i3s-converter/i3s-converter.ts +125 -210
  106. package/src/i3s-converter/types.ts +4 -0
  107. package/src/workers/3d-tiles-attributes-worker.ts +1 -1
@@ -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","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;AA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ACD;;AAOD,SAASI,sCAAT,CACEJ,SADF,EAE2B;AACzB,MAAIA,SAAJ,aAAIA,SAAJ,eAAIA,SAAS,CAAES,eAAf,EAAgC;AAC9BP,IAAAA,OAAO,CAACC,IAAR,CACE,kFADF;AAGA,WAAO,IAAP;AACD;;AAED,MAAIH,SAAJ,aAAIA,SAAJ,eAAIA,SAAS,CAAEU,aAAf,EAA8B;AAAA;;AAO5B,UAAMC,qBAAqB,mBAAGC,MAAM,CAACjN,IAAP,CAAYqM,SAAS,CAACU,aAAtB,CAAH,iDAAG,aAAuC,CAAvC,CAA9B;;AAEA,QAAIC,qBAAJ,EAA2B;AACzB,YAAME,YAAY,GAAGb,SAAH,aAAGA,SAAH,uBAAGA,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"}
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","addNodeToNodePage","propertyTable","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","workerSource","useCartesianPositions","materialAndTextureList","convertMaterials","gltf","materials","dataForAttributesConversion","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","length","id","i","sourceMaterial","convertedAttributes","get","texture","nodeId","_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","images","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","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","extensionName","extension","getPropertyTableExtension","console","warn","getPropertyTableFromExtFeatureMetadata","extensionsWithPropertyTables","extensionsUsed","extensionItem","extensions","featureTextures","featureTables","firstFeatureTableName","Object","featureTable"],"mappings":"AAYA,SAAQA,OAA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hC,CAAlB;AAEA,SAAO;AAACA,IAAAA,aAAD;AAAgBC,IAAAA;AAAhB,GAAP;AACD;;AAOD,SAASI,sCAAT,CACEJ,SADF,EAE2B;AACzB,MAAIA,SAAJ,aAAIA,SAAJ,eAAIA,SAAS,CAAES,eAAf,EAAgC;AAC9BP,IAAAA,OAAO,CAACC,IAAR,CACE,kFADF;AAGA,WAAO,IAAP;AACD;;AAED,MAAIH,SAAJ,aAAIA,SAAJ,eAAIA,SAAS,CAAEU,aAAf,EAA8B;AAAA;;AAO5B,UAAMC,qBAAqB,mBAAGC,MAAM,CAAC9M,IAAP,CAAYkM,SAAS,CAACU,aAAtB,CAAH,iDAAG,aAAuC,CAAvC,CAA9B;;AAEA,QAAIC,qBAAJ,EAA2B;AACzB,YAAME,YAAY,GAAGb,SAAH,aAAGA,SAAH,uBAAGA,SAAS,CAAEU,aAAX,CAAyBC,qBAAzB,CAArB;AACA,YAAMhS,aAAa,GAAG,EAAtB;;AAEA,WAAK,MAAMuO,YAAX,IAA2B2D,YAAY,CAAC9D,UAAxC,EAAoD;AAClDpO,QAAAA,aAAa,CAACuO,YAAD,CAAb,GAA8B2D,YAAY,CAAC9D,UAAb,CAAwBG,YAAxB,EAAsCrC,IAApE;AACD;;AAED,aAAOlM,aAAP;AACD;AACF;;AAEDuR,EAAAA,OAAO,CAACC,IAAR,CAAa,kEAAb;AACA,SAAO,IAAP;AACD","sourcesContent":["import type {B3DMContent, FeatureTableJson} from '@loaders.gl/3d-tiles';\nimport type {\n GLTF_EXT_feature_metadata,\n GLTFAccessorPostprocessed,\n GLTFMaterialPostprocessed,\n GLTFNodePostprocessed,\n GLTFImagePostprocessed,\n GLTFMeshPrimitivePostprocessed,\n GLTFMeshPostprocessed,\n GLTFTexturePostprocessed\n} 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 {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 {\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';\n/** Usage of worker here brings more overhead than advantage */\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 addNodeToNodePage - function to add new node to node pages\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 addNodeToNodePage: () => 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): Promise<I3SConvertedResources[] | null> {\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 /** Usage of worker here brings more overhead than advantage */\n // const convertedAttributesMap: Map<string, ConvertedAttributes> =\n // await transformI3SAttributesOnWorker(dataForAttributesConversion, {\n // reuseWorkers: true,\n // _nodeWorkers: true,\n // useCartesianPositions,\n // source: workerSource.I3SAttributes\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 {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 const nodeId = addNodeToNodePage();\n result.push(\n await _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n propertyTable,\n attributeStorageInfo,\n draco,\n workerSource\n })\n );\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 nodeId,\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, images, 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 images,\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 images - gltf images 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 images: GLTFImagePostprocessed[],\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 images,\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 images - gltf images array\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param 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 images: GLTFImagePostprocessed[],\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\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 images,\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: GLTFImagePostprocessed[],\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: GLTFMeshPrimitivePostprocessed,\n images: GLTFImagePostprocessed[]\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 * @return batch table from b3dm / feature properties from EXT_FEATURE_METADATA\n */\nexport function getPropertyTable(tileContent: B3DMContent): FeatureTableJson | null {\n const batchTableJson = tileContent?.batchTableJson;\n\n if (batchTableJson) {\n return batchTableJson;\n }\n\n const {extensionName, extension} = getPropertyTableExtension(tileContent);\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(tileContent: B3DMContent) {\n const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];\n const extensionsUsed = tileContent?.gltf?.extensionsUsed;\n\n if (!extensionsUsed) {\n return {extensionName: null, extension: null};\n }\n\n let extensionName: string = '';\n\n for (const extensionItem of tileContent?.gltf?.extensionsUsed || []) {\n if (extensionsWithPropertyTables.includes(extensionItem)) {\n extensionName = extensionItem;\n break;\n }\n }\n\n const extension = tileContent?.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"}
@@ -18,51 +18,70 @@ export function prepareDataForAttributesConversion(tileContent) {
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
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;
21
+ var _imageObject$image;
22
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
- })) || [];
33
- const prepearedNodes = nodes.map(node => {
34
- var _node$mesh;
23
+ if (imageObject !== null && imageObject !== void 0 && (_imageObject$image = imageObject.image) !== null && _imageObject$image !== void 0 && _imageObject$image.compressed) {
24
+ return {
25
+ data: null,
26
+ compressed: true
27
+ };
28
+ } else {
29
+ var _imageObject$image2;
35
30
 
36
- if (!node.mesh) {
37
- return node;
31
+ const data = imageObject === null || imageObject === void 0 ? void 0 : (_imageObject$image2 = imageObject.image) === null || _imageObject$image2 === void 0 ? void 0 : _imageObject$image2.data;
32
+ const dataCopy = new Uint8Array(data.length);
33
+ dataCopy.set(data);
34
+ return {
35
+ data: dataCopy,
36
+ compressed: false,
37
+ height: imageObject.image.height,
38
+ width: imageObject.image.width,
39
+ components: imageObject.image.components,
40
+ mimeType: imageObject.mimeType
41
+ };
38
42
  }
39
-
40
- return { ...node,
41
- images,
42
- mesh: { ...node.mesh,
43
- primitives: (_node$mesh = node.mesh) === null || _node$mesh === void 0 ? void 0 : _node$mesh.primitives.map(primitive => {
44
- var _primitive$indices, _primitive$material;
45
-
46
- return { ...primitive,
47
- indices: {
48
- value: primitive === null || primitive === void 0 ? void 0 : (_primitive$indices = primitive.indices) === null || _primitive$indices === void 0 ? void 0 : _primitive$indices.value
49
- },
50
- attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),
51
- material: {
52
- id: primitive === null || primitive === void 0 ? void 0 : (_primitive$material = primitive.material) === null || _primitive$material === void 0 ? void 0 : _primitive$material.id
53
- }
54
- };
55
- })
56
- }
57
- };
58
- });
43
+ })) || [];
44
+ prepareNodes(nodes);
59
45
  const cartographicOrigin = tileContent.cartographicOrigin;
60
46
  const cartesianModelMatrix = tileContent.cartesianModelMatrix;
61
47
  return {
62
48
  gltfMaterials,
63
- nodes: prepearedNodes,
49
+ nodes,
50
+ images,
64
51
  cartographicOrigin,
65
52
  cartesianModelMatrix
66
53
  };
67
54
  }
55
+
56
+ function prepareNodes(nodes) {
57
+ for (let index = 0; index < nodes.length; index++) {
58
+ const node = nodes[index];
59
+
60
+ if (node.mesh) {
61
+ var _node$mesh;
62
+
63
+ nodes[index] = { ...node,
64
+ mesh: { ...node.mesh,
65
+ primitives: (_node$mesh = node.mesh) === null || _node$mesh === void 0 ? void 0 : _node$mesh.primitives.map(primitive => {
66
+ var _primitive$indices, _primitive$material;
67
+
68
+ return { ...primitive,
69
+ indices: {
70
+ value: primitive === null || primitive === void 0 ? void 0 : (_primitive$indices = primitive.indices) === null || _primitive$indices === void 0 ? void 0 : _primitive$indices.value
71
+ },
72
+ attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),
73
+ material: {
74
+ id: primitive === null || primitive === void 0 ? void 0 : (_primitive$material = primitive.material) === null || _primitive$material === void 0 ? void 0 : _primitive$material.id
75
+ }
76
+ };
77
+ })
78
+ }
79
+ };
80
+ }
81
+
82
+ if (node.children) {
83
+ prepareNodes(node.children);
84
+ }
85
+ }
86
+ }
68
87
  //# sourceMappingURL=gltf-attributes.js.map
@@ -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","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,QAAQ,CAACC;AAAd,GAAf,CAAjC,CAAtB;AACA,MAAIC,KAAK,GACP,uBAAAP,WAAW,CAACE,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+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"}
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","image","compressed","data","dataCopy","Uint8Array","length","set","height","width","components","mimeType","prepareNodes","cartographicOrigin","cartesianModelMatrix","index","node","mesh","primitives","primitive","indices","children"],"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,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gBAAAA,EAAE,EAAEwB,SAAF,aAAEA,SAAF,8CAAEA,SAAS,CAAEzB,QAAb,wDAAE,oBAAqBC;AADjB;AAJ0C,aAAhB;AAAA,WAA1B;AAFR;AAFO,OAAf;AAcD;;AAED,QAAIqB,IAAI,CAACK,QAAT,EAAmB;AACjBT,MAAAA,YAAY,CAACI,IAAI,CAACK,QAAN,CAAZ;AACD;AACF;AACF","sourcesContent":["import type {B3DMContent} from '@loaders.gl/3d-tiles';\nimport type {GLTFAccessorPostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';\nimport type {B3DMAttributesData} from '../../i3s-attributes-worker';\n\ntype AttributesObject = {\n [k: string]: GLTFAccessorPostprocessed;\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 if (imageObject?.image?.compressed) {\n return {\n data: null,\n compressed: true\n };\n } else {\n const data = imageObject?.image?.data;\n const dataCopy = new Uint8Array(data.length);\n dataCopy.set(data);\n return {\n data: dataCopy,\n compressed: false,\n height: imageObject.image.height,\n width: imageObject.image.width,\n components: imageObject.image.components,\n mimeType: imageObject.mimeType\n };\n }\n }) || [];\n\n prepareNodes(nodes);\n\n const cartographicOrigin = tileContent.cartographicOrigin;\n const cartesianModelMatrix = tileContent.cartesianModelMatrix;\n\n return {\n gltfMaterials,\n nodes,\n images,\n cartographicOrigin,\n cartesianModelMatrix\n };\n}\n\n/**\n * Traverse all nodes to replace all sensible data with copy to avoid data corruption in worker.\n * @param nodes\n */\nfunction prepareNodes(nodes: GLTFNodePostprocessed[]): void {\n for (let index = 0; index < nodes.length; index++) {\n const node = nodes[index] as any;\n\n if (node.mesh) {\n nodes[index] = {\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 if (node.children) {\n prepareNodes(node.children);\n }\n }\n}\n"],"file":"gltf-attributes.js"}
@@ -29,6 +29,13 @@ export default class NodePages {
29
29
  return this.nodePages[pageIndex].nodes[nodeIndex];
30
30
  }
31
31
 
32
+ updateAll(id, data) {
33
+ const node = this.getNodeById(id);
34
+ Object.assign(node, data, {
35
+ index: node.index
36
+ });
37
+ }
38
+
32
39
  updateMaterialByNodeId(id, materialId) {
33
40
  const node = this.getNodeById(id);
34
41
 
@@ -55,7 +62,7 @@ export default class NodePages {
55
62
  updateNodeAttributeByNodeId(id) {
56
63
  const node = this.getNodeById(id);
57
64
 
58
- if (!node.mesh) {
65
+ if (!node.mesh || !node.index) {
59
66
  return;
60
67
  }
61
68
 
@@ -94,7 +101,7 @@ export default class NodePages {
94
101
  }
95
102
 
96
103
  updateResourceInMesh(node) {
97
- if (node.mesh) {
104
+ if (node.mesh && isFinite(node.index)) {
98
105
  node.mesh.geometry.resource = node.index;
99
106
  }
100
107
  }