@loaders.gl/tile-converter 3.1.8 → 3.2.0-alpha.3

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 (238) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  2. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  3. package/dist/3d-tiles-attributes-worker.js +4 -0
  4. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  5. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +82 -0
  6. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  7. package/dist/3d-tiles-converter/3d-tiles-converter.js +268 -0
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +84 -0
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +278 -0
  11. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +13 -0
  12. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  13. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +23 -0
  14. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  15. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  16. package/dist/3d-tiles-converter/helpers/texture-atlas.js +52 -0
  17. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  18. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  19. package/dist/3d-tiles-converter/json-templates/tileset.js +43 -0
  20. package/dist/bundle.d.ts +2 -0
  21. package/dist/bundle.d.ts.map +1 -0
  22. package/dist/bundle.js +5 -0
  23. package/dist/converter-cli.d.ts +2 -0
  24. package/dist/converter-cli.d.ts.map +1 -0
  25. package/dist/converter-cli.js +232 -0
  26. package/dist/converter.min.js +68 -68
  27. package/dist/deps-installer/deps-installer.d.ts +14 -0
  28. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  29. package/dist/deps-installer/deps-installer.js +31 -0
  30. package/dist/dist.min.js +1151 -1264
  31. package/dist/es5/3d-tiles-attributes-worker.js +29 -0
  32. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  33. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +104 -44
  34. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  35. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +34 -43
  36. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  37. package/dist/es5/converter-cli.js +306 -0
  38. package/dist/es5/converter-cli.js.map +1 -0
  39. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  40. package/dist/es5/i3s-attributes-worker.js +29 -0
  41. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  42. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +19 -11
  43. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  44. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +2 -2
  45. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  46. package/dist/es5/i3s-converter/helpers/geometry-converter.js +271 -182
  47. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  48. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +71 -0
  49. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  50. package/dist/es5/i3s-converter/helpers/node-pages.js +47 -99
  51. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  52. package/dist/es5/i3s-converter/i3s-converter.js +311 -245
  53. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  54. package/dist/es5/index.js +0 -16
  55. package/dist/es5/index.js.map +1 -1
  56. package/dist/es5/lib/utils/compress-util.js +14 -17
  57. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  58. package/dist/es5/lib/utils/file-utils.js +39 -14
  59. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  60. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  61. package/dist/es5/lib/utils/queue.js +61 -0
  62. package/dist/es5/lib/utils/queue.js.map +1 -0
  63. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  64. package/dist/es5/lib/utils/write-queue.js +225 -0
  65. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  66. package/dist/es5/pgm-loader.js +1 -1
  67. package/dist/es5/pgm-loader.js.map +1 -1
  68. package/dist/es5/workers/3d-tiles-attributes-worker.js +37 -0
  69. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  70. package/dist/es5/workers/i3s-attributes-worker.js +40 -0
  71. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  72. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  73. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  74. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +32 -5
  75. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  76. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +23 -23
  77. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  78. package/dist/esm/converter-cli.js +230 -0
  79. package/dist/esm/converter-cli.js.map +1 -0
  80. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  81. package/dist/esm/i3s-attributes-worker.js +16 -0
  82. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  83. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +19 -11
  84. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  85. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +2 -2
  86. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  87. package/dist/esm/i3s-converter/helpers/geometry-converter.js +121 -62
  88. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +54 -0
  90. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  91. package/dist/esm/i3s-converter/helpers/node-pages.js +12 -4
  92. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  93. package/dist/esm/i3s-converter/i3s-converter.js +155 -50
  94. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  95. package/dist/esm/index.js +0 -2
  96. package/dist/esm/index.js.map +1 -1
  97. package/dist/esm/lib/utils/compress-util.js +6 -8
  98. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  99. package/dist/esm/lib/utils/file-utils.js +11 -1
  100. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  101. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  102. package/dist/esm/lib/utils/queue.js +19 -0
  103. package/dist/esm/lib/utils/queue.js.map +1 -0
  104. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  105. package/dist/esm/lib/utils/write-queue.js +88 -0
  106. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  107. package/dist/esm/pgm-loader.js +1 -1
  108. package/dist/esm/pgm-loader.js.map +1 -1
  109. package/dist/esm/workers/3d-tiles-attributes-worker.js +5 -0
  110. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  111. package/dist/esm/workers/i3s-attributes-worker.js +4 -0
  112. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  113. package/dist/i3s-attributes-worker.d.ts +33 -0
  114. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  115. package/dist/i3s-attributes-worker.js +10 -0
  116. package/dist/i3s-attributes-worker.js.map +7 -0
  117. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
  118. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  119. package/dist/i3s-converter/helpers/coordinate-converter.js +122 -0
  120. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  121. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  122. package/dist/i3s-converter/helpers/create-scene-server-path.js +28 -0
  123. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
  124. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  125. package/dist/i3s-converter/helpers/geometry-attributes.js +177 -0
  126. package/dist/i3s-converter/helpers/geometry-converter.d.ts +29 -0
  127. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  128. package/dist/i3s-converter/helpers/geometry-converter.js +901 -0
  129. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +9 -0
  130. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  131. package/dist/i3s-converter/helpers/gltf-attributes.js +56 -0
  132. package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
  133. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  134. package/dist/i3s-converter/helpers/node-debug.js +114 -0
  135. package/dist/i3s-converter/helpers/node-pages.d.ts +117 -0
  136. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  137. package/dist/i3s-converter/helpers/node-pages.js +208 -0
  138. package/dist/i3s-converter/i3s-converter.d.ts +323 -0
  139. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  140. package/dist/i3s-converter/i3s-converter.js +1074 -0
  141. package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
  142. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  143. package/dist/i3s-converter/json-templates/layers.js +199 -0
  144. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  145. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  146. package/dist/i3s-converter/json-templates/metadata.js +25 -0
  147. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  148. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  149. package/dist/i3s-converter/json-templates/node.js +89 -0
  150. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  151. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  152. package/dist/i3s-converter/json-templates/scene-server.js +31 -0
  153. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  154. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  155. package/dist/i3s-converter/json-templates/shared-resources.js +129 -0
  156. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  157. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  158. package/dist/i3s-converter/json-templates/store.js +103 -0
  159. package/dist/i3s-converter/types.d.ts +114 -0
  160. package/dist/i3s-converter/types.d.ts.map +1 -0
  161. package/dist/i3s-converter/types.js +2 -0
  162. package/dist/i3s-server/app.d.ts +3 -0
  163. package/dist/i3s-server/app.d.ts.map +1 -0
  164. package/dist/i3s-server/app.js +14 -0
  165. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  166. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  167. package/dist/i3s-server/controllers/index-controller.js +23 -0
  168. package/dist/i3s-server/routes/index.d.ts +3 -0
  169. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  170. package/dist/i3s-server/routes/index.js +16 -0
  171. package/dist/index.d.ts +3 -0
  172. package/dist/index.d.ts.map +1 -0
  173. package/dist/index.js +10 -0
  174. package/dist/lib/utils/compress-util.d.ts +45 -0
  175. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  176. package/dist/lib/utils/compress-util.js +257 -0
  177. package/dist/{esm/lib → lib}/utils/file-utils.d.ts +6 -14
  178. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  179. package/dist/lib/utils/file-utils.js +81 -0
  180. package/dist/lib/utils/lod-conversion-utils.d.ts +41 -0
  181. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  182. package/dist/lib/utils/lod-conversion-utils.js +76 -0
  183. package/dist/lib/utils/queue.d.ts +7 -0
  184. package/dist/lib/utils/queue.d.ts.map +1 -0
  185. package/dist/lib/utils/queue.js +18 -0
  186. package/dist/lib/utils/statistic-utills.d.ts +3 -0
  187. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  188. package/dist/lib/utils/statistic-utills.js +64 -0
  189. package/dist/lib/utils/write-queue.d.ts +22 -0
  190. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  191. package/dist/lib/utils/write-queue.js +62 -0
  192. package/dist/pgm-loader.d.ts +6 -0
  193. package/dist/pgm-loader.d.ts.map +1 -0
  194. package/dist/pgm-loader.js +23 -0
  195. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  196. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  197. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  198. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  199. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  200. package/dist/workers/i3s-attributes-worker.js +5 -0
  201. package/package.json +19 -18
  202. package/src/3d-tiles-attributes-worker.ts +43 -0
  203. package/src/3d-tiles-converter/3d-tiles-converter.ts +49 -6
  204. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +21 -18
  205. package/src/converter-cli.ts +310 -0
  206. package/src/deps-installer/{deps-installer.js → deps-installer.ts} +11 -1
  207. package/src/i3s-attributes-worker.ts +46 -0
  208. package/src/i3s-converter/helpers/coordinate-converter.ts +29 -24
  209. package/src/i3s-converter/helpers/geometry-attributes.ts +4 -3
  210. package/src/i3s-converter/helpers/{geometry-converter.js → geometry-converter.ts} +425 -179
  211. package/src/i3s-converter/helpers/gltf-attributes.ts +68 -0
  212. package/src/i3s-converter/helpers/node-pages.ts +25 -17
  213. package/src/i3s-converter/i3s-converter.ts +154 -87
  214. package/src/i3s-converter/types.ts +90 -8
  215. package/src/index.ts +0 -4
  216. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  217. package/src/lib/utils/file-utils.ts +84 -0
  218. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +27 -5
  219. package/src/lib/utils/queue.ts +17 -0
  220. package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
  221. package/src/lib/utils/write-queue.ts +75 -0
  222. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  223. package/src/workers/i3s-attributes-worker.ts +6 -0
  224. package/dist/es5/deps-installer/deps-installer.d.ts +0 -10
  225. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  226. package/dist/es5/lib/utils/compress-util.d.ts +0 -53
  227. package/dist/es5/lib/utils/file-utils.d.ts +0 -43
  228. package/dist/es5/lib/utils/lod-conversion-utils.d.ts +0 -32
  229. package/dist/esm/deps-installer/deps-installer.d.ts +0 -10
  230. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  231. package/dist/esm/lib/utils/compress-util.d.ts +0 -53
  232. package/dist/esm/lib/utils/lod-conversion-utils.d.ts +0 -32
  233. package/src/deps-installer/deps-installer.d.ts +0 -10
  234. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  235. package/src/lib/utils/compress-util.d.ts +0 -53
  236. package/src/lib/utils/file-utils.d.ts +0 -43
  237. package/src/lib/utils/file-utils.js +0 -38
  238. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
