@loaders.gl/tile-converter 3.1.0-beta.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/bundle.js +1455 -1296
  2. package/dist/converter.min.js +292 -0
  3. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +429 -189
  4. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  5. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +306 -209
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  7. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +8 -4
  8. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  9. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +13 -13
  10. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  11. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +51 -32
  12. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  13. package/dist/es5/bundle.js +1 -1
  14. package/dist/es5/bundle.js.map +1 -1
  15. package/dist/es5/deps-installer/deps-installer.js +61 -17
  16. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +55 -16
  18. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  19. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +33 -9
  20. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  21. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +103 -93
  22. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  24. package/dist/es5/i3s-converter/helpers/geometry-converter.js +546 -351
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/node-debug.js +27 -31
  27. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/node-pages.js +209 -101
  29. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  30. package/dist/es5/i3s-converter/i3s-converter.js +1645 -700
  31. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/json-templates/layers.js +213 -177
  33. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  34. package/dist/es5/i3s-converter/json-templates/metadata.js +24 -20
  35. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  36. package/dist/es5/i3s-converter/json-templates/node.js +92 -74
  37. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  38. package/dist/es5/i3s-converter/json-templates/scene-server.js +34 -28
  39. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  40. package/dist/es5/i3s-converter/json-templates/shared-resources.js +162 -107
  41. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  42. package/dist/es5/i3s-converter/json-templates/store.js +4 -2
  43. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  44. package/dist/es5/i3s-converter/types.js +2 -0
  45. package/dist/es5/i3s-converter/types.js.map +1 -0
  46. package/dist/es5/i3s-server/app.js +6 -6
  47. package/dist/es5/i3s-server/app.js.map +1 -1
  48. package/dist/es5/i3s-server/controllers/index-controller.js +60 -20
  49. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  50. package/dist/es5/i3s-server/routes/index.js +41 -14
  51. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  52. package/dist/es5/index.js +4 -4
  53. package/dist/es5/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  54. package/dist/es5/lib/utils/compress-util.js +345 -123
  55. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  56. package/dist/es5/lib/utils/file-utils.js +98 -20
  57. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  58. package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
  59. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  60. package/dist/es5/lib/utils/statistic-utills.js +152 -41
  61. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  62. package/dist/es5/pgm-loader.js +31 -4
  63. package/dist/es5/pgm-loader.js.map +1 -1
  64. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +7 -6
  65. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  66. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +7 -0
  67. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  68. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  69. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -1
  70. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  71. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +12 -9
  72. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  73. package/dist/esm/deps-installer/deps-installer.js +2 -6
  74. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  75. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +35 -3
  76. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  77. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +2 -2
  78. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  79. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  80. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  81. package/dist/esm/i3s-converter/helpers/geometry-converter.js +52 -34
  82. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  83. package/dist/esm/i3s-converter/helpers/node-debug.js +2 -4
  84. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  85. package/dist/esm/i3s-converter/helpers/node-pages.js +15 -4
  86. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  87. package/dist/esm/i3s-converter/i3s-converter.js +147 -62
  88. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/json-templates/layers.js +37 -27
  90. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
  91. package/dist/esm/i3s-converter/json-templates/metadata.js +2 -2
  92. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  93. package/dist/esm/i3s-converter/json-templates/node.js +16 -12
  94. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
  95. package/dist/esm/i3s-converter/json-templates/scene-server.js +2 -2
  96. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  97. package/dist/esm/i3s-converter/json-templates/shared-resources.js +19 -14
  98. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  99. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  100. package/dist/esm/i3s-converter/types.js +2 -0
  101. package/dist/esm/i3s-converter/types.js.map +1 -0
  102. package/dist/esm/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  103. package/dist/esm/pgm-loader.js +3 -3
  104. package/dist/esm/pgm-loader.js.map +1 -1
  105. package/package.json +16 -14
  106. package/src/3d-tiles-converter/3d-tiles-converter.ts +21 -20
  107. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +19 -2
  108. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  109. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  110. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  111. package/src/deps-installer/deps-installer.js +2 -2
  112. package/src/i3s-converter/helpers/coordinate-converter.ts +62 -9
  113. package/src/i3s-converter/helpers/{create-scene-server-path.js → create-scene-server-path.ts} +2 -2
  114. package/src/i3s-converter/helpers/{geometry-attributes.js → geometry-attributes.ts} +4 -4
  115. package/src/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  116. package/src/i3s-converter/helpers/geometry-converter.js +68 -26
  117. package/src/i3s-converter/helpers/{node-debug.js → node-debug.ts} +3 -2
  118. package/src/i3s-converter/helpers/{node-pages.js → node-pages.ts} +41 -26
  119. package/src/i3s-converter/i3s-converter.ts +204 -133
  120. package/src/i3s-converter/json-templates/{layers.js → layers.ts} +29 -27
  121. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  122. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  123. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  124. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +14 -14
  125. package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  126. package/src/i3s-converter/types.ts +14 -0
  127. package/src/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  128. package/src/pgm-loader.ts +2 -2
  129. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  130. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  131. package/dist/es5/i3s-converter/helpers/node-pages.d.ts +0 -144
  132. package/dist/es5/lib/geoid-height-model.d.ts +0 -41
  133. package/dist/es5/lib/geoid-height-model.js +0 -149
  134. package/dist/es5/lib/geoid-height-model.js.map +0 -1
  135. package/dist/es5/lib/pgm-parser.d.ts +0 -14
  136. package/dist/es5/lib/pgm-parser.js +0 -192
  137. package/dist/es5/lib/pgm-parser.js.map +0 -1
  138. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  139. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  140. package/dist/esm/i3s-converter/helpers/node-pages.d.ts +0 -144
  141. package/dist/esm/lib/geoid-height-model.d.ts +0 -41
  142. package/dist/esm/lib/geoid-height-model.js +0 -140
  143. package/dist/esm/lib/geoid-height-model.js.map +0 -1
  144. package/dist/esm/lib/pgm-parser.d.ts +0 -14
  145. package/dist/esm/lib/pgm-parser.js +0 -183
  146. package/dist/esm/lib/pgm-parser.js.map +0 -1
  147. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  148. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  149. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  150. package/src/lib/geoid-height-model.d.ts +0 -41
  151. package/src/lib/geoid-height-model.js +0 -239
  152. package/src/lib/pgm-parser.d.ts +0 -14
  153. package/src/lib/pgm-parser.js +0 -179
