@loaders.gl/tile-converter 3.1.0-beta.5 → 3.1.2

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 (153) hide show
  1. package/dist/converter.min.js +20 -20
  2. package/dist/{bundle.js → dist.min.js} +2228 -1482
  3. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +429 -189
  4. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  5. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +306 -209
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  7. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +8 -4
  8. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  9. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +13 -13
  10. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  11. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +51 -32
  12. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  13. package/dist/es5/bundle.js +1 -1
  14. package/dist/es5/bundle.js.map +1 -1
  15. package/dist/es5/deps-installer/deps-installer.js +61 -17
  16. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +55 -16
  18. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  19. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +33 -9
  20. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  21. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +103 -93
  22. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  24. package/dist/es5/i3s-converter/helpers/geometry-converter.js +547 -336
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/node-debug.js +27 -31
  27. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/node-pages.js +209 -101
  29. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  30. package/dist/es5/i3s-converter/i3s-converter.js +1645 -700
  31. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/json-templates/layers.js +213 -177
  33. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  34. package/dist/es5/i3s-converter/json-templates/metadata.js +24 -20
  35. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  36. package/dist/es5/i3s-converter/json-templates/node.js +92 -74
  37. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  38. package/dist/es5/i3s-converter/json-templates/scene-server.js +34 -28
  39. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  40. package/dist/es5/i3s-converter/json-templates/shared-resources.js +162 -107
  41. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  42. package/dist/es5/i3s-converter/json-templates/store.js +4 -2
  43. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  44. package/dist/es5/i3s-converter/types.js +2 -0
  45. package/dist/es5/i3s-converter/types.js.map +1 -0
  46. package/dist/es5/i3s-server/app.js +6 -6
  47. package/dist/es5/i3s-server/app.js.map +1 -1
  48. package/dist/es5/i3s-server/controllers/index-controller.js +60 -20
  49. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  50. package/dist/es5/i3s-server/routes/index.js +41 -14
  51. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  52. package/dist/es5/index.js +4 -4
  53. package/dist/es5/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  54. package/dist/es5/lib/utils/compress-util.js +345 -123
  55. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  56. package/dist/es5/lib/utils/file-utils.js +98 -20
  57. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  58. package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
  59. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  60. package/dist/es5/lib/utils/statistic-utills.js +152 -41
  61. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  62. package/dist/es5/pgm-loader.js +31 -4
  63. package/dist/es5/pgm-loader.js.map +1 -1
  64. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +7 -6
  65. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  66. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +7 -0
  67. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  68. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  69. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -1
  70. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  71. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +12 -9
  72. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  73. package/dist/esm/deps-installer/deps-installer.js +2 -6
  74. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  75. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +35 -3
  76. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  77. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +2 -2
  78. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  79. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  80. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  81. package/dist/esm/i3s-converter/helpers/geometry-converter.js +50 -16
  82. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  83. package/dist/esm/i3s-converter/helpers/node-debug.js +2 -4
  84. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  85. package/dist/esm/i3s-converter/helpers/node-pages.js +15 -4
  86. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  87. package/dist/esm/i3s-converter/i3s-converter.js +147 -62
  88. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/json-templates/layers.js +37 -27
  90. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
  91. package/dist/esm/i3s-converter/json-templates/metadata.js +2 -2
  92. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  93. package/dist/esm/i3s-converter/json-templates/node.js +16 -12
  94. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
  95. package/dist/esm/i3s-converter/json-templates/scene-server.js +2 -2
  96. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  97. package/dist/esm/i3s-converter/json-templates/shared-resources.js +19 -14
  98. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  99. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  100. package/dist/esm/i3s-converter/types.js +2 -0
  101. package/dist/esm/i3s-converter/types.js.map +1 -0
  102. package/dist/esm/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  103. package/dist/esm/pgm-loader.js +3 -3
  104. package/dist/esm/pgm-loader.js.map +1 -1
  105. package/package.json +17 -15
  106. package/src/3d-tiles-converter/3d-tiles-converter.ts +21 -20
  107. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +19 -2
  108. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  109. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  110. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  111. package/src/deps-installer/deps-installer.js +2 -2
  112. package/src/i3s-converter/helpers/coordinate-converter.ts +62 -9
  113. package/src/i3s-converter/helpers/{create-scene-server-path.js → create-scene-server-path.ts} +2 -2
  114. package/src/i3s-converter/helpers/{geometry-attributes.js → geometry-attributes.ts} +4 -4
  115. package/src/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  116. package/src/i3s-converter/helpers/geometry-converter.js +63 -13
  117. package/src/i3s-converter/helpers/{node-debug.js → node-debug.ts} +3 -2
  118. package/src/i3s-converter/helpers/{node-pages.js → node-pages.ts} +41 -26
  119. package/src/i3s-converter/i3s-converter.ts +204 -133
  120. package/src/i3s-converter/json-templates/{layers.js → layers.ts} +29 -27
  121. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  122. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  123. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  124. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +14 -14
  125. package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  126. package/src/i3s-converter/types.ts +14 -0
  127. package/src/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  128. package/src/pgm-loader.ts +2 -2
  129. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  130. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  131. package/dist/es5/i3s-converter/helpers/node-pages.d.ts +0 -144
  132. package/dist/es5/lib/geoid-height-model.d.ts +0 -41
  133. package/dist/es5/lib/geoid-height-model.js +0 -149
  134. package/dist/es5/lib/geoid-height-model.js.map +0 -1
  135. package/dist/es5/lib/pgm-parser.d.ts +0 -14
  136. package/dist/es5/lib/pgm-parser.js +0 -192
  137. package/dist/es5/lib/pgm-parser.js.map +0 -1
  138. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  139. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  140. package/dist/esm/i3s-converter/helpers/node-pages.d.ts +0 -144
  141. package/dist/esm/lib/geoid-height-model.d.ts +0 -41
  142. package/dist/esm/lib/geoid-height-model.js +0 -140
  143. package/dist/esm/lib/geoid-height-model.js.map +0 -1
  144. package/dist/esm/lib/pgm-parser.d.ts +0 -14
  145. package/dist/esm/lib/pgm-parser.js +0 -183
  146. package/dist/esm/lib/pgm-parser.js.map +0 -1
  147. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  148. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  149. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  150. package/src/lib/geoid-height-model.d.ts +0 -41
  151. package/src/lib/geoid-height-model.js +0 -239
  152. package/src/lib/pgm-parser.d.ts +0 -14
  153. package/src/lib/pgm-parser.js +0 -179
