@loaders.gl/tile-converter 3.2.12 → 3.3.0-alpha.10

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 (251) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +3 -3
  2. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -1
  3. package/dist/3d-tiles-attributes-worker.js +2 -3
  4. package/dist/3d-tiles-attributes-worker.js.map +3 -3
  5. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +8 -0
  6. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/3d-tiles-converter.js +57 -43
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -5
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +21 -17
  11. package/dist/converter-cli.js +43 -8
  12. package/dist/converter.min.js +24 -21
  13. package/dist/deps-installer/deps-installer.d.ts +5 -1
  14. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  15. package/dist/deps-installer/deps-installer.js +29 -1
  16. package/dist/dist.min.js +58405 -61237
  17. package/dist/es5/3d-tiles-attributes-worker.js +4 -7
  18. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  19. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +125 -210
  20. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  21. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +53 -85
  22. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  23. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -8
  24. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  25. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +0 -5
  26. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  27. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +0 -6
  28. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  29. package/dist/es5/bundle.js +0 -1
  30. package/dist/es5/bundle.js.map +1 -1
  31. package/dist/es5/constants.js.map +1 -1
  32. package/dist/es5/converter-cli.js +50 -60
  33. package/dist/es5/converter-cli.js.map +1 -1
  34. package/dist/es5/deps-installer/deps-installer.js +73 -28
  35. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  36. package/dist/es5/i3s-attributes-worker.js +3 -6
  37. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  38. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +124 -0
  39. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  40. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +2 -19
  41. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  42. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +0 -11
  43. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  44. package/dist/es5/i3s-converter/helpers/feature-attributes.js +184 -0
  45. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
  46. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +60 -51
  47. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  48. package/dist/es5/i3s-converter/helpers/geometry-converter.js +516 -356
  49. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  50. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +57 -43
  51. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  52. package/dist/es5/i3s-converter/helpers/node-debug.js +4 -23
  53. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  54. package/dist/es5/i3s-converter/helpers/node-index-document.js +507 -0
  55. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
  56. package/dist/es5/i3s-converter/helpers/node-pages.js +462 -208
  57. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  58. package/dist/es5/i3s-converter/i3s-converter.js +722 -1153
  59. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  60. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
  61. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  62. package/dist/es5/i3s-converter/json-templates/layers.js +2 -107
  63. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  64. package/dist/es5/i3s-converter/json-templates/metadata.js +0 -2
  65. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  66. package/dist/es5/i3s-converter/json-templates/node.js +2 -12
  67. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  68. package/dist/es5/i3s-converter/json-templates/scene-server.js +0 -2
  69. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  70. package/dist/es5/i3s-converter/json-templates/shared-resources.js +9 -32
  71. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  72. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  73. package/dist/es5/i3s-converter/types.js.map +1 -1
  74. package/dist/es5/i3s-server/app.js +0 -5
  75. package/dist/es5/i3s-server/app.js.map +1 -1
  76. package/dist/es5/i3s-server/controllers/index-controller.js +0 -16
  77. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  78. package/dist/es5/i3s-server/routes/index.js +1 -10
  79. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  80. package/dist/es5/index.js +0 -3
  81. package/dist/es5/index.js.map +1 -1
  82. package/dist/es5/lib/utils/compress-util.js +19 -74
  83. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  84. package/dist/es5/lib/utils/file-utils.js +103 -47
  85. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  86. package/dist/es5/lib/utils/lod-conversion-utils.js +0 -7
  87. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  88. package/dist/es5/lib/utils/queue.js +0 -14
  89. package/dist/es5/lib/utils/queue.js.map +1 -1
  90. package/dist/es5/lib/utils/statistic-utills.js +1 -46
  91. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  92. package/dist/es5/lib/utils/write-queue.js +41 -82
  93. package/dist/es5/lib/utils/write-queue.js.map +1 -1
  94. package/dist/es5/pgm-loader.js +1 -8
  95. package/dist/es5/pgm-loader.js.map +1 -1
  96. package/dist/es5/workers/3d-tiles-attributes-worker.js +2 -9
  97. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
  98. package/dist/es5/workers/i3s-attributes-worker.js +2 -10
  99. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
  100. package/dist/esm/3d-tiles-attributes-worker.js +4 -2
  101. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
  102. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +60 -77
  103. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  104. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +29 -50
  105. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  106. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +1 -0
  107. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  108. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -4
  109. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  110. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +0 -3
  111. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  112. package/dist/esm/bundle.js +1 -1
  113. package/dist/esm/bundle.js.map +1 -1
  114. package/dist/esm/constants.js.map +1 -1
  115. package/dist/esm/converter-cli.js +46 -40
  116. package/dist/esm/converter-cli.js.map +1 -1
  117. package/dist/esm/deps-installer/deps-installer.js +30 -4
  118. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  119. package/dist/esm/i3s-attributes-worker.js +3 -1
  120. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  121. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +113 -0
  122. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  123. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +5 -6
  124. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  125. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +1 -0
  126. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  127. package/dist/esm/i3s-converter/helpers/feature-attributes.js +158 -0
  128. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
  129. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +39 -33
  130. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  131. package/dist/esm/i3s-converter/helpers/geometry-converter.js +295 -196
  132. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  133. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +59 -34
  134. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  135. package/dist/esm/i3s-converter/helpers/node-debug.js +3 -13
  136. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  137. package/dist/esm/i3s-converter/helpers/node-index-document.js +197 -0
  138. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
  139. package/dist/esm/i3s-converter/helpers/node-pages.js +161 -87
  140. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  141. package/dist/esm/i3s-converter/i3s-converter.js +216 -491
  142. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  143. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
  144. package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
  145. package/dist/esm/i3s-converter/json-templates/layers.js +2 -95
  146. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
  147. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  148. package/dist/esm/i3s-converter/json-templates/node.js +0 -4
  149. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
  150. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  151. package/dist/esm/i3s-converter/json-templates/shared-resources.js +3 -15
  152. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  153. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  154. package/dist/esm/i3s-converter/types.js.map +1 -1
  155. package/dist/esm/i3s-server/app.js +0 -5
  156. package/dist/esm/i3s-server/app.js.map +1 -1
  157. package/dist/esm/i3s-server/controllers/index-controller.js +0 -5
  158. package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
  159. package/dist/esm/i3s-server/routes/index.js +0 -3
  160. package/dist/esm/i3s-server/routes/index.js.map +1 -1
  161. package/dist/esm/index.js.map +1 -1
  162. package/dist/esm/lib/utils/compress-util.js +19 -12
  163. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  164. package/dist/esm/lib/utils/file-utils.js +54 -11
  165. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  166. package/dist/esm/lib/utils/lod-conversion-utils.js +2 -6
  167. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  168. package/dist/esm/lib/utils/queue.js +0 -4
  169. package/dist/esm/lib/utils/queue.js.map +1 -1
  170. package/dist/esm/lib/utils/statistic-utills.js +0 -11
  171. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  172. package/dist/esm/lib/utils/write-queue.js +27 -38
  173. package/dist/esm/lib/utils/write-queue.js.map +1 -1
  174. package/dist/esm/pgm-loader.js +3 -1
  175. package/dist/esm/pgm-loader.js.map +1 -1
  176. package/dist/esm/workers/3d-tiles-attributes-worker.js +4 -1
  177. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -1
  178. package/dist/esm/workers/i3s-attributes-worker.js +4 -1
  179. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -1
  180. package/dist/i3s-attributes-worker.d.ts +7 -3
  181. package/dist/i3s-attributes-worker.d.ts.map +1 -1
  182. package/dist/i3s-attributes-worker.js +2 -3
  183. package/dist/i3s-attributes-worker.js.map +3 -3
  184. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +11 -0
  185. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
  186. package/dist/i3s-converter/helpers/batch-ids-extensions.js +141 -0
  187. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +2 -2
  188. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  189. package/dist/i3s-converter/helpers/feature-attributes.d.ts +56 -0
  190. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
  191. package/dist/i3s-converter/helpers/feature-attributes.js +216 -0
  192. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  193. package/dist/i3s-converter/helpers/geometry-attributes.js +42 -17
  194. package/dist/i3s-converter/helpers/geometry-converter.d.ts +18 -6
  195. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  196. package/dist/i3s-converter/helpers/geometry-converter.js +349 -99
  197. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  198. package/dist/i3s-converter/helpers/gltf-attributes.js +53 -21
  199. package/dist/i3s-converter/helpers/node-index-document.d.ts +91 -0
  200. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
  201. package/dist/i3s-converter/helpers/node-index-document.js +242 -0
  202. package/dist/i3s-converter/helpers/node-pages.d.ts +81 -42
  203. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  204. package/dist/i3s-converter/helpers/node-pages.js +200 -92
  205. package/dist/i3s-converter/i3s-converter.d.ts +52 -108
  206. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  207. package/dist/i3s-converter/i3s-converter.js +218 -403
  208. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
  209. package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
  210. package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
  211. package/dist/i3s-converter/json-templates/layers.d.ts +1 -30
  212. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -1
  213. package/dist/i3s-converter/json-templates/layers.js +2 -86
  214. package/dist/i3s-converter/json-templates/shared-resources.js +3 -3
  215. package/dist/i3s-converter/types.d.ts +38 -8
  216. package/dist/i3s-converter/types.d.ts.map +1 -1
  217. package/dist/lib/utils/file-utils.d.ts +17 -1
  218. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  219. package/dist/lib/utils/file-utils.js +64 -7
  220. package/dist/lib/utils/write-queue.d.ts +19 -3
  221. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  222. package/dist/lib/utils/write-queue.js +21 -16
  223. package/dist/pgm-loader.d.ts.map +1 -1
  224. package/dist/pgm-loader.js +2 -1
  225. package/dist/workers/3d-tiles-attributes-worker.js +1 -1
  226. package/dist/workers/i3s-attributes-worker.js +1 -1
  227. package/package.json +18 -16
  228. package/src/3d-tiles-attributes-worker.ts +1 -1
  229. package/src/3d-tiles-converter/3d-tiles-converter.ts +71 -55
  230. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +25 -18
  231. package/src/converter-cli.ts +54 -8
  232. package/src/deps-installer/deps-installer.ts +38 -2
  233. package/src/i3s-attributes-worker.ts +5 -1
  234. package/src/i3s-converter/helpers/batch-ids-extensions.ts +206 -0
  235. package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
  236. package/src/i3s-converter/helpers/feature-attributes.ts +247 -0
  237. package/src/i3s-converter/helpers/geometry-attributes.ts +46 -18
  238. package/src/i3s-converter/helpers/geometry-converter.ts +423 -111
  239. package/src/i3s-converter/helpers/gltf-attributes.ts +59 -24
  240. package/src/i3s-converter/helpers/node-index-document.ts +306 -0
  241. package/src/i3s-converter/helpers/node-pages.ts +222 -109
  242. package/src/i3s-converter/i3s-converter.ts +264 -487
  243. package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
  244. package/src/i3s-converter/json-templates/layers.ts +2 -91
  245. package/src/i3s-converter/json-templates/shared-resources.ts +3 -3
  246. package/src/i3s-converter/types.ts +33 -2
  247. package/src/lib/utils/file-utils.ts +62 -7
  248. package/src/lib/utils/write-queue.ts +42 -19
  249. package/src/pgm-loader.ts +2 -2
  250. package/src/workers/3d-tiles-attributes-worker.ts +1 -1
  251. package/src/workers/i3s-attributes-worker.ts +2 -1
