@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,232 +1,239 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { load } from '@loaders.gl/core';
|
|
3
|
+
import { getSupportedGPUTextureFormats, selectSupportedBasisFormat } from '@loaders.gl/textures';
|
|
4
|
+
import { I3SNodePageLoader } from '../../i3s-node-page-loader';
|
|
5
|
+
import { normalizeTileNonUrlData } from '../parsers/parse-i3s';
|
|
6
|
+
import { getUrlWithToken, generateTilesetAttributeUrls } from '../utils/url-utils';
|
|
7
|
+
export default class I3SNodePagesTiles {
|
|
8
|
+
constructor(tileset, options) {
|
|
9
|
+
var _tileset$nodePages, _tileset$nodePages2;
|
|
10
|
+
|
|
11
|
+
_defineProperty(this, "tileset", void 0);
|
|
12
|
+
|
|
13
|
+
_defineProperty(this, "nodePages", []);
|
|
14
|
+
|
|
15
|
+
_defineProperty(this, "pendingNodePages", []);
|
|
16
|
+
|
|
17
|
+
_defineProperty(this, "nodesPerPage", void 0);
|
|
18
|
+
|
|
19
|
+
_defineProperty(this, "options", void 0);
|
|
20
|
+
|
|
21
|
+
_defineProperty(this, "lodSelectionMetricType", void 0);
|
|
22
|
+
|
|
23
|
+
_defineProperty(this, "textureDefinitionsSelectedFormats", []);
|
|
24
|
+
|
|
25
|
+
_defineProperty(this, "textureLoaderOptions", {});
|
|
26
|
+
|
|
27
|
+
this.tileset = { ...tileset
|
|
28
|
+
};
|
|
29
|
+
this.nodesPerPage = ((_tileset$nodePages = tileset.nodePages) === null || _tileset$nodePages === void 0 ? void 0 : _tileset$nodePages.nodesPerPage) || 64;
|
|
30
|
+
this.lodSelectionMetricType = (_tileset$nodePages2 = tileset.nodePages) === null || _tileset$nodePages2 === void 0 ? void 0 : _tileset$nodePages2.lodSelectionMetricType;
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.initSelectedFormatsForTextureDefinitions(tileset);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async getNodeById(id) {
|
|
36
|
+
const pageIndex = Math.floor(id / this.nodesPerPage);
|
|
37
|
+
|
|
38
|
+
if (!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex]) {
|
|
39
|
+
var _this$options$i3s;
|
|
40
|
+
|
|
41
|
+
const nodePageUrl = getUrlWithToken("".concat(this.tileset.url, "/nodepages/").concat(pageIndex), (_this$options$i3s = this.options.i3s) === null || _this$options$i3s === void 0 ? void 0 : _this$options$i3s.token);
|
|
42
|
+
this.pendingNodePages[pageIndex] = {
|
|
43
|
+
status: 'Pending',
|
|
44
|
+
promise: load(nodePageUrl, I3SNodePageLoader, this.options)
|
|
45
|
+
};
|
|
46
|
+
this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
|
|
47
|
+
this.pendingNodePages[pageIndex].status = 'Done';
|
|
28
48
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
async getNodeById(id) {
|
|
34
|
-
const pageIndex = Math.floor(id / this.nodesPerPage);
|
|
35
|
-
if (!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex]) {
|
|
36
|
-
const nodePageUrl = (0, url_utils_1.getUrlWithToken)(`${this.tileset.url}/nodepages/${pageIndex}`, this.options.i3s?.token);
|
|
37
|
-
this.pendingNodePages[pageIndex] = {
|
|
38
|
-
status: 'Pending',
|
|
39
|
-
promise: (0, core_1.load)(nodePageUrl, i3s_node_page_loader_1.I3SNodePageLoader, this.options)
|
|
40
|
-
};
|
|
41
|
-
this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
|
|
42
|
-
this.pendingNodePages[pageIndex].status = 'Done';
|
|
43
|
-
}
|
|
44
|
-
if (this.pendingNodePages[pageIndex].status === 'Pending') {
|
|
45
|
-
this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
|
|
46
|
-
}
|
|
47
|
-
const nodeIndex = id % this.nodesPerPage;
|
|
48
|
-
return this.nodePages[pageIndex].nodes[nodeIndex];
|
|
49
|
+
|
|
50
|
+
if (this.pendingNodePages[pageIndex].status === 'Pending') {
|
|
51
|
+
this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
|
|
49
52
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
let contentUrl;
|
|
66
|
-
let textureUrl;
|
|
67
|
-
let materialDefinition;
|
|
68
|
-
let textureFormat = 'jpg';
|
|
69
|
-
let attributeUrls = [];
|
|
70
|
-
let isDracoGeometry = false;
|
|
71
|
-
if (node && node.mesh) {
|
|
72
|
-
// Get geometry resource URL and type (compressed / non-compressed)
|
|
73
|
-
const { url, isDracoGeometry: isDracoGeometryResult } = (node.mesh.geometry &&
|
|
74
|
-
this.getContentUrl(node.mesh.geometry)) || { isDracoGeometry: false };
|
|
75
|
-
contentUrl = url;
|
|
76
|
-
isDracoGeometry = isDracoGeometryResult;
|
|
77
|
-
const { textureData, materialDefinition: nodeMaterialDefinition } = this.getInformationFromMaterial(node.mesh.material);
|
|
78
|
-
materialDefinition = nodeMaterialDefinition;
|
|
79
|
-
textureFormat = textureData.format || textureFormat;
|
|
80
|
-
if (textureData.name) {
|
|
81
|
-
textureUrl = `${this.tileset.url}/nodes/${node.mesh.material.resource}/textures/${textureData.name}`;
|
|
82
|
-
}
|
|
83
|
-
if (this.tileset.attributeStorageInfo) {
|
|
84
|
-
attributeUrls = (0, url_utils_1.generateTilesetAttributeUrls)(this.tileset, node.mesh.attribute.resource);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const lodSelection = this.getLodSelection(node);
|
|
88
|
-
return (0, parse_i3s_1.normalizeTileNonUrlData)({
|
|
89
|
-
id: id.toString(),
|
|
90
|
-
lodSelection,
|
|
91
|
-
obb: node.obb,
|
|
92
|
-
contentUrl,
|
|
93
|
-
textureUrl,
|
|
94
|
-
attributeUrls,
|
|
95
|
-
materialDefinition,
|
|
96
|
-
textureFormat,
|
|
97
|
-
textureLoaderOptions: this.textureLoaderOptions,
|
|
98
|
-
children,
|
|
99
|
-
isDracoGeometry
|
|
100
|
-
});
|
|
53
|
+
|
|
54
|
+
const nodeIndex = id % this.nodesPerPage;
|
|
55
|
+
return this.nodePages[pageIndex].nodes[nodeIndex];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async formTileFromNodePages(id) {
|
|
59
|
+
const node = await this.getNodeById(id);
|
|
60
|
+
const children = [];
|
|
61
|
+
|
|
62
|
+
for (const child of node.children || []) {
|
|
63
|
+
const childNode = await this.getNodeById(child);
|
|
64
|
+
children.push({
|
|
65
|
+
id: child.toString(),
|
|
66
|
+
obb: childNode.obb
|
|
67
|
+
});
|
|
101
68
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
69
|
+
|
|
70
|
+
let contentUrl;
|
|
71
|
+
let textureUrl;
|
|
72
|
+
let materialDefinition;
|
|
73
|
+
let textureFormat = 'jpg';
|
|
74
|
+
let attributeUrls = [];
|
|
75
|
+
let isDracoGeometry = false;
|
|
76
|
+
|
|
77
|
+
if (node && node.mesh) {
|
|
78
|
+
const {
|
|
79
|
+
url,
|
|
80
|
+
isDracoGeometry: isDracoGeometryResult
|
|
81
|
+
} = node.mesh.geometry && this.getContentUrl(node.mesh.geometry) || {
|
|
82
|
+
isDracoGeometry: false
|
|
83
|
+
};
|
|
84
|
+
contentUrl = url;
|
|
85
|
+
isDracoGeometry = isDracoGeometryResult;
|
|
86
|
+
const {
|
|
87
|
+
textureData,
|
|
88
|
+
materialDefinition: nodeMaterialDefinition
|
|
89
|
+
} = this.getInformationFromMaterial(node.mesh.material);
|
|
90
|
+
materialDefinition = nodeMaterialDefinition;
|
|
91
|
+
textureFormat = textureData.format || textureFormat;
|
|
92
|
+
|
|
93
|
+
if (textureData.name) {
|
|
94
|
+
textureUrl = "".concat(this.tileset.url, "/nodes/").concat(node.mesh.material.resource, "/textures/").concat(textureData.name);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (this.tileset.attributeStorageInfo) {
|
|
98
|
+
attributeUrls = generateTilesetAttributeUrls(this.tileset, node.mesh.attribute.resource);
|
|
99
|
+
}
|
|
130
100
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
101
|
+
|
|
102
|
+
const lodSelection = this.getLodSelection(node);
|
|
103
|
+
return normalizeTileNonUrlData({
|
|
104
|
+
id: id.toString(),
|
|
105
|
+
lodSelection,
|
|
106
|
+
obb: node.obb,
|
|
107
|
+
contentUrl,
|
|
108
|
+
textureUrl,
|
|
109
|
+
attributeUrls,
|
|
110
|
+
materialDefinition,
|
|
111
|
+
textureFormat,
|
|
112
|
+
textureLoaderOptions: this.textureLoaderOptions,
|
|
113
|
+
children,
|
|
114
|
+
isDracoGeometry
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
getContentUrl(meshGeometryData) {
|
|
119
|
+
let result = null;
|
|
120
|
+
const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];
|
|
121
|
+
let geometryIndex = -1;
|
|
122
|
+
|
|
123
|
+
if (this.options.i3s && this.options.i3s.useDracoGeometry) {
|
|
124
|
+
geometryIndex = geometryDefinition.geometryBuffers.findIndex(buffer => buffer.compressedAttributes && buffer.compressedAttributes.encoding === 'draco');
|
|
151
125
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* @returns - Couple {textureData, materialDefinition}
|
|
156
|
-
* {string} textureData.name - path name of the texture
|
|
157
|
-
* {string} textureData.format - format of the texture
|
|
158
|
-
* materialDefinition - PBR-like material definition from `materialDefinitions`
|
|
159
|
-
*/
|
|
160
|
-
getInformationFromMaterial(material) {
|
|
161
|
-
const informationFromMaterial = { textureData: { name: null } };
|
|
162
|
-
if (material) {
|
|
163
|
-
const materialDefinition = this.tileset.materialDefinitions?.[material.definition];
|
|
164
|
-
if (materialDefinition) {
|
|
165
|
-
informationFromMaterial.materialDefinition = materialDefinition;
|
|
166
|
-
const textureSetDefinitionIndex = materialDefinition?.pbrMetallicRoughness?.baseColorTexture?.textureSetDefinitionId;
|
|
167
|
-
if (typeof textureSetDefinitionIndex === 'number') {
|
|
168
|
-
informationFromMaterial.textureData =
|
|
169
|
-
this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] ||
|
|
170
|
-
informationFromMaterial.textureData;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return informationFromMaterial;
|
|
126
|
+
|
|
127
|
+
if (geometryIndex === -1) {
|
|
128
|
+
geometryIndex = geometryDefinition.geometryBuffers.findIndex(buffer => !buffer.compressedAttributes);
|
|
175
129
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
130
|
+
|
|
131
|
+
if (geometryIndex !== -1) {
|
|
132
|
+
const isDracoGeometry = Boolean(geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes);
|
|
133
|
+
result = {
|
|
134
|
+
url: "".concat(this.tileset.url, "/nodes/").concat(meshGeometryData.resource, "/geometries/").concat(geometryIndex),
|
|
135
|
+
isDracoGeometry
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getLodSelection(node) {
|
|
143
|
+
const lodSelection = [];
|
|
144
|
+
|
|
145
|
+
if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {
|
|
146
|
+
lodSelection.push({
|
|
147
|
+
metricType: 'maxScreenThreshold',
|
|
148
|
+
maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
lodSelection.push({
|
|
153
|
+
metricType: this.lodSelectionMetricType,
|
|
154
|
+
maxError: node.lodThreshold
|
|
155
|
+
});
|
|
156
|
+
return lodSelection;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
getInformationFromMaterial(material) {
|
|
160
|
+
const informationFromMaterial = {
|
|
161
|
+
textureData: {
|
|
162
|
+
name: null
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (material) {
|
|
167
|
+
var _this$tileset$materia;
|
|
168
|
+
|
|
169
|
+
const materialDefinition = (_this$tileset$materia = this.tileset.materialDefinitions) === null || _this$tileset$materia === void 0 ? void 0 : _this$tileset$materia[material.definition];
|
|
170
|
+
|
|
171
|
+
if (materialDefinition) {
|
|
172
|
+
var _materialDefinition$p, _materialDefinition$p2;
|
|
173
|
+
|
|
174
|
+
informationFromMaterial.materialDefinition = materialDefinition;
|
|
175
|
+
const textureSetDefinitionIndex = materialDefinition === null || materialDefinition === void 0 ? void 0 : (_materialDefinition$p = materialDefinition.pbrMetallicRoughness) === null || _materialDefinition$p === void 0 ? void 0 : (_materialDefinition$p2 = _materialDefinition$p.baseColorTexture) === null || _materialDefinition$p2 === void 0 ? void 0 : _materialDefinition$p2.textureSetDefinitionId;
|
|
176
|
+
|
|
177
|
+
if (typeof textureSetDefinitionIndex === 'number') {
|
|
178
|
+
informationFromMaterial.textureData = this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || informationFromMaterial.textureData;
|
|
204
179
|
}
|
|
180
|
+
}
|
|
205
181
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
formats.push('ktx2');
|
|
182
|
+
|
|
183
|
+
return informationFromMaterial;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
initSelectedFormatsForTextureDefinitions(tileset) {
|
|
187
|
+
this.textureDefinitionsSelectedFormats = [];
|
|
188
|
+
const possibleI3sFormats = this.getSupportedTextureFormats();
|
|
189
|
+
const textureSetDefinitions = tileset.textureSetDefinitions || [];
|
|
190
|
+
|
|
191
|
+
for (const textureSetDefinition of textureSetDefinitions) {
|
|
192
|
+
const formats = textureSetDefinition && textureSetDefinition.formats || [];
|
|
193
|
+
let selectedFormat = null;
|
|
194
|
+
|
|
195
|
+
for (const i3sFormat of possibleI3sFormats) {
|
|
196
|
+
const format = formats.find(value => value.format === i3sFormat);
|
|
197
|
+
|
|
198
|
+
if (format) {
|
|
199
|
+
selectedFormat = format;
|
|
200
|
+
break;
|
|
226
201
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (selectedFormat && selectedFormat.format === 'ktx2') {
|
|
205
|
+
this.textureLoaderOptions.basis = {
|
|
206
|
+
format: selectSupportedBasisFormat(),
|
|
207
|
+
containerFormat: 'ktx2',
|
|
208
|
+
module: 'encoder'
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
this.textureDefinitionsSelectedFormats.push(selectedFormat);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
getSupportedTextureFormats() {
|
|
217
|
+
const formats = [];
|
|
218
|
+
|
|
219
|
+
if (!this.options.i3s || this.options.i3s.useCompressedTextures) {
|
|
220
|
+
const supportedCompressedFormats = getSupportedGPUTextureFormats();
|
|
221
|
+
|
|
222
|
+
if (supportedCompressedFormats.has('etc2')) {
|
|
223
|
+
formats.push('ktx-etc2');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (supportedCompressedFormats.has('dxt')) {
|
|
227
|
+
formats.push('dds');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
formats.push('ktx2');
|
|
230
231
|
}
|
|
232
|
+
|
|
233
|
+
formats.push('jpg');
|
|
234
|
+
formats.push('png');
|
|
235
|
+
return formats;
|
|
236
|
+
}
|
|
237
|
+
|
|
231
238
|
}
|
|
232
|
-
|
|
239
|
+
//# sourceMappingURL=i3s-nodepages-tiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/helpers/i3s-nodepages-tiles.ts"],"names":["load","getSupportedGPUTextureFormats","selectSupportedBasisFormat","I3SNodePageLoader","normalizeTileNonUrlData","getUrlWithToken","generateTilesetAttributeUrls","I3SNodePagesTiles","constructor","tileset","options","nodesPerPage","nodePages","lodSelectionMetricType","initSelectedFormatsForTextureDefinitions","getNodeById","id","pageIndex","Math","floor","pendingNodePages","nodePageUrl","url","i3s","token","status","promise","nodeIndex","nodes","formTileFromNodePages","node","children","child","childNode","push","toString","obb","contentUrl","textureUrl","materialDefinition","textureFormat","attributeUrls","isDracoGeometry","mesh","isDracoGeometryResult","geometry","getContentUrl","textureData","nodeMaterialDefinition","getInformationFromMaterial","material","format","name","resource","attributeStorageInfo","attribute","lodSelection","getLodSelection","textureLoaderOptions","meshGeometryData","result","geometryDefinition","geometryDefinitions","definition","geometryIndex","useDracoGeometry","geometryBuffers","findIndex","buffer","compressedAttributes","encoding","Boolean","metricType","maxError","sqrt","lodThreshold","PI","informationFromMaterial","materialDefinitions","textureSetDefinitionIndex","pbrMetallicRoughness","baseColorTexture","textureSetDefinitionId","textureDefinitionsSelectedFormats","possibleI3sFormats","getSupportedTextureFormats","textureSetDefinitions","textureSetDefinition","formats","selectedFormat","i3sFormat","find","value","basis","containerFormat","module","useCompressedTextures","supportedCompressedFormats","has"],"mappings":";AAAA,SAAQA,IAAR,QAAmB,kBAAnB;AACA,SAAQC,6BAAR,EAAuCC,0BAAvC,QAAwE,sBAAxE;AACA,SAAQC,iBAAR,QAAgC,4BAAhC;AACA,SAAQC,uBAAR,QAAsC,sBAAtC;AACA,SAAQC,eAAR,EAAyBC,4BAAzB,QAA4D,oBAA5D;AAkBA,e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,GAAGqC,OAAO,CAACG,IAAR,CAAcC,KAAD,IAAWA,KAAK,CAACzC,MAAN,KAAiBuC,SAAzC,CAAf;;AACA,YAAIvC,MAAJ,EAAY;AACVsC,UAAAA,cAAc,GAAGtC,MAAjB;AACA;AACD;AACF;;AAED,UAAIsC,cAAc,IAAIA,cAAc,CAACtC,MAAf,KAA0B,MAAhD,EAAwD;AACtD,aAAKO,oBAAL,CAA0BmC,KAA1B,GAAkC;AAChC1C,UAAAA,MAAM,EAAEjD,0BAA0B,EADF;AAEhC4F,UAAAA,eAAe,EAAE,MAFe;AAGhCC,UAAAA,MAAM,EAAE;AAHwB,SAAlC;AAKD;;AAED,WAAKZ,iCAAL,CAAuCjD,IAAvC,CAA4CuD,cAA5C;AACD;AACF;;AAMOJ,EAAAA,0BAA0B,GAAuB;AACvD,UAAMG,OAA2B,GAAG,EAApC;;AACA,QAAI,CAAC,KAAK9E,OAAL,CAAaa,GAAd,IAAqB,KAAKb,OAAL,CAAaa,GAAb,CAAiByE,qBAA1C,EAAiE;AAE/D,YAAMC,0BAA0B,GAAGhG,6BAA6B,EAAhE;;AAGA,UAAIgG,0BAA0B,CAACC,GAA3B,CAA+B,MAA/B,CAAJ,EAA4C;AAC1CV,QAAAA,OAAO,CAACtD,IAAR,CAAa,UAAb;AACD;;AACD,UAAI+D,0BAA0B,CAACC,GAA3B,CAA+B,KAA/B,CAAJ,EAA2C;AACzCV,QAAAA,OAAO,CAACtD,IAAR,CAAa,KAAb;AACD;;AAIDsD,MAAAA,OAAO,CAACtD,IAAR,CAAa,MAAb;AACD;;AAEDsD,IAAAA,OAAO,CAACtD,IAAR,CAAa,KAAb;AACAsD,IAAAA,OAAO,CAACtD,IAAR,CAAa,KAAb;AACA,WAAOsD,OAAP;AACD;;AAjQoC","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {getSupportedGPUTextureFormats, selectSupportedBasisFormat} from '@loaders.gl/textures';\nimport {I3SNodePageLoader} from '../../i3s-node-page-loader';\nimport {normalizeTileNonUrlData} from '../parsers/parse-i3s';\nimport {getUrlWithToken, generateTilesetAttributeUrls} from '../utils/url-utils';\nimport type {LoaderOptions} from '@loaders.gl/loader-utils';\nimport {\n I3STilesetHeader,\n LodSelection,\n NodePage,\n NodeInPage,\n Obb,\n MeshMaterial,\n I3SMaterialDefinition,\n I3STextureFormat,\n MeshGeometry,\n I3STileHeader\n} from '../../types';\n\n/**\n * class I3SNodePagesTiles - loads nodePages and form i3s tiles from them\n */\nexport default class I3SNodePagesTiles {\n tileset: I3STilesetHeader;\n nodePages: NodePage[] = [];\n pendingNodePages: {promise: Promise<NodePage>; status: 'Pending' | 'Done'}[] = [];\n nodesPerPage: number;\n options: LoaderOptions;\n lodSelectionMetricType?: string;\n textureDefinitionsSelectedFormats: ({format: I3STextureFormat; name: string} | null)[] = [];\n private textureLoaderOptions: {[key: string]: any} = {};\n\n /**\n * @constructs\n * Create a I3SNodePagesTiles instance.\n * @param tileset - i3s tileset header ('layers/0')\n * @param options - i3s loader options\n */\n constructor(tileset: I3STilesetHeader, options: LoaderOptions) {\n this.tileset = {...tileset}; // spread the tileset to avoid circular reference\n this.nodesPerPage = tileset.nodePages?.nodesPerPage || 64;\n this.lodSelectionMetricType = tileset.nodePages?.lodSelectionMetricType;\n this.options = options;\n\n this.initSelectedFormatsForTextureDefinitions(tileset);\n }\n\n /**\n * Loads some nodePage and return a particular node from it\n * @param id - id of node through all node pages\n */\n async getNodeById(id: number): Promise<NodeInPage> {\n const pageIndex = Math.floor(id / this.nodesPerPage);\n if (!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex]) {\n const nodePageUrl = getUrlWithToken(\n `${this.tileset.url}/nodepages/${pageIndex}`,\n this.options.i3s?.token\n );\n this.pendingNodePages[pageIndex] = {\n status: 'Pending',\n promise: load(nodePageUrl, I3SNodePageLoader, this.options)\n };\n this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;\n this.pendingNodePages[pageIndex].status = 'Done';\n }\n if (this.pendingNodePages[pageIndex].status === 'Pending') {\n this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;\n }\n const nodeIndex = id % this.nodesPerPage;\n return this.nodePages[pageIndex].nodes[nodeIndex];\n }\n\n /**\n * Forms tile header using node and tileset data\n * @param id - id of node through all node pages\n */\n // eslint-disable-next-line complexity\n async formTileFromNodePages(id: number): Promise<I3STileHeader> {\n const node: NodeInPage = await this.getNodeById(id);\n const children: {id: string; obb: Obb}[] = [];\n for (const child of node.children || []) {\n const childNode = await this.getNodeById(child);\n children.push({\n id: child.toString(),\n obb: childNode.obb\n });\n }\n\n let contentUrl: string | undefined;\n let textureUrl: string | undefined;\n let materialDefinition: I3SMaterialDefinition | undefined;\n let textureFormat: I3STextureFormat = 'jpg';\n let attributeUrls: string[] = [];\n let isDracoGeometry: boolean = false;\n\n if (node && node.mesh) {\n // Get geometry resource URL and type (compressed / non-compressed)\n const {url, isDracoGeometry: isDracoGeometryResult} = (node.mesh.geometry &&\n this.getContentUrl(node.mesh.geometry)) || {isDracoGeometry: false};\n contentUrl = url;\n isDracoGeometry = isDracoGeometryResult;\n\n const {textureData, materialDefinition: nodeMaterialDefinition} =\n this.getInformationFromMaterial(node.mesh.material);\n materialDefinition = nodeMaterialDefinition;\n textureFormat = textureData.format || textureFormat;\n if (textureData.name) {\n textureUrl = `${this.tileset.url}/nodes/${node.mesh.material.resource}/textures/${textureData.name}`;\n }\n\n if (this.tileset.attributeStorageInfo) {\n attributeUrls = generateTilesetAttributeUrls(this.tileset, node.mesh.attribute.resource);\n }\n }\n\n const lodSelection = this.getLodSelection(node);\n\n return normalizeTileNonUrlData({\n id: id.toString(),\n lodSelection,\n obb: node.obb,\n contentUrl,\n textureUrl,\n attributeUrls,\n materialDefinition,\n textureFormat,\n textureLoaderOptions: this.textureLoaderOptions,\n children,\n isDracoGeometry\n });\n }\n\n /**\n * Forms url and type of geometry resource by nodepage's data and `geometryDefinitions` in the tileset\n * @param - data about the node's mesh from the nodepage\n * @returns -\n * {string} url - url to the geometry resource\n * {boolean} isDracoGeometry - whether the geometry resource contain DRACO compressed geometry\n */\n private getContentUrl(meshGeometryData: MeshGeometry) {\n let result: {url: string; isDracoGeometry: boolean} | null = null;\n // @ts-ignore\n const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];\n let geometryIndex = -1;\n // Try to find DRACO geometryDefinition of `useDracoGeometry` option is set\n if (this.options.i3s && this.options.i3s.useDracoGeometry) {\n geometryIndex = geometryDefinition.geometryBuffers.findIndex(\n (buffer) => buffer.compressedAttributes && buffer.compressedAttributes.encoding === 'draco'\n );\n }\n // If DRACO geometry is not applicable try to select non-compressed geometry\n if (geometryIndex === -1) {\n geometryIndex = geometryDefinition.geometryBuffers.findIndex(\n (buffer) => !buffer.compressedAttributes\n );\n }\n if (geometryIndex !== -1) {\n const isDracoGeometry = Boolean(\n geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes\n );\n result = {\n url: `${this.tileset.url}/nodes/${meshGeometryData.resource}/geometries/${geometryIndex}`,\n isDracoGeometry\n };\n }\n return result;\n }\n\n /**\n * Forms 1.6 compatible LOD selection object from a nodepage's node data\n * @param node - a node from nodepage\n * @returns- Array of LodSelection\n */\n private getLodSelection(node: NodeInPage): LodSelection[] {\n const lodSelection: LodSelection[] = [];\n if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {\n lodSelection.push({\n metricType: 'maxScreenThreshold',\n // @ts-ignore\n maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))\n });\n }\n lodSelection.push({\n metricType: this.lodSelectionMetricType,\n // @ts-ignore\n maxError: node.lodThreshold\n });\n return lodSelection;\n }\n\n /**\n * Returns information about texture and material from `materialDefinitions`\n * @param material - material data from nodepage\n * @returns - Couple {textureData, materialDefinition}\n * {string} textureData.name - path name of the texture\n * {string} textureData.format - format of the texture\n * materialDefinition - PBR-like material definition from `materialDefinitions`\n */\n private getInformationFromMaterial(material: MeshMaterial) {\n const informationFromMaterial: {\n textureData: {name: string | null; format?: I3STextureFormat};\n materialDefinition?: I3SMaterialDefinition;\n } = {textureData: {name: null}};\n\n if (material) {\n const materialDefinition = this.tileset.materialDefinitions?.[material.definition];\n if (materialDefinition) {\n informationFromMaterial.materialDefinition = materialDefinition;\n const textureSetDefinitionIndex =\n materialDefinition?.pbrMetallicRoughness?.baseColorTexture?.textureSetDefinitionId;\n\n if (typeof textureSetDefinitionIndex === 'number') {\n informationFromMaterial.textureData =\n this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] ||\n informationFromMaterial.textureData;\n }\n }\n }\n return informationFromMaterial;\n }\n\n /**\n * Sets preferable and supported format for each textureDefinition of the tileset\n * @param tileset - I3S layer data\n * @returns\n */\n private initSelectedFormatsForTextureDefinitions(tileset: I3STilesetHeader): void {\n this.textureDefinitionsSelectedFormats = [];\n const possibleI3sFormats = this.getSupportedTextureFormats();\n const textureSetDefinitions = tileset.textureSetDefinitions || [];\n for (const textureSetDefinition of textureSetDefinitions) {\n const formats = (textureSetDefinition && textureSetDefinition.formats) || [];\n let selectedFormat: {name: string; format: I3STextureFormat} | null = null;\n for (const i3sFormat of possibleI3sFormats) {\n const format = formats.find((value) => value.format === i3sFormat);\n if (format) {\n selectedFormat = format;\n break;\n }\n }\n // For I3S 1.8 need to define basis target format to decode\n if (selectedFormat && selectedFormat.format === 'ktx2') {\n this.textureLoaderOptions.basis = {\n format: selectSupportedBasisFormat(),\n containerFormat: 'ktx2',\n module: 'encoder'\n };\n }\n\n this.textureDefinitionsSelectedFormats.push(selectedFormat);\n }\n }\n\n /**\n * Returns the array of supported texture format\n * @returns list of format strings\n */\n private getSupportedTextureFormats(): I3STextureFormat[] {\n const formats: I3STextureFormat[] = [];\n if (!this.options.i3s || this.options.i3s.useCompressedTextures) {\n // I3S 1.7 selection\n const supportedCompressedFormats = getSupportedGPUTextureFormats();\n // List of possible in i3s formats:\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n if (supportedCompressedFormats.has('etc2')) {\n formats.push('ktx-etc2');\n }\n if (supportedCompressedFormats.has('dxt')) {\n formats.push('dds');\n }\n\n // I3S 1.8 selection\n // ktx2 wraps basis texture which at the edge case can be decoded as uncompressed image\n formats.push('ktx2');\n }\n\n formats.push('jpg');\n formats.push('png');\n return formats;\n }\n}\n"],"file":"i3s-nodepages-tiles.js"}
|