@@ -1,11 +1,12 @@
1
1
  import { Vector3, Matrix4, Vector4 } from '@math.gl/core';
2
2
  import { Ellipsoid } from '@math.gl/geospatial';
3
- import { DracoWriter } from '@loaders.gl/draco';
4
- import { encode, assert } from '@loaders.gl/core';
3
+ import { DracoWriterWorker } from '@loaders.gl/draco';
4
+ import { assert, encode } 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
8
  import { createBoundingVolumesFromGeometry } from './coordinate-converter';
9
+ import { prepareDataForAttributesConversion } from './gltf-attributes';
9
10
  const DEFAULT_ROUGHNESS_FACTOR = 1;
10
11
  const DEFAULT_METALLIC_FACTOR = 1;
11
12
  const VALUES_PER_VERTEX = 3;
@@ -17,10 +18,13 @@ const DOUBLE_TYPE = 'Float64';
17
18
  const OBJECT_ID_TYPE = 'Oid32';
18
19
  const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
19
20
  let scratchVector = new Vector3();
20
- export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel) {
21
+ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel, workerSource) {
22
+ var _tileContent$gltf;
23
+
21
24
  const useCartesianPositions = generateBoundingVolumes;
22
- const materialAndTextureList = convertMaterials(tileContent);
23
- const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);
25
+ const materialAndTextureList = convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials);
26
+ const dataForAttributesConversion = prepareDataForAttributesConversion(tileContent);
27
+ const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, useCartesianPositions);
24
28
 
