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

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 (177) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +1 -1
  2. package/dist/3d-tiles-attributes-worker.js +2 -3
  3. package/dist/3d-tiles-attributes-worker.js.map +3 -3
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -5
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +21 -17
  7. package/dist/converter.min.js +23 -20
  8. package/dist/dist.min.js +38223 -46900
  9. package/dist/es5/3d-tiles-attributes-worker.js +4 -7
  10. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  11. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +12 -111
  12. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  13. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +53 -85
  14. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  15. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -8
  16. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  17. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +0 -5
  18. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  19. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +0 -6
  20. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  21. package/dist/es5/bundle.js +0 -1
  22. package/dist/es5/bundle.js.map +1 -1
  23. package/dist/es5/constants.js.map +1 -1
  24. package/dist/es5/converter-cli.js +2 -53
  25. package/dist/es5/converter-cli.js.map +1 -1
  26. package/dist/es5/deps-installer/deps-installer.js +5 -35
  27. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  28. package/dist/es5/i3s-attributes-worker.js +3 -6
  29. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  30. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +2 -28
  31. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  32. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +2 -20
  33. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  34. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +0 -11
  35. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  36. package/dist/es5/i3s-converter/helpers/feature-attributes.js +5 -34
  37. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  38. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +13 -45
  39. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  40. package/dist/es5/i3s-converter/helpers/geometry-converter.js +26 -221
  41. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  42. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +2 -16
  43. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  44. package/dist/es5/i3s-converter/helpers/node-debug.js +4 -23
  45. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  46. package/dist/es5/i3s-converter/helpers/node-pages.js +50 -86
  47. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  48. package/dist/es5/i3s-converter/i3s-converter.js +43 -360
  49. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  50. package/dist/es5/i3s-converter/json-templates/layers.js +1 -15
  51. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  52. package/dist/es5/i3s-converter/json-templates/metadata.js +0 -2
  53. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  54. package/dist/es5/i3s-converter/json-templates/node.js +2 -12
  55. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  56. package/dist/es5/i3s-converter/json-templates/scene-server.js +0 -2
  57. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  58. package/dist/es5/i3s-converter/json-templates/shared-resources.js +6 -29
  59. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  60. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  61. package/dist/es5/i3s-converter/types.js.map +1 -1
  62. package/dist/es5/i3s-server/app.js +0 -5
  63. package/dist/es5/i3s-server/app.js.map +1 -1
  64. package/dist/es5/i3s-server/controllers/index-controller.js +0 -16
  65. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  66. package/dist/es5/i3s-server/routes/index.js +1 -10
  67. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  68. package/dist/es5/index.js +0 -3
  69. package/dist/es5/index.js.map +1 -1
  70. package/dist/es5/lib/utils/compress-util.js +19 -74
  71. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  72. package/dist/es5/lib/utils/file-utils.js +10 -38
  73. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  74. package/dist/es5/lib/utils/lod-conversion-utils.js +0 -7
  75. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  76. package/dist/es5/lib/utils/queue.js +0 -14
  77. package/dist/es5/lib/utils/queue.js.map +1 -1
  78. package/dist/es5/lib/utils/statistic-utills.js +1 -46
  79. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  80. package/dist/es5/lib/utils/write-queue.js +0 -52
  81. package/dist/es5/lib/utils/write-queue.js.map +1 -1
  82. package/dist/es5/pgm-loader.js +1 -8
  83. package/dist/es5/pgm-loader.js.map +1 -1
  84. package/dist/es5/workers/3d-tiles-attributes-worker.js +2 -9
  85. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
  86. package/dist/es5/workers/i3s-attributes-worker.js +1 -9
  87. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
  88. package/dist/esm/3d-tiles-attributes-worker.js +4 -2
  89. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
  90. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +8 -40
  91. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  92. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +29 -50
  93. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  94. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +1 -0
  95. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  96. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -4
  97. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  98. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +0 -3
  99. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  100. package/dist/esm/bundle.js +1 -1
  101. package/dist/esm/bundle.js.map +1 -1
  102. package/dist/esm/constants.js.map +1 -1
  103. package/dist/esm/converter-cli.js +3 -38
  104. package/dist/esm/converter-cli.js.map +1 -1
  105. package/dist/esm/deps-installer/deps-installer.js +6 -7
  106. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  107. package/dist/esm/i3s-attributes-worker.js +3 -1
  108. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  109. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +4 -23
  110. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  111. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +4 -6
  112. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  113. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +1 -0
  114. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  115. package/dist/esm/i3s-converter/helpers/feature-attributes.js +6 -20
  116. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  117. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +3 -22
  118. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  119. package/dist/esm/i3s-converter/helpers/geometry-converter.js +28 -139
  120. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  121. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +7 -12
  122. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  123. package/dist/esm/i3s-converter/helpers/node-debug.js +3 -13
  124. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  125. package/dist/esm/i3s-converter/helpers/node-pages.js +2 -21
  126. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  127. package/dist/esm/i3s-converter/i3s-converter.js +49 -137
  128. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  129. package/dist/esm/i3s-converter/json-templates/layers.js +1 -11
  130. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
  131. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  132. package/dist/esm/i3s-converter/json-templates/node.js +0 -4
  133. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
  134. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  135. package/dist/esm/i3s-converter/json-templates/shared-resources.js +0 -12
  136. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  137. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  138. package/dist/esm/i3s-converter/types.js.map +1 -1
  139. package/dist/esm/i3s-server/app.js +0 -5
  140. package/dist/esm/i3s-server/app.js.map +1 -1
  141. package/dist/esm/i3s-server/controllers/index-controller.js +0 -5
  142. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
  143. package/dist/esm/i3s-server/routes/index.js +0 -3
  144. package/dist/esm/i3s-server/routes/index.js.map +1 -1
  145. package/dist/esm/index.js.map +1 -1
  146. package/dist/esm/lib/utils/compress-util.js +19 -12
  147. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  148. package/dist/esm/lib/utils/file-utils.js +10 -8
  149. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  150. package/dist/esm/lib/utils/lod-conversion-utils.js +2 -6
  151. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  152. package/dist/esm/lib/utils/queue.js +0 -4
  153. package/dist/esm/lib/utils/queue.js.map +1 -1
  154. package/dist/esm/lib/utils/statistic-utills.js +0 -11
  155. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  156. package/dist/esm/lib/utils/write-queue.js +5 -23
  157. package/dist/esm/lib/utils/write-queue.js.map +1 -1
  158. package/dist/esm/pgm-loader.js +3 -1
  159. package/dist/esm/pgm-loader.js.map +1 -1
  160. package/dist/esm/workers/3d-tiles-attributes-worker.js +4 -1
  161. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -1
  162. package/dist/esm/workers/i3s-attributes-worker.js +4 -1
  163. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -1
  164. package/dist/i3s-attributes-worker.js +2 -3
  165. package/dist/i3s-attributes-worker.js.map +3 -3
  166. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  167. package/dist/i3s-converter/helpers/geometry-converter.js +2 -0
  168. package/dist/i3s-converter/i3s-converter.js +5 -1
  169. package/dist/pgm-loader.d.ts.map +1 -1
  170. package/dist/pgm-loader.js +2 -1
  171. package/dist/workers/3d-tiles-attributes-worker.js +1 -1
  172. package/package.json +15 -15
  173. package/src/3d-tiles-attributes-worker.ts +1 -1
  174. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +25 -18
  175. package/src/i3s-converter/helpers/geometry-converter.ts +2 -0
  176. package/src/pgm-loader.ts +2 -2
  177. package/src/workers/3d-tiles-attributes-worker.ts +1 -1
