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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +1 -1
  2. package/dist/3d-tiles-attributes-worker.js +2 -2
  3. package/dist/3d-tiles-attributes-worker.js.map +2 -2
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -5
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +21 -17
  7. package/dist/converter.min.js +1 -1
  8. package/dist/dist.min.js +2 -2
  9. package/dist/es5/3d-tiles-attributes-worker.js +2 -2
  10. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  11. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +27 -19
  12. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  13. package/dist/es5/deps-installer/deps-installer.js +1 -1
  14. package/dist/es5/i3s-attributes-worker.js +1 -1
  15. package/dist/es5/pgm-loader.js +1 -1
  16. package/dist/es5/workers/3d-tiles-attributes-worker.js +1 -1
  17. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
  18. package/dist/esm/3d-tiles-attributes-worker.js +2 -2
  19. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
  20. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +25 -15
  21. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  22. package/dist/esm/deps-installer/deps-installer.js +1 -1
  23. package/dist/esm/i3s-attributes-worker.js +1 -1
  24. package/dist/esm/pgm-loader.js +1 -1
  25. package/dist/esm/workers/3d-tiles-attributes-worker.js +1 -1
  26. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -1
  27. package/dist/i3s-attributes-worker.js.map +1 -1
  28. package/dist/workers/3d-tiles-attributes-worker.js +1 -1
  29. package/package.json +15 -15
  30. package/src/3d-tiles-attributes-worker.ts +1 -1
  31. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +25 -18
  32. package/src/workers/3d-tiles-attributes-worker.ts +1 -1
package/dist/dist.min.js CHANGED
@@ -73578,7 +73578,7 @@ function getTransferListForWriter(object) {
73578
73578
  }
73579
73579
  const clone2 = Object.assign({}, object);