@@ -1,47 +1,35 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = convertB3dmToI3sGeometry;
9
8
  exports.convertAttributes = convertAttributes;
10
-
9
+ exports.default = convertB3dmToI3sGeometry;
10
+ exports.getPropertyTable = getPropertyTable;
11
11
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
-
13
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
-
15
13
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
-
17
14
  var _core = require("@math.gl/core");
18
-
19
15
  var _geospatial = require("@math.gl/geospatial");
20
-
21
16
  var _draco = require("@loaders.gl/draco");
22
-
23
17
  var _core2 = require("@loaders.gl/core");
24
-
25
18
  var _loaderUtils = require("@loaders.gl/loader-utils");
26
-
27
19
  var _md = _interopRequireDefault(require("md5"));
28
-
20
+ var _uuid = require("uuid");
29
21
  var _geometryAttributes = require("./geometry-attributes");
30
-
31
22
  var _coordinateConverter = require("./coordinate-converter");
32
-
33
23
  var _gltfAttributes = require("./gltf-attributes");
34
-
35
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
36
-
37
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
38
-
24
+ var _batchIdsExtensions = require("./batch-ids-extensions");
25
+ var _featureAttributes = require("./feature-attributes");
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
39
30
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
40
-
41
31
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
42
-
43
32
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
44
-
45
33
  var DEFAULT_ROUGHNESS_FACTOR = 1;
46
34
  var DEFAULT_METALLIC_FACTOR = 1;
47
35
  var VALUES_PER_VERTEX = 3;
@@ -52,145 +40,124 @@ var SHORT_INT_TYPE = 'Int32';
52
40
  var DOUBLE_TYPE = 'Float64';
53
41
  var OBJECT_ID_TYPE = 'Oid32';
54
42
  var BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
43
+ var EXT_FEATURE_METADATA = 'EXT_feature_metadata';
44
+ var EXT_MESH_FEATURES = 'EXT_mesh_features';
55
45
  var scratchVector = new _core.Vector3();
56
46
 
57
- function convertB3dmToI3sGeometry(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
47
+ function convertB3dmToI3sGeometry(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8, _x9, _x10) {
58
48
  return _convertB3dmToI3sGeometry.apply(this, arguments);
59
49
  }
60
-
61
50
  function _convertB3dmToI3sGeometry() {
62
- _convertB3dmToI3sGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel, workerSource) {
63
- var _tileContent$gltf;
64
-
65
- var useCartesianPositions, materialAndTextureList, dataForAttributesConversion, convertedAttributesMap, result, nodesCounter, _ref3, _ref3$materials, materials, i, sourceMaterial, convertedAttributes, _materialAndTextureLi, material, texture;
66
-
51
+ _convertB3dmToI3sGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(tileContent, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
52
+ var _tileContent$gltf4;
53
+ var useCartesianPositions, materialAndTextureList, dataForAttributesConversion, convertedAttributesMap, result, _iterator6, _step6, materialAndTexture, originarMaterialId, convertedAttributes, material, texture, nodeId;
67
54
  return _regenerator.default.wrap(function _callee$(_context) {
68
55
  while (1) {
69
56
  switch (_context.prev = _context.next) {
70
57
  case 0:
71
58
  useCartesianPositions = generateBoundingVolumes;
72
- materialAndTextureList = convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials);
59
+ _context.next = 3;
60
+ return convertMaterials((_tileContent$gltf4 = tileContent.gltf) === null || _tileContent$gltf4 === void 0 ? void 0 : _tileContent$gltf4.materials, shouldMergeMaterials);
61
+ case 3:
62
+ materialAndTextureList = _context.sent;
73
63
  dataForAttributesConversion = (0, _gltfAttributes.prepareDataForAttributesConversion)(tileContent);
74
- _context.next = 5;
75
- return convertAttributes(dataForAttributesConversion, useCartesianPositions);
76
-
77
- case 5:
64
+ _context.next = 7;
65
+ return convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions);
66
+ case 7:
78
67
  convertedAttributesMap = _context.sent;
79
68
 
80
69
  if (generateBoundingVolumes) {
81
70
  _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
82
71
  }
83
-
84
- if (convertedAttributesMap.has('default')) {
85
- materialAndTextureList.push({
86
- material: getDefaultMaterial()
87
- });
88
- }
89
-
90
72
  result = [];
91
- nodesCounter = nodeId;
92
- _ref3 = tileContent.gltf || {
93
- materials: []
94
- }, _ref3$materials = _ref3.materials, materials = _ref3$materials === void 0 ? [] : _ref3$materials;
95
-
96
- if (!(materials !== null && materials !== void 0 && materials.length)) {
97
- materials.push({
98
- id: 'default'
99
- });
100
- }
101
-
102
- i = 0;
103
-
73
+ _iterator6 = _createForOfIteratorHelper(materialAndTextureList);
74
+ _context.prev = 11;
75
+ _iterator6.s();
104
76
  case 13:
105
- if (!(i < materials.length)) {
106
- _context.next = 30;
77
+ if ((_step6 = _iterator6.n()).done) {
78
+ _context.next = 32;
107
79
  break;
108
80
  }
109
-
110
- sourceMaterial = materials[i];
111
-
112
- if (convertedAttributesMap.has(sourceMaterial.id)) {
113
- _context.next = 17;
81
+ materialAndTexture = _step6.value;
82
+ originarMaterialId = materialAndTexture.mergedMaterials[0].originalMaterialId;
83
+ if (convertedAttributesMap.has(originarMaterialId)) {
84
+ _context.next = 18;
114
85
  break;
115
86
  }
116
-
117
- return _context.abrupt("continue", 27);
118
-
119
- case 17:
120
- convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
121
-
87
+ return _context.abrupt("continue", 30);
88
+ case 18:
89
+ convertedAttributes = convertedAttributesMap.get(originarMaterialId);
122
90
  if (convertedAttributes) {
123
- _context.next = 20;
91
+ _context.next = 21;
124
92
  break;
125
93
  }
126
-
127
- return _context.abrupt("continue", 27);
128
-
129
- case 20:
130
- _materialAndTextureLi = materialAndTextureList[i], material = _materialAndTextureLi.material, texture = _materialAndTextureLi.texture;
131
- _context.t0 = result;
94
+ return _context.abrupt("continue", 30);
95
+ case 21:
96
+ material = materialAndTexture.material, texture = materialAndTexture.texture;
132
97
  _context.next = 24;
98
+ return addNodeToNodePage();
99
+ case 24:
100
+ nodeId = _context.sent;
101
+ _context.t0 = result;
102
+ _context.next = 28;
133
103
  return _makeNodeResources({
134
104
  convertedAttributes: convertedAttributes,
135
105
  material: material,
136
106
  texture: texture,
137
107
  tileContent: tileContent,
138
- nodeId: nodesCounter,
108
+ nodeId: nodeId,
139
109
  featuresHashArray: featuresHashArray,
110
+ propertyTable: propertyTable,
140
111
  attributeStorageInfo: attributeStorageInfo,
141
112
  draco: draco,
142
113
  workerSource: workerSource
143
114
  });
144
-
145
- case 24:
115
+ case 28:
146
116
  _context.t1 = _context.sent;
147
-
148
117
  _context.t0.push.call(_context.t0, _context.t1);
149
-
150
- nodesCounter++;
151
-
152
- case 27:
153
- i++;
118
+ case 30:
154
119
  _context.next = 13;
155
120
  break;
156
-
157
- case 30:
121
+ case 32:
122
+ _context.next = 37;
123
+ break;
124
+ case 34:
125
+ _context.prev = 34;
126
+ _context.t2 = _context["catch"](11);
127
+ _iterator6.e(_context.t2);
128
+ case 37:
129
+ _context.prev = 37;
130
+ _iterator6.f();
131
+ return _context.finish(37);
132
+ case 40:
158
133
  if (result.length) {
159
- _context.next = 32;
134
+ _context.next = 42;
160
135
  break;
161
136
  }
162
-
163
137
  return _context.abrupt("return", null);
164
-
165
- case 32:
138
+ case 42:
166
139
  return _context.abrupt("return", result);
167
-
168
- case 33:
140
+ case 43:
169
141
  case "end":
170
142
  return _context.stop();
171
143
  }
172
144
  }
173
- }, _callee);
145
+ }, _callee, null, [[11, 34, 37, 40]]);
174
146
  }));
