@loaders.gl/tile-converter 4.1.0-alpha.1 → 4.1.0-alpha.10
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/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/converter-cli.js +41 -4
- package/dist/converter-cli.js.map +1 -1
- package/dist/converter.min.cjs +110 -110
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/deps-installer/deps-installer.js +4 -3
- package/dist/deps-installer/deps-installer.js.map +1 -1
- package/dist/i3s-converter/i3s-converter.d.ts +14 -0
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +71 -17
- package/dist/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/i3s-converter/types.d.ts +7 -0
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/i3s-converter/types.js +8 -0
- package/dist/i3s-converter/types.js.map +1 -1
- package/dist/i3s-server/bin/i3s-server.min.cjs +72 -72
- package/dist/index.cjs +347 -38
- package/dist/lib/utils/conversion-dump.d.ts +80 -0
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -0
- package/dist/lib/utils/conversion-dump.js +127 -0
- package/dist/lib/utils/conversion-dump.js.map +1 -0
- package/dist/lib/utils/statistic-utills.d.ts +23 -6
- package/dist/lib/utils/write-queue.d.ts +6 -1
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +15 -3
- package/dist/lib/utils/write-queue.js.map +1 -1
- package/dist/pgm-loader.js +1 -1
- package/dist/pgm-loader.js.map +1 -1
- package/dist/slpk-extractor.min.cjs +46 -46
- package/package.json +16 -16
- package/src/constants.ts +1 -0
- package/src/converter-cli.ts +58 -4
- package/src/deps-installer/deps-installer.ts +3 -2
- package/src/i3s-converter/i3s-converter.ts +189 -21
- package/src/i3s-converter/types.ts +8 -0
- package/src/lib/utils/conversion-dump.ts +198 -0
- package/src/lib/utils/write-queue.ts +15 -2
- package/dist/lib/utils/statistic-utills.d.js +0 -2
- package/dist/lib/utils/statistic-utills.d.js.map +0 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {DUMP_FILE_SUFFIX} from '../../constants';
|
|
2
|
+
import {removeFile, writeFile} from './file-utils';
|
|
3
|
+
import {join} from 'path';
|
|
4
|
+
|
|
5
|
+
export type ConversionDumpOptions = {
|
|
6
|
+
inputUrl: string;
|
|
7
|
+
outputPath: string;
|
|
8
|
+
tilesetName: string;
|
|
9
|
+
maxDepth: number;
|
|
10
|
+
slpk: boolean;
|
|
11
|
+
egmFilePath: string;
|
|
12
|
+
token: string;
|
|
13
|
+
draco: boolean;
|
|
14
|
+
mergeMaterials: boolean;
|
|
15
|
+
generateTextures: boolean;
|
|
16
|
+
generateBoundingVolumes: boolean;
|
|
17
|
+
metadataClass: string;
|
|
18
|
+
analyze: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type NodeDoneStatus = {
|
|
22
|
+
nodeId: number;
|
|
23
|
+
done: Record<string, boolean> | boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type TilesConverted = {
|
|
27
|
+
nodes: NodeDoneStatus[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class ConversionDump {
|
|
31
|
+
/** Conversion options */
|
|
32
|
+
private options?: ConversionDumpOptions;
|
|
33
|
+
/** Tiles conversion progress status map */
|
|
34
|
+
tilesConverted: Record<string, TilesConverted>;
|
|
35
|
+
|
|
36
|
+
constructor() {
|
|
37
|
+
this.tilesConverted = {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create a dump file with convertion options
|
|
42
|
+
* @param options - converter options
|
|
43
|
+
*/
|
|
44
|
+
async createDumpFile(options: ConversionDumpOptions): Promise<void> {
|
|
45
|
+
const {
|
|
46
|
+
tilesetName,
|
|
47
|
+
slpk,
|
|
48
|
+
egmFilePath,
|
|
49
|
+
inputUrl,
|
|
50
|
+
outputPath,
|
|
51
|
+
draco = true,
|
|
52
|
+
maxDepth,
|
|
53
|
+
token,
|
|
54
|
+
generateTextures,
|
|
55
|
+
generateBoundingVolumes,
|
|
56
|
+
mergeMaterials = true,
|
|
57
|
+
metadataClass,
|
|
58
|
+
analyze = false
|
|
59
|
+
} = options;
|
|
60
|
+
this.options = {
|
|
61
|
+
tilesetName,
|
|
62
|
+
slpk,
|
|
63
|
+
egmFilePath,
|
|
64
|
+
inputUrl,
|
|
65
|
+
outputPath,
|
|
66
|
+
draco,
|
|
67
|
+
maxDepth,
|
|
68
|
+
token,
|
|
69
|
+
generateTextures,
|
|
70
|
+
generateBoundingVolumes,
|
|
71
|
+
mergeMaterials,
|
|
72
|
+
metadataClass,
|
|
73
|
+
analyze
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await writeFile(
|
|
78
|
+
options.outputPath,
|
|
79
|
+
JSON.stringify({options: this.options}),
|
|
80
|
+
`${options.tilesetName}${DUMP_FILE_SUFFIX}`
|
|
81
|
+
);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.log("Can't create dump file", error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Update conversion status in the dump file
|
|
89
|
+
*/
|
|
90
|
+
private async updateDumpFile(): Promise<void> {
|
|
91
|
+
if (this.options?.outputPath && this.options.tilesetName) {
|
|
92
|
+
try {
|
|
93
|
+
await writeFile(
|
|
94
|
+
this.options.outputPath,
|
|
95
|
+
JSON.stringify({
|
|
96
|
+
options: this.options,
|
|
97
|
+
tilesConverted: this.tilesConverted
|
|
98
|
+
}),
|
|
99
|
+
`${this.options.tilesetName}${DUMP_FILE_SUFFIX}`
|
|
100
|
+
);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.log("Can't update dump file", error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Delete a dump file
|
|
109
|
+
*/
|
|
110
|
+
async deleteDumpFile(): Promise<void> {
|
|
111
|
+
if (this.options?.outputPath && this.options.tilesetName) {
|
|
112
|
+
await removeFile(
|
|
113
|
+
join(this.options.outputPath, `${this.options.tilesetName}${DUMP_FILE_SUFFIX}`)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get record from the tilesConverted Map
|
|
120
|
+
* @param fileName - source filename
|
|
121
|
+
* @returns existing object from the tilesConverted Map
|
|
122
|
+
*/
|
|
123
|
+
private getRecord(fileName: string) {
|
|
124
|
+
return this.tilesConverted[fileName];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Set a record for the dump file
|
|
129
|
+
* @param fileName - key - source filename
|
|
130
|
+
* @param object - value
|
|
131
|
+
*/
|
|
132
|
+
private setRecord(fileName: string, object: any) {
|
|
133
|
+
this.tilesConverted[fileName] = object;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Add a node into the dump file for the source file record
|
|
138
|
+
* @param fileName - source filename
|
|
139
|
+
* @param nodeId - nodeId of the node
|
|
140
|
+
*/
|
|
141
|
+
async addNode(filename: string, nodeId: number) {
|
|
142
|
+
const {nodes} = this.getRecord(filename) || {nodes: []};
|
|
143
|
+
nodes.push({nodeId, done: {}});
|
|
144
|
+
if (nodes.length === 1) {
|
|
145
|
+
this.setRecord(filename, {nodes});
|
|
146
|
+
}
|
|
147
|
+
await this.updateDumpFile();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Update done status object for the writing resources
|
|
152
|
+
* @param fileName - key - source filename
|
|
153
|
+
* @param nodeId - nodeId for the source filename
|
|
154
|
+
* @param resourceType - resource type to update status
|
|
155
|
+
* @param value - value
|
|
156
|
+
*/
|
|
157
|
+
updateDoneStatus(filename: string, nodeId: number, resourceType: string, value: boolean) {
|
|
158
|
+
const nodeDump = this.tilesConverted[filename]?.nodes.find(
|
|
159
|
+
(element) => element.nodeId === nodeId
|
|
160
|
+
);
|
|
161
|
+
if (nodeDump) {
|
|
162
|
+
nodeDump.done[resourceType] = value;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Update dump file according to writing results
|
|
168
|
+
* @param changedRecords - array of parameters ids for the written resources
|
|
169
|
+
* @param writeResults - array of writing resource files results
|
|
170
|
+
*/
|
|
171
|
+
async updateConvertedTilesDump(
|
|
172
|
+
changedRecords: {outputId?: number; sourceId?: string; resourceType?: string}[],
|
|
173
|
+
writeResults: PromiseSettledResult<string | null>[]
|
|
174
|
+
) {
|
|
175
|
+
for (let i = 0; i < changedRecords.length; i++) {
|
|
176
|
+
if (changedRecords[i] && 'value' in writeResults[i]) {
|
|
177
|
+
const {sourceId, resourceType, outputId} = changedRecords[i];
|
|
178
|
+
if (!sourceId || !resourceType || !outputId) continue;
|
|
179
|
+
for (const node of this.tilesConverted[sourceId].nodes) {
|
|
180
|
+
if (typeof node.done !== 'boolean' && node.nodeId === outputId) {
|
|
181
|
+
node.done[resourceType] = true;
|
|
182
|
+
}
|
|
183
|
+
if (typeof node.done !== 'boolean') {
|
|
184
|
+
let done = false;
|
|
185
|
+
for (const key in node.done) {
|
|
186
|
+
done = node.done[key];
|
|
187
|
+
if (!done) break;
|
|
188
|
+
}
|
|
189
|
+
if (done) {
|
|
190
|
+
node.done = true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
await this.updateDumpFile();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {Queue} from './queue';
|
|
2
2
|
import process from 'process';
|
|
3
|
+
import {ConversionDump} from './conversion-dump';
|
|
3
4
|
|
|
4
5
|
/** Memory limit size is based on testing */
|
|
5
6
|
const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB
|
|
6
7
|
|
|
7
8
|
export type WriteQueueItem = {
|
|
8
9
|
archiveKey?: string;
|
|
10
|
+
sourceId?: string;
|
|
11
|
+
outputId?: number;
|
|
12
|
+
resourceType?: string;
|
|
9
13
|
/**
|
|
10
14
|
* writePromise() returns a Promise that will be awaited in Promise.allSettled(promises);
|
|
11
15
|
* Arguments for this call are specified in writeQueue.enqueue call like this:
|
|
@@ -27,13 +31,19 @@ export type WriteQueueItem = {
|
|
|
27
31
|
|
|
28
32
|
export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
29
33
|
private intervalId?: NodeJS.Timeout;
|
|
34
|
+
private conversionDump: ConversionDump;
|
|
30
35
|
public writePromise: Promise<void> | null = null;
|
|
31
36
|
public fileMap: {[key: string]: string} = {};
|
|
32
37
|
public listeningInterval: number;
|
|
33
38
|
public writeConcurrency: number;
|
|
34
39
|
|
|
35
|
-
constructor(
|
|
40
|
+
constructor(
|
|
41
|
+
conversionDump: ConversionDump,
|
|
42
|
+
listeningInterval: number = 2000,
|
|
43
|
+
writeConcurrency: number = 400
|
|
44
|
+
) {
|
|
36
45
|
super();
|
|
46
|
+
this.conversionDump = conversionDump;
|
|
37
47
|
this.listeningInterval = listeningInterval;
|
|
38
48
|
this.writeConcurrency = writeConcurrency;
|
|
39
49
|
}
|
|
@@ -81,18 +91,21 @@ export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
|
81
91
|
while (this.length) {
|
|
82
92
|
const promises: Promise<string | null>[] = [];
|
|
83
93
|
const archiveKeys: (string | undefined)[] = [];
|
|
94
|
+
const changedRecords: {outputId?: number; sourceId?: string; resourceType?: string}[] = [];
|
|
84
95
|
for (let i = 0; i < this.writeConcurrency; i++) {
|
|
85
96
|
const item = this.dequeue();
|
|
86
97
|
if (!item) {
|
|
87
98
|
break;
|
|
88
99
|
}
|
|
89
|
-
const {archiveKey, writePromise} = item as WriteQueueItem;
|
|
100
|
+
const {archiveKey, sourceId, outputId, resourceType, writePromise} = item as WriteQueueItem;
|
|
90
101
|
archiveKeys.push(archiveKey);
|
|
102
|
+
changedRecords.push({sourceId, outputId, resourceType});
|
|
91
103
|
const promise = writePromise();
|
|
92
104
|
promises.push(promise);
|
|
93
105
|
}
|
|
94
106
|
const writeResults = await Promise.allSettled(promises);
|
|
95
107
|
this.updateFileMap(archiveKeys, writeResults);
|
|
108
|
+
await this.conversionDump.updateConvertedTilesDump(changedRecords, writeResults);
|
|
96
109
|
}
|
|
97
110
|
}
|
|
98
111
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"statistic-utills.d.js","names":[],"sources":["../../../src/lib/utils/statistic-utills.d.ts"],"sourcesContent":["/**\n * Do milliseconds time conversion to readable time string.\n * @param tile - 3d-tiles tile Object\n * @param coordinates - node converted coordinates\n * @returns String which characterizes conversion time period\n */\nexport function timeConverter(time: [number, number]): String;\n\n/**\n * Calculate files sizes after conversion.\n * @param params - Object with params of conversion.\n * @returns Promise with generated files size in bytes.\n */\nexport function calculateFilesSize(params: {\n slpk: boolean;\n outputPath: string;\n tilesetName: string;\n}): Number;\n\n/**\n * Reqursivelly calculate files sizes in directory.\n * @param dirPath - Directory path.\n * @returns Promise with files size in directory.\n */\nexport function getTotalFilesSize(dirPath: string): Number;\n"],"mappings":""}
|