73580
73580
  Object.keys(clone2).forEach((key) => {
73581
- if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key])) {
73581
+ if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
73582
73582
  clone2[key] = getTransferListForWriter(object[key]);
73583
73583
  } else if (typeof clone2[key] === "function" || clone2[key] instanceof RegExp) {
73584
73584
  clone2[key] = {};
@@ -87853,7 +87853,7 @@ var Tile3dAttributesWorker = {
87853
87853
  module: "tile-converter",
87854
87854
  version: VERSION16,
87855
87855
  options: {
87856
- attributes: null
87856
+ featureAttributes: null
87857
87857
  }
87858
87858
  };
87859
87859
  function transform3DTilesAttributesOnWorker(i3sAttributesData, options) {
@@ -8,14 +8,14 @@ exports._typecheckI3SAttributesWorker = exports.Tile3dAttributesWorker = void 0;
8
8
 
9
9
  var _workerUtils = require("@loaders.gl/worker-utils");
10
10
 
11
- var VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
11
+ var VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'latest';
12
12
  var Tile3dAttributesWorker = {
13
13
  id: '3d-tiles-attributes',
14
14
  name: '3DTiles Attributes Worker',
15
15
  module: 'tile-converter',
16
16
  version: VERSION,
17
17
  options: {
18
- attributes: null
18
+ featureAttributes: null
19
19
  }
20
20
  };
21
21
  exports.Tile3dAttributesWorker = Tile3dAttributesWorker;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/3d-tiles-attributes-worker.ts"],"names":["VERSION","Tile3dAttributesWorker","id","name","module","version","options","attributes","transform3DTilesAttributesOnWorker","i3sAttributesData","_typecheckI3SAttributesWorker"],"mappings":";;;;;;;;AAGA;;AAIA,IAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAeO,IAAMC,sBAAsB,GAAG;AACpCC,EAAAA,EAAE,EAAE,qBADgC;AAEpCC,EAAAA,IAAI,EAAE,2BAF8B;AAGpCC,EAAAA,MAAM,EAAE,gBAH4B;AAIpCC,EAAAA,OAAO,EAAEL,OAJ2B;AAKpCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,UAAU,EAAE;AADL;AAL2B,CAA/B;;;AAaA,SAASC,kCAAT,CACLC,iBADK,EAELH,OAFK,EAGiB;AACtB,SAAO,kCAAgBL,sBAAhB,EAAwCQ,iBAAxC,EAA2DH,OAA3D,CAAP;AACD;;AAEM,IAAMI,6BAA2C,GAAGT,sBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {FeatureAttribute} from '@loaders.gl/i3s';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type Tile3DAttributesWorkerOptions = {\n featureAttributes: FeatureAttribute | null;\n source: string;\n};\n\nexport type I3SAttributesData = {\n tileContent: any;\n textureFormat: string;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const Tile3dAttributesWorker = {\n id: '3d-tiles-attributes',\n name: '3DTiles Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n attributes: null\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transform3DTilesAttributesOnWorker(\n i3sAttributesData: I3SAttributesData,\n options: Tile3DAttributesWorkerOptions\n): Promise<ArrayBuffer> {\n return processOnWorker(Tile3dAttributesWorker, i3sAttributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = Tile3dAttributesWorker;\n"],"file":"3d-tiles-attributes-worker.js"}
1
+ {"version":3,"sources":["../../src/3d-tiles-attributes-worker.ts"],"names":["VERSION","Tile3dAttributesWorker","id","name","module","version","options","featureAttributes","transform3DTilesAttributesOnWorker","i3sAttributesData","_typecheckI3SAttributesWorker"],"mappings":";;;;;;;;AAGA;;AAIA,IAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAeO,IAAMC,sBAAsB,GAAG;AACpCC,EAAAA,EAAE,EAAE,qBADgC;AAEpCC,EAAAA,IAAI,EAAE,2BAF8B;AAGpCC,EAAAA,MAAM,EAAE,gBAH4B;AAIpCC,EAAAA,OAAO,EAAEL,OAJ2B;AAKpCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,iBAAiB,EAAE;AADZ;AAL2B,CAA/B;;;AAaA,SAASC,kCAAT,CACLC,iBADK,EAELH,OAFK,EAGiB;AACtB,SAAO,kCAAgBL,sBAAhB,EAAwCQ,iBAAxC,EAA2DH,OAA3D,CAAP;AACD;;AAEM,IAAMI,6BAA2C,GAAGT,sBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {FeatureAttribute} from '@loaders.gl/i3s';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type Tile3DAttributesWorkerOptions = {\n featureAttributes: FeatureAttribute | null;\n source: string;\n};\n\nexport type I3SAttributesData = {\n tileContent: any;\n textureFormat: string;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const Tile3dAttributesWorker = {\n id: '3d-tiles-attributes',\n name: '3DTiles Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n featureAttributes: null\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transform3DTilesAttributesOnWorker(\n i3sAttributesData: I3SAttributesData,\n options: Tile3DAttributesWorkerOptions\n): Promise<ArrayBuffer> {\n return processOnWorker(Tile3dAttributesWorker, i3sAttributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = Tile3dAttributesWorker;\n"],"file":"3d-tiles-attributes-worker.js"}
@@ -57,7 +57,7 @@ var B3dmConverter = function () {
57
57
  case 0:
58
58
  featureAttributes = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
59
59
  _context.next = 3;
60
- return this.buildGltf(i3sAttributesData);
60
+ return this.buildGltf(i3sAttributesData, featureAttributes);
61
61
 
62
62
  case 3:
63
63
  gltf = _context.sent;
@@ -86,7 +86,7 @@ var B3dmConverter = function () {
86
86
  }, {
87
87
  key: "buildGltf",
88
88
  value: function () {
89
- var _buildGltf = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(i3sAttributesData) {
89
+ var _buildGltf = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(i3sAttributesData, featureAttributes) {
90
90
  var tileContent, textureFormat, material, attributes, originalIndices, cartesianOrigin, cartographicOrigin, modelMatrix, gltfBuilder, textureIndex, pbrMaterialInfo, materialIndex, positions, positionsValue, indices, meshIndex, transformMatrix, nodeIndex, sceneIndex, gltfBuffer;
91
91
  return _regenerator.default.wrap(function _callee2$(_context2) {
92
92
  while (1) {
@@ -111,6 +111,8 @@ var B3dmConverter = function () {
111
111
 
112
112
  attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
113
113
 
114
+ this._createBatchIds(tileContent, featureAttributes);
115
+
114
116
  if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
115
117
  delete attributes.normals;
116
118
  }
@@ -135,7 +137,7 @@ var B3dmConverter = function () {
135
137
  gltfBuffer = (0, _core.encodeSync)(gltfBuilder.gltf, _gltf.GLTFWriter);
136
138
  return _context2.abrupt("return", gltfBuffer);
137
139
 
138
- case 22:
140
+ case 23:
139
141
  case "end":
140
142
  return _context2.stop();
141
143
  }
@@ -143,7 +145,7 @@ var B3dmConverter = function () {
143
145
  }, _callee2, this);
144
146
  }));
145
147
 
146
- function buildGltf(_x2) {
148
+ function buildGltf(_x2, _x3) {
147
149
  return _buildGltf.apply(this, arguments);
148
150
  }
149
151
 
@@ -185,7 +187,7 @@ var B3dmConverter = function () {
185
187
  }, _callee3, this);
186
188
  }));
187
189
 
188
- function _addI3sTextureToGltf(_x3, _x4, _x5) {
190
+ function _addI3sTextureToGltf(_x4, _x5, _x6) {
189
191
  return _addI3sTextureToGltf2.apply(this, arguments);
190
192
  }
191
193
 
@@ -217,22 +219,28 @@ var B3dmConverter = function () {
217
219
  return result;
218
220
  }
219
221
  }, {
220
- key: "_generateBatchId",
221
- value: function _generateBatchId(faceRanges) {
222
- var batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;
223
- var batchId = new Float32Array(batchIdArraySize);
224
- var rangeIndex = 0;
225
- var currentBatchId = 0;
226
-
227
- for (var index = 0; index < faceRanges.length / 2; index++) {
228
- var fromIndex = faceRanges[rangeIndex] * 3;
229
- var untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;
230
- batchId.fill(currentBatchId, fromIndex, untilPosition);
231
- rangeIndex += 2;
232
- currentBatchId += 1;
222
+ key: "_createBatchIds",
223
+ value: function _createBatchIds(i3sContent, featureAttributes) {
224
+ var featureIds = i3sContent.featureIds;
225
+
226
+ var _ref = featureAttributes || {},
227
+ objectIds = _ref.OBJECTID;
228
+
229
+ if (!featureIds || !objectIds) {
230
+ return;
231
+ }
232
+
233
+ for (var i = 0; i < featureIds.length; i++) {
234
+ var featureId = featureIds[i];
235
+ var batchId = objectIds.indexOf(featureId);
236
+ featureIds[i] = batchId;
233
237
  }
234
238
 
235
- return batchId;
239
+ i3sContent.attributes._BATCHID = {
240
+ size: 1,
241
+ byteOffset: 0,
242
+ value: featureIds
243
+ };
236
244
  }
237
245
  }, {
238
246
  key: "_generateSynteticIndices",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/3d-tiles-converter/helpers/b3dm-converter.ts"],"names":["Z_UP_TO_Y_UP_MATRIX","Matrix4","scratchVector","Vector3","B3dmConverter","i3sAttributesData","featureAttributes","buildGltf","gltf","b3dm","gltfEncoded","Uint8Array","type","featuresLength","_getFeaturesLength","batchTable","Tile3DWriter","tileContent","textureFormat","material","attributes","originalIndices","indices","cartesianOrigin","cartographicOrigin","modelMatrix","gltfBuilder","GLTFScenegraph","_addI3sTextureToGltf","textureIndex","pbrMaterialInfo","_convertI3sMaterialToGltfMaterial","materialIndex","addMaterial","positions","positionsValue","value","uvRegions","texCoords","_normalizePositions","normals","_checkNormals","_generateSynteticIndices","length","size","meshIndex","addMesh","mode","transformMatrix","_generateTransformMatrix","nodeIndex","addNode","matrix","sceneIndex","addScene","nodeIndices","setDefaultScene","createBinaryChunk","gltfBuffer","GLTFWriter","texture","selectedTexture","pbrMetallicRoughness","baseColorTexture","source","image","mimeType","_deduceMimeTypeFromFormat","imageIndex","addImage","addTexture","colors","newPositionsValue","Float32Array","index","vertex","subarray","cartesianOriginVector","vertexVector","Array","from","transform","add","Ellipsoid","WGS84","cartographicToCartesian","subtract","set","translateOriginMatrix","translate","result","multiplyLeft","faceRanges","batchIdArraySize","batchId","rangeIndex","currentBatchId","fromIndex","untilPosition","fill","vertexCount","Uint32Array","format","console","warn","isTextureIndexExists","alphaMode","doubleSided","metallicFactor","roughnessFactor","texCoord","baseColorFactor","_setGltfTexture","materialDefinition","emissiveTexture","metallicRoughnessTexture","normalTexture","occlusionTexture","firstKey","Object","keys","find"],"mappings":";;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,mBAAmB,GAAG,IAAIC,cAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAC,CAApB,EAAuB,CAAvB,EAA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AO,CAACiF,IAAR,CAAa,UAACrF,KAAD;AAAA,eAAWA,KAAX;AAAA,OAAb,CAAP;AACD","sourcesContent":["import type {I3SAttributesData} from '../../3d-tiles-attributes-worker';\n\nimport {encodeSync} from '@loaders.gl/core';\nimport {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';\nimport {Tile3DWriter} from '@loaders.gl/3d-tiles';\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {convertTextureAtlas} from './texture-atlas';\n\nconst Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);\nconst scratchVector = new Vector3();\n\n/**\n * Converts content of an I3S node to *.b3dm's file content\n */\nexport default class B3dmConverter {\n // @ts-expect-error\n rtcCenter: Float32Array;\n i3sTile: any;\n\n /**\n * The starter of content conversion\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded content\n */\n async convert(\n i3sAttributesData: I3SAttributesData,\n featureAttributes: any = null\n ): Promise<ArrayBuffer> {\n const gltf = await this.buildGltf(i3sAttributesData);\n const b3dm = encodeSync(\n {\n gltfEncoded: new Uint8Array(gltf),\n type: 'b3dm',\n featuresLength: this._getFeaturesLength(featureAttributes),\n batchTable: featureAttributes\n },\n Tile3DWriter\n );\n return b3dm;\n }\n\n /**\n * Build and encode gltf\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded glb content\n */\n async buildGltf(i3sAttributesData: I3SAttributesData): Promise<ArrayBuffer> {\n const {tileContent, textureFormat} = i3sAttributesData;\n const {\n material,\n attributes,\n indices: originalIndices,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n } = tileContent;\n const gltfBuilder = new GLTFScenegraph();\n\n const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);\n const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);\n const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);\n\n const positions = attributes.positions;\n const positionsValue = positions.value;\n\n if (attributes.uvRegions && attributes.texCoords) {\n attributes.texCoords.value = convertTextureAtlas(\n attributes.texCoords.value,\n attributes.uvRegions.value\n );\n }\n\n attributes.positions.value = this._normalizePositions(\n positionsValue,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n );\n if (attributes.normals && !this._checkNormals(attributes.normals.value)) {\n delete attributes.normals;\n }\n const indices =\n originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);\n const meshIndex = gltfBuilder.addMesh({\n attributes,\n indices,\n material: materialIndex,\n mode: 4\n });\n const transformMatrix = this._generateTransformMatrix(cartesianOrigin);\n const nodeIndex = gltfBuilder.addNode({meshIndex, matrix: transformMatrix});\n const sceneIndex = gltfBuilder.addScene({nodeIndices: [nodeIndex]});\n gltfBuilder.setDefaultScene(sceneIndex);\n\n gltfBuilder.createBinaryChunk();\n\n const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);\n\n return gltfBuffer;\n }\n\n /**\n * Update gltfBuilder with texture from I3S tile\n * @param {object} i3sTile - Tile3D object\n * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF\n * @returns {Promise<number | null>} - GLTF texture index\n */\n async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {\n const {texture, material, attributes} = tileContent;\n let textureIndex = null;\n let selectedTexture = texture;\n if (!texture && material) {\n selectedTexture =\n material.pbrMetallicRoughness &&\n material.pbrMetallicRoughness.baseColorTexture &&\n material.pbrMetallicRoughness.baseColorTexture.texture.source.image;\n }\n if (selectedTexture) {\n const mimeType = this._deduceMimeTypeFromFormat(textureFormat);\n const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);\n textureIndex = gltfBuilder.addTexture({imageIndex});\n delete attributes.colors;\n }\n return textureIndex;\n }\n\n /**\n * Generate a positions array which is correct for 3DTiles/GLTF format\n * @param {Float64Array} positionsValue - the input geometry positions array\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system\n * @param {number[]} modelMatrix - the model matrix of geometry\n * @returns {Float32Array} - the output geometry positions array\n */\n _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {\n const newPositionsValue = new Float32Array(positionsValue.length);\n for (let index = 0; index < positionsValue.length; index += 3) {\n const vertex = positionsValue.subarray(index, index + 3);\n const cartesianOriginVector = new Vector3(cartesianOrigin);\n let vertexVector = new Vector3(Array.from(vertex))\n .transform(modelMatrix)\n .add(cartographicOrigin);\n Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);\n vertexVector = scratchVector.subtract(cartesianOriginVector);\n newPositionsValue.set(vertexVector, index);\n }\n return newPositionsValue;\n }\n\n /**\n * Generate the transformation matrix for GLTF node:\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node\n * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)\n * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)\n */\n _generateTransformMatrix(cartesianOrigin) {\n const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);\n const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);\n return result;\n }\n\n /**\n * Generate batchId attribute from faceRanges.\n * @param {Uint32Array} faceRanges - the source array\n * @returns {Float32Array} batchId list.\n */\n _generateBatchId(faceRanges) {\n const batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;\n const batchId = new Float32Array(batchIdArraySize);\n let rangeIndex = 0;\n let currentBatchId = 0;\n\n for (let index = 0; index < faceRanges.length / 2; index++) {\n const fromIndex = faceRanges[rangeIndex] * 3;\n const untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;\n\n batchId.fill(currentBatchId, fromIndex, untilPosition);\n rangeIndex += 2;\n currentBatchId += 1;\n }\n return batchId;\n }\n\n /**\n * luma.gl can not work without indices now:\n * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115\n * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]\n * @param {number} vertexCount - vertex count in the geometry\n * @returns {Uint32Array} indices array.\n */\n _generateSynteticIndices(vertexCount) {\n const result = new Uint32Array(vertexCount);\n for (let index = 0; index < vertexCount; index++) {\n result.set([index], index);\n }\n return result;\n }\n\n /**\n * Deduce mime type by format from `textureSetDefinition.formats[0].format`\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n * @param {string} format - format name\n * @returns {string} mime type.\n */\n _deduceMimeTypeFromFormat(format) {\n switch (format) {\n case 'jpg':\n return 'image/jpeg';\n case 'png':\n return 'image/png';\n case 'ktx2':\n return 'image/ktx2';\n default:\n console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef\n return 'image/jpeg';\n }\n }\n\n /**\n * Convert i3s material to GLTF compatible material\n * @param {object} material - i3s material definition\n * @param {number | null} textureIndex - texture index in GLTF\n * @returns {object} GLTF material\n */\n _convertI3sMaterialToGltfMaterial(material, textureIndex) {\n const isTextureIndexExists = textureIndex !== null;\n\n if (!material) {\n material = {\n alphaMode: 'OPAQUE',\n doubleSided: false,\n pbrMetallicRoughness: {\n metallicFactor: 0,\n roughnessFactor: 1\n }\n };\n\n if (isTextureIndexExists) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else {\n material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];\n }\n\n return material;\n }\n\n if (textureIndex !== null) {\n material = this._setGltfTexture(material, textureIndex);\n }\n\n return material;\n }\n\n /**\n * Set texture properties in material with GLTF textureIndex\n * @param {object} materialDefinition - i3s material definition\n * @param {number} textureIndex - texture index in GLTF\n * @returns {void}\n */\n _setGltfTexture(materialDefinition, textureIndex) {\n const material = {\n ...materialDefinition,\n pbrMetallicRoughness: {...materialDefinition.pbrMetallicRoughness}\n };\n // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of\n // properties defined in materialDefinition\n if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.baseColorTexture\n ) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.emissiveTexture) {\n material.emissiveTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture\n ) {\n material.pbrMetallicRoughness.metallicRoughnessTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.normalTexture) {\n material.normalTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.occlusionTexture) {\n material.occlusionTexture = {\n index: textureIndex,\n texCoord: 0\n };\n }\n return material;\n }\n\n /*\n * Returns Features length based on attribute array in attribute object.\n * @param {Object} attributes\n * @returns {Number} Features length .\n */\n _getFeaturesLength(attributes) {\n if (!attributes) {\n return 0;\n }\n const firstKey = Object.keys(attributes)[0];\n return firstKey ? attributes[firstKey].length : 0;\n }\n\n /* Checks that normals buffer is correct\n * @param {TypedArray} normals\n * @returns {boolean} true - normals are correct; false - normals are incorrect\n */\n _checkNormals(normals) {\n // If all normals === 0, the resulting tileset is all in black colors on Cesium\n return normals.find((value) => value);\n }\n}\n"],"file":"b3dm-converter.js"}
1
+ {"version":3,"sources":["../../../../src/3d-tiles-converter/helpers/b3dm-converter.ts"],"names":["Z_UP_TO_Y_UP_MATRIX","Matrix4","scratchVector","Vector3","B3dmConverter","i3sAttributesData","featureAttributes","buildGltf","gltf","b3dm","gltfEncoded","Uint8Array","type","featuresLength","_getFeaturesLength","batchTable","Tile3DWriter","tileContent","textureFormat","material","attributes","originalIndices","indices","cartesianOrigin","cartographicOrigin","modelMatrix","gltfBuilder","GLTFScenegraph","_addI3sTextureToGltf","textureIndex","pbrMaterialInfo","_convertI3sMaterialToGltfMaterial","materialIndex","addMaterial","positions","positionsValue","value","uvRegions","texCoords","_normalizePositions","_createBatchIds","normals","_checkNormals","_generateSynteticIndices","length","size","meshIndex","addMesh","mode","transformMatrix","_generateTransformMatrix","nodeIndex","addNode","matrix","sceneIndex","addScene","nodeIndices","setDefaultScene","createBinaryChunk","gltfBuffer","GLTFWriter","texture","selectedTexture","pbrMetallicRoughness","baseColorTexture","source","image","mimeType","_deduceMimeTypeFromFormat","imageIndex","addImage","addTexture","colors","newPositionsValue","Float32Array","index","vertex","subarray","cartesianOriginVector","vertexVector","Array","from","transform","add","Ellipsoid","WGS84","cartographicToCartesian","subtract","set","translateOriginMatrix","translate","result","multiplyLeft","i3sContent","featureIds","objectIds","OBJECTID","i","featureId","batchId","indexOf","_BATCHID","byteOffset","vertexCount","Uint32Array","format","console","warn","isTextureIndexExists","alphaMode","doubleSided","metallicFactor","roughnessFactor","texCoord","baseColorFactor","_setGltfTexture","materialDefinition","emissiveTexture","metallicRoughnessTexture","normalTexture","occlusionTexture","firstKey","Object","keys","find"],"mappings":";;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,mBAAmB,GAAG,IAAIC,cAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAC,CAApB,EAAuB,CAAvB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmC,CAAnC,EAAsC,CAAtC,EAAyC,CAAzC,EAA4C,CAA5C,EAA+C,CAA/C,CAAZ,CAA5B;AACA,IAAMC,aAAa,GAAG,IAAIC,cAAJ,EAAtB;;IAKqBC,a;;;;;;;;;;+EAUnB,iBACEC,iBADF;AAAA;AAAA;AAAA;AAAA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core';\nimport {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';\nimport {Tile3DWriter} from '@loaders.gl/3d-tiles';\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {convertTextureAtlas} from './texture-atlas';\n\nconst Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);\nconst scratchVector = new Vector3();\n\n/**\n * Converts content of an I3S node to *.b3dm's file content\n */\nexport default class B3dmConverter {\n // @ts-expect-error\n rtcCenter: Float32Array;\n i3sTile: any;\n\n /**\n * The starter of content conversion\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded content\n */\n async convert(\n i3sAttributesData: I3SAttributesData,\n featureAttributes: any = null\n ): Promise<ArrayBuffer> {\n const gltf = await this.buildGltf(i3sAttributesData, featureAttributes);\n const b3dm = encodeSync(\n {\n gltfEncoded: new Uint8Array(gltf),\n type: 'b3dm',\n featuresLength: this._getFeaturesLength(featureAttributes),\n batchTable: featureAttributes\n },\n Tile3DWriter\n );\n return b3dm;\n }\n\n /**\n * Build and encode gltf\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded glb content\n */\n async buildGltf(\n i3sAttributesData: I3SAttributesData,\n featureAttributes: any\n ): Promise<ArrayBuffer> {\n const {tileContent, textureFormat} = i3sAttributesData;\n const {\n material,\n attributes,\n indices: originalIndices,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n } = tileContent;\n const gltfBuilder = new GLTFScenegraph();\n\n const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);\n const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);\n const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);\n\n const positions = attributes.positions;\n const positionsValue = positions.value;\n\n if (attributes.uvRegions && attributes.texCoords) {\n attributes.texCoords.value = convertTextureAtlas(\n attributes.texCoords.value,\n attributes.uvRegions.value\n );\n }\n\n attributes.positions.value = this._normalizePositions(\n positionsValue,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n );\n this._createBatchIds(tileContent, featureAttributes);\n if (attributes.normals && !this._checkNormals(attributes.normals.value)) {\n delete attributes.normals;\n }\n const indices =\n originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);\n const meshIndex = gltfBuilder.addMesh({\n attributes,\n indices,\n material: materialIndex,\n mode: 4\n });\n const transformMatrix = this._generateTransformMatrix(cartesianOrigin);\n const nodeIndex = gltfBuilder.addNode({meshIndex, matrix: transformMatrix});\n const sceneIndex = gltfBuilder.addScene({nodeIndices: [nodeIndex]});\n gltfBuilder.setDefaultScene(sceneIndex);\n\n gltfBuilder.createBinaryChunk();\n\n const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);\n\n return gltfBuffer;\n }\n\n /**\n * Update gltfBuilder with texture from I3S tile\n * @param {object} i3sTile - Tile3D object\n * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF\n * @returns {Promise<number | null>} - GLTF texture index\n */\n async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {\n const {texture, material, attributes} = tileContent;\n let textureIndex = null;\n let selectedTexture = texture;\n if (!texture && material) {\n selectedTexture =\n material.pbrMetallicRoughness &&\n material.pbrMetallicRoughness.baseColorTexture &&\n material.pbrMetallicRoughness.baseColorTexture.texture.source.image;\n }\n if (selectedTexture) {\n const mimeType = this._deduceMimeTypeFromFormat(textureFormat);\n const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);\n textureIndex = gltfBuilder.addTexture({imageIndex});\n delete attributes.colors;\n }\n return textureIndex;\n }\n\n /**\n * Generate a positions array which is correct for 3DTiles/GLTF format\n * @param {Float64Array} positionsValue - the input geometry positions array\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system\n * @param {number[]} modelMatrix - the model matrix of geometry\n * @returns {Float32Array} - the output geometry positions array\n */\n _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {\n const newPositionsValue = new Float32Array(positionsValue.length);\n for (let index = 0; index < positionsValue.length; index += 3) {\n const vertex = positionsValue.subarray(index, index + 3);\n const cartesianOriginVector = new Vector3(cartesianOrigin);\n let vertexVector = new Vector3(Array.from(vertex))\n .transform(modelMatrix)\n .add(cartographicOrigin);\n Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);\n vertexVector = scratchVector.subtract(cartesianOriginVector);\n newPositionsValue.set(vertexVector, index);\n }\n return newPositionsValue;\n }\n\n /**\n * Generate the transformation matrix for GLTF node:\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node\n * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)\n * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)\n */\n _generateTransformMatrix(cartesianOrigin) {\n const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);\n const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);\n return result;\n }\n\n /**\n * Create _BATCHID attribute\n * @param {Object} i3sContent - the source object\n * @returns {void}\n */\n _createBatchIds(i3sContent, featureAttributes) {\n const {featureIds} = i3sContent;\n const {OBJECTID: objectIds} = featureAttributes || {};\n if (!featureIds || !objectIds) {\n return;\n }\n\n for (let i = 0; i < featureIds.length; i++) {\n const featureId = featureIds[i];\n const batchId = objectIds.indexOf(featureId);\n featureIds[i] = batchId;\n }\n\n i3sContent.attributes._BATCHID = {\n size: 1,\n byteOffset: 0,\n value: featureIds\n };\n }\n\n /**\n * luma.gl can not work without indices now:\n * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115\n * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]\n * @param {number} vertexCount - vertex count in the geometry\n * @returns {Uint32Array} indices array.\n */\n _generateSynteticIndices(vertexCount) {\n const result = new Uint32Array(vertexCount);\n for (let index = 0; index < vertexCount; index++) {\n result.set([index], index);\n }\n return result;\n }\n\n /**\n * Deduce mime type by format from `textureSetDefinition.formats[0].format`\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n * @param {string} format - format name\n * @returns {string} mime type.\n */\n _deduceMimeTypeFromFormat(format) {\n switch (format) {\n case 'jpg':\n return 'image/jpeg';\n case 'png':\n return 'image/png';\n case 'ktx2':\n return 'image/ktx2';\n default:\n console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef\n return 'image/jpeg';\n }\n }\n\n /**\n * Convert i3s material to GLTF compatible material\n * @param {object} material - i3s material definition\n * @param {number | null} textureIndex - texture index in GLTF\n * @returns {object} GLTF material\n */\n _convertI3sMaterialToGltfMaterial(material, textureIndex) {\n const isTextureIndexExists = textureIndex !== null;\n\n if (!material) {\n material = {\n alphaMode: 'OPAQUE',\n doubleSided: false,\n pbrMetallicRoughness: {\n metallicFactor: 0,\n roughnessFactor: 1\n }\n };\n\n if (isTextureIndexExists) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else {\n material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];\n }\n\n return material;\n }\n\n if (textureIndex !== null) {\n material = this._setGltfTexture(material, textureIndex);\n }\n\n return material;\n }\n\n /**\n * Set texture properties in material with GLTF textureIndex\n * @param {object} materialDefinition - i3s material definition\n * @param {number} textureIndex - texture index in GLTF\n * @returns {void}\n */\n _setGltfTexture(materialDefinition, textureIndex) {\n const material = {\n ...materialDefinition,\n pbrMetallicRoughness: {...materialDefinition.pbrMetallicRoughness}\n };\n // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of\n // properties defined in materialDefinition\n if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.baseColorTexture\n ) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.emissiveTexture) {\n material.emissiveTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture\n ) {\n material.pbrMetallicRoughness.metallicRoughnessTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.normalTexture) {\n material.normalTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.occlusionTexture) {\n material.occlusionTexture = {\n index: textureIndex,\n texCoord: 0\n };\n }\n return material;\n }\n\n /*\n * Returns Features length based on attribute array in attribute object.\n * @param {Object} attributes\n * @returns {Number} Features length .\n */\n _getFeaturesLength(attributes) {\n if (!attributes) {\n return 0;\n }\n const firstKey = Object.keys(attributes)[0];\n return firstKey ? attributes[firstKey].length : 0;\n }\n\n /* Checks that normals buffer is correct\n * @param {TypedArray} normals\n * @returns {boolean} true - normals are correct; false - normals are incorrect\n */\n _checkNormals(normals) {\n // If all normals === 0, the resulting tileset is all in black colors on Cesium\n return normals.find((value) => value);\n }\n}\n"],"file":"b3dm-converter.js"}
@@ -23,7 +23,7 @@ var _fileUtils = require("../lib/utils/file-utils");
23
23
 
24
24
  var _path = require("path");
25
25
 
26
- var VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'beta';
26
+ var VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'beta';
27
27
  var PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';
28
28
 
29
29
  var DepsInstaller = function () {
@@ -8,7 +8,7 @@ exports._typecheckI3SAttributesWorker = exports.I3SAttributesWorker = void 0;
8
8
 
9
9
  var _workerUtils = require("@loaders.gl/worker-utils");
10
10
 
11
- var VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
11
+ var VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'latest';
12
12
  var I3SAttributesWorker = {
13
13
  id: 'i3s-attributes',
14
14
  name: 'I3S Attributes Worker',
@@ -13,7 +13,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
13
13
 
14
14
  var _geoid = require("@math.gl/geoid");
15
15
 
16
- var VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
16
+ var VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'latest';
17
17
  var PGMLoader = {
18
18
  name: 'PGM - Netpbm grayscale image format',
19
19
  id: 'pgm',
@@ -20,7 +20,7 @@ var b3dmConverter = new _b3dmConverter.default();
20
20
  switch (_context.prev = _context.next) {
21
21
  case 0:
22
22
  options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
23
- return _context.abrupt("return", b3dmConverter.convert(data, options.attributes));
23
+ return _context.abrupt("return", b3dmConverter.convert(data, options.featureAttributes));
24
24
 
25
25
  case 2:
26
26
  case "end":
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/workers/3d-tiles-attributes-worker.ts"],"names":["b3dmConverter","B3dmConverter","data","options","convert","attributes"],"mappings":";;;;;;;;AAAA;;AACA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,sBAAJ,EAAtB;AAEA;AAAA,uEAAa,iBAAOC,IAAP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAaC,YAAAA,OAAb,2DAAuB,EAAvB;AAAA,6CAA8BH,aAAa,CAACI,OAAd,CAAsBF,IAAtB,EAA4BC,OAAO,CAACE,UAApC,CAA9B;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAb;;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';\n\nconst b3dmConverter = new B3dmConverter();\n\ncreateWorker(async (data, options = {}) => b3dmConverter.convert(data, options.attributes));\n"],"file":"3d-tiles-attributes-worker.js"}
1
+ {"version":3,"sources":["../../../src/workers/3d-tiles-attributes-worker.ts"],"names":["b3dmConverter","B3dmConverter","data","options","convert","featureAttributes"],"mappings":";;;;;;;;AAAA;;AACA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,sBAAJ,EAAtB;AAEA;AAAA,uEAAa,iBAAOC,IAAP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAaC,YAAAA,OAAb,2DAAuB,EAAvB;AAAA,6CAA8BH,aAAa,CAACI,OAAd,CAAsBF,IAAtB,EAA4BC,OAAO,CAACE,iBAApC,CAA9B;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAb;;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';\n\nconst b3dmConverter = new B3dmConverter();\n\ncreateWorker(async (data, options = {}) => b3dmConverter.convert(data, options.featureAttributes));\n"],"file":"3d-tiles-attributes-worker.js"}
@@ -1,12 +1,12 @@
1
1
  import { processOnWorker } from '@loaders.gl/worker-utils';
2
- const VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
2
+ const VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'latest';
3
3
  export const Tile3dAttributesWorker = {
4
4
  id: '3d-tiles-attributes',
5
5
  name: '3DTiles Attributes Worker',
6
6
  module: 'tile-converter',
7
7
  version: VERSION,
8
8
  options: {
9
- attributes: null
9
+ featureAttributes: null
10
10
  }
11
11
  };
12
12
  export function transform3DTilesAttributesOnWorker(i3sAttributesData, options) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/3d-tiles-attributes-worker.ts"],"names":["processOnWorker","VERSION","Tile3dAttributesWorker","id","name","module","version","options","attributes","transform3DTilesAttributesOnWorker","i3sAttributesData","_typecheckI3SAttributesWorker"],"mappings":"AAGA,SAAQA,eAAR,QAA8B,0BAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAeA,OAAO,MAAMC,sBAAsB,GAAG;AACpCC,EAAAA,EAAE,EAAE,qBADgC;AAEpCC,EAAAA,IAAI,EAAE,2BAF8B;AAGpCC,EAAAA,MAAM,EAAE,gBAH4B;AAIpCC,EAAAA,OAAO,EAAEL,OAJ2B;AAKpCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,UAAU,EAAE;AADL;AAL2B,CAA/B;AAaP,OAAO,SAASC,kCAAT,CACLC,iBADK,EAELH,OAFK,EAGiB;AACtB,SAAOP,eAAe,CAACE,sBAAD,EAAyBQ,iBAAzB,EAA4CH,OAA5C,CAAtB;AACD;AAED,OAAO,MAAMI,6BAA2C,GAAGT,sBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {FeatureAttribute} from '@loaders.gl/i3s';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type Tile3DAttributesWorkerOptions = {\n featureAttributes: FeatureAttribute | null;\n source: string;\n};\n\nexport type I3SAttributesData = {\n tileContent: any;\n textureFormat: string;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const Tile3dAttributesWorker = {\n id: '3d-tiles-attributes',\n name: '3DTiles Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n attributes: null\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transform3DTilesAttributesOnWorker(\n i3sAttributesData: I3SAttributesData,\n options: Tile3DAttributesWorkerOptions\n): Promise<ArrayBuffer> {\n return processOnWorker(Tile3dAttributesWorker, i3sAttributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = Tile3dAttributesWorker;\n"],"file":"3d-tiles-attributes-worker.js"}
1
+ {"version":3,"sources":["../../src/3d-tiles-attributes-worker.ts"],"names":["processOnWorker","VERSION","Tile3dAttributesWorker","id","name","module","version","options","featureAttributes","transform3DTilesAttributesOnWorker","i3sAttributesData","_typecheckI3SAttributesWorker"],"mappings":"AAGA,SAAQA,eAAR,QAA8B,0BAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAeA,OAAO,MAAMC,sBAAsB,GAAG;AACpCC,EAAAA,EAAE,EAAE,qBADgC;AAEpCC,EAAAA,IAAI,EAAE,2BAF8B;AAGpCC,EAAAA,MAAM,EAAE,gBAH4B;AAIpCC,EAAAA,OAAO,EAAEL,OAJ2B;AAKpCM,EAAAA,OAAO,EAAE;AACPC,IAAAA,iBAAiB,EAAE;AADZ;AAL2B,CAA/B;AAaP,OAAO,SAASC,kCAAT,CACLC,iBADK,EAELH,OAFK,EAGiB;AACtB,SAAOP,eAAe,CAACE,sBAAD,EAAyBQ,iBAAzB,EAA4CH,OAA5C,CAAtB;AACD;AAED,OAAO,MAAMI,6BAA2C,GAAGT,sBAApD","sourcesContent":["import type {WorkerObject} from '@loaders.gl/worker-utils';\nimport type {FeatureAttribute} from '@loaders.gl/i3s';\n\nimport {processOnWorker} from '@loaders.gl/worker-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type Tile3DAttributesWorkerOptions = {\n featureAttributes: FeatureAttribute | null;\n source: string;\n};\n\nexport type I3SAttributesData = {\n tileContent: any;\n textureFormat: string;\n};\n\n/**\n * I3S Attributes Worker to handle B3DM object\n */\nexport const Tile3dAttributesWorker = {\n id: '3d-tiles-attributes',\n name: '3DTiles Attributes Worker',\n module: 'tile-converter',\n version: VERSION,\n options: {\n featureAttributes: null\n }\n};\n\n/**\n * Performs I3S attributes transformation\n */\nexport function transform3DTilesAttributesOnWorker(\n i3sAttributesData: I3SAttributesData,\n options: Tile3DAttributesWorkerOptions\n): Promise<ArrayBuffer> {\n return processOnWorker(Tile3dAttributesWorker, i3sAttributesData, options);\n}\n\nexport const _typecheckI3SAttributesWorker: WorkerObject = Tile3dAttributesWorker;\n"],"file":"3d-tiles-attributes-worker.js"}
@@ -15,7 +15,7 @@ export default class B3dmConverter {
15
15
  }
16
16
 
17
17
  async convert(i3sAttributesData, featureAttributes = null) {
18
- const gltf = await this.buildGltf(i3sAttributesData);
18
+ const gltf = await this.buildGltf(i3sAttributesData, featureAttributes);
19
19
  const b3dm = encodeSync({
20
20
  gltfEncoded: new Uint8Array(gltf),
21
21
  type: 'b3dm',
@@ -25,7 +25,7 @@ export default class B3dmConverter {
25
25
  return b3dm;
26
26
  }
27
27
 
28
- async buildGltf(i3sAttributesData) {
28
+ async buildGltf(i3sAttributesData, featureAttributes) {
29
29
  const {
30
30
  tileContent,
31
31
  textureFormat
@@ -53,6 +53,8 @@ export default class B3dmConverter {
53
53
 
54
54
  attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
55
55
 
56
+ this._createBatchIds(tileContent, featureAttributes);
57
+
56
58
  if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
57
59
  delete attributes.normals;
58
60
  }
@@ -128,21 +130,29 @@ export default class B3dmConverter {
128
130
  return result;
129
131
  }
130
132
 
131
- _generateBatchId(faceRanges) {
132
- const batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;
133
- const batchId = new Float32Array(batchIdArraySize);
134
- let rangeIndex = 0;
135
- let currentBatchId = 0;
136
-
137
- for (let index = 0; index < faceRanges.length / 2; index++) {
138
- const fromIndex = faceRanges[rangeIndex] * 3;
139
- const untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;
140
- batchId.fill(currentBatchId, fromIndex, untilPosition);
141
- rangeIndex += 2;
142
- currentBatchId += 1;
133
+ _createBatchIds(i3sContent, featureAttributes) {
134
+ const {
135
+ featureIds
136
+ } = i3sContent;
137
+ const {
138
+ OBJECTID: objectIds
139
+ } = featureAttributes || {};
140
+
141
+ if (!featureIds || !objectIds) {
142
+ return;
143
143
  }
144
144
 
145
- return batchId;
145
+ for (let i = 0; i < featureIds.length; i++) {
146
+ const featureId = featureIds[i];
147
+ const batchId = objectIds.indexOf(featureId);
148
+ featureIds[i] = batchId;
149
+ }
150
+
151
+ i3sContent.attributes._BATCHID = {
152
+ size: 1,
153
+ byteOffset: 0,
154
+ value: featureIds
155
+ };
146
156
  }
147
157
 
148
158
  _generateSynteticIndices(vertexCount) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/3d-tiles-converter/helpers/b3dm-converter.ts"],"names":["encodeSync","GLTFScenegraph","GLTFWriter","Tile3DWriter","Matrix4","Vector3","Ellipsoid","convertTextureAtlas","Z_UP_TO_Y_UP_MATRIX","scratchVector","B3dmConverter","convert","i3sAttributesData","featureAttributes","gltf","buildGltf","b3dm","gltfEncoded","Uint8Array","type","featuresLength","_getFeaturesLength","batchTable","tileContent","textureFormat","material","attributes","indices","originalIndices","cartesianOrigin","cartographicOrigin","modelMatrix","gltfBuilder","textureIndex","_addI3sTextureToGltf","pbrMaterialInfo","_convertI3sMaterialToGltfMaterial","materialIndex","addMaterial","positions","positionsValue","value","uvRegions","texCoords","_normalizePositions","normals","_checkNormals","_generateSynteticIndices","length","size","meshIndex","addMesh","mode","transformMatrix","_generateTransformMatrix","nodeIndex","addNode","matrix","sceneIndex","addScene","nodeIndices","setDefaultScene","createBinaryChunk","gltfBuffer","texture","selectedTexture","pbrMetallicRoughness","baseColorTexture","source","image","mimeType","_deduceMimeTypeFromFormat","imageIndex","addImage","addTexture","colors","newPositionsValue","Float32Array","index","vertex","subarray","cartesianOriginVector","vertexVector","Array","from","transform","add","WGS84","cartographicToCartesian","subtract","set","translateOriginMatrix","translate","result","multiplyLeft","_generateBatchId","faceRanges","batchIdArraySize","batchId","rangeIndex","currentBatchId","fromIndex","untilPosition","fill","vertexCount","Uint32Array","format","console","warn","isTextureIndexExists","alphaMode","doubleSided","metallicFactor","roughnessFactor","texCoord","baseColorFactor","_setGltfTexture","materialDefinition","emissiveTexture","metallicRoughnessTexture","normalTexture","occlusionTexture","firstKey","Object","keys","find"],"mappings":";AAEA,SAAQA,UAAR,QAAyB,kBAAzB;AACA,SAAQC,cAAR,EAAwBC,UAAxB,QAAyC,kBAAzC;AACA,SAAQC,YAAR,QAA2B,sBAA3B;AACA,SAAQC,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,mBAAR,QAAkC,iBAAlC;AAEA,MAAMC,mBAAmB,GAAG,IAAIJ,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAC,CAApB,EAAuB,CAAvB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmC,CAAnC,EAAsC,CAAtC,EAAyC,CAAzC,EAA4C,CAA5C,EAA+C,CAA/C,CAAZ,CAA5B;AACA,MAAMK,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AAKA,eAAe,MAAMK,aAAN,CAAoB;AAAA;AAAA;;AAAA;AAAA;;AAUpB,QAAPC,OAAO,CACXC,iBADW,EAEXC,iBAAsB,GAAG,IAFd,EAGW;AACtB,UAAMC,IAAI,GAAG,MAAM,KAAKC,SAAL,CAAeH,iBAAf,CAAnB;AACA,UAAMI,IAAI,GAAGhB,UAAU,CACrB;AACEiB,MAAAA,WAAW,EAAE,IAAIC,UAAJ,CAAeJ,IAAf,CADf;AAEEK,MAAAA,IAAI,EAAE,MAFR;AAGEC,M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kB,CAACK,UAAD,EAAa;AAC7B,QAAI,CAACA,UAAL,EAAiB;AACf,aAAO,CAAP;AACD;;AACD,UAAMgG,QAAQ,GAAGC,MAAM,CAACC,IAAP,CAAYlG,UAAZ,EAAwB,CAAxB,CAAjB;AACA,WAAOgG,QAAQ,GAAGhG,UAAU,CAACgG,QAAD,CAAV,CAAqB1E,MAAxB,GAAiC,CAAhD;AACD;;AAMDF,EAAAA,aAAa,CAACD,OAAD,EAAU;AAErB,WAAOA,OAAO,CAACgF,IAAR,CAAcpF,KAAD,IAAWA,KAAxB,CAAP;AACD;;AAxTgC","sourcesContent":["import type {I3SAttributesData} from '../../3d-tiles-attributes-worker';\n\nimport {encodeSync} from '@loaders.gl/core';\nimport {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';\nimport {Tile3DWriter} from '@loaders.gl/3d-tiles';\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {convertTextureAtlas} from './texture-atlas';\n\nconst Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);\nconst scratchVector = new Vector3();\n\n/**\n * Converts content of an I3S node to *.b3dm's file content\n */\nexport default class B3dmConverter {\n // @ts-expect-error\n rtcCenter: Float32Array;\n i3sTile: any;\n\n /**\n * The starter of content conversion\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded content\n */\n async convert(\n i3sAttributesData: I3SAttributesData,\n featureAttributes: any = null\n ): Promise<ArrayBuffer> {\n const gltf = await this.buildGltf(i3sAttributesData);\n const b3dm = encodeSync(\n {\n gltfEncoded: new Uint8Array(gltf),\n type: 'b3dm',\n featuresLength: this._getFeaturesLength(featureAttributes),\n batchTable: featureAttributes\n },\n Tile3DWriter\n );\n return b3dm;\n }\n\n /**\n * Build and encode gltf\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded glb content\n */\n async buildGltf(i3sAttributesData: I3SAttributesData): Promise<ArrayBuffer> {\n const {tileContent, textureFormat} = i3sAttributesData;\n const {\n material,\n attributes,\n indices: originalIndices,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n } = tileContent;\n const gltfBuilder = new GLTFScenegraph();\n\n const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);\n const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);\n const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);\n\n const positions = attributes.positions;\n const positionsValue = positions.value;\n\n if (attributes.uvRegions && attributes.texCoords) {\n attributes.texCoords.value = convertTextureAtlas(\n attributes.texCoords.value,\n attributes.uvRegions.value\n );\n }\n\n attributes.positions.value = this._normalizePositions(\n positionsValue,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n );\n if (attributes.normals && !this._checkNormals(attributes.normals.value)) {\n delete attributes.normals;\n }\n const indices =\n originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);\n const meshIndex = gltfBuilder.addMesh({\n attributes,\n indices,\n material: materialIndex,\n mode: 4\n });\n const transformMatrix = this._generateTransformMatrix(cartesianOrigin);\n const nodeIndex = gltfBuilder.addNode({meshIndex, matrix: transformMatrix});\n const sceneIndex = gltfBuilder.addScene({nodeIndices: [nodeIndex]});\n gltfBuilder.setDefaultScene(sceneIndex);\n\n gltfBuilder.createBinaryChunk();\n\n const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);\n\n return gltfBuffer;\n }\n\n /**\n * Update gltfBuilder with texture from I3S tile\n * @param {object} i3sTile - Tile3D object\n * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF\n * @returns {Promise<number | null>} - GLTF texture index\n */\n async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {\n const {texture, material, attributes} = tileContent;\n let textureIndex = null;\n let selectedTexture = texture;\n if (!texture && material) {\n selectedTexture =\n material.pbrMetallicRoughness &&\n material.pbrMetallicRoughness.baseColorTexture &&\n material.pbrMetallicRoughness.baseColorTexture.texture.source.image;\n }\n if (selectedTexture) {\n const mimeType = this._deduceMimeTypeFromFormat(textureFormat);\n const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);\n textureIndex = gltfBuilder.addTexture({imageIndex});\n delete attributes.colors;\n }\n return textureIndex;\n }\n\n /**\n * Generate a positions array which is correct for 3DTiles/GLTF format\n * @param {Float64Array} positionsValue - the input geometry positions array\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system\n * @param {number[]} modelMatrix - the model matrix of geometry\n * @returns {Float32Array} - the output geometry positions array\n */\n _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {\n const newPositionsValue = new Float32Array(positionsValue.length);\n for (let index = 0; index < positionsValue.length; index += 3) {\n const vertex = positionsValue.subarray(index, index + 3);\n const cartesianOriginVector = new Vector3(cartesianOrigin);\n let vertexVector = new Vector3(Array.from(vertex))\n .transform(modelMatrix)\n .add(cartographicOrigin);\n Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);\n vertexVector = scratchVector.subtract(cartesianOriginVector);\n newPositionsValue.set(vertexVector, index);\n }\n return newPositionsValue;\n }\n\n /**\n * Generate the transformation matrix for GLTF node:\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node\n * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)\n * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)\n */\n _generateTransformMatrix(cartesianOrigin) {\n const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);\n const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);\n return result;\n }\n\n /**\n * Generate batchId attribute from faceRanges.\n * @param {Uint32Array} faceRanges - the source array\n * @returns {Float32Array} batchId list.\n */\n _generateBatchId(faceRanges) {\n const batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;\n const batchId = new Float32Array(batchIdArraySize);\n let rangeIndex = 0;\n let currentBatchId = 0;\n\n for (let index = 0; index < faceRanges.length / 2; index++) {\n const fromIndex = faceRanges[rangeIndex] * 3;\n const untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;\n\n batchId.fill(currentBatchId, fromIndex, untilPosition);\n rangeIndex += 2;\n currentBatchId += 1;\n }\n return batchId;\n }\n\n /**\n * luma.gl can not work without indices now:\n * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115\n * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]\n * @param {number} vertexCount - vertex count in the geometry\n * @returns {Uint32Array} indices array.\n */\n _generateSynteticIndices(vertexCount) {\n const result = new Uint32Array(vertexCount);\n for (let index = 0; index < vertexCount; index++) {\n result.set([index], index);\n }\n return result;\n }\n\n /**\n * Deduce mime type by format from `textureSetDefinition.formats[0].format`\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n * @param {string} format - format name\n * @returns {string} mime type.\n */\n _deduceMimeTypeFromFormat(format) {\n switch (format) {\n case 'jpg':\n return 'image/jpeg';\n case 'png':\n return 'image/png';\n case 'ktx2':\n return 'image/ktx2';\n default:\n console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef\n return 'image/jpeg';\n }\n }\n\n /**\n * Convert i3s material to GLTF compatible material\n * @param {object} material - i3s material definition\n * @param {number | null} textureIndex - texture index in GLTF\n * @returns {object} GLTF material\n */\n _convertI3sMaterialToGltfMaterial(material, textureIndex) {\n const isTextureIndexExists = textureIndex !== null;\n\n if (!material) {\n material = {\n alphaMode: 'OPAQUE',\n doubleSided: false,\n pbrMetallicRoughness: {\n metallicFactor: 0,\n roughnessFactor: 1\n }\n };\n\n if (isTextureIndexExists) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else {\n material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];\n }\n\n return material;\n }\n\n if (textureIndex !== null) {\n material = this._setGltfTexture(material, textureIndex);\n }\n\n return material;\n }\n\n /**\n * Set texture properties in material with GLTF textureIndex\n * @param {object} materialDefinition - i3s material definition\n * @param {number} textureIndex - texture index in GLTF\n * @returns {void}\n */\n _setGltfTexture(materialDefinition, textureIndex) {\n const material = {\n ...materialDefinition,\n pbrMetallicRoughness: {...materialDefinition.pbrMetallicRoughness}\n };\n // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of\n // properties defined in materialDefinition\n if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.baseColorTexture\n ) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.emissiveTexture) {\n material.emissiveTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture\n ) {\n material.pbrMetallicRoughness.metallicRoughnessTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.normalTexture) {\n material.normalTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.occlusionTexture) {\n material.occlusionTexture = {\n index: textureIndex,\n texCoord: 0\n };\n }\n return material;\n }\n\n /*\n * Returns Features length based on attribute array in attribute object.\n * @param {Object} attributes\n * @returns {Number} Features length .\n */\n _getFeaturesLength(attributes) {\n if (!attributes) {\n return 0;\n }\n const firstKey = Object.keys(attributes)[0];\n return firstKey ? attributes[firstKey].length : 0;\n }\n\n /* Checks that normals buffer is correct\n * @param {TypedArray} normals\n * @returns {boolean} true - normals are correct; false - normals are incorrect\n */\n _checkNormals(normals) {\n // If all normals === 0, the resulting tileset is all in black colors on Cesium\n return normals.find((value) => value);\n }\n}\n"],"file":"b3dm-converter.js"}
1
+ {"version":3,"sources":["../../../../src/3d-tiles-converter/helpers/b3dm-converter.ts"],"names":["encodeSync","GLTFScenegraph","GLTFWriter","Tile3DWriter","Matrix4","Vector3","Ellipsoid","convertTextureAtlas","Z_UP_TO_Y_UP_MATRIX","scratchVector","B3dmConverter","convert","i3sAttributesData","featureAttributes","gltf","buildGltf","b3dm","gltfEncoded","Uint8Array","type","featuresLength","_getFeaturesLength","batchTable","tileContent","textureFormat","material","attributes","indices","originalIndices","cartesianOrigin","cartographicOrigin","modelMatrix","gltfBuilder","textureIndex","_addI3sTextureToGltf","pbrMaterialInfo","_convertI3sMaterialToGltfMaterial","materialIndex","addMaterial","positions","positionsValue","value","uvRegions","texCoords","_normalizePositions","_createBatchIds","normals","_checkNormals","_generateSynteticIndices","length","size","meshIndex","addMesh","mode","transformMatrix","_generateTransformMatrix","nodeIndex","addNode","matrix","sceneIndex","addScene","nodeIndices","setDefaultScene","createBinaryChunk","gltfBuffer","texture","selectedTexture","pbrMetallicRoughness","baseColorTexture","source","image","mimeType","_deduceMimeTypeFromFormat","imageIndex","addImage","addTexture","colors","newPositionsValue","Float32Array","index","vertex","subarray","cartesianOriginVector","vertexVector","Array","from","transform","add","WGS84","cartographicToCartesian","subtract","set","translateOriginMatrix","translate","result","multiplyLeft","i3sContent","featureIds","OBJECTID","objectIds","i","featureId","batchId","indexOf","_BATCHID","byteOffset","vertexCount","Uint32Array","format","console","warn","isTextureIndexExists","alphaMode","doubleSided","metallicFactor","roughnessFactor","texCoord","baseColorFactor","_setGltfTexture","materialDefinition","emissiveTexture","metallicRoughnessTexture","normalTexture","occlusionTexture","firstKey","Object","keys","find"],"mappings":";AAEA,SAAQA,UAAR,QAAyB,kBAAzB;AACA,SAAQC,cAAR,EAAwBC,UAAxB,QAAyC,kBAAzC;AACA,SAAQC,YAAR,QAA2B,sBAA3B;AACA,SAAQC,OAAR,EAAiBC,OAA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import {encodeSync} from '@loaders.gl/core';\nimport {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';\nimport {Tile3DWriter} from '@loaders.gl/3d-tiles';\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {convertTextureAtlas} from './texture-atlas';\n\nconst Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);\nconst scratchVector = new Vector3();\n\n/**\n * Converts content of an I3S node to *.b3dm's file content\n */\nexport default class B3dmConverter {\n // @ts-expect-error\n rtcCenter: Float32Array;\n i3sTile: any;\n\n /**\n * The starter of content conversion\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded content\n */\n async convert(\n i3sAttributesData: I3SAttributesData,\n featureAttributes: any = null\n ): Promise<ArrayBuffer> {\n const gltf = await this.buildGltf(i3sAttributesData, featureAttributes);\n const b3dm = encodeSync(\n {\n gltfEncoded: new Uint8Array(gltf),\n type: 'b3dm',\n featuresLength: this._getFeaturesLength(featureAttributes),\n batchTable: featureAttributes\n },\n Tile3DWriter\n );\n return b3dm;\n }\n\n /**\n * Build and encode gltf\n * @param i3sTile - Tile3D instance for I3S node\n * @returns - encoded glb content\n */\n async buildGltf(\n i3sAttributesData: I3SAttributesData,\n featureAttributes: any\n ): Promise<ArrayBuffer> {\n const {tileContent, textureFormat} = i3sAttributesData;\n const {\n material,\n attributes,\n indices: originalIndices,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n } = tileContent;\n const gltfBuilder = new GLTFScenegraph();\n\n const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);\n const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);\n const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);\n\n const positions = attributes.positions;\n const positionsValue = positions.value;\n\n if (attributes.uvRegions && attributes.texCoords) {\n attributes.texCoords.value = convertTextureAtlas(\n attributes.texCoords.value,\n attributes.uvRegions.value\n );\n }\n\n attributes.positions.value = this._normalizePositions(\n positionsValue,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n );\n this._createBatchIds(tileContent, featureAttributes);\n if (attributes.normals && !this._checkNormals(attributes.normals.value)) {\n delete attributes.normals;\n }\n const indices =\n originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);\n const meshIndex = gltfBuilder.addMesh({\n attributes,\n indices,\n material: materialIndex,\n mode: 4\n });\n const transformMatrix = this._generateTransformMatrix(cartesianOrigin);\n const nodeIndex = gltfBuilder.addNode({meshIndex, matrix: transformMatrix});\n const sceneIndex = gltfBuilder.addScene({nodeIndices: [nodeIndex]});\n gltfBuilder.setDefaultScene(sceneIndex);\n\n gltfBuilder.createBinaryChunk();\n\n const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);\n\n return gltfBuffer;\n }\n\n /**\n * Update gltfBuilder with texture from I3S tile\n * @param {object} i3sTile - Tile3D object\n * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF\n * @returns {Promise<number | null>} - GLTF texture index\n */\n async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {\n const {texture, material, attributes} = tileContent;\n let textureIndex = null;\n let selectedTexture = texture;\n if (!texture && material) {\n selectedTexture =\n material.pbrMetallicRoughness &&\n material.pbrMetallicRoughness.baseColorTexture &&\n material.pbrMetallicRoughness.baseColorTexture.texture.source.image;\n }\n if (selectedTexture) {\n const mimeType = this._deduceMimeTypeFromFormat(textureFormat);\n const imageIndex = gltfBuilder.addImage(selectedTexture, mimeType);\n textureIndex = gltfBuilder.addTexture({imageIndex});\n delete attributes.colors;\n }\n return textureIndex;\n }\n\n /**\n * Generate a positions array which is correct for 3DTiles/GLTF format\n * @param {Float64Array} positionsValue - the input geometry positions array\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system\n * @param {number[]} modelMatrix - the model matrix of geometry\n * @returns {Float32Array} - the output geometry positions array\n */\n _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {\n const newPositionsValue = new Float32Array(positionsValue.length);\n for (let index = 0; index < positionsValue.length; index += 3) {\n const vertex = positionsValue.subarray(index, index + 3);\n const cartesianOriginVector = new Vector3(cartesianOrigin);\n let vertexVector = new Vector3(Array.from(vertex))\n .transform(modelMatrix)\n .add(cartographicOrigin);\n Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);\n vertexVector = scratchVector.subtract(cartesianOriginVector);\n newPositionsValue.set(vertexVector, index);\n }\n return newPositionsValue;\n }\n\n /**\n * Generate the transformation matrix for GLTF node:\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node\n * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)\n * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)\n */\n _generateTransformMatrix(cartesianOrigin) {\n const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);\n const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);\n return result;\n }\n\n /**\n * Create _BATCHID attribute\n * @param {Object} i3sContent - the source object\n * @returns {void}\n */\n _createBatchIds(i3sContent, featureAttributes) {\n const {featureIds} = i3sContent;\n const {OBJECTID: objectIds} = featureAttributes || {};\n if (!featureIds || !objectIds) {\n return;\n }\n\n for (let i = 0; i < featureIds.length; i++) {\n const featureId = featureIds[i];\n const batchId = objectIds.indexOf(featureId);\n featureIds[i] = batchId;\n }\n\n i3sContent.attributes._BATCHID = {\n size: 1,\n byteOffset: 0,\n value: featureIds\n };\n }\n\n /**\n * luma.gl can not work without indices now:\n * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115\n * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]\n * @param {number} vertexCount - vertex count in the geometry\n * @returns {Uint32Array} indices array.\n */\n _generateSynteticIndices(vertexCount) {\n const result = new Uint32Array(vertexCount);\n for (let index = 0; index < vertexCount; index++) {\n result.set([index], index);\n }\n return result;\n }\n\n /**\n * Deduce mime type by format from `textureSetDefinition.formats[0].format`\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n * @param {string} format - format name\n * @returns {string} mime type.\n */\n _deduceMimeTypeFromFormat(format) {\n switch (format) {\n case 'jpg':\n return 'image/jpeg';\n case 'png':\n return 'image/png';\n case 'ktx2':\n return 'image/ktx2';\n default:\n console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef\n return 'image/jpeg';\n }\n }\n\n /**\n * Convert i3s material to GLTF compatible material\n * @param {object} material - i3s material definition\n * @param {number | null} textureIndex - texture index in GLTF\n * @returns {object} GLTF material\n */\n _convertI3sMaterialToGltfMaterial(material, textureIndex) {\n const isTextureIndexExists = textureIndex !== null;\n\n if (!material) {\n material = {\n alphaMode: 'OPAQUE',\n doubleSided: false,\n pbrMetallicRoughness: {\n metallicFactor: 0,\n roughnessFactor: 1\n }\n };\n\n if (isTextureIndexExists) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else {\n material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];\n }\n\n return material;\n }\n\n if (textureIndex !== null) {\n material = this._setGltfTexture(material, textureIndex);\n }\n\n return material;\n }\n\n /**\n * Set texture properties in material with GLTF textureIndex\n * @param {object} materialDefinition - i3s material definition\n * @param {number} textureIndex - texture index in GLTF\n * @returns {void}\n */\n _setGltfTexture(materialDefinition, textureIndex) {\n const material = {\n ...materialDefinition,\n pbrMetallicRoughness: {...materialDefinition.pbrMetallicRoughness}\n };\n // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of\n // properties defined in materialDefinition\n if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.baseColorTexture\n ) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.emissiveTexture) {\n material.emissiveTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture\n ) {\n material.pbrMetallicRoughness.metallicRoughnessTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.normalTexture) {\n material.normalTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.occlusionTexture) {\n material.occlusionTexture = {\n index: textureIndex,\n texCoord: 0\n };\n }\n return material;\n }\n\n /*\n * Returns Features length based on attribute array in attribute object.\n * @param {Object} attributes\n * @returns {Number} Features length .\n */\n _getFeaturesLength(attributes) {\n if (!attributes) {\n return 0;\n }\n const firstKey = Object.keys(attributes)[0];\n return firstKey ? attributes[firstKey].length : 0;\n }\n\n /* Checks that normals buffer is correct\n * @param {TypedArray} normals\n * @returns {boolean} true - normals are correct; false - normals are incorrect\n */\n _checkNormals(normals) {\n // If all normals === 0, the resulting tileset is all in black colors on Cesium\n return normals.find((value) => value);\n }\n}\n"],"file":"b3dm-converter.js"}
@@ -2,7 +2,7 @@ import { load, fetchFile } from '@loaders.gl/core';
2
2
  import { ZipLoader } from '@loaders.gl/zip';
3
3
  import { writeFile } from '../lib/utils/file-utils';
4
4
  import { join } from 'path';
5
- const VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'beta';
5
+ const VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'beta';
6
6
  const PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';
7
7
  export class DepsInstaller {
8
8
  async install(path = '', workersPath = '') {
@@ -1,5 +1,5 @@
1
1
  import { processOnWorker } from '@loaders.gl/worker-utils';
2
- const VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
2
+ const VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'latest';
3
3
  export const I3SAttributesWorker = {
4
4
  id: 'i3s-attributes',
5
5
  name: 'I3S Attributes Worker',
@@ -1,4 +1,4 @@
1
- const VERSION = typeof "3.3.0-alpha.4" !== 'undefined' ? "3.3.0-alpha.4" : 'latest';
1
+ const VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 'latest';
2
2
  import { parsePGM } from '@math.gl/geoid';
3
3
  export const PGMLoader = {
4
4
  name: 'PGM - Netpbm grayscale image format',
@@ -1,5 +1,5 @@
1
1
  import { createWorker } from '@loaders.gl/worker-utils';
2
2
  import B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';
3
3
  const b3dmConverter = new B3dmConverter();
4
- createWorker(async (data, options = {}) => b3dmConverter.convert(data, options.attributes));
4
+ createWorker(async (data, options = {}) => b3dmConverter.convert(data, options.featureAttributes));
5
5
  //# sourceMappingURL=3d-tiles-attributes-worker.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/workers/3d-tiles-attributes-worker.ts"],"names":["createWorker","B3dmConverter","b3dmConverter","data","options","convert","attributes"],"mappings":"AAAA,SAAQA,YAAR,QAA2B,0BAA3B;AACA,OAAOC,aAAP,MAA0B,8CAA1B;AAEA,MAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AAEAD,YAAY,CAAC,OAAOG,IAAP,EAAaC,OAAO,GAAG,EAAvB,KAA8BF,aAAa,CAACG,OAAd,CAAsBF,IAAtB,EAA4BC,OAAO,CAACE,UAApC,CAA/B,CAAZ","sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';\n\nconst b3dmConverter = new B3dmConverter();\n\ncreateWorker(async (data, options = {}) => b3dmConverter.convert(data, options.attributes));\n"],"file":"3d-tiles-attributes-worker.js"}
1
+ {"version":3,"sources":["../../../src/workers/3d-tiles-attributes-worker.ts"],"names":["createWorker","B3dmConverter","b3dmConverter","data","options","convert","featureAttributes"],"mappings":"AAAA,SAAQA,YAAR,QAA2B,0BAA3B;AACA,OAAOC,aAAP,MAA0B,8CAA1B;AAEA,MAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AAEAD,YAAY,CAAC,OAAOG,IAAP,EAAaC,OAAO,GAAG,EAAvB,KAA8BF,aAAa,CAACG,OAAd,CAAsBF,IAAtB,EAA4BC,OAAO,CAACE,iBAApC,CAA/B,CAAZ","sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';\n\nconst b3dmConverter = new B3dmConverter();\n\ncreateWorker(async (data, options = {}) => b3dmConverter.convert(data, options.featureAttributes));\n"],"file":"3d-tiles-attributes-worker.js"}