175
147
  return _convertB3dmToI3sGeometry.apply(this, arguments);
176
148
  }
177
-
178
149
  function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
179
150
  var _iterator = _createForOfIteratorHelper(convertedAttributesMap.values()),
180
- _step;
181
-
151
+ _step;
182
152
  try {
183
153
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
184
154
  var attributes = _step.value;
185
155
  var boundingVolumes = (0, _coordinateConverter.createBoundingVolumesFromGeometry)(attributes.positions, geoidHeightModel);
186
156
  attributes.boundingVolumes = boundingVolumes;
187
157
  var cartographicOrigin = boundingVolumes.obb.center;
188
-
189
158
  for (var index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
190
159
  var vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
191
-
192
160
  _geospatial.Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
193
-
194
161
  scratchVector[2] = scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
195
162
  scratchVector = scratchVector.subtract(cartographicOrigin);
196
163
  attributes.positions.set(scratchVector, index);
@@ -203,55 +170,55 @@ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeigh
203
170
  }
204
171
  }
205
172
 
206
- function _makeNodeResources(_x9) {
173
+ function _makeNodeResources(_x11) {
207
174
  return _makeNodeResources2.apply(this, arguments);
208
175
  }
209
-
210
176
  function _makeNodeResources2() {
211
177
  _makeNodeResources2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref) {
212
- var _tileContent$gltf2;
213
-
214
- var convertedAttributes, material, texture, tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, workerSource, boundingVolumes, vertexCount, _generateAttributes, faceRange, featureIds, positions, normals, colors, texCoords, featureCount, header, typedFeatureIds, fileBuffer, compressedGeometry, attributes;
215
-
178
+ var _tileContent$gltf5;
179
+ var convertedAttributes, material, texture, tileContent, nodeId, featuresHashArray, propertyTable, attributeStorageInfo, draco, workerSource, boundingVolumes, vertexCount, _generateAttributes, faceRange, featureIds, positions, normals, colors, uvRegions, texCoords, featureCount, header, typedFeatureIds, fileBuffer, compressedGeometry, attributes;
216
180
  return _regenerator.default.wrap(function _callee2$(_context2) {
217
181
  while (1) {
218
182
  switch (_context2.prev = _context2.next) {
219
183
  case 0:
220
- convertedAttributes = _ref.convertedAttributes, material = _ref.material, texture = _ref.texture, tileContent = _ref.tileContent, nodeId = _ref.nodeId, featuresHashArray = _ref.featuresHashArray, attributeStorageInfo = _ref.attributeStorageInfo, draco = _ref.draco, workerSource = _ref.workerSource;
184
+ convertedAttributes = _ref.convertedAttributes, material = _ref.material, texture = _ref.texture, tileContent = _ref.tileContent, nodeId = _ref.nodeId, featuresHashArray = _ref.featuresHashArray, propertyTable = _ref.propertyTable, attributeStorageInfo = _ref.attributeStorageInfo, draco = _ref.draco, workerSource = _ref.workerSource;
221
185
  boundingVolumes = convertedAttributes.boundingVolumes;
222
186
  vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
223
- _generateAttributes = (0, _geometryAttributes.generateAttributes)(convertedAttributes), faceRange = _generateAttributes.faceRange, featureIds = _generateAttributes.featureIds, positions = _generateAttributes.positions, normals = _generateAttributes.normals, colors = _generateAttributes.colors, texCoords = _generateAttributes.texCoords, featureCount = _generateAttributes.featureCount;
224
-
187
+ _generateAttributes = (0, _geometryAttributes.generateAttributes)(convertedAttributes), faceRange = _generateAttributes.faceRange, featureIds = _generateAttributes.featureIds, positions = _generateAttributes.positions, normals = _generateAttributes.normals, colors = _generateAttributes.colors, uvRegions = _generateAttributes.uvRegions, texCoords = _generateAttributes.texCoords, featureCount = _generateAttributes.featureCount;
225
188
  if (tileContent.batchTableJson) {
226
189
  makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
227
190
  }
228
-
229
191
  header = new Uint32Array(2);
230
192
  typedFeatureIds = generateBigUint64Array(featureIds);
231
193
  header.set([vertexCount, featureCount], 0);
232
- fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
194
+ fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, uvRegions, typedFeatureIds.buffer, faceRange.buffer));
233
195
  compressedGeometry = draco ? generateCompressedGeometry(vertexCount, convertedAttributes, {
234
196
  positions: positions,
235
197
  normals: normals,
236
198
  texCoords: texture ? texCoords : new Float32Array(0),
237
199
  colors: colors,
200
+ uvRegions: uvRegions,
238
201
  featureIds: featureIds,
239
202
  faceRange: faceRange
240
203
  }, workerSource.draco) : null;
241
- attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
204
+ attributes = [];
205
+ if (attributeStorageInfo && propertyTable) {
206
+ attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
207
+ }
242
208
  return _context2.abrupt("return", {
209
+ nodeId: nodeId,
243
210
  geometry: fileBuffer,
244
211
  compressedGeometry: compressedGeometry,
245
212
  texture: texture,
246
- sharedResources: getSharedResources(((_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : _tileContent$gltf2.materials) || [], nodeId),
213
+ hasUvRegions: Boolean(uvRegions.length),
214
+ sharedResources: getSharedResources(((_tileContent$gltf5 = tileContent.gltf) === null || _tileContent$gltf5 === void 0 ? void 0 : _tileContent$gltf5.materials) || [], nodeId),
247
215
  meshMaterial: material,
248
216
  vertexCount: vertexCount,
249
217
  attributes: attributes,
250
218
  featureCount: featureCount,
251
219
  boundingVolumes: boundingVolumes
252
220
  });
253
-
254
- case 12:
221
+ case 13:
255
222
  case "end":
256
223
  return _context2.stop();
257
224
  }
@@ -260,107 +227,96 @@ function _makeNodeResources2() {
260
227
  }));
261
228
  return _makeNodeResources2.apply(this, arguments);
262
229
  }
263
-
264
- function convertAttributes(_x10, _x11) {
230
+ function convertAttributes(_x12, _x13, _x14) {
265
231
  return _convertAttributes.apply(this, arguments);
266
232
  }
267
-
268
233
  function _convertAttributes() {
269
- _convertAttributes = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(attributesData, useCartesianPositions) {
270
- var gltfMaterials, nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, _iterator6, _step6, material, _iterator7, _step7, attrKey, attributes;
271
-
234
+ _convertAttributes = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(attributesData, materialAndTextureList, useCartesianPositions) {
235
+ var nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, _iterator7, _step7, materialAndTexture, attributes, _iterator9, _step9, mergedMaterial, _iterator8, _step8, attrKey, _attributes;
272
236
  return _regenerator.default.wrap(function _callee3$(_context3) {
273
237
  while (1) {
274
238
  switch (_context3.prev = _context3.next) {
275
239
  case 0:
276
- gltfMaterials = attributesData.gltfMaterials, nodes = attributesData.nodes, cartographicOrigin = attributesData.cartographicOrigin, cartesianModelMatrix = attributesData.cartesianModelMatrix;
240
+ nodes = attributesData.nodes, images = attributesData.images, cartographicOrigin = attributesData.cartographicOrigin, cartesianModelMatrix = attributesData.cartesianModelMatrix;
277
241
  attributesMap = new Map();
278
- _iterator6 = _createForOfIteratorHelper(gltfMaterials || [{
279
- id: 'default'
280
- }]);
281
-
242
+ _iterator7 = _createForOfIteratorHelper(materialAndTextureList);
282
243
  try {
283
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
284
- material = _step6.value;
285
- attributesMap.set(material.id, {
244
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
245
+ materialAndTexture = _step7.value;
246
+ attributes = {
286
247
  positions: new Float32Array(0),
287
248
  normals: new Float32Array(0),
288
249
  texCoords: new Float32Array(0),
289
250
  colors: new Uint8Array(0),
251
+ uvRegions: new Uint16Array(0),
290
252
  featureIndicesGroups: [],
291
253
  featureIndices: [],
292
- boundingVolumes: null
293
- });
254
+ boundingVolumes: null,
255
+ mergedMaterials: materialAndTexture.mergedMaterials
256
+ };
257
+ _iterator9 = _createForOfIteratorHelper(materialAndTexture.mergedMaterials);
258
+ try {
259
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
260
+ mergedMaterial = _step9.value;
261
+ attributesMap.set(mergedMaterial.originalMaterialId, attributes);
262
+ }
263
+ } catch (err) {
264
+ _iterator9.e(err);
265
+ } finally {
266
+ _iterator9.f();
267
+ }
294
268
  }
295
269
  } catch (err) {
296
- _iterator6.e(err);
270
+ _iterator7.e(err);
297
271
  } finally {
298
- _iterator6.f();
272
+ _iterator7.f();
299
273
  }
300
-
301
- convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
302
- _iterator7 = _createForOfIteratorHelper(attributesMap.keys());
274
+ convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
275
+ _iterator8 = _createForOfIteratorHelper(attributesMap.keys());
303
276
  _context3.prev = 6;
304
-
305
- _iterator7.s();
306
-
277
+ _iterator8.s();
307
278
  case 8:
308
- if ((_step7 = _iterator7.n()).done) {
279
+ if ((_step8 = _iterator8.n()).done) {
309
280
  _context3.next = 19;
310
281
  break;
311
282
  }
312
-
313
- attrKey = _step7.value;
314
- attributes = attributesMap.get(attrKey);
315
-
316
- if (attributes) {
283
+ attrKey = _step8.value;
284
+ _attributes = attributesMap.get(attrKey);
285
+ if (_attributes) {
317
286
  _context3.next = 13;
318
287
  break;
319
288
  }
320
-
321
289
  return _context3.abrupt("continue", 17);
322
-
323
290
  case 13:
324
- if (!(attributes.positions.length === 0)) {
291
+ if (!(_attributes.positions.length === 0)) {
325
292
  _context3.next = 16;
326
293
  break;
327
294
  }
328
-
329
295
  attributesMap.delete(attrKey);
330
296
  return _context3.abrupt("continue", 17);
331
-
332
297
  case 16:
333
- if (attributes.featureIndicesGroups) {
334
- attributes.featureIndices = attributes.featureIndicesGroups.reduce(function (acc, value) {
298
+ if (_attributes.featureIndicesGroups) {
299
+ _attributes.featureIndices = _attributes.featureIndicesGroups.reduce(function (acc, value) {
335
300
  return acc.concat(value);
336
301
  });
337
- delete attributes.featureIndicesGroups;
302
+ delete _attributes.featureIndicesGroups;
338
303
  }
339
-
340
304
  case 17:
341
305
  _context3.next = 8;
342
306
  break;
343
-
344
307
  case 19:
345
308
  _context3.next = 24;
346
309
  break;
347
-
348
310
  case 21:
349
311
  _context3.prev = 21;
350
312
  _context3.t0 = _context3["catch"](6);
351
-
352
- _iterator7.e(_context3.t0);
353
-
313
+ _iterator8.e(_context3.t0);
354
314
  case 24:
355
315
  _context3.prev = 24;
356
-
357
- _iterator7.f();
358
-
316
+ _iterator8.f();
359
317
  return _context3.finish(24);
360
-
361
318
  case 27:
362
319
  return _context3.abrupt("return", attributesMap);
363
-
364
320
  case 28:
365
321
  case "end":
366
322
  return _context3.stop();
@@ -370,18 +326,15 @@ function _convertAttributes() {
370
326
  }));
371
327
  return _convertAttributes.apply(this, arguments);
372
328
  }
373
-
374
- function convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
375
- var matrix = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
376
-
329
+ function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
330
+ var matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
377
331
  if (nodes) {
378
332
  var _iterator2 = _createForOfIteratorHelper(nodes),
379
- _step2;
380
-
333
+ _step2;
381
334
  try {
382
335
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
383
336
  var node = _step2.value;
384
- convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
337
+ convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
385
338
  }
386
339
  } catch (err) {
387
340
  _iterator2.e(err);
@@ -394,68 +347,61 @@ function convertNodes(nodes, cartographicOrigin, cartesianModelMatrix, attribute
394
347
  function getCompositeTransformationMatrix(node, matrix) {
395
348
  var transformationMatrix = matrix;
396
349
  var nodeMatrix = node.matrix,
397
- rotation = node.rotation,
398
- scale = node.scale,
399
- translation = node.translation;
400
-
350
+ rotation = node.rotation,
351
+ scale = node.scale,
352
+ translation = node.translation;
401
353
  if (nodeMatrix) {
402
354
  transformationMatrix = matrix.multiplyRight(nodeMatrix);
403
355
  }
404
-
405
356
  if (translation) {
406
357
  transformationMatrix = transformationMatrix.translate(translation);
407
358
  }
408
-
409
359
  if (rotation) {
410
360
  transformationMatrix = transformationMatrix.rotateXYZ(rotation);
411
361
  }
412
-
413
362
  if (scale) {
414
363
  transformationMatrix = transformationMatrix.scale(scale);
415
364
  }
416
-
417
365
  return transformationMatrix;
418
366
  }
419
367
 
420
- function convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
421
- var matrix = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
368
+ function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
369
+ var matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
422
370
  var transformationMatrix = getCompositeTransformationMatrix(node, matrix);
423
371
  var mesh = node.mesh;
424
-
425
372
  if (mesh) {
426
- convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
373
+ convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
427
374
  }
428
-
429
- convertNodes(node.children || [], cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
375
+ convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
430
376
  }
431
377
 
432
- function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap) {
433
- var useCartesianPositions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
434
- var matrix = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
435
-
378
+ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap) {
379
+ var useCartesianPositions = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
380
+ var matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
436
381
  var _iterator3 = _createForOfIteratorHelper(mesh.primitives),
437
- _step3;
438
-
382
+ _step3;
439
383
  try {
440
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
441
- var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$indices5;
442
-
384
+ var _loop = function _loop() {
385
+ var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$indices6;
443
386
  var primitive = _step3.value;
444
387
  var outputAttributes = null;
445
-
388
+ var materialUvRegion = void 0;
446
389
  if (primitive.material) {
447
- outputAttributes = attributesMap.get(primitive.material.id);
390
+ var _outputAttributes, _outputAttributes$mer;
391
+ outputAttributes = attributesMap.get(primitive.material.uniqueId);
392
+ materialUvRegion = (_outputAttributes = outputAttributes) === null || _outputAttributes === void 0 ? void 0 : (_outputAttributes$mer = _outputAttributes.mergedMaterials.find(function (_ref2) {
393
+ var _primitive$material;
394
+ var originalMaterialId = _ref2.originalMaterialId;
395
+ return originalMaterialId === ((_primitive$material = primitive.material) === null || _primitive$material === void 0 ? void 0 : _primitive$material.uniqueId);
396
+ })) === null || _outputAttributes$mer === void 0 ? void 0 : _outputAttributes$mer.uvRegion;
448
397
  } else if (attributesMap.has('default')) {
449
398
  outputAttributes = attributesMap.get('default');
450
399
  }
451
-
452
400
  (0, _core2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
453
401
  var attributes = primitive.attributes;
454
-
455
402
  if (!outputAttributes) {
456
- continue;
403
+ return "continue";
457
404
  }
458
-
459
405
  outputAttributes.positions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
460
406
  vertices: attributes.POSITION.value,
461
407
  cartographicOrigin: cartographicOrigin,
@@ -476,8 +422,16 @@ function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesM
476
422
  }));
477
423
  outputAttributes.texCoords = (0, _loaderUtils.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));
478
424
  outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, (_primitive$indices4 = primitive.indices) === null || _primitive$indices4 === void 0 ? void 0 : _primitive$indices4.value));
425
+ if (materialUvRegion) {
426
+ var _primitive$indices5;
427
+ outputAttributes.uvRegions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.uvRegions, createUvRegion(materialUvRegion, (_primitive$indices5 = primitive.indices) === null || _primitive$indices5 === void 0 ? void 0 : _primitive$indices5.value));
428
+ }
479
429
  outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
480
- outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), (_primitive$indices5 = primitive.indices) === null || _primitive$indices5 === void 0 ? void 0 : _primitive$indices5.value));
430
+ outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), (_primitive$indices6 = primitive.indices) === null || _primitive$indices6 === void 0 ? void 0 : _primitive$indices6.value));
431
+ };
432
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
433
+ var _ret = _loop();
434
+ if (_ret === "continue") continue;
481
435
  }
