@loaders.gl/i3s 3.1.3 → 4.0.0-alpha.5
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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/dist.min.js +28 -25
- package/dist/i3s-attribute-loader.js +130 -155
- package/dist/i3s-attribute-loader.js.map +1 -0
- package/dist/i3s-building-scene-layer-loader.js +18 -23
- package/dist/i3s-building-scene-layer-loader.js.map +1 -0
- package/dist/i3s-content-loader.js +22 -25
- package/dist/i3s-content-loader.js.map +1 -0
- package/dist/i3s-content-worker.js +23 -21
- package/dist/i3s-loader.js +81 -84
- package/dist/i3s-loader.js.map +1 -0
- package/dist/i3s-node-page-loader.js +17 -21
- package/dist/i3s-node-page-loader.js.map +1 -0
- package/dist/index.js +6 -14
- package/dist/index.js.map +1 -0
- package/dist/lib/helpers/i3s-nodepages-tiles.js +228 -221
- package/dist/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
- package/dist/lib/parsers/constants.js +63 -85
- package/dist/lib/parsers/constants.js.map +1 -0
- package/dist/lib/parsers/parse-i3s-attribute.js +62 -86
- package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -0
- package/dist/lib/parsers/parse-i3s-building-scene-layer.js +40 -41
- package/dist/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
- package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
- package/dist/lib/parsers/parse-i3s-tile-content.js +458 -441
- package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -0
- package/dist/lib/parsers/parse-i3s.js +88 -86
- package/dist/lib/parsers/parse-i3s.js.map +1 -0
- package/dist/lib/utils/convert-i3s-obb-to-mbs.js +8 -19
- package/dist/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
- package/dist/lib/utils/url-utils.js +28 -41
- package/dist/lib/utils/url-utils.js.map +1 -0
- package/dist/types.d.ts +2 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +19 -18
- package/dist/types.js.map +1 -0
- package/dist/workers/i3s-content-worker.js +4 -5
- package/dist/workers/i3s-content-worker.js.map +1 -0
- package/package.json +12 -12
- package/src/i3s-building-scene-layer-loader.ts +1 -1
- package/src/i3s-content-loader.ts +1 -1
- package/src/lib/parsers/parse-i3s-tile-content.ts +4 -1
- package/src/types.ts +2 -3
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/i3s-attribute-loader.js +0 -249
- package/dist/es5/i3s-attribute-loader.js.map +0 -1
- package/dist/es5/i3s-building-scene-layer-loader.js +0 -58
- package/dist/es5/i3s-building-scene-layer-loader.js.map +0 -1
- package/dist/es5/i3s-content-loader.js +0 -60
- package/dist/es5/i3s-content-loader.js.map +0 -1
- package/dist/es5/i3s-loader.js +0 -233
- package/dist/es5/i3s-loader.js.map +0 -1
- package/dist/es5/i3s-node-page-loader.js +0 -72
- package/dist/es5/i3s-node-page-loader.js.map +0 -1
- package/dist/es5/index.js +0 -52
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +0 -393
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
- package/dist/es5/lib/parsers/constants.js +0 -89
- package/dist/es5/lib/parsers/constants.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s-attribute.js +0 -124
- package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +0 -86
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js +0 -635
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +0 -1
- package/dist/es5/lib/parsers/parse-i3s.js +0 -155
- package/dist/es5/lib/parsers/parse-i3s.js.map +0 -1
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +0 -24
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
- package/dist/es5/lib/utils/url-utils.js +0 -40
- package/dist/es5/lib/utils/url-utils.js.map +0 -1
- package/dist/es5/types.js +0 -29
- package/dist/es5/types.js.map +0 -1
- package/dist/es5/workers/i3s-content-worker.js +0 -8
- package/dist/es5/workers/i3s-content-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/i3s-attribute-loader.js +0 -152
- package/dist/esm/i3s-attribute-loader.js.map +0 -1
- package/dist/esm/i3s-building-scene-layer-loader.js +0 -21
- package/dist/esm/i3s-building-scene-layer-loader.js.map +0 -1
- package/dist/esm/i3s-content-loader.js +0 -25
- package/dist/esm/i3s-content-loader.js.map +0 -1
- package/dist/esm/i3s-loader.js +0 -97
- package/dist/esm/i3s-loader.js.map +0 -1
- package/dist/esm/i3s-node-page-loader.js +0 -22
- package/dist/esm/i3s-node-page-loader.js.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +0 -239
- package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
- package/dist/esm/lib/parsers/constants.js +0 -67
- package/dist/esm/lib/parsers/constants.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s-attribute.js +0 -74
- package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js +0 -45
- package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js +0 -494
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +0 -1
- package/dist/esm/lib/parsers/parse-i3s.js +0 -91
- package/dist/esm/lib/parsers/parse-i3s.js.map +0 -1
- package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js +0 -9
- package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
- package/dist/esm/lib/utils/url-utils.js +0 -31
- package/dist/esm/lib/utils/url-utils.js.map +0 -1
- package/dist/esm/types.js +0 -21
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/workers/i3s-content-worker.js +0 -4
- package/dist/esm/workers/i3s-content-worker.js.map +0 -1
|
@@ -1,482 +1,499 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const constants_1 = require("./constants");
|
|
13
|
-
const scratchVector = new core_2.Vector3([0, 0, 0]);
|
|
1
|
+
import { load, parse } from '@loaders.gl/core';
|
|
2
|
+
import { Vector3, Matrix4 } from '@math.gl/core';
|
|
3
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
4
|
+
import { ImageLoader } from '@loaders.gl/images';
|
|
5
|
+
import { DracoLoader } from '@loaders.gl/draco';
|
|
6
|
+
import { BasisLoader, CompressedTextureLoader } from '@loaders.gl/textures';
|
|
7
|
+
import { HeaderAttributeProperty } from '../../types';
|
|
8
|
+
import { getUrlWithToken } from '../utils/url-utils';
|
|
9
|
+
import { GL_TYPE_MAP, getConstructorForDataFormat, sizeOf, COORDINATE_SYSTEM } from './constants';
|
|
10
|
+
const scratchVector = new Vector3([0, 0, 0]);
|
|
11
|
+
|
|
14
12
|
function getLoaderForTextureFormat(textureFormat) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
switch (textureFormat) {
|
|
14
|
+
case 'ktx-etc2':
|
|
15
|
+
case 'dds':
|
|
16
|
+
return CompressedTextureLoader;
|
|
17
|
+
|
|
18
|
+
case 'ktx2':
|
|
19
|
+
return BasisLoader;
|
|
20
|
+
|
|
21
|
+
case 'jpg':
|
|
22
|
+
case 'png':
|
|
23
|
+
default:
|
|
24
|
+
return ImageLoader;
|
|
25
|
+
}
|
|
26
26
|
}
|
|
27
|
+
|
|
27
28
|
const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
|
|
28
|
-
async function parseI3STileContent(arrayBuffer, tile, tileset, options, context) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const texture = await (0, core_1.load)(arrayBuffer, loader, tile.textureLoaderOptions);
|
|
54
|
-
tile.content.texture = {
|
|
55
|
-
compressed: true,
|
|
56
|
-
mipmaps: false,
|
|
57
|
-
width: texture[0].width,
|
|
58
|
-
height: texture[0].height,
|
|
59
|
-
data: texture
|
|
60
|
-
};
|
|
61
|
-
}
|
|
29
|
+
export async function parseI3STileContent(arrayBuffer, tile, tileset, options, context) {
|
|
30
|
+
tile.content = tile.content || {};
|
|
31
|
+
tile.content.featureIds = tile.content.featureIds || null;
|
|
32
|
+
tile.content.attributes = {};
|
|
33
|
+
|
|
34
|
+
if (tile.textureUrl) {
|
|
35
|
+
var _options$i3s;
|
|
36
|
+
|
|
37
|
+
const url = getUrlWithToken(tile.textureUrl, options === null || options === void 0 ? void 0 : (_options$i3s = options.i3s) === null || _options$i3s === void 0 ? void 0 : _options$i3s.token);
|
|
38
|
+
const loader = getLoaderForTextureFormat(tile.textureFormat);
|
|
39
|
+
const response = await fetch(url);
|
|
40
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
41
|
+
|
|
42
|
+
if (options !== null && options !== void 0 && options.i3s.decodeTextures) {
|
|
43
|
+
if (loader === ImageLoader) {
|
|
44
|
+
const options = { ...tile.textureLoaderOptions,
|
|
45
|
+
image: {
|
|
46
|
+
type: 'data'
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
tile.content.texture = await context.parse(arrayBuffer, options);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
tile.content.texture = await parse(arrayBuffer, loader, options);
|
|
62
54
|
}
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
} else if (loader === CompressedTextureLoader || loader === BasisLoader) {
|
|
56
|
+
let texture = await load(arrayBuffer, loader, tile.textureLoaderOptions);
|
|
57
|
+
|
|
58
|
+
if (loader === BasisLoader) {
|
|
59
|
+
texture = texture[0];
|
|
65
60
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
|
|
62
|
+
tile.content.texture = {
|
|
63
|
+
compressed: true,
|
|
64
|
+
mipmaps: false,
|
|
65
|
+
width: texture[0].width,
|
|
66
|
+
height: texture[0].height,
|
|
67
|
+
data: texture
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
tile.content.texture = arrayBuffer;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
tile.content.material = makePbrMaterial(tile.materialDefinition, tile.content.texture);
|
|
76
|
+
|
|
77
|
+
if (tile.content.material) {
|
|
78
|
+
tile.content.texture = null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return await parseI3SNodeGeometry(arrayBuffer, tile, tileset, options);
|
|
72
82
|
}
|
|
73
|
-
|
|
74
|
-
/* eslint-disable max-statements */
|
|
83
|
+
|
|
75
84
|
async function parseI3SNodeGeometry(arrayBuffer, tile, tileset, options) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const content = tile.content;
|
|
80
|
-
let attributes;
|
|
81
|
-
let vertexCount;
|
|
82
|
-
let byteOffset = 0;
|
|
83
|
-
let featureCount = 0;
|
|
84
|
-
let indices;
|
|
85
|
-
if (tile.isDracoGeometry) {
|
|
86
|
-
const decompressedGeometry = await (0, core_1.parse)(arrayBuffer, draco_1.DracoLoader, {
|
|
87
|
-
draco: {
|
|
88
|
-
attributeNameEntry: I3S_ATTRIBUTE_TYPE
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
// @ts-expect-error
|
|
92
|
-
vertexCount = decompressedGeometry.header.vertexCount;
|
|
93
|
-
indices = decompressedGeometry.indices?.value;
|
|
94
|
-
const { POSITION, NORMAL, COLOR_0, TEXCOORD_0, ['feature-index']: featureIndex, ['uv-region']: uvRegion } = decompressedGeometry.attributes;
|
|
95
|
-
attributes = {
|
|
96
|
-
position: POSITION,
|
|
97
|
-
normal: NORMAL,
|
|
98
|
-
color: COLOR_0,
|
|
99
|
-
uv0: TEXCOORD_0,
|
|
100
|
-
uvRegion,
|
|
101
|
-
id: featureIndex
|
|
102
|
-
};
|
|
103
|
-
updateAttributesMetadata(attributes, decompressedGeometry);
|
|
104
|
-
const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
|
|
105
|
-
if (featureIds) {
|
|
106
|
-
flattenFeatureIdsByFeatureIndices(attributes, featureIds);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
const { vertexAttributes, ordering: attributesOrder, featureAttributes, featureAttributeOrder } = tileset.store.defaultGeometrySchema;
|
|
111
|
-
// First 8 bytes reserved for header (vertexCount and featureCount)
|
|
112
|
-
const headers = parseHeaders(tileset, arrayBuffer);
|
|
113
|
-
byteOffset = headers.byteOffset;
|
|
114
|
-
vertexCount = headers.vertexCount;
|
|
115
|
-
featureCount = headers.featureCount;
|
|
116
|
-
// Getting vertex attributes such as positions, normals, colors, etc...
|
|
117
|
-
const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
|
|
118
|
-
// Getting feature attributes such as featureIds and faceRange
|
|
119
|
-
const { attributes: normalizedFeatureAttributes } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
|
|
120
|
-
flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
|
|
121
|
-
attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
|
|
122
|
-
}
|
|
123
|
-
if (!options?.i3s?.coordinateSystem ||
|
|
124
|
-
options.i3s.coordinateSystem === constants_1.COORDINATE_SYSTEM.METER_OFFSETS) {
|
|
125
|
-
const enuMatrix = parsePositions(attributes.position, tile);
|
|
126
|
-
content.modelMatrix = enuMatrix.invert();
|
|
127
|
-
content.coordinateSystem = constants_1.COORDINATE_SYSTEM.METER_OFFSETS;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
content.modelMatrix = getModelMatrix(attributes.position);
|
|
131
|
-
content.coordinateSystem = constants_1.COORDINATE_SYSTEM.LNGLAT_OFFSETS;
|
|
132
|
-
}
|
|
133
|
-
content.attributes = {
|
|
134
|
-
positions: attributes.position,
|
|
135
|
-
normals: attributes.normal,
|
|
136
|
-
colors: normalizeAttribute(attributes.color),
|
|
137
|
-
texCoords: attributes.uv0,
|
|
138
|
-
uvRegions: normalizeAttribute(attributes.uvRegion) // Normalize from UInt16
|
|
139
|
-
};
|
|
140
|
-
content.indices = indices || null;
|
|
141
|
-
if (attributes.id && attributes.id.value) {
|
|
142
|
-
tile.content.featureIds = attributes.id.value;
|
|
143
|
-
}
|
|
144
|
-
// Remove undefined attributes
|
|
145
|
-
for (const attributeIndex in content.attributes) {
|
|
146
|
-
if (!content.attributes[attributeIndex]) {
|
|
147
|
-
delete content.attributes[attributeIndex];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
content.vertexCount = vertexCount;
|
|
151
|
-
content.byteLength = arrayBuffer.byteLength;
|
|
85
|
+
var _options$i3s2;
|
|
86
|
+
|
|
87
|
+
if (!tile.content) {
|
|
152
88
|
return tile;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const content = tile.content;
|
|
92
|
+
let attributes;
|
|
93
|
+
let vertexCount;
|
|
94
|
+
let byteOffset = 0;
|
|
95
|
+
let featureCount = 0;
|
|
96
|
+
let indices;
|
|
97
|
+
|
|
98
|
+
if (tile.isDracoGeometry) {
|
|
99
|
+
var _decompressedGeometry;
|
|
100
|
+
|
|
101
|
+
const decompressedGeometry = await parse(arrayBuffer, DracoLoader, {
|
|
102
|
+
draco: {
|
|
103
|
+
attributeNameEntry: I3S_ATTRIBUTE_TYPE
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
vertexCount = decompressedGeometry.header.vertexCount;
|
|
107
|
+
indices = (_decompressedGeometry = decompressedGeometry.indices) === null || _decompressedGeometry === void 0 ? void 0 : _decompressedGeometry.value;
|
|
108
|
+
const {
|
|
109
|
+
POSITION,
|
|
110
|
+
NORMAL,
|
|
111
|
+
COLOR_0,
|
|
112
|
+
TEXCOORD_0,
|
|
113
|
+
['feature-index']: featureIndex,
|
|
114
|
+
['uv-region']: uvRegion
|
|
115
|
+
} = decompressedGeometry.attributes;
|
|
116
|
+
attributes = {
|
|
117
|
+
position: POSITION,
|
|
118
|
+
normal: NORMAL,
|
|
119
|
+
color: COLOR_0,
|
|
120
|
+
uv0: TEXCOORD_0,
|
|
121
|
+
uvRegion,
|
|
122
|
+
id: featureIndex
|
|
123
|
+
};
|
|
124
|
+
updateAttributesMetadata(attributes, decompressedGeometry);
|
|
125
|
+
const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
|
|
126
|
+
|
|
127
|
+
if (featureIds) {
|
|
128
|
+
flattenFeatureIdsByFeatureIndices(attributes, featureIds);
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
const {
|
|
132
|
+
vertexAttributes,
|
|
133
|
+
ordering: attributesOrder,
|
|
134
|
+
featureAttributes,
|
|
135
|
+
featureAttributeOrder
|
|
136
|
+
} = tileset.store.defaultGeometrySchema;
|
|
137
|
+
const headers = parseHeaders(tileset, arrayBuffer);
|
|
138
|
+
byteOffset = headers.byteOffset;
|
|
139
|
+
vertexCount = headers.vertexCount;
|
|
140
|
+
featureCount = headers.featureCount;
|
|
141
|
+
const {
|
|
142
|
+
attributes: normalizedVertexAttributes,
|
|
143
|
+
byteOffset: offset
|
|
144
|
+
} = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
|
|
145
|
+
const {
|
|
146
|
+
attributes: normalizedFeatureAttributes
|
|
147
|
+
} = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
|
|
148
|
+
flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
|
|
149
|
+
attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!(options !== null && options !== void 0 && (_options$i3s2 = options.i3s) !== null && _options$i3s2 !== void 0 && _options$i3s2.coordinateSystem) || options.i3s.coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS) {
|
|
153
|
+
const enuMatrix = parsePositions(attributes.position, tile);
|
|
154
|
+
content.modelMatrix = enuMatrix.invert();
|
|
155
|
+
content.coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS;
|
|
156
|
+
} else {
|
|
157
|
+
content.modelMatrix = getModelMatrix(attributes.position);
|
|
158
|
+
content.coordinateSystem = COORDINATE_SYSTEM.LNGLAT_OFFSETS;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
content.attributes = {
|
|
162
|
+
positions: attributes.position,
|
|
163
|
+
normals: attributes.normal,
|
|
164
|
+
colors: normalizeAttribute(attributes.color),
|
|
165
|
+
texCoords: attributes.uv0,
|
|
166
|
+
uvRegions: normalizeAttribute(attributes.uvRegion)
|
|
167
|
+
};
|
|
168
|
+
content.indices = indices || null;
|
|
169
|
+
|
|
170
|
+
if (attributes.id && attributes.id.value) {
|
|
171
|
+
tile.content.featureIds = attributes.id.value;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (const attributeIndex in content.attributes) {
|
|
175
|
+
if (!content.attributes[attributeIndex]) {
|
|
176
|
+
delete content.attributes[attributeIndex];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
content.vertexCount = vertexCount;
|
|
181
|
+
content.byteLength = arrayBuffer.byteLength;
|
|
182
|
+
return tile;
|
|
153
183
|
}
|
|
154
|
-
|
|
155
|
-
* Update attributes with metadata from decompressed geometry.
|
|
156
|
-
* @param decompressedGeometry
|
|
157
|
-
* @param attributes
|
|
158
|
-
*/
|
|
184
|
+
|
|
159
185
|
function updateAttributesMetadata(attributes, decompressedGeometry) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
186
|
+
for (const key in decompressedGeometry.loaderData.attributes) {
|
|
187
|
+
const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
|
|
188
|
+
|
|
189
|
+
switch (dracoAttribute.name) {
|
|
190
|
+
case 'POSITION':
|
|
191
|
+
attributes.position.metadata = dracoAttribute.metadata;
|
|
192
|
+
break;
|
|
193
|
+
|
|
194
|
+
case 'feature-index':
|
|
195
|
+
attributes.id.metadata = dracoAttribute.metadata;
|
|
196
|
+
break;
|
|
197
|
+
|
|
198
|
+
default:
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
173
202
|
}
|
|
174
|
-
|
|
175
|
-
* Do concatenation of attribute objects.
|
|
176
|
-
* Done as separate fucntion to avoid ts errors.
|
|
177
|
-
* @param normalizedVertexAttributes
|
|
178
|
-
* @param normalizedFeatureAttributes
|
|
179
|
-
* @returns - result of attributes concatenation.
|
|
180
|
-
*/
|
|
203
|
+
|
|
181
204
|
function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
|
|
182
|
-
|
|
205
|
+
return { ...normalizedVertexAttributes,
|
|
206
|
+
...normalizedFeatureAttributes
|
|
207
|
+
};
|
|
183
208
|
}
|
|
184
|
-
|
|
185
|
-
* Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
|
|
186
|
-
* @param attribute - geometry attribute
|
|
187
|
-
* @returns - geometry attribute in right format
|
|
188
|
-
*/
|
|
209
|
+
|
|
189
210
|
function normalizeAttribute(attribute) {
|
|
190
|
-
|
|
191
|
-
return attribute;
|
|
192
|
-
}
|
|
193
|
-
attribute.normalized = true;
|
|
211
|
+
if (!attribute) {
|
|
194
212
|
return attribute;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
attribute.normalized = true;
|
|
216
|
+
return attribute;
|
|
195
217
|
}
|
|
218
|
+
|
|
196
219
|
function parseHeaders(tileset, arrayBuffer) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
220
|
+
let byteOffset = 0;
|
|
221
|
+
let vertexCount = 0;
|
|
222
|
+
let featureCount = 0;
|
|
223
|
+
|
|
224
|
+
for (const {
|
|
225
|
+
property,
|
|
226
|
+
type
|
|
227
|
+
} of tileset.store.defaultGeometrySchema.header) {
|
|
228
|
+
const TypedArrayTypeHeader = getConstructorForDataFormat(type);
|
|
229
|
+
|
|
230
|
+
switch (property) {
|
|
231
|
+
case HeaderAttributeProperty.vertexCount:
|
|
232
|
+
vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
|
|
233
|
+
byteOffset += sizeOf(type);
|
|
234
|
+
break;
|
|
235
|
+
|
|
236
|
+
case HeaderAttributeProperty.featureCount:
|
|
237
|
+
featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
|
|
238
|
+
byteOffset += sizeOf(type);
|
|
239
|
+
break;
|
|
240
|
+
|
|
241
|
+
default:
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
vertexCount,
|
|
248
|
+
featureCount,
|
|
249
|
+
byteOffset
|
|
250
|
+
};
|
|
221
251
|
}
|
|
222
|
-
|
|
252
|
+
|
|
223
253
|
function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
254
|
+
const attributes = {};
|
|
255
|
+
|
|
256
|
+
for (const attribute of attributesOrder) {
|
|
257
|
+
if (vertexAttributes[attribute]) {
|
|
258
|
+
const {
|
|
259
|
+
valueType,
|
|
260
|
+
valuesPerElement
|
|
261
|
+
} = vertexAttributes[attribute];
|
|
262
|
+
const count = vertexCount;
|
|
263
|
+
|
|
264
|
+
if (byteOffset + count * valuesPerElement > arrayBuffer.byteLength) {
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const buffer = arrayBuffer.slice(byteOffset);
|
|
269
|
+
let value;
|
|
270
|
+
|
|
271
|
+
if (valueType === 'UInt64') {
|
|
272
|
+
value = parseUint64Values(buffer, count * valuesPerElement, sizeOf(valueType));
|
|
273
|
+
} else {
|
|
274
|
+
const TypedArrayType = getConstructorForDataFormat(valueType);
|
|
275
|
+
value = new TypedArrayType(buffer, 0, count * valuesPerElement);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
attributes[attribute] = {
|
|
279
|
+
value,
|
|
280
|
+
type: GL_TYPE_MAP[valueType],
|
|
281
|
+
size: valuesPerElement
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
switch (attribute) {
|
|
285
|
+
case 'color':
|
|
286
|
+
attributes.color.normalized = true;
|
|
287
|
+
break;
|
|
288
|
+
|
|
289
|
+
case 'position':
|
|
290
|
+
case 'region':
|
|
291
|
+
case 'normal':
|
|
292
|
+
default:
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
byteOffset = byteOffset + count * valuesPerElement * sizeOf(valueType);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
attributes,
|
|
301
|
+
byteOffset
|
|
302
|
+
};
|
|
267
303
|
}
|
|
268
|
-
|
|
269
|
-
* Parse buffer to return array of uint64 values
|
|
270
|
-
*
|
|
271
|
-
* @param buffer
|
|
272
|
-
* @param elementsCount
|
|
273
|
-
* @returns 64-bit array of values until precision is lost after Number.MAX_SAFE_INTEGER
|
|
274
|
-
*/
|
|
304
|
+
|
|
275
305
|
function parseUint64Values(buffer, elementsCount, attributeSize) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
306
|
+
const values = [];
|
|
307
|
+
const dataView = new DataView(buffer);
|
|
308
|
+
let offset = 0;
|
|
309
|
+
|
|
310
|
+
for (let index = 0; index < elementsCount; index++) {
|
|
311
|
+
const left = dataView.getUint32(offset, true);
|
|
312
|
+
const right = dataView.getUint32(offset + 4, true);
|
|
313
|
+
const value = left + 2 ** 32 * right;
|
|
314
|
+
values.push(value);
|
|
315
|
+
offset += attributeSize;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return new Uint32Array(values);
|
|
289
319
|
}
|
|
320
|
+
|
|
290
321
|
function parsePositions(attribute, tile) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
322
|
+
const mbs = tile.mbs;
|
|
323
|
+
const value = attribute.value;
|
|
324
|
+
const metadata = attribute.metadata;
|
|
325
|
+
const enuMatrix = new Matrix4();
|
|
326
|
+
const cartographicOrigin = new Vector3(mbs[0], mbs[1], mbs[2]);
|
|
327
|
+
const cartesianOrigin = new Vector3();
|
|
328
|
+
Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
|
|
329
|
+
Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
|
|
330
|
+
attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
|
|
331
|
+
return enuMatrix;
|
|
301
332
|
}
|
|
302
|
-
|
|
303
|
-
* Converts position coordinates to absolute cartesian coordinates
|
|
304
|
-
* @param vertices - "position" attribute data
|
|
305
|
-
* @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
|
|
306
|
-
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
|
|
307
|
-
* @param cartographicOrigin - Cartographic origin coordinates
|
|
308
|
-
* @returns - converted "position" data
|
|
309
|
-
*/
|
|
333
|
+
|
|
310
334
|
function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
335
|
+
const positions = new Float64Array(vertices.length);
|
|
336
|
+
const scaleX = metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double || 1;
|
|
337
|
+
const scaleY = metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double || 1;
|
|
338
|
+
|
|
339
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
340
|
+
positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
|
|
341
|
+
positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
|
|
342
|
+
positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
346
|
+
Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
|
|
347
|
+
positions[i] = scratchVector.x;
|
|
348
|
+
positions[i + 1] = scratchVector.y;
|
|
349
|
+
positions[i + 2] = scratchVector.z;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return positions;
|
|
327
353
|
}
|
|
328
|
-
|
|
329
|
-
* Get model matrix for loaded vertices
|
|
330
|
-
* @param positions positions attribute
|
|
331
|
-
* @returns Matrix4 - model matrix for geometry transformation
|
|
332
|
-
*/
|
|
354
|
+
|
|
333
355
|
function getModelMatrix(positions) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
356
|
+
var _metadata$i3sScale_x, _metadata$i3sScale_y;
|
|
357
|
+
|
|
358
|
+
const metadata = positions.metadata;
|
|
359
|
+
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;
|
|
360
|
+
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;
|
|
361
|
+
const modelMatrix = new Matrix4();
|
|
362
|
+
modelMatrix[0] = scaleX;
|
|
363
|
+
modelMatrix[5] = scaleY;
|
|
364
|
+
return modelMatrix;
|
|
341
365
|
}
|
|
342
|
-
|
|
343
|
-
* Makes a glTF-compatible PBR material from an I3S material definition
|
|
344
|
-
* @param materialDefinition - i3s material definition
|
|
345
|
-
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
|
|
346
|
-
* @param texture - texture image
|
|
347
|
-
* @returns {object}
|
|
348
|
-
*/
|
|
366
|
+
|
|
349
367
|
function makePbrMaterial(materialDefinition, texture) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
pbrMaterial.pbrMetallicRoughness.baseColorTexture = { texCoord: 0 };
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
// Set default 0.25 per spec https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
|
|
371
|
-
pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
|
|
372
|
-
if (pbrMaterial.alphaMode) {
|
|
373
|
-
// I3S contain alphaMode in lowerCase
|
|
374
|
-
pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
|
|
375
|
-
}
|
|
376
|
-
// Convert colors from [255,255,255,255] to [1,1,1,1]
|
|
377
|
-
if (pbrMaterial.emissiveFactor) {
|
|
378
|
-
pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
|
|
379
|
-
}
|
|
380
|
-
if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
|
|
381
|
-
pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
|
|
382
|
-
}
|
|
368
|
+
let pbrMaterial;
|
|
369
|
+
|
|
370
|
+
if (materialDefinition) {
|
|
371
|
+
pbrMaterial = { ...materialDefinition,
|
|
372
|
+
pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness ? { ...materialDefinition.pbrMetallicRoughness
|
|
373
|
+
} : {
|
|
374
|
+
baseColorFactor: [255, 255, 255, 255]
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
} else {
|
|
378
|
+
pbrMaterial = {
|
|
379
|
+
pbrMetallicRoughness: {}
|
|
380
|
+
};
|
|
381
|
+
|
|
383
382
|
if (texture) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
383
|
+
pbrMaterial.pbrMetallicRoughness.baseColorTexture = {
|
|
384
|
+
texCoord: 0
|
|
385
|
+
};
|
|
386
|
+
} else {
|
|
387
|
+
pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
|
|
392
|
+
|
|
393
|
+
if (pbrMaterial.alphaMode) {
|
|
394
|
+
pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (pbrMaterial.emissiveFactor) {
|
|
398
|
+
pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
|
|
402
|
+
pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (texture) {
|
|
406
|
+
setMaterialTexture(pbrMaterial, texture);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return pbrMaterial;
|
|
387
410
|
}
|
|
388
|
-
|
|
389
|
-
* Convert color from [255,255,255,255] to [1,1,1,1]
|
|
390
|
-
* @param colorFactor - color array
|
|
391
|
-
* @returns - new color array
|
|
392
|
-
*/
|
|
411
|
+
|
|
393
412
|
function convertColorFormat(colorFactor) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
413
|
+
const normalizedColor = [...colorFactor];
|
|
414
|
+
|
|
415
|
+
for (let index = 0; index < colorFactor.length; index++) {
|
|
416
|
+
normalizedColor[index] = colorFactor[index] / 255;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return normalizedColor;
|
|
399
420
|
}
|
|
400
|
-
|
|
401
|
-
* Set texture in PBR material
|
|
402
|
-
* @param {object} material - i3s material definition
|
|
403
|
-
* @param image - texture image
|
|
404
|
-
* @returns
|
|
405
|
-
*/
|
|
421
|
+
|
|
406
422
|
function setMaterialTexture(material, image) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
423
|
+
const texture = {
|
|
424
|
+
source: {
|
|
425
|
+
image
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
|
|
430
|
+
material.pbrMetallicRoughness.baseColorTexture = { ...material.pbrMetallicRoughness.baseColorTexture,
|
|
431
|
+
texture
|
|
432
|
+
};
|
|
433
|
+
} else if (material.emissiveTexture) {
|
|
434
|
+
material.emissiveTexture = { ...material.emissiveTexture,
|
|
435
|
+
texture
|
|
436
|
+
};
|
|
437
|
+
} else if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
438
|
+
material.pbrMetallicRoughness.metallicRoughnessTexture = { ...material.pbrMetallicRoughness.metallicRoughnessTexture,
|
|
439
|
+
texture
|
|
440
|
+
};
|
|
441
|
+
} else if (material.normalTexture) {
|
|
442
|
+
material.normalTexture = { ...material.normalTexture,
|
|
443
|
+
texture
|
|
444
|
+
};
|
|
445
|
+
} else if (material.occlusionTexture) {
|
|
446
|
+
material.occlusionTexture = { ...material.occlusionTexture,
|
|
447
|
+
texture
|
|
448
|
+
};
|
|
449
|
+
}
|
|
432
450
|
}
|
|
433
|
-
|
|
434
|
-
* Flatten feature ids using face ranges
|
|
435
|
-
* @param normalizedFeatureAttributes
|
|
436
|
-
* @returns
|
|
437
|
-
*/
|
|
451
|
+
|
|
438
452
|
function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
453
|
+
const {
|
|
454
|
+
id,
|
|
455
|
+
faceRange
|
|
456
|
+
} = normalizedFeatureAttributes;
|
|
457
|
+
|
|
458
|
+
if (!id || !faceRange) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const featureIds = id.value;
|
|
463
|
+
const range = faceRange.value;
|
|
464
|
+
const featureIdsLength = range[range.length - 1] + 1;
|
|
465
|
+
const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
|
|
466
|
+
let featureIndex = 0;
|
|
467
|
+
let startIndex = 0;
|
|
468
|
+
|
|
469
|
+
for (let index = 1; index < range.length; index += 2) {
|
|
470
|
+
const fillId = Number(featureIds[featureIndex]);
|
|
471
|
+
const endValue = range[index];
|
|
472
|
+
const prevValue = range[index - 1];
|
|
473
|
+
const trianglesCount = endValue - prevValue + 1;
|
|
474
|
+
const endIndex = startIndex + trianglesCount * 3;
|
|
475
|
+
orderedFeatureIndices.fill(fillId, startIndex, endIndex);
|
|
476
|
+
featureIndex++;
|
|
477
|
+
startIndex = endIndex;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
normalizedFeatureAttributes.id.value = orderedFeatureIndices;
|
|
460
481
|
}
|
|
461
|
-
|
|
462
|
-
* Flatten feature ids using featureIndices
|
|
463
|
-
* @param attributes
|
|
464
|
-
* @param featureIds
|
|
465
|
-
* @returns
|
|
466
|
-
*/
|
|
482
|
+
|
|
467
483
|
function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
484
|
+
const featureIndices = attributes.id.value;
|
|
485
|
+
const result = new Float32Array(featureIndices.length);
|
|
486
|
+
|
|
487
|
+
for (let index = 0; index < featureIndices.length; index++) {
|
|
488
|
+
result[index] = featureIds[featureIndices[index]];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
attributes.id.value = result;
|
|
474
492
|
}
|
|
475
|
-
|
|
476
|
-
* Flatten feature ids using featureIndices
|
|
477
|
-
* @param featureIndex
|
|
478
|
-
* @returns
|
|
479
|
-
*/
|
|
493
|
+
|
|
480
494
|
function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
|
|
481
|
-
|
|
495
|
+
var _featureIndex$metadat, _featureIndex$metadat2;
|
|
496
|
+
|
|
497
|
+
return featureIndex === null || featureIndex === void 0 ? void 0 : (_featureIndex$metadat = featureIndex.metadata) === null || _featureIndex$metadat === void 0 ? void 0 : (_featureIndex$metadat2 = _featureIndex$metadat['i3s-feature-ids']) === null || _featureIndex$metadat2 === void 0 ? void 0 : _featureIndex$metadat2.intArray;
|
|
482
498
|
}
|
|
499
|
+
//# sourceMappingURL=parse-i3s-tile-content.js.map
|