@@ -7,6 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = convertB3dmToI3sGeometry;
9
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
10
16
  var _core = require("@math.gl/core");
11
17
 
12
18
  var _geospatial = require("@math.gl/geospatial");
@@ -21,245 +27,388 @@ var _md = _interopRequireDefault(require("md5"));
21
27
 
22
28
  var _geometryAttributes = require("./geometry-attributes");
23
29
 
24
- const VALUES_PER_VERTEX = 3;
25
- const VALUES_PER_TEX_COORD = 2;
26
- const VALUES_PER_COLOR_ELEMENT = 4;
27
- const STRING_TYPE = 'string';
28
- const SHORT_INT_TYPE = 'Int32';
29
- const DOUBLE_TYPE = 'Float64';
30
- const OBJECT_ID_TYPE = 'Oid32';
31
- const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
30
+ var _coordinateConverter = require("./coordinate-converter");
32
31
 
33
- async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco) {
34
- const materialAndTextureList = convertMaterials(tileContent);
35
- const convertedAttributesMap = convertAttributes(tileContent);
32
+ 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
33
 
37
- if (convertedAttributesMap.has('default')) {
38
- materialAndTextureList.push({
39
- material: getDefaultMaterial()
40
- });
41
- }
34
+ 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; }
42
35
 
43
- const result = [];
44
- let nodesCounter = nodeId;
45
- let {
46
- materials = []
47
- } = tileContent.gltf;
36
+ 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; } } }; }
37
+
38
+ 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); }
48
39
 
49
- if (!materials.length === 0) {
50
- materials.push({
51
- id: 'default'
52
- });
53
- }
40
+ 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; }
54
41
 