25
29
  if (generateBoundingVolumes) {
26
30
  _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
@@ -36,7 +40,9 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
36
40
  let nodesCounter = nodeId;
37
41
  let {
38
42
  materials = []
39
- } = tileContent.gltf;
43
+ } = tileContent.gltf || {
44
+ materials: []
45
+ };
40
46
 
41
47
  if (!(materials !== null && materials !== void 0 && materials.length)) {
42
48
  materials.push({
@@ -52,6 +58,11 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
52
58
  }
53
59
 
54
60
  const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
61
+
62
+ if (!convertedAttributes) {
63
+ continue;
64
+ }
65
+
55
66
  const {
56
67
  material,
57
68
  texture
@@ -64,7 +75,8 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
64
75
  nodeId: nodesCounter,
65
76
  featuresHashArray,
66
77
  attributeStorageInfo,
67
- draco
78
+ draco,
79
+ workerSource
68
80
  }));
69
81
  nodesCounter++;
70
82
  }
@@ -100,11 +112,13 @@ async function _makeNodeResources({
100
112
  nodeId,
101
113
  featuresHashArray,
102
114
  attributeStorageInfo,
103
- draco
115
+ draco,
116
+ workerSource
104
117
  }) {
118
+ var _tileContent$gltf2;
119
+
105
120
  const boundingVolumes = convertedAttributes.boundingVolumes;
106
121
  const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
107
- const triangleCount = vertexCount / 3;
108
122
  const {
109
123
  faceRange,
110
124
  featureIds,
@@ -113,10 +127,7 @@ async function _makeNodeResources({
113
127
  colors,
114
128
  texCoords,
115
129
  featureCount
116
- } = generateAttributes({
117
- triangleCount,
118
- ...convertedAttributes
119
- });
130
+ } = generateAttributes(convertedAttributes);
120
131
 
121
132
  if (tileContent.batchTableJson) {
122
133
  makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
@@ -126,20 +137,20 @@ async function _makeNodeResources({
126
137
  const typedFeatureIds = generateBigUint64Array(featureIds);
127
138
  header.set([vertexCount, featureCount], 0);
128
139
  const fileBuffer = new Uint8Array(concatenateArrayBuffers(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
129
- const compressedGeometry = draco ? await generateCompressedGeometry(vertexCount, convertedAttributes, {
140
+ const compressedGeometry = draco ? generateCompressedGeometry(vertexCount, convertedAttributes, {
130
141
  positions,
131
142
  normals,
132
143
  texCoords: texture ? texCoords : new Float32Array(0),
133
144
  colors,
134
145
  featureIds,
135
146
  faceRange
136
- }) : null;
147
+ }, workerSource.draco) : null;
137
148
  const attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
138
149
  return {
139
150
  geometry: fileBuffer,
140
151
  compressedGeometry,
141
152
  texture,
142
- sharedResources: getSharedResources(tileContent, nodeId),
153
+ sharedResources: getSharedResources(((_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : _tileContent$gltf2.materials) || [], nodeId),
143
154
  meshMaterial: material,
144
155
  vertexCount,
145
156
  attributes,
@@ -148,12 +159,16 @@ async function _makeNodeResources({
148
159
  };
149
160
  }
150
161
 
151
- function convertAttributes(tileContent, useCartesianPositions) {
152
- var _tileContent$gltf$sce;
153
-
162
+ export async function convertAttributes(attributesData, useCartesianPositions) {
163
+ const {
164
+ gltfMaterials,
165
+ nodes,
166
+ cartographicOrigin,
167
+ cartesianModelMatrix
168
+ } = attributesData;
154
169
  const attributesMap = new Map();
155
170
 
156
- for (const material of tileContent.gltf.materials || [{
171
+ for (const material of gltfMaterials || [{
157
172
  id: 'default'
158
173
  }]) {
159
174
  attributesMap.set(material.id, {
@@ -161,32 +176,39 @@ function convertAttributes(tileContent, useCartesianPositions) {
161
176
  normals: new Float32Array(0),
162
177
  texCoords: new Float32Array(0),
163
178
  colors: new Uint8Array(0),
179
+ featureIndicesGroups: [],
164
180
  featureIndices: [],
165
181
  boundingVolumes: null
166
182
  });
167
183
  }
168
184
 
169
- 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;
170
- convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);
185
+ convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
171
186
 
172
187
  for (const attrKey of attributesMap.keys()) {
173
188
  const attributes = attributesMap.get(attrKey);
174
189
 
190
+ if (!attributes) {
191
+ continue;
192
+ }
193
+
175
194
  if (attributes.positions.length === 0) {
176
195
  attributesMap.delete(attrKey);
177
196
  continue;
178
197
  }
179
198
 
180
- attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
199
+ if (attributes.featureIndicesGroups) {
200
+ attributes.featureIndices = attributes.featureIndicesGroups.reduce((acc, value) => acc.concat(value));
201
+ delete attributes.featureIndicesGroups;
202
+ }
181
203
  }
182
204
 
183
205
  return attributesMap;
184
206
  }
185
207
 
186
- 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])) {
208
+ function convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
187
209
  if (nodes) {
188
210
  for (const node of nodes) {
189
- convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);
211
+ convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
190
212
  }
191
213
  }
192
214
  }
@@ -204,6 +226,10 @@ function getCompositeTransformationMatrix(node, matrix) {
204
226
  transformationMatrix = matrix.multiplyRight(nodeMatrix);
205
227
  }
206
228
 
229
+ if (translation) {
230
+ transformationMatrix = transformationMatrix.translate(translation);
231
+ }
232
+
207
233
  if (rotation) {
208
234
  transformationMatrix = transformationMatrix.rotateXYZ(rotation);
209
235
  }
@@ -212,26 +238,24 @@ function getCompositeTransformationMatrix(node, matrix) {
212
238
  transformationMatrix = transformationMatrix.scale(scale);
213
239
  }
214
240
 
215
- if (translation) {
216
- transformationMatrix = transformationMatrix.translate(translation);
217
- }
218
-
219
241
  return transformationMatrix;
220
242
  }
221
243
 
222
- 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])) {
244
+ function convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
223
245
  const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
224
246
  const mesh = node.mesh;
225
247
 
226
248
  if (mesh) {
227
- convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
249
+ convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
228
250
  }
229
251
 
230
- convertNodes(node.children, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
252
+ convertNodes(node.children || [], cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
231
253
  }
232
254
 
233
- 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])) {
255
+ function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
234
256
  for (const primitive of mesh.primitives) {
257
+ var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$indices5;
258
+
235
259
  let outputAttributes = null;
236
260
 
237
261
  if (primitive.material) {
@@ -242,27 +266,33 @@ function convertMesh(mesh, content, attributesMap, useCartesianPositions = false
242
266
 
243
267
  assert(outputAttributes !== null, 'Primitive - material mapping failed');
244
268
  const attributes = primitive.attributes;
269
+
270
+ if (!outputAttributes) {
271
+ continue;
272
+ }
273
+
245
274
  outputAttributes.positions = concatenateTypedArrays(outputAttributes.positions, transformVertexArray({
246
275
  vertices: attributes.POSITION.value,
247
- cartographicOrigin: content.cartographicOrigin,
248
- cartesianModelMatrix: content.cartesianModelMatrix,
276
+ cartographicOrigin,
277
+ cartesianModelMatrix,
249
278
  nodeMatrix: matrix,
250
- indices: primitive.indices.value,
279
+ indices: (_primitive$indices = primitive.indices) === null || _primitive$indices === void 0 ? void 0 : _primitive$indices.value,
251
280
  attributeSpecificTransformation: transformVertexPositions,
252
281
  useCartesianPositions
253
282
  }));
254
283
  outputAttributes.normals = concatenateTypedArrays(outputAttributes.normals, transformVertexArray({
255
284
  vertices: attributes.NORMAL && attributes.NORMAL.value,
256
- cartographicOrigin: content.cartographicOrigin,
257
- cartesianModelMatrix: content.cartesianModelMatrix,
285
+ cartographicOrigin,
286
+ cartesianModelMatrix,
258
287
  nodeMatrix: matrix,
259
- indices: primitive.indices.value,
288
+ indices: (_primitive$indices2 = primitive.indices) === null || _primitive$indices2 === void 0 ? void 0 : _primitive$indices2.value,
260
289
  attributeSpecificTransformation: transformVertexNormals,
261
290
  useCartesianPositions: false
262
291
  }));
263
- outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
264
- outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
265
- outputAttributes.featureIndices.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value));
292
+ outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, (_primitive$indices3 = primitive.indices) === null || _primitive$indices3 === void 0 ? void 0 : _primitive$indices3.value));
293
+ outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, (_primitive$indices4 = primitive.indices) === null || _primitive$indices4 === void 0 ? void 0 : _primitive$indices4.value));
294
+ outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
295
+ outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), (_primitive$indices5 = primitive.indices) === null || _primitive$indices5 === void 0 ? void 0 : _primitive$indices5.value));
266
296
  }
