@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.
Files changed (112) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/dist.min.js +28 -25
  4. package/dist/i3s-attribute-loader.js +130 -155
  5. package/dist/i3s-attribute-loader.js.map +1 -0
  6. package/dist/i3s-building-scene-layer-loader.js +18 -23
  7. package/dist/i3s-building-scene-layer-loader.js.map +1 -0
  8. package/dist/i3s-content-loader.js +22 -25
  9. package/dist/i3s-content-loader.js.map +1 -0
  10. package/dist/i3s-content-worker.js +23 -21
  11. package/dist/i3s-loader.js +81 -84
  12. package/dist/i3s-loader.js.map +1 -0
  13. package/dist/i3s-node-page-loader.js +17 -21
  14. package/dist/i3s-node-page-loader.js.map +1 -0
  15. package/dist/index.js +6 -14
  16. package/dist/index.js.map +1 -0
  17. package/dist/lib/helpers/i3s-nodepages-tiles.js +228 -221
  18. package/dist/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
  19. package/dist/lib/parsers/constants.js +63 -85
  20. package/dist/lib/parsers/constants.js.map +1 -0
  21. package/dist/lib/parsers/parse-i3s-attribute.js +62 -86
  22. package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -0
  23. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +40 -41
  24. package/dist/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
  25. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
  26. package/dist/lib/parsers/parse-i3s-tile-content.js +458 -441
  27. package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -0
  28. package/dist/lib/parsers/parse-i3s.js +88 -86
  29. package/dist/lib/parsers/parse-i3s.js.map +1 -0
  30. package/dist/lib/utils/convert-i3s-obb-to-mbs.js +8 -19
  31. package/dist/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
  32. package/dist/lib/utils/url-utils.js +28 -41
  33. package/dist/lib/utils/url-utils.js.map +1 -0
  34. package/dist/types.d.ts +2 -3
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/types.js +19 -18
  37. package/dist/types.js.map +1 -0
  38. package/dist/workers/i3s-content-worker.js +4 -5
  39. package/dist/workers/i3s-content-worker.js.map +1 -0
  40. package/package.json +12 -12
  41. package/src/i3s-building-scene-layer-loader.ts +1 -1
  42. package/src/i3s-content-loader.ts +1 -1
  43. package/src/lib/parsers/parse-i3s-tile-content.ts +4 -1
  44. package/src/types.ts +2 -3
  45. package/dist/es5/bundle.js +0 -7
  46. package/dist/es5/bundle.js.map +0 -1
  47. package/dist/es5/i3s-attribute-loader.js +0 -249
  48. package/dist/es5/i3s-attribute-loader.js.map +0 -1
  49. package/dist/es5/i3s-building-scene-layer-loader.js +0 -58
  50. package/dist/es5/i3s-building-scene-layer-loader.js.map +0 -1
  51. package/dist/es5/i3s-content-loader.js +0 -60
  52. package/dist/es5/i3s-content-loader.js.map +0 -1
  53. package/dist/es5/i3s-loader.js +0 -233
  54. package/dist/es5/i3s-loader.js.map +0 -1
  55. package/dist/es5/i3s-node-page-loader.js +0 -72
  56. package/dist/es5/i3s-node-page-loader.js.map +0 -1
  57. package/dist/es5/index.js +0 -52
  58. package/dist/es5/index.js.map +0 -1
  59. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +0 -393
  60. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
  61. package/dist/es5/lib/parsers/constants.js +0 -89
  62. package/dist/es5/lib/parsers/constants.js.map +0 -1
  63. package/dist/es5/lib/parsers/parse-i3s-attribute.js +0 -124
  64. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +0 -1
  65. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +0 -86
  66. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
  67. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +0 -635
  68. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +0 -1
  69. package/dist/es5/lib/parsers/parse-i3s.js +0 -155
  70. package/dist/es5/lib/parsers/parse-i3s.js.map +0 -1
  71. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +0 -24
  72. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
  73. package/dist/es5/lib/utils/url-utils.js +0 -40
  74. package/dist/es5/lib/utils/url-utils.js.map +0 -1
  75. package/dist/es5/types.js +0 -29
  76. package/dist/es5/types.js.map +0 -1
  77. package/dist/es5/workers/i3s-content-worker.js +0 -8
  78. package/dist/es5/workers/i3s-content-worker.js.map +0 -1
  79. package/dist/esm/bundle.js +0 -5
  80. package/dist/esm/bundle.js.map +0 -1
  81. package/dist/esm/i3s-attribute-loader.js +0 -152
  82. package/dist/esm/i3s-attribute-loader.js.map +0 -1
  83. package/dist/esm/i3s-building-scene-layer-loader.js +0 -21
  84. package/dist/esm/i3s-building-scene-layer-loader.js.map +0 -1
  85. package/dist/esm/i3s-content-loader.js +0 -25
  86. package/dist/esm/i3s-content-loader.js.map +0 -1
  87. package/dist/esm/i3s-loader.js +0 -97
  88. package/dist/esm/i3s-loader.js.map +0 -1
  89. package/dist/esm/i3s-node-page-loader.js +0 -22
  90. package/dist/esm/i3s-node-page-loader.js.map +0 -1
  91. package/dist/esm/index.js +0 -6
  92. package/dist/esm/index.js.map +0 -1
  93. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +0 -239
  94. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
  95. package/dist/esm/lib/parsers/constants.js +0 -67
  96. package/dist/esm/lib/parsers/constants.js.map +0 -1
  97. package/dist/esm/lib/parsers/parse-i3s-attribute.js +0 -74
  98. package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +0 -1
  99. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js +0 -45
  100. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
  101. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +0 -494
  102. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +0 -1
  103. package/dist/esm/lib/parsers/parse-i3s.js +0 -91
  104. package/dist/esm/lib/parsers/parse-i3s.js.map +0 -1
  105. package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js +0 -9
  106. package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
  107. package/dist/esm/lib/utils/url-utils.js +0 -31
  108. package/dist/esm/lib/utils/url-utils.js.map +0 -1
  109. package/dist/esm/types.js +0 -21
  110. package/dist/esm/types.js.map +0 -1
  111. package/dist/esm/workers/i3s-content-worker.js +0 -4
  112. package/dist/esm/workers/i3s-content-worker.js.map +0 -1
@@ -1,232 +1,239 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@loaders.gl/core");
4
- const textures_1 = require("@loaders.gl/textures");
5
- const i3s_node_page_loader_1 = require("../../i3s-node-page-loader");
6
- const parse_i3s_1 = require("../parsers/parse-i3s");
7
- const url_utils_1 = require("../utils/url-utils");
8
- /**
9
- * class I3SNodePagesTiles - loads nodePages and form i3s tiles from them
10
- */
11
- class I3SNodePagesTiles {
12
- /**
13
- * @constructs
14
- * Create a I3SNodePagesTiles instance.
15
- * @param tileset - i3s tileset header ('layers/0')
16
- * @param options - i3s loader options
17
- */
18
- constructor(tileset, options) {
19
- this.nodePages = [];
20
- this.pendingNodePages = [];
21
- this.textureDefinitionsSelectedFormats = [];
22
- this.textureLoaderOptions = {};
23
- this.tileset = { ...tileset }; // spread the tileset to avoid circular reference
24
- this.nodesPerPage = tileset.nodePages?.nodesPerPage || 64;
25
- this.lodSelectionMetricType = tileset.nodePages?.lodSelectionMetricType;
26
- this.options = options;
27
- this.initSelectedFormatsForTextureDefinitions(tileset);
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
- * Loads some nodePage and return a particular node from it
31
- * @param id - id of node through all node pages
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
- * Forms tile header using node and tileset data
52
- * @param id - id of node through all node pages
53
- */
54
- // eslint-disable-next-line complexity
55
- async formTileFromNodePages(id) {
56
- const node = await this.getNodeById(id);
57
- const children = [];
58
- for (const child of node.children || []) {
59
- const childNode = await this.getNodeById(child);
60
- children.push({
61
- id: child.toString(),
62
- obb: childNode.obb
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
- * Forms url and type of geometry resource by nodepage's data and `geometryDefinitions` in the tileset
104
- * @param - data about the node's mesh from the nodepage
105
- * @returns -
106
- * {string} url - url to the geometry resource
107
- * {boolean} isDracoGeometry - whether the geometry resource contain DRACO compressed geometry
108
- */
109
- getContentUrl(meshGeometryData) {
110
- let result = null;
111
- // @ts-ignore
112
- const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];
113
- let geometryIndex = -1;
114
- // Try to find DRACO geometryDefinition of `useDracoGeometry` option is set
115
- if (this.options.i3s && this.options.i3s.useDracoGeometry) {
116
- geometryIndex = geometryDefinition.geometryBuffers.findIndex((buffer) => buffer.compressedAttributes && buffer.compressedAttributes.encoding === 'draco');
117
- }
118
- // If DRACO geometry is not applicable try to select non-compressed geometry
119
- if (geometryIndex === -1) {
120
- geometryIndex = geometryDefinition.geometryBuffers.findIndex((buffer) => !buffer.compressedAttributes);
121
- }
122
- if (geometryIndex !== -1) {
123
- const isDracoGeometry = Boolean(geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes);
124
- result = {
125
- url: `${this.tileset.url}/nodes/${meshGeometryData.resource}/geometries/${geometryIndex}`,
126
- isDracoGeometry
127
- };
128
- }
129
- return result;
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
- * Forms 1.6 compatible LOD selection object from a nodepage's node data
133
- * @param node - a node from nodepage
134
- * @returns- Array of LodSelection
135
- */
136
- getLodSelection(node) {
137
- const lodSelection = [];
138
- if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {
139
- lodSelection.push({
140
- metricType: 'maxScreenThreshold',
141
- // @ts-ignore
142
- maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))
143
- });
144
- }
145
- lodSelection.push({
146
- metricType: this.lodSelectionMetricType,
147
- // @ts-ignore
148
- maxError: node.lodThreshold
149
- });
150
- return lodSelection;
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
- * Returns information about texture and material from `materialDefinitions`
154
- * @param material - material data from nodepage
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
- * Sets preferable and supported format for each textureDefinition of the tileset
178
- * @param tileset - I3S layer data
179
- * @returns
180
- */
181
- initSelectedFormatsForTextureDefinitions(tileset) {
182
- this.textureDefinitionsSelectedFormats = [];
183
- const possibleI3sFormats = this.getSupportedTextureFormats();
184
- const textureSetDefinitions = tileset.textureSetDefinitions || [];
185
- for (const textureSetDefinition of textureSetDefinitions) {
186
- const formats = (textureSetDefinition && textureSetDefinition.formats) || [];
187
- let selectedFormat = null;
188
- for (const i3sFormat of possibleI3sFormats) {
189
- const format = formats.find((value) => value.format === i3sFormat);
190
- if (format) {
191
- selectedFormat = format;
192
- break;
193
- }
194
- }
195
- // For I3S 1.8 need to define basis target format to decode
196
- if (selectedFormat && selectedFormat.format === 'ktx2') {
197
- this.textureLoaderOptions.basis = {
198
- format: (0, textures_1.selectSupportedBasisFormat)(),
199
- containerFormat: 'ktx2',
200
- module: 'encoder'
201
- };
202
- }
203
- this.textureDefinitionsSelectedFormats.push(selectedFormat);
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
- * Returns the array of supported texture format
208
- * @returns list of format strings
209
- */
210
- getSupportedTextureFormats() {
211
- const formats = [];
212
- if (!this.options.i3s || this.options.i3s.useCompressedTextures) {
213
- // I3S 1.7 selection
214
- const supportedCompressedFormats = (0, textures_1.getSupportedGPUTextureFormats)();
215
- // List of possible in i3s formats:
216
- // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md
217
- if (supportedCompressedFormats.has('etc2')) {
218
- formats.push('ktx-etc2');
219
- }
220
- if (supportedCompressedFormats.has('dxt')) {
221
- formats.push('dds');
222
- }
223
- // I3S 1.8 selection
224
- // ktx2 wraps basis texture which at the edge case can be decoded as uncompressed image
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
- formats.push('jpg');
228
- formats.push('png');
229
- return formats;
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
- exports.default = I3SNodePagesTiles;
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,eAAe,MAAMC,iBAAN,CAAwB;AAgBrCC,EAAAA,WAAW,CAACC,OAAD,EAA4BC,OAA5B,EAAoD;AAAA;;AAAA;;AAAA,uCAdvC,EAcuC;;AAAA,8CAbgB,EAahB;;AAAA;;AAAA;;AAAA;;AAAA,+DAT0B,EAS1B;;AAAA,kDARV,EAQU;;AAC7D,SAAKD,OAAL,GAAe,EAAC,GAAGA;AAAJ,KAAf;AACA,SAAKE,YAAL,GAAoB,uBAAAF,OAAO,CAACG,SAAR,0EAAmBD,YAAnB,KAAmC,EAAvD;AACA,SAAKE,sBAAL,0BAA8BJ,OAAO,CAACG,SAAtC,wDAA8B,oBAAmBC,sBAAjD;AACA,SAAKH,OAAL,GAAeA,OAAf;AAEA,SAAKI,wCAAL,CAA8CL,OAA9C;AACD;;AAMgB,QAAXM,WAAW,CAACC,EAAD,EAAkC;AACjD,UAAMC,SAAS,GAAGC,IAAI,CAACC,KAAL,CAAWH,EAAE,GAAG,KAAKL,YAArB,CAAlB;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,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"}