@@ -5,6 +5,7 @@ import { encode, assert } from '@loaders.gl/core';
5
5
  import { concatenateArrayBuffers, concatenateTypedArrays } from '@loaders.gl/loader-utils';
6
6
  import md5 from 'md5';
7
7
  import { generateAttributes } from './geometry-attributes';
8
+ import { createBoundingVolumesFromGeometry } from './coordinate-converter';
8
9
  const VALUES_PER_VERTEX = 3;
9
10
  const VALUES_PER_TEX_COORD = 2;
10
11
  const VALUES_PER_COLOR_ELEMENT = 4;
@@ -13,9 +14,15 @@ const SHORT_INT_TYPE = 'Int32';
13
14
  const DOUBLE_TYPE = 'Float64';
14
15
  const OBJECT_ID_TYPE = 'Oid32';
15
16
  const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
16
- export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco) {
17
+ let scratchVector = new Vector3();
18
+ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel) {
19
+ const useCartesianPositions = generateBoundingVolumes;
17
20
  const materialAndTextureList = convertMaterials(tileContent);
18
- const convertedAttributesMap = convertAttributes(tileContent);
21
+ const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);
22
+
23
+ if (generateBoundingVolumes) {
24
+ _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
25
+ }
19
26
 
20
27
  if (convertedAttributesMap.has('default')) {
21
28
  materialAndTextureList.push({
@@ -29,7 +36,7 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
29
36
  materials = []
30
37
  } = tileContent.gltf;
31
38
 
32
- if (!materials.length === 0) {
39
+ if (!(materials !== null && materials !== void 0 && materials.length)) {
33
40
  materials.push({
34
41
  id: 'default'
35
42
  });
@@ -67,6 +74,22 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
67
74
  return result;
68
75
  }
69
76
 
77
+ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
78
+ for (const attributes of convertedAttributesMap.values()) {
79
+ const boundingVolumes = createBoundingVolumesFromGeometry(attributes.positions, geoidHeightModel);
80
+ attributes.boundingVolumes = boundingVolumes;
81
+ const cartographicOrigin = boundingVolumes.obb.center;
82
+
83
+ for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
84
+ const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
85
+ Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
86
+ scratchVector[2] = scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
87
+ scratchVector = scratchVector.subtract(cartographicOrigin);
88
+ attributes.positions.set(scratchVector, index);
89
+ }
90
+ }
91
+ }
92
+
70
93
  async function _makeNodeResources({
71
94
  convertedAttributes,
72
95
  material,
@@ -77,6 +100,7 @@ async function _makeNodeResources({
77
100
  attributeStorageInfo,
78
101
  draco
79
102
  }) {
103
+ const boundingVolumes = convertedAttributes.boundingVolumes;
80
104
  const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
81
105
  const triangleCount = vertexCount / 3;
82
106
  const {
@@ -117,11 +141,12 @@ async function _makeNodeResources({
117
141
  meshMaterial: material,
118
142
  vertexCount,
119
143
  attributes,
120
- featureCount
144
+ featureCount,
145
+ boundingVolumes
121
146
  };
122
147
  }
123
148
 
124
- function convertAttributes(tileContent) {
149
+ function convertAttributes(tileContent, useCartesianPositions) {
125
150
  var _tileContent$gltf$sce;
126
151
 
127
152
  const attributesMap = new Map();
@@ -134,12 +159,13 @@ function convertAttributes(tileContent) {
134
159
  normals: new Float32Array(0),
135
160
  texCoords: new Float32Array(0),
136
161
  colors: new Uint8Array(0),
137
- featureIndices: []
162
+ featureIndices: [],
163
+ boundingVolumes: null
138
164
  });
139
165
  }
140
166
 
141
167
  const nodes = (tileContent.gltf.scene || ((_tileContent$gltf$sce = tileContent.gltf.scenes) === null || _tileContent$gltf$sce === void 0 ? void 0 : _tileContent$gltf$sce[0]) || tileContent.gltf).nodes;
142
- convertNodes(nodes, tileContent, attributesMap);
168
+ convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);
143
169
 
144
170
  for (const attrKey of attributesMap.keys()) {
145
171
  const attributes = attributesMap.get(attrKey);
@@ -155,27 +181,27 @@ function convertAttributes(tileContent) {
155
181
  return attributesMap;
156
182
  }
157
183
 
158
- function convertNodes(nodes, tileContent, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
184
+ function convertNodes(nodes, tileContent, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
159
185
  if (nodes) {
160
186
  for (const node of nodes) {
161
- convertNode(node, tileContent, attributesMap, matrix);
187
+ convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);
162
188
  }
163
189
  }
164
190
  }
165
191
 
166
- function convertNode(node, tileContent, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
192
+ function convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
167
193
  const nodeMatrix = node.matrix;
168
194
  const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
169
195
  const mesh = node.mesh;
170
196
 
171
197
  if (mesh) {
172
- convertMesh(mesh, tileContent, attributesMap, compositeMatrix);
198
+ convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, compositeMatrix);
173
199
  }
174
200
 
175
- convertNodes(node.children, tileContent, attributesMap, compositeMatrix);
201
+ convertNodes(node.children, tileContent, attributesMap, useCartesianPositions, compositeMatrix);
176
202
  }
177
203
 
178
- function convertMesh(mesh, content, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
204
+ function convertMesh(mesh, content, attributesMap, useCartesianPositions = false, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
179
205
  for (const primitive of mesh.primitives) {
180
206
  let outputAttributes = null;
181
207
 
@@ -193,7 +219,8 @@ function convertMesh(mesh, content, attributesMap, matrix = new Matrix4([1, 0, 0
193
219
  cartesianModelMatrix: content.cartesianModelMatrix,
194
220
  nodeMatrix: matrix,
195
221
  indices: primitive.indices.value,
196
- attributeSpecificTransformation: transformVertexPositions
222
+ attributeSpecificTransformation: transformVertexPositions,
223
+ useCartesianPositions
197
224
  }));
198
225
  outputAttributes.normals = concatenateTypedArrays(outputAttributes.normals, transformVertexArray({
199
226
  vertices: attributes.NORMAL && attributes.NORMAL.value,
@@ -201,7 +228,8 @@ function convertMesh(mesh, content, attributesMap, matrix = new Matrix4([1, 0, 0
201
228
  cartesianModelMatrix: content.cartesianModelMatrix,
202
229
  nodeMatrix: matrix,
203
230
  indices: primitive.indices.value,
204
- attributeSpecificTransformation: transformVertexNormals
231
+ attributeSpecificTransformation: transformVertexNormals,
232
+ useCartesianPositions: false
205
233
  }));
206
234
  outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
207
235
  outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
@@ -238,7 +266,8 @@ function transformVertexPositions(vertexVector, calleeArgs) {
238
266
  const {
239
267
  cartesianModelMatrix,
240
268
  cartographicOrigin,
241
- nodeMatrix
269
+ nodeMatrix,
270
+ useCartesianPositions
242
271
  } = calleeArgs;
243
272
 
244
273
  if (nodeMatrix) {
@@ -246,6 +275,11 @@ function transformVertexPositions(vertexVector, calleeArgs) {
246
275
  }
247
276
 
248
277
  vertexVector = vertexVector.transform(cartesianModelMatrix);
278
+
279
+ if (useCartesianPositions) {
280
+ return vertexVector;
281
+ }
282
+
249
283
  Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
250
284
  vertexVector = vertexVector.subtract(cartographicOrigin);
251
285
  return vertexVector;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-converter.js"],"names":["Vector3","Matrix4","Vector4","Ellipsoid","DracoWriter","encode","assert","concatenateArrayBuffers","concatenateTypedArrays","md5","generateAttributes","VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","has","push","material","getDefaultMaterial","result","nodesCounter","materials","gltf","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","vertexCount","positions","triangleCount","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","set","fileBuffer","Uint8Array","buffer","ArrayBuffer","compressedGeometry","generateCompressedGeometry","Float32Array","attributes","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","attrKey","keys","delete","reduce","acc","value","concat","matrix","node","convertNode","nodeMatrix","compositeMatrix","multiplyRight","mesh","convertMesh","children","content","primitive","primitives","outputAttributes","transformVertexArray","vertices","POSITION","cartographicOrigin","cartesianModelMatrix","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIdsByAttributeName","args","newVertices","coordIndex","vertex","subarray","vertexVector","Array","from","x","y","z","calleeArgs","transform","WGS84","cartesianToCartographic","subtract","transformAsVector","newTexCoords","fill","texCoord","colorsAttribute","components","newColors","colorIndex","color","colorUint8","j","batchedIds","newBatchIds","batchIds","index","possibleBatchIdAttributeName","sourceMaterials","convertMaterial","doubleSided","emissiveFactor","map","c","Math","round","alphaMode","toLowerCase","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfMaterials","i3sResources","materialDefinitionInfos","gltfMaterial","materialDefinitionInfo","textureDefinitionInfo","convertGLTFMaterialToI3sSharedResources","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","toArray","encoding","mimeType","images","generateImageId","size","image","width","data","height","levelCountOfTexture","indexOfLevel","indexOfTextureInStore","zerosCount","toString","rightHalf","repeat","shiftedLevelCountOfTexture","shiftedIndexOfLevel","shiftedWidth","shiftedHeight","leftHalf","imageId","BigInt","batchTable","replaceMap","getFeaturesReplaceMap","replaceIndicesByUnique","featureMap","oldFeatureId","uniqueFeatureId","getOrCreateUniqueFeatureId","generateStringFromBatchTableByIndex","str","key","batchTableStr","hash","includes","indexOf","indicesArray","attributeBuffers","batchTableWithFeatureIds","OBJECTID","type","getAttributeType","attributeBuffer","generateShortIntegerAttributeBuffer","generateDoubleAttributeBuffer","generateStringAttributeBuffer","attribute","find","attr","name","attributeValues","valueType","count","valuesArray","padding","Float64Array","batchAttributes","stringCountArray","totalNumberOfBytes","stringSizesArray","stringBufferArray","currentString","String","currentStringBuffer","Buffer","currentStringSize","totalBytes","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","method","orderedFeatureIndices","fillIndex","startIndex","endIndex"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,OAA1B,QAAwC,eAAxC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAEA,SAAQC,WAAR,QAA0B,mBAA1B;AACA,SAAQC,MAAR,EAAgBC,MAAhB,QAA6B,kBAA7B;AACA,SAAQC,uBAAR,EAAiCC,sBAAjC,QAA8D,0BAA9D;AACA,OAAOC,GAAP,MAAgB,KAAhB;AACA,SAAQC,kBAAR,QAAiC,uBAAjC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,oBAAoB,GAAG,CAA7B;AACA,MAAMC,wBAAwB,GAAG,CAAjC;AAEA,MAAMC,WAAW,GAAG,QAApB;AACA,MAAMC,cAAc,GAAG,OAAvB;AACA,MAAMC,WAAW,GAAG,SAApB;AACA,MAAMC,cAAc,GAAG,OAAvB;AAMA,MAAMC,mCAAmC,GAAG,CAAC,oBAAD,EAAuB,UAAvB,EAAmC,SAAnC,CAA5C;AAEA,eAAe,eAAeC,wBAAf,CACbC,WADa,EAEbC,MAFa,EAGbC,iBAHa,EAIbC,oBAJa,EAKbC,KALa,EAMb;AACA,QAAMC,sBAAsB,GAAGC,gBAAgB,CAACN,WAAD,CAA/C;AACA,QAAMO,sBAAsB,GAAGC,iBAAiB,CAACR,WAAD,CAAhD;;AAEA,MAAIO,sBAAsB,C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A9C,EAA2D;AACrEoB,IAAAA,KAAK,EAAE;AACLiP,MAAAA,MAAM,EAAE,0BADH;AAELF,MAAAA;AAFK;AAD8D,GAA3D,CADP,CAAP;AAQD;;AAQD,SAASF,6BAAT,CAAuCD,YAAvC,EAAqDpN,SAArD,EAAgE;AAC9D,QAAM0N,qBAAqB,GAAG,IAAIhN,WAAJ,CAAgB0M,YAAY,CAAC/N,MAA7B,CAA9B;AACA,MAAIsO,SAAS,GAAG,CAAhB;AACA,MAAIC,UAAU,GAAG,CAAjB;;AAEA,OAAK,IAAIzH,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGnG,SAAS,CAACX,MAAtC,EAA8C8G,KAAK,IAAI,CAAvD,EAA0D;AACxD,UAAM0H,QAAQ,GAAG,CAAC7N,SAAS,CAACmG,KAAD,CAAT,GAAmB,CAApB,IAAyBxI,iBAA1C;AAEA+P,IAAAA,qBAAqB,CAACnI,IAAtB,CAA2BoI,SAA3B,EAAsCC,UAAtC,EAAkDC,QAAlD;AAEAF,IAAAA,SAAS;AACTC,IAAAA,UAAU,GAAGC,QAAQ,GAAG,CAAxB;AACD;;AAED,SAAOH,qBAAP;AACD","sourcesContent":["import {Vector3, Matrix4, Vector4} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nimport {DracoWriter} from '@loaders.gl/draco';\nimport {encode, assert} from '@loaders.gl/core';\nimport {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';\nimport md5 from 'md5';\nimport {generateAttributes} from './geometry-attributes';\n\nconst VALUES_PER_VERTEX = 3;\nconst VALUES_PER_TEX_COORD = 2;\nconst VALUES_PER_COLOR_ELEMENT = 4;\n\nconst STRING_TYPE = 'string';\nconst SHORT_INT_TYPE = 'Int32';\nconst DOUBLE_TYPE = 'Float64';\nconst OBJECT_ID_TYPE = 'Oid32';\n/*\n * 'CUSTOM_ATTRIBUTE_2' - Attribute name which includes batch info and used by New York map.\n * _BATCHID - Default attribute name which includes batch info.\n * BATCHID - Legacy attribute name which includes batch info.\n */\nconst BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];\n\nexport default async function convertB3dmToI3sGeometry(\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n) {\n const materialAndTextureList = convertMaterials(tileContent);\n const convertedAttributesMap = convertAttributes(tileContent);\n\n if (convertedAttributesMap.has('default')) {\n materialAndTextureList.push({\n material: getDefaultMaterial()\n });\n }\n\n const result = [];\n let nodesCounter = nodeId;\n let {materials = []} = tileContent.gltf;\n if (!materials.length === 0) {\n materials.push({id: 'default'});\n }\n for (let i = 0; i < materials.length; i++) {\n const sourceMaterial = materials[i];\n if (!convertedAttributesMap.has(sourceMaterial.id)) {\n continue; // eslint-disable-line no-continue\n }\n const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);\n const {material, texture} = materialAndTextureList[i];\n result.push(\n await _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId: nodesCounter,\n featuresHashArray,\n attributeStorageInfo,\n draco\n })\n );\n nodesCounter++;\n }\n\n if (!result.length) {\n return null;\n }\n return result;\n}\n\nasync function _makeNodeResources({\n convertedAttributes,\n material,\n texture,\n tileContent,\n nodeId,\n featuresHashArray,\n attributeStorageInfo,\n draco\n}) {\n const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;\n const triangleCount = vertexCount / 3;\n const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =\n generateAttributes({triangleCount, ...convertedAttributes});\n\n if (tileContent.batchTableJson) {\n makeFeatureIdsUnique(\n featureIds,\n convertedAttributes.featureIndices,\n featuresHashArray,\n tileContent.batchTableJson\n );\n }\n\n const header = new Uint32Array(2);\n const typedFeatureIds = generateBigUint64Array(featureIds);\n\n header.set([vertexCount, featureCount], 0);\n const fileBuffer = new Uint8Array(\n concatenateArrayBuffers(\n header.buffer,\n positions.buffer,\n normals.buffer,\n texture ? texCoords.buffer : new ArrayBuffer(0),\n colors.buffer,\n typedFeatureIds.buffer,\n faceRange.buffer\n )\n );\n const compressedGeometry = draco\n ? await generateCompressedGeometry(vertexCount, convertedAttributes, {\n positions,\n normals,\n texCoords: texture ? texCoords : new Float32Array(0),\n colors,\n featureIds,\n faceRange\n })\n : null;\n\n const attributes = convertBatchTableToAttributeBuffers(\n tileContent.batchTableJson,\n featureIds,\n attributeStorageInfo\n );\n\n return {\n geometry: fileBuffer,\n compressedGeometry,\n texture,\n sharedResources: getSharedResources(tileContent, nodeId),\n meshMaterial: material,\n vertexCount,\n attributes,\n featureCount\n };\n}\n\n/**\n * Convert attributes from the gltf nodes tree to i3s plain geometry\n * @param {Object} tileContent - 3d tile content\n * @returns {Map}\n * Map<{\n * positions: Float32Array,\n * normals: Float32Array,\n * colors: Uint8Array,\n * texCoords: Float32Array\n * }>\n * @todo implement colors support (if applicable for gltf format)\n */\nfunction convertAttributes(tileContent) {\n const attributesMap = new Map();\n\n for (const material of tileContent.gltf.materials || [{id: 'default'}]) {\n attributesMap.set(material.id, {\n positions: new Float32Array(0),\n normals: new Float32Array(0),\n texCoords: new Float32Array(0),\n colors: new Uint8Array(0),\n featureIndices: []\n });\n }\n\n const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;\n convertNodes(nodes, tileContent, attributesMap);\n\n for (const attrKey of attributesMap.keys()) {\n const attributes = attributesMap.get(attrKey);\n if (attributes.positions.length === 0) {\n attributesMap.delete(attrKey);\n continue; // eslint-disable-line no-continue\n }\n attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));\n }\n\n return attributesMap;\n}\n\n/**\n * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.\n * The goal is applying tranformation matrix for all children. Functions \"convertNodes\" and \"convertNode\" work together recursively.\n * @param {Object[]} nodes - gltf nodes array\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: UInt8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @returns {void}\n */\nfunction convertNodes(\n nodes,\n tileContent,\n attributesMap,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n if (nodes) {\n for (const node of nodes) {\n convertNode(node, tileContent, attributesMap, matrix);\n }\n }\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} node - gltf node\n * @param {Object} tileContent - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertNode(\n node,\n tileContent,\n attributesMap,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n const nodeMatrix = node.matrix;\n const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;\n\n const mesh = node.mesh;\n if (mesh) {\n convertMesh(mesh, tileContent, attributesMap, compositeMatrix);\n }\n\n convertNodes(node.children, tileContent, attributesMap, compositeMatrix);\n}\n\n/**\n * Convert all primitives of node and all children nodes\n * @param {Object} mesh - gltf node\n * @param {Object} content - 3d tile content\n * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of\n * attributes\n * @param {Matrix4} matrix - transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @todo: optimize arrays concatenation\n */\nfunction convertMesh(\n mesh,\n content,\n attributesMap,\n matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])\n) {\n for (const primitive of mesh.primitives) {\n let outputAttributes = null;\n if (primitive.material) {\n outputAttributes = attributesMap.get(primitive.material.id);\n } else if (attributesMap.has('default')) {\n outputAttributes = attributesMap.get('default');\n }\n assert(outputAttributes !== null, 'Primitive - material mapping failed');\n const attributes = primitive.attributes;\n\n outputAttributes.positions = concatenateTypedArrays(\n outputAttributes.positions,\n transformVertexArray({\n vertices: attributes.POSITION.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexPositions\n })\n );\n outputAttributes.normals = concatenateTypedArrays(\n outputAttributes.normals,\n transformVertexArray({\n vertices: attributes.NORMAL && attributes.NORMAL.value,\n cartographicOrigin: content.cartographicOrigin,\n cartesianModelMatrix: content.cartesianModelMatrix,\n nodeMatrix: matrix,\n indices: primitive.indices.value,\n attributeSpecificTransformation: transformVertexNormals\n })\n );\n outputAttributes.texCoords = concatenateTypedArrays(\n outputAttributes.texCoords,\n flattenTexCoords(\n attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value,\n primitive.indices.value\n )\n );\n\n outputAttributes.colors = concatenateTypedArrays(\n outputAttributes.colors,\n flattenColors(attributes.COLOR_0, primitive.indices.value)\n );\n\n outputAttributes.featureIndices.push(\n flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value)\n );\n }\n}\n\n/**\n * Convert vertices attributes (POSITIONS or NORMALS) to i3s compatible format\n * @param {object} args - source tile (3DTile)\n * @param {Float32Array} args.vertices - gltf primitive POSITION or NORMAL attribute\n * @param {Object} args.cartographicOrigin - cartographic origin coordinates\n * @param {Object} args.cartesianModelMatrix - a cartesian model matrix to transform coordnates from cartesian to cartographic format\n * @param {Matrix4} args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices\n * @param {Uint8Array} args.indices - gltf primitive indices\n * @param {Function} args.attributeSpecificTransformation - function to do attribute - specific transformations\n * @returns {Float32Array}\n */\nfunction transformVertexArray(args) {\n const {vertices, indices, attributeSpecificTransformation} = args;\n const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);\n if (!vertices) {\n return newVertices;\n }\n for (let i = 0; i < indices.length; i++) {\n const coordIndex = indices[i] * VALUES_PER_VERTEX;\n const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);\n let vertexVector = new Vector3(Array.from(vertex));\n\n vertexVector = attributeSpecificTransformation(vertexVector, args);\n\n newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;\n newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;\n newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;\n }\n return newVertices;\n}\n\nfunction transformVertexPositions(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, cartographicOrigin, nodeMatrix} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transform(nodeMatrix);\n }\n\n vertexVector = vertexVector.transform(cartesianModelMatrix);\n Ellipsoid.WGS84.cartesianToCartographic(\n [vertexVector[0], vertexVector[1], vertexVector[2]],\n vertexVector\n );\n vertexVector = vertexVector.subtract(cartographicOrigin);\n return vertexVector;\n}\n\nfunction transformVertexNormals(vertexVector, calleeArgs) {\n const {cartesianModelMatrix, nodeMatrix} = calleeArgs;\n\n if (nodeMatrix) {\n vertexVector = vertexVector.transformAsVector(nodeMatrix);\n }\n\n vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);\n return vertexVector;\n}\n\n/**\n * Convert uv0 (texture coordinates) from coords based on indices to plain arrays, compatible with i3s\n * @param {Float32Array} texCoords - gltf primitive TEXCOORD_0 attribute\n * @param {Uint8Array} indices - gltf primitive indices\n * @returns {Float32Array}\n */\nfunction flattenTexCoords(texCoords, indices) {\n 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":["Vector3","Matrix4","Vector4","Ellipsoid","DracoWriter","encode","assert","concatenateArrayBuffers","concatenateTypedArrays","md5","generateAttributes","createBoundingVolumesFromGeometry","VALUES_PER_VERTEX","VALUES_PER_TEX_COORD","VALUES_PER_COLOR_ELEMENT","STRING_TYPE","SHORT_INT_TYPE","DOUBLE_TYPE","OBJECT_ID_TYPE","BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES","scratchVector","convertB3dmToI3sGeometry","tileContent","nodeId","featuresHashArray","attributeStorageInfo","draco","generateBoundingVolumes","geoidHeightModel","useCartesianPositions","materialAndTextureList","convertMaterials","convertedAttributesMap","convertAttributes","_generateBoundingVolumesFromGeometry","has","push","material","getDefaultMaterial","result","nodesCounter","materials","gltf","length","id","i","sourceMaterial","convertedAttributes","get","texture","_makeNodeResources","attributes","values","boundingVolumes","positions","cartographicOrigin","obb","center","index","vertex","subarray","WGS84","cartesianToCartographic","Array","from","getHeight","subtract","set","vertexCount","triangleCount","faceRange","featureIds","normals","colors","texCoords","featureCount","batchTableJson","makeFeatureIdsUnique","featureIndices","header","Uint32Array","typedFeatureIds","generateBigUint64Array","fileBuffer","Uint8Array","buffer","ArrayBuffer","compressedGeometry","generateCompressedGeometry","Float32Array","convertBatchTableToAttributeBuffers","geometry","sharedResources","getSharedResources","meshMaterial","attributesMap","Map","nodes","scene","scenes","convertNodes","attrKey","keys","delete","reduce","acc","value","concat","matrix","node","convertNode","nodeMatrix","compositeMatrix","multiplyRight","mesh","convertMesh","children","content","primitive","primitives","outputAttributes","transformVertexArray","vertices","POSITION","cartesianModelMatrix","indices","attributeSpecificTransformation","transformVertexPositions","NORMAL","transformVertexNormals","flattenTexCoords","TEXCOORD_0","flattenColors","COLOR_0","flattenBatchIds","getBatchIdsByAttributeName","args","newVertices","coordIndex","vertexVector","x","y","z","calleeArgs","transform","transformAsVector","newTexCoords","fill","texCoord","colorsAttribute","components","newColors","colorIndex","color","colorUint8","j","batchedIds","newBatchIds","batchIds","possibleBatchIdAttributeName","sourceMaterials","convertMaterial","doubleSided","emissiveFactor","map","c","Math","round","alphaMode","toLowerCase","pbrMetallicRoughness","roughnessFactor","metallicFactor","baseColorTexture","source","textureSetDefinitionId","emissiveTexture","baseColorFactor","undefined","gltfMaterials","i3sResources","materialDefinitionInfos","gltfMaterial","materialDefinitionInfo","textureDefinitionInfo","convertGLTFMaterialToI3sSharedResources","textureDefinitionInfos","extractSharedResourcesTextureInfo","colorFactor","extractSharedResourcesMaterialInfo","matDielectricColorComponent","black","unitVector","dielectricSpecular","baseColorVector","firstOperand","multiply","diffuse","lerp","specular","toArray","encoding","mimeType","images","generateImageId","size","image","width","data","height","levelCountOfTexture","indexOfLevel","indexOfTextureInStore","zerosCount","toString","rightHalf","repeat","shiftedLevelCountOfTexture","shiftedIndexOfLevel","shiftedWidth","shiftedHeight","leftHalf","imageId","BigInt","batchTable","replaceMap","getFeaturesReplaceMap","replaceIndicesByUnique","featureMap","oldFeatureId","uniqueFeatureId","getOrCreateUniqueFeatureId","generateStringFromBatchTableByIndex","str","key","batchTableStr","hash","includes","indexOf","indicesArray","attributeBuffers","batchTableWithFeatureIds","OBJECTID","type","getAttributeType","attributeBuffer","generateShortIntegerAttributeBuffer","generateDoubleAttributeBuffer","generateStringAttributeBuffer","attribute","find","attr","name","attributeValues","valueType","count","valuesArray","padding","Float64Array","batchAttributes","stringCountArray","totalNumberOfBytes","stringSizesArray","stringBufferArray","currentString","String","currentStringBuffer","Buffer","currentStringSize","totalBytes","BigUint64Array","featureIndex","generateFeatureIndexAttribute","compressedAttributes","attributesMetadata","Int32Array","method","orderedFeatureIndices","fillIndex","startIndex","endIndex"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,OAA1B,QAAwC,eAAxC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAEA,SAAQC,WAAR,QAA0B,mBAA1B;AACA,SAAQC,MAAR,EAAgBC,MAAhB,QAA6B,kBAA7B;AACA,SAAQC,uBAAR,EAAiCC,sBAAjC,QAA8D,0BAA9D;AACA,OAAOC,GAAP,MAAgB,KAAhB;AACA,SAAQC,kBAAR,QAAiC,uBAAjC;AACA,SAAQC,iCAAR,QAAgD,wBAAhD;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,oBAAoB,GAAG,CAA7B;AACA,MAAMC,wBAAwB,GAAG,CAAjC;AAEA,MAAMC,WAAW,GAAG,QAApB;AACA,MAAMC,cAAc,GAAG,OAAvB;AACA,MAAMC,WAAW,GAAG,SAApB;AACA,MAAMC,cAAc,GAAG,OAAvB;AAMA,MAAMC,mCAAmC,GAAG,CAAC,oBAAD,EAAuB,UAAvB,EAAmC,SAAnC,CAA5C;AAEA,IAAIC,aAAa,GAAG,IAAIpB,OAAJ,EAApB;AAEA,eAAe,eAAeqB,wBAAf,CACbC,WADa,EAEbC,MAFa,EAGbC,iBAHa,EAIbC,oBAJa,EAKbC,KALa,EAMbC,uBANa,EAObC,gBAPa,EAQb;AACA,QAAMC,qBAAqB,GAAGF,uBAA9B;AACA,QAAMG,sBAAsB,GAAGC,gBAAgB,CAACT,WAAD,CAA/C;AACA,QAAMU,sBAAsB,GAAGC,iBAAiB,CAACX,WAAD,EAAcO,qBAAd,CAAhD;;AAEA,MAAIF,uBAAJ,EAA6B;AAC3BO,IAAAA,oCAAoC,CAACF,sBAAD,EAAyBJ,gBAAzB,CAApC;AACD;;AAED,MAAII,sBAAsB,CAACG,GAAvB,CAA2B,SAA3B,CAAJ,EAA2C;AACzCL,IAAAA,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,4BAAsB,eADP;AAEf,yBAAmB,IAAIC,UAAJ,CAAe5M,UAAf;AAFJ;AADQ,GAA3B;AAOA,SAAO,IAAIa,UAAJ,CACL,MAAM/E,MAAM,CAAC;AAAC8C,IAAAA,UAAU,EAAE8N,oBAAb;AAAmCpJ,IAAAA;AAAnC,GAAD,EAA8CzH,WAA9C,EAA2D;AACrEsB,IAAAA,KAAK,EAAE;AACL0P,MAAAA,MAAM,EAAE,0BADH;AAELF,MAAAA;AAFK;AAD8D,GAA3D,CADP,CAAP;AAQD;;AAQD,SAASF,6BAAT,CAAuCD,YAAvC,EAAqDzM,SAArD,EAAgE;AAC9D,QAAM+M,qBAAqB,GAAG,IAAIrM,WAAJ,CAAgB+L,YAAY,CAACpO,MAA7B,CAA9B;AACA,MAAI2O,SAAS,GAAG,CAAhB;AACA,MAAIC,UAAU,GAAG,CAAjB;;AAEA,OAAK,IAAI7N,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGY,SAAS,CAAC3B,MAAtC,EAA8Ce,KAAK,IAAI,CAAvD,EAA0D;AACxD,UAAM8N,QAAQ,GAAG,CAAClN,SAAS,CAACZ,KAAD,CAAT,GAAmB,CAApB,IAAyB9C,iBAA1C;AAEAyQ,IAAAA,qBAAqB,CAAClI,IAAtB,CAA2BmI,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"}
@@ -4,7 +4,7 @@ import { Vector3 } from '@math.gl/core';
4
4
  import { Ellipsoid } from '@math.gl/geospatial';
5
5
  export function validateNodeBoundingVolumes(node) {
6
6
  if (!node.parentNode.obb || !node.parentNode.mbs) {
7
- return null;
7
+ return [];
8
8
  }
9
9
 
10
10
  const tileWarnings = [];
@@ -53,9 +53,7 @@ function createBoundingBoxFromTileObb(obb) {
53
53
  function getTileObbVertices(node) {
54
54
  const geometry = new CubeGeometry();
55
55
  const halfSize = node.obb.halfSize;
56
- const {
57
- attributes
58
- } = geometry;
56
+ const attributes = geometry.getAttributes();
59
57
  const positions = new Float32Array(attributes.POSITION.value);
60
58
  const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);
61
59
  let vertices = [];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/i3s-converter/helpers/node-debug.js"],"names":["OrientedBoundingBox","BoundingSphere","CubeGeometry","Vector3","Ellipsoid","validateNodeBoundingVolumes","node","parentNode","obb","mbs","tileWarnings","validateObb","validateMbs","parentObb","createBoundingBoxFromTileObb","tileVertices","getTileObbVertices","isTileObbInsideParentObb","isAllVerticesInsideBoundingVolume","title","id","push","tileMbs","createBoundingSphereFromTileMbs","parentMbs","distanceBetweenCenters","center","distanceTo","radius","halfSize","quaternion","fromCenterHalfSizeQuaternion","geometry","attributes","positions","Float32Array","POSITION","value","obbCenterCartesian","WGS84","cartographicToCartesian","vertices","i","length","positionsVector","rotatedPositions","transformByQuaternion","add","concat","boundingVolume","isVerticesInsideObb","index","point","cartographicPoint","cartesianToCartographic","distance"],"mappings":"AAAA,SAAQA,mBAAR,EAA6BC,cAA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import {Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\n// TODO Unite Tile validation logic in i3s-17-and-debug with this code.\nexport function validateNodeBoundingVolumes(node) {\n if (!node.parentNode.obb || !node.parentNode.mbs) {\n return null;\n }\n const tileWarnings = [];\n\n validateObb(tileWarnings, node);\n validateMbs(tileWarnings, node);\n\n return tileWarnings;\n}\n\nfunction validateObb(tileWarnings, node) {\n const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);\n const tileVertices = getTileObbVertices(node);\n const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);\n\n if (isTileObbInsideParentObb) {\n return;\n }\n\n const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile OBB`;\n tileWarnings.push(title);\n}\n\nfunction validateMbs(tileWarnings, node) {\n const tileMbs = createBoundingSphereFromTileMbs(node.mbs);\n const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);\n const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);\n\n if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {\n const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile MBS`;\n tileWarnings.push(title);\n }\n}\n\nfunction createBoundingSphereFromTileMbs(mbs) {\n return new BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);\n}\n\nfunction createBoundingBoxFromTileObb(obb) {\n const {center, halfSize, quaternion} = obb;\n return new OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);\n}\n\n// TODO check if Obb generates properly\nfunction getTileObbVertices(node) {\n const geometry = new CubeGeometry();\n const halfSize = node.obb.halfSize;\n const {attributes} = geometry;\n const positions = new Float32Array(attributes.POSITION.value);\n const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);\n\n let vertices = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n const positionsVector = new Vector3(\n (positions[i] *= halfSize[0]),\n (positions[i + 1] *= halfSize[1]),\n (positions[i + 2] *= halfSize[2])\n );\n const rotatedPositions = positionsVector\n .transformByQuaternion(node.obb.quaternion)\n .add(obbCenterCartesian);\n vertices = vertices.concat(rotatedPositions);\n }\n\n return vertices;\n}\n\nfunction isAllVerticesInsideBoundingVolume(boundingVolume, positions) {\n let isVerticesInsideObb = true;\n\n for (let index = 0; index < positions.length / 3; index += 3) {\n const point = [positions[index], positions[index + 1], positions[index + 2]];\n const cartographicPoint = Ellipsoid.WGS84.cartesianToCartographic(point);\n\n const distance = boundingVolume.distanceTo(cartographicPoint);\n\n if (distance > 0) {\n isVerticesInsideObb = false;\n break;\n }\n }\n\n return isVerticesInsideObb;\n}\n"],"file":"node-debug.js"}
1
+ {"version":3,"sources":["../../../../src/i3s-converter/helpers/node-debug.ts"],"names":["OrientedBoundingBox","BoundingSphere","CubeGeometry","Vector3","Ellipsoid","validateNodeBoundingVolumes","node","parentNode","obb","mbs","tileWarnings","validateObb","validateMbs","parentObb","createBoundingBoxFromTileObb","tileVertices","getTileObbVertices","isTileObbInsideParentObb","isAllVerticesInsideBoundingVolume","title","id","push","tileMbs","createBoundingSphereFromTileMbs","parentMbs","distanceBetweenCenters","center","distanceTo","radius","halfSize","quaternion","fromCenterHalfSizeQuaternion","geometry","attributes","getAttributes","positions","Float32Array","POSITION","value","obbCenterCartesian","WGS84","cartographicToCartesian","vertices","i","length","positionsVector","rotatedPositions","transformByQuaternion","add","concat","boundingVolume","isVerticesInsideObb","index","point","cartographicPoint","cartesianToCartographic","distance"],"mappings":"AAAA,SAAQA,mBAAR,EAA6BC,cAA7B,QAAkD,kBAAlD;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AACA,SAAQC,OAAR,QAAsB,eAAtB;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAGA,OAAO,SAASC,2BAAT,CAAqCC,IAArC,EAA2C;AAChD,MAAI,CAACA,IAAI,CAACC,UAAL,CAAgBC,GAAjB,IAAwB,CAACF,IAAI,CAAC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AQ,CAAC,CAAD,CAHP,CAAxB;AAKA,UAAMiB,gBAAgB,GAAGD,eAAe,CACrCE,qBADsB,CACAzC,IAAI,CAACE,GAAL,CAASsB,UADT,EAEtBkB,GAFsB,CAElBT,kBAFkB,CAAzB;AAIAG,IAAAA,QAAQ,GAAGA,QAAQ,CAACO,MAAT,CAAgBH,gBAAhB,CAAX;AACD;;AAED,SAAOJ,QAAP;AACD;;AAED,SAASxB,iCAAT,CAA2CgC,cAA3C,EAA2Df,SAA3D,EAAsE;AACpE,MAAIgB,mBAAmB,GAAG,IAA1B;;AAEA,OAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGjB,SAAS,CAACS,MAAV,GAAmB,CAA/C,EAAkDQ,KAAK,IAAI,CAA3D,EAA8D;AAC5D,UAAMC,KAAK,GAAG,CAAClB,SAAS,CAACiB,KAAD,CAAV,EAAmBjB,SAAS,CAACiB,KAAK,GAAG,CAAT,CAA5B,EAAyCjB,SAAS,CAACiB,KAAK,GAAG,CAAT,CAAlD,CAAd;AACA,UAAME,iBAAiB,GAAGlD,SAAS,CAACoC,KAAV,CAAgBe,uBAAhB,CAAwCF,KAAxC,CAA1B;AAEA,UAAMG,QAAQ,GAAGN,cAAc,CAACvB,UAAf,CAA0B2B,iBAA1B,CAAjB;;AAEA,QAAIE,QAAQ,GAAG,CAAf,EAAkB;AAChBL,MAAAA,mBAAmB,GAAG,KAAtB;AACA;AACD;AACF;;AAED,SAAOA,mBAAP;AACD","sourcesContent":["import {OrientedBoundingBox, BoundingSphere} from '@math.gl/culling';\nimport {CubeGeometry} from '@luma.gl/engine';\nimport {Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\n// TODO Unite Tile validation logic in i3s-17-and-debug with this code.\nexport function validateNodeBoundingVolumes(node) {\n if (!node.parentNode.obb || !node.parentNode.mbs) {\n return [];\n }\n const tileWarnings = [];\n\n validateObb(tileWarnings, node);\n validateMbs(tileWarnings, node);\n\n return tileWarnings;\n}\n\nfunction validateObb(tileWarnings, node) {\n const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);\n const tileVertices = getTileObbVertices(node);\n const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);\n\n if (isTileObbInsideParentObb) {\n return;\n }\n\n const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile OBB`;\n tileWarnings.push(title);\n}\n\nfunction validateMbs(tileWarnings, node) {\n const tileMbs = createBoundingSphereFromTileMbs(node.mbs);\n const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);\n const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);\n\n if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {\n const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode.id}) tile MBS`;\n tileWarnings.push(title);\n }\n}\n\nfunction createBoundingSphereFromTileMbs(mbs) {\n return new BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);\n}\n\nfunction createBoundingBoxFromTileObb(obb) {\n const {center, halfSize, quaternion} = obb;\n return new OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);\n}\n\n// TODO check if Obb generates properly\nfunction getTileObbVertices(node) {\n const geometry = new CubeGeometry();\n const halfSize = node.obb.halfSize;\n const attributes = geometry.getAttributes();\n const positions = new Float32Array(attributes.POSITION.value);\n const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);\n\n let vertices = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n const positionsVector = new Vector3(\n (positions[i] *= halfSize[0]),\n (positions[i + 1] *= halfSize[1]),\n (positions[i + 2] *= halfSize[2])\n );\n const rotatedPositions = positionsVector\n .transformByQuaternion(node.obb.quaternion)\n .add(obbCenterCartesian);\n // @ts-expect-error\n vertices = vertices.concat(rotatedPositions);\n }\n\n return vertices;\n}\n\nfunction isAllVerticesInsideBoundingVolume(boundingVolume, positions) {\n let isVerticesInsideObb = true;\n\n for (let index = 0; index < positions.length / 3; index += 3) {\n const point = [positions[index], positions[index + 1], positions[index + 2]];\n const cartographicPoint = Ellipsoid.WGS84.cartesianToCartographic(point);\n\n const distance = boundingVolume.distanceTo(cartographicPoint);\n\n if (distance > 0) {\n isVerticesInsideObb = false;\n break;\n }\n }\n\n return isVerticesInsideObb;\n}\n"],"file":"node-debug.js"}
@@ -1,8 +1,17 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import { join } from 'path';
2
3
  import transform from 'json-map-transform';
3
4
  import { METADATA as metadataTemplate } from '../json-templates/metadata';
4
5
  export default class NodePages {
5
6
  constructor(writeFileFunc, nodesPerPage) {
7
+ _defineProperty(this, "nodesPerPage", void 0);
8
+
9
+ _defineProperty(this, "nodesCounter", void 0);
10
+
11
+ _defineProperty(this, "writeFile", void 0);
12
+
13
+ _defineProperty(this, "nodePages", void 0);
14
+
6
15
  this.nodesPerPage = nodesPerPage;
7
16
  this.nodesCounter = 0;
8
17
  this.nodePages = [{}];
@@ -74,12 +83,14 @@ export default class NodePages {
74
83
  }
75
84
 
76
85
  addChildRelation(parentId, childId) {
77
- if (parentId === null) {
86
+ var _parentNode$children;
87
+
88
+ if (parentId === null || parentId === undefined) {
78
89
  return;
79
90
  }
80
91
 
81
92
  const parentNode = this.getNodeById(parentId);
82
- parentNode.children.push(childId);
93
+ (_parentNode$children = parentNode.children) === null || _parentNode$children === void 0 ? void 0 : _parentNode$children.push(childId);
83
94
  }
84
95
 
85
96
  updateResourceInMesh(node) {
@@ -88,7 +99,7 @@ export default class NodePages {
88
99
  }
89
100
  }
90
101
 
91
- push(node, parentId = null) {
102
+ push(node, parentId) {
92
103
  let currentNodePage = this.nodePages[this.nodePages.length - 1];
93
104
 
94
105
  if (currentNodePage.nodes.length === this.nodesPerPage) {
@@ -118,7 +129,7 @@ export default class NodePages {
118
129
 
119
130
  const metadata = transform({
120
131
  nodeCount: this.nodesCounter
121
- }, metadataTemplate);
132
+ }, metadataTemplate());
122
133
  const compress = false;
123
134
  fileMap['metadata.json'] = await this.writeFile(layers0Path, JSON.stringify(metadata), 'metadata.json', compress);
124
135
  } else {