482
436
  } catch (err) {
483
437
  _iterator3.e(err);
@@ -488,14 +442,12 @@ function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesM
488
442
 
489
443
  function transformVertexArray(args) {
490
444
  var vertices = args.vertices,
491
- indices = args.indices,
492
- attributeSpecificTransformation = args.attributeSpecificTransformation;
445
+ indices = args.indices,
446
+ attributeSpecificTransformation = args.attributeSpecificTransformation;
493
447
  var newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
494
-
495
448
  if (!vertices) {
496
449
  return newVertices;
497
450
  }
498
-
499
451
  for (var i = 0; i < indices.length; i++) {
500
452
  var coordIndex = indices[i] * VALUES_PER_VERTEX;
501
453
  var vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
@@ -505,142 +457,303 @@ function transformVertexArray(args) {
505
457
  newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
506
458
  newVertices[i * VALUES_PER_VERTEX + 2] = vertexVector.z;
507
459
  }
508
-
509
460
  return newVertices;
510
461
  }
511
462
 
512
463
  function transformVertexPositions(vertexVector, calleeArgs) {
513
464
  var cartesianModelMatrix = calleeArgs.cartesianModelMatrix,
514
- cartographicOrigin = calleeArgs.cartographicOrigin,
515
- nodeMatrix = calleeArgs.nodeMatrix,
516
- useCartesianPositions = calleeArgs.useCartesianPositions;
517
-
465
+ cartographicOrigin = calleeArgs.cartographicOrigin,
466
+ nodeMatrix = calleeArgs.nodeMatrix,
467
+ useCartesianPositions = calleeArgs.useCartesianPositions;
518
468
  if (nodeMatrix) {
519
469
  vertexVector = vertexVector.transform(nodeMatrix);
520
470
  }
521
-
522
471
  vertexVector = vertexVector.transform(cartesianModelMatrix);
523
-
524
472
  if (useCartesianPositions) {
525
473
  return vertexVector;
526
474
  }
527
-
528
475
  _geospatial.Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
529
-
530
476
  vertexVector = vertexVector.subtract(cartographicOrigin);
531
477
  return vertexVector;
532
478
  }
533
479
 
534
480
  function transformVertexNormals(vertexVector, calleeArgs) {
535
481
  var cartesianModelMatrix = calleeArgs.cartesianModelMatrix,
536
- nodeMatrix = calleeArgs.nodeMatrix;
537
-
482
+ nodeMatrix = calleeArgs.nodeMatrix;
538
483
  if (nodeMatrix) {
539
484
  vertexVector = vertexVector.transformAsVector(nodeMatrix);
540
485
  }
541
-
542
486
  vertexVector = vertexVector.transformAsVector(cartesianModelMatrix);
543
487
  return vertexVector;
544
488
  }
545
489
 
546
490
  function flattenTexCoords(texCoords, indices) {
547
491
  var newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
548
-
549
492
  if (!texCoords) {
550
493
  newTexCoords.fill(1);
551
494
  return newTexCoords;
552
495
  }
553
-
554
496
  for (var i = 0; i < indices.length; i++) {
555
497
  var coordIndex = indices[i] * VALUES_PER_TEX_COORD;
556
498
  var texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
557
499
  newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
558
500
  newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
559
501
  }
560
-
561
502
  return newTexCoords;
562
503
  }
563
504
 
564
505
  function flattenColors(colorsAttribute, indices) {
565
506
  var components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
566
507
  var newColors = new Uint8Array(indices.length * components);
567
-
568
508
  if (!colorsAttribute) {
569
509
  newColors.fill(255);
570
510
  return newColors;
571
511
  }
572
-
573
512
  var colors = colorsAttribute.value;
574
-
575
513
  for (var i = 0; i < indices.length; i++) {
576
514
  var colorIndex = indices[i] * components;
577
515
  var color = colors.subarray(colorIndex, colorIndex + components);
578
516
  var colorUint8 = new Uint8Array(components);
579
-
580
517
  for (var j = 0; j < color.length; j++) {
581
518
  colorUint8[j] = color[j] * 255;
582
519
  }
583
-
584
520
  newColors.set(colorUint8, i * components);
585
521
  }
586
-
587
522
  return newColors;
588
523
  }
589
524
 
525
+ function createUvRegion(materialUvRegion, indices) {
526
+ var result = new Uint16Array(indices.length * 4);
527
+ for (var i = 0; i < result.length; i += 4) {
528
+ result.set(materialUvRegion, i);
529
+ }
530
+ return result;
531
+ }
532
+
590
533
  function flattenBatchIds(batchedIds, indices) {
591
534
  if (!batchedIds.length || !indices.length) {
592
535
  return [];
593
536
  }
594
-
595
537
  var newBatchIds = [];
596
-
597
538
  for (var i = 0; i < indices.length; i++) {
598
539
  var coordIndex = indices[i];
599
540
  newBatchIds.push(batchedIds[coordIndex]);
600
541
  }
601
-
602
542
  return newBatchIds;
603
543
  }
604
544
 
605
- function getBatchIdsByAttributeName(attributes) {
606
- var batchIds = [];
607
-
545
+ function getBatchIds(attributes, primitive, images) {
546
+ var batchIds = (0, _batchIdsExtensions.handleBatchIdsExtensions)(attributes, primitive, images);
547
+ if (batchIds.length) {
548
+ return batchIds;
549
+ }
608
550
  for (var index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
609
551
  var possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
610
-
611
552
  if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
612
- batchIds = attributes[possibleBatchIdAttributeName].value;
613
- break;
553
+ return attributes[possibleBatchIdAttributeName].value;
614
554
  }
615
555
  }
616
-
617
- return batchIds;
556
+ return [];
618
557
  }
619
558
 
620
559
  function convertMaterials() {
621
- var sourceMaterials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
622
- var result = [];
623
-
624
- var _iterator4 = _createForOfIteratorHelper(sourceMaterials),
625
- _step4;
626
-
627
- try {
628
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
629
- var sourceMaterial = _step4.value;
630
- result.push(convertMaterial(sourceMaterial));
631
- }
632
- } catch (err) {
633
- _iterator4.e(err);
634
- } finally {
635
- _iterator4.f();
636
- }
637
-
638
- return result;
560
+ return _convertMaterials.apply(this, arguments);
561
+ }
562
+ function _convertMaterials() {
563
+ _convertMaterials = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4() {
564
+ var sourceMaterials,
565
+ shouldMergeMaterials,
566
+ materials,
567
+ _iterator10,
568
+ _step10,
569
+ sourceMaterial,
570
+ _args4 = arguments;
571
+ return _regenerator.default.wrap(function _callee4$(_context4) {
572
+ while (1) {
573
+ switch (_context4.prev = _context4.next) {
574
+ case 0:
575
+ sourceMaterials = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : [];
576
+ shouldMergeMaterials = _args4.length > 1 ? _args4[1] : undefined;
577
+ materials = [];
578
+ _iterator10 = _createForOfIteratorHelper(sourceMaterials);
579
+ try {
580
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
581
+ sourceMaterial = _step10.value;
582
+ materials.push(convertMaterial(sourceMaterial));
583
+ }
584
+ } catch (err) {
585
+ _iterator10.e(err);
586
+ } finally {
587
+ _iterator10.f();
588
+ }
589
+ if (!shouldMergeMaterials) {
590
+ _context4.next = 9;
591
+ break;
592
+ }
593
+ _context4.next = 8;
594
+ return mergeAllMaterials(materials);
595
+ case 8:
596
+ materials = _context4.sent;
597
+ case 9:
598
+ return _context4.abrupt("return", materials);
599
+ case 10:
600
+ case "end":
601
+ return _context4.stop();
602
+ }
603
+ }
604
+ }, _callee4);
605
+ }));
606
+ return _convertMaterials.apply(this, arguments);
607
+ }
608
+ function mergeAllMaterials(_x15) {
609
+ return _mergeAllMaterials.apply(this, arguments);
610
+ }
611
+ function _mergeAllMaterials() {
612
+ _mergeAllMaterials = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee5(materials) {
613
+ var result, newMaterial, mergedIndices, i, material, _newMaterial$mergedMa, _newMaterial$mergedMa2, newWidth, newHeight, currentX, _iterator11, _step11, aTextureMetadata, newX, _iterator12, _step12, index;
614
+ return _regenerator.default.wrap(function _callee5$(_context5) {
615
+ while (1) {
616
+ switch (_context5.prev = _context5.next) {
617
+ case 0:
618
+ result = [];
619
+ case 1:
620
+ if (!(materials.length > 0)) {
621
+ _context5.next = 21;
622
+ break;
623
+ }
624
+ newMaterial = materials.splice(0, 1)[0];
625
+ mergedIndices = [];
626
+ i = 0;
627
+ case 5:
628
+ if (!(i < materials.length)) {
629
+ _context5.next = 15;
630
+ break;
631
+ }
632
+ material = materials[i];
633
+ if (!(newMaterial.texture && material.texture || !newMaterial.texture && !material.texture)) {
634
+ _context5.next = 12;
635
+ break;
636
+ }
637
+ _context5.next = 10;
638
+ return mergeMaterials(newMaterial, material);
639
+ case 10:
640
+ newMaterial = _context5.sent;
641
+ mergedIndices.push(i);
642
+ case 12:
643
+ i++;
644
+ _context5.next = 5;
645
+ break;
646
+ case 15:
647
+ if (newMaterial.texture && mergedIndices.length) {
648
+ newWidth = (_newMaterial$mergedMa = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa === void 0 ? void 0 : _newMaterial$mergedMa.reduce(function (accum, _ref4) {
649
+ var textureSize = _ref4.textureSize;
650
+ return accum + ((textureSize === null || textureSize === void 0 ? void 0 : textureSize.width) || 0);
651
+ }, 0);
652
+ newHeight = (_newMaterial$mergedMa2 = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa2 === void 0 ? void 0 : _newMaterial$mergedMa2.reduce(function (accum, _ref5) {
653
+ var textureSize = _ref5.textureSize;
654
+ return Math.max(accum, (textureSize === null || textureSize === void 0 ? void 0 : textureSize.height) || 0);
655
+ }, 0);
656
+ currentX = -1;
657
+ _iterator11 = _createForOfIteratorHelper(newMaterial.mergedMaterials);
658
+ try {
659
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
660
+ aTextureMetadata = _step11.value;
661
+ if (aTextureMetadata.textureSize) {
662
+ newX = currentX + 1 + aTextureMetadata.textureSize.width / newWidth * Math.pow(2, Uint16Array.BYTES_PER_ELEMENT * 8) - 1;
663
+ aTextureMetadata.uvRegion = new Uint16Array([currentX + 1, 0, newX, aTextureMetadata.textureSize.height / newHeight * Math.pow(2, Uint16Array.BYTES_PER_ELEMENT * 8) - 1]);
664
+ currentX = newX;
665
+ }
666
+ }
667
+ } catch (err) {
668
+ _iterator11.e(err);
669
+ } finally {
670
+ _iterator11.f();
671
+ }
672
+ newMaterial.texture.image.width = newWidth;
673
+ newMaterial.texture.image.height = newHeight;
674
+ }
675
+ _iterator12 = _createForOfIteratorHelper(mergedIndices.reverse());
676
+ try {
677
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
678
+ index = _step12.value;
679
+ materials.splice(index, 1);
680
+ }
681
+ } catch (err) {
682
+ _iterator12.e(err);
683
+ } finally {
684
+ _iterator12.f();
685
+ }
686
+ result.push(newMaterial);
687
+ _context5.next = 1;
688
+ break;
689
+ case 21:
690
+ if (!result.length) {
691
+ result.push({
692
+ material: getDefaultMaterial(),
693
+ mergedMaterials: [{
694
+ originalMaterialId: 'default'
695
+ }]
696
+ });
697
+ }
698
+ return _context5.abrupt("return", result);
699
+ case 23:
700
+ case "end":
701
+ return _context5.stop();
702
+ }
703
+ }
704
+ }, _callee5);
705
+ }));
706
+ return _mergeAllMaterials.apply(this, arguments);
707
+ }
708
+ function mergeMaterials(_x16, _x17) {
709
+ return _mergeMaterials.apply(this, arguments);
710
+ }
711
+ function _mergeMaterials() {
712
+ _mergeMaterials = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee6(material1, material2) {
713
+ var _material1$texture, _material2$texture;
714
+ var buffer1, buffer2, _yield$import, joinImages, sharpData;
715
+ return _regenerator.default.wrap(function _callee6$(_context6) {
716
+ while (1) {
717
+ switch (_context6.prev = _context6.next) {
718
+ case 0:
719
+ if (!((_material1$texture = material1.texture) !== null && _material1$texture !== void 0 && _material1$texture.bufferView && (_material2$texture = material2.texture) !== null && _material2$texture !== void 0 && _material2$texture.bufferView && material1.mergedMaterials && material2.mergedMaterials)) {
720
+ _context6.next = 14;
721
+ break;
722
+ }
723
+ buffer1 = Buffer.from(material1.texture.bufferView.data);
724
+ buffer2 = Buffer.from(material2.texture.bufferView.data);
725
+ _context6.next = 5;
726
+ return Promise.resolve().then(function () {
727
+ return _interopRequireWildcard(require('join-images'));
728
+ });
729
+ case 5:
730
+ _yield$import = _context6.sent;
731
+ joinImages = _yield$import.joinImages;
732
+ _context6.next = 9;
733
+ return joinImages([buffer1, buffer2], {
734
+ direction: 'horizontal'
735
+ });
736
+ case 9:
737
+ sharpData = _context6.sent;
738
+ _context6.next = 12;
739
+ return sharpData.toFormat(material1.texture.mimeType === 'image/png' ? 'png' : 'jpeg').toBuffer();
740
+ case 12:
741
+ material1.texture.bufferView.data = _context6.sent;
742
+ material1.material.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId = 1;
743
+ case 14:
744
+ material1.mergedMaterials = material1.mergedMaterials.concat(material2.mergedMaterials);
745
+ return _context6.abrupt("return", material1);
746
+ case 16:
747
+ case "end":
748
+ return _context6.stop();
749
+ }
750
+ }
751
+ }, _callee6);
752
+ }));
753
+ return _mergeMaterials.apply(this, arguments);
639
754
  }