267
297
  }
268
298
 
@@ -402,9 +432,8 @@ function getBatchIdsByAttributeName(attributes) {
402
432
  return batchIds;
403
433
  }
404
434
 
405
- function convertMaterials(tileContent) {
435
+ function convertMaterials(sourceMaterials = []) {
406
436
  const result = [];
407
- const sourceMaterials = tileContent.gltf.materials || [];
408
437
 
409
438
  for (const sourceMaterial of sourceMaterials) {
410
439
  result.push(convertMaterial(sourceMaterial));
@@ -414,12 +443,12 @@ function convertMaterials(tileContent) {
414
443
  }
415
444
 
416
445
  function convertMaterial(sourceMaterial) {
417
- var _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
446
+ var _sourceMaterial$emiss, _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
418
447
 
419
448
  const material = {
420
449
  doubleSided: sourceMaterial.doubleSided,
421
- emissiveFactor: sourceMaterial.emissiveFactor.map(c => Math.round(c * 255)),
422
- alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),
450
+ emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(c => Math.round(c * 255)),
451
+ alphaMode: convertAlphaMode(sourceMaterial.alphaMode),
423
452
  pbrMetallicRoughness: {
424
453
  roughnessFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe === void 0 ? void 0 : _sourceMaterial$pbrMe.roughnessFactor) || DEFAULT_ROUGHNESS_FACTOR,
425
454
  metallicFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe2 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe2 === void 0 ? void 0 : _sourceMaterial$pbrMe2.metallicFactor) || DEFAULT_METALLIC_FACTOR
@@ -452,15 +481,33 @@ function convertMaterial(sourceMaterial) {
452
481
  };
453
482
  }
454
483
 
484
+ function convertAlphaMode(gltfAlphaMode) {
485
+ switch (gltfAlphaMode) {
486
+ case 'OPAQUE':
487
+ return 'opaque';
488
+
489
+ case 'MASK':
490
+ return 'mask';
491
+
492
+ case 'BLEND':
493
+ return 'blend';
494
+
495
+ default:
496
+ return 'opaque';
497
+ }
498
+ }
499
+
455
500
  function getDefaultMaterial() {
456
501
  return {
457
502
  alphaMode: 'opaque',
458
- pbrMetallicRoughness: {}
503
+ pbrMetallicRoughness: {
504
+ metallicFactor: 1,
505
+ roughnessFactor: 1
506
+ }
459
507
  };
460
508
  }
461
509
 
462
- function getSharedResources(tileContent, nodeId) {
463
- const gltfMaterials = tileContent.gltf.materials;
510
+ function getSharedResources(gltfMaterials, nodeId) {
464
511
  const i3sResources = {};
465
512
 
466
513
  if (!gltfMaterials || !gltfMaterials.length) {
@@ -507,7 +554,7 @@ function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
507
554
  }
508
555
 
509
556
  return {
510
- materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),
557
+ materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
511
558
  textureDefinitionInfo
512
559
  };
513
560
  }
@@ -523,27 +570,34 @@ function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 1)
523
570
  dielectricSpecular[3] = 1;
524
571
  const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
525
572
  return {
526
- diffuse: diffuse.toArray(),
527
- specular: specular.toArray()
573
+ params: {
574
+ diffuse: diffuse.toArray(),
575
+ specular: specular.toArray(),
576
+ renderMode: 'solid'
577
+ }
528
578
  };
529
579
  }