@@ -9,6 +9,7 @@ import { createBoundingVolumesFromGeometry } from './coordinate-converter';
9
9
  import { prepareDataForAttributesConversion } from './gltf-attributes';
10
10
  import { handleBatchIdsExtensions } from './batch-ids-extensions';
11
11
  import { checkPropertiesLength, flattenPropertyTableByFeatureIds } from './feature-attributes';
12
+
12
13
  const DEFAULT_ROUGHNESS_FACTOR = 1;
13
14
  const DEFAULT_METALLIC_FACTOR = 1;
14
15
  const VALUES_PER_VERTEX = 3;
@@ -22,9 +23,9 @@ const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', '
22
23
  const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
23
24
  const EXT_MESH_FEATURES = 'EXT_mesh_features';
24
25
  let scratchVector = new Vector3();
26
+
25
27
  export default async function convertB3dmToI3sGeometry(tileContent, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel, workerSource) {
26
28
  var _tileContent$gltf;
27
-
28
29
  const useCartesianPositions = generateBoundingVolumes;
29
30
  const materialAndTextureList = convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials);
30
31
  const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent);
@@ -33,39 +34,32 @@ export default async function convertB3dmToI3sGeometry(tileContent, addNodeToNod
33
34
  if (generateBoundingVolumes) {
34
35
  _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
35
36
  }
36
-
37
37
  if (convertedAttributesMap.has('default')) {
38
38
  materialAndTextureList.push({
39
39
  material: getDefaultMaterial()
40
40
  });
41
41
  }
42
-
43
42
  const result = [];
44
43
  let {
45
44
  materials = []
46
45
  } = tileContent.gltf || {
47
46
  materials: []
48
47
  };
49
-
50
48
  if (!(materials !== null && materials !== void 0 && materials.length)) {
51
49
  materials.push({
52
50
  id: 'default'
53
51
  });
54
52
  }
55
-
56
53
  for (let i = 0; i < materials.length; i++) {
57
54
  const sourceMaterial = materials[i];
58
-
59
55
  if (!convertedAttributesMap.has(sourceMaterial.id)) {
60
56
  continue;
61
57
  }
62
58
 
63
59
  const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
64
-
65
60
  if (!convertedAttributes) {
66
61
  continue;
67
62
  }
68
-
69
63
  const {
70
64
  material,
71
65
  texture
@@ -84,11 +78,9 @@ export default async function convertB3dmToI3sGeometry(tileContent, addNodeToNod
84
78
  workerSource
85
79
  }));
86
80
  }