640
-
641
755
  function convertMaterial(sourceMaterial) {
642
756
  var _sourceMaterial$emiss, _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
643
-
644
757
  var material = {
645
758
  doubleSided: sourceMaterial.doubleSided,
646
759
  emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(function (c) {
@@ -653,7 +766,6 @@ function convertMaterial(sourceMaterial) {
653
766
  }
654
767
  };
655
768
  var texture;
656
-
657
769
  if (sourceMaterial !== null && sourceMaterial !== void 0 && (_sourceMaterial$pbrMe3 = sourceMaterial.pbrMetallicRoughness) !== null && _sourceMaterial$pbrMe3 !== void 0 && _sourceMaterial$pbrMe3.baseColorTexture) {
658
770
  texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
659
771
  material.pbrMetallicRoughness.baseColorTexture = {
@@ -665,19 +777,27 @@ function convertMaterial(sourceMaterial) {
665
777
  textureSetDefinitionId: 0
666
778
  };
667
779
  }
668
-
780
+ var uniqueId = (0, _uuid.v4)();
781
+ sourceMaterial.uniqueId = uniqueId;
782
+ var mergedMaterials = [{
783
+ originalMaterialId: uniqueId
784
+ }];
669
785
  if (!texture) {
670
786
  var _sourceMaterial$pbrMe4;
671
-
672
787
  var baseColorFactor = sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe4 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe4 === void 0 ? void 0 : _sourceMaterial$pbrMe4.baseColorFactor;
673
788
  material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(function (c) {
674
789
  return Math.round(c * 255);
675
790
  }) || undefined;
791
+ } else {
792
+ mergedMaterials[0].textureSize = {
793
+ width: texture.image.width,
794
+ height: texture.image.height
795
+ };
676
796
  }
677
-
678
797
  return {
679
798
  material: material,
680
- texture: texture
799
+ texture: texture,
800
+ mergedMaterials: mergedMaterials
681
801
  };
682
802
  }
683
803
 
@@ -685,13 +805,10 @@ function convertAlphaMode(gltfAlphaMode) {
685
805
  switch (gltfAlphaMode) {
686
806
  case 'OPAQUE':
687
807
  return 'opaque';
688
-
689
808
  case 'MASK':
690
809
  return 'mask';
691
-
692
810
  case 'BLEND':
693
811
  return 'blend';
694
-
695
812
  default:
696
813
  return 'opaque';
697
814
  }
@@ -709,61 +826,47 @@ function getDefaultMaterial() {
709
826
 
710
827
  function getSharedResources(gltfMaterials, nodeId) {
711
828
  var i3sResources = {};
712
-
713
829
  if (!gltfMaterials || !gltfMaterials.length) {
714
830
  return i3sResources;
715
831
  }
716
-
717
832
  i3sResources.materialDefinitionInfos = [];
718
-
719
- var _iterator5 = _createForOfIteratorHelper(gltfMaterials),
720
- _step5;
721
-
833
+ var _iterator4 = _createForOfIteratorHelper(gltfMaterials),
834
+ _step4;
722
835
  try {
723
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
724
- var gltfMaterial = _step5.value;
725
-
836
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
837
+ var gltfMaterial = _step4.value;
726
838
  var _convertGLTFMaterialT = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId),
727
- materialDefinitionInfo = _convertGLTFMaterialT.materialDefinitionInfo,
728
- textureDefinitionInfo = _convertGLTFMaterialT.textureDefinitionInfo;
729
-
839
+ materialDefinitionInfo = _convertGLTFMaterialT.materialDefinitionInfo,
840
+ textureDefinitionInfo = _convertGLTFMaterialT.textureDefinitionInfo;
730
841
  i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
731
-
732
842
  if (textureDefinitionInfo) {
733
843
  i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
734
844
  i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
735
845
  }
736
846
  }
737
847
  } catch (err) {
738
- _iterator5.e(err);
848
+ _iterator4.e(err);
739
849
  } finally {
740
- _iterator5.f();
850
+ _iterator4.f();
741
851
  }
742
-
743
852
  return i3sResources;
744
853
  }
745
854
 
746
855
  function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
747
856
  var _gltfMaterial$pbrMeta;
748
-
749
857
  var texture = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : (_gltfMaterial$pbrMeta = gltfMaterial.pbrMetallicRoughness) === null || _gltfMaterial$pbrMeta === void 0 ? void 0 : _gltfMaterial$pbrMeta.baseColorTexture) || gltfMaterial.emissiveTexture;
750
858
  var textureDefinitionInfo = null;
751
-
752
859
  if (texture) {
753
860
  textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
754
861
  }
755
-
756
- var _ref2 = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : gltfMaterial.pbrMetallicRoughness) || {},
757
- baseColorFactor = _ref2.baseColorFactor,
758
- metallicFactor = _ref2.metallicFactor;
759
-
862
+ var _ref3 = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : gltfMaterial.pbrMetallicRoughness) || {},
863
+ baseColorFactor = _ref3.baseColorFactor,
864
+ metallicFactor = _ref3.metallicFactor;
760
865
  var colorFactor = baseColorFactor;
