@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.
- package/dist/dist.min.js +124 -111
- package/dist/es5/arcgis-webscene-loader.js +5 -22
- package/dist/es5/arcgis-webscene-loader.js.map +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/i3s-attribute-loader.js +58 -123
- package/dist/es5/i3s-attribute-loader.js.map +1 -1
- package/dist/es5/i3s-building-scene-layer-loader.js +8 -28
- package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
- package/dist/es5/i3s-content-loader.js +16 -35
- package/dist/es5/i3s-content-loader.js.map +1 -1
- package/dist/es5/i3s-loader.js +49 -148
- package/dist/es5/i3s-loader.js.map +1 -1
- package/dist/es5/i3s-node-page-loader.js +8 -39
- package/dist/es5/i3s-node-page-loader.js.map +1 -1
- package/dist/es5/i3s-slpk-loader.js +2 -2
- package/dist/es5/i3s-slpk-loader.js.map +1 -1
- package/dist/es5/index.js +8 -8
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +161 -267
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
- package/dist/es5/lib/parsers/constants.js +6 -6
- package/dist/es5/lib/parsers/constants.js.map +1 -1
- package/dist/es5/lib/parsers/parse-arcgis-webscene.js +64 -146
- package/dist/es5/lib/parsers/parse-arcgis-webscene.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-attribute.js +26 -55
- package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +27 -47
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js +278 -347
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s.js +55 -79
- package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
- package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +30 -81
- package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -1
- package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +44 -90
- package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -1
- package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +17 -17
- package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +1 -1
- package/dist/es5/lib/parsers/parse-zip/local-file-header.js +10 -10
- package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +1 -1
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +4 -6
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
- package/dist/es5/lib/utils/customizeColors.js +79 -140
- package/dist/es5/lib/utils/customizeColors.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js +14 -11
- package/dist/es5/lib/utils/url-utils.js.map +1 -1
- package/dist/es5/types.js +2 -2
- package/dist/esm/arcgis-webscene-loader.js +1 -1
- package/dist/esm/i3s-attribute-loader.js +1 -1
- package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
- package/dist/esm/i3s-content-loader.js +1 -1
- package/dist/esm/i3s-loader.js +1 -1
- package/dist/esm/i3s-node-page-loader.js +1 -1
- package/dist/esm/i3s-slpk-loader.js +1 -1
- package/dist/i3s-content-nodejs-worker.js +61 -59
- package/dist/i3s-content-nodejs-worker.js.map +3 -3
- package/dist/i3s-content-worker.js +69 -81
- 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
|
-
|
|
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
|
-
|
|
42
|
-
function parseI3STileContent(
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
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 (
|
|
241
|
-
|
|
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
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
|
296
|
-
featureCount
|
|
297
|
-
byteOffset
|
|
224
|
+
vertexCount,
|
|
225
|
+
featureCount,
|
|
226
|
+
byteOffset
|
|
298
227
|
};
|
|
299
228
|
}
|
|
300
229
|
function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, attributeCount, attributesOrder) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
|
347
|
-
byteOffset
|
|
267
|
+
attributes,
|
|
268
|
+
byteOffset
|
|
348
269
|
};
|
|
349
270
|
}
|
|
350
271
|
function parseUint64Values(buffer, elementsCount, attributeSize) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
for (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
for (
|
|
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 (
|
|
387
|
-
_geospatial.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(
|
|
388
|
-
positions[
|
|
389
|
-
positions[
|
|
390
|
-
positions[
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
326
|
+
let pbrMaterial;
|
|
406
327
|
if (materialDefinition) {
|
|
407
|
-
pbrMaterial =
|
|
408
|
-
|
|
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
|
-
|
|
441
|
-
for (
|
|
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
|
-
|
|
371
|
+
const texture = {
|
|
448
372
|
source: {
|
|
449
|
-
image
|
|
373
|
+
image
|
|
450
374
|
}
|
|
451
375
|
};
|
|
452
376
|
if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
|
|
453
|
-
material.pbrMetallicRoughness.baseColorTexture =
|
|
454
|
-
|
|
455
|
-
|
|
377
|
+
material.pbrMetallicRoughness.baseColorTexture = {
|
|
378
|
+
...material.pbrMetallicRoughness.baseColorTexture,
|
|
379
|
+
texture
|
|
380
|
+
};
|
|
456
381
|
} else if (material.emissiveTexture) {
|
|
457
|
-
material.emissiveTexture =
|
|
458
|
-
|
|
459
|
-
|
|
382
|
+
material.emissiveTexture = {
|
|
383
|
+
...material.emissiveTexture,
|
|
384
|
+
texture
|
|
385
|
+
};
|
|
460
386
|
} else if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
461
|
-
material.pbrMetallicRoughness.metallicRoughnessTexture =
|
|
462
|
-
|
|
463
|
-
|
|
387
|
+
material.pbrMetallicRoughness.metallicRoughnessTexture = {
|
|
388
|
+
...material.pbrMetallicRoughness.metallicRoughnessTexture,
|
|
389
|
+
texture
|
|
390
|
+
};
|
|
464
391
|
} else if (material.normalTexture) {
|
|
465
|
-
material.normalTexture =
|
|
466
|
-
|
|
467
|
-
|
|
392
|
+
material.normalTexture = {
|
|
393
|
+
...material.normalTexture,
|
|
394
|
+
texture
|
|
395
|
+
};
|
|
468
396
|
} else if (material.occlusionTexture) {
|
|
469
|
-
material.occlusionTexture =
|
|
470
|
-
|
|
471
|
-
|
|
397
|
+
material.occlusionTexture = {
|
|
398
|
+
...material.occlusionTexture,
|
|
399
|
+
texture
|
|
400
|
+
};
|
|
472
401
|
}
|
|
473
402
|
}
|
|
474
403
|
function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
|
|
475
|
-
|
|
476
|
-
|
|
404
|
+
const {
|
|
405
|
+
id,
|
|
406
|
+
faceRange
|
|
407
|
+
} = normalizedFeatureAttributes;
|
|
477
408
|
if (!id || !faceRange) {
|
|
478
409
|
return;
|
|
479
410
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
for (
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
-
|
|
500
|
-
|
|
501
|
-
for (
|
|
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;
|