@loaders.gl/tile-converter 3.1.1 → 3.1.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 (29) hide show
  1. package/dist/converter.min.js +1 -1
  2. package/dist/{bundle.js → dist.min.js} +88 -24
  3. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  4. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +11 -18
  5. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  6. package/dist/es5/i3s-converter/helpers/geometry-converter.js +29 -4
  7. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  8. package/dist/es5/i3s-converter/helpers/node-debug.js +9 -3
  9. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  10. package/dist/es5/i3s-converter/i3s-converter.js +12 -10
  11. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  12. package/dist/es5/pgm-loader.js +1 -1
  13. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  14. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +10 -18
  15. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  16. package/dist/esm/i3s-converter/helpers/geometry-converter.js +31 -4
  17. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  18. package/dist/esm/i3s-converter/helpers/node-debug.js +9 -3
  19. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  20. package/dist/esm/i3s-converter/i3s-converter.js +3 -3
  21. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  22. package/dist/esm/pgm-loader.js +1 -1
  23. package/package.json +15 -15
  24. package/src/i3s-converter/helpers/create-scene-server-path.ts +9 -5
  25. package/src/i3s-converter/helpers/geometry-attributes.ts +52 -30
  26. package/src/i3s-converter/helpers/geometry-converter.js +39 -4
  27. package/src/i3s-converter/helpers/node-debug.ts +58 -12
  28. package/src/i3s-converter/i3s-converter.ts +4 -4
  29. package/src/i3s-converter/types.ts +28 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-converter.js"],"names":["VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","scratchVector","Vector3","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","useCartesianPositions","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","gltf","materials","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","values","attributes","boundingVolumes","positions","cartographicOrigin","obb","center","index","vertex","subarray","Ellipsoid","WGS84","cartesianToCartographic","Array","from","getHeight","subtract","set","vertexCount","triangleCount","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","fileBuffer","Uint8Array","buffer","ArrayBuffer","generateCompressedGeometry","Float32Array","compressedGeometry","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","keys","attrKey","delete","reduce","acc","value","concat","matrix","Matrix4","node","convertNode","nodeMatrix","compositeMatrix","multiplyRight","mesh","convertMesh","children","content","primitives","primitive","outputAttributes","transformVertexArray","vertices","POSITION","cartesianModelMatrix","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIdsByAttributeName","args","newVertices","coordIndex","vertexVector","x","y","z","calleeArgs","transform","transformAsVector","newTexCoords","fill","texCoord","colorsAttribute","components","newColors","colorIndex","color","colorUint8","j","batchedIds","newBatchIds","batchIds","possibleBatchIdAttributeName","sourceMaterials","convertMaterial","doubleSided","emissiveFactor","map","c","Math","round","alphaMode","toLowerCase","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfMaterials","i3sResources","materialDefinitionInfos","gltfMaterial","convertGLTFMaterialToI3sSharedResources","materialDefinitionInfo","textureDefinitionInfo","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","Vector4","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","toArray","encoding","mimeType","images","generateImageId","size","image","width","data","height","levelCountOfTexture","indexOfLevel","indexOfTextureInStore","zerosCount","toString","rightHalf","repeat","shiftedLevelCountOfTexture","shiftedIndexOfLevel","shiftedWidth","shiftedHeight","leftHalf","imageId","BigInt","batchTable","replaceMap","getFeaturesReplaceMap","replaceIndicesByUnique","featureMap","oldFeatureId","uniqueFeatureId","getOrCreateUniqueFeatureId","generateStringFromBatchTableByIndex","str","key","batchTableStr","hash","includes","indexOf","indicesArray","attributeBuffers","batchTableWithFeatureIds","OBJECTID","type","getAttributeType","attributeBuffer","generateShortIntegerAttributeBuffer","generateDoubleAttributeBuffer","generateStringAttributeBuffer","attribute","find","attr","name","attributeValues","valueType","count","valuesArray","padding","Float64Array","batchAttributes","stringCountArray","totalNumberOfBytes","stringSizesArray","stringBufferArray","currentString","String","currentStringBuffer","Buffer","currentStringSize","totalBytes","concatenateArrayBuffers","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","DracoWriter","method","orderedFeatureIndices","fillIndex","startIndex","endIndex"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAEA,IAAMA,iBAAiB,GAAG,CAA1B;AACA,IAAMC,oBAAoB,GAAG,CAA7B;AACA,IAA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,2BAgCaa,UAhCb;AAAA;AAAA,mBAiCU,mBAAO;AAACjC,cAAAA,UAAU,EAAEiO,oBAAb;AAAmCtJ,cAAAA,OAAO,EAAPA;AAAnC,aAAP,EAAoDyJ,kBAApD,EAAiE;AACrE9P,cAAAA,KAAK,EAAE;AACL+P,gBAAAA,MAAM,EAAE,0BADH;AAELH,gBAAAA,kBAAkB,EAAlBA;AAFK;AAD8D,aAAjE,CAjCV;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAgDA,SAASF,6BAAT,CAAuCD,YAAvC,EAAqD5M,SAArD,EAAgE;AAC9D,MAAMmN,qBAAqB,GAAG,IAAIzM,WAAJ,CAAgBkM,YAAY,CAACxO,MAA7B,CAA9B;AACA,MAAIgP,SAAS,GAAG,CAAhB;AACA,MAAIC,UAAU,GAAG,CAAjB;;AAEA,OAAK,IAAIlO,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGa,SAAS,CAAC5B,MAAtC,EAA8Ce,KAAK,IAAI,CAAvD,EAA0D;AACxD,QAAMmO,QAAQ,GAAG,CAACtN,SAAS,CAACb,KAAD,CAAT,GAAmB,CAApB,IAAyB/C,iBAA1C;AAEA+Q,IAAAA,qBAAqB,CAACrI,IAAtB,CAA2BsI,SAA3B,EAAsCC,UAAtC,EAAkDC,QAAlD;AAEAF,IAAAA,SAAS;AACTC,IAAAA,UAAU,GAAGC,QAAQ,GAAG,CAAxB;AACD;;AAED,SAAOH,qBAAP;AACD","sourcesContent":["import {Vector3, Matrix4, Vector4} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nimport {DracoWriter} from '@loaders.gl/draco';\nimport {encode, assert} from '@loaders.gl/core';\nimport {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';\nimport md5 from 'md5';\nimport {generateAttributes} from './geometry-attributes';\nimport {createBoundingVolumesFromGeometry} from './coordinate-converter';\n\nconst VALUES_PER_VERTEX = 3;\nconst VALUES_PER_TEX_COORD = 2;\nconst VALUES_PER_COLOR_ELEMENT = 4;\n\nconst STRING_TYPE = 'string';\nconst SHORT_INT_TYPE = 'Int32';\nconst DOUBLE_TYPE = 'Float64';\nconst OBJECT_ID_TYPE = 'Oid32';\n/*\n * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.\n * _BATCHID - Default attribute name which includes batch info.\n * BATCHID - Legacy attribute name which includes batch info.\n */\nconst BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];\n\nlet scratchVector = new Vector3();\n\nexport default async function convertB3dmToI3sGeometry(\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco,\n generateBoundingVolumes,\n geoidHeightModel\n) {\n const useCartesianPositions = generateBoundingVolumes;\n const materialAndTextureList = convertMaterials(tileContent);\n const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);\n\n if (generateBoundingVolumes) {\n _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);\n }\n\n if (convertedAttributesMap.has('default')) {\n materialAndTextureList.push({\n material: getDefaultMaterial()\n });\n }\n\n const result = [];\n let nodesCounter = nodeId;\n let {materials = []} = tileContent.gltf;\n if (!materials?.length) {\n materials.push({id: 'default'});\n }\n for (let i = 0; i < materials.length; i++) {\n const sourceMaterial = materials[i];\n if (!convertedAttributesMap.has(sourceMaterial.id)) {\n continue; // eslint-disable-line no-continue\n }\n const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);\n const {material, texture} = materialAndTextureList[i];\n result.push(\n await _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId: nodesCounter,\n featuresHashArray,\n attributeStorageInfo,\n draco\n })\n );\n nodesCounter++;\n }\n\n if (!result.length) {\n return null;\n }\n return result;\n}\n\n/**\n * Create bounding volumes based on positions\n * @param convertedAttributesMap\n * @param geoidHeightModel\n */\nfunction _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {\n for (const attributes of convertedAttributesMap.values()) {\n const boundingVolumes = createBoundingVolumesFromGeometry(\n attributes.positions,\n geoidHeightModel\n );\n\n attributes.boundingVolumes = boundingVolumes;\n const cartographicOrigin = boundingVolumes.obb.center;\n\n for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {\n const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);\n Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);\n scratchVector[2] =\n scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);\n scratchVector = scratchVector.subtract(cartographicOrigin);\n attributes.positions.set(scratchVector, index);\n }\n }\n}\n\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n}) {\n const boundingVolumes = convertedAttributes.boundingVolumes;\n const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;\n const triangleCount = vertexCount / 3;\n const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =\n generateAttributes({triangleCount, ...convertedAttributes});\n\n if (tileContent.batchTableJson) {\n makeFeatureIdsUnique(\n featureIds,\n convertedAttributes.featureIndices,\n featuresHashArray,\n tileContent.batchTableJson\n );\n }\n\n const header = new Uint32Array(2);\n const typedFeatureIds = generateBigUint64Array(featureIds);\n\n header.set([vertexCount, featureCount], 0);\n const fileBuffer = new Uint8Array(\n concatenateArrayBuffers(\n header.buffer,\n positions.buffer,\n normals.buffer,\n texture ? texCoords.buffer : new ArrayBuffer(0),\n colors.buffer,\n typedFeatureIds.buffer,\n faceRange.buffer\n )\n );\n const compressedGeometry = draco\n ? await generateCompressedGeometry(vertexCount, convertedAttributes, {\n positions,\n normals,\n texCoords: texture ? texCoords : new Float32Array(0),\n colors,\n featureIds,\n faceRange\n })\n : null;\n\n const attributes = convertBatchTableToAttributeBuffers(\n tileContent.batchTableJson,\n featureIds,\n attributeStorageInfo\n );\n\n return {\n geometry: fileBuffer,\n compressedGeometry,\n texture,\n sharedResources: getSharedResources(tileContent, nodeId),\n meshMaterial: material,\n vertexCount,\n attributes,\n featureCount,\n boundingVolumes\n };\n}\n\n/**\n * Convert attributes from the gltf nodes tree to i3s plain geometry\n * @param {Object} tileContent - 3d tile content\n * @returns {Map}\n * Map<{\n * positions: Float32Array,\n * normals: Float32Array,\n * colors: Uint8Array,\n * texCoords: Float32Array\n * }>\n * @todo implement colors support (if applicable for gltf format)\n */\nfunction convertAttributes(tileContent, useCartesianPositions) {\n const attributesMap = new Map();\n\n for (const material of tileContent.gltf.materials || [{id: 'default'}]) {\n attributesMap.set(material.id, {\n positions: new Float32Array(0),\n normals: new Float32Array(0),\n texCoords: new Float32Array(0),\n colors: new Uint8Array(0),\n featureIndices: [],\n boundingVolumes: null\n });\n }\n\n const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;\n convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);\n\n for (const attrKey of attributesMap.keys()) {\n const attributes = attributesMap.get(attrKey);\n if (attributes.positions.length === 0) {\n attributesMap.delete(attrKey);\n continue; // eslint-disable-line no-continue\n }\n attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));\n }\n\n return attributesMap;\n}\n\n/**\n * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.\n * The goal is applying tranformation matrix for all children. Functions \"convertNodes\" and \"convertNode\" work together recursively.\n * @param {Object[]} nodes - gltf nodes array\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: UInt8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns {void}\n */\nfunction convertNodes(\n nodes,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n if (nodes) {\n for (const node of nodes) {\n convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);\n }\n }\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} node - gltf node\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertNode(\n node,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n const nodeMatrix = node.matrix;\n const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;\n\n const mesh = node.mesh;\n if (mesh) {\n convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, compositeMatrix);\n }\n\n convertNodes(node.children, tileContent, attributesMap, useCartesianPositions, compositeMatrix);\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} mesh - gltf node\n * @param {Object} content - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertMesh(\n mesh,\n content,\n attributesMap,\n useCartesianPositions = false,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n for (const primitive of mesh.primitives) {\n let outputAttributes = null;\n if (primitive.material) {\n outputAttributes = attributesMap.get(primitive.material.id);\n } else if (attributesMap.has('default')) {\n outputAttributes = attributesMap.get('default');\n }\n assert(outputAttributes !== null, 'Primitive - material mapping failed');\n const attributes = primitive.attributes;\n\n outputAttributes.positions = concatenateTypedArrays(\n outputAttributes.positions,\n transformVertexArray({\n vertices: attributes.POSITION.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexPositions,\n useCartesianPositions\n })\n );\n outputAttributes.normals = concatenateTypedArrays(\n outputAttributes.normals,\n transformVertexArray({\n vertices: attributes.NORMAL && attributes.NORMAL.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexNormals,\n useCartesianPositions: false\n })\n );\n outputAttributes.texCoords = concatenateTypedArrays(\n outputAttributes.texCoords,\n flattenTexCoords(\n attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value,\n primitive.indices.value\n )\n );\n\n outputAttributes.colors = concatenateTypedArrays(\n outputAttributes.colors,\n flattenColors(attributes.COLOR_0, primitive.indices.value)\n );\n\n outputAttributes.featureIndices.push(\n flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value)\n );\n }\n}\n\n/**\n * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format\n * @param {object} args - source tile (3DTile)\n * @param {Float32Array} args.vertices - gltf primitive POSITION or NORMAL attribute\n * @param {Object} args.cartographicOrigin - cartographic origin coordinates\n * @param {Object} args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param {Matrix4} args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param {Uint8Array} args.indices - gltf primitive indices\n * @param {Function} args.attributeSpecificTransformation - function to do attribute - specific transformations\n * @param {Boolean} args.useCartesianPositions - use coordinates as it is.\n * @returns {Float32Array}\n */\nfunction transformVertexArray(args) {\n const {vertices, indices, attributeSpecificTransformation} = args;\n const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);\n if (!vertices) {\n return newVertices;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_VERTEX;\n const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);\n let vertexVector = new Vector3(Array.from(vertex));\n\n vertexVector = attributeSpecificTransformation(vertexVector, args);\n\n newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;\n newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;\n newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;\n }\n return newVertices;\n}\n\nfunction transformVertexPositions(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, cartographicOrigin, nodeMatrix, useCartesianPositions} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transform(nodeMatrix);\n }\n\n vertexVector = vertexVector.transform(cartesianModelMatrix);\n\n if (useCartesianPositions) {\n return vertexVector;\n }\n\n Ellipsoid.WGS84.cartesianToCartographic(\n [vertexVector[0], vertexVector[1], vertexVector[2]],\n vertexVector\n );\n vertexVector = vertexVector.subtract(cartographicOrigin);\n return vertexVector;\n}\n\nfunction transformVertexNormals(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, nodeMatrix} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transformAsVector(nodeMatrix);\n }\n\n vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);\n return vertexVector;\n}\n\n/**\n * Convert uv0 (texture coordinates) from coords based on indices to plain arrays, compatible with i3s\n * @param {Float32Array} texCoords - gltf primitive TEXCOORD_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Float32Array}\n */\nfunction flattenTexCoords(texCoords, indices) {\n const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);\n if (!texCoords) {\n // We need dummy UV0s because it is required in 1.6\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.6/vertexAttribute.cmn.md\n newTexCoords.fill(1);\n return newTexCoords;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_TEX_COORD;\n const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);\n newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];\n newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];\n }\n return newTexCoords;\n}\n\n/**\n * Convert color from COLOR_0 based on indices to plain arrays, compatible with i3s\n * @param {object} colorsAttribute - gltf primitive COLOR_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Uint8Array}\n */\nfunction flattenColors(colorsAttribute, indices) {\n const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;\n const newColors = new Uint8Array(indices.length * components);\n if (!colorsAttribute) {\n // Vertex color multiplies by material color so it must be normalized 1 by default\n newColors.fill(255);\n return newColors;\n }\n const colors = colorsAttribute.value;\n for (let i = 0; i < indices.length; i++) {\n const colorIndex = indices[i] * components;\n const color = colors.subarray(colorIndex, colorIndex + components);\n const colorUint8 = new Uint8Array(components);\n for (let j = 0; j < color.length; j++) {\n colorUint8[j] = color[j] * 255;\n }\n newColors.set(colorUint8, i * components);\n }\n return newColors;\n}\n\n/**\n * Flatten batchedIds list based on indices to right ordered array, compatible with i3s\n * @param {Array} batchedIds - gltf primitive\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Array}\n */\nfunction flattenBatchIds(batchedIds, indices) {\n if (!batchedIds.length || !indices.length) {\n return [];\n }\n const newBatchIds = [];\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i];\n newBatchIds.push(batchedIds[coordIndex]);\n }\n return newBatchIds;\n}\n/**\n * Return batchIds based on possible attribute names for different kind of maps.\n * @param {Object} attributes {attributeName: Float32Array}\n * @returns {Array}\n */\nfunction getBatchIdsByAttributeName(attributes) {\n let batchIds = [];\n\n for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {\n const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];\n if (\n attributes[possibleBatchIdAttributeName] &&\n attributes[possibleBatchIdAttributeName].value\n ) {\n batchIds = attributes[possibleBatchIdAttributeName].value;\n break;\n }\n }\n\n return batchIds;\n}\n\nfunction convertMaterials(tileContent) {\n const result = [];\n const sourceMaterials = tileContent.gltf.materials || [];\n for (const sourceMaterial of sourceMaterials) {\n result.push(convertMaterial(sourceMaterial));\n }\n return result;\n}\n\n/**\n * Convert texture and material from gltf 2.0 material object\n * @param {Object} sourceMaterial - material object\n * @returns {Object}\n */\nfunction convertMaterial(sourceMaterial) {\n const material = {\n doubleSided: sourceMaterial.doubleSided,\n emissiveFactor: sourceMaterial.emissiveFactor.map((c) => Math.round(c * 255)),\n // It is in upper case in GLTF: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#alpha-coverage\n // But it is in lower case in I3S: https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md\n alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),\n pbrMetallicRoughness: {\n roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,\n metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor\n }\n };\n\n let texture;\n if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {\n texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n } else if (sourceMaterial.emissiveTexture) {\n texture = sourceMaterial.emissiveTexture.texture.source;\n // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n }\n\n if (!texture) {\n // Should use default baseColorFactor if it is not present in source material\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness\n const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;\n material.pbrMetallicRoughness.baseColorFactor =\n (baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) || undefined;\n }\n\n return {material, texture};\n}\n\nfunction getDefaultMaterial() {\n return {\n alphaMode: 'opaque',\n pbrMetallicRoughness: {}\n };\n}\n\n/**\n * Form \"sharedResources\" from gltf materials array\n * @param {Object} tileContent - 3d tile content\n * @returns {Object} {materialDefinitionInfos: Object[], textureDefinitionInfos: Object[]} -\n * 2 arrays in format of i3s sharedResources data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/sharedResource.cmn.md\n */\nfunction getSharedResources(tileContent, nodeId) {\n const gltfMaterials = tileContent.gltf.materials;\n const i3sResources = {};\n\n if (!gltfMaterials || !gltfMaterials.length) {\n return i3sResources;\n }\n\n i3sResources.materialDefinitionInfos = [];\n for (const gltfMaterial of gltfMaterials) {\n const {materialDefinitionInfo, textureDefinitionInfo} = convertGLTFMaterialToI3sSharedResources(\n gltfMaterial,\n nodeId\n );\n i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);\n if (textureDefinitionInfo) {\n i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];\n i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);\n }\n }\n return i3sResources;\n}\n\n/**\n * Convert gltf material into I3S sharedResources data\n * @param {Object} gltfMaterial - gltf material data\n * @returns {Object} - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data\n */\nfunction convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {\n const texture =\n gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;\n let textureDefinitionInfo = null;\n if (texture) {\n textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);\n }\n const {baseColorFactor, metallicFactor} = gltfMaterial.pbrMetallicRoughness;\n let colorFactor = baseColorFactor;\n // If alpha channel is 0 try to get emissive factor from gltf material.\n if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {\n colorFactor = gltfMaterial.emissiveFactor;\n colorFactor[3] = colorFactor[3] || 1;\n }\n\n return {\n materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),\n textureDefinitionInfo\n };\n}\n\n/**\n * Form \"materialDefinition\" which is part of \"sharedResouces\"\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materials\n * See formulas in appendix \"Appendix B: BRDF Implementation\":\n * const dielectricSpecular = rgb(0.04, 0.04, 0.04)\n * const black = rgb(0, 0, 0)\n * cdiff = lerp(baseColor.rgb * (1 - dielectricSpecular.r), black, metallic)\n * F0 = lerp(dieletricSpecular, baseColor.rgb, metallic)\n *\n * Assumption: F0 - specular in i3s (\"specular reflection\" <-> \"reflectance value at normal incidence\")\n * cdiff - diffuse in i3s (\"Diffuse color\" <-> \"'c' diffuse\" (c means color?))\n * @param {number[]} baseColorFactor - RGBA color in 0..1 format\n * @param {number} metallicFactor - \"metallicFactor\" attribute of gltf material object\n * @returns {Object}\n */\nfunction extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {\n const matDielectricColorComponent = 0.04 / 255; // Color from rgb (255) to 0..1 resolution\n // All color resolutions are 0..1\n const black = new Vector4(0, 0, 0, 1);\n const unitVector = new Vector4(1, 1, 1, 1);\n const dielectricSpecular = new Vector4(\n matDielectricColorComponent,\n matDielectricColorComponent,\n matDielectricColorComponent,\n 0\n );\n const baseColorVector = new Vector4(baseColorFactor);\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material\n // Formulas for Cdiff & F0\n const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);\n const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);\n dielectricSpecular[3] = 1;\n const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);\n return {\n diffuse: diffuse.toArray(),\n specular: specular.toArray()\n };\n}\n\n/**\n * Form \"textureDefinition\" which is part of \"sharedResouces\"\n * @param {Object} texture - texture image info\n * @returns {Object}\n */\nfunction extractSharedResourcesTextureInfo(texture, nodeId) {\n return {\n encoding: [texture.source.mimeType],\n images: [\n {\n // 'i3s' has just size which is width of the image. Images are supposed to be square.\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md\n id: generateImageId(texture, nodeId),\n size: texture.source.image.width,\n length: [texture.source.image.data.length]\n }\n ]\n };\n}\n/*\n * Formula for counting imageId:\n * https://github.com/Esri/i3s-spec/blob/0a6366a9249b831db8436c322f8d27521e86cf07/format/Indexed%203d%20Scene%20Layer%20Format%20Specification.md#generating-image-ids\n * @param {Object} texture - texture image info\n * @returns {string}\n */\nfunction generateImageId(texture, nodeId) {\n const {width, height} = texture.source.image;\n const levelCountOfTexture = 1;\n const indexOfLevel = 0;\n const indexOfTextureInStore = nodeId + 1;\n\n const zerosCount = 32 - indexOfTextureInStore.toString(2).length;\n const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));\n\n const shiftedLevelCountOfTexture = levelCountOfTexture << 28;\n const shiftedIndexOfLevel = indexOfLevel << 24;\n const shiftedWidth = (width - 1) << 12;\n const shiftedHeight = (height - 1) << 0;\n\n const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;\n const imageId = BigInt(`0b${leftHalf.toString(2)}${rightHalf}`);\n return imageId.toString();\n}\n\n/**\n * Make all feature ids unique through all nodes in layout.\n * @param {Array} featureIds\n * @param {Array} featureIndices\n * @param {Array} featuresHashArray\n * @param {Object} batchTable\n * @returns {void}\n */\nfunction makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {\n const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);\n replaceIndicesByUnique(featureIndices, replaceMap);\n replaceIndicesByUnique(featureIds, replaceMap);\n}\n\n/**\n * Generate replace map to make featureIds unique.\n * @param {Array} featureIds\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Object}\n */\nfunction getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {\n const featureMap = {};\n\n for (let index = 0; index < featureIds.length; index++) {\n const oldFeatureId = featureIds[index];\n const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);\n featureMap[oldFeatureId.toString()] = uniqueFeatureId;\n }\n\n return featureMap;\n}\n\n/**\n * Generates string for unique batch id creation.\n * @param {Object} batchTable\n * @param {Number} index\n * @returns {String}\n */\nfunction generateStringFromBatchTableByIndex(batchTable, index) {\n let str = '';\n for (const key in batchTable) {\n str += batchTable[key][index];\n }\n return str;\n}\n\n/**\n * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.\n * @param {Number} index\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Number}\n */\nfunction getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {\n const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);\n const hash = md5(batchTableStr);\n\n if (featuresHashArray.includes(hash)) {\n return featuresHashArray.indexOf(hash);\n }\n return featuresHashArray.push(hash) - 1;\n}\n\n/**\n * Do replacement of indices for making them unique through all nodes.\n * @param {Array} indicesArray\n * @param {Object} featureMap\n * @returns {void}\n */\nfunction replaceIndicesByUnique(indicesArray, featureMap) {\n for (let index = 0; index < indicesArray.length; index++) {\n indicesArray[index] = featureMap[indicesArray[index]];\n }\n}\n\n/**\n * Convert batch table data to attribute buffers.\n * @param {Object} batchTable - table with metadata for particular feature.\n * @param {Array} featureIds\n * @param {Array} attributeStorageInfo\n * @returns {Array} - Array of file buffers.\n */\nfunction convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {\n const attributeBuffers = [];\n\n if (batchTable) {\n const batchTableWithFeatureIds = {\n OBJECTID: featureIds,\n ...batchTable\n };\n\n for (const key in batchTableWithFeatureIds) {\n const type = getAttributeType(key, attributeStorageInfo);\n\n let attributeBuffer = null;\n\n switch (type) {\n case OBJECT_ID_TYPE:\n case SHORT_INT_TYPE:\n attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case DOUBLE_TYPE:\n attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case STRING_TYPE:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n default:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n }\n\n attributeBuffers.push(attributeBuffer);\n }\n }\n\n return attributeBuffers;\n}\n/**\n * Return attribute type.\n * @param {String} key\n * @param {Array} attributeStorageInfo\n * @returns {String} attribute type.\n */\nfunction getAttributeType(key, attributeStorageInfo) {\n const attribute = attributeStorageInfo.find((attr) => attr.name === key);\n return attribute.attributeValues.valueType;\n}\n\n/**\n * Convert short integer to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateShortIntegerAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const valuesArray = new Uint32Array(featureIds);\n return concatenateArrayBuffers(count.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert double to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateDoubleAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const padding = new Uint8Array(4);\n const valuesArray = new Float64Array(featureIds);\n\n return concatenateArrayBuffers(count.buffer, padding.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert batch table attributes to array buffer with batch table data.\n * @param {Array} batchAttributes\n * @returns {ArrayBuffer} - Buffer with batch table data.\n */\nfunction generateStringAttributeBuffer(batchAttributes) {\n const stringCountArray = new Uint32Array([batchAttributes.length]);\n let totalNumberOfBytes = 0;\n const stringSizesArray = new Uint32Array(batchAttributes.length);\n const stringBufferArray = [];\n\n for (let index = 0; index < batchAttributes.length; index++) {\n const currentString = `${String(batchAttributes[index])}\\0`;\n const currentStringBuffer = Buffer.from(currentString);\n const currentStringSize = currentStringBuffer.length;\n totalNumberOfBytes += currentStringSize;\n stringSizesArray[index] = currentStringSize;\n stringBufferArray.push(currentStringBuffer);\n }\n\n const totalBytes = new Uint32Array([totalNumberOfBytes]);\n\n return concatenateArrayBuffers(\n stringCountArray.buffer,\n totalBytes.buffer,\n stringSizesArray.buffer,\n ...stringBufferArray\n );\n}\n\n/**\n * Convert featureIds to BigUint64Array.\n * @param {Array} featureIds\n * @returns {BigUint64Array} - Array of feature ids in BigUint64 format.\n */\nfunction generateBigUint64Array(featureIds) {\n const typedFeatureIds = new BigUint64Array(featureIds.length);\n for (let index = 0; index < featureIds.length; index++) {\n typedFeatureIds[index] = BigInt(featureIds[index]);\n }\n return typedFeatureIds;\n}\n\n/**\n * Generates draco compressed geometry\n * @param {Number} vertexCount\n * @param {Object} convertedAttributes\n * @returns {Promise<object>} - COmpressed geometry.\n */\nasync function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {\n const {positions, normals, texCoords, colors, featureIds, faceRange} = attributes;\n const indices = new Uint32Array(vertexCount);\n\n for (let index = 0; index < indices.length; index++) {\n indices.set([index], index);\n }\n\n const featureIndices = new Uint32Array(\n convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount\n );\n\n const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);\n\n const compressedAttributes = {\n positions,\n normals,\n colors,\n 'feature-index': featureIndex\n };\n\n if (texCoords.length) {\n compressedAttributes.texCoords = texCoords;\n }\n\n const attributesMetadata = {\n 'feature-index': {\n 'i3s-attribute-type': 'feature-index',\n 'i3s-feature-ids': new Int32Array(featureIds)\n }\n };\n\n return new Uint8Array(\n await encode({attributes: compressedAttributes, indices}, DracoWriter, {\n draco: {\n method: 'MESH_SEQUENTIAL_ENCODING',\n attributesMetadata\n }\n })\n );\n}\n\n/**\n * Generates ordered feature indices based on face range\n * @param {Uint32Array} featureIndex\n * @param {Uint32Array} faceRange\n * @returns {Uint32Array}\n */\nfunction generateFeatureIndexAttribute(featureIndex, faceRange) {\n const orderedFeatureIndices = new Uint32Array(featureIndex.length);\n let fillIndex = 0;\n let startIndex = 0;\n\n for (let index = 1; index < faceRange.length; index += 2) {\n const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;\n\n orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);\n\n fillIndex++;\n startIndex = endIndex + 1;\n }\n\n return orderedFeatureIndices;\n}\n"],"file":"geometry-converter.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-converter.js"],"names":["VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","scratchVector","Vector3","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","useCartesianPositions","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","gltf","materials","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","values","attributes","boundingVolumes","positions","cartographicOrigin","obb","center","index","vertex","subarray","Ellipsoid","WGS84","cartesianToCartographic","Array","from","getHeight","subtract","set","vertexCount","triangleCount","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","fileBuffer","Uint8Array","buffer","ArrayBuffer","generateCompressedGeometry","Float32Array","compressedGeometry","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","keys","attrKey","delete","reduce","acc","value","concat","matrix","Matrix4","node","convertNode","getCompositeTransformationMatrix","transformationMatrix","nodeMatrix","rotation","scale","translation","multiplyRight","rotateXYZ","translate","mesh","convertMesh","children","content","primitives","primitive","outputAttributes","transformVertexArray","vertices","POSITION","cartesianModelMatrix","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIdsByAttributeName","args","newVertices","coordIndex","vertexVector","x","y","z","calleeArgs","transform","transformAsVector","newTexCoords","fill","texCoord","colorsAttribute","components","newColors","colorIndex","color","colorUint8","j","batchedIds","newBatchIds","batchIds","possibleBatchIdAttributeName","sourceMaterials","convertMaterial","doubleSided","emissiveFactor","map","c","Math","round","alphaMode","toLowerCase","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfMaterials","i3sResources","materialDefinitionInfos","gltfMaterial","convertGLTFMaterialToI3sSharedResources","materialDefinitionInfo","textureDefinitionInfo","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","Vector4","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","toArray","encoding","mimeType","images","generateImageId","size","image","width","data","height","levelCountOfTexture","indexOfLevel","indexOfTextureInStore","zerosCount","toString","rightHalf","repeat","shiftedLevelCountOfTexture","shiftedIndexOfLevel","shiftedWidth","shiftedHeight","leftHalf","imageId","BigInt","batchTable","replaceMap","getFeaturesReplaceMap","replaceIndicesByUnique","featureMap","oldFeatureId","uniqueFeatureId","getOrCreateUniqueFeatureId","generateStringFromBatchTableByIndex","str","key","batchTableStr","hash","includes","indexOf","indicesArray","attributeBuffers","batchTableWithFeatureIds","OBJECTID","type","getAttributeType","attributeBuffer","generateShortIntegerAttributeBuffer","generateDoubleAttributeBuffer","generateStringAttributeBuffer","attribute","find","attr","name","attributeValues","valueType","count","valuesArray","padding","Float64Array","batchAttributes","stringCountArray","totalNumberOfBytes","stringSizesArray","stringBufferArray","currentString","String","currentStringBuffer","Buffer","currentStringSize","totalBytes","concatenateArrayBuffers","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array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AgDA,SAASF,6BAAT,CAAuCD,YAAvC,EAAqDlN,SAArD,EAAgE;AAC9D,MAAMyN,qBAAqB,GAAG,IAAI/M,WAAJ,CAAgBwM,YAAY,CAAC9O,MAA7B,CAA9B;AACA,MAAIsP,SAAS,GAAG,CAAhB;AACA,MAAIC,UAAU,GAAG,CAAjB;;AAEA,OAAK,IAAIxO,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGa,SAAS,CAAC5B,MAAtC,EAA8Ce,KAAK,IAAI,CAAvD,EAA0D;AACxD,QAAMyO,QAAQ,GAAG,CAAC5N,SAAS,CAACb,KAAD,CAAT,GAAmB,CAApB,IAAyB/C,iBAA1C;AAEAqR,IAAAA,qBAAqB,CAACrI,IAAtB,CAA2BsI,SAA3B,EAAsCC,UAAtC,EAAkDC,QAAlD;AAEAF,IAAAA,SAAS;AACTC,IAAAA,UAAU,GAAGC,QAAQ,GAAG,CAAxB;AACD;;AAED,SAAOH,qBAAP;AACD","sourcesContent":["import {Vector3, Matrix4, Vector4} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nimport {DracoWriter} from '@loaders.gl/draco';\nimport {encode, assert} from '@loaders.gl/core';\nimport {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';\nimport md5 from 'md5';\nimport {generateAttributes} from './geometry-attributes';\nimport {createBoundingVolumesFromGeometry} from './coordinate-converter';\n\nconst VALUES_PER_VERTEX = 3;\nconst VALUES_PER_TEX_COORD = 2;\nconst VALUES_PER_COLOR_ELEMENT = 4;\n\nconst STRING_TYPE = 'string';\nconst SHORT_INT_TYPE = 'Int32';\nconst DOUBLE_TYPE = 'Float64';\nconst OBJECT_ID_TYPE = 'Oid32';\n/*\n * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.\n * _BATCHID - Default attribute name which includes batch info.\n * BATCHID - Legacy attribute name which includes batch info.\n */\nconst BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];\n\nlet scratchVector = new Vector3();\n\nexport default async function convertB3dmToI3sGeometry(\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco,\n generateBoundingVolumes,\n geoidHeightModel\n) {\n const useCartesianPositions = generateBoundingVolumes;\n const materialAndTextureList = convertMaterials(tileContent);\n const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);\n\n if (generateBoundingVolumes) {\n _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);\n }\n\n if (convertedAttributesMap.has('default')) {\n materialAndTextureList.push({\n material: getDefaultMaterial()\n });\n }\n\n const result = [];\n let nodesCounter = nodeId;\n let {materials = []} = tileContent.gltf;\n if (!materials?.length) {\n materials.push({id: 'default'});\n }\n for (let i = 0; i < materials.length; i++) {\n const sourceMaterial = materials[i];\n if (!convertedAttributesMap.has(sourceMaterial.id)) {\n continue; // eslint-disable-line no-continue\n }\n const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);\n const {material, texture} = materialAndTextureList[i];\n result.push(\n await _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId: nodesCounter,\n featuresHashArray,\n attributeStorageInfo,\n draco\n })\n );\n nodesCounter++;\n }\n\n if (!result.length) {\n return null;\n }\n return result;\n}\n\n/**\n * Create bounding volumes based on positions\n * @param convertedAttributesMap\n * @param geoidHeightModel\n */\nfunction _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {\n for (const attributes of convertedAttributesMap.values()) {\n const boundingVolumes = createBoundingVolumesFromGeometry(\n attributes.positions,\n geoidHeightModel\n );\n\n attributes.boundingVolumes = boundingVolumes;\n const cartographicOrigin = boundingVolumes.obb.center;\n\n for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {\n const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);\n Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);\n scratchVector[2] =\n scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);\n scratchVector = scratchVector.subtract(cartographicOrigin);\n attributes.positions.set(scratchVector, index);\n }\n }\n}\n\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n}) {\n const boundingVolumes = convertedAttributes.boundingVolumes;\n const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;\n const triangleCount = vertexCount / 3;\n const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =\n generateAttributes({triangleCount, ...convertedAttributes});\n\n if (tileContent.batchTableJson) {\n makeFeatureIdsUnique(\n featureIds,\n convertedAttributes.featureIndices,\n featuresHashArray,\n tileContent.batchTableJson\n );\n }\n\n const header = new Uint32Array(2);\n const typedFeatureIds = generateBigUint64Array(featureIds);\n\n header.set([vertexCount, featureCount], 0);\n const fileBuffer = new Uint8Array(\n concatenateArrayBuffers(\n header.buffer,\n positions.buffer,\n normals.buffer,\n texture ? texCoords.buffer : new ArrayBuffer(0),\n colors.buffer,\n typedFeatureIds.buffer,\n faceRange.buffer\n )\n );\n const compressedGeometry = draco\n ? await generateCompressedGeometry(vertexCount, convertedAttributes, {\n positions,\n normals,\n texCoords: texture ? texCoords : new Float32Array(0),\n colors,\n featureIds,\n faceRange\n })\n : null;\n\n const attributes = convertBatchTableToAttributeBuffers(\n tileContent.batchTableJson,\n featureIds,\n attributeStorageInfo\n );\n\n return {\n geometry: fileBuffer,\n compressedGeometry,\n texture,\n sharedResources: getSharedResources(tileContent, nodeId),\n meshMaterial: material,\n vertexCount,\n attributes,\n featureCount,\n boundingVolumes\n };\n}\n\n/**\n * Convert attributes from the gltf nodes tree to i3s plain geometry\n * @param {Object} tileContent - 3d tile content\n * @returns {Map}\n * Map<{\n * positions: Float32Array,\n * normals: Float32Array,\n * colors: Uint8Array,\n * texCoords: Float32Array\n * }>\n * @todo implement colors support (if applicable for gltf format)\n */\nfunction convertAttributes(tileContent, useCartesianPositions) {\n const attributesMap = new Map();\n\n for (const material of tileContent.gltf.materials || [{id: 'default'}]) {\n attributesMap.set(material.id, {\n positions: new Float32Array(0),\n normals: new Float32Array(0),\n texCoords: new Float32Array(0),\n colors: new Uint8Array(0),\n featureIndices: [],\n boundingVolumes: null\n });\n }\n\n const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;\n convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);\n\n for (const attrKey of attributesMap.keys()) {\n const attributes = attributesMap.get(attrKey);\n if (attributes.positions.length === 0) {\n attributesMap.delete(attrKey);\n continue; // eslint-disable-line no-continue\n }\n attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));\n }\n\n return attributesMap;\n}\n\n/**\n * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.\n * The goal is applying tranformation matrix for all children. Functions \"convertNodes\" and \"convertNode\" work together recursively.\n * @param {Object[]} nodes - gltf nodes array\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: UInt8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns {void}\n */\nfunction convertNodes(\n nodes,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n if (nodes) {\n for (const node of nodes) {\n convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);\n }\n }\n}\n\n/**\n * Generate transformation matrix for node\n * Aapply all gltf transformations to initial transformation matrix.\n * @param node\n * @param matrix\n */\nfunction getCompositeTransformationMatrix(node, matrix) {\n let transformationMatrix = matrix;\n\n const {matrix: nodeMatrix, rotation, scale, translation} = node;\n\n if (nodeMatrix) {\n transformationMatrix = matrix.multiplyRight(nodeMatrix);\n }\n\n if (rotation) {\n transformationMatrix = transformationMatrix.rotateXYZ(rotation);\n }\n\n if (scale) {\n transformationMatrix = transformationMatrix.scale(scale);\n }\n\n if (translation) {\n transformationMatrix = transformationMatrix.translate(translation);\n }\n\n return transformationMatrix;\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} node - gltf node\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertNode(\n node,\n tileContent,\n attributesMap,\n useCartesianPositions,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n const transformationMatrix = getCompositeTransformationMatrix(node, matrix);\n\n const mesh = node.mesh;\n if (mesh) {\n convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);\n }\n\n convertNodes(\n node.children,\n tileContent,\n attributesMap,\n useCartesianPositions,\n transformationMatrix\n );\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} mesh - gltf node\n * @param {Object} content - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertMesh(\n mesh,\n content,\n attributesMap,\n useCartesianPositions = false,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n for (const primitive of mesh.primitives) {\n let outputAttributes = null;\n if (primitive.material) {\n outputAttributes = attributesMap.get(primitive.material.id);\n } else if (attributesMap.has('default')) {\n outputAttributes = attributesMap.get('default');\n }\n assert(outputAttributes !== null, 'Primitive - material mapping failed');\n const attributes = primitive.attributes;\n\n outputAttributes.positions = concatenateTypedArrays(\n outputAttributes.positions,\n transformVertexArray({\n vertices: attributes.POSITION.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexPositions,\n useCartesianPositions\n })\n );\n outputAttributes.normals = concatenateTypedArrays(\n outputAttributes.normals,\n transformVertexArray({\n vertices: attributes.NORMAL && attributes.NORMAL.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexNormals,\n useCartesianPositions: false\n })\n );\n outputAttributes.texCoords = concatenateTypedArrays(\n outputAttributes.texCoords,\n flattenTexCoords(\n attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value,\n primitive.indices.value\n )\n );\n\n outputAttributes.colors = concatenateTypedArrays(\n outputAttributes.colors,\n flattenColors(attributes.COLOR_0, primitive.indices.value)\n );\n\n outputAttributes.featureIndices.push(\n flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value)\n );\n }\n}\n\n/**\n * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format\n * @param {object} args - source tile (3DTile)\n * @param {Float32Array} args.vertices - gltf primitive POSITION or NORMAL attribute\n * @param {Object} args.cartographicOrigin - cartographic origin coordinates\n * @param {Object} args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param {Matrix4} args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param {Uint8Array} args.indices - gltf primitive indices\n * @param {Function} args.attributeSpecificTransformation - function to do attribute - specific transformations\n * @param {Boolean} args.useCartesianPositions - use coordinates as it is.\n * @returns {Float32Array}\n */\nfunction transformVertexArray(args) {\n const {vertices, indices, attributeSpecificTransformation} = args;\n const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);\n if (!vertices) {\n return newVertices;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_VERTEX;\n const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);\n let vertexVector = new Vector3(Array.from(vertex));\n\n vertexVector = attributeSpecificTransformation(vertexVector, args);\n\n newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;\n newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;\n newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;\n }\n return newVertices;\n}\n\nfunction transformVertexPositions(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, cartographicOrigin, nodeMatrix, useCartesianPositions} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transform(nodeMatrix);\n }\n\n vertexVector = vertexVector.transform(cartesianModelMatrix);\n\n if (useCartesianPositions) {\n return vertexVector;\n }\n\n Ellipsoid.WGS84.cartesianToCartographic(\n [vertexVector[0], vertexVector[1], vertexVector[2]],\n vertexVector\n );\n vertexVector = vertexVector.subtract(cartographicOrigin);\n return vertexVector;\n}\n\nfunction transformVertexNormals(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, nodeMatrix} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transformAsVector(nodeMatrix);\n }\n\n vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);\n return vertexVector;\n}\n\n/**\n * Convert uv0 (texture coordinates) from coords based on indices to plain arrays, compatible with i3s\n * @param {Float32Array} texCoords - gltf primitive TEXCOORD_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Float32Array}\n */\nfunction flattenTexCoords(texCoords, indices) {\n const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);\n if (!texCoords) {\n // We need dummy UV0s because it is required in 1.6\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.6/vertexAttribute.cmn.md\n newTexCoords.fill(1);\n return newTexCoords;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_TEX_COORD;\n const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);\n newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];\n newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];\n }\n return newTexCoords;\n}\n\n/**\n * Convert color from COLOR_0 based on indices to plain arrays, compatible with i3s\n * @param {object} colorsAttribute - gltf primitive COLOR_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Uint8Array}\n */\nfunction flattenColors(colorsAttribute, indices) {\n const components = colorsAttribute?.components || VALUES_PER_COLOR_ELEMENT;\n const newColors = new Uint8Array(indices.length * components);\n if (!colorsAttribute) {\n // Vertex color multiplies by material color so it must be normalized 1 by default\n newColors.fill(255);\n return newColors;\n }\n const colors = colorsAttribute.value;\n for (let i = 0; i < indices.length; i++) {\n const colorIndex = indices[i] * components;\n const color = colors.subarray(colorIndex, colorIndex + components);\n const colorUint8 = new Uint8Array(components);\n for (let j = 0; j < color.length; j++) {\n colorUint8[j] = color[j] * 255;\n }\n newColors.set(colorUint8, i * components);\n }\n return newColors;\n}\n\n/**\n * Flatten batchedIds list based on indices to right ordered array, compatible with i3s\n * @param {Array} batchedIds - gltf primitive\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Array}\n */\nfunction flattenBatchIds(batchedIds, indices) {\n if (!batchedIds.length || !indices.length) {\n return [];\n }\n const newBatchIds = [];\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i];\n newBatchIds.push(batchedIds[coordIndex]);\n }\n return newBatchIds;\n}\n/**\n * Return batchIds based on possible attribute names for different kind of maps.\n * @param {Object} attributes {attributeName: Float32Array}\n * @returns {Array}\n */\nfunction getBatchIdsByAttributeName(attributes) {\n let batchIds = [];\n\n for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {\n const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];\n if (\n attributes[possibleBatchIdAttributeName] &&\n attributes[possibleBatchIdAttributeName].value\n ) {\n batchIds = attributes[possibleBatchIdAttributeName].value;\n break;\n }\n }\n\n return batchIds;\n}\n\nfunction convertMaterials(tileContent) {\n const result = [];\n const sourceMaterials = tileContent.gltf.materials || [];\n for (const sourceMaterial of sourceMaterials) {\n result.push(convertMaterial(sourceMaterial));\n }\n return result;\n}\n\n/**\n * Convert texture and material from gltf 2.0 material object\n * @param {Object} sourceMaterial - material object\n * @returns {Object}\n */\nfunction convertMaterial(sourceMaterial) {\n const material = {\n doubleSided: sourceMaterial.doubleSided,\n emissiveFactor: sourceMaterial.emissiveFactor.map((c) => Math.round(c * 255)),\n // It is in upper case in GLTF: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#alpha-coverage\n // But it is in lower case in I3S: https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md\n alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),\n pbrMetallicRoughness: {\n roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,\n metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor\n }\n };\n\n let texture;\n if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {\n texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n } else if (sourceMaterial.emissiveTexture) {\n texture = sourceMaterial.emissiveTexture.texture.source;\n // ArcGIS webscene doesn't show emissiveTexture but shows baseColorTexture\n material.pbrMetallicRoughness.baseColorTexture = {\n textureSetDefinitionId: 0\n };\n }\n\n if (!texture) {\n // Should use default baseColorFactor if it is not present in source material\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness\n const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;\n material.pbrMetallicRoughness.baseColorFactor =\n (baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255))) || undefined;\n }\n\n return {material, texture};\n}\n\nfunction getDefaultMaterial() {\n return {\n alphaMode: 'opaque',\n pbrMetallicRoughness: {}\n };\n}\n\n/**\n * Form \"sharedResources\" from gltf materials array\n * @param {Object} tileContent - 3d tile content\n * @returns {Object} {materialDefinitionInfos: Object[], textureDefinitionInfos: Object[]} -\n * 2 arrays in format of i3s sharedResources data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/sharedResource.cmn.md\n */\nfunction getSharedResources(tileContent, nodeId) {\n const gltfMaterials = tileContent.gltf.materials;\n const i3sResources = {};\n\n if (!gltfMaterials || !gltfMaterials.length) {\n return i3sResources;\n }\n\n i3sResources.materialDefinitionInfos = [];\n for (const gltfMaterial of gltfMaterials) {\n const {materialDefinitionInfo, textureDefinitionInfo} = convertGLTFMaterialToI3sSharedResources(\n gltfMaterial,\n nodeId\n );\n i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);\n if (textureDefinitionInfo) {\n i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];\n i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);\n }\n }\n return i3sResources;\n}\n\n/**\n * Convert gltf material into I3S sharedResources data\n * @param {Object} gltfMaterial - gltf material data\n * @returns {Object} - Couple {materialDefinitionInfo, textureDefinitionInfo} extracted from gltf material data\n */\nfunction convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {\n const texture =\n gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;\n let textureDefinitionInfo = null;\n if (texture) {\n textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);\n }\n const {baseColorFactor, metallicFactor} = gltfMaterial.pbrMetallicRoughness;\n let colorFactor = baseColorFactor;\n // If alpha channel is 0 try to get emissive factor from gltf material.\n if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {\n colorFactor = gltfMaterial.emissiveFactor;\n colorFactor[3] = colorFactor[3] || 1;\n }\n\n return {\n materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),\n textureDefinitionInfo\n };\n}\n\n/**\n * Form \"materialDefinition\" which is part of \"sharedResouces\"\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materials\n * See formulas in appendix \"Appendix B: BRDF Implementation\":\n * const dielectricSpecular = rgb(0.04, 0.04, 0.04)\n * const black = rgb(0, 0, 0)\n * cdiff = lerp(baseColor.rgb * (1 - dielectricSpecular.r), black, metallic)\n * F0 = lerp(dieletricSpecular, baseColor.rgb, metallic)\n *\n * Assumption: F0 - specular in i3s (\"specular reflection\" <-> \"reflectance value at normal incidence\")\n * cdiff - diffuse in i3s (\"Diffuse color\" <-> \"'c' diffuse\" (c means color?))\n * @param {number[]} baseColorFactor - RGBA color in 0..1 format\n * @param {number} metallicFactor - \"metallicFactor\" attribute of gltf material object\n * @returns {Object}\n */\nfunction extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {\n const matDielectricColorComponent = 0.04 / 255; // Color from rgb (255) to 0..1 resolution\n // All color resolutions are 0..1\n const black = new Vector4(0, 0, 0, 1);\n const unitVector = new Vector4(1, 1, 1, 1);\n const dielectricSpecular = new Vector4(\n matDielectricColorComponent,\n matDielectricColorComponent,\n matDielectricColorComponent,\n 0\n );\n const baseColorVector = new Vector4(baseColorFactor);\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material\n // Formulas for Cdiff & F0\n const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);\n const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);\n dielectricSpecular[3] = 1;\n const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);\n return {\n diffuse: diffuse.toArray(),\n specular: specular.toArray()\n };\n}\n\n/**\n * Form \"textureDefinition\" which is part of \"sharedResouces\"\n * @param {Object} texture - texture image info\n * @returns {Object}\n */\nfunction extractSharedResourcesTextureInfo(texture, nodeId) {\n return {\n encoding: [texture.source.mimeType],\n images: [\n {\n // 'i3s' has just size which is width of the image. Images are supposed to be square.\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md\n id: generateImageId(texture, nodeId),\n size: texture.source.image.width,\n length: [texture.source.image.data.length]\n }\n ]\n };\n}\n/*\n * Formula for counting imageId:\n * https://github.com/Esri/i3s-spec/blob/0a6366a9249b831db8436c322f8d27521e86cf07/format/Indexed%203d%20Scene%20Layer%20Format%20Specification.md#generating-image-ids\n * @param {Object} texture - texture image info\n * @returns {string}\n */\nfunction generateImageId(texture, nodeId) {\n const {width, height} = texture.source.image;\n const levelCountOfTexture = 1;\n const indexOfLevel = 0;\n const indexOfTextureInStore = nodeId + 1;\n\n const zerosCount = 32 - indexOfTextureInStore.toString(2).length;\n const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));\n\n const shiftedLevelCountOfTexture = levelCountOfTexture << 28;\n const shiftedIndexOfLevel = indexOfLevel << 24;\n const shiftedWidth = (width - 1) << 12;\n const shiftedHeight = (height - 1) << 0;\n\n const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;\n const imageId = BigInt(`0b${leftHalf.toString(2)}${rightHalf}`);\n return imageId.toString();\n}\n\n/**\n * Make all feature ids unique through all nodes in layout.\n * @param {Array} featureIds\n * @param {Array} featureIndices\n * @param {Array} featuresHashArray\n * @param {Object} batchTable\n * @returns {void}\n */\nfunction makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {\n const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);\n replaceIndicesByUnique(featureIndices, replaceMap);\n replaceIndicesByUnique(featureIds, replaceMap);\n}\n\n/**\n * Generate replace map to make featureIds unique.\n * @param {Array} featureIds\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Object}\n */\nfunction getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {\n const featureMap = {};\n\n for (let index = 0; index < featureIds.length; index++) {\n const oldFeatureId = featureIds[index];\n const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);\n featureMap[oldFeatureId.toString()] = uniqueFeatureId;\n }\n\n return featureMap;\n}\n\n/**\n * Generates string for unique batch id creation.\n * @param {Object} batchTable\n * @param {Number} index\n * @returns {String}\n */\nfunction generateStringFromBatchTableByIndex(batchTable, index) {\n let str = '';\n for (const key in batchTable) {\n str += batchTable[key][index];\n }\n return str;\n}\n\n/**\n * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.\n * @param {Number} index\n * @param {Object} batchTable\n * @param {Array} featuresHashArray\n * @returns {Number}\n */\nfunction getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {\n const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);\n const hash = md5(batchTableStr);\n\n if (featuresHashArray.includes(hash)) {\n return featuresHashArray.indexOf(hash);\n }\n return featuresHashArray.push(hash) - 1;\n}\n\n/**\n * Do replacement of indices for making them unique through all nodes.\n * @param {Array} indicesArray\n * @param {Object} featureMap\n * @returns {void}\n */\nfunction replaceIndicesByUnique(indicesArray, featureMap) {\n for (let index = 0; index < indicesArray.length; index++) {\n indicesArray[index] = featureMap[indicesArray[index]];\n }\n}\n\n/**\n * Convert batch table data to attribute buffers.\n * @param {Object} batchTable - table with metadata for particular feature.\n * @param {Array} featureIds\n * @param {Array} attributeStorageInfo\n * @returns {Array} - Array of file buffers.\n */\nfunction convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {\n const attributeBuffers = [];\n\n if (batchTable) {\n const batchTableWithFeatureIds = {\n OBJECTID: featureIds,\n ...batchTable\n };\n\n for (const key in batchTableWithFeatureIds) {\n const type = getAttributeType(key, attributeStorageInfo);\n\n let attributeBuffer = null;\n\n switch (type) {\n case OBJECT_ID_TYPE:\n case SHORT_INT_TYPE:\n attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case DOUBLE_TYPE:\n attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n case STRING_TYPE:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n break;\n default:\n attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);\n }\n\n attributeBuffers.push(attributeBuffer);\n }\n }\n\n return attributeBuffers;\n}\n/**\n * Return attribute type.\n * @param {String} key\n * @param {Array} attributeStorageInfo\n * @returns {String} attribute type.\n */\nfunction getAttributeType(key, attributeStorageInfo) {\n const attribute = attributeStorageInfo.find((attr) => attr.name === key);\n return attribute.attributeValues.valueType;\n}\n\n/**\n * Convert short integer to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateShortIntegerAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const valuesArray = new Uint32Array(featureIds);\n return concatenateArrayBuffers(count.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert double to attribute arrayBuffer.\n * @param {Array} featureIds\n * @returns {ArrayBuffer} - Buffer with objectId data.\n */\nfunction generateDoubleAttributeBuffer(featureIds) {\n const count = new Uint32Array([featureIds.length]);\n const padding = new Uint8Array(4);\n const valuesArray = new Float64Array(featureIds);\n\n return concatenateArrayBuffers(count.buffer, padding.buffer, valuesArray.buffer);\n}\n\n/**\n * Convert batch table attributes to array buffer with batch table data.\n * @param {Array} batchAttributes\n * @returns {ArrayBuffer} - Buffer with batch table data.\n */\nfunction generateStringAttributeBuffer(batchAttributes) {\n const stringCountArray = new Uint32Array([batchAttributes.length]);\n let totalNumberOfBytes = 0;\n const stringSizesArray = new Uint32Array(batchAttributes.length);\n const stringBufferArray = [];\n\n for (let index = 0; index < batchAttributes.length; index++) {\n const currentString = `${String(batchAttributes[index])}\\0`;\n const currentStringBuffer = Buffer.from(currentString);\n const currentStringSize = currentStringBuffer.length;\n totalNumberOfBytes += currentStringSize;\n stringSizesArray[index] = currentStringSize;\n stringBufferArray.push(currentStringBuffer);\n }\n\n const totalBytes = new Uint32Array([totalNumberOfBytes]);\n\n return concatenateArrayBuffers(\n stringCountArray.buffer,\n totalBytes.buffer,\n stringSizesArray.buffer,\n ...stringBufferArray\n );\n}\n\n/**\n * Convert featureIds to BigUint64Array.\n * @param {Array} featureIds\n * @returns {BigUint64Array} - Array of feature ids in BigUint64 format.\n */\nfunction generateBigUint64Array(featureIds) {\n const typedFeatureIds = new BigUint64Array(featureIds.length);\n for (let index = 0; index < featureIds.length; index++) {\n typedFeatureIds[index] = BigInt(featureIds[index]);\n }\n return typedFeatureIds;\n}\n\n/**\n * Generates draco compressed geometry\n * @param {Number} vertexCount\n * @param {Object} convertedAttributes\n * @returns {Promise<object>} - COmpressed geometry.\n */\nasync function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {\n const {positions, normals, texCoords, colors, featureIds, faceRange} = attributes;\n const indices = new Uint32Array(vertexCount);\n\n for (let index = 0; index < indices.length; index++) {\n indices.set([index], index);\n }\n\n const featureIndices = new Uint32Array(\n convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount\n );\n\n const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);\n\n const compressedAttributes = {\n positions,\n normals,\n colors,\n 'feature-index': featureIndex\n };\n\n if (texCoords.length) {\n compressedAttributes.texCoords = texCoords;\n }\n\n const attributesMetadata = {\n 'feature-index': {\n 'i3s-attribute-type': 'feature-index',\n 'i3s-feature-ids': new Int32Array(featureIds)\n }\n };\n\n return new Uint8Array(\n await encode({attributes: compressedAttributes, indices}, DracoWriter, {\n draco: {\n method: 'MESH_SEQUENTIAL_ENCODING',\n attributesMetadata\n }\n })\n );\n}\n\n/**\n * Generates ordered feature indices based on face range\n * @param {Uint32Array} featureIndex\n * @param {Uint32Array} faceRange\n * @returns {Uint32Array}\n */\nfunction generateFeatureIndexAttribute(featureIndex, faceRange) {\n const orderedFeatureIndices = new Uint32Array(featureIndex.length);\n let fillIndex = 0;\n let startIndex = 0;\n\n for (let index = 1; index < faceRange.length; index += 2) {\n const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;\n\n orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);\n\n fillIndex++;\n startIndex = endIndex + 1;\n }\n\n return orderedFeatureIndices;\n}\n"],"file":"geometry-converter.js"}
