@loaders.gl/tile-converter 3.3.0-alpha.8 → 3.3.0
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/3d-tiles-attributes-worker.js +2 -2
- package/dist/3d-tiles-attributes-worker.js.map +3 -3
- package/dist/converter-cli.js +14 -2
- package/dist/converter.min.js +22 -22
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/deps-installer/deps-installer.js +8 -0
- package/dist/dist.min.js +1165 -846
- package/dist/es5/3d-tiles-attributes-worker.js +1 -1
- package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/converter-cli.js +14 -2
- package/dist/es5/converter-cli.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +13 -2
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +1 -1
- package/dist/es5/i3s-attributes-worker.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +16 -7
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +363 -113
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +6 -11
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +517 -0
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js +455 -173
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +549 -618
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +107 -0
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/layers.js +2 -93
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +3 -3
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +93 -9
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/write-queue.js +38 -25
- package/dist/es5/lib/utils/write-queue.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/esm/converter-cli.js +14 -2
- package/dist/esm/converter-cli.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +9 -1
- package/dist/esm/deps-installer/deps-installer.js.map +1 -1
- package/dist/esm/i3s-attributes-worker.js +1 -1
- package/dist/esm/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +16 -7
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +150 -40
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js +6 -9
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js +202 -0
- package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/node-pages.js +162 -76
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +115 -220
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/geometry-definitions.js +89 -0
- package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -0
- package/dist/esm/i3s-converter/json-templates/layers.js +2 -85
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/shared-resources.js +3 -3
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/lib/utils/file-utils.js +44 -3
- package/dist/esm/lib/utils/file-utils.js.map +1 -1
- package/dist/esm/lib/utils/write-queue.js +19 -10
- package/dist/esm/lib/utils/write-queue.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/esm/workers/i3s-attributes-worker.js +1 -1
- package/dist/esm/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/i3s-attributes-worker.js +2 -2
- package/dist/i3s-attributes-worker.js.map +2 -2
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +3 -3
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +3 -3
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +16 -10
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +8 -4
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +200 -44
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +2 -3
- package/dist/i3s-converter/helpers/node-index-document.d.ts +95 -0
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-index-document.js +250 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts +78 -43
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +195 -94
- package/dist/i3s-converter/i3s-converter.d.ts +33 -58
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +122 -233
- package/dist/i3s-converter/json-templates/geometry-definitions.d.ts +7 -0
- package/dist/i3s-converter/json-templates/geometry-definitions.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/geometry-definitions.js +87 -0
- package/dist/i3s-converter/json-templates/layers.d.ts +1 -30
- package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -1
- package/dist/i3s-converter/json-templates/layers.js +2 -86
- package/dist/i3s-converter/json-templates/shared-resources.js +3 -3
- package/dist/i3s-converter/types.d.ts +28 -2
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/lib/utils/file-utils.d.ts +17 -1
- package/dist/lib/utils/file-utils.d.ts.map +1 -1
- package/dist/lib/utils/file-utils.js +64 -7
- package/dist/lib/utils/write-queue.d.ts +18 -2
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +18 -12
- package/dist/workers/i3s-attributes-worker.js +1 -1
- package/package.json +25 -20
- package/src/converter-cli.ts +22 -2
- package/src/deps-installer/deps-installer.ts +9 -0
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +3 -3
- package/src/i3s-converter/helpers/geometry-attributes.ts +16 -11
- package/src/i3s-converter/helpers/geometry-converter.ts +217 -48
- package/src/i3s-converter/helpers/gltf-attributes.ts +2 -3
- package/src/i3s-converter/helpers/node-index-document.ts +315 -0
- package/src/i3s-converter/helpers/node-pages.ts +215 -110
- package/src/i3s-converter/i3s-converter.ts +170 -312
- package/src/i3s-converter/json-templates/geometry-definitions.ts +83 -0
- package/src/i3s-converter/json-templates/layers.ts +2 -91
- package/src/i3s-converter/json-templates/shared-resources.ts +3 -3
- package/src/i3s-converter/types.ts +29 -2
- package/src/lib/utils/file-utils.ts +62 -7
- package/src/lib/utils/write-queue.ts +36 -15
- package/src/workers/i3s-attributes-worker.ts +2 -1
|
@@ -6,18 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const json_map_transform_1 = __importDefault(require("json-map-transform"));
|
|
8
8
|
const metadata_1 = require("../json-templates/metadata");
|
|
9
|
-
|
|
9
|
+
const file_utils_1 = require("../../lib/utils/file-utils");
|
|
10
10
|
/**
|
|
11
11
|
* class NodePages - wrapper of nodePages array
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* import {writeFile} from './helpers/write-file';
|
|
14
|
+
* import {writeFile} from './helpers/write-file.js';
|
|
15
15
|
*
|
|
16
16
|
* // create an instance of the class
|
|
17
17
|
* const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);
|
|
18
18
|
* ...
|
|
19
19
|
* // push root node
|
|
20
|
-
* const
|
|
20
|
+
* const parent = await nodePages.push({
|
|
21
21
|
lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,
|
|
22
22
|
obb: coordinates.obb,
|
|
23
23
|
children: []
|
|
@@ -34,7 +34,7 @@ const metadata_1 = require("../json-templates/metadata");
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
* const
|
|
37
|
+
* const node = await this.nodePages.push(nodeInPage, parent.index);
|
|
38
38
|
* ...
|
|
39
39
|
* // save all the nodePages in the end of pushing all the nodes
|
|
40
40
|
* await this.nodePages.save(layers0path);
|
|
@@ -46,13 +46,16 @@ class NodePages {
|
|
|
46
46
|
* @param writeFileFunc - function to save one nodePage into a file
|
|
47
47
|
* @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met
|
|
48
48
|
*/
|
|
49
|
-
constructor(writeFileFunc, nodesPerPage) {
|
|
49
|
+
constructor(writeFileFunc, nodesPerPage, converter) {
|
|
50
|
+
this.length = 0;
|
|
50
51
|
this.nodesPerPage = nodesPerPage;
|
|
51
52
|
this.nodesCounter = 0;
|
|
52
53
|
// @ts-expect-error
|
|
53
54
|
this.nodePages = [{}];
|
|
54
55
|
this.nodePages[0].nodes = [];
|
|
55
56
|
this.writeFile = writeFileFunc;
|
|
57
|
+
this.converter = converter;
|
|
58
|
+
this.length = 0;
|
|
56
59
|
}
|
|
57
60
|
/**
|
|
58
61
|
* Setup function to save node pages
|
|
@@ -61,30 +64,203 @@ class NodePages {
|
|
|
61
64
|
useWriteFunction(func) {
|
|
62
65
|
this.writeFile = func;
|
|
63
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Get file path and file name of the node page with the particular id
|
|
69
|
+
* @param nodePageId - node page id
|
|
70
|
+
* @returns file path and file name
|
|
71
|
+
*/
|
|
72
|
+
getNodePageFileName(nodePageId) {
|
|
73
|
+
let filePath;
|
|
74
|
+
let fileName;
|
|
75
|
+
if (this.converter.options.slpk) {
|
|
76
|
+
filePath = (0, path_1.join)(this.converter.layers0Path, 'nodepages');
|
|
77
|
+
fileName = `${nodePageId.toString()}.json`;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
filePath = (0, path_1.join)(this.converter.layers0Path, 'nodepages', nodePageId.toString());
|
|
81
|
+
fileName = 'index.json';
|
|
82
|
+
}
|
|
83
|
+
return { filePath, fileName };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Load node page from a file on the disk
|
|
87
|
+
* @param nodePageId - node page id
|
|
88
|
+
* @returns - node page data
|
|
89
|
+
*/
|
|
90
|
+
async loadNodePage(nodePageId) {
|
|
91
|
+
const { filePath, fileName } = this.getNodePageFileName(nodePageId);
|
|
92
|
+
const fullName = (0, path_1.join)(filePath, fileName);
|
|
93
|
+
if (await (0, file_utils_1.isFileExists)(fullName)) {
|
|
94
|
+
console.log(`load ${fullName}.`); // eslint-disable-line
|
|
95
|
+
return (await (0, file_utils_1.openJson)(filePath, fileName));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return { nodes: [] };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get nodepage id by node id
|
|
103
|
+
* @param id node id
|
|
104
|
+
* @returns node page id
|
|
105
|
+
*/
|
|
106
|
+
getPageIndexByNodeId(id) {
|
|
107
|
+
return Math.floor(id / this.nodesPerPage);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get node page data by node id
|
|
111
|
+
* @param id node id
|
|
112
|
+
* @returns node page data
|
|
113
|
+
*/
|
|
114
|
+
async getPageByNodeId(id) {
|
|
115
|
+
const pageIndex = this.getPageIndexByNodeId(id);
|
|
116
|
+
if (this.converter.options.instantNodeWriting) {
|
|
117
|
+
return await this.loadNodePage(pageIndex);
|
|
118
|
+
}
|
|
119
|
+
return this.nodePages[pageIndex];
|
|
120
|
+
}
|
|
64
121
|
/**
|
|
65
122
|
* Get the node by its end-to-end index
|
|
66
123
|
* @param id - end-to-end index of the node
|
|
67
124
|
* @return the node object
|
|
68
125
|
*/
|
|
69
|
-
getNodeById(id) {
|
|
70
|
-
const pageIndex = Math.floor(id / this.nodesPerPage);
|
|
126
|
+
async getNodeById(id, nodePage) {
|
|
71
127
|
const nodeIndex = id % this.nodesPerPage;
|
|
72
|
-
|
|
128
|
+
nodePage = nodePage || (await this.getPageByNodeId(id));
|
|
129
|
+
return nodePage.nodes[nodeIndex];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Add a child id into the parent node.children array
|
|
133
|
+
* @param parentId - end-to-end parent node index
|
|
134
|
+
* @param childId - end-to-end child node index
|
|
135
|
+
*/
|
|
136
|
+
async addChildRelation(parentId, childId) {
|
|
137
|
+
if (parentId === null || parentId === undefined) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const parentNode = await this.getNodeById(parentId);
|
|
141
|
+
parentNode.children?.push(childId);
|
|
142
|
+
await this.saveNode(parentNode);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Put new node in nodePages array
|
|
146
|
+
* @param node - node object
|
|
147
|
+
* @param parentId - index of parent node
|
|
148
|
+
* @return
|
|
149
|
+
*/
|
|
150
|
+
async push(node, parentId) {
|
|
151
|
+
node.index = this.nodesCounter++;
|
|
152
|
+
if (!this.converter.options.instantNodeWriting) {
|
|
153
|
+
let currentNodePage = this.nodePages[this.nodePages.length - 1];
|
|
154
|
+
if (currentNodePage.nodes.length === this.nodesPerPage) {
|
|
155
|
+
currentNodePage = { nodes: [] };
|
|
156
|
+
this.nodePages.push(currentNodePage);
|
|
157
|
+
}
|
|
158
|
+
currentNodePage.nodes.push(node);
|
|
159
|
+
}
|
|
160
|
+
await this.addChildRelation(parentId, node.index);
|
|
161
|
+
NodePages.updateResourceInMesh(node);
|
|
162
|
+
await this.saveNode(node);
|
|
163
|
+
return node;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Save node to the file on the disk
|
|
167
|
+
* @param node - node data
|
|
168
|
+
*/
|
|
169
|
+
async saveNode(node) {
|
|
170
|
+
if (!this.converter.options.instantNodeWriting) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const nodePageIndex = this.getPageIndexByNodeId(node.index);
|
|
175
|
+
const nodePage = await this.getPageByNodeId(node.index);
|
|
176
|
+
const { filePath, fileName } = this.getNodePageFileName(nodePageIndex);
|
|
177
|
+
const nodeToUpdate = await this.getNodeById(node.index, nodePage);
|
|
178
|
+
if (nodeToUpdate) {
|
|
179
|
+
NodePages.updateAll(nodeToUpdate, node);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
nodePage.nodes.push(node);
|
|
183
|
+
}
|
|
184
|
+
const nodePageStr = JSON.stringify(nodePage);
|
|
185
|
+
if (this.converter.options.slpk) {
|
|
186
|
+
await this.converter.writeQueue.enqueue({
|
|
187
|
+
archiveKey: `nodePages/${nodePageIndex.toString()}.json.gz`,
|
|
188
|
+
writePromise: () => this.writeFile(filePath, nodePageStr, fileName, true, this.converter.compressList)
|
|
189
|
+
}, true);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
await this.converter.writeQueue.enqueue({
|
|
193
|
+
writePromise: () => this.writeFile(filePath, nodePageStr)
|
|
194
|
+
}, true);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Save metadata file (for slpk only)
|
|
200
|
+
*/
|
|
201
|
+
async saveMetadata() {
|
|
202
|
+
const metadata = (0, json_map_transform_1.default)({ nodeCount: this.nodesCounter }, (0, metadata_1.METADATA)());
|
|
203
|
+
const compress = false;
|
|
204
|
+
await this.converter.writeQueue.enqueue({
|
|
205
|
+
archiveKey: 'metadata.json',
|
|
206
|
+
writePromise: () => this.writeFile(this.converter.layers0Path, JSON.stringify(metadata), 'metadata.json', compress)
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Save all the node pages
|
|
211
|
+
* Run this method when all nodes is pushed in nodePages
|
|
212
|
+
*/
|
|
213
|
+
async save() {
|
|
214
|
+
if (this.converter.options.instantNodeWriting) {
|
|
215
|
+
await this.saveMetadata();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (this.converter.options.slpk) {
|
|
219
|
+
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
220
|
+
const nodePageStr = JSON.stringify(nodePage);
|
|
221
|
+
const slpkPath = (0, path_1.join)(this.converter.layers0Path, 'nodepages');
|
|
222
|
+
await this.converter.writeQueue.enqueue({
|
|
223
|
+
archiveKey: `nodePages/${index.toString()}.json.gz`,
|
|
224
|
+
writePromise: () => this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`)
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
await this.saveMetadata();
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
231
|
+
const nodePageStr = JSON.stringify(nodePage);
|
|
232
|
+
const nodePagePath = (0, path_1.join)(this.converter.layers0Path, 'nodepages', index.toString());
|
|
233
|
+
await this.converter.writeQueue.enqueue({
|
|
234
|
+
writePromise: () => this.writeFile(nodePagePath, nodePageStr)
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Update resource index in node.mesh object
|
|
241
|
+
* @param node - node object
|
|
242
|
+
*/
|
|
243
|
+
static updateResourceInMesh(node) {
|
|
244
|
+
if (node.mesh && isFinite(node.index)) {
|
|
245
|
+
node.mesh.geometry.resource = node.index;
|
|
246
|
+
}
|
|
73
247
|
}
|
|
74
248
|
/**
|
|
75
249
|
* Update all fields in the node excluding id
|
|
250
|
+
* @param node - node object
|
|
251
|
+
* @param data - NodeInPage data to replace original data
|
|
76
252
|
*/
|
|
77
|
-
updateAll(
|
|
78
|
-
const node = this.getNodeById(id);
|
|
253
|
+
static updateAll(node, data) {
|
|
79
254
|
Object.assign(node, data, { index: node.index });
|
|
255
|
+
NodePages.updateResourceInMesh(node);
|
|
256
|
+
return node;
|
|
80
257
|
}
|
|
81
258
|
/**
|
|
82
259
|
* Update material in node.mesh object by node id
|
|
83
260
|
* @param id - end-to-end index of the node
|
|
84
261
|
* @param materialId - id from scene layer materialDefinitions
|
|
85
262
|
*/
|
|
86
|
-
updateMaterialByNodeId(
|
|
87
|
-
const node = this.getNodeById(id);
|
|
263
|
+
static updateMaterialByNodeId(node, materialId) {
|
|
88
264
|
if (!node.mesh) {
|
|
89
265
|
return;
|
|
90
266
|
}
|
|
@@ -98,8 +274,7 @@ class NodePages {
|
|
|
98
274
|
* @param id - end-to-end index of the node
|
|
99
275
|
* @param vertexCount - vertex count for particular node
|
|
100
276
|
*/
|
|
101
|
-
updateVertexCountByNodeId(
|
|
102
|
-
const node = this.getNodeById(id);
|
|
277
|
+
static updateVertexCountByNodeId(node, vertexCount) {
|
|
103
278
|
if (!node.mesh) {
|
|
104
279
|
return;
|
|
105
280
|
}
|
|
@@ -107,10 +282,9 @@ class NodePages {
|
|
|
107
282
|
}
|
|
108
283
|
/**
|
|
109
284
|
* Update resource in node.mesh.attribute object by node id
|
|
110
|
-
* @param
|
|
285
|
+
* @param node - node object
|
|
111
286
|
*/
|
|
112
|
-
updateNodeAttributeByNodeId(
|
|
113
|
-
const node = this.getNodeById(id);
|
|
287
|
+
static updateNodeAttributeByNodeId(node) {
|
|
114
288
|
if (!node.mesh || !node.index) {
|
|
115
289
|
return;
|
|
116
290
|
}
|
|
@@ -118,11 +292,10 @@ class NodePages {
|
|
|
118
292
|
}
|
|
119
293
|
/**
|
|
120
294
|
* Update featureCount in node.mesh.geometry object by node id
|
|
121
|
-
* @param
|
|
295
|
+
* @param node - node object
|
|
122
296
|
* @param featureCount - features count of the node
|
|
123
297
|
*/
|
|
124
|
-
updateFeatureCountByNodeId(
|
|
125
|
-
const node = this.getNodeById(id);
|
|
298
|
+
static updateFeatureCountByNodeId(node, featureCount) {
|
|
126
299
|
if (!node.mesh) {
|
|
127
300
|
return;
|
|
128
301
|
}
|
|
@@ -130,86 +303,14 @@ class NodePages {
|
|
|
130
303
|
}
|
|
131
304
|
/**
|
|
132
305
|
* Update texelCountHint in node.mesh.material object by node id
|
|
133
|
-
* @param
|
|
306
|
+
* @param node - node object
|
|
134
307
|
* @param texelCountHint - texelCountHint of particular node
|
|
135
308
|
*/
|
|
136
|
-
updateTexelCountHintByNodeId(
|
|
137
|
-
const node = this.getNodeById(id);
|
|
309
|
+
static updateTexelCountHintByNodeId(node, texelCountHint) {
|
|
138
310
|
if (!node.mesh || !node.mesh.material) {
|
|
139
311
|
return;
|
|
140
312
|
}
|
|
141
313
|
node.mesh.material.texelCountHint = texelCountHint;
|
|
142
314
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Add a child id into the parent node.children array
|
|
145
|
-
* @param parentId - end-to-end parent node index
|
|
146
|
-
* @param childId - end-to-end child node index
|
|
147
|
-
*/
|
|
148
|
-
addChildRelation(parentId, childId) {
|
|
149
|
-
if (parentId === null || parentId === undefined) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const parentNode = this.getNodeById(parentId);
|
|
153
|
-
parentNode.children?.push(childId);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Update resource index in node.mesh object
|
|
157
|
-
* @param node - node object
|
|
158
|
-
*/
|
|
159
|
-
updateResourceInMesh(node) {
|
|
160
|
-
if (node.mesh && isFinite(node.index)) {
|
|
161
|
-
node.mesh.geometry.resource = node.index;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Put new node in nodePages array
|
|
166
|
-
* @param node - node object
|
|
167
|
-
* @param parentId - index of parent node
|
|
168
|
-
* @return
|
|
169
|
-
*/
|
|
170
|
-
push(node, parentId) {
|
|
171
|
-
let currentNodePage = this.nodePages[this.nodePages.length - 1];
|
|
172
|
-
if (currentNodePage.nodes.length === this.nodesPerPage) {
|
|
173
|
-
currentNodePage = { nodes: [] };
|
|
174
|
-
this.nodePages.push(currentNodePage);
|
|
175
|
-
}
|
|
176
|
-
node.index = this.nodesCounter++;
|
|
177
|
-
currentNodePage.nodes.push(node);
|
|
178
|
-
this.addChildRelation(parentId, node.index);
|
|
179
|
-
this.updateResourceInMesh(node);
|
|
180
|
-
return node.index;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Save all the node pages
|
|
184
|
-
* Run this method when all nodes is pushed in nodePages
|
|
185
|
-
* @param layers0Path - path of layer
|
|
186
|
-
* @param writeQueue - write queue that controlls files write concurrency
|
|
187
|
-
* @param slpk
|
|
188
|
-
*/
|
|
189
|
-
async save(layers0Path, writeQueue, slpk = false) {
|
|
190
|
-
if (slpk) {
|
|
191
|
-
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
192
|
-
const nodePageStr = JSON.stringify(nodePage);
|
|
193
|
-
const slpkPath = (0, path_1.join)(layers0Path, 'nodepages');
|
|
194
|
-
await writeQueue.enqueue({
|
|
195
|
-
archiveKey: `nodePages/${index.toString()}.json.gz`,
|
|
196
|
-
writePromise: this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`)
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
const metadata = (0, json_map_transform_1.default)({ nodeCount: this.nodesCounter }, (0, metadata_1.METADATA)());
|
|
200
|
-
const compress = false;
|
|
201
|
-
await writeQueue.enqueue({
|
|
202
|
-
archiveKey: 'metadata.json',
|
|
203
|
-
writePromise: this.writeFile(layers0Path, JSON.stringify(metadata), 'metadata.json', compress)
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
208
|
-
const nodePageStr = JSON.stringify(nodePage);
|
|
209
|
-
const nodePagePath = (0, path_1.join)(layers0Path, 'nodepages', index.toString());
|
|
210
|
-
await writeQueue.enqueue({ writePromise: this.writeFile(nodePagePath, nodePageStr) });
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
315
|
}
|
|
215
316
|
exports.default = NodePages;
|
|
@@ -13,8 +13,13 @@ export default class I3SConverter {
|
|
|
13
13
|
nodePages: NodePages;
|
|
14
14
|
options: any;
|
|
15
15
|
layers0Path: string;
|
|
16
|
-
materialMap: Map<
|
|
16
|
+
materialMap: Map<string, number>;
|
|
17
17
|
materialDefinitions: I3SMaterialDefinition[];
|
|
18
|
+
geometryMap: Map<string, number>;
|
|
19
|
+
geometryConfigs: {
|
|
20
|
+
hasTexture: boolean;
|
|
21
|
+
hasUvRegions: boolean;
|
|
22
|
+
}[];
|
|
18
23
|
vertexCounter: number;
|
|
19
24
|
layers0: SceneLayer3D | null;
|
|
20
25
|
featuresHashArray: string[];
|
|
@@ -36,6 +41,7 @@ export default class I3SConverter {
|
|
|
36
41
|
[key: string]: string;
|
|
37
42
|
};
|
|
38
43
|
writeQueue: WriteQueue<WriteQueueItem>;
|
|
44
|
+
compressList: string[] | null;
|
|
39
45
|
constructor();
|
|
40
46
|
/**
|
|
41
47
|
* Convert a 3d tileset
|
|
@@ -50,6 +56,9 @@ export default class I3SConverter {
|
|
|
50
56
|
* @param options.token Token for Cesium ION tilesets authentication
|
|
51
57
|
* @param options.draco Generate I3S 1.7 draco compressed geometries
|
|
52
58
|
* @param options.validate -enable validation
|
|
59
|
+
* @param options.generateTextures - generate alternative type of textures (to have non-compressed jpeg/png and compressed ktx2)
|
|
60
|
+
* @param options.generateBoundingVolumes - generate bounding volumes from vertices coordinates instead of source tiles bounding volumes
|
|
61
|
+
* @param options.instantNodeWriting - Keep created 3DNodeIndexDocument files on disk instead of memory. This option reduce memory usage but decelerates conversion speed
|
|
53
62
|
*/
|
|
54
63
|
convert(options: {
|
|
55
64
|
inputUrl: string;
|
|
@@ -61,9 +70,11 @@ export default class I3SConverter {
|
|
|
61
70
|
slpk?: boolean;
|
|
62
71
|
token?: string;
|
|
63
72
|
draco?: boolean;
|
|
73
|
+
mergeMaterials?: boolean;
|
|
64
74
|
validate?: boolean;
|
|
65
75
|
generateTextures?: boolean;
|
|
66
76
|
generateBoundingVolumes?: boolean;
|
|
77
|
+
instantNodeWriting?: boolean;
|
|
67
78
|
}): Promise<any>;
|
|
68
79
|
/**
|
|
69
80
|
* Convert and save the layer and embedded tiles
|
|
@@ -76,28 +87,16 @@ export default class I3SConverter {
|
|
|
76
87
|
* @param tilesetName - Name of layer
|
|
77
88
|
*/
|
|
78
89
|
private _formLayers0;
|
|
79
|
-
/**
|
|
80
|
-
* Convert and save the layer and embedded tiles
|
|
81
|
-
* @param boundingVolumes - mbs and obb data about node's bounding volume
|
|
82
|
-
* @return 3DNodeIndexDocument data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
|
|
83
|
-
*/
|
|
84
|
-
private _formRootNodeIndexDocument;
|
|
85
90
|
/**
|
|
86
91
|
* Form object of 3DSceneLayer https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DSceneLayer.cmn.md
|
|
87
|
-
* @param
|
|
92
|
+
* @param rootNode - 3DNodeIndexDocument of root node https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
|
|
88
93
|
* @param sourceRootTile - Source (3DTile) tile data
|
|
89
|
-
* @param parentId - node id in node pages
|
|
90
|
-
* @param boundingVolumes - mbs and obb data about node's bounding volume
|
|
91
94
|
*/
|
|
92
95
|
private _convertNodesTree;
|
|
93
96
|
/**
|
|
94
97
|
* Write 3DSceneLayer https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DSceneLayer.cmn.md in file
|
|
95
98
|
*/
|
|
96
99
|
private _writeLayers0;
|
|
97
|
-
/**
|
|
98
|
-
* Write 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md in file
|
|
99
|
-
*/
|
|
100
|
-
private _writeNodeIndexDocument;
|
|
101
100
|
/**
|
|
102
101
|
* Pack files into *.slpk archive
|
|
103
102
|
* @param tilesetPath - Path to save file
|
|
@@ -106,54 +105,40 @@ export default class I3SConverter {
|
|
|
106
105
|
/**
|
|
107
106
|
* Add child nodes recursively and write them to files
|
|
108
107
|
* @param data - arguments
|
|
108
|
+
* @param data.parentNode - 3DNodeIndexDocument of parent node
|
|
109
109
|
* @param data.sourceTiles - array of source child nodes
|
|
110
|
-
* @param data.parentNode - 3DNodeIndexDocument of parent node for processing child nodes
|
|
111
|
-
* @param data.parentId - id of parent node in node pages
|
|
112
110
|
* @param data.level - level of node (distanse to root node in the tree)
|
|
113
111
|
*/
|
|
114
112
|
private _addChildrenWithNeighborsAndWriteFile;
|
|
115
113
|
/**
|
|
116
114
|
* Convert nested subtree of 3DTiles dataset
|
|
117
115
|
* @param param0
|
|
116
|
+
* @param data.parentNode - 3DNodeIndexDocument of parent node
|
|
118
117
|
* @param param0.sourceTile - source 3DTile data
|
|
119
|
-
* @param param0.parentNode - parent I3S node
|
|
120
|
-
* @param param0.childNodes - child I3S nodes
|
|
121
|
-
* @param param0.parentId - parent node ID
|
|
122
118
|
* @param param0.level - tree level
|
|
123
119
|
*/
|
|
124
120
|
private convertNestedTileset;
|
|
125
121
|
/**
|
|
126
122
|
* Convert 3DTiles tile to I3S node
|
|
127
123
|
* @param param0
|
|
124
|
+
* @param param0.parentNode - 3DNodeIndexDocument of parent node
|
|
128
125
|
* @param param0.sourceTile - source 3DTile data
|
|
129
|
-
* @param param0.parentNode - parent I3S node
|
|
130
|
-
* @param param0.childNodes - child I3S nodes
|
|
131
|
-
* @param param0.parentId - parent node ID
|
|
132
126
|
* @param param0.level - tree level
|
|
133
127
|
*/
|
|
134
128
|
private convertNode;
|
|
135
129
|
/**
|
|
136
130
|
* Add child nodes recursively and write them to files
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
-
* @param data.parentId - id of parent node in node pages
|
|
142
|
-
* @param data.level - level of node (distanse to root node in the tree)
|
|
131
|
+
* @param param0 - arguments
|
|
132
|
+
* @param param0.parentNode - 3DNodeIndexDocument of parent node
|
|
133
|
+
* @param param0.sourceTile - source 3DTile data
|
|
134
|
+
* @param param0.level - tree level
|
|
143
135
|
*/
|
|
144
136
|
private _addChildren;
|
|
145
|
-
/**
|
|
146
|
-
* Add neightbors to 3DNodeIndexDocument and write it in a file
|
|
147
|
-
* @param parentNode - arguments
|
|
148
|
-
* @param childNodes - array of target child nodes
|
|
149
|
-
*/
|
|
150
|
-
private _addNeighborsAndWriteFile;
|
|
151
137
|
/**
|
|
152
138
|
* Convert tile to one or more I3S nodes
|
|
153
|
-
* @param
|
|
154
|
-
* @param sourceTile - source
|
|
155
|
-
* @param
|
|
156
|
-
* @param level - level of node (distanse to root node in the tree)
|
|
139
|
+
* @param parentNode - 3DNodeIndexDocument of parent node
|
|
140
|
+
* @param sourceTile - source 3DTile data
|
|
141
|
+
* @param level - tree level
|
|
157
142
|
*/
|
|
158
143
|
private _createNode;
|
|
159
144
|
/**
|
|
@@ -161,14 +146,7 @@ export default class I3SConverter {
|
|
|
161
146
|
* @param sourceTile - source tile (3DTile)
|
|
162
147
|
* @param parentId - id of parent node in node pages
|
|
163
148
|
* @param propertyTable - batch table from b3dm / feature properties from EXT_FEATURE_METADATA
|
|
164
|
-
*
|
|
165
|
-
* result.compressedGeometry - ArrayBuffer with compressed (draco) geometry
|
|
166
|
-
* result.texture - texture image
|
|
167
|
-
* result.sharedResources - shared resource data object
|
|
168
|
-
* result.meshMaterial - PBR-like material object
|
|
169
|
-
* result.vertexCount - number of vertices in geometry
|
|
170
|
-
* result.attributes - feature attributes
|
|
171
|
-
* result.featureCount - number of features
|
|
149
|
+
* @returns - converted node resources
|
|
172
150
|
*/
|
|
173
151
|
private _convertResources;
|
|
174
152
|
/**
|
|
@@ -183,21 +161,10 @@ export default class I3SConverter {
|
|
|
183
161
|
* @param resources.texture - texture image
|
|
184
162
|
* @param resources.vertexCount - number of vertices in geometry
|
|
185
163
|
* @param resources.featureCount - number of features
|
|
164
|
+
* @param resources.geometry - Uint8Array with geometry attributes
|
|
186
165
|
* @return the node object in node pages
|
|
187
166
|
*/
|
|
188
167
|
private _updateNodeInNodePages;
|
|
189
|
-
/**
|
|
190
|
-
* Create a new node page object in node pages
|
|
191
|
-
* @param parentNode - 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md object of the parent node
|
|
192
|
-
* @param boundingVolumes - Bounding volumes
|
|
193
|
-
* @param lodSelection - Level of Details (LOD) metrics
|
|
194
|
-
* @param nodeInPage - corresponding node object in a node page
|
|
195
|
-
* @param resources - the node resources data
|
|
196
|
-
* @param resources.texture - texture image
|
|
197
|
-
* @param resources.attributes - feature attributes
|
|
198
|
-
* @return 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md object
|
|
199
|
-
*/
|
|
200
|
-
private _createNodeIndexDocument;
|
|
201
168
|
/**
|
|
202
169
|
* Write node resources in files
|
|
203
170
|
* @param resources - source tile (3DTile)
|
|
@@ -259,6 +226,14 @@ export default class I3SConverter {
|
|
|
259
226
|
* @return material id
|
|
260
227
|
*/
|
|
261
228
|
private _findOrCreateMaterial;
|
|
229
|
+
/**
|
|
230
|
+
* Get unique geometry configuration index
|
|
231
|
+
* In the end of conversion configurations will be transformed to geometryDefinitions array
|
|
232
|
+
* @param hasTexture
|
|
233
|
+
* @param hasUvRegions
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
private findOrCreateGeometryDefinition;
|
|
262
237
|
/**
|
|
263
238
|
* Do conversion of 3DTiles property table to I3s node attributes.
|
|
264
239
|
* @param propertyTable - Table with layer meta data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i3s-converter.d.ts","sourceRoot":"","sources":["../../src/i3s-converter/i3s-converter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"i3s-converter.d.ts","sourceRoot":"","sources":["../../src/i3s-converter/i3s-converter.ts"],"names":[],"mappings":"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"}
|