87
-
88
81
  if (!result.length) {
89
82
  return null;
90
83
  }
91
-
92
84
  return result;
93
85
  }
94
86
 
@@ -97,7 +89,6 @@ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeigh
97
89
  const boundingVolumes = createBoundingVolumesFromGeometry(attributes.positions, geoidHeightModel);
98
90
  attributes.boundingVolumes = boundingVolumes;
99
91
  const cartographicOrigin = boundingVolumes.obb.center;
100
-
101
92
  for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
102
93
  const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
103
94
  Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
@@ -108,20 +99,20 @@ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeigh
108
99
  }
109
100
  }
110
101
 
111
- async function _makeNodeResources({
112
- convertedAttributes,
113
- material,
114
- texture,
115
- tileContent,
116
- nodeId,
117
- featuresHashArray,
118
- propertyTable,
119
- attributeStorageInfo,
120
- draco,
121
- workerSource
122
- }) {
102
+ async function _makeNodeResources(_ref) {
123
103
  var _tileContent$gltf2;
124
-
104
+ let {
105
+ convertedAttributes,
106
+ material,
107
+ texture,
108
+ tileContent,
109
+ nodeId,
110
+ featuresHashArray,
111
+ propertyTable,
112
+ attributeStorageInfo,
113
+ draco,
114
+ workerSource
115
+ } = _ref;
125
116
  const boundingVolumes = convertedAttributes.boundingVolumes;
126
117
  const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
127
118
  const {
@@ -133,11 +124,9 @@ async function _makeNodeResources({
133
124
  texCoords,
134
125
  featureCount
135
126
  } = generateAttributes(convertedAttributes);
136
-
137
127
  if (tileContent.batchTableJson) {
138
128
  makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
139
129
  }
140
-
141
130
  const header = new Uint32Array(2);
142
131
  const typedFeatureIds = generateBigUint64Array(featureIds);
143
132
  header.set([vertexCount, featureCount], 0);
@@ -151,11 +140,9 @@ async function _makeNodeResources({
151
140
  faceRange
152
141
  }, workerSource.draco) : null;
153
142
  let attributes = [];
154
-
155
143
  if (attributeStorageInfo && propertyTable) {
156
144
  attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
157
145
  }
158
-
159
146
  return {
160
147
  nodeId,
161
148
  geometry: fileBuffer,
@@ -179,7 +166,6 @@ export async function convertAttributes(attributesData, useCartesianPositions) {
179
166
  cartesianModelMatrix
180
167
  } = attributesData;
181
168
  const attributesMap = new Map();
182
-
183
169
  for (const material of gltfMaterials || [{
184
170
  id: 'default'
185
171
  }]) {
@@ -193,16 +179,12 @@ export async function convertAttributes(attributesData, useCartesianPositions) {
193
179
  boundingVolumes: null
194
180
  });
195
181
  }
196
-
197
182
  convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
198
-
199
183
  for (const attrKey of attributesMap.keys()) {
200
184
  const attributes = attributesMap.get(attrKey);
201
-
202
185
  if (!attributes) {
203
186
  continue;
204
187
  }
205
-
206
188
  if (attributes.positions.length === 0) {
207
189
  attributesMap.delete(attrKey);
208
190
  continue;
@@ -213,11 +195,11 @@ export async function convertAttributes(attributesData, useCartesianPositions) {
213
195
  delete attributes.featureIndicesGroups;
214
196
  }
215
197
  }
216
-
217
198
  return attributesMap;
218
199
  }
219
200
 
220
- function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
201
+ function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
202
+ let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
221
203
  if (nodes) {
222
204
  for (const node of nodes) {
223
205
  convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
@@ -233,56 +215,47 @@ function getCompositeTransformationMatrix(node, matrix) {
233
215
  scale,
234
216
  translation
235
217
  } = node;
236
-
237
218
  if (nodeMatrix) {
238
219
  transformationMatrix = matrix.multiplyRight(nodeMatrix);
239
220
  }
240
-
241
221
  if (translation) {
242
222
  transformationMatrix = transformationMatrix.translate(translation);
243
223
  }
244
-
245
224
  if (rotation) {
246
225
  transformationMatrix = transformationMatrix.rotateXYZ(rotation);
247
226
  }
248
-
249
227
  if (scale) {
250
228
  transformationMatrix = transformationMatrix.scale(scale);
251
229
  }
252
-
253
230
  return transformationMatrix;
254
231
  }
255
232
 
256
- function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
233
+ function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
234
+ let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
257
235
  const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
258
236
  const mesh = node.mesh;
259
-
260
237
  if (mesh) {
261
238
  convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
262
239
  }
263
-
264
240
  convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
265
241
  }
266
242
 
267
- function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
243
+ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap) {
244
+ let useCartesianPositions = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
245
+ let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
268
246
  for (const primitive of mesh.primitives) {
269
247
  var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$indices5;
270
-
271
248
  let outputAttributes = null;
272
-
273
249
  if (primitive.material) {
274
250
  outputAttributes = attributesMap.get(primitive.material.id);
275
251
  } else if (attributesMap.has('default')) {
276
252
  outputAttributes = attributesMap.get('default');
277
253
  }
278
-
279
254
  assert(outputAttributes !== null, 'Primitive - material mapping failed');
280
255
  const attributes = primitive.attributes;
281
-
282
256
  if (!outputAttributes) {
283
257
  continue;
284
258
  }
285
-
286
259
  outputAttributes.positions = concatenateTypedArrays(outputAttributes.positions, transformVertexArray({
287
260
  vertices: attributes.POSITION.value,
288
261
  cartographicOrigin,
@@ -315,11 +288,9 @@ function transformVertexArray(args) {
315
288
  attributeSpecificTransformation
316
289
  } = args;
317
290
  const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
318
-
319
291
  if (!vertices) {
320
292
  return newVertices;
321
293
  }
322
-
323
294
  for (let i = 0; i < indices.length; i++) {
324
295
  const coordIndex = indices[i] * VALUES_PER_VERTEX;
325
296
  const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
@@ -329,7 +300,6 @@ function transformVertexArray(args) {
329
300
  newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
330
301
  newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
331
302
  }
332
-
333
303
  return newVertices;
334
304
  }
335
305
 
@@ -340,17 +310,13 @@ function transformVertexPositions(vertexVector, calleeArgs) {
340
310
  nodeMatrix,
341
311
  useCartesianPositions
342
312
  } = calleeArgs;
343
-
344
313
  if (nodeMatrix) {
345
314
  vertexVector = vertexVector.transform(nodeMatrix);
346
315
  }
347
-
348
316
  vertexVector = vertexVector.transform(cartesianModelMatrix);
349
-
350
317
  if (useCartesianPositions) {
351
318
  return vertexVector;
352
319
  }
353
-
354
320
  Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
355
321
  vertexVector = vertexVector.subtract(cartographicOrigin);
356
322
  return vertexVector;
@@ -361,56 +327,45 @@ function transformVertexNormals(vertexVector, calleeArgs) {
361
327
  cartesianModelMatrix,
362
328
  nodeMatrix
363
329
  } = calleeArgs;
364
-
365
330
  if (nodeMatrix) {
366
331
  vertexVector = vertexVector.transformAsVector(nodeMatrix);
367
332
  }
368
-
369
333
  vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
370
334
  return vertexVector;
371
335
  }
372
336
 
373
337
  function flattenTexCoords(texCoords, indices) {
374
338
  const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
375
-
376
339
  if (!texCoords) {
377
340
  newTexCoords.fill(1);
378
341
  return newTexCoords;
379
342
  }
380
-
381
343
  for (let i = 0; i < indices.length; i++) {
382
344
  const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
383
345
  const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
384
346
  newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
385
347
  newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
386
348
  }
387
-
388
349
  return newTexCoords;
389
350
  }
390
351
 
391
352
  function flattenColors(colorsAttribute, indices) {
392
353
  const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
393
354
  const newColors = new Uint8Array(indices.length * components);
394
-
395
355
  if (!colorsAttribute) {
396
356
  newColors.fill(255);
397
357
  return newColors;
398
358
  }
399
-
400
359
  const colors = colorsAttribute.value;
401
-
402
360
  for (let i = 0; i < indices.length; i++) {
403
361
  const colorIndex = indices[i] * components;
404
362
  const color = colors.subarray(colorIndex, colorIndex + components);
405
363
  const colorUint8 = new Uint8Array(components);
406
-
407
364
  for (let j = 0; j < color.length; j++) {
408
365
  colorUint8[j] = color[j] * 255;
409
366
  }
410
-
411
367
  newColors.set(colorUint8, i * components);
412
368
  }
413
-
414
369
  return newColors;
415
370
  }
416
371
 
@@ -418,48 +373,39 @@ function flattenBatchIds(batchedIds, indices) {
418
373
  if (!batchedIds.length || !indices.length) {
419
374
  return [];
420
375
  }
421
-
422
376
  const newBatchIds = [];
423
-
424
377
  for (let i = 0; i < indices.length; i++) {
425
378
  const coordIndex = indices[i];
426
379
  newBatchIds.push(batchedIds[coordIndex]);
427
380
  }
428
-
429
381
  return newBatchIds;
430
382
  }
431
383
 
432
384
  function getBatchIds(attributes, primitive, images) {
433
385
  const batchIds = handleBatchIdsExtensions(attributes, primitive, images);
434
-
435
386
  if (batchIds.length) {
436
387
  return batchIds;
437
388
  }
438
-
439
389
  for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
440
390
  const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
441
-
442
391
  if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
443
392
  return attributes[possibleBatchIdAttributeName].value;
444
393
  }
445
394
  }
446
-
447
395
  return [];
448
396
  }
449
397
 
450
- function convertMaterials(sourceMaterials = []) {
398
+ function convertMaterials() {
399
+ let sourceMaterials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
451
400
  const result = [];
452
-
453
401
  for (const sourceMaterial of sourceMaterials) {
454
402
  result.push(convertMaterial(sourceMaterial));
455
403
  }
456
-
457
404
  return result;
458
405
  }
459
406
 
460
407
  function convertMaterial(sourceMaterial) {
461
408
  var _sourceMaterial$emiss, _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
462
-
463
409
  const material = {
464
410
  doubleSided: sourceMaterial.doubleSided,
465
411
  emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(c => Math.round(c * 255)),
@@ -470,7 +416,6 @@ function convertMaterial(sourceMaterial) {
470
416
  }
471
417
  };
472
418
  let texture;
473
-
474
419
  if (sourceMaterial !== null && sourceMaterial !== void 0 && (_sourceMaterial$pbrMe3 = sourceMaterial.pbrMetallicRoughness) !== null && _sourceMaterial$pbrMe3 !== void 0 && _sourceMaterial$pbrMe3.baseColorTexture) {
475
420
  texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
476
421
  material.pbrMetallicRoughness.baseColorTexture = {
@@ -482,14 +427,11 @@ function convertMaterial(sourceMaterial) {
482
427
  textureSetDefinitionId: 0
483
428
  };
484
429
  }
485
-
486
430
  if (!texture) {
487
431
  var _sourceMaterial$pbrMe4;
488
-
489
432
  const baseColorFactor = sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe4 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe4 === void 0 ? void 0 : _sourceMaterial$pbrMe4.baseColorFactor;
490
433
  material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
491
434
  }
492
-
493
435
  return {
494
436
  material,
495
437
  texture
@@ -500,13 +442,10 @@ function convertAlphaMode(gltfAlphaMode) {
500
442
  switch (gltfAlphaMode) {
501
443
  case 'OPAQUE':
502
444
  return 'opaque';
503
-
504
445
  case 'MASK':
505
446
  return 'mask';
506
-
507
447
  case 'BLEND':
508
448
  return 'blend';
509
-
510
449
  default:
511
450
  return 'opaque';
512
451
  }
@@ -524,57 +463,48 @@ function getDefaultMaterial() {
524
463
 
525
464
  function getSharedResources(gltfMaterials, nodeId) {
526
465
  const i3sResources = {};
527
-
528
466
  if (!gltfMaterials || !gltfMaterials.length) {
529
467
  return i3sResources;
530
468
  }
531
-
532
469
  i3sResources.materialDefinitionInfos = [];
533
-
534
470
  for (const gltfMaterial of gltfMaterials) {
535
471
  const {
536
472
  materialDefinitionInfo,
537
473
  textureDefinitionInfo
538
474
  } = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
539
475
  i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
540
-
541
476
  if (textureDefinitionInfo) {
542
477
  i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
543
478
  i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
544
479
  }
545
480
  }
546
-
547
481
  return i3sResources;
548
482
  }
549
483
 
550
484
  function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
551
485
  var _gltfMaterial$pbrMeta;
552
-
553
486
  const texture = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : (_gltfMaterial$pbrMeta = gltfMaterial.pbrMetallicRoughness) === null || _gltfMaterial$pbrMeta === void 0 ? void 0 : _gltfMaterial$pbrMeta.baseColorTexture) || gltfMaterial.emissiveTexture;
554
487
  let textureDefinitionInfo = null;
555
-
556
488
  if (texture) {
557
489
  textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
558
490
  }
559
-
560
491
  const {
561
492
  baseColorFactor,
562
493
  metallicFactor
563
494
  } = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : gltfMaterial.pbrMetallicRoughness) || {};
564
495
  let colorFactor = baseColorFactor;
565
-
566
496
  if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
567
497
  colorFactor = gltfMaterial.emissiveFactor;
568
498
  colorFactor[3] = colorFactor[3] || 1;
569
499
  }
570
-
571
500
  return {
572
501
  materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
573
502
  textureDefinitionInfo
574
503
  };
575
504
  }
576
505
 
577
- function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1) {
506
+ function extractSharedResourcesMaterialInfo(baseColorFactor) {
507
+ let metallicFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
578
508
  const matDielectricColorComponent = 0.04 / 255;
579
509
  const black = new Vector4(0, 0, 0, 1);
580
510
  const unitVector = new Vector4(1, 1, 1, 1);
@@ -595,7 +525,6 @@ function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1)
595
525
 
596
526
  function extractSharedResourcesTextureInfo(texture, nodeId) {
597
527
  var _texture$source, _texture$source2, _texture$source3;
598
-
599
528
  return {
600
529
  encoding: texture !== null && texture !== void 0 && (_texture$source = texture.source) !== null && _texture$source !== void 0 && _texture$source.mimeType ? [texture.source.mimeType] : undefined,
601
530
  images: [{
@@ -608,7 +537,6 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
608
537
 
609
538
  function generateImageId(texture, nodeId) {
610
539
  var _texture$source4;
611
-
612
540
  const {
613
541
  width,
614
542
  height
@@ -635,34 +563,28 @@ function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, bat
635
563
 
636
564
  function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
637
565
  const featureMap = {};
638
-
639
566
  for (let index = 0; index < featureIds.length; index++) {
640
567
  const oldFeatureId = featureIds[index];
641
568
  const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
642
569
  featureMap[oldFeatureId.toString()] = uniqueFeatureId;
643
570
  }
644
-
645
571
  return featureMap;
646
572
  }
647
573
 
648
574
  function generateStringFromBatchTableByIndex(batchTable, index) {
649
575
  let str = '';
650
-
651
576
  for (const key in batchTable) {
652
577
  str += batchTable[key][index];
653
578
  }
654
-
655
579
  return str;
656
580
  }
657
581
 
658
582
  function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
659
583
  const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
660
584
  const hash = md5(batchTableStr);
661
-
662
585
  if (featuresHashArray.includes(hash)) {
663
586
  return featuresHashArray.indexOf(hash);
664
587
  }
665
-
666
588
  return featuresHashArray.push(hash) - 1;
667
589
  }
668
590
 
@@ -680,38 +602,31 @@ function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attri
680
602
  OBJECTID: featureIds,
681
603
  ...properties
682
604
  };
683
-
684
605
  for (const propertyName in propertyTableWithObjectIds) {
685
606
  const type = getAttributeType(propertyName, attributeStorageInfo);
686
607
  const value = propertyTableWithObjectIds[propertyName];
687
608
  const attributeBuffer = generateAttributeBuffer(type, value);
688
609
  attributeBuffers.push(attributeBuffer);
689
610
  }
690
-
691
611
  return attributeBuffers;
692
612
  }
693
613
 
694
614
  function generateAttributeBuffer(type, value) {
695
615
  let attributeBuffer;
696
-
697
616
  switch (type) {
698
617
  case OBJECT_ID_TYPE:
699
618
  case SHORT_INT_TYPE:
700
619
  attributeBuffer = generateShortIntegerAttributeBuffer(value);
701
620
  break;
702
-
703
621
  case DOUBLE_TYPE:
704
622
  attributeBuffer = generateDoubleAttributeBuffer(value);
705
623
  break;
706
-
707
624
  case STRING_TYPE:
708
625
  attributeBuffer = generateStringAttributeBuffer(value);
709
626
  break;
710
-
711
627
  default:
712
628
  attributeBuffer = generateStringAttributeBuffer(value);
713
629
  }
714
-
715
630
  return attributeBuffer;
716
631
  }
717
632
 
@@ -738,7 +653,6 @@ function generateStringAttributeBuffer(batchAttributes) {
738
653
  let totalNumberOfBytes = 0;
739
654
  const stringSizesArray = new Uint32Array(batchAttributes.length);
740
655
  const stringBufferArray = [];
741
-
742
656
  for (let index = 0; index < batchAttributes.length; index++) {
743
657
  const currentString = "".concat(String(batchAttributes[index]), "\0");
744
658
  const currentStringBuffer = Buffer.from(currentString);
@@ -747,18 +661,15 @@ function generateStringAttributeBuffer(batchAttributes) {
747
661
  stringSizesArray[index] = currentStringSize;
748
662
  stringBufferArray.push(currentStringBuffer);
749
663
  }
750
-
751
664
  const totalBytes = new Uint32Array([totalNumberOfBytes]);
752
665
  return concatenateArrayBuffers(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
753
666
  }
754
667
 
755
668
  function generateBigUint64Array(featureIds) {
756
669
  const typedFeatureIds = new BigUint64Array(featureIds.length);
757
-
758
670
  for (let index = 0; index < featureIds.length; index++) {
759
671
  typedFeatureIds[index] = BigInt(featureIds[index]);
760
672
  }
761
-
762
673
  return typedFeatureIds;
763
674
  }
764
675
 
@@ -772,11 +683,9 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
772
683
  faceRange
773
684
  } = attributes;
774
685
  const indices = new Uint32Array(vertexCount);
775
-
776
686
  for (let index = 0; index < indices.length; index++) {
777
687
  indices.set([index], index);
778
688
  }
779
-
780
689
  const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
781
690
  const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
782
691
  const compressedAttributes = {
@@ -785,11 +694,9 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
785
694
  colors,
786
695
  'feature-index': featureIndex
787
696
  };
788
-
789
697
  if (texCoords.length) {
790
698
  compressedAttributes.texCoords = texCoords;
791
699
  }
792
-
793
700
  const attributesMetadata = {
794
701
  'feature-index': {
795
702
  'i3s-attribute-type': 'feature-index',
@@ -799,7 +706,8 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
799
706
  return encode({
800
707
  attributes: compressedAttributes,
801
708
  indices
802
- }, DracoWriterWorker, { ...DracoWriterWorker.options,
709
+ }, DracoWriterWorker, {
710
+ ...DracoWriterWorker.options,
803
711
  source: dracoWorkerSoure,
804
712
  reuseWorkers: true,
805
713
  _nodeWorkers: true,
@@ -814,41 +722,34 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
814
722
  const orderedFeatureIndices = new Uint32Array(featureIndex.length);
815
723
  let fillIndex = 0;
816
724
  let startIndex = 0;
817
-
818
725
  for (let index = 1; index < faceRange.length; index += 2) {
819
726
  const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
820
727
  orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
821
728
  fillIndex++;
822
729
  startIndex = endIndex + 1;
823
730
  }
824
-
825
731
  return orderedFeatureIndices;
826
732
  }
827
733
 
828
734
  export function getPropertyTable(tileContent) {
829
735
  const batchTableJson = tileContent === null || tileContent === void 0 ? void 0 : tileContent.batchTableJson;
830
-
831
736
  if (batchTableJson) {
832
737
  return batchTableJson;
833
738
  }
834
-
835
739
  const {
836
740
  extensionName,
837
741
  extension
838
742
  } = getPropertyTableExtension(tileContent);
839
-
840
743
  switch (extensionName) {
841
744
  case EXT_MESH_FEATURES:
842
745
  {
843
746
  console.warn('The I3S converter does not yet support the EXT_mesh_features extension');
844
747
  return null;
845
748
  }
846
-
847
749
  case EXT_FEATURE_METADATA:
848
750
  {
849
751
  return getPropertyTableFromExtFeatureMetadata(extension);
850
752
  }
851
-
852
753
  default:
853
754
  return null;
854
755
  }
@@ -856,28 +757,22 @@ export function getPropertyTable(tileContent) {
856
757
 
857
758
  function getPropertyTableExtension(tileContent) {
858
759
  var _tileContent$gltf3, _tileContent$gltf5, _tileContent$gltf5$ex;
859
-
860
760
  const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
861
761
  const extensionsUsed = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf3 = tileContent.gltf) === null || _tileContent$gltf3 === void 0 ? void 0 : _tileContent$gltf3.extensionsUsed;
862
-
863
762
  if (!extensionsUsed) {
864
763
  return {
865
764
  extensionName: null,
866
765
  extension: null
867
766
  };
868
767
  }
869
-
870
768
  let extensionName = '';
871
-
872
769
  for (const extensionItem of (tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf4 = tileContent.gltf) === null || _tileContent$gltf4 === void 0 ? void 0 : _tileContent$gltf4.extensionsUsed) || []) {
873
770
  var _tileContent$gltf4;
874
-
875
771
  if (extensionsWithPropertyTables.includes(extensionItem)) {
876
772
  extensionName = extensionItem;
877
773
  break;
878
774
  }
879
775
  }
880
-
881
776
  const extension = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf5 = tileContent.gltf) === null || _tileContent$gltf5 === void 0 ? void 0 : (_tileContent$gltf5$ex = _tileContent$gltf5.extensions) === null || _tileContent$gltf5$ex === void 0 ? void 0 : _tileContent$gltf5$ex[extensionName];
882
777
  return {
883
778
  extensionName,
@@ -890,24 +785,18 @@ function getPropertyTableFromExtFeatureMetadata(extension) {
890
785
  console.warn('The I3S converter does not yet support the EXT_feature_metadata feature textures');
891
786
  return null;
892
787
  }
893
-
894
788
  if (extension !== null && extension !== void 0 && extension.featureTables) {
895
789
  var _Object$keys;
896
-
897
790
  const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
898
-
899
791
  if (firstFeatureTableName) {
900
792
  const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTables[firstFeatureTableName];
901
793
  const propertyTable = {};
902
-
903
794
  for (const propertyName in featureTable.properties) {
904
795
  propertyTable[propertyName] = featureTable.properties[propertyName].data;
905
796
  }
906
-
907
797
  return propertyTable;
908
798
  }
909
799
  }
910
-
911
800
  console.warn("The I3S converter couldn't handle EXT_feature_metadata extension");
912
801
  return null;
913
802
  }