@loaders.gl/i3s 3.4.13 → 3.4.15

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 (58) hide show
  1. package/dist/dist.min.js +124 -111
  2. package/dist/es5/arcgis-webscene-loader.js +5 -22
  3. package/dist/es5/arcgis-webscene-loader.js.map +1 -1
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/i3s-attribute-loader.js +58 -123
  7. package/dist/es5/i3s-attribute-loader.js.map +1 -1
  8. package/dist/es5/i3s-building-scene-layer-loader.js +8 -28
  9. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
  10. package/dist/es5/i3s-content-loader.js +16 -35
  11. package/dist/es5/i3s-content-loader.js.map +1 -1
  12. package/dist/es5/i3s-loader.js +49 -148
  13. package/dist/es5/i3s-loader.js.map +1 -1
  14. package/dist/es5/i3s-node-page-loader.js +8 -39
  15. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  16. package/dist/es5/i3s-slpk-loader.js +2 -2
  17. package/dist/es5/i3s-slpk-loader.js.map +1 -1
  18. package/dist/es5/index.js +8 -8
  19. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +161 -267
  20. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  21. package/dist/es5/lib/parsers/constants.js +6 -6
  22. package/dist/es5/lib/parsers/constants.js.map +1 -1
  23. package/dist/es5/lib/parsers/parse-arcgis-webscene.js +64 -146
  24. package/dist/es5/lib/parsers/parse-arcgis-webscene.js.map +1 -1
  25. package/dist/es5/lib/parsers/parse-i3s-attribute.js +26 -55
  26. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
  27. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +27 -47
  28. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
  29. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +278 -347
  30. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  31. package/dist/es5/lib/parsers/parse-i3s.js +55 -79
  32. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  33. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +30 -81
  34. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
  35. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +44 -90
  36. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
  37. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +17 -17
  38. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +1 -1
  39. package/dist/es5/lib/parsers/parse-zip/local-file-header.js +10 -10
  40. package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +1 -1
  41. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +4 -6
  42. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
  43. package/dist/es5/lib/utils/customizeColors.js +79 -140
  44. package/dist/es5/lib/utils/customizeColors.js.map +1 -1
  45. package/dist/es5/lib/utils/url-utils.js +14 -11
  46. package/dist/es5/lib/utils/url-utils.js.map +1 -1
  47. package/dist/es5/types.js +2 -2
  48. package/dist/esm/arcgis-webscene-loader.js +1 -1
  49. package/dist/esm/i3s-attribute-loader.js +1 -1
  50. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  51. package/dist/esm/i3s-content-loader.js +1 -1
  52. package/dist/esm/i3s-loader.js +1 -1
  53. package/dist/esm/i3s-node-page-loader.js +1 -1
  54. package/dist/esm/i3s-slpk-loader.js +1 -1
  55. package/dist/i3s-content-nodejs-worker.js +61 -59
  56. package/dist/i3s-content-nodejs-worker.js.map +3 -3
  57. package/dist/i3s-content-worker.js +69 -81
  58. package/package.json +9 -9
@@ -1,14 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.parseI3STileContent = parseI3STileContent;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
7
  var _core = require("@loaders.gl/core");
13
8
  var _core2 = require("@math.gl/core");
14
9
  var _geospatial = require("@math.gl/geospatial");
@@ -19,12 +14,7 @@ var _types = require("../../types");
19
14
  var _urlUtils = require("../utils/url-utils");
20
15
  var _constants = require("./constants");
21
16
  var _customizeColors = require("../utils/customizeColors");
22
- 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; } } }; }
23
- 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); }
24
- 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; }
25
- 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; }
26
- 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; }
27
- var scratchVector = new _core2.Vector3([0, 0, 0]);
17
+ const scratchVector = new _core2.Vector3([0, 0, 0]);
28
18
  function getLoaderForTextureFormat(textureFormat) {
29
19
  switch (textureFormat) {
30
20
  case 'ktx-etc2':
@@ -38,207 +28,151 @@ function getLoaderForTextureFormat(textureFormat) {
38
28
  return _images.ImageLoader;
39
29
  }
40
30
  }
41
- var I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
42
- function parseI3STileContent(_x, _x2, _x3, _x4, _x5) {
43
- return _parseI3STileContent.apply(this, arguments);
44
- }
45
- function _parseI3STileContent() {
46
- _parseI3STileContent = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, tileOptions, tilesetOptions, options, context) {
47
- var content, _options$i3s, url, loader, response, _arrayBuffer, _options, texture;
48
- return _regenerator.default.wrap(function _callee$(_context) {
49
- while (1) switch (_context.prev = _context.next) {
50
- case 0:
51
- content = {
52
- attributes: {},
53
- indices: null,
54
- featureIds: [],
55
- vertexCount: 0,
56
- modelMatrix: new _core2.Matrix4(),
57
- coordinateSystem: 0,
58
- byteLength: 0,
59
- texture: null
60
- };
61
- if (!tileOptions.textureUrl) {
62
- _context.next = 35;
63
- break;
64
- }
65
- url = (0, _urlUtils.getUrlWithToken)(tileOptions.textureUrl, options === null || options === void 0 ? void 0 : (_options$i3s = options.i3s) === null || _options$i3s === void 0 ? void 0 : _options$i3s.token);
66
- loader = getLoaderForTextureFormat(tileOptions.textureFormat);
67
- _context.next = 6;
68
- return fetch(url, options === null || options === void 0 ? void 0 : options.fetch);
69
- case 6:
70
- response = _context.sent;
71
- _context.next = 9;
72
- return response.arrayBuffer();
73
- case 9:
74
- _arrayBuffer = _context.sent;
75
- if (!(options !== null && options !== void 0 && options.i3s.decodeTextures)) {
76
- _context.next = 34;
77
- break;
78
- }
79
- if (!(loader === _images.ImageLoader)) {
80
- _context.next = 26;
81
- break;
82
- }
83
- _options = _objectSpread(_objectSpread({}, tileOptions.textureLoaderOptions), {}, {
84
- image: {
85
- type: 'data'
86
- }
87
- });
88
- _context.prev = 13;
89
- _context.next = 16;
90
- return context.parse(_arrayBuffer, _options);
91
- case 16:
92
- content.texture = _context.sent;
93
- _context.next = 24;
94
- break;
95
- case 19:
96
- _context.prev = 19;
97
- _context.t0 = _context["catch"](13);
98
- _context.next = 23;
99
- return (0, _core.parse)(_arrayBuffer, loader, _options);
100
- case 23:
101
- content.texture = _context.sent;
102
- case 24:
103
- _context.next = 32;
104
- break;
105
- case 26:
106
- if (!(loader === _textures.CompressedTextureLoader || loader === _textures.BasisLoader)) {
107
- _context.next = 32;
108
- break;
109
- }
110
- _context.next = 29;
111
- return (0, _core.load)(_arrayBuffer, loader, tileOptions.textureLoaderOptions);
112
- case 29:
113
- texture = _context.sent;
114
- if (loader === _textures.BasisLoader) {
115
- texture = texture[0];
116
- }
117
- content.texture = {
118
- compressed: true,
119
- mipmaps: false,
120
- width: texture[0].width,
121
- height: texture[0].height,
122
- data: texture
123
- };
124
- case 32:
125
- _context.next = 35;
126
- break;
127
- case 34:
128
- content.texture = _arrayBuffer;
129
- case 35:
130
- content.material = makePbrMaterial(tileOptions.materialDefinition, content.texture);
131
- if (content.material) {
132
- content.texture = null;
31
+ const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
32
+ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, options, context) {
33
+ const content = {
34
+ attributes: {},
35
+ indices: null,
36
+ featureIds: [],
37
+ vertexCount: 0,
38
+ modelMatrix: new _core2.Matrix4(),
39
+ coordinateSystem: 0,
40
+ byteLength: 0,
41
+ texture: null
42
+ };
43
+ if (tileOptions.textureUrl) {
44
+ var _options$i3s;
45
+ const url = (0, _urlUtils.getUrlWithToken)(tileOptions.textureUrl, options === null || options === void 0 ? void 0 : (_options$i3s = options.i3s) === null || _options$i3s === void 0 ? void 0 : _options$i3s.token);
46
+ const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
47
+ const response = await fetch(url, options === null || options === void 0 ? void 0 : options.fetch);
48
+ const arrayBuffer = await response.arrayBuffer();
49
+ if (options !== null && options !== void 0 && options.i3s.decodeTextures) {
50
+ if (loader === _images.ImageLoader) {
51
+ const options = {
52
+ ...tileOptions.textureLoaderOptions,
53
+ image: {
54
+ type: 'data'
133
55
  }
134
- _context.next = 39;
135
- return parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options);
136
- case 39:
137
- return _context.abrupt("return", _context.sent);
138
- case 40:
139
- case "end":
140
- return _context.stop();
56
+ };
57
+ try {
58
+ content.texture = await context.parse(arrayBuffer, options);
59
+ } catch (e) {
60
+ content.texture = await (0, _core.parse)(arrayBuffer, loader, options);
61
+ }
62
+ } else if (loader === _textures.CompressedTextureLoader || loader === _textures.BasisLoader) {
63
+ let texture = await (0, _core.load)(arrayBuffer, loader, tileOptions.textureLoaderOptions);
64
+ if (loader === _textures.BasisLoader) {
65
+ texture = texture[0];
66
+ }
67
+ content.texture = {
68
+ compressed: true,
69
+ mipmaps: false,
70
+ width: texture[0].width,
71
+ height: texture[0].height,
72
+ data: texture
73
+ };
141
74
  }
142
- }, _callee, null, [[13, 19]]);
143
- }));
144
- return _parseI3STileContent.apply(this, arguments);
145
- }
146
- function parseI3SNodeGeometry(_x6, _x7, _x8, _x9, _x10) {
147
- return _parseI3SNodeGeometry.apply(this, arguments);
75
+ } else {
76
+ content.texture = arrayBuffer;
77
+ }
78
+ }
79
+ content.material = makePbrMaterial(tileOptions.materialDefinition, content.texture);
80
+ if (content.material) {
81
+ content.texture = null;
82
+ }
83
+ return await parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options);
148
84
  }
149
- function _parseI3SNodeGeometry() {
150
- _parseI3SNodeGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(arrayBuffer, content, tileOptions, tilesetOptions, options) {
151
- var _options$i3s2;
152
- var contentByteLength, attributes, vertexCount, byteOffset, featureCount, indices, _decompressedGeometry, decompressedGeometry, _decompressedGeometry2, POSITION, NORMAL, COLOR_0, TEXCOORD_0, featureIndex, uvRegion, featureIds, _tilesetOptions$store, vertexAttributes, attributesOrder, featureAttributes, featureAttributeOrder, headers, _normalizeAttributes, normalizedVertexAttributes, offset, _normalizeAttributes2, normalizedFeatureAttributes, enuMatrix, attributeIndex;
153
- return _regenerator.default.wrap(function _callee2$(_context2) {
154
- while (1) switch (_context2.prev = _context2.next) {
155
- case 0:
156
- contentByteLength = arrayBuffer.byteLength;
157
- byteOffset = 0;
158
- featureCount = 0;
159
- if (!tileOptions.isDracoGeometry) {
160
- _context2.next = 16;
161
- break;
162
- }
163
- _context2.next = 6;
164
- return (0, _core.parse)(arrayBuffer, _draco.DracoLoader, {
165
- draco: {
166
- attributeNameEntry: I3S_ATTRIBUTE_TYPE
167
- }
168
- });
169
- case 6:
170
- decompressedGeometry = _context2.sent;
171
- vertexCount = decompressedGeometry.header.vertexCount;
172
- indices = (_decompressedGeometry = decompressedGeometry.indices) === null || _decompressedGeometry === void 0 ? void 0 : _decompressedGeometry.value;
173
- _decompressedGeometry2 = decompressedGeometry.attributes, POSITION = _decompressedGeometry2.POSITION, NORMAL = _decompressedGeometry2.NORMAL, COLOR_0 = _decompressedGeometry2.COLOR_0, TEXCOORD_0 = _decompressedGeometry2.TEXCOORD_0, featureIndex = _decompressedGeometry2['feature-index'], uvRegion = _decompressedGeometry2['uv-region'];
174
- attributes = {
175
- position: POSITION,
176
- normal: NORMAL,
177
- color: COLOR_0,
178
- uv0: TEXCOORD_0,
179
- uvRegion: uvRegion,
180
- id: featureIndex
181
- };
182
- updateAttributesMetadata(attributes, decompressedGeometry);
183
- featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
184
- if (featureIds) {
185
- flattenFeatureIdsByFeatureIndices(attributes, featureIds);
186
- }
187
- _context2.next = 25;
188
- break;
189
- case 16:
190
- _tilesetOptions$store = tilesetOptions.store.defaultGeometrySchema, vertexAttributes = _tilesetOptions$store.vertexAttributes, attributesOrder = _tilesetOptions$store.ordering, featureAttributes = _tilesetOptions$store.featureAttributes, featureAttributeOrder = _tilesetOptions$store.featureAttributeOrder;
191
- headers = parseHeaders(arrayBuffer, tilesetOptions);
192
- byteOffset = headers.byteOffset;
193
- vertexCount = headers.vertexCount;
194
- featureCount = headers.featureCount;
195
- _normalizeAttributes = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder), normalizedVertexAttributes = _normalizeAttributes.attributes, offset = _normalizeAttributes.byteOffset;
196
- _normalizeAttributes2 = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder), normalizedFeatureAttributes = _normalizeAttributes2.attributes;
197
- flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
198
- attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
199
- case 25:
200
- if (!(options !== null && options !== void 0 && (_options$i3s2 = options.i3s) !== null && _options$i3s2 !== void 0 && _options$i3s2.coordinateSystem) || options.i3s.coordinateSystem === _constants.COORDINATE_SYSTEM.METER_OFFSETS) {
201
- enuMatrix = parsePositions(attributes.position, tileOptions);
202
- content.modelMatrix = enuMatrix.invert();
203
- content.coordinateSystem = _constants.COORDINATE_SYSTEM.METER_OFFSETS;
204
- } else {
205
- content.modelMatrix = getModelMatrix(attributes.position);
206
- content.coordinateSystem = _constants.COORDINATE_SYSTEM.LNGLAT_OFFSETS;
207
- }
208
- _context2.next = 28;
209
- return (0, _customizeColors.customizeColors)(attributes.color, attributes.id, tileOptions, tilesetOptions, options);
210
- case 28:
211
- attributes.color = _context2.sent;
212
- content.attributes = {
213
- positions: attributes.position,
214
- normals: attributes.normal,
215
- colors: normalizeAttribute(attributes.color),
216
- texCoords: attributes.uv0,
217
- uvRegions: normalizeAttribute(attributes.uvRegion || attributes.region)
218
- };
219
- content.indices = indices || null;
220
- if (attributes.id && attributes.id.value) {
221
- content.featureIds = attributes.id.value;
222
- }
223
- for (attributeIndex in content.attributes) {
224
- if (!content.attributes[attributeIndex]) {
225
- delete content.attributes[attributeIndex];
226
- }
227
- }
228
- content.vertexCount = vertexCount;
229
- content.byteLength = contentByteLength;
230
- return _context2.abrupt("return", content);
231
- case 36:
232
- case "end":
233
- return _context2.stop();
85
+ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options) {
86
+ var _options$i3s2;
87
+ const contentByteLength = arrayBuffer.byteLength;
88
+ let attributes;
89
+ let vertexCount;
90
+ let byteOffset = 0;
91
+ let featureCount = 0;
92
+ let indices;
93
+ if (tileOptions.isDracoGeometry) {
94
+ var _decompressedGeometry;
95
+ const decompressedGeometry = await (0, _core.parse)(arrayBuffer, _draco.DracoLoader, {
96
+ draco: {
97
+ attributeNameEntry: I3S_ATTRIBUTE_TYPE
234
98
  }
235
- }, _callee2);
236
- }));
237
- return _parseI3SNodeGeometry.apply(this, arguments);
99
+ });
100
+ vertexCount = decompressedGeometry.header.vertexCount;
101
+ indices = (_decompressedGeometry = decompressedGeometry.indices) === null || _decompressedGeometry === void 0 ? void 0 : _decompressedGeometry.value;
102
+ const {
103
+ POSITION,
104
+ NORMAL,
105
+ COLOR_0,
106
+ TEXCOORD_0,
107
+ ['feature-index']: featureIndex,
108
+ ['uv-region']: uvRegion
109
+ } = decompressedGeometry.attributes;
110
+ attributes = {
111
+ position: POSITION,
112
+ normal: NORMAL,
113
+ color: COLOR_0,
114
+ uv0: TEXCOORD_0,
115
+ uvRegion,
116
+ id: featureIndex
117
+ };
118
+ updateAttributesMetadata(attributes, decompressedGeometry);
119
+ const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
120
+ if (featureIds) {
121
+ flattenFeatureIdsByFeatureIndices(attributes, featureIds);
122
+ }
123
+ } else {
124
+ const {
125
+ vertexAttributes,
126
+ ordering: attributesOrder,
127
+ featureAttributes,
128
+ featureAttributeOrder
129
+ } = tilesetOptions.store.defaultGeometrySchema;
130
+ const headers = parseHeaders(arrayBuffer, tilesetOptions);
131
+ byteOffset = headers.byteOffset;
132
+ vertexCount = headers.vertexCount;
133
+ featureCount = headers.featureCount;
134
+ const {
135
+ attributes: normalizedVertexAttributes,
136
+ byteOffset: offset
137
+ } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
138
+ const {
139
+ attributes: normalizedFeatureAttributes
140
+ } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
141
+ flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
142
+ attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
143
+ }
144
+ if (!(options !== null && options !== void 0 && (_options$i3s2 = options.i3s) !== null && _options$i3s2 !== void 0 && _options$i3s2.coordinateSystem) || options.i3s.coordinateSystem === _constants.COORDINATE_SYSTEM.METER_OFFSETS) {
145
+ const enuMatrix = parsePositions(attributes.position, tileOptions);
146
+ content.modelMatrix = enuMatrix.invert();
147
+ content.coordinateSystem = _constants.COORDINATE_SYSTEM.METER_OFFSETS;
148
+ } else {
149
+ content.modelMatrix = getModelMatrix(attributes.position);
150
+ content.coordinateSystem = _constants.COORDINATE_SYSTEM.LNGLAT_OFFSETS;
151
+ }
152
+ attributes.color = await (0, _customizeColors.customizeColors)(attributes.color, attributes.id, tileOptions, tilesetOptions, options);
153
+ content.attributes = {
154
+ positions: attributes.position,
155
+ normals: attributes.normal,
156
+ colors: normalizeAttribute(attributes.color),
157
+ texCoords: attributes.uv0,
158
+ uvRegions: normalizeAttribute(attributes.uvRegion || attributes.region)
159
+ };
160
+ content.indices = indices || null;
161
+ if (attributes.id && attributes.id.value) {
162
+ content.featureIds = attributes.id.value;
163
+ }
164
+ for (const attributeIndex in content.attributes) {
165
+ if (!content.attributes[attributeIndex]) {
166
+ delete content.attributes[attributeIndex];
167
+ }
168
+ }
169
+ content.vertexCount = vertexCount;
170
+ content.byteLength = contentByteLength;
171
+ return content;
238
172
  }
239
173
  function updateAttributesMetadata(attributes, decompressedGeometry) {
240
- for (var key in decompressedGeometry.loaderData.attributes) {
241
- var dracoAttribute = decompressedGeometry.loaderData.attributes[key];
174
+ for (const key in decompressedGeometry.loaderData.attributes) {
175
+ const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
242
176
  switch (dracoAttribute.name) {
243
177
  case 'POSITION':
244
178
  attributes.position.metadata = dracoAttribute.metadata;
@@ -252,7 +186,10 @@ function updateAttributesMetadata(attributes, decompressedGeometry) {
252
186
  }
253
187
  }
254
188
  function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
255
- return _objectSpread(_objectSpread({}, normalizedVertexAttributes), normalizedFeatureAttributes);
189
+ return {
190
+ ...normalizedVertexAttributes,
191
+ ...normalizedFeatureAttributes
192
+ };
256
193
  }
257
194
  function normalizeAttribute(attribute) {
258
195
  if (!attribute) {
@@ -262,153 +199,140 @@ function normalizeAttribute(attribute) {
262
199
  return attribute;
263
200
  }
264
201
  function parseHeaders(arrayBuffer, options) {
265
- var byteOffset = 0;
266
- var vertexCount = 0;
267
- var featureCount = 0;
268
- var _iterator = _createForOfIteratorHelper(options.store.defaultGeometrySchema.header),
269
- _step;
270
- try {
271
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
272
- var _step$value = _step.value,
273
- property = _step$value.property,
274
- type = _step$value.type;
275
- var TypedArrayTypeHeader = (0, _constants.getConstructorForDataFormat)(type);
276
- switch (property) {
277
- case _types.HeaderAttributeProperty.vertexCount:
278
- vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
279
- byteOffset += (0, _constants.sizeOf)(type);
280
- break;
281
- case _types.HeaderAttributeProperty.featureCount:
282
- featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
283
- byteOffset += (0, _constants.sizeOf)(type);
284
- break;
285
- default:
286
- break;
287
- }
202
+ let byteOffset = 0;
203
+ let vertexCount = 0;
204
+ let featureCount = 0;
205
+ for (const {
206
+ property,
207
+ type
208
+ } of options.store.defaultGeometrySchema.header) {
209
+ const TypedArrayTypeHeader = (0, _constants.getConstructorForDataFormat)(type);
210
+ switch (property) {
211
+ case _types.HeaderAttributeProperty.vertexCount:
212
+ vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
213
+ byteOffset += (0, _constants.sizeOf)(type);
214
+ break;
215
+ case _types.HeaderAttributeProperty.featureCount:
216
+ featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
217
+ byteOffset += (0, _constants.sizeOf)(type);
218
+ break;
219
+ default:
220
+ break;
288
221
  }
289
- } catch (err) {
290
- _iterator.e(err);
291
- } finally {
292
- _iterator.f();
293
222
  }
294
223
  return {
295
- vertexCount: vertexCount,
296
- featureCount: featureCount,
297
- byteOffset: byteOffset
224
+ vertexCount,
225
+ featureCount,
226
+ byteOffset
298
227
  };
299
228
  }
300
229
  function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, attributeCount, attributesOrder) {
301
- var attributes = {};
302
- var _iterator2 = _createForOfIteratorHelper(attributesOrder),
303
- _step2;
304
- try {
305
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
306
- var attribute = _step2.value;
307
- if (vertexAttributes[attribute]) {
308
- var _vertexAttributes$att = vertexAttributes[attribute],
309
- valueType = _vertexAttributes$att.valueType,
310
- valuesPerElement = _vertexAttributes$att.valuesPerElement;
311
- if (byteOffset + attributeCount * valuesPerElement * (0, _constants.sizeOf)(valueType) <= arrayBuffer.byteLength) {
312
- var buffer = arrayBuffer.slice(byteOffset);
313
- var value = void 0;
314
- if (valueType === 'UInt64') {
315
- value = parseUint64Values(buffer, attributeCount * valuesPerElement, (0, _constants.sizeOf)(valueType));
316
- } else {
317
- var TypedArrayType = (0, _constants.getConstructorForDataFormat)(valueType);
318
- value = new TypedArrayType(buffer, 0, attributeCount * valuesPerElement);
319
- }
320
- attributes[attribute] = {
321
- value: value,
322
- type: _constants.GL_TYPE_MAP[valueType],
323
- size: valuesPerElement
324
- };
325
- switch (attribute) {
326
- case 'color':
327
- attributes.color.normalized = true;
328
- break;
329
- case 'position':
330
- case 'region':
331
- case 'normal':
332
- default:
333
- }
334
- byteOffset = byteOffset + attributeCount * valuesPerElement * (0, _constants.sizeOf)(valueType);
335
- } else if (attribute !== 'uv0') {
336
- break;
230
+ const attributes = {};
231
+ for (const attribute of attributesOrder) {
232
+ if (vertexAttributes[attribute]) {
233
+ const {
234
+ valueType,
235
+ valuesPerElement
236
+ } = vertexAttributes[attribute];
237
+ if (byteOffset + attributeCount * valuesPerElement * (0, _constants.sizeOf)(valueType) <= arrayBuffer.byteLength) {
238
+ const buffer = arrayBuffer.slice(byteOffset);
239
+ let value;
240
+ if (valueType === 'UInt64') {
241
+ value = parseUint64Values(buffer, attributeCount * valuesPerElement, (0, _constants.sizeOf)(valueType));
242
+ } else {
243
+ const TypedArrayType = (0, _constants.getConstructorForDataFormat)(valueType);
244
+ value = new TypedArrayType(buffer, 0, attributeCount * valuesPerElement);
245
+ }
246
+ attributes[attribute] = {
247
+ value,
248
+ type: _constants.GL_TYPE_MAP[valueType],
249
+ size: valuesPerElement
250
+ };
251
+ switch (attribute) {
252
+ case 'color':
253
+ attributes.color.normalized = true;
254
+ break;
255
+ case 'position':
256
+ case 'region':
257
+ case 'normal':
258
+ default:
337
259
  }
260
+ byteOffset = byteOffset + attributeCount * valuesPerElement * (0, _constants.sizeOf)(valueType);
261
+ } else if (attribute !== 'uv0') {
262
+ break;
338
263
  }
339
264
  }
340
- } catch (err) {
341
- _iterator2.e(err);
342
- } finally {
343
- _iterator2.f();
344
265
  }
345
266
  return {
346
- attributes: attributes,
347
- byteOffset: byteOffset
267
+ attributes,
268
+ byteOffset
348
269
  };
349
270
  }
350
271
  function parseUint64Values(buffer, elementsCount, attributeSize) {
351
- var values = [];
352
- var dataView = new DataView(buffer);
353
- var offset = 0;
354
- for (var index = 0; index < elementsCount; index++) {
355
- var left = dataView.getUint32(offset, true);
356
- var right = dataView.getUint32(offset + 4, true);
357
- var value = left + Math.pow(2, 32) * right;
272
+ const values = [];
273
+ const dataView = new DataView(buffer);
274
+ let offset = 0;
275
+ for (let index = 0; index < elementsCount; index++) {
276
+ const left = dataView.getUint32(offset, true);
277
+ const right = dataView.getUint32(offset + 4, true);
278
+ const value = left + 2 ** 32 * right;
358
279
  values.push(value);
359
280
  offset += attributeSize;
360
281
  }
361
282
  return new Uint32Array(values);
362
283
  }
363
284
  function parsePositions(attribute, options) {
364
- var mbs = options.mbs;
365
- var value = attribute.value;
366
- var metadata = attribute.metadata;
367
- var enuMatrix = new _core2.Matrix4();
368
- var cartographicOrigin = new _core2.Vector3(mbs[0], mbs[1], mbs[2]);
369
- var cartesianOrigin = new _core2.Vector3();
285
+ const mbs = options.mbs;
286
+ const value = attribute.value;
287
+ const metadata = attribute.metadata;
288
+ const enuMatrix = new _core2.Matrix4();
289
+ const cartographicOrigin = new _core2.Vector3(mbs[0], mbs[1], mbs[2]);
290
+ const cartesianOrigin = new _core2.Vector3();
370
291
  _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
371
292
  _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
372
293
  attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
373
294
  return enuMatrix;
374
295
  }
375
296
  function offsetsToCartesians(vertices) {
376
- var metadata = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
377
- var cartographicOrigin = arguments.length > 2 ? arguments[2] : undefined;
378
- var positions = new Float64Array(vertices.length);
379
- var scaleX = metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double || 1;
380
- var scaleY = metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double || 1;
381
- for (var i = 0; i < positions.length; i += 3) {
297
+ let metadata = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
298
+ let cartographicOrigin = arguments.length > 2 ? arguments[2] : undefined;
299
+ const positions = new Float64Array(vertices.length);
300
+ const scaleX = metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double || 1;
301
+ const scaleY = metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double || 1;
302
+ for (let i = 0; i < positions.length; i += 3) {
382
303
  positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
383
304
  positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
384
305
  positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
385
306
  }
386
- for (var _i = 0; _i < positions.length; _i += 3) {
387
- _geospatial.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(_i, _i + 3), scratchVector);
388
- positions[_i] = scratchVector.x;
389
- positions[_i + 1] = scratchVector.y;
390
- positions[_i + 2] = scratchVector.z;
307
+ for (let i = 0; i < positions.length; i += 3) {
308
+ _geospatial.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
309
+ positions[i] = scratchVector.x;
310
+ positions[i + 1] = scratchVector.y;
311
+ positions[i + 2] = scratchVector.z;
391
312
  }
392
313
  return positions;
393
314
  }
394
315
  function getModelMatrix(positions) {
395
316
  var _metadata$i3sScale_x, _metadata$i3sScale_y;
396
- var metadata = positions.metadata;
397
- var scaleX = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_x = metadata['i3s-scale_x']) === null || _metadata$i3sScale_x === void 0 ? void 0 : _metadata$i3sScale_x.double) || 1;
398
- var scaleY = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_y = metadata['i3s-scale_y']) === null || _metadata$i3sScale_y === void 0 ? void 0 : _metadata$i3sScale_y.double) || 1;
399
- var modelMatrix = new _core2.Matrix4();
317
+ const metadata = positions.metadata;
318
+ const scaleX = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_x = metadata['i3s-scale_x']) === null || _metadata$i3sScale_x === void 0 ? void 0 : _metadata$i3sScale_x.double) || 1;
319
+ const scaleY = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_y = metadata['i3s-scale_y']) === null || _metadata$i3sScale_y === void 0 ? void 0 : _metadata$i3sScale_y.double) || 1;
320
+ const modelMatrix = new _core2.Matrix4();
400
321
  modelMatrix[0] = scaleX;
401
322
  modelMatrix[5] = scaleY;
402
323
  return modelMatrix;
403
324
  }
404
325
  function makePbrMaterial(materialDefinition, texture) {
405
- var pbrMaterial;
326
+ let pbrMaterial;
406
327
  if (materialDefinition) {
407
- pbrMaterial = _objectSpread(_objectSpread({}, materialDefinition), {}, {
408
- pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness ? _objectSpread({}, materialDefinition.pbrMetallicRoughness) : {
328
+ pbrMaterial = {
329
+ ...materialDefinition,
330
+ pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness ? {
331
+ ...materialDefinition.pbrMetallicRoughness
332
+ } : {
409
333
  baseColorFactor: [255, 255, 255, 255]
410
334
  }
411
- });
335
+ };
412
336
  } else {
413
337
  pbrMaterial = {
414
338
  pbrMetallicRoughness: {}
@@ -437,58 +361,65 @@ function makePbrMaterial(materialDefinition, texture) {
437
361
  return pbrMaterial;
438
362
  }
439
363
  function convertColorFormat(colorFactor) {
440
- var normalizedColor = (0, _toConsumableArray2.default)(colorFactor);
441
- for (var index = 0; index < colorFactor.length; index++) {
364
+ const normalizedColor = [...colorFactor];
365
+ for (let index = 0; index < colorFactor.length; index++) {
442
366
  normalizedColor[index] = colorFactor[index] / 255;
443
367
  }
444
368
  return normalizedColor;
445
369
  }
446
370
  function setMaterialTexture(material, image) {
447
- var texture = {
371
+ const texture = {
448
372
  source: {
449
- image: image
373
+ image
450
374
  }
451
375
  };
452
376
  if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
453
- material.pbrMetallicRoughness.baseColorTexture = _objectSpread(_objectSpread({}, material.pbrMetallicRoughness.baseColorTexture), {}, {
454
- texture: texture
455
- });
377
+ material.pbrMetallicRoughness.baseColorTexture = {
378
+ ...material.pbrMetallicRoughness.baseColorTexture,
379
+ texture
380
+ };
456
381
  } else if (material.emissiveTexture) {
457
- material.emissiveTexture = _objectSpread(_objectSpread({}, material.emissiveTexture), {}, {
458
- texture: texture
459
- });
382
+ material.emissiveTexture = {
383
+ ...material.emissiveTexture,
384
+ texture
385
+ };
460
386
  } else if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.metallicRoughnessTexture) {
461
- material.pbrMetallicRoughness.metallicRoughnessTexture = _objectSpread(_objectSpread({}, material.pbrMetallicRoughness.metallicRoughnessTexture), {}, {
462
- texture: texture
463
- });
387
+ material.pbrMetallicRoughness.metallicRoughnessTexture = {
388
+ ...material.pbrMetallicRoughness.metallicRoughnessTexture,
389
+ texture
390
+ };
464
391
  } else if (material.normalTexture) {
465
- material.normalTexture = _objectSpread(_objectSpread({}, material.normalTexture), {}, {
466
- texture: texture
467
- });
392
+ material.normalTexture = {
393
+ ...material.normalTexture,
394
+ texture
395
+ };
468
396
  } else if (material.occlusionTexture) {
469
- material.occlusionTexture = _objectSpread(_objectSpread({}, material.occlusionTexture), {}, {
470
- texture: texture
471
- });
397
+ material.occlusionTexture = {
398
+ ...material.occlusionTexture,
399
+ texture
400
+ };
472
401
  }
473
402
  }
474
403
  function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
475
- var id = normalizedFeatureAttributes.id,
476
- faceRange = normalizedFeatureAttributes.faceRange;
404
+ const {
405
+ id,
406
+ faceRange
407
+ } = normalizedFeatureAttributes;
477
408
  if (!id || !faceRange) {
478
409
  return;
479
410
  }
480
- var featureIds = id.value;
481
- var range = faceRange.value;
482
- var featureIdsLength = range[range.length - 1] + 1;
483
- var orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
484
- var featureIndex = 0;
485
- var startIndex = 0;
486
- for (var index = 1; index < range.length; index += 2) {
487
- var fillId = Number(featureIds[featureIndex]);
488
- var endValue = range[index];
489
- var prevValue = range[index - 1];
490
- var trianglesCount = endValue - prevValue + 1;
491
- var endIndex = startIndex + trianglesCount * 3;
411
+ const featureIds = id.value;
412
+ const range = faceRange.value;
413
+ const featureIdsLength = range[range.length - 1] + 1;
414
+ const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
415
+ let featureIndex = 0;
416
+ let startIndex = 0;
417
+ for (let index = 1; index < range.length; index += 2) {
418
+ const fillId = Number(featureIds[featureIndex]);
419
+ const endValue = range[index];
420
+ const prevValue = range[index - 1];
421
+ const trianglesCount = endValue - prevValue + 1;
422
+ const endIndex = startIndex + trianglesCount * 3;
492
423
  orderedFeatureIndices.fill(fillId, startIndex, endIndex);
493
424
  featureIndex++;
494
425
  startIndex = endIndex;
@@ -496,9 +427,9 @@ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
496
427
  normalizedFeatureAttributes.id.value = orderedFeatureIndices;
497
428
  }
498
429
  function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
499
- var featureIndices = attributes.id.value;
500
- var result = new Float32Array(featureIndices.length);
501
- for (var index = 0; index < featureIndices.length; index++) {
430
+ const featureIndices = attributes.id.value;
431
+ const result = new Float32Array(featureIndices.length);
432
+ for (let index = 0; index < featureIndices.length; index++) {
502
433
  result[index] = featureIds[featureIndices[index]];
503
434
  }
504
435
  attributes.id.value = result;