530
580
 
531
581
  function extractSharedResourcesTextureInfo(texture, nodeId) {
582
+ var _texture$source, _texture$source2, _texture$source3;
583
+
532
584
  return {
533
- encoding: [texture.source.mimeType],
585
+ encoding: texture !== null && texture !== void 0 && (_texture$source = texture.source) !== null && _texture$source !== void 0 && _texture$source.mimeType ? [texture.source.mimeType] : undefined,
534
586
  images: [{
535
587
  id: generateImageId(texture, nodeId),
536
- size: texture.source.image.width,
537
- length: [texture.source.image.data.length]
588
+ size: (_texture$source2 = texture.source) === null || _texture$source2 === void 0 ? void 0 : _texture$source2.image.width,
589
+ length: [(_texture$source3 = texture.source) === null || _texture$source3 === void 0 ? void 0 : _texture$source3.image.data.length]
538
590
  }]
539
591
  };
540
592
  }
541
593
 
542
594
  function generateImageId(texture, nodeId) {
595
+ var _texture$source4;
596
+
543
597
  const {
544
598
  width,
545
599
  height
546
- } = texture.source.image;
600
+ } = (_texture$source4 = texture.source) === null || _texture$source4 === void 0 ? void 0 : _texture$source4.image;
547
601
  const levelCountOfTexture = 1;
548
602
  const indexOfLevel = 0;
549
603
  const indexOfTextureInStore = nodeId + 1;
@@ -634,7 +688,9 @@ function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeSt
634
688
  attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
635
689
  }
636
690
 
637
- attributeBuffers.push(attributeBuffer);
691
+ if (attributeBuffer) {
692
+ attributeBuffers.push(attributeBuffer);
693
+ }
638
694
  }
639
695
  }
640
696
 
@@ -688,7 +744,7 @@ function generateBigUint64Array(featureIds) {
688
744
  return typedFeatureIds;
689
745
  }
690
746
 
691
- async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {
747
+ async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
692
748
  const {
693
749
  positions,
694
750
  normals,
@@ -722,15 +778,18 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
722
778
  'i3s-feature-ids': new Int32Array(featureIds)
723
779
  }
724
780
  };
725
- return new Uint8Array(await encode({
781
+ return encode({
726
782
  attributes: compressedAttributes,
727
783
  indices
728
- }, DracoWriter, {
784
+ }, DracoWriterWorker, { ...DracoWriterWorker.options,
785
+ source: dracoWorkerSoure,
786
+ reuseWorkers: true,
787
+ _nodeWorkers: true,
729
788
  draco: {
730
789
  method: 'MESH_SEQUENTIAL_ENCODING',
731
790
  attributesMetadata
732
791
  }
733
- }));
792
+ });
734
793
  }
735
794
 
736
795
  function generateFeatureIndexAttribute(featureIndex, faceRange) {