@@ -14,7 +14,9 @@ var _core = require("@math.gl/core");
14
14
  var _geospatial = require("@math.gl/geospatial");
15
15
 
16
16
  function validateNodeBoundingVolumes(node) {
17
- if (!node.parentNode.obb || !node.parentNode.mbs) {
17
+ var _node$parentNode, _node$parentNode2;
18
+
19
+ if (!(node !== null && node !== void 0 && (_node$parentNode = node.parentNode) !== null && _node$parentNode !== void 0 && _node$parentNode.obb) || !(node !== null && node !== void 0 && (_node$parentNode2 = node.parentNode) !== null && _node$parentNode2 !== void 0 && _node$parentNode2.mbs)) {
18
20
  return [];
19
21
  }
20
22
 
@@ -25,6 +27,8 @@ function validateNodeBoundingVolumes(node) {
25
27
  }
26
28
 
27
29
  function validateObb(tileWarnings, node) {
30
+ var _node$parentNode3;
31
+
28
32
  var parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);
29
33
  var tileVertices = getTileObbVertices(node);
30
34
  var isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);
@@ -33,7 +37,7 @@ function validateObb(tileWarnings, node) {
33
37
  return;
34
38
  }
35
39
 
36
- var title = "OBB of Tile (".concat(node.id, ") doesn't fit into Parent (").concat(node.parentNode.id, ") tile OBB");
40
+ var title = "OBB of Tile (".concat(node.id, ") doesn't fit into Parent (").concat((_node$parentNode3 = node.parentNode) === null || _node$parentNode3 === void 0 ? void 0 : _node$parentNode3.id, ") tile OBB");
37
41
  tileWarnings.push(title);
38
42
  }
39
43
 
@@ -43,7 +47,9 @@ function validateMbs(tileWarnings, node) {
43
47
  var distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);
44
48
 
45
49
  if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {
46
- var title = "MBS of Tile (".concat(node.id, ") doesn't fit into Parent (").concat(node.parentNode.id, ") tile MBS");
50
+ var _node$parentNode4;
51
+
52
+ var title = "MBS of Tile (".concat(node.id, ") doesn't fit into Parent (").concat((_node$parentNode4 = node.parentNode) === null || _node$parentNode4 === void 0 ? void 0 : _node$parentNode4.id, ") tile MBS");
47
53
  tileWarnings.push(title);
48
54
  }
49
55
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/node-debug.ts"],"names":["validateNodeBoundingVolumes","node","parentNode","obb","mbs","tileWarnings","validateObb","validateMbs","parentObb","createBoundingBoxFromTileObb","tileVertices","getTileObbVertices","isTileObbInsideParentObb","isAllVerticesInsideBoundingVolume","title","id","push","tileMbs","createBoundingSphereFromTileMbs","parentMbs","distanceBetweenCenters","center","distanceTo","radius","BoundingSphere","halfSize","quaternion","OrientedBoundingBox","fromCenterHalfSizeQuaternion","geometry","CubeGeometry","attributes","getAttributes","positions","Float32Array","POSITION","value","obbCenterCartesian","Ellipsoid","WGS84","cartographicToCartesian","vertices","i","length","positionsVector","Vector3","rotatedPositions","transformByQuaternion","add","concat","boundingVolume","isVerticesInsideObb","index","point","cartographicPoint","cartesianToCartographic","distance"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAGO,SAASA,2BAAT,CAAqCC,IAArC,EAA2C;AAChD,MAAI,CAACA,IAAI,CAACC,UAAL,CAAgBC,GAAjB,IAAwB,CAACF,IAAI,CAACC,UAAL,CAAgBE,GAA7C,EAAkD;AAChD,WAAO,EAAP;AACD;;AACD,MAAMC,YAAY,GAAG,EAArB;AAEAC,EAAAA,WAAW,CAACD,YAAD,EAAeJ,IAAf,CAAX;AACAM,EAAAA,WAAW,CAACF,YAAD,EAAeJ,IAAf,CAAX;AAEA,SAAOI,YAAP;AACD;;AAED,SAASC,WAAT,CAAqBD,YAArB,EAAmCJ,IAAnC,EAAyC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AgBH,gBAAhB,CAAX;AACD;;AAED,SAAOL,QAAP;AACD;;AAED,SAAS5B,iCAAT,CAA2CqC,cAA3C,EAA2DjB,SAA3D,EAAsE;AACpE,MAAIkB,mBAAmB,GAAG,IAA1B;;AAEA,OAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGnB,SAAS,CAACU,MAAV,GAAmB,CAA/C,EAAkDS,KAAK,IAAI,CAA3D,EAA8D;AAC5D,QAAMC,KAAK,GAAG,CAACpB,SAAS,CAACmB,KAAD,CAAV,EAAmBnB,SAAS,CAACmB,KAAK,GAAG,CAAT,CAA5B,EAAyCnB,SAAS,CAACmB,KAAK,GAAG,CAAT,CAAlD,CAAd;;AACA,QAAME,iBAAiB,GAAGhB,sBAAUC,KAAV,CAAgBgB,uBAAhB,CAAwCF,KAAxC,CAA1B;;AAEA,QAAMG,QAAQ,GAAGN,cAAc,CAAC5B,UAAf,CAA0BgC,iBAA1B,CAAjB;;AAEA,QAAIE,QAAQ,GAAG,CAAf,EAAkB;AAChBL,MAAAA,mBAAmB,GAAG,KAAtB;AACA;AACD;AACF;;AAED,SAAOA,mBAAP;AACD","sourcesContent":["import {OrientedBoundingBox, BoundingSphere} from '@math.gl/culling';\nimport {CubeGeometry} from '@luma.gl/engine';\nimport {Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\n// TODO Unite Tile validation logic in i3s-17-and-debug with this code.\nexport function validateNodeBoundingVolumes(node) {\n if (!node.parentNode.obb || !node.parentNode.mbs) {\n return [];\n }\n const tileWarnings = [];\n\n validateObb(tileWarnings, node);\n validateMbs(tileWarnings, node);\n\n return tileWarnings;\n}\n\nfunction validateObb(tileWarnings, node) {\n const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);\n const tileVertices = getTileObbVertices(node);\n const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);\n\n if (isTileObbInsideParentObb) {\n return;\n }\n\n const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile OBB`;\n tileWarnings.push(title);\n}\n\nfunction validateMbs(tileWarnings, node) {\n const tileMbs = createBoundingSphereFromTileMbs(node.mbs);\n const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);\n const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);\n\n if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {\n const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile MBS`;\n tileWarnings.push(title);\n }\n}\n\nfunction createBoundingSphereFromTileMbs(mbs) {\n return new BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);\n}\n\nfunction createBoundingBoxFromTileObb(obb) {\n const {center, halfSize, quaternion} = obb;\n return new OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);\n}\n\n// TODO check if Obb generates properly\nfunction getTileObbVertices(node) {\n const geometry = new CubeGeometry();\n const halfSize = node.obb.halfSize;\n const attributes = geometry.getAttributes();\n const positions = new Float32Array(attributes.POSITION.value);\n const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);\n\n let vertices = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n const positionsVector = new Vector3(\n (positions[i] *= halfSize[0]),\n (positions[i + 1] *= halfSize[1]),\n (positions[i + 2] *= halfSize[2])\n );\n const rotatedPositions = positionsVector\n .transformByQuaternion(node.obb.quaternion)\n .add(obbCenterCartesian);\n // @ts-expect-error\n vertices = vertices.concat(rotatedPositions);\n }\n\n return vertices;\n}\n\nfunction isAllVerticesInsideBoundingVolume(boundingVolume, positions) {\n let isVerticesInsideObb = true;\n\n for (let index = 0; index < positions.length / 3; index += 3) {\n const point = [positions[index], positions[index + 1], positions[index + 2]];\n const cartographicPoint = Ellipsoid.WGS84.cartesianToCartographic(point);\n\n const distance = boundingVolume.distanceTo(cartographicPoint);\n\n if (distance > 0) {\n isVerticesInsideObb = false;\n break;\n }\n }\n\n return isVerticesInsideObb;\n}\n"],"file":"node-debug.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/node-debug.ts"],"names":["validateNodeBoundingVolumes","node","parentNode","obb","mbs","tileWarnings","validateObb","validateMbs","parentObb","createBoundingBoxFromTileObb","tileVertices","getTileObbVertices","isTileObbInsideParentObb","isAllVerticesInsideBoundingVolume","title","id","push","tileMbs","createBoundingSphereFromTileMbs","parentMbs","distanceBetweenCenters","center","distanceTo","radius","BoundingSphere","halfSize","quaternion","OrientedBoundingBox","fromCenterHalfSizeQuaternion","geometry","CubeGeometry","attributes","getAttributes","positions","Float32Array","POSITION","value","obbCenterCartesian","Ellipsoid","WGS84","cartographicToCartesian","vertices","i","length","positionsVector","Vector3","rotatedPositions","transformByQuaternion","add","concat","boundingVolume","isVerticesInsideObb","index","point","cartographicPoint","cartesianToCartographic","distance"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AACA;;AASO,SAASA,2BAAT,CAAqCC,IAArC,EAA0E;AAAA;;AAC/E,MAAI,EAACA,IAAD,aAACA,IAAD,mCAACA,IAAI,CAAEC,UAAP,6CAAC,iBAAkBC,GAAnB,KAA0B,EAACF,IAAD,aAACA,IAAD,oCAACA,IAAI,CAAEC,UAAP,8CAAC,kBAAkBE,GAAnB,CAA9B,EAAsD;AACpD,WAAO,EAAP;AACD;;AAED,MAAMC,YAAsB,GAAG,EAA/B;AAEAC,EAAAA,WAAW,CAACD,YAAD,EAAeJ,IAAf,CAAX;AACAM,EAAAA,WAAW,CAACF,YAAD,EAAeJ,IAAf,CAAX;AAEA,SAAOI,YAAP;AACD;;AAOD,SAASC,WAAT,CAAqBD,YAArB,EAA6CJ,IAA7C,EAA8E;AAAA;;AAE5E,MAAMO,SAAS,GAAGC,4BAA4B,CAACR,IAAI,CAACC,UAAL,CAAgBC,GAAjB,CAA9C;AACA,MAAMO,YAAY,GAAGC,kBAAkB,CAACV,IAAD,CAAvC;AACA,MAAMW,wBAAwB,GAAGC,iCAAiC,CAACL,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1B;;AAEA,OAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGnB,SAAS,CAACU,MAAV,GAAmB,CAA/C,EAAkDS,KAAK,IAAI,CAA3D,EAA8D;AAC5D,QAAMC,KAAK,GAAG,CAACpB,SAAS,CAACmB,KAAD,CAAV,EAAmBnB,SAAS,CAACmB,KAAK,GAAG,CAAT,CAA5B,EAAyCnB,SAAS,CAACmB,KAAK,GAAG,CAAT,CAAlD,CAAd;;AACA,QAAME,iBAAiB,GAAGhB,sBAAUC,KAAV,CAAgBgB,uBAAhB,CAAwCF,KAAxC,CAA1B;;AAEA,QAAMG,QAAQ,GAAGN,cAAc,CAAC5B,UAAf,CAA0BgC,iBAA1B,CAAjB;;AAEA,QAAIE,QAAQ,GAAG,CAAf,EAAkB;AAChBL,MAAAA,mBAAmB,GAAG,KAAtB;AACA;AACD;AACF;;AAED,SAAOA,mBAAP;AACD","sourcesContent":["import type {Mbs, Node3DIndexDocument, Obb} from '@loaders.gl/i3s';\n\nimport {OrientedBoundingBox, BoundingSphere} from '@math.gl/culling';\nimport {CubeGeometry} from '@luma.gl/engine';\nimport {Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\n// TODO Unite Tile validation logic in i3s-17-and-debug with this code.\n\n/**\n * Do validation of bounding volumes for particular node.\n * Generates special warnings if there are some issues.\n * @param node\n */\nexport function validateNodeBoundingVolumes(node: Node3DIndexDocument): string[] {\n if (!node?.parentNode?.obb || !node?.parentNode?.mbs) {\n return [];\n }\n\n const tileWarnings: string[] = [];\n\n validateObb(tileWarnings, node);\n validateMbs(tileWarnings, node);\n\n return tileWarnings;\n}\n\n/**\n * Check if child Obb fit into parent Obb.\n * @param tileWarnings\n * @param node\n */\nfunction validateObb(tileWarnings: string[], node: Node3DIndexDocument): void {\n // @ts-expect-error\n const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);\n const tileVertices = getTileObbVertices(node);\n const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);\n\n if (isTileObbInsideParentObb) {\n return;\n }\n\n const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode?.id}) tile OBB`;\n tileWarnings.push(title);\n}\n\n/**\n * Check if child Mbs fit into parent Mbs.\n * @param tileWarnings\n * @param node\n */\nfunction validateMbs(tileWarnings: string[], node: Node3DIndexDocument): void {\n // @ts-expect-error\n const tileMbs = createBoundingSphereFromTileMbs(node.mbs);\n // @ts-expect-error\n const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);\n const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);\n\n if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {\n const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode?.id}) tile MBS`;\n tileWarnings.push(title);\n }\n}\n\n/**\n * Generates bounding sphere from mbs\n * @param mbs\n */\nfunction createBoundingSphereFromTileMbs(mbs: Mbs): BoundingSphere {\n return new BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);\n}\n\n/**\n * Generates oriented bounding box from tile obb\n * @param obb\n * @returns\n */\nfunction createBoundingBoxFromTileObb(obb: Obb): OrientedBoundingBox {\n const {center, halfSize, quaternion} = obb;\n return new OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);\n}\n\n/**\n * Get vertices fromnode obb\n * TODO check if Obb generates properly\n * @param node\n */\nfunction getTileObbVertices(node: Node3DIndexDocument): number[] {\n const geometry = new CubeGeometry();\n // @ts-expect-error\n const halfSize = node.obb.halfSize;\n const attributes = geometry.getAttributes();\n const positions = new Float32Array(attributes.POSITION.value);\n // @ts-expect-error\n const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);\n\n let vertices = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n const positionsVector = new Vector3(\n (positions[i] *= halfSize[0]),\n (positions[i + 1] *= halfSize[1]),\n (positions[i + 2] *= halfSize[2])\n );\n const rotatedPositions = positionsVector\n // @ts-expect-error\n .transformByQuaternion(node.obb.quaternion)\n .add(obbCenterCartesian);\n // @ts-expect-error\n vertices = vertices.concat(rotatedPositions);\n }\n\n return vertices;\n}\n\n/**\n * Check if all vertices inside bounding volume\n * @param boundingVolume\n * @param positions\n */\nfunction isAllVerticesInsideBoundingVolume(\n boundingVolume: OrientedBoundingBox,\n positions: number[]\n): boolean {\n let isVerticesInsideObb = true;\n\n for (let index = 0; index < positions.length / 3; index += 3) {\n const point = [positions[index], positions[index + 1], positions[index + 2]];\n const cartographicPoint = Ellipsoid.WGS84.cartesianToCartographic(point);\n\n const distance = boundingVolume.distanceTo(cartographicPoint);\n\n if (distance > 0) {\n isVerticesInsideObb = false;\n break;\n }\n }\n\n return isVerticesInsideObb;\n}\n"],"file":"node-debug.js"}
@@ -1389,30 +1389,32 @@ var I3SConverter = function () {
1389
1389
  key: "writeTextureFile",
1390
1390
  value: function () {
1391
1391
  var _writeTextureFile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee16(textureData, name, format, childPath, slpkChildPath) {
1392
- var texturePath, slpkTexturePath, compress;
1392
+ var slpkTexturePath, compress, texturePath;
1393
1393
  return _regenerator.default.wrap(function _callee16$(_context16) {
1394
1394
  while (1) {
1395
1395
  switch (_context16.prev = _context16.next) {
1396
1396
  case 0:
1397
- texturePath = (0, _path.join)(childPath, "textures/".concat(name, "/"));
1398
- _context16.next = 3;
1399
- return (0, _fileUtils.writeFile)(texturePath, textureData, "index.".concat(format));
1400
-
1401
- case 3:
1402
1397
  if (!this.options.slpk) {
1403
- _context16.next = 9;
1398
+ _context16.next = 8;
1404
1399
  break;
1405
1400
  }
1406
1401
 
1407
1402
  slpkTexturePath = (0, _path.join)(childPath, 'textures');
1408
1403
  compress = false;
1409
- _context16.next = 8;
1404
+ _context16.next = 5;
1410
1405
  return (0, _fileUtils.writeFileForSlpk)(slpkTexturePath, textureData, "".concat(name, ".").concat(format), compress);
1411
1406
 
1412
- case 8:
1407
+ case 5:
1413
1408
  this.fileMap["".concat(slpkChildPath, "/textures/").concat(name, ".").concat(format)] = _context16.sent;
1409
+ _context16.next = 11;
1410
+ break;
1414
1411
 
1415
- case 9:
1412
+ case 8:
1413
+ texturePath = (0, _path.join)(childPath, "textures/".concat(name, "/"));
1414
+ _context16.next = 11;
1415
+ return (0, _fileUtils.writeFile)(texturePath, textureData, "index.".concat(format));
1416
+
1417
+ case 11:
1416
1418
  case "end":
1417
1419
  return _context16.stop();
1418
1420
  }