55
- for (let i = 0; i < materials.length; i++) {
56
- const sourceMaterial = materials[i];
42
+ var VALUES_PER_VERTEX = 3;
43
+ var VALUES_PER_TEX_COORD = 2;
44
+ var VALUES_PER_COLOR_ELEMENT = 4;
45
+ var STRING_TYPE = 'string';
46
+ var SHORT_INT_TYPE = 'Int32';
47
+ var DOUBLE_TYPE = 'Float64';
48
+ var OBJECT_ID_TYPE = 'Oid32';
49
+ var BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
50
+ var scratchVector = new _core.Vector3();
57
51
 
58
- if (!convertedAttributesMap.has(sourceMaterial.id)) {
59
- continue;
60
- }
52
+ function convertB3dmToI3sGeometry(_x, _x2, _x3, _x4, _x5, _x6, _x7) {
53
+ return _convertB3dmToI3sGeometry.apply(this, arguments);
54
+ }
61
55
 
62
- const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
63
- const {
64
- material,
65
- texture
66
- } = materialAndTextureList[i];
67
- result.push(await _makeNodeResources({
68
- convertedAttributes,
69
- material,
70
- texture,
71
- tileContent,
72
- nodeId: nodesCounter,
73
- featuresHashArray,
74
- attributeStorageInfo,
75
- draco
76
- }));
77
- nodesCounter++;
78
- }
56
+ function _convertB3dmToI3sGeometry() {
57
+ _convertB3dmToI3sGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel) {
58
+ var useCartesianPositions, materialAndTextureList, convertedAttributesMap, result, nodesCounter, _tileContent$gltf$mat, materials, i, sourceMaterial, convertedAttributes, _materialAndTextureLi, material, texture;
79
59
 
80
- if (!result.length) {
81
- return null;
82
- }
60
+ return _regenerator.default.wrap(function _callee$(_context) {
61
+ while (1) {
62
+ switch (_context.prev = _context.next) {
63
+ case 0:
64
+ useCartesianPositions = generateBoundingVolumes;
65
+ materialAndTextureList = convertMaterials(tileContent);
66
+ convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);
83
67
 
84
- return result;
85
- }
68
+ if (generateBoundingVolumes) {
69
+ _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
70
+ }
86
71
 
87
- async function _makeNodeResources({
88
- convertedAttributes,
89
- material,
90
- texture,
91
- tileContent,
92
- nodeId,
93
- featuresHashArray,
94
- attributeStorageInfo,
95
- draco
96
- }) {
97
- const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
98
- const triangleCount = vertexCount / 3;
99
- const {
100
- faceRange,
101
- featureIds,
102
- positions,
103
- normals,
104
- colors,
105
- texCoords,
106
- featureCount
107
- } = (0, _geometryAttributes.generateAttributes)({
108
- triangleCount,
109
- ...convertedAttributes
110
- });
72
+ if (convertedAttributesMap.has('default')) {
73
+ materialAndTextureList.push({
74
+ material: getDefaultMaterial()
75
+ });
76
+ }
111
77
 
112
- if (tileContent.batchTableJson) {
113
- makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
114
- }
115
-
116
- const header = new Uint32Array(2);
117
- const typedFeatureIds = generateBigUint64Array(featureIds);
118
- header.set([vertexCount, featureCount], 0);
119
- const fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
120
- const compressedGeometry = draco ? await generateCompressedGeometry(vertexCount, convertedAttributes, {
121
- positions,
122
- normals,
123
- texCoords: texture ? texCoords : new Float32Array(0),
124
- colors,
125
- featureIds,
126
- faceRange
127
- }) : null;
128
- const attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
129
- return {
130
- geometry: fileBuffer,
131
- compressedGeometry,
132
- texture,
133
- sharedResources: getSharedResources(tileContent, nodeId),
134
- meshMaterial: material,
135
- vertexCount,
136
- attributes,
137
- featureCount
138
- };
139
- }
78
+ result = [];
79
+ nodesCounter = nodeId;
80
+ _tileContent$gltf$mat = tileContent.gltf.materials, materials = _tileContent$gltf$mat === void 0 ? [] : _tileContent$gltf$mat;
140
81
 
141
- function convertAttributes(tileContent) {
142
- var _tileContent$gltf$sce;
82
+ if (!(materials !== null && materials !== void 0 && materials.length)) {
83
+ materials.push({
84
+ id: 'default'
85
+ });
86
+ }
143
87
 
144
- const attributesMap = new Map();
88
+ i = 0;
145
89
 
146
- for (const material of tileContent.gltf.materials || [{
147
- id: 'default'
148
- }]) {
149
- attributesMap.set(material.id, {
150
- positions: new Float32Array(0),
151
- normals: new Float32Array(0),
152
- texCoords: new Float32Array(0),
153
- colors: new Uint8Array(0),
154
- featureIndices: []
155
- });
156
- }
90
+ case 10:
91
+ if (!(i < materials.length)) {
92
+ _context.next = 25;
93
+ break;
94
+ }
157
95
 
158
- 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;
159
- convertNodes(nodes, tileContent, attributesMap);
96
+ sourceMaterial = materials[i];
160
97
 
161
- for (const attrKey of attributesMap.keys()) {
162
- const attributes = attributesMap.get(attrKey);
98
+ if (convertedAttributesMap.has(sourceMaterial.id)) {
99
+ _context.next = 14;
100
+ break;
101
+ }
163
102
 
164
- if (attributes.positions.length === 0) {
165
- attributesMap.delete(attrKey);
166
- continue;
167
- }
103
+ return _context.abrupt("continue", 22);
104
+
105
+ case 14:
106
+ convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
107
+ _materialAndTextureLi = materialAndTextureList[i], material = _materialAndTextureLi.material, texture = _materialAndTextureLi.texture;
108
+ _context.t0 = result;
109
+ _context.next = 19;
110
+ return _makeNodeResources({
111
+ convertedAttributes: convertedAttributes,
112
+ material: material,
113
+ texture: texture,
114
+ tileContent: tileContent,
115
+ nodeId: nodesCounter,
116
+ featuresHashArray: featuresHashArray,
117
+ attributeStorageInfo: attributeStorageInfo,
118
+ draco: draco
119
+ });
120
+
121
+ case 19:
122
+ _context.t1 = _context.sent;
168
123
 
169
- const vertexCount = attributes.positions.length / VALUES_PER_VERTEX;
124
+ _context.t0.push.call(_context.t0, _context.t1);
170
125
 
171
- if (!attributes.colors.length) {
172
- attributes.colors = new Uint8Array(vertexCount * VALUES_PER_COLOR_ELEMENT);
126
+ nodesCounter++;
173
127
 
174
- for (let index = 0; index < attributes.colors.length; index += 4) {
175
- attributes.colors.set([255, 255, 255, 255], index);
128
+ case 22:
129
+ i++;
130
+ _context.next = 10;
131
+ break;
132
+
133
+ case 25:
134
+ if (result.length) {
135
+ _context.next = 27;
136
+ break;
137
+ }
138
+
139
+ return _context.abrupt("return", null);
140
+
141
+ case 27:
142
+ return _context.abrupt("return", result);
143
+
144
+ case 28:
145
+ case "end":
146
+ return _context.stop();
147
+ }
176
148
  }
177
- }
149
+ }, _callee);
150
+ }));
151
+ return _convertB3dmToI3sGeometry.apply(this, arguments);
152
+ }
153
+
154
+ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
155
+ var _iterator = _createForOfIteratorHelper(convertedAttributesMap.values()),
156
+ _step;
157
+
158
+ try {
159
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
160
+ var attributes = _step.value;
161
+ var boundingVolumes = (0, _coordinateConverter.createBoundingVolumesFromGeometry)(attributes.positions, geoidHeightModel);
162
+ attributes.boundingVolumes = boundingVolumes;
163
+ var cartographicOrigin = boundingVolumes.obb.center;
164
+
165
+ for (var index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
166
+ var vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
178
167
 
179
- if (!attributes.texCoords.length) {
180
- attributes.texCoords = new Float32Array(vertexCount * VALUES_PER_TEX_COORD);
168
+ _geospatial.Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
181
169
 
182
- for (let index = 0; index < attributes.texCoords.length; index += 2) {
183
- attributes.texCoords.set([1, 1], index);
170
+ scratchVector[2] = scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
171
+ scratchVector = scratchVector.subtract(cartographicOrigin);
172
+ attributes.positions.set(scratchVector, index);
184
173
  }
185
174
  }
175
+ } catch (err) {
176
+ _iterator.e(err);
177
+ } finally {
178
+ _iterator.f();
179
+ }
180
+ }
181
+
182
+ function _makeNodeResources(_x8) {
183
+ return _makeNodeResources2.apply(this, arguments);
184
+ }
185
+
186
+ function _makeNodeResources2() {
187
+ _makeNodeResources2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref) {
188
+ var convertedAttributes, material, texture, tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, boundingVolumes, vertexCount, triangleCount, _generateAttributes, faceRange, featureIds, positions, normals, colors, texCoords, featureCount, header, typedFeatureIds, fileBuffer, compressedGeometry, attributes;
189
+
190
+ return _regenerator.default.wrap(function _callee2$(_context2) {
191
+ while (1) {
192
+ switch (_context2.prev = _context2.next) {
193
+ case 0:
194
+ convertedAttributes = _ref.convertedAttributes, material = _ref.material, texture = _ref.texture, tileContent = _ref.tileContent, nodeId = _ref.nodeId, featuresHashArray = _ref.featuresHashArray, attributeStorageInfo = _ref.attributeStorageInfo, draco = _ref.draco;
195
+ boundingVolumes = convertedAttributes.boundingVolumes;
196
+ vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
197
+ triangleCount = vertexCount / 3;
198
+ _generateAttributes = (0, _geometryAttributes.generateAttributes)(_objectSpread({
199
+ triangleCount: triangleCount
200
+ }, convertedAttributes)), faceRange = _generateAttributes.faceRange, featureIds = _generateAttributes.featureIds, positions = _generateAttributes.positions, normals = _generateAttributes.normals, colors = _generateAttributes.colors, texCoords = _generateAttributes.texCoords, featureCount = _generateAttributes.featureCount;
201
+
202
+ if (tileContent.batchTableJson) {
203
+ makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
204
+ }
205
+
206
+ header = new Uint32Array(2);
207
+ typedFeatureIds = generateBigUint64Array(featureIds);
208
+ header.set([vertexCount, featureCount], 0);
209
+ fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
210
+
211
+ if (!draco) {
212
+ _context2.next = 16;
213
+ break;
214
+ }
215
+
216
+ _context2.next = 13;
217
+ return generateCompressedGeometry(vertexCount, convertedAttributes, {
218
+ positions: positions,
219
+ normals: normals,
220
+ texCoords: texture ? texCoords : new Float32Array(0),
221
+ colors: colors,
222
+ featureIds: featureIds,
223
+ faceRange: faceRange
224
+ });
225
+
226
+ case 13:
227
+ _context2.t0 = _context2.sent;
228
+ _context2.next = 17;
229
+ break;
230
+
231
+ case 16:
232
+ _context2.t0 = null;
233
+
234
+ case 17:
235
+ compressedGeometry = _context2.t0;
236
+ attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
237
+ return _context2.abrupt("return", {
238
+ geometry: fileBuffer,
239
+ compressedGeometry: compressedGeometry,
240
+ texture: texture,
241
+ sharedResources: getSharedResources(tileContent, nodeId),
242
+ meshMaterial: material,
243
+ vertexCount: vertexCount,
244
+ attributes: attributes,
245
+ featureCount: featureCount,
246
+ boundingVolumes: boundingVolumes
247
+ });
248
+
249
+ case 20:
250
+ case "end":
251
+ return _context2.stop();
252
+ }
253
+ }
254
+ }, _callee2);
255
+ }));
256
+ return _makeNodeResources2.apply(this, arguments);
257
+ }
258
+
259
+ function convertAttributes(tileContent, useCartesianPositions) {
260
+ var _tileContent$gltf$sce;
261
+
262
+ var attributesMap = new Map();
186
263
 
187
- attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
264
+ var _iterator2 = _createForOfIteratorHelper(tileContent.gltf.materials || [{
265
+ id: 'default'
266
+ }]),
267
+ _step2;
268
+
269
+ try {
270
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
271
+ var material = _step2.value;
272
+ attributesMap.set(material.id, {
273
+ positions: new Float32Array(0),
274
+ normals: new Float32Array(0),
275
+ texCoords: new Float32Array(0),
276
+ colors: new Uint8Array(0),
277
+ featureIndices: [],
278
+ boundingVolumes: null
279
+ });
280
+ }
281
+ } catch (err) {
282
+ _iterator2.e(err);
283
+ } finally {
284
+ _iterator2.f();
285
+ }
286
+
287
+ var 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;
288
+ convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);
289
+
290
+ var _iterator3 = _createForOfIteratorHelper(attributesMap.keys()),
291
+ _step3;
292
+
293
+ try {
294
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
295
+ var attrKey = _step3.value;
296
+ var attributes = attributesMap.get(attrKey);
297
+
298
+ if (attributes.positions.length === 0) {
299
+ attributesMap.delete(attrKey);
300
+ continue;
301
+ }
302
+
303
+ attributes.featureIndices = attributes.featureIndices.reduce(function (acc, value) {
304
+ return acc.concat(value);
305
+ });
306
+ }
307
+ } catch (err) {
308
+ _iterator3.e(err);
309
+ } finally {
310
+ _iterator3.f();
188
311
  }
189
312
 
190
313
  return attributesMap;
191
314
  }
192
315
 
193
- function convertNodes(nodes, tileContent, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
316
+ function convertNodes(nodes, tileContent, attributesMap, useCartesianPositions) {
317
+ var matrix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
318
+
194
319
  if (nodes) {
195
- for (const node of nodes) {
196
- convertNode(node, tileContent, attributesMap, matrix);
320
+ var _iterator4 = _createForOfIteratorHelper(nodes),
321
+ _step4;
322
+
323
+ try {
324
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
325
+ var node = _step4.value;
326
+ convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);
327
+ }
328
+ } catch (err) {
329
+ _iterator4.e(err);
330
+ } finally {
331
+ _iterator4.f();
197
332
  }
198
333
  }
199
334
  }
200
335
 
201
- function convertNode(node, tileContent, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
202
- const nodeMatrix = node.matrix;
203
- const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
204
- const mesh = node.mesh;
336
+ function convertNode(node, tileContent, attributesMap, useCartesianPositions) {
337
+ var matrix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
338
+ var nodeMatrix = node.matrix;
339
+ var compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
340
+ var mesh = node.mesh;
205
341
 
206
342
  if (mesh) {
207
- convertMesh(mesh, tileContent, attributesMap, compositeMatrix);
343
+ convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, compositeMatrix);
208
344
  }
209
345
 
210
- convertNodes(node.children, tileContent, attributesMap, compositeMatrix);
346
+ convertNodes(node.children, tileContent, attributesMap, useCartesianPositions, compositeMatrix);
211
347
  }
212
348
 
213
- function convertMesh(mesh, content, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
214
- for (const primitive of mesh.primitives) {
215
- let outputAttributes = null;
349
+ function convertMesh(mesh, content, attributesMap) {
350
+ var useCartesianPositions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
351
+ var matrix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
216
352
 
217
- if (primitive.material) {
218
- outputAttributes = attributesMap.get(primitive.material.id);
219
- } else if (attributesMap.has('default')) {
220
- outputAttributes = attributesMap.get('default');
221
- }
353
+ var _iterator5 = _createForOfIteratorHelper(mesh.primitives),
354
+ _step5;
355
+
356
+ try {
357
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
358
+ var primitive = _step5.value;
359
+ var outputAttributes = null;
222
360
 
223
- (0, _core2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
224
- const attributes = primitive.attributes;
225
- outputAttributes.positions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
226
- vertices: attributes.POSITION.value,
227
- cartographicOrigin: content.cartographicOrigin,
228
- cartesianModelMatrix: content.cartesianModelMatrix,
229
- nodeMatrix: matrix,
230
- indices: primitive.indices.value,
231
- attributeSpecificTransformation: transformVertexPositions
232
- }));
233
- outputAttributes.normals = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
234
- vertices: attributes.NORMAL && attributes.NORMAL.value,
235
- cartographicOrigin: content.cartographicOrigin,
236
- cartesianModelMatrix: content.cartesianModelMatrix,
237
- nodeMatrix: matrix,
238
- indices: primitive.indices.value,
239
- attributeSpecificTransformation: transformVertexNormals
240
- }));
241
- outputAttributes.texCoords = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
242
- outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
243
- outputAttributes.featureIndices.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value));
361
+ if (primitive.material) {
362
+ outputAttributes = attributesMap.get(primitive.material.id);
363
+ } else if (attributesMap.has('default')) {
364
+ outputAttributes = attributesMap.get('default');
365
+ }
366
+
367
+ (0, _core2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
368
+ var attributes = primitive.attributes;
369
+ outputAttributes.positions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
370
+ vertices: attributes.POSITION.value,
371
+ cartographicOrigin: content.cartographicOrigin,
372
+ cartesianModelMatrix: content.cartesianModelMatrix,
373
+ nodeMatrix: matrix,
374
+ indices: primitive.indices.value,
375
+ attributeSpecificTransformation: transformVertexPositions,
376
+ useCartesianPositions: useCartesianPositions
377
+ }));
378
+ outputAttributes.normals = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
379
+ vertices: attributes.NORMAL && attributes.NORMAL.value,
380
+ cartographicOrigin: content.cartographicOrigin,
381
+ cartesianModelMatrix: content.cartesianModelMatrix,
382
+ nodeMatrix: matrix,
383
+ indices: primitive.indices.value,
384
+ attributeSpecificTransformation: transformVertexNormals,
385
+ useCartesianPositions: false
386
+ }));
387
+ outputAttributes.texCoords = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
388
+ outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
389
+ outputAttributes.featureIndices.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value));
390
+ }
391
+ } catch (err) {
392
+ _iterator5.e(err);
393
+ } finally {
394
+ _iterator5.f();
244
395
  }
245
396
  }
246
397
 
247
398
  function transformVertexArray(args) {
248
- const {
249
- vertices,
250
- indices,
251
- attributeSpecificTransformation
252
- } = args;
253
- const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
399
+ var vertices = args.vertices,
400
+ indices = args.indices,
401
+ attributeSpecificTransformation = args.attributeSpecificTransformation;
402
+ var newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
254
403
 
255
404
  if (!vertices) {
256
405
  return newVertices;
257
406
  }
258
407
 
259
- for (let i = 0; i < indices.length; i++) {
260
- const coordIndex = indices[i] * VALUES_PER_VERTEX;
261
- const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
262
- let vertexVector = new _core.Vector3(Array.from(vertex));
408
+ for (var i = 0; i < indices.length; i++) {
409
+ var coordIndex = indices[i] * VALUES_PER_VERTEX;
410
+ var vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
411
+ var vertexVector = new _core.Vector3(Array.from(vertex));
263
412
  vertexVector = attributeSpecificTransformation(vertexVector, args);
264
413
  newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
265
414
  newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
@@ -270,11 +419,10 @@ function transformVertexArray(args) {
270
419
  }
271
420
 
272
421
  function transformVertexPositions(vertexVector, calleeArgs) {
273
- const {
274
- cartesianModelMatrix,
275
- cartographicOrigin,
276
- nodeMatrix
277
- } = calleeArgs;
422
+ var cartesianModelMatrix = calleeArgs.cartesianModelMatrix,
423
+ cartographicOrigin = calleeArgs.cartographicOrigin,
424
+ nodeMatrix = calleeArgs.nodeMatrix,
425
+ useCartesianPositions = calleeArgs.useCartesianPositions;
278
426
 
279
427
  if (nodeMatrix) {
280
428
  vertexVector = vertexVector.transform(nodeMatrix);
@@ -282,6 +430,10 @@ function transformVertexPositions(vertexVector, calleeArgs) {
282
430
 
283
431
  vertexVector = vertexVector.transform(cartesianModelMatrix);
284
432
 
433
+ if (useCartesianPositions) {
434
+ return vertexVector;
435
+ }
436
+
285
437
  _geospatial.Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
286
438
 
287
439
  vertexVector = vertexVector.subtract(cartographicOrigin);
@@ -289,10 +441,8 @@ function transformVertexPositions(vertexVector, calleeArgs) {
289
441
  }
290
442
 
291
443
  function transformVertexNormals(vertexVector, calleeArgs) {
292
- const {
293
- cartesianModelMatrix,
294
- nodeMatrix
295
- } = calleeArgs;
444
+ var cartesianModelMatrix = calleeArgs.cartesianModelMatrix,
445
+ nodeMatrix = calleeArgs.nodeMatrix;
296
446
 
297
447
  if (nodeMatrix) {
298
448
  vertexVector = vertexVector.transformAsVector(nodeMatrix);
@@ -303,15 +453,16 @@ function transformVertexNormals(vertexVector, calleeArgs) {
303
453
  }
304
454
 
305
455
  function flattenTexCoords(texCoords, indices) {
306
- const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
456
+ var newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
307
457
 
308
458
  if (!texCoords) {
459
+ newTexCoords.fill(1);
309
460
  return newTexCoords;
310
461
  }
311
462
 
312
- for (let i = 0; i < indices.length; i++) {
313
- const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
314
- const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
463
+ for (var i = 0; i < indices.length; i++) {
464
+ var coordIndex = indices[i] * VALUES_PER_TEX_COORD;
465
+ var texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
315
466
  newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
316
467
  newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
317
468
  }
@@ -320,21 +471,22 @@ function flattenTexCoords(texCoords, indices) {
320
471
  }
321
472
 
322
473
  function flattenColors(colorsAttribute, indices) {
323
- const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
324
- const newColors = new Uint8Array(indices.length * components);
474
+ var components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
475
+ var newColors = new Uint8Array(indices.length * components);
325
476
 
326
477
  if (!colorsAttribute) {
478
+ newColors.fill(255);
327
479
  return newColors;
328
480
  }
329
481
 
330
- const colors = colorsAttribute.value;
482
+ var colors = colorsAttribute.value;
331
483
 
332
- for (let i = 0; i < indices.length; i++) {
333
- const colorIndex = indices[i] * components;
334
- const color = colors.subarray(colorIndex, colorIndex + components);
335
- const colorUint8 = new Uint8Array(components);
484
+ for (var i = 0; i < indices.length; i++) {
485
+ var colorIndex = indices[i] * components;
486
+ var color = colors.subarray(colorIndex, colorIndex + components);
487
+ var colorUint8 = new Uint8Array(components);
336
488
 
337
- for (let j = 0; j < color.length; j++) {
489
+ for (var j = 0; j < color.length; j++) {
338
490
  colorUint8[j] = color[j] * 255;
339
491
  }
340
492
 
@@ -349,10 +501,10 @@ function flattenBatchIds(batchedIds, indices) {
349
501
  return [];
350
502
  }
351
503
 
352
- const newBatchIds = [];
504
+ var newBatchIds = [];
353
505
 
354
- for (let i = 0; i < indices.length; i++) {
355
- const coordIndex = indices[i];
506
+ for (var i = 0; i < indices.length; i++) {
507
+ var coordIndex = indices[i];
356
508
  newBatchIds.push(batchedIds[coordIndex]);
357
509
  }
358
510
 
@@ -360,10 +512,10 @@ function flattenBatchIds(batchedIds, indices) {
360
512
  }
361
513
 
362
514
  function getBatchIdsByAttributeName(attributes) {
363
- let batchIds = [];
515
+ var batchIds = [];
364
516
 
365
- for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
366
- const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
517
+ for (var index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
518
+ var possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
367
519
 
368
520
  if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
369
521
  batchIds = attributes[possibleBatchIdAttributeName].value;
@@ -375,27 +527,39 @@ function getBatchIdsByAttributeName(attributes) {
375
527
  }
376
528
 
377
529
  function convertMaterials(tileContent) {
378
- const result = [];
379
- const sourceMaterials = tileContent.gltf.materials || [];
530
+ var result = [];
531
+ var sourceMaterials = tileContent.gltf.materials || [];
532
+
533
+ var _iterator6 = _createForOfIteratorHelper(sourceMaterials),
534
+ _step6;
380
535
 
381
- for (const sourceMaterial of sourceMaterials) {
382
- result.push(convertMaterial(sourceMaterial));
536
+ try {
537
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
538
+ var sourceMaterial = _step6.value;
539
+ result.push(convertMaterial(sourceMaterial));
540
+ }
541
+ } catch (err) {
542
+ _iterator6.e(err);
543
+ } finally {
544
+ _iterator6.f();
383
545
  }
384
546
 
385
547
  return result;
386
548
  }
387
549
 
388
550
  function convertMaterial(sourceMaterial) {
389
- const material = {
551
+ var material = {
390
552
  doubleSided: sourceMaterial.doubleSided,
391
- emissiveFactor: sourceMaterial.emissiveFactor.map(c => Math.round(c * 255)),
553
+ emissiveFactor: sourceMaterial.emissiveFactor.map(function (c) {
554
+ return Math.round(c * 255);
555
+ }),
392
556
  alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),
393
557
  pbrMetallicRoughness: {
394
558
  roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,
395
559
  metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor
396
560
  }
397
561
  };
398
- let texture;
562
+ var texture;
399
563
 
400
564
  if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {
401
565
  texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
@@ -410,13 +574,15 @@ function convertMaterial(sourceMaterial) {
410
574
  }
411
575
 
412
576
  if (!texture) {
413
- const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;
414
- material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
577
+ var baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;
578
+ material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(function (c) {
579
+ return Math.round(c * 255);
580
+ }) || undefined;
415
581
  }
416
582
 
417
583
  return {
418
- material,
419
- texture
584
+ material: material,
585
+ texture: texture
420
586
  };
421
587
  }
422
588
 
@@ -428,8 +594,8 @@ function getDefaultMaterial() {
428
594
  }
429
595
 
430
596
  function getSharedResources(tileContent, nodeId) {
431
- const gltfMaterials = tileContent.gltf.materials;
432
- const i3sResources = {};
597
+ var gltfMaterials = tileContent.gltf.materials;
598
+ var i3sResources = {};
433
599
 
434
600
  if (!gltfMaterials || !gltfMaterials.length) {
435
601
  return i3sResources;
@@ -437,35 +603,45 @@ function getSharedResources(tileContent, nodeId) {
437
603
 
438
604
  i3sResources.materialDefinitionInfos = [];
439
605
 
440
- for (const gltfMaterial of gltfMaterials) {
441
- const {
442
- materialDefinitionInfo,
443
- textureDefinitionInfo
444
- } = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
445
- i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
606
+ var _iterator7 = _createForOfIteratorHelper(gltfMaterials),
607
+ _step7;
608
+
609
+ try {
610
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
611
+ var gltfMaterial = _step7.value;
612
+
613
+ var _convertGLTFMaterialT = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId),
614
+ materialDefinitionInfo = _convertGLTFMaterialT.materialDefinitionInfo,
615
+ textureDefinitionInfo = _convertGLTFMaterialT.textureDefinitionInfo;
446
616
 
447
- if (textureDefinitionInfo) {
448
- i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
449
- i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
617
+ i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
618
+
619
+ if (textureDefinitionInfo) {
620
+ i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
621
+ i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
622
+ }
450
623
  }
624
+ } catch (err) {
625
+ _iterator7.e(err);
626
+ } finally {
627
+ _iterator7.f();
451
628
  }
452
629
 
453
630
  return i3sResources;
454
631
  }
455
632
 
456
633
  function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
457
- const texture = gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;
458
- let textureDefinitionInfo = null;
634
+ var texture = gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;
635
+ var textureDefinitionInfo = null;
459
636
 
460
637
  if (texture) {
461
638
  textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
462
639
  }
463
640
 
464
- const {
465
- baseColorFactor,
466
- metallicFactor
467
- } = gltfMaterial.pbrMetallicRoughness;
468
- let colorFactor = baseColorFactor;
641
+ var _gltfMaterial$pbrMeta = gltfMaterial.pbrMetallicRoughness,
642
+ baseColorFactor = _gltfMaterial$pbrMeta.baseColorFactor,
643
+ metallicFactor = _gltfMaterial$pbrMeta.metallicFactor;
644
+ var colorFactor = baseColorFactor;
469
645
 
470
646
  if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
471
647
  colorFactor = gltfMaterial.emissiveFactor;
@@ -474,20 +650,21 @@ function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
474
650
 
475
651
  return {
476
652
  materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),
477
- textureDefinitionInfo
653
+ textureDefinitionInfo: textureDefinitionInfo
478
654
  };
479
655
  }
480
656
 
481
- function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {
482
- const matDielectricColorComponent = 0.04 / 255;
483
- const black = new _core.Vector4(0, 0, 0, 1);
484
- const unitVector = new _core.Vector4(1, 1, 1, 1);
485
- const dielectricSpecular = new _core.Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
486
- const baseColorVector = new _core.Vector4(baseColorFactor);
487
- const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
488
- const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
657
+ function extractSharedResourcesMaterialInfo(baseColorFactor) {
658
+ var metallicFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
659
+ var matDielectricColorComponent = 0.04 / 255;
660
+ var black = new _core.Vector4(0, 0, 0, 1);
661
+ var unitVector = new _core.Vector4(1, 1, 1, 1);
662
+ var dielectricSpecular = new _core.Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
663
+ var baseColorVector = new _core.Vector4(baseColorFactor);
664
+ var firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
665
+ var diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
489
666
  dielectricSpecular[3] = 1;
490
- const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
667
+ var specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
491
668
  return {
492
669
  diffuse: diffuse.toArray(),
493
670
  specular: specular.toArray()
@@ -506,36 +683,35 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
506
683
  }
507
684
 
508
685
  function generateImageId(texture, nodeId) {
509
- const {
510
- width,
511
- height
512
- } = texture.source.image;
513
- const levelCountOfTexture = 1;
514
- const indexOfLevel = 0;
515
- const indexOfTextureInStore = nodeId + 1;
516
- const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
517
- const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
518
- const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
519
- const shiftedIndexOfLevel = indexOfLevel << 24;
520
- const shiftedWidth = width - 1 << 12;
521
- const shiftedHeight = height - 1 << 0;
522
- const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
523
- const imageId = BigInt("0b".concat(leftHalf.toString(2)).concat(rightHalf));
686
+ var _texture$source$image = texture.source.image,
687
+ width = _texture$source$image.width,
688
+ height = _texture$source$image.height;
689
+ var levelCountOfTexture = 1;
690
+ var indexOfLevel = 0;
691
+ var indexOfTextureInStore = nodeId + 1;
692
+ var zerosCount = 32 - indexOfTextureInStore.toString(2).length;
693
+ var rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
694
+ var shiftedLevelCountOfTexture = levelCountOfTexture << 28;
695
+ var shiftedIndexOfLevel = indexOfLevel << 24;
696
+ var shiftedWidth = width - 1 << 12;
697
+ var shiftedHeight = height - 1 << 0;
698
+ var leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
699
+ var imageId = BigInt("0b".concat(leftHalf.toString(2)).concat(rightHalf));
524
700
  return imageId.toString();
525
701
  }
526
702
 
527
703
  function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
528
- const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
704
+ var replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
529
705
  replaceIndicesByUnique(featureIndices, replaceMap);
530
706
  replaceIndicesByUnique(featureIds, replaceMap);
531
707
  }
532
708
 
533
709
  function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
534
- const featureMap = {};
710
+ var featureMap = {};
535
711
 
536
- for (let index = 0; index < featureIds.length; index++) {
537
- const oldFeatureId = featureIds[index];
538
- const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
712
+ for (var index = 0; index < featureIds.length; index++) {
713
+ var oldFeatureId = featureIds[index];
714
+ var uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
539
715
  featureMap[oldFeatureId.toString()] = uniqueFeatureId;
540
716
  }
541
717
 
@@ -543,9 +719,9 @@ function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
543
719
  }
544
720
 
545
721
  function generateStringFromBatchTableByIndex(batchTable, index) {
546
- let str = '';
722
+ var str = '';
547
723
 
548
- for (const key in batchTable) {
724
+ for (var key in batchTable) {
549
725
  str += batchTable[key][index];
550
726
  }
551
727
 
@@ -553,8 +729,8 @@ function generateStringFromBatchTableByIndex(batchTable, index) {
553
729
  }
554
730
 
555
731
  function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
556
- const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
557
- const hash = (0, _md.default)(batchTableStr);
732
+ var batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
733
+ var hash = (0, _md.default)(batchTableStr);
558
734
 
559
735
  if (featuresHashArray.includes(hash)) {
560
736
  return featuresHashArray.indexOf(hash);
@@ -564,23 +740,22 @@ function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
564
740
  }
565
741
 
566
742
  function replaceIndicesByUnique(indicesArray, featureMap) {
567
- for (let index = 0; index < indicesArray.length; index++) {
743
+ for (var index = 0; index < indicesArray.length; index++) {
568
744
  indicesArray[index] = featureMap[indicesArray[index]];
569
745
  }
570
746
  }
571
747
 
572
748
  function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {
573
- const attributeBuffers = [];
749
+ var attributeBuffers = [];
574
750
 
575
751
  if (batchTable) {
576
- const batchTableWithFeatureIds = {
577
- OBJECTID: featureIds,
578
- ...batchTable
579
- };
752
+ var batchTableWithFeatureIds = _objectSpread({
753
+ OBJECTID: featureIds
754
+ }, batchTable);
580
755
 
581
- for (const key in batchTableWithFeatureIds) {
582
- const type = getAttributeType(key, attributeStorageInfo);
583
- let attributeBuffer = null;
756
+ for (var key in batchTableWithFeatureIds) {
757
+ var type = getAttributeType(key, attributeStorageInfo);
758
+ var attributeBuffer = null;
584
759
 
585
760
  switch (type) {
586
761
  case OBJECT_ID_TYPE:
@@ -608,104 +783,124 @@ function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeSt
608
783
  }
609
784
 
610
785
  function getAttributeType(key, attributeStorageInfo) {
611
- const attribute = attributeStorageInfo.find(attr => attr.name === key);
786
+ var attribute = attributeStorageInfo.find(function (attr) {
787
+ return attr.name === key;
788
+ });
612
789
  return attribute.attributeValues.valueType;
613
790
  }
614
791
 
615
792
  function generateShortIntegerAttributeBuffer(featureIds) {
616
- const count = new Uint32Array([featureIds.length]);
617
- const valuesArray = new Uint32Array(featureIds);
793
+ var count = new Uint32Array([featureIds.length]);
794
+ var valuesArray = new Uint32Array(featureIds);
618
795
  return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, valuesArray.buffer);
619
796
  }
620
797
 
621
798
  function generateDoubleAttributeBuffer(featureIds) {
622
- const count = new Uint32Array([featureIds.length]);
623
- const padding = new Uint8Array(4);
624
- const valuesArray = new Float64Array(featureIds);
799
+ var count = new Uint32Array([featureIds.length]);
800
+ var padding = new Uint8Array(4);
801
+ var valuesArray = new Float64Array(featureIds);
625
802
  return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, padding.buffer, valuesArray.buffer);
626
803
  }
627
804
 
628
805
  function generateStringAttributeBuffer(batchAttributes) {
629
- const stringCountArray = new Uint32Array([batchAttributes.length]);
630
- let totalNumberOfBytes = 0;
631
- const stringSizesArray = new Uint32Array(batchAttributes.length);
632
- const stringBufferArray = [];
633
-
634
- for (let index = 0; index < batchAttributes.length; index++) {
635
- const currentString = "".concat(String(batchAttributes[index]), "\0");
636
- const currentStringBuffer = Buffer.from(currentString);
637
- const currentStringSize = currentStringBuffer.length;
806
+ var stringCountArray = new Uint32Array([batchAttributes.length]);
807
+ var totalNumberOfBytes = 0;
808
+ var stringSizesArray = new Uint32Array(batchAttributes.length);
809
+ var stringBufferArray = [];
810
+
811
+ for (var index = 0; index < batchAttributes.length; index++) {
812
+ var currentString = "".concat(String(batchAttributes[index]), "\0");
813
+ var currentStringBuffer = Buffer.from(currentString);
814
+ var currentStringSize = currentStringBuffer.length;
638
815
  totalNumberOfBytes += currentStringSize;
639
816
  stringSizesArray[index] = currentStringSize;
640
817
  stringBufferArray.push(currentStringBuffer);
641
818
  }
642
819
 
643
- const totalBytes = new Uint32Array([totalNumberOfBytes]);
644
- return (0, _loaderUtils.concatenateArrayBuffers)(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
820
+ var totalBytes = new Uint32Array([totalNumberOfBytes]);
821
+ return _loaderUtils.concatenateArrayBuffers.apply(void 0, [stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer].concat(stringBufferArray));
645
822
  }
646
823
 
647
824
  function generateBigUint64Array(featureIds) {
648
- const typedFeatureIds = new BigUint64Array(featureIds.length);
825
+ var typedFeatureIds = new BigUint64Array(featureIds.length);
649
826
 
650
- for (let index = 0; index < featureIds.length; index++) {
827
+ for (var index = 0; index < featureIds.length; index++) {
651
828
  typedFeatureIds[index] = BigInt(featureIds[index]);
652
829
  }
653
830
 
654
831
  return typedFeatureIds;
655
832
  }
656
833
 
657
- async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {
658
- const {
659
- positions,
660
- normals,
661
- texCoords,
662
- colors,
663
- featureIds,
664
- faceRange
665
- } = attributes;
666
- const indices = new Uint32Array(vertexCount);
667
-
668
- for (let index = 0; index < indices.length; index++) {
669
- indices.set([index], index);
670
- }
671
-
672
- const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
673
- const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
674
- const compressedAttributes = {
675
- positions,
676
- normals,
677
- colors,
678
- 'feature-index': featureIndex
679
- };
680
-
681
- if (texCoords.length) {
682
- compressedAttributes.texCoords = texCoords;
683
- }
684
-
685
- const attributesMetadata = {
686
- 'feature-index': {
687
- 'i3s-attribute-type': 'feature-index',
688
- 'i3s-feature-ids': new Int32Array(featureIds)
689
- }
690
- };
691
- return new Uint8Array(await (0, _core2.encode)({
692
- attributes: compressedAttributes,
693
- indices
694
- }, _draco.DracoWriter, {
695
- draco: {
696
- method: 'MESH_SEQUENTIAL_ENCODING',
697
- attributesMetadata
698
- }
834
+ function generateCompressedGeometry(_x9, _x10, _x11) {
835
+ return _generateCompressedGeometry.apply(this, arguments);
836
+ }
837
+
838
+ function _generateCompressedGeometry() {
839
+ _generateCompressedGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(vertexCount, convertedAttributes, attributes) {
840
+ var positions, normals, texCoords, colors, featureIds, faceRange, indices, index, featureIndices, featureIndex, compressedAttributes, attributesMetadata;
841
+ return _regenerator.default.wrap(function _callee3$(_context3) {
842
+ while (1) {
843
+ switch (_context3.prev = _context3.next) {
844
+ case 0:
845
+ positions = attributes.positions, normals = attributes.normals, texCoords = attributes.texCoords, colors = attributes.colors, featureIds = attributes.featureIds, faceRange = attributes.faceRange;
846
+ indices = new Uint32Array(vertexCount);
847
+
848
+ for (index = 0; index < indices.length; index++) {
849
+ indices.set([index], index);
850
+ }
851
+
852
+ featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
853
+ featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
854
+ compressedAttributes = {
855
+ positions: positions,
856
+ normals: normals,
857
+ colors: colors,
858
+ 'feature-index': featureIndex
859
+ };
860
+
861
+ if (texCoords.length) {
862
+ compressedAttributes.texCoords = texCoords;
863
+ }
864
+
865
+ attributesMetadata = {
866
+ 'feature-index': {
867
+ 'i3s-attribute-type': 'feature-index',
868
+ 'i3s-feature-ids': new Int32Array(featureIds)
869
+ }
870
+ };
871
+ _context3.t0 = Uint8Array;
872
+ _context3.next = 11;
873
+ return (0, _core2.encode)({
874
+ attributes: compressedAttributes,
875
+ indices: indices
876
+ }, _draco.DracoWriter, {
877
+ draco: {
878
+ method: 'MESH_SEQUENTIAL_ENCODING',
879
+ attributesMetadata: attributesMetadata
880
+ }
881
+ });
882
+
883
+ case 11:
884
+ _context3.t1 = _context3.sent;
885
+ return _context3.abrupt("return", new _context3.t0(_context3.t1));
886
+
887
+ case 13:
888
+ case "end":
889
+ return _context3.stop();
890
+ }
891
+ }
892
+ }, _callee3);
699
893
  }));
894
+ return _generateCompressedGeometry.apply(this, arguments);
700
895
  }
701
896
 
702
897
  function generateFeatureIndexAttribute(featureIndex, faceRange) {
703
- const orderedFeatureIndices = new Uint32Array(featureIndex.length);
704
- let fillIndex = 0;
705
- let startIndex = 0;
898
+ var orderedFeatureIndices = new Uint32Array(featureIndex.length);
899
+ var fillIndex = 0;
900
+ var startIndex = 0;
706
901
 
707
- for (let index = 1; index < faceRange.length; index += 2) {
708
- const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
902
+ for (var index = 1; index < faceRange.length; index += 2) {
903
+ var endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
709
904
  orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
710
905
  fillIndex++;
711
906
  startIndex = endIndex + 1;