@loaders.gl/tile-converter 3.4.11 → 3.4.12
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 +1 -1
- package/dist/converter.min.js +58 -58
- package/dist/dist.min.js +11 -26
- package/dist/es5/3d-tiles-attributes-worker.js +1 -1
- package/dist/es5/deps-installer/deps-installer.js +1 -1
- package/dist/es5/i3s-attributes-worker.js +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -1
- package/dist/esm/i3s-attributes-worker.js +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/package.json +15 -15
- package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -287
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -282
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -52
- package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
- package/dist/bundle.js +0 -5
- package/dist/constants.js +0 -4
- package/dist/converter-cli.js +0 -280
- package/dist/deps-installer/deps-installer.js +0 -63
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -141
- package/dist/i3s-converter/helpers/coordinate-converter.js +0 -124
- package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
- package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
- package/dist/i3s-converter/helpers/geometry-attributes.js +0 -202
- package/dist/i3s-converter/helpers/geometry-converter.js +0 -1195
- package/dist/i3s-converter/helpers/gltf-attributes.js +0 -88
- package/dist/i3s-converter/helpers/node-debug.js +0 -120
- package/dist/i3s-converter/helpers/node-index-document.js +0 -250
- package/dist/i3s-converter/helpers/node-pages.js +0 -316
- package/dist/i3s-converter/i3s-converter.js +0 -890
- package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
- package/dist/i3s-converter/json-templates/layers.js +0 -139
- package/dist/i3s-converter/json-templates/metadata.js +0 -25
- package/dist/i3s-converter/json-templates/node.js +0 -89
- package/dist/i3s-converter/json-templates/scene-server.js +0 -31
- package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
- package/dist/i3s-converter/json-templates/store.js +0 -103
- package/dist/i3s-converter/types.js +0 -2
- package/dist/i3s-server/app.js +0 -14
- package/dist/i3s-server/controllers/index-controller.js +0 -23
- package/dist/i3s-server/routes/index.js +0 -16
- package/dist/index.js +0 -10
- package/dist/lib/utils/compress-util.js +0 -257
- package/dist/lib/utils/file-utils.js +0 -138
- package/dist/lib/utils/lod-conversion-utils.js +0 -76
- package/dist/lib/utils/queue.js +0 -18
- package/dist/lib/utils/statistic-utills.js +0 -64
- package/dist/lib/utils/write-queue.js +0 -80
- package/dist/pgm-loader.js +0 -24
- package/dist/workers/3d-tiles-attributes-worker.js +0 -9
- package/dist/workers/i3s-attributes-worker.js +0 -5
package/dist/converter-cli.js
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint-disable no-console */
|
|
4
|
-
require("@loaders.gl/polyfills");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const tile_converter_1 = require("@loaders.gl/tile-converter");
|
|
7
|
-
const deps_installer_1 = require("./deps-installer/deps-installer");
|
|
8
|
-
const TILESET_TYPE = {
|
|
9
|
-
I3S: 'I3S',
|
|
10
|
-
_3DTILES: '3DTILES'
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* CLI entry
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
async function main() {
|
|
17
|
-
const [, , ...args] = process.argv;
|
|
18
|
-
if (args.length === 0) {
|
|
19
|
-
printHelp();
|
|
20
|
-
}
|
|
21
|
-
const validatedOptionsArr = validateOptionsWithEqual(args);
|
|
22
|
-
const options = parseOptions(validatedOptionsArr);
|
|
23
|
-
if (options.installDependencies) {
|
|
24
|
-
const depthInstaller = new deps_installer_1.DepsInstaller();
|
|
25
|
-
depthInstaller.install('deps');
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const validatedOptions = validateOptions(options);
|
|
29
|
-
await convert(validatedOptions);
|
|
30
|
-
}
|
|
31
|
-
main().catch((error) => {
|
|
32
|
-
console.log(error);
|
|
33
|
-
process.exit(1); // eslint-disable-line
|
|
34
|
-
});
|
|
35
|
-
/**
|
|
36
|
-
* Output for `npx tile-converter --help`
|
|
37
|
-
*/
|
|
38
|
-
function printHelp() {
|
|
39
|
-
console.log('cli: converter 3dTiles to I3S or I3S to 3dTiles...');
|
|
40
|
-
console.log('--install-dependencies [Run the script for installing dependencies. Run this options separate from others. Now "*.pgm" file installation is implemented]');
|
|
41
|
-
console.log('--max-depth [Maximal depth of hierarchical tiles tree traversal, default: infinite]');
|
|
42
|
-
console.log('--name [Tileset name]');
|
|
43
|
-
console.log('--output [Output folder, default: "data" folder]');
|
|
44
|
-
console.log('--instant-node-writing [Keep created 3DNodeIndexDocument files on disk instead of memory. This option reduce memory usage but decelerates conversion speed]');
|
|
45
|
-
console.log('--split-nodes [Prevent to merge similar materials that could lead to incorrect visualization (I3S to 3DTiles conversion only)]');
|
|
46
|
-
console.log('--slpk [Generate slpk (Scene Layer Packages) I3S output file]');
|
|
47
|
-
console.log('--tileset [tileset.json file (3DTiles) / http://..../SceneServer/layers/0 resource (I3S)]');
|
|
48
|
-
console.log('--input-type [tileset input type: I3S or 3DTILES]');
|
|
49
|
-
console.log('--7zExe [location of 7z.exe archiver to create slpk on Windows, default: "C:\\Program Files\\7-Zip\\7z.exe"]');
|
|
50
|
-
console.log('--egm [location of Earth Gravity Model *.pgm file to convert heights from ellipsoidal to gravity-related format. A model file can be loaded from GeographicLib https://geographiclib.sourceforge.io/html/geoid.html], default: "./deps/egm2008-5.zip"');
|
|
51
|
-
console.log('--token [Token for Cesium ION tilesets authentication]');
|
|
52
|
-
console.log('--no-draco [Disable draco compression for geometry]');
|
|
53
|
-
console.log('--generate-textures [Enable KTX2 textures generation if only one of (JPG, PNG) texture is provided or generate JPG texture if only KTX2 is provided]');
|
|
54
|
-
console.log('--generate-bounding-volumes [Will generate obb and mbs bounding volumes from geometry]');
|
|
55
|
-
console.log('--validate [Enable validation]');
|
|
56
|
-
process.exit(0); // eslint-disable-line
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Run conversion process
|
|
60
|
-
* @param options validated tile-converter options
|
|
61
|
-
*/
|
|
62
|
-
async function convert(options) {
|
|
63
|
-
console.log(`------------------------------------------------`); // eslint-disable-line
|
|
64
|
-
console.log(`Starting conversion of ${options.inputType}`); // eslint-disable-line
|
|
65
|
-
console.log(`------------------------------------------------`); // eslint-disable-line
|
|
66
|
-
const inputType = options.inputType.toUpperCase();
|
|
67
|
-
switch (inputType) {
|
|
68
|
-
case TILESET_TYPE.I3S:
|
|
69
|
-
const tiles3DConverter = new tile_converter_1.Tiles3DConverter();
|
|
70
|
-
tiles3DConverter.convert({
|
|
71
|
-
inputUrl: options.tileset,
|
|
72
|
-
outputPath: options.output,
|
|
73
|
-
tilesetName: options.name,
|
|
74
|
-
maxDepth: options.maxDepth,
|
|
75
|
-
egmFilePath: options.egm
|
|
76
|
-
});
|
|
77
|
-
break;
|
|
78
|
-
case TILESET_TYPE._3DTILES:
|
|
79
|
-
const converter = new tile_converter_1.I3SConverter();
|
|
80
|
-
await converter.convert({
|
|
81
|
-
inputUrl: options.tileset,
|
|
82
|
-
outputPath: options.output,
|
|
83
|
-
tilesetName: options.name,
|
|
84
|
-
maxDepth: options.maxDepth,
|
|
85
|
-
slpk: options.slpk,
|
|
86
|
-
sevenZipExe: options.sevenZipExe,
|
|
87
|
-
egmFilePath: options.egm,
|
|
88
|
-
token: options.token,
|
|
89
|
-
draco: options.draco,
|
|
90
|
-
mergeMaterials: options.mergeMaterials,
|
|
91
|
-
generateTextures: options.generateTextures,
|
|
92
|
-
generateBoundingVolumes: options.generateBoundingVolumes,
|
|
93
|
-
validate: options.validate,
|
|
94
|
-
instantNodeWriting: options.instantNodeWriting
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
97
|
-
default:
|
|
98
|
-
printHelp();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// OPTIONS
|
|
102
|
-
/**
|
|
103
|
-
* Validate input options of the CLI command
|
|
104
|
-
* @param options - input options of the CLI command
|
|
105
|
-
* @returns validated options
|
|
106
|
-
*/
|
|
107
|
-
function validateOptions(options) {
|
|
108
|
-
const mandatoryOptionsWithExceptions = {
|
|
109
|
-
name: () => console.log('Missed: --name [Tileset name]'),
|
|
110
|
-
output: () => console.log('Missed: --output [Output path name]'),
|
|
111
|
-
sevenZipExe: () => console.log('Missed: --7zExe [7z archiver executable path]'),
|
|
112
|
-
egm: () => console.log('Missed: --egm [*.pgm earth gravity model file path]'),
|
|
113
|
-
tileset: () => console.log('Missed: --tileset [tileset.json file]'),
|
|
114
|
-
inputType: () => console.log('Missed/Incorrect: --input-type [tileset input type: I3S or 3DTILES]')
|
|
115
|
-
};
|
|
116
|
-
const exceptions = [];
|
|
117
|
-
for (const mandatoryOption in mandatoryOptionsWithExceptions) {
|
|
118
|
-
const optionValue = options[mandatoryOption];
|
|
119
|
-
const isWrongInputType = Boolean(optionValue) &&
|
|
120
|
-
mandatoryOption === 'inputType' &&
|
|
121
|
-
!Object.values(TILESET_TYPE).includes(optionValue.toUpperCase());
|
|
122
|
-
if (!optionValue || isWrongInputType) {
|
|
123
|
-
exceptions.push(mandatoryOptionsWithExceptions[mandatoryOption]);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (exceptions.length) {
|
|
127
|
-
exceptions.forEach((exeption) => exeption());
|
|
128
|
-
process.exit(1);
|
|
129
|
-
}
|
|
130
|
-
return options;
|
|
131
|
-
}
|
|
132
|
-
function validateOptionsWithEqual(args) {
|
|
133
|
-
return args.reduce((acc, curr) => {
|
|
134
|
-
const equalSignIndex = curr.indexOf('=');
|
|
135
|
-
const beforeEqual = curr.slice(0, equalSignIndex);
|
|
136
|
-
const afterEqual = curr.slice(equalSignIndex + 1, curr.length);
|
|
137
|
-
const condition = curr.includes('=') && curr.startsWith('--') && afterEqual;
|
|
138
|
-
if (condition) {
|
|
139
|
-
return acc.concat(beforeEqual, afterEqual);
|
|
140
|
-
}
|
|
141
|
-
return acc.concat(curr);
|
|
142
|
-
}, []);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Parse option from the cli arguments array
|
|
146
|
-
* @param args
|
|
147
|
-
* @returns
|
|
148
|
-
*/
|
|
149
|
-
function parseOptions(args) {
|
|
150
|
-
const opts = {
|
|
151
|
-
output: 'data',
|
|
152
|
-
instantNodeWriting: false,
|
|
153
|
-
mergeMaterials: true,
|
|
154
|
-
sevenZipExe: 'C:\\Program Files\\7-Zip\\7z.exe',
|
|
155
|
-
egm: (0, path_1.join)(process.cwd(), 'deps', 'egm2008-5.pgm'),
|
|
156
|
-
draco: true,
|
|
157
|
-
installDependencies: false,
|
|
158
|
-
generateTextures: false,
|
|
159
|
-
generateBoundingVolumes: false,
|
|
160
|
-
validate: false,
|
|
161
|
-
slpk: false
|
|
162
|
-
};
|
|
163
|
-
// eslint-disable-next-line complexity
|
|
164
|
-
args.forEach((arg, index) => {
|
|
165
|
-
if (arg.indexOf('--') === 0) {
|
|
166
|
-
switch (arg) {
|
|
167
|
-
case '--input-type':
|
|
168
|
-
opts.inputType = getStringValue(index, args);
|
|
169
|
-
break;
|
|
170
|
-
case '--tileset':
|
|
171
|
-
opts.tileset = getURLValue(index, args);
|
|
172
|
-
break;
|
|
173
|
-
case '--name':
|
|
174
|
-
opts.name = getStringValue(index, args);
|
|
175
|
-
break;
|
|
176
|
-
case '--output':
|
|
177
|
-
opts.output = getStringValue(index, args);
|
|
178
|
-
break;
|
|
179
|
-
case '--instant-node-writing':
|
|
180
|
-
opts.instantNodeWriting = getBooleanValue(index, args);
|
|
181
|
-
break;
|
|
182
|
-
case '--split-nodes':
|
|
183
|
-
opts.mergeMaterials = getBooleanValue(index, args);
|
|
184
|
-
break;
|
|
185
|
-
case '--max-depth':
|
|
186
|
-
opts.maxDepth = getIntegerValue(index, args);
|
|
187
|
-
break;
|
|
188
|
-
case '--slpk':
|
|
189
|
-
opts.slpk = getBooleanValue(index, args);
|
|
190
|
-
break;
|
|
191
|
-
case '--7zExe':
|
|
192
|
-
opts.sevenZipExe = getStringValue(index, args);
|
|
193
|
-
break;
|
|
194
|
-
case '--egm':
|
|
195
|
-
opts.egm = getStringValue(index, args);
|
|
196
|
-
break;
|
|
197
|
-
case '--token':
|
|
198
|
-
opts.token = getStringValue(index, args);
|
|
199
|
-
break;
|
|
200
|
-
case '--no-draco':
|
|
201
|
-
opts.draco = getBooleanValue(index, args);
|
|
202
|
-
break;
|
|
203
|
-
case '--validate':
|
|
204
|
-
opts.validate = getBooleanValue(index, args);
|
|
205
|
-
break;
|
|
206
|
-
case '--install-dependencies':
|
|
207
|
-
opts.installDependencies = getBooleanValue(index, args);
|
|
208
|
-
break;
|
|
209
|
-
case '--generate-textures':
|
|
210
|
-
opts.generateTextures = getBooleanValue(index, args);
|
|
211
|
-
break;
|
|
212
|
-
case '--generate-bounding-volumes':
|
|
213
|
-
opts.generateBoundingVolumes = getBooleanValue(index, args);
|
|
214
|
-
break;
|
|
215
|
-
case '--help':
|
|
216
|
-
printHelp();
|
|
217
|
-
break;
|
|
218
|
-
default:
|
|
219
|
-
console.warn(`Unknown option ${arg}`);
|
|
220
|
-
process.exit(0); // eslint-disable-line
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
return opts;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Get string option value from cli arguments
|
|
228
|
-
* @param index - option's name index in the argument's array.
|
|
229
|
-
* The value of the option should be next to name of the option.
|
|
230
|
-
* @param args - cli arguments array
|
|
231
|
-
* @returns - string value of the option
|
|
232
|
-
*/
|
|
233
|
-
function getStringValue(index, args) {
|
|
234
|
-
if (index + 1 >= args.length) {
|
|
235
|
-
return '';
|
|
236
|
-
}
|
|
237
|
-
const value = args[index + 1];
|
|
238
|
-
if (value.indexOf('--') === 0) {
|
|
239
|
-
return '';
|
|
240
|
-
}
|
|
241
|
-
return value;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Modyfy URL path to be compatible with fetch
|
|
245
|
-
* @param index - option's name index in the argument's array.
|
|
246
|
-
* The value of the option should be next to name of the option.
|
|
247
|
-
* @param args - cli arguments array
|
|
248
|
-
* @returns - string value of the option
|
|
249
|
-
*/
|
|
250
|
-
function getURLValue(index, args) {
|
|
251
|
-
const value = getStringValue(index, args);
|
|
252
|
-
console.log(`Input tileset value: ${value}`);
|
|
253
|
-
console.log(`Modified tileset value: ${value.replace(/\\/g, '/')}`);
|
|
254
|
-
return value.replace(/\\/g, '/');
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Get integer option value from cli arguments
|
|
258
|
-
* @param index - option's name index in the argument's array
|
|
259
|
-
* The value of the option should be next to name of the option.
|
|
260
|
-
* @param args - cli arguments array
|
|
261
|
-
* @returns - number value of the option
|
|
262
|
-
*/
|
|
263
|
-
function getIntegerValue(index, args) {
|
|
264
|
-
const stringValue = getStringValue(index, args);
|
|
265
|
-
const result = Number.parseInt(stringValue);
|
|
266
|
-
if (isFinite(result)) {
|
|
267
|
-
return result;
|
|
268
|
-
}
|
|
269
|
-
return NaN;
|
|
270
|
-
}
|
|
271
|
-
function getBooleanValue(index, args) {
|
|
272
|
-
const stringValue = getStringValue(index, args).toLowerCase().trim();
|
|
273
|
-
if (['--no-draco', '--split-nodes'].includes(args[index]) && !stringValue) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
if (!stringValue || stringValue === 'true') {
|
|
277
|
-
return true;
|
|
278
|
-
}
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DepsInstaller = void 0;
|
|
4
|
-
const core_1 = require("@loaders.gl/core");
|
|
5
|
-
const zip_1 = require("@loaders.gl/zip");
|
|
6
|
-
const file_utils_1 = require("../lib/utils/file-utils");
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
9
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
10
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
|
-
const PGM_LINK = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/egm/egm2008-5.zip';
|
|
12
|
-
/**
|
|
13
|
-
* Install external dependencies for converter:
|
|
14
|
-
* * PGM file (implemented);
|
|
15
|
-
* * Draco library (not implemented);
|
|
16
|
-
* * 7z archiver (not implemented);
|
|
17
|
-
*/
|
|
18
|
-
class DepsInstaller {
|
|
19
|
-
/**
|
|
20
|
-
* Run instalation
|
|
21
|
-
* @param path destination folder
|
|
22
|
-
* @param workersPath destination folder for workers.
|
|
23
|
-
* This path is '' by default and is not used by tile-converter.
|
|
24
|
-
* It is used in tests to prevent rewriting actual workers during tests running
|
|
25
|
-
*/
|
|
26
|
-
async install(path = '', workersPath = '') {
|
|
27
|
-
console.log('Installing "EGM2008-5" model...'); // eslint-disable-line no-console
|
|
28
|
-
const fileMap = await (0, core_1.load)(PGM_LINK, zip_1.ZipLoader, {});
|
|
29
|
-
let depsPath = process.cwd();
|
|
30
|
-
if (path) {
|
|
31
|
-
depsPath = (0, path_1.join)(depsPath, path);
|
|
32
|
-
}
|
|
33
|
-
await (0, file_utils_1.writeFile)(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');
|
|
34
|
-
console.log('Installing "I3S Content Loader worker"'); // eslint-disable-line no-console
|
|
35
|
-
await this.installWorker('i3s', 'i3s-content-nodejs-worker.js', workersPath);
|
|
36
|
-
console.log('Installing "Draco Loader worker"'); // eslint-disable-line no-console
|
|
37
|
-
await this.installWorker('draco', 'draco-nodejs-worker.js', workersPath);
|
|
38
|
-
console.log('Installing "Basis Loader worker"'); // eslint-disable-line no-console
|
|
39
|
-
await this.installWorker('textures', 'basis-nodejs-worker.js', workersPath);
|
|
40
|
-
console.log('Installing "join-images" npm package');
|
|
41
|
-
const childProcess = new worker_utils_1.ChildProcessProxy();
|
|
42
|
-
await childProcess.start({
|
|
43
|
-
command: process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
|
44
|
-
// `npm install sharp join-images` works unstable. It fails because installed `sharp` version
|
|
45
|
-
// may be different from the version required by `join-images`. Pointing to specific versions
|
|
46
|
-
// resolve this issue
|
|
47
|
-
arguments: ['install', 'sharp@0.30.4', 'join-images@1.1.3'],
|
|
48
|
-
wait: 0,
|
|
49
|
-
ignoreStderr: true
|
|
50
|
-
});
|
|
51
|
-
console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console
|
|
52
|
-
}
|
|
53
|
-
async installWorker(module, name, extraPath) {
|
|
54
|
-
const fileResponse = await (0, core_1.fetchFile)(`https://unpkg.com/@loaders.gl/${module}@${VERSION}/dist/${name}`);
|
|
55
|
-
const fileData = await fileResponse.arrayBuffer();
|
|
56
|
-
if (!fileData) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const path = (0, path_1.join)(process.cwd(), extraPath, 'modules', module, 'dist');
|
|
60
|
-
await (0, file_utils_1.writeFile)(path, fileData, name);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.DepsInstaller = DepsInstaller;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleBatchIdsExtensions = void 0;
|
|
4
|
-
const EXT_MESH_FEATURES = 'EXT_mesh_features';
|
|
5
|
-
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
6
|
-
/**
|
|
7
|
-
* Getting batchIds from 3DTilesNext extensions.
|
|
8
|
-
* @param attributes - gltf accessors
|
|
9
|
-
* @param primitive - gltf primitive data
|
|
10
|
-
* @param images - gltf texture images
|
|
11
|
-
*/
|
|
12
|
-
function handleBatchIdsExtensions(attributes, primitive, images) {
|
|
13
|
-
const extensions = primitive?.extensions;
|
|
14
|
-
if (!extensions) {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
for (const [extensionName, extensionData] of Object.entries(extensions || {})) {
|
|
18
|
-
switch (extensionName) {
|
|
19
|
-
case EXT_FEATURE_METADATA:
|
|
20
|
-
return handleExtFeatureMetadataExtension(attributes, extensionData, images);
|
|
21
|
-
case EXT_MESH_FEATURES:
|
|
22
|
-
console.warn('EXT_mesh_features extension is not supported yet');
|
|
23
|
-
return [];
|
|
24
|
-
default:
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
exports.handleBatchIdsExtensions = handleBatchIdsExtensions;
|
|
31
|
-
/**
|
|
32
|
-
* Get batchIds from EXT_feature_metadata extension.
|
|
33
|
-
* Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata
|
|
34
|
-
* @param attributes
|
|
35
|
-
* @param extFeatureMetadata
|
|
36
|
-
* @param textures
|
|
37
|
-
*/
|
|
38
|
-
function handleExtFeatureMetadataExtension(attributes, extFeatureMetadata, images) {
|
|
39
|
-
// Take only first extension object to get batchIds attribute name.
|
|
40
|
-
const featureIdAttribute = extFeatureMetadata?.featureIdAttributes?.[0];
|
|
41
|
-
if (featureIdAttribute?.featureIds?.attribute) {
|
|
42
|
-
const batchIdsAttribute = attributes[featureIdAttribute.featureIds.attribute];
|
|
43
|
-
return batchIdsAttribute.value;
|
|
44
|
-
}
|
|
45
|
-
if (featureIdAttribute?.featureIds?.hasOwnProperty('constant') &&
|
|
46
|
-
featureIdAttribute?.featureIds?.hasOwnProperty('divisor')) {
|
|
47
|
-
const featuresCount = attributes?.POSITIONS?.value.length / 3 || 0;
|
|
48
|
-
return generateImplicitFeatureIds(featuresCount, featureIdAttribute.featureIds.constant, featureIdAttribute.featureIds.divisor);
|
|
49
|
-
}
|
|
50
|
-
// Take only first extension object to get batchIds attribute name.
|
|
51
|
-
const featureIdTexture = extFeatureMetadata?.featureIdTextures && extFeatureMetadata?.featureIdTextures[0];
|
|
52
|
-
if (featureIdTexture) {
|
|
53
|
-
const textureAttributeIndex = featureIdTexture?.featureIds?.texture?.texCoord || 0;
|
|
54
|
-
const textCoordAttribute = `TEXCOORD_${textureAttributeIndex}`;
|
|
55
|
-
const textureCoordinates = attributes[textCoordAttribute].value;
|
|
56
|
-
return generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images);
|
|
57
|
-
}
|
|
58
|
-
// Take only first extension texture to get batchIds from the root EXT_feature_metadata object.
|
|
59
|
-
const featureTexture = extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];
|
|
60
|
-
/**
|
|
61
|
-
* TODO need to get batchIds from root extension
|
|
62
|
-
*/
|
|
63
|
-
if (featureTexture) {
|
|
64
|
-
console.warn("EXT_feature_metadata doesn't yet support featureTextures in primitive");
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
return [];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Generates implicit feature ids
|
|
71
|
-
* Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids
|
|
72
|
-
* @param featuresCount
|
|
73
|
-
* @param constant
|
|
74
|
-
* @param devisor
|
|
75
|
-
*/
|
|
76
|
-
function generateImplicitFeatureIds(featuresCount, constant = 0, divisor = 0) {
|
|
77
|
-
let featureIds = [];
|
|
78
|
-
if (divisor > 0) {
|
|
79
|
-
let currentValue = constant;
|
|
80
|
-
let devisorCounter = divisor;
|
|
81
|
-
for (let index = 0; index < featuresCount; index++) {
|
|
82
|
-
featureIds.push(currentValue);
|
|
83
|
-
devisorCounter -= 1;
|
|
84
|
-
if (devisorCounter === 0) {
|
|
85
|
-
currentValue++;
|
|
86
|
-
devisorCounter = divisor;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
featureIds = Array(featuresCount).fill(constant, 0, featuresCount);
|
|
92
|
-
}
|
|
93
|
-
return featureIds;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Get batchIds from texture.
|
|
97
|
-
* @param primitive
|
|
98
|
-
* @param featureIdTextures
|
|
99
|
-
*/
|
|
100
|
-
function generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, images) {
|
|
101
|
-
if (!images?.length) {
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
const CHANNELS_MAP = {
|
|
105
|
-
r: 0,
|
|
106
|
-
g: 1,
|
|
107
|
-
b: 2,
|
|
108
|
-
a: 3
|
|
109
|
-
};
|
|
110
|
-
const textureIndex = featureIdTexture?.featureIds?.texture?.index;
|
|
111
|
-
const featureChannel = featureIdTexture?.featureIds?.channels;
|
|
112
|
-
if (!featureChannel || textureIndex === undefined) {
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
const image = images[textureIndex];
|
|
116
|
-
const batchIds = [];
|
|
117
|
-
const channels = CHANNELS_MAP[featureChannel];
|
|
118
|
-
if (!image.compressed) {
|
|
119
|
-
for (let index = 0; index < textureCoordinates.length; index += 2) {
|
|
120
|
-
const u = textureCoordinates[index];
|
|
121
|
-
const v = textureCoordinates[index + 1];
|
|
122
|
-
const tx = Math.min((emod(u) * image.width) | 0, image.width - 1);
|
|
123
|
-
const ty = Math.min((emod(v) * image.height) | 0, image.height - 1);
|
|
124
|
-
const offset = (ty * image.width + tx) * image.components + channels;
|
|
125
|
-
const batchId = new Uint8Array(image.data)[offset];
|
|
126
|
-
batchIds.push(batchId);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);
|
|
131
|
-
}
|
|
132
|
-
return batchIds;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Handle UVs if they are out of range [0,1].
|
|
136
|
-
* @param n
|
|
137
|
-
* @param m
|
|
138
|
-
*/
|
|
139
|
-
function emod(n) {
|
|
140
|
-
return ((n % 1) + 1) % 1;
|
|
141
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createObbFromMbs = exports.convertBoundingVolumeToI3SFullExtent = exports.convertPositionsToVectors = exports.createBoundingVolumesFromGeometry = exports.createBoundingVolumes = void 0;
|
|
4
|
-
const core_1 = require("@math.gl/core");
|
|
5
|
-
const geospatial_1 = require("@math.gl/geospatial");
|
|
6
|
-
const culling_1 = require("@math.gl/culling");
|
|
7
|
-
/**
|
|
8
|
-
* Create bounding volumes object from tile and geoid height model.
|
|
9
|
-
* @param tile
|
|
10
|
-
* @param geoidHeightModel
|
|
11
|
-
* @returns - Bounding volumes object
|
|
12
|
-
*/
|
|
13
|
-
function createBoundingVolumes(tile, geoidHeightModel) {
|
|
14
|
-
let radius;
|
|
15
|
-
let halfSize;
|
|
16
|
-
let quaternion;
|
|
17
|
-
const boundingVolume = tile.boundingVolume;
|
|
18
|
-
const cartographicCenter = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(boundingVolume.center, new core_1.Vector3());
|
|
19
|
-
cartographicCenter[2] =
|
|
20
|
-
cartographicCenter[2] -
|
|
21
|
-
geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);
|
|
22
|
-
if (boundingVolume instanceof culling_1.OrientedBoundingBox) {
|
|
23
|
-
halfSize = boundingVolume.halfSize;
|
|
24
|
-
radius = new core_1.Vector3(halfSize[0], halfSize[1], halfSize[2]).len();
|
|
25
|
-
quaternion = boundingVolume.quaternion;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
radius = tile.boundingVolume.radius;
|
|
29
|
-
halfSize = [radius, radius, radius];
|
|
30
|
-
quaternion = new core_1.Quaternion()
|
|
31
|
-
.fromMatrix3(new core_1.Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))
|
|
32
|
-
.normalize();
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],
|
|
36
|
-
obb: {
|
|
37
|
-
center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],
|
|
38
|
-
halfSize,
|
|
39
|
-
quaternion
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
exports.createBoundingVolumes = createBoundingVolumes;
|
|
44
|
-
/**
|
|
45
|
-
* Generates bounding volumes from geometry positions
|
|
46
|
-
* @param cartesianPositions
|
|
47
|
-
* @param geoidHeightModel
|
|
48
|
-
*/
|
|
49
|
-
function createBoundingVolumesFromGeometry(cartesianPositions, geoidHeightModel) {
|
|
50
|
-
const positionVectors = convertPositionsToVectors(cartesianPositions);
|
|
51
|
-
const geometryObb = (0, culling_1.makeOrientedBoundingBoxFromPoints)(positionVectors);
|
|
52
|
-
const geometryMbs = (0, culling_1.makeBoundingSphereFromPoints)(positionVectors);
|
|
53
|
-
let mbsCenter = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new core_1.Vector3());
|
|
54
|
-
let obbCenter = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new core_1.Vector3());
|
|
55
|
-
mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);
|
|
56
|
-
obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);
|
|
57
|
-
return {
|
|
58
|
-
mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],
|
|
59
|
-
obb: {
|
|
60
|
-
center: obbCenter,
|
|
61
|
-
halfSize: geometryObb.halfSize,
|
|
62
|
-
quaternion: geometryObb.quaternion
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
exports.createBoundingVolumesFromGeometry = createBoundingVolumesFromGeometry;
|
|
67
|
-
/**
|
|
68
|
-
* Create array of posisitons where each vertex is vector
|
|
69
|
-
* @param {array} positions
|
|
70
|
-
* @returns {Vector3[]}
|
|
71
|
-
*/
|
|
72
|
-
function convertPositionsToVectors(positions) {
|
|
73
|
-
const result = [];
|
|
74
|
-
for (let i = 0; i < positions.length; i += 3) {
|
|
75
|
-
// TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.
|
|
76
|
-
// modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors
|
|
77
|
-
const positionVector = new core_1.Vector3([positions[i], positions[i + 1], positions[i + 2]]);
|
|
78
|
-
result.push(positionVector);
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
exports.convertPositionsToVectors = convertPositionsToVectors;
|
|
83
|
-
/**
|
|
84
|
-
* Convert common coordinate to fullExtent https://github.com/Esri/i3s-spec/blob/master/docs/1.8/fullExtent.cmn.md
|
|
85
|
-
* @param
|
|
86
|
-
* @param boundingVolume
|
|
87
|
-
* @returns - fullExtent object
|
|
88
|
-
*/
|
|
89
|
-
function convertBoundingVolumeToI3SFullExtent(boundingVolume) {
|
|
90
|
-
let sphere;
|
|
91
|
-
if (boundingVolume instanceof culling_1.BoundingSphere) {
|
|
92
|
-
sphere = boundingVolume;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
sphere = boundingVolume.getBoundingSphere();
|
|
96
|
-
}
|
|
97
|
-
const center = sphere.center;
|
|
98
|
-
const radius = sphere.radius;
|
|
99
|
-
const vertexMax = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(new core_1.Vector3(center[0] + radius, center[1] + radius, center[2] + radius), new core_1.Vector3());
|
|
100
|
-
const vertexMin = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(new core_1.Vector3(center[0] - radius, center[1] - radius, center[2] - radius), new core_1.Vector3());
|
|
101
|
-
// Converter sometimes returns min values that are bigger then max,
|
|
102
|
-
// so we should check and take bigger value from max and smaller for nim
|
|
103
|
-
return {
|
|
104
|
-
xmin: Math.min(vertexMin[0], vertexMax[0]),
|
|
105
|
-
xmax: Math.max(vertexMin[0], vertexMax[0]),
|
|
106
|
-
ymin: Math.min(vertexMin[1], vertexMax[1]),
|
|
107
|
-
ymax: Math.max(vertexMin[1], vertexMax[1]),
|
|
108
|
-
zmin: Math.min(vertexMin[2], vertexMax[2]),
|
|
109
|
-
zmax: Math.max(vertexMin[2], vertexMax[2])
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
exports.convertBoundingVolumeToI3SFullExtent = convertBoundingVolumeToI3SFullExtent;
|
|
113
|
-
/**
|
|
114
|
-
* Creates oriented boundinb box from mbs.
|
|
115
|
-
* @param mbs - Minimum Bounding Sphere
|
|
116
|
-
* @returns - Oriented BOunding Box
|
|
117
|
-
*/
|
|
118
|
-
function createObbFromMbs(mbs) {
|
|
119
|
-
const radius = mbs[3];
|
|
120
|
-
const center = new core_1.Vector3(mbs[0], mbs[1], mbs[2]);
|
|
121
|
-
const halfAxex = new core_1.Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);
|
|
122
|
-
return new culling_1.OrientedBoundingBox(center, halfAxex);
|
|
123
|
-
}
|
|
124
|
-
exports.createObbFromMbs = createObbFromMbs;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createSceneServerPath = void 0;
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
8
|
-
const json_map_transform_1 = __importDefault(require("json-map-transform"));
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const scene_server_1 = require("../json-templates/scene-server");
|
|
11
|
-
const file_utils_1 = require("../../lib/utils/file-utils");
|
|
12
|
-
/**
|
|
13
|
-
* Form and save sceneServer meta data into a file
|
|
14
|
-
* @param layerName - layer name to display
|
|
15
|
-
* @param layers0 - layer object embedded into sceneServer meta data
|
|
16
|
-
* @param rootPath - root path of new converted tileset
|
|
17
|
-
*/
|
|
18
|
-
async function createSceneServerPath(layerName, layers0, rootPath) {
|
|
19
|
-
const sceneServerData = {
|
|
20
|
-
serviceItemId: (0, uuid_1.v4)().replace(/-/gi, ''),
|
|
21
|
-
layerName,
|
|
22
|
-
layers0
|
|
23
|
-
};
|
|
24
|
-
const sceneServer = (0, json_map_transform_1.default)(sceneServerData, (0, scene_server_1.SCENE_SERVER)());
|
|
25
|
-
const nodePagePath = (0, path_1.join)(rootPath, 'SceneServer');
|
|
26
|
-
await (0, file_utils_1.writeFile)(nodePagePath, JSON.stringify(sceneServer));
|
|
27
|
-
}
|
|
28
|
-
exports.createSceneServerPath = createSceneServerPath;
|