761
-
762
866
  if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
763
867
  colorFactor = gltfMaterial.emissiveFactor;
764
868
  colorFactor[3] = colorFactor[3] || 1;
765
869
  }
766
-
767
870
  return {
768
871
  materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
769
872
  textureDefinitionInfo: textureDefinitionInfo
@@ -792,7 +895,6 @@ function extractSharedResourcesMaterialInfo(baseColorFactor) {
792
895
 
793
896
  function extractSharedResourcesTextureInfo(texture, nodeId) {
794
897
  var _texture$source, _texture$source2, _texture$source3;
795
-
796
898
  return {
797
899
  encoding: texture !== null && texture !== void 0 && (_texture$source = texture.source) !== null && _texture$source !== void 0 && _texture$source.mimeType ? [texture.source.mimeType] : undefined,
798
900
  images: [{
@@ -805,11 +907,9 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
805
907
 
806
908
  function generateImageId(texture, nodeId) {
807
909
  var _texture$source4;
808
-
809
910
  var _texture$source$image = (_texture$source4 = texture.source) === null || _texture$source4 === void 0 ? void 0 : _texture$source4.image,
810
- width = _texture$source$image.width,
811
- height = _texture$source$image.height;
812
-
911
+ width = _texture$source$image.width,
912
+ height = _texture$source$image.height;
813
913
  var levelCountOfTexture = 1;
814
914
  var indexOfLevel = 0;
815
915
  var indexOfTextureInStore = nodeId + 1;
@@ -832,34 +932,28 @@ function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, bat
832
932
 
833
933
  function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
834
934
  var featureMap = {};
835
-
836
935
  for (var index = 0; index < featureIds.length; index++) {
837
936
  var oldFeatureId = featureIds[index];
838
937
  var uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
839
938
  featureMap[oldFeatureId.toString()] = uniqueFeatureId;
840
939
  }
841
-
842
940
  return featureMap;
843
941
  }
844
942
 
845
943
  function generateStringFromBatchTableByIndex(batchTable, index) {
846
944
  var str = '';
847
-
848
945
  for (var _key in batchTable) {
849
946
  str += batchTable[_key][index];
850
947
  }
851
-
852
948
  return str;
853
949
  }
854
950
 
855
951
  function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
856
952
  var batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
857
953
  var hash = (0, _md.default)(batchTableStr);
858
-
859
954
  if (featuresHashArray.includes(hash)) {
860
955
  return featuresHashArray.indexOf(hash);
861
956
  }
862
-
863
957
  return featuresHashArray.push(hash) - 1;
864
958
  }
865
959
 
@@ -869,45 +963,41 @@ function replaceIndicesByUnique(indicesArray, featureMap) {
869
963
  }
870
964
  }
871
965
 
872
- function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {
966
+ function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
873
967
  var attributeBuffers = [];
874
-
875
- if (batchTable) {
876
- var batchTableWithFeatureIds = _objectSpread({
877
- OBJECTID: featureIds
878
- }, batchTable);
879
-
880
- for (var _key2 in batchTableWithFeatureIds) {
881
- var type = getAttributeType(_key2, attributeStorageInfo);
882
- var attributeBuffer = null;
883
-
884
- switch (type) {
885
- case OBJECT_ID_TYPE:
886
- case SHORT_INT_TYPE:
887
- attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[_key2]);
888
- break;
889
-
890
- case DOUBLE_TYPE:
891
- attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[_key2]);
892
- break;
893
-
894
- case STRING_TYPE:
895
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[_key2]);
896
- break;
897
-
898
- default:
899
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[_key2]);
900
- }
901
-
902
- if (attributeBuffer) {
903
- attributeBuffers.push(attributeBuffer);
904
- }
905
- }
968
+ var needFlattenPropertyTable = (0, _featureAttributes.checkPropertiesLength)(featureIds, propertyTable);
969
+ var properties = needFlattenPropertyTable ? (0, _featureAttributes.flattenPropertyTableByFeatureIds)(featureIds, propertyTable) : propertyTable;
970
+ var propertyTableWithObjectIds = _objectSpread({
971
+ OBJECTID: featureIds
972
+ }, properties);
973
+ for (var propertyName in propertyTableWithObjectIds) {
974
+ var type = getAttributeType(propertyName, attributeStorageInfo);
975
+ var value = propertyTableWithObjectIds[propertyName];
976
+ var attributeBuffer = generateAttributeBuffer(type, value);
977
+ attributeBuffers.push(attributeBuffer);
906
978
  }
907
-
908
979
  return attributeBuffers;
909
980
  }
910
981
 
982
+ function generateAttributeBuffer(type, value) {
983
+ var attributeBuffer;
984
+ switch (type) {
985
+ case OBJECT_ID_TYPE:
986
+ case SHORT_INT_TYPE:
987
+ attributeBuffer = generateShortIntegerAttributeBuffer(value);
988
+ break;
989
+ case DOUBLE_TYPE:
990
+ attributeBuffer = generateDoubleAttributeBuffer(value);
991
+ break;
992
+ case STRING_TYPE:
993
+ attributeBuffer = generateStringAttributeBuffer(value);
994
+ break;
995
+ default:
996
+ attributeBuffer = generateStringAttributeBuffer(value);
997
+ }
998
+ return attributeBuffer;
999
+ }
1000
+
911
1001
  function getAttributeType(key, attributeStorageInfo) {
912
1002
  var attribute = attributeStorageInfo.find(function (attr) {
913
1003
  return attr.name === key;
@@ -933,7 +1023,6 @@ function generateStringAttributeBuffer(batchAttributes) {
933
1023
  var totalNumberOfBytes = 0;
934
1024
  var stringSizesArray = new Uint32Array(batchAttributes.length);
935
1025
  var stringBufferArray = [];
936
-
937
1026
  for (var index = 0; index < batchAttributes.length; index++) {
938
1027
  var currentString = "".concat(String(batchAttributes[index]), "\0");
939
1028
  var currentStringBuffer = Buffer.from(currentString);
@@ -942,39 +1031,33 @@ function generateStringAttributeBuffer(batchAttributes) {
942
1031
  stringSizesArray[index] = currentStringSize;
943
1032
  stringBufferArray.push(currentStringBuffer);
944
1033
  }
945
-
946
1034
  var totalBytes = new Uint32Array([totalNumberOfBytes]);
947
1035
  return _loaderUtils.concatenateArrayBuffers.apply(void 0, [stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer].concat(stringBufferArray));
948
1036
  }
949
1037
 
950
1038
  function generateBigUint64Array(featureIds) {
951
1039
  var typedFeatureIds = new BigUint64Array(featureIds.length);
952
-
953
1040
  for (var index = 0; index < featureIds.length; index++) {
954
1041
  typedFeatureIds[index] = BigInt(featureIds[index]);
955
1042
  }
956
-
957
1043
  return typedFeatureIds;
958
1044
  }
959
1045
 
960
- function generateCompressedGeometry(_x12, _x13, _x14, _x15) {
1046
+ function generateCompressedGeometry(_x18, _x19, _x20, _x21) {
961
1047
  return _generateCompressedGeometry.apply(this, arguments);
962
1048
  }
963
-
964
1049
  function _generateCompressedGeometry() {
965
- _generateCompressedGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
966
- var positions, normals, texCoords, colors, featureIds, faceRange, indices, index, featureIndices, featureIndex, compressedAttributes, attributesMetadata;
967
- return _regenerator.default.wrap(function _callee4$(_context4) {
1050
+ _generateCompressedGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee7(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
1051
+ var positions, normals, texCoords, colors, uvRegions, featureIds, faceRange, indices, index, featureIndices, featureIndex, compressedAttributes, attributesMetadata;
1052
+ return _regenerator.default.wrap(function _callee7$(_context7) {
968
1053
  while (1) {
969
- switch (_context4.prev = _context4.next) {
1054
+ switch (_context7.prev = _context7.next) {
970
1055
  case 0:
971
- positions = attributes.positions, normals = attributes.normals, texCoords = attributes.texCoords, colors = attributes.colors, featureIds = attributes.featureIds, faceRange = attributes.faceRange;
1056
+ positions = attributes.positions, normals = attributes.normals, texCoords = attributes.texCoords, colors = attributes.colors, uvRegions = attributes.uvRegions, featureIds = attributes.featureIds, faceRange = attributes.faceRange;
972
1057
  indices = new Uint32Array(vertexCount);
973
-
974
1058
  for (index = 0; index < indices.length; index++) {
975
1059
  indices.set([index], index);
976
1060
  }
977
-
978
1061
  featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
979
1062
  featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
980
1063
  compressedAttributes = {
@@ -983,18 +1066,22 @@ function _generateCompressedGeometry() {
983
1066
  colors: colors,
984
1067
  'feature-index': featureIndex
985
1068
  };
986
-
987
1069
  if (texCoords.length) {
988
1070
  compressedAttributes.texCoords = texCoords;
989
1071
  }
990
-
991
1072
  attributesMetadata = {
992
1073
  'feature-index': {
993
1074
  'i3s-attribute-type': 'feature-index',
994
1075
  'i3s-feature-ids': new Int32Array(featureIds)
995
1076
  }
996
1077
  };
997
- return _context4.abrupt("return", (0, _core2.encode)({
1078
+ if (uvRegions.length) {
1079
+ compressedAttributes['uv-region'] = uvRegions;
1080
+ attributesMetadata['uv-region'] = {
1081
+ 'i3s-attribute-type': 'uv-region'
1082
+ };
1083
+ }
1084
+ return _context7.abrupt("return", (0, _core2.encode)({
998
1085
  attributes: compressedAttributes,
999
1086
  indices: indices
1000
1087
  }, _draco.DracoWriterWorker, _objectSpread(_objectSpread({}, _draco.DracoWriterWorker.options), {}, {
@@ -1006,29 +1093,102 @@ function _generateCompressedGeometry() {
1006
1093
  attributesMetadata: attributesMetadata
1007
1094
  }
1008
1095
  })));
1009
-
1010
- case 9:
1096
+ case 10:
1011
1097
  case "end":
1012
- return _context4.stop();
1098
+ return _context7.stop();
1013
1099
  }
1014
1100
  }
1015
- }, _callee4);
1101
+ }, _callee7);
1016
1102
  }));
1017
1103
  return _generateCompressedGeometry.apply(this, arguments);
1018
1104
  }
1019
-
1020
1105
  function generateFeatureIndexAttribute(featureIndex, faceRange) {
1021
1106
  var orderedFeatureIndices = new Uint32Array(featureIndex.length);
1022
1107
  var fillIndex = 0;
1023
1108
  var startIndex = 0;
1024
-
1025
1109
  for (var index = 1; index < faceRange.length; index += 2) {
1026
1110
  var endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
1027
1111
  orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
1028
1112
  fillIndex++;
1029
1113
  startIndex = endIndex + 1;
1030
1114
  }
1031
-
1032
1115
  return orderedFeatureIndices;
1033
1116
  }
1117
+
1118
+ function getPropertyTable(tileContent) {
1119
+ var batchTableJson = tileContent === null || tileContent === void 0 ? void 0 : tileContent.batchTableJson;
1120
+ if (batchTableJson) {
1121
+ return batchTableJson;
1122
+ }
1123
+ var _getPropertyTableExte = getPropertyTableExtension(tileContent),
1124
+ extensionName = _getPropertyTableExte.extensionName,
1125
+ extension = _getPropertyTableExte.extension;
1126
+ switch (extensionName) {
1127
+ case EXT_MESH_FEATURES:
1128
+ {
1129
+ console.warn('The I3S converter does not yet support the EXT_mesh_features extension');
1130
+ return null;
1131
+ }
1132
+ case EXT_FEATURE_METADATA:
1133
+ {
1134
+ return getPropertyTableFromExtFeatureMetadata(extension);
1135
+ }
1136
+ default:
1137
+ return null;
1138
+ }
1139
+ }
1140
+
1141
+ function getPropertyTableExtension(tileContent) {
1142
+ var _tileContent$gltf, _tileContent$gltf2, _tileContent$gltf2$ex, _tileContent$gltf3;
1143
+ var extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
1144
+ var extensionsUsed = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.extensionsUsed;
1145
+ if (!extensionsUsed) {
1146
+ return {
1147
+ extensionName: null,
1148
+ extension: null
1149
+ };
1150
+ }
1151
+ var extensionName = '';
1152
+ var _iterator5 = _createForOfIteratorHelper((tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf3 = tileContent.gltf) === null || _tileContent$gltf3 === void 0 ? void 0 : _tileContent$gltf3.extensionsUsed) || []),
1153
+ _step5;
1154
+ try {
1155
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1156
+ var extensionItem = _step5.value;
1157
+ if (extensionsWithPropertyTables.includes(extensionItem)) {
1158
+ extensionName = extensionItem;
1159
+ break;
1160
+ }
1161
+ }
1162
+ } catch (err) {
1163
+ _iterator5.e(err);
1164
+ } finally {
1165
+ _iterator5.f();
1166
+ }
1167
+ var extension = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : (_tileContent$gltf2$ex = _tileContent$gltf2.extensions) === null || _tileContent$gltf2$ex === void 0 ? void 0 : _tileContent$gltf2$ex[extensionName];
1168
+ return {
1169
+ extensionName: extensionName,
1170
+ extension: extension
1171
+ };
1172
+ }
1173
+
1174
+ function getPropertyTableFromExtFeatureMetadata(extension) {
1175
+ if (extension !== null && extension !== void 0 && extension.featureTextures) {
1176
+ console.warn('The I3S converter does not yet support the EXT_feature_metadata feature textures');
1177
+ return null;
1178
+ }
1179
+ if (extension !== null && extension !== void 0 && extension.featureTables) {
1180
+ var _Object$keys;
1181
+ var firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
1182
+ if (firstFeatureTableName) {
1183
+ var featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTables[firstFeatureTableName];
1184
+ var propertyTable = {};
1185
+ for (var propertyName in featureTable.properties) {
1186
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
1187
+ }
1188
+ return propertyTable;
1189
+ }
1190
+ }
1191
+ console.warn("The I3S converter couldn't handle EXT_feature_metadata extension");
1192
+ return null;
1193
+ }
1034
1194
  //# sourceMappingURL=geometry-converter.js.map