@loaders.gl/tile-converter 3.4.0-alpha.2 → 3.4.0-alpha.4
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.min.js +90 -2875
- package/dist/dist.min.js +1823 -19725
- package/dist/es5/3d-tiles-attributes-worker.js +1 -2
- package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +264 -287
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +89 -113
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +0 -2
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/converter-cli.js +67 -81
- package/dist/es5/converter-cli.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +64 -69
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +1 -2
- package/dist/es5/i3s-attributes-worker.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +0 -8
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +0 -5
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +14 -16
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +1 -11
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +3 -10
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +427 -457
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +0 -2
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +3 -13
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +293 -318
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +279 -319
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +964 -1030
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +28 -30
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +15 -18
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/utils/compress-util.js +198 -218
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +118 -128
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +0 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/queue.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +81 -85
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/lib/utils/write-queue.js +84 -92
- package/dist/es5/lib/utils/write-queue.js.map +1 -1
- package/dist/es5/pgm-loader.js +7 -10
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/workers/3d-tiles-attributes-worker.js +7 -9
- package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js +10 -12
- package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +1 -3
- package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +1 -15
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +0 -12
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -1
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +0 -3
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/esm/bundle.js +0 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/converter-cli.js +0 -11
- package/dist/esm/converter-cli.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -4
- package/dist/esm/deps-installer/deps-installer.js.map +1 -1
- package/dist/esm/i3s-attributes-worker.js +1 -3
- package/dist/esm/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +0 -8
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js +0 -5
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +0 -1
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/feature-attributes.js +0 -11
- package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +0 -7
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +30 -56
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js +0 -3
- package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-debug.js +3 -13
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-index-document.js +0 -14
- package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-pages.js +0 -18
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +4 -42
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/geometry-definitions.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/i3s-server/app.js.map +1 -1
- package/dist/esm/i3s-server/controllers/index-controller.js +0 -2
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/esm/i3s-server/routes/index.js +0 -1
- package/dist/esm/i3s-server/routes/index.js.map +1 -1
- package/dist/esm/lib/utils/compress-util.js +1 -17
- package/dist/esm/lib/utils/compress-util.js.map +1 -1
- package/dist/esm/lib/utils/file-utils.js +0 -7
- package/dist/esm/lib/utils/file-utils.js.map +1 -1
- package/dist/esm/lib/utils/lod-conversion-utils.js +0 -2
- package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/esm/lib/utils/queue.js.map +1 -1
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
- package/dist/esm/lib/utils/write-queue.js +0 -2
- package/dist/esm/lib/utils/write-queue.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -3
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/esm/workers/3d-tiles-attributes-worker.js.map +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 +3 -3
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +44 -6
- package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-debug.js +10 -4
- package/dist/i3s-converter/helpers/node-pages.js +1 -1
- package/dist/i3s-converter/types.d.ts +1 -0
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/package.json +15 -16
- package/src/i3s-converter/helpers/geometry-converter.ts +59 -14
- package/src/i3s-converter/helpers/node-debug.ts +11 -5
- package/src/i3s-converter/types.ts +10 -0
|
@@ -5,7 +5,6 @@ const {
|
|
|
5
5
|
} = fs;
|
|
6
6
|
const I3S_LAYER_PATH = process.env.I3sLayerPath || '';
|
|
7
7
|
const FULL_LAYER_PATH = path.join(process.cwd(), I3S_LAYER_PATH);
|
|
8
|
-
|
|
9
8
|
async function getFileNameByUrl(url) {
|
|
10
9
|
const extensions = ['json', 'bin', 'jpg', 'jpeg', 'png', 'bin.dds', 'ktx2'];
|
|
11
10
|
for (const ext of extensions) {
|
|
@@ -17,7 +16,6 @@ async function getFileNameByUrl(url) {
|
|
|
17
16
|
continue;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
return null;
|
|
22
20
|
}
|
|
23
21
|
module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-controller.js","names":["path","require","fs","promises","I3S_LAYER_PATH","process","env","I3sLayerPath","FULL_LAYER_PATH","join","cwd","getFileNameByUrl","url","extensions","ext","fileName","access","module","exports"],"sources":["../../../../src/i3s-server/controllers/index-controller.js"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\n\nconst {promises} = fs;\n\nconst I3S_LAYER_PATH = process.env.I3sLayerPath || ''; // eslint-disable-line no-process-env, no-undef\nconst FULL_LAYER_PATH = path.join(process.cwd(), I3S_LAYER_PATH); // eslint-disable-line no-undef\n\nasync function getFileNameByUrl(url) {\n const extensions = ['json', 'bin', 'jpg', 'jpeg', 'png', 'bin.dds', 'ktx2'];\n for (const ext of extensions) {\n const fileName = `${FULL_LAYER_PATH}${url}/index.${ext}`;\n try {\n await promises.access(fileName);\n return fileName;\n } catch {\n continue; // eslint-disable-line no-continue\n }\n }\n return null;\n}\n\nmodule.exports = {\n getFileNameByUrl\n};\n"],"mappings":"AAAA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAMC,EAAE,GAAGD,OAAO,CAAC,IAAI,CAAC;AAExB,MAAM;EAACE;AAAQ,CAAC,GAAGD,EAAE;AAErB,MAAME,cAAc,GAAGC,OAAO,CAACC,GAAG,CAACC,YAAY,IAAI,EAAE;AACrD,MAAMC,eAAe,GAAGR,IAAI,CAACS,IAAI,CAACJ,OAAO,CAACK,GAAG,
|
|
1
|
+
{"version":3,"file":"index-controller.js","names":["path","require","fs","promises","I3S_LAYER_PATH","process","env","I3sLayerPath","FULL_LAYER_PATH","join","cwd","getFileNameByUrl","url","extensions","ext","fileName","concat","access","module","exports"],"sources":["../../../../src/i3s-server/controllers/index-controller.js"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\n\nconst {promises} = fs;\n\nconst I3S_LAYER_PATH = process.env.I3sLayerPath || ''; // eslint-disable-line no-process-env, no-undef\nconst FULL_LAYER_PATH = path.join(process.cwd(), I3S_LAYER_PATH); // eslint-disable-line no-undef\n\nasync function getFileNameByUrl(url) {\n const extensions = ['json', 'bin', 'jpg', 'jpeg', 'png', 'bin.dds', 'ktx2'];\n for (const ext of extensions) {\n const fileName = `${FULL_LAYER_PATH}${url}/index.${ext}`;\n try {\n await promises.access(fileName);\n return fileName;\n } catch {\n continue; // eslint-disable-line no-continue\n }\n }\n return null;\n}\n\nmodule.exports = {\n getFileNameByUrl\n};\n"],"mappings":"AAAA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAMC,EAAE,GAAGD,OAAO,CAAC,IAAI,CAAC;AAExB,MAAM;EAACE;AAAQ,CAAC,GAAGD,EAAE;AAErB,MAAME,cAAc,GAAGC,OAAO,CAACC,GAAG,CAACC,YAAY,IAAI,EAAE;AACrD,MAAMC,eAAe,GAAGR,IAAI,CAACS,IAAI,CAACJ,OAAO,CAACK,GAAG,CAAC,CAAC,EAAEN,cAAc,CAAC;AAEhE,eAAeO,gBAAgBA,CAACC,GAAG,EAAE;EACnC,MAAMC,UAAU,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC;EAC3E,KAAK,MAAMC,GAAG,IAAID,UAAU,EAAE;IAC5B,MAAME,QAAQ,MAAAC,MAAA,CAAMR,eAAe,EAAAQ,MAAA,CAAGJ,GAAG,aAAAI,MAAA,CAAUF,GAAG,CAAE;IACxD,IAAI;MACF,MAAMX,QAAQ,CAACc,MAAM,CAACF,QAAQ,CAAC;MAC/B,OAAOA,QAAQ;IACjB,CAAC,CAAC,MAAM;MACN;IACF;EACF;EACA,OAAO,IAAI;AACb;AAEAG,MAAM,CAACC,OAAO,GAAG;EACfR;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["express","require","router","Router","getFileNameByUrl","get","req","res","next","fileName","path","sendFile","status","send","module","exports"],"sources":["../../../../src/i3s-server/routes/index.js"],"sourcesContent":["const express = require('express');\nconst router = express.Router();\nconst {getFileNameByUrl} = require('../controllers/index-controller');\n\n/* GET home page. */\nrouter.get('*', async function (req, res, next) {\n const fileName = await getFileNameByUrl(req.path);\n if (fileName) {\n res.sendFile(fileName);\n } else {\n res.status(404);\n res.send('File not found');\n }\n});\n\nmodule.exports = router;\n"],"mappings":"AAAA,MAAMA,OAAO,GAAGC,OAAO,CAAC,SAAS,CAAC;AAClC,MAAMC,MAAM,GAAGF,OAAO,CAACG,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","names":["express","require","router","Router","getFileNameByUrl","get","req","res","next","fileName","path","sendFile","status","send","module","exports"],"sources":["../../../../src/i3s-server/routes/index.js"],"sourcesContent":["const express = require('express');\nconst router = express.Router();\nconst {getFileNameByUrl} = require('../controllers/index-controller');\n\n/* GET home page. */\nrouter.get('*', async function (req, res, next) {\n const fileName = await getFileNameByUrl(req.path);\n if (fileName) {\n res.sendFile(fileName);\n } else {\n res.status(404);\n res.send('File not found');\n }\n});\n\nmodule.exports = router;\n"],"mappings":"AAAA,MAAMA,OAAO,GAAGC,OAAO,CAAC,SAAS,CAAC;AAClC,MAAMC,MAAM,GAAGF,OAAO,CAACG,MAAM,CAAC,CAAC;AAC/B,MAAM;EAACC;AAAgB,CAAC,GAAGH,OAAO,CAAC,iCAAiC,CAAC;AAGrEC,MAAM,CAACG,GAAG,CAAC,GAAG,EAAE,gBAAgBC,GAAG,EAAEC,GAAG,EAAEC,IAAI,EAAE;EAC9C,MAAMC,QAAQ,GAAG,MAAML,gBAAgB,CAACE,GAAG,CAACI,IAAI,CAAC;EACjD,IAAID,QAAQ,EAAE;IACZF,GAAG,CAACI,QAAQ,CAACF,QAAQ,CAAC;EACxB,CAAC,MAAM;IACLF,GAAG,CAACK,MAAM,CAAC,GAAG,CAAC;IACfL,GAAG,CAACM,IAAI,CAAC,gBAAgB,CAAC;EAC5B;AACF,CAAC,CAAC;AAEFC,MAAM,CAACC,OAAO,GAAGb,MAAM"}
|
|
@@ -8,7 +8,6 @@ import JSZip from 'jszip';
|
|
|
8
8
|
import { MD5Hash } from '@loaders.gl/crypto';
|
|
9
9
|
import crypt from 'crypt';
|
|
10
10
|
import { getAbsoluteFilePath } from './file-utils';
|
|
11
|
-
|
|
12
11
|
export function compressFileWithGzip(pathFile) {
|
|
13
12
|
const compressedPathFile = "".concat(pathFile, ".gz");
|
|
14
13
|
const gzip = createGzip();
|
|
@@ -26,51 +25,42 @@ export function compressFileWithGzip(pathFile) {
|
|
|
26
25
|
input.pipe(gzip).pipe(output);
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
|
-
|
|
30
28
|
export async function compressFilesWithZip(fileMap, outputFile) {
|
|
31
29
|
let level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
32
30
|
try {
|
|
33
31
|
await removeFile(outputFile);
|
|
34
|
-
} catch (e) {
|
|
35
|
-
}
|
|
32
|
+
} catch (e) {}
|
|
36
33
|
const output = createWriteStream(outputFile);
|
|
37
34
|
const archive = archiver('zip', {
|
|
38
35
|
zlib: {
|
|
39
36
|
level
|
|
40
37
|
}
|
|
41
38
|
});
|
|
42
|
-
|
|
43
39
|
return new Promise(async (resolve, reject) => {
|
|
44
40
|
output.on('close', function () {
|
|
45
41
|
console.log("".concat(outputFile, " saved."));
|
|
46
42
|
console.log("".concat(archive.pointer(), " total bytes"));
|
|
47
43
|
resolve(null);
|
|
48
44
|
});
|
|
49
|
-
|
|
50
45
|
output.on('end', function () {
|
|
51
46
|
console.log('Data has been drained');
|
|
52
47
|
resolve(null);
|
|
53
48
|
});
|
|
54
|
-
|
|
55
49
|
archive.on('warning', function (err) {
|
|
56
50
|
console.log(err);
|
|
57
51
|
reject(err);
|
|
58
52
|
});
|
|
59
|
-
|
|
60
53
|
archive.on('error', function (err) {
|
|
61
54
|
reject(err);
|
|
62
55
|
});
|
|
63
|
-
|
|
64
56
|
archive.pipe(output);
|
|
65
57
|
for (const subFileName in fileMap) {
|
|
66
58
|
const subFileData = fileMap[subFileName];
|
|
67
59
|
await appendFileToArchive(archive, subFileName, subFileData);
|
|
68
60
|
}
|
|
69
|
-
|
|
70
61
|
archive.finalize();
|
|
71
62
|
});
|
|
72
63
|
}
|
|
73
|
-
|
|
74
64
|
export async function compressWithChildProcess(inputFolder, outputFile, level, inputFiles, sevenZipExe) {
|
|
75
65
|
if (process.platform === 'win32') {
|
|
76
66
|
await compressWithChildProcessWindows(inputFolder, outputFile, level, inputFiles, sevenZipExe);
|
|
@@ -78,7 +68,6 @@ export async function compressWithChildProcess(inputFolder, outputFile, level, i
|
|
|
78
68
|
await compressWithChildProcessUnix(inputFolder, outputFile, level, inputFiles);
|
|
79
69
|
}
|
|
80
70
|
}
|
|
81
|
-
|
|
82
71
|
async function compressWithChildProcessUnix(inputFolder, outputFile) {
|
|
83
72
|
let level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
84
73
|
let inputFiles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
@@ -94,7 +83,6 @@ async function compressWithChildProcessUnix(inputFolder, outputFile) {
|
|
|
94
83
|
wait: 0
|
|
95
84
|
});
|
|
96
85
|
}
|
|
97
|
-
|
|
98
86
|
async function compressWithChildProcessWindows(inputFolder, outputFile) {
|
|
99
87
|
let level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
100
88
|
let inputFiles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : join('.', '*');
|
|
@@ -114,7 +102,6 @@ async function compressWithChildProcessWindows(inputFolder, outputFile) {
|
|
|
114
102
|
wait: 0
|
|
115
103
|
});
|
|
116
104
|
}
|
|
117
|
-
|
|
118
105
|
export async function generateHash128FromZip(inputZipFile, outputFile) {
|
|
119
106
|
const input = await fs.readFile(inputZipFile);
|
|
120
107
|
const zip = await JSZip.loadAsync(input);
|
|
@@ -155,19 +142,16 @@ export async function generateHash128FromZip(inputZipFile, outputFile) {
|
|
|
155
142
|
output.close();
|
|
156
143
|
});
|
|
157
144
|
}
|
|
158
|
-
|
|
159
145
|
function longToByteArray(long) {
|
|
160
146
|
const buffer = new ArrayBuffer(8);
|
|
161
147
|
const longNum = new Float64Array(buffer);
|
|
162
148
|
longNum[0] = parseInt(long);
|
|
163
149
|
return Array.from(new Uint8Array(buffer)).reverse();
|
|
164
150
|
}
|
|
165
|
-
|
|
166
151
|
export async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {
|
|
167
152
|
await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
|
|
168
153
|
console.log("".concat(fileName, " added to ").concat(zipFile, "."));
|
|
169
154
|
}
|
|
170
|
-
|
|
171
155
|
function appendFileToArchive(archive, subFileName, subFileData) {
|
|
172
156
|
return new Promise(resolve => {
|
|
173
157
|
const fileStream = createReadStream(subFileData);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress-util.js","names":["createGzip","join","promises","fs","createReadStream","createWriteStream","archiver","removeFile","ChildProcessProxy","JSZip","MD5Hash","crypt","getAbsoluteFilePath","compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","e","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","inputFolder","inputFiles","sevenZipExe","process","platform","compressWithChildProcessWindows","compressWithChildProcessUnix","fullOutputFile","args","childProcess","start","command","arguments","spawn","cwd","wait","substr","generateHash128FromZip","inputZipFile","readFile","zip","loadAsync","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","longToByteArray","write","hexToBytes","concat","close","long","buffer","ArrayBuffer","longNum","Float64Array","parseInt","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],"sources":["../../../../src/lib/utils/compress-util.ts"],"sourcesContent":["import {createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\n/**\n * Compress file to gzip file\n *\n * @param pathFile - the path to the file\n * @return the path to the gzip file\n */\nexport function compressFileWithGzip(pathFile: string): Promise<string> {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\n/**\n * Compress files from map into slpk file\n *\n * @param fileMap - map with file paths (key: output path, value: input path)\n * @param outputFile - output slpk file\n * @param level - compression level\n */\nexport async function compressFilesWithZip(\n fileMap: {[key: string]: string},\n outputFile: string,\n level: number = 0\n) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\n/**\n * Compress files using external tool 'zip'/'7z'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n * @param sevenZipExe - path to 7z.exe executable\n */\nexport async function compressWithChildProcess(\n inputFolder: string,\n outputFile: string,\n level: number,\n inputFiles: string,\n sevenZipExe: string\n) {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(inputFolder, outputFile, level, inputFiles, sevenZipExe);\n } else {\n await compressWithChildProcessUnix(inputFolder, outputFile, level, inputFiles);\n }\n}\n\n/**\n * Compress files using external linux tool 'zip'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n */\nasync function compressWithChildProcessUnix(\n inputFolder: string,\n outputFile: string,\n level: number = 0,\n inputFiles: string = '.'\n) {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\n/**\n * Compress files using windows external tool '7z'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n * @param sevenZipExe - path to 7z.exe executable\n */\nasync function compressWithChildProcessWindows(\n inputFolder: string,\n outputFile: string,\n level: number = 0,\n inputFiles: string = join('.', '*'),\n sevenZipExe: string\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\n/**\n * Generate hash file from zip archive\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/slpk_hashtable.cmn.md\n *\n * @param inputZipFile\n * @param outputFile\n */\nexport async function generateHash128FromZip(inputZipFile: string, outputFile: string) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable: {key: string; value: string}[] = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\n/**\n * Encode 64 bit value to byte array\n *\n * @param long - stringified number\n * @returns\n */\nfunction longToByteArray(long: string): number[] {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = parseInt(long);\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\n/**\n * Add file to zip archive\n *\n * @param inputFile\n * @param fileName\n * @param zipFile\n * @param sevenZipExe\n */\nexport async function addFileToZip(\n inputFolder: string,\n fileName: string,\n zipFile: string,\n sevenZipExe: string\n) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\n/**\n *\n * @param archive zip archive instance\n * @param subFileName file path inside archive\n * @param subFileData source file path\n * @returns\n */\nfunction appendFileToArchive(archive: any, subFileName: string, subFileData: string) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"mappings":"AAAA,SAAQA,UAAU,QAAO,MAAM;AAC/B,SAAQC,IAAI,QAAO,MAAM;AACzB,SAAQC,QAAQ,IAAIC,EAAE,EAAEC,gBAAgB,EAAEC,iBAAiB,QAAO,IAAI;AACtE,OAAOC,QAAQ,MAAM,UAAU;AAC/B,SAAQC,UAAU,QAAO,cAAc;AACvC,SAAQC,iBAAiB,QAAO,0BAA0B;AAC1D,OAAOC,KAAK,MAAM,OAAO;AACzB,SAAQC,OAAO,QAAO,oBAAoB;AAC1C,OAAOC,KAAK,MAAM,OAAO;AACzB,SAAQC,mBAAmB,QAAO,cAAc;;AAQhD,OAAO,SAASC,oBAAoB,CAACC,QAAgB,EAAmB;EACtE,MAAMC,kBAAkB,aAAMD,QAAQ,QAAK;EAC3C,MAAME,IAAI,GAAGhB,UAAU,EAAE;EACzB,MAAMiB,KAAK,GAAGb,gBAAgB,CAACU,QAAQ,CAAC;EACxC,MAAMI,MAAM,GAAGb,iBAAiB,CAACU,kBAAkB,CAAC;EAEpD,OAAO,IAAII,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtCJ,KAAK,CAACK,EAAE,CAAC,KAAK,EAAE,MAAM;MACpBC,OAAO,CAACC,GAAG,WAAIT,kBAAkB,4BAAyB;MAC1DK,OAAO,CAACL,kBAAkB,CAAC;IAC7B,CAAC,CAAC;IACFE,KAAK,CAACK,EAAE,CAAC,OAAO,EAAGG,KAAK,IAAK;MAC3BF,OAAO,CAACC,GAAG,WAAIT,kBAAkB,0BAAuB;MACxDM,MAAM,CAACI,KAAK,CAAC;IACf,CAAC,CAAC;IACFR,KAAK,CAACS,IAAI,CAACV,IAAI,CAAC,CAACU,IAAI,CAACR,MAAM,CAAC;EAC/B,CAAC,CAAC;AACJ;;AASA,OAAO,eAAeS,oBAAoB,CACxCC,OAAgC,EAChCC,UAAkB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L,IAAI,CAAC;EAC3B,OAAOM,KAAK,CAACtB,IAAI,CAAC,IAAIuB,UAAU,CAACN,MAAM,CAAC,CAAC,CAACO,OAAO,EAAE;AACrD;;AAUA,OAAO,eAAeC,YAAY,CAChC1D,WAAmB,EACnB2D,QAAgB,EAChBC,OAAe,EACf1D,WAAmB,EACnB;EACA,MAAMH,wBAAwB,CAACC,WAAW,EAAE4D,OAAO,EAAE,CAAC,EAAED,QAAQ,EAAEzD,WAAW,CAAC;EAC9EpB,OAAO,CAACC,GAAG,WAAI4E,QAAQ,uBAAaC,OAAO,OAAI;AACjD;;AASA,SAAS/D,mBAAmB,CAACN,OAAY,EAAEI,WAAmB,EAAEC,WAAmB,EAAE;EACnF,OAAO,IAAIlB,OAAO,CAAEC,OAAO,IAAK;IAC9B,MAAMkF,UAAU,GAAGlG,gBAAgB,CAACiC,WAAW,CAAC;IAChDd,OAAO,CAACC,GAAG,8BAAuBY,WAAW,EAAG;IAChDkE,UAAU,CAAChF,EAAE,CAAC,OAAO,EAAE,MAAM;MAC3BC,OAAO,CAACC,GAAG,+BAAwBY,WAAW,EAAG;MACjDhB,OAAO,CAAC,IAAI,CAAC;IACf,CAAC,CAAC;IACFY,OAAO,CAACuE,MAAM,CAACD,UAAU,EAAE;MAACE,IAAI,EAAEpE;IAAW,CAAC,CAAC;EACjD,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"file":"compress-util.js","names":["createGzip","join","promises","fs","createReadStream","createWriteStream","archiver","removeFile","ChildProcessProxy","JSZip","MD5Hash","crypt","getAbsoluteFilePath","compressFileWithGzip","pathFile","compressedPathFile","concat","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","arguments","length","undefined","e","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","inputFolder","inputFiles","sevenZipExe","process","platform","compressWithChildProcessWindows","compressWithChildProcessUnix","fullOutputFile","args","childProcess","start","command","spawn","cwd","wait","substr","generateHash128FromZip","inputZipFile","readFile","zip","loadAsync","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","longToByteArray","write","hexToBytes","close","long","buffer","ArrayBuffer","longNum","Float64Array","parseInt","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],"sources":["../../../../src/lib/utils/compress-util.ts"],"sourcesContent":["import {createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\n/**\n * Compress file to gzip file\n *\n * @param pathFile - the path to the file\n * @return the path to the gzip file\n */\nexport function compressFileWithGzip(pathFile: string): Promise<string> {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\n/**\n * Compress files from map into slpk file\n *\n * @param fileMap - map with file paths (key: output path, value: input path)\n * @param outputFile - output slpk file\n * @param level - compression level\n */\nexport async function compressFilesWithZip(\n fileMap: {[key: string]: string},\n outputFile: string,\n level: number = 0\n) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\n/**\n * Compress files using external tool 'zip'/'7z'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n * @param sevenZipExe - path to 7z.exe executable\n */\nexport async function compressWithChildProcess(\n inputFolder: string,\n outputFile: string,\n level: number,\n inputFiles: string,\n sevenZipExe: string\n) {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(inputFolder, outputFile, level, inputFiles, sevenZipExe);\n } else {\n await compressWithChildProcessUnix(inputFolder, outputFile, level, inputFiles);\n }\n}\n\n/**\n * Compress files using external linux tool 'zip'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n */\nasync function compressWithChildProcessUnix(\n inputFolder: string,\n outputFile: string,\n level: number = 0,\n inputFiles: string = '.'\n) {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\n/**\n * Compress files using windows external tool '7z'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n * @param sevenZipExe - path to 7z.exe executable\n */\nasync function compressWithChildProcessWindows(\n inputFolder: string,\n outputFile: string,\n level: number = 0,\n inputFiles: string = join('.', '*'),\n sevenZipExe: string\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\n/**\n * Generate hash file from zip archive\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/slpk_hashtable.cmn.md\n *\n * @param inputZipFile\n * @param outputFile\n */\nexport async function generateHash128FromZip(inputZipFile: string, outputFile: string) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable: {key: string; value: string}[] = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()));\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\n/**\n * Encode 64 bit value to byte array\n *\n * @param long - stringified number\n * @returns\n */\nfunction longToByteArray(long: string): number[] {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = parseInt(long);\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\n/**\n * Add file to zip archive\n *\n * @param inputFile\n * @param fileName\n * @param zipFile\n * @param sevenZipExe\n */\nexport async function addFileToZip(\n inputFolder: string,\n fileName: string,\n zipFile: string,\n sevenZipExe: string\n) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\n/**\n *\n * @param archive zip archive instance\n * @param subFileName file path inside archive\n * @param subFileData source file path\n * @returns\n */\nfunction appendFileToArchive(archive: any, subFileName: string, subFileData: string) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"mappings":"AAA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AAA,CAAwBwB,WAAW,CAAE,CAAC;MACjDnB,OAAO,CAAC,IAAI,CAAC;IACf,CAAC,CAAC;IACFe,OAAO,CAACqE,MAAM,CAACD,UAAU,EAAE;MAACE,IAAI,EAAElE;IAAW,CAAC,CAAC;EACjD,CAAC,CAAC;AACJ"}
|
|
@@ -3,7 +3,6 @@ import { JSONLoader } from '@loaders.gl/loader-utils';
|
|
|
3
3
|
import { promises as fs } from 'fs';
|
|
4
4
|
import { isAbsolute, join } from 'path';
|
|
5
5
|
import { compressFileWithGzip } from './compress-util';
|
|
6
|
-
|
|
7
6
|
export async function writeFile(path, data) {
|
|
8
7
|
let fileName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'index.json';
|
|
9
8
|
let toWriteData;
|
|
@@ -26,7 +25,6 @@ export async function writeFile(path, data) {
|
|
|
26
25
|
console.log("".concat(pathFile, " saved."));
|
|
27
26
|
return pathFile;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
28
|
export async function writeFileForSlpk(path, data) {
|
|
31
29
|
let fileName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'index.json';
|
|
32
30
|
let compress = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
@@ -48,7 +46,6 @@ export async function writeFileForSlpk(path, data) {
|
|
|
48
46
|
}
|
|
49
47
|
return pathFile;
|
|
50
48
|
}
|
|
51
|
-
|
|
52
49
|
export async function openJson(path, fileName) {
|
|
53
50
|
return new Promise((resolve, reject) => {
|
|
54
51
|
let count = 0;
|
|
@@ -68,7 +65,6 @@ export async function openJson(path, fileName) {
|
|
|
68
65
|
}, 200);
|
|
69
66
|
});
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
export async function isFileExists(fileName) {
|
|
73
69
|
try {
|
|
74
70
|
await fs.stat(fileName);
|
|
@@ -77,17 +73,14 @@ export async function isFileExists(fileName) {
|
|
|
77
73
|
return false;
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
|
-
|
|
81
76
|
export function removeDir(path) {
|
|
82
77
|
return fs.rmdir(path, {
|
|
83
78
|
recursive: true
|
|
84
79
|
});
|
|
85
80
|
}
|
|
86
|
-
|
|
87
81
|
export function removeFile(path) {
|
|
88
82
|
return fs.unlink(path);
|
|
89
83
|
}
|
|
90
|
-
|
|
91
84
|
export function getAbsoluteFilePath(filePath) {
|
|
92
85
|
return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath);
|
|
93
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-utils.js","names":["load","JSONLoader","promises","fs","isAbsolute","join","compressFileWithGzip","writeFile","path","data","fileName","toWriteData","Promise","Uint8Array","ArrayBuffer","mkdir","recursive","pathFile","err","console","log","writeFileForSlpk","compress","compressList","includes","push","pathGzFile","removeFile","openJson","resolve","reject","count","intervalId","setInterval","then","result","clearInterval","catch","Error","isFileExists","stat","removeDir","rmdir","unlink","getAbsoluteFilePath","filePath","process","cwd"],"sources":["../../../../src/lib/utils/file-utils.ts"],"sourcesContent":["import {load} from '@loaders.gl/core';\nimport {JSONLoader} from '@loaders.gl/loader-utils';\nimport {promises as fs} from 'fs';\nimport {isAbsolute, join} from 'path';\nimport {compressFileWithGzip} from './compress-util';\n\n/**\n * Write a file with data and name fileName to path\n *\n * @param path - output path\n * @param data - file content\n * @param fileName - name of output file (default: index.json)\n */\nexport async function writeFile(\n path: string,\n data: string | Uint8Array | ArrayBuffer | Promise<ArrayBuffer>,\n fileName: string = 'index.json'\n): Promise<string> {\n let toWriteData: string | Uint8Array;\n if (data instanceof Promise) {\n toWriteData = new Uint8Array(await data);\n } else if (data instanceof ArrayBuffer) {\n toWriteData = new Uint8Array(data as ArrayBuffer);\n } else {\n toWriteData = data;\n }\n await fs.mkdir(path, {recursive: true});\n const pathFile = join(path, fileName);\n try {\n await fs.writeFile(pathFile, toWriteData);\n } catch (err) {\n throw err;\n }\n console.log(`${pathFile} saved.`); // eslint-disable-line\n return pathFile;\n}\n\n/**\n * Write a file with data and name fileName to path - specific one for further packaging into slpk\n *\n * @param path - output path\n * @param data - file content\n * @param fileName - name of output file (default: index.json)\n * @param compress - if need to compress file with gzip (default: true)\n * @param compressList - if set - the file should be added to this list and compressed in the end of conversion\n */\nexport async function writeFileForSlpk(\n path: string,\n data: string | Uint8Array | ArrayBuffer | Promise<ArrayBuffer>,\n fileName: string = 'index.json',\n compress: boolean = true,\n compressList?: string[] | null\n): Promise<string | null> {\n const pathFile = await writeFile(path, data, fileName);\n if (compress) {\n if (compressList) {\n if (!compressList.includes(pathFile)) {\n compressList.push(pathFile);\n return `${pathFile}.gz`;\n } else {\n return null;\n }\n } else {\n const pathGzFile = await compressFileWithGzip(pathFile);\n // After compression, we don't need an uncompressed file\n await removeFile(pathFile);\n return pathGzFile;\n }\n }\n return pathFile;\n}\n\n/**\n * Open json file\n * @param path - path to the file\n * @param fileName - file name\n * @returns object\n */\nexport async function openJson(path: string, fileName: string): Promise<{[key: string]: any}> {\n return new Promise((resolve, reject) => {\n let count = 0;\n console.log(`load ${path}/${fileName}.`); // eslint-disable-line\n const intervalId = setInterval(() => {\n const pathFile = join(path, fileName);\n load(pathFile, JSONLoader)\n .then((result) => {\n clearInterval(intervalId);\n resolve(result);\n })\n .catch(() => {\n count++;\n if (count > 100) {\n clearInterval(intervalId);\n reject(new Error(`Cannon load ${path}/${fileName}.`));\n }\n });\n }, 200);\n });\n}\n\n/**\n * Check if the file exists\n * @param fileName - full name of file\n * @returns true if file exists, otherwise - false\n */\nexport async function isFileExists(fileName: string): Promise<boolean> {\n try {\n await fs.stat(fileName);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Remove dir with path\n *\n * @param path\n */\nexport function removeDir(path: string) {\n return fs.rmdir(path, {recursive: true});\n}\n\n/**\n * Remove file with path\n *\n * @param path\n */\nexport function removeFile(path: string) {\n return fs.unlink(path);\n}\n\n/**\n * Generates absolute file path\n * @param filePath\n */\nexport function getAbsoluteFilePath(filePath: string) {\n return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath);\n}\n"],"mappings":"AAAA,SAAQA,IAAI,QAAO,kBAAkB;AACrC,SAAQC,UAAU,QAAO,0BAA0B;AACnD,SAAQC,QAAQ,IAAIC,EAAE,QAAO,IAAI;AACjC,SAAQC,UAAU,EAAEC,IAAI,QAAO,MAAM;AACrC,SAAQC,oBAAoB,QAAO,iBAAiB
|
|
1
|
+
{"version":3,"file":"file-utils.js","names":["load","JSONLoader","promises","fs","isAbsolute","join","compressFileWithGzip","writeFile","path","data","fileName","arguments","length","undefined","toWriteData","Promise","Uint8Array","ArrayBuffer","mkdir","recursive","pathFile","err","console","log","concat","writeFileForSlpk","compress","compressList","includes","push","pathGzFile","removeFile","openJson","resolve","reject","count","intervalId","setInterval","then","result","clearInterval","catch","Error","isFileExists","stat","removeDir","rmdir","unlink","getAbsoluteFilePath","filePath","process","cwd"],"sources":["../../../../src/lib/utils/file-utils.ts"],"sourcesContent":["import {load} from '@loaders.gl/core';\nimport {JSONLoader} from '@loaders.gl/loader-utils';\nimport {promises as fs} from 'fs';\nimport {isAbsolute, join} from 'path';\nimport {compressFileWithGzip} from './compress-util';\n\n/**\n * Write a file with data and name fileName to path\n *\n * @param path - output path\n * @param data - file content\n * @param fileName - name of output file (default: index.json)\n */\nexport async function writeFile(\n path: string,\n data: string | Uint8Array | ArrayBuffer | Promise<ArrayBuffer>,\n fileName: string = 'index.json'\n): Promise<string> {\n let toWriteData: string | Uint8Array;\n if (data instanceof Promise) {\n toWriteData = new Uint8Array(await data);\n } else if (data instanceof ArrayBuffer) {\n toWriteData = new Uint8Array(data as ArrayBuffer);\n } else {\n toWriteData = data;\n }\n await fs.mkdir(path, {recursive: true});\n const pathFile = join(path, fileName);\n try {\n await fs.writeFile(pathFile, toWriteData);\n } catch (err) {\n throw err;\n }\n console.log(`${pathFile} saved.`); // eslint-disable-line\n return pathFile;\n}\n\n/**\n * Write a file with data and name fileName to path - specific one for further packaging into slpk\n *\n * @param path - output path\n * @param data - file content\n * @param fileName - name of output file (default: index.json)\n * @param compress - if need to compress file with gzip (default: true)\n * @param compressList - if set - the file should be added to this list and compressed in the end of conversion\n */\nexport async function writeFileForSlpk(\n path: string,\n data: string | Uint8Array | ArrayBuffer | Promise<ArrayBuffer>,\n fileName: string = 'index.json',\n compress: boolean = true,\n compressList?: string[] | null\n): Promise<string | null> {\n const pathFile = await writeFile(path, data, fileName);\n if (compress) {\n if (compressList) {\n if (!compressList.includes(pathFile)) {\n compressList.push(pathFile);\n return `${pathFile}.gz`;\n } else {\n return null;\n }\n } else {\n const pathGzFile = await compressFileWithGzip(pathFile);\n // After compression, we don't need an uncompressed file\n await removeFile(pathFile);\n return pathGzFile;\n }\n }\n return pathFile;\n}\n\n/**\n * Open json file\n * @param path - path to the file\n * @param fileName - file name\n * @returns object\n */\nexport async function openJson(path: string, fileName: string): Promise<{[key: string]: any}> {\n return new Promise((resolve, reject) => {\n let count = 0;\n console.log(`load ${path}/${fileName}.`); // eslint-disable-line\n const intervalId = setInterval(() => {\n const pathFile = join(path, fileName);\n load(pathFile, JSONLoader)\n .then((result) => {\n clearInterval(intervalId);\n resolve(result);\n })\n .catch(() => {\n count++;\n if (count > 100) {\n clearInterval(intervalId);\n reject(new Error(`Cannon load ${path}/${fileName}.`));\n }\n });\n }, 200);\n });\n}\n\n/**\n * Check if the file exists\n * @param fileName - full name of file\n * @returns true if file exists, otherwise - false\n */\nexport async function isFileExists(fileName: string): Promise<boolean> {\n try {\n await fs.stat(fileName);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Remove dir with path\n *\n * @param path\n */\nexport function removeDir(path: string) {\n return fs.rmdir(path, {recursive: true});\n}\n\n/**\n * Remove file with path\n *\n * @param path\n */\nexport function removeFile(path: string) {\n return fs.unlink(path);\n}\n\n/**\n * Generates absolute file path\n * @param filePath\n */\nexport function getAbsoluteFilePath(filePath: string) {\n return isAbsolute(filePath) ? filePath : join(process.cwd(), filePath);\n}\n"],"mappings":"AAAA,SAAQA,IAAI,QAAO,kBAAkB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Q,KAAK,gBAAAlB,MAAA,CAAgBhB,IAAI,OAAAgB,MAAA,CAAId,QAAQ,MAAG,CAAC,CAAC;QACvD;MACF,CAAC,CAAC;IACN,CAAC,EAAE,GAAG,CAAC;EACT,CAAC,CAAC;AACJ;AAOA,OAAO,eAAeiC,YAAYA,CAACjC,QAAgB,EAAoB;EACrE,IAAI;IACF,MAAMP,EAAE,CAACyC,IAAI,CAAClC,QAAQ,CAAC;IACvB,OAAO,IAAI;EACb,CAAC,CAAC,MAAM;IACN,OAAO,KAAK;EACd;AACF;AAOA,OAAO,SAASmC,SAASA,CAACrC,IAAY,EAAE;EACtC,OAAOL,EAAE,CAAC2C,KAAK,CAACtC,IAAI,EAAE;IAACW,SAAS,EAAE;EAAI,CAAC,CAAC;AAC1C;AAOA,OAAO,SAASY,UAAUA,CAACvB,IAAY,EAAE;EACvC,OAAOL,EAAE,CAAC4C,MAAM,CAACvC,IAAI,CAAC;AACxB;AAMA,OAAO,SAASwC,mBAAmBA,CAACC,QAAgB,EAAE;EACpD,OAAO7C,UAAU,CAAC6C,QAAQ,CAAC,GAAGA,QAAQ,GAAG5C,IAAI,CAAC6C,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEF,QAAQ,CAAC;AACxE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
const DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;
|
|
3
2
|
export function convertGeometricErrorToScreenThreshold(tile, coordinates) {
|
|
4
3
|
const lodSelection = [];
|
|
@@ -21,7 +20,6 @@ export function convertGeometricErrorToScreenThreshold(tile, coordinates) {
|
|
|
21
20
|
}
|
|
22
21
|
return lodSelection;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
export function convertScreenThresholdToGeometricError(node) {
|
|
26
24
|
const metricData = node.header.lodSelection.maxScreenThreshold || {};
|
|
27
25
|
let maxError = metricData.maxError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lod-conversion-utils.js","names":["DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR","convertGeometricErrorToScreenThreshold","tile","coordinates","lodSelection","boundingVolume","lodMetricValue","maxScreenThreshold","metricType","maxError","mbs","maxScreenThresholdSQ","Math","PI","constructor","name","push","convertScreenThresholdToGeometricError","node","metricData","header","sqMetricData","sqrt"],"sources":["../../../../src/lib/utils/lod-conversion-utils.ts"],"sourcesContent":["import {BoundingVolumes} from '@loaders.gl/i3s';\nimport {Tile3D} from '@loaders.gl/tiles';\n\n// https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html\nconst DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;\n/**\n * Do conversion from geometric error to screen threshold\n * \n * In 3DTiles we have HLOD logic and parent tile also has bigger lodMetric value then its children.\n * In I3s we have reverse logic related to maxError. Parent has lower maxError than its child.\n * In nodes where are no children tile.lodMetricValue is 0. This is because of logic of HLOD in 3DTiles\n * 3DTiles spec:\n * https://github.com/CesiumGS/3d-tiles/tree/master/specification#geometric-error\n * I3S spec:\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/lodSelection.cmn.md\n * To avoid infinity values when we do calculations of maxError we shold replace 0 with value which allows us\n * to make child maxError bigger than his parent maxError.\n * \n * @param tile - 3d-tiles tile Object\n * @param coordinates - node converted coordinates\n * @returns An array of LOD metrics in format compatible with i3s 3DNodeIndexDocument.lodSelection\n * @example \n * [\n {\n \"metricType\": \"maxScreenThresholdSQ\",\n \"maxError\": 870638.071285568\n },\n {\n \"metricType\": \"maxScreenThreshold\",\n \"maxError\": 1052.8679031638949\n }\n ]\n */\nexport function convertGeometricErrorToScreenThreshold(tile: Tile3D, coordinates: BoundingVolumes) {\n const lodSelection: {metricType: string; maxError: number}[] = [];\n const boundingVolume = tile.boundingVolume;\n const lodMetricValue = tile.lodMetricValue || 0.1;\n const maxScreenThreshold = {\n metricType: 'maxScreenThreshold',\n maxError: (coordinates.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / lodMetricValue\n };\n const maxScreenThresholdSQ = {\n metricType: 'maxScreenThresholdSQ',\n maxError: Math.PI * 0.25 * maxScreenThreshold.maxError * maxScreenThreshold.maxError\n };\n\n if (boundingVolume.constructor.name === 'OrientedBoundingBox') {\n lodSelection.push(maxScreenThresholdSQ);\n lodSelection.push(maxScreenThreshold);\n } else {\n lodSelection.push(maxScreenThreshold);\n lodSelection.push(maxScreenThresholdSQ);\n }\n\n return lodSelection;\n}\n\n/**\n * Convert LOD metric from \"Screen Threshold\" to \"Screen Space Error\"\n * @param node - i3s node data\n * @returns lod metric in 3d-tiles format\n */\nexport function convertScreenThresholdToGeometricError(node: Tile3D): number {\n const metricData = node.header.lodSelection.maxScreenThreshold || {};\n let maxError = metricData.maxError;\n if (!maxError) {\n const sqMetricData = node.header.lodSelection.maxScreenThresholdSQ;\n if (sqMetricData) {\n maxError = Math.sqrt(sqMetricData.maxError / (Math.PI * 0.25));\n }\n }\n\n if (!maxError) {\n maxError = DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR;\n }\n\n return (node.header.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / maxError;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"lod-conversion-utils.js","names":["DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR","convertGeometricErrorToScreenThreshold","tile","coordinates","lodSelection","boundingVolume","lodMetricValue","maxScreenThreshold","metricType","maxError","mbs","maxScreenThresholdSQ","Math","PI","constructor","name","push","convertScreenThresholdToGeometricError","node","metricData","header","sqMetricData","sqrt"],"sources":["../../../../src/lib/utils/lod-conversion-utils.ts"],"sourcesContent":["import {BoundingVolumes} from '@loaders.gl/i3s';\nimport {Tile3D} from '@loaders.gl/tiles';\n\n// https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html\nconst DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;\n/**\n * Do conversion from geometric error to screen threshold\n * \n * In 3DTiles we have HLOD logic and parent tile also has bigger lodMetric value then its children.\n * In I3s we have reverse logic related to maxError. Parent has lower maxError than its child.\n * In nodes where are no children tile.lodMetricValue is 0. This is because of logic of HLOD in 3DTiles\n * 3DTiles spec:\n * https://github.com/CesiumGS/3d-tiles/tree/master/specification#geometric-error\n * I3S spec:\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/lodSelection.cmn.md\n * To avoid infinity values when we do calculations of maxError we shold replace 0 with value which allows us\n * to make child maxError bigger than his parent maxError.\n * \n * @param tile - 3d-tiles tile Object\n * @param coordinates - node converted coordinates\n * @returns An array of LOD metrics in format compatible with i3s 3DNodeIndexDocument.lodSelection\n * @example \n * [\n {\n \"metricType\": \"maxScreenThresholdSQ\",\n \"maxError\": 870638.071285568\n },\n {\n \"metricType\": \"maxScreenThreshold\",\n \"maxError\": 1052.8679031638949\n }\n ]\n */\nexport function convertGeometricErrorToScreenThreshold(tile: Tile3D, coordinates: BoundingVolumes) {\n const lodSelection: {metricType: string; maxError: number}[] = [];\n const boundingVolume = tile.boundingVolume;\n const lodMetricValue = tile.lodMetricValue || 0.1;\n const maxScreenThreshold = {\n metricType: 'maxScreenThreshold',\n maxError: (coordinates.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / lodMetricValue\n };\n const maxScreenThresholdSQ = {\n metricType: 'maxScreenThresholdSQ',\n maxError: Math.PI * 0.25 * maxScreenThreshold.maxError * maxScreenThreshold.maxError\n };\n\n if (boundingVolume.constructor.name === 'OrientedBoundingBox') {\n lodSelection.push(maxScreenThresholdSQ);\n lodSelection.push(maxScreenThreshold);\n } else {\n lodSelection.push(maxScreenThreshold);\n lodSelection.push(maxScreenThresholdSQ);\n }\n\n return lodSelection;\n}\n\n/**\n * Convert LOD metric from \"Screen Threshold\" to \"Screen Space Error\"\n * @param node - i3s node data\n * @returns lod metric in 3d-tiles format\n */\nexport function convertScreenThresholdToGeometricError(node: Tile3D): number {\n const metricData = node.header.lodSelection.maxScreenThreshold || {};\n let maxError = metricData.maxError;\n if (!maxError) {\n const sqMetricData = node.header.lodSelection.maxScreenThresholdSQ;\n if (sqMetricData) {\n maxError = Math.sqrt(sqMetricData.maxError / (Math.PI * 0.25));\n }\n }\n\n if (!maxError) {\n maxError = DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR;\n }\n\n return (node.header.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / maxError;\n}\n"],"mappings":"AAIA,MAAMA,kCAAkC,GAAG,EAAE;AA6B7C,OAAO,SAASC,sCAAsCA,CAACC,IAAY,EAAEC,WAA4B,EAAE;EACjG,MAAMC,YAAsD,GAAG,EAAE;EACjE,MAAMC,cAAc,GAAGH,IAAI,CAACG,cAAc;EAC1C,MAAMC,cAAc,GAAGJ,IAAI,CAACI,cAAc,IAAI,GAAG;EACjD,MAAMC,kBAAkB,GAAG;IACzBC,UAAU,EAAE,oBAAoB;IAChCC,QAAQ,EAAGN,WAAW,CAACO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAGV,kCAAkC,GAAIM;EAC5E,CAAC;EACD,MAAMK,oBAAoB,GAAG;IAC3BH,UAAU,EAAE,sBAAsB;IAClCC,QAAQ,EAAEG,IAAI,CAACC,EAAE,GAAG,IAAI,GAAGN,kBAAkB,CAACE,QAAQ,GAAGF,kBAAkB,CAACE;EAC9E,CAAC;EAED,IAAIJ,cAAc,CAACS,WAAW,CAACC,IAAI,KAAK,qBAAqB,EAAE;IAC7DX,YAAY,CAACY,IAAI,CAACL,oBAAoB,CAAC;IACvCP,YAAY,CAACY,IAAI,CAACT,kBAAkB,CAAC;EACvC,CAAC,MAAM;IACLH,YAAY,CAACY,IAAI,CAACT,kBAAkB,CAAC;IACrCH,YAAY,CAACY,IAAI,CAACL,oBAAoB,CAAC;EACzC;EAEA,OAAOP,YAAY;AACrB;AAOA,OAAO,SAASa,sCAAsCA,CAACC,IAAY,EAAU;EAC3E,MAAMC,UAAU,GAAGD,IAAI,CAACE,MAAM,CAAChB,YAAY,CAACG,kBAAkB,IAAI,CAAC,CAAC;EACpE,IAAIE,QAAQ,GAAGU,UAAU,CAACV,QAAQ;EAClC,IAAI,CAACA,QAAQ,EAAE;IACb,MAAMY,YAAY,GAAGH,IAAI,CAACE,MAAM,CAAChB,YAAY,CAACO,oBAAoB;IAClE,IAAIU,YAAY,EAAE;MAChBZ,QAAQ,GAAGG,IAAI,CAACU,IAAI,CAACD,YAAY,CAACZ,QAAQ,IAAIG,IAAI,CAACC,EAAE,GAAG,IAAI,CAAC,CAAC;IAChE;EACF;EAEA,IAAI,CAACJ,QAAQ,EAAE;IACbA,QAAQ,GAAGT,kCAAkC;EAC/C;EAEA,OAAQkB,IAAI,CAACE,MAAM,CAACV,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAGV,kCAAkC,GAAIS,QAAQ;AACjF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","names":["Queue","Array","enqueue","val","push","dequeue","shift","peek","isEmpty","length"],"sources":["../../../../src/lib/utils/queue.ts"],"sourcesContent":["export class Queue<T> extends Array<T> {\n enqueue(val: T) {\n this.push(val);\n }\n\n dequeue(): T | undefined {\n return this.shift();\n }\n\n peek(): T {\n return this[0];\n }\n\n isEmpty() {\n return this.length === 0;\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,KAAK,SAAYC,KAAK,CAAI;EACrCC,
|
|
1
|
+
{"version":3,"file":"queue.js","names":["Queue","Array","enqueue","val","push","dequeue","shift","peek","isEmpty","length"],"sources":["../../../../src/lib/utils/queue.ts"],"sourcesContent":["export class Queue<T> extends Array<T> {\n enqueue(val: T) {\n this.push(val);\n }\n\n dequeue(): T | undefined {\n return this.shift();\n }\n\n peek(): T {\n return this[0];\n }\n\n isEmpty() {\n return this.length === 0;\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,KAAK,SAAYC,KAAK,CAAI;EACrCC,OAAOA,CAACC,GAAM,EAAE;IACd,IAAI,CAACC,IAAI,CAACD,GAAG,CAAC;EAChB;EAEAE,OAAOA,CAAA,EAAkB;IACvB,OAAO,IAAI,CAACC,KAAK,CAAC,CAAC;EACrB;EAEAC,IAAIA,CAAA,EAAM;IACR,OAAO,IAAI,CAAC,CAAC,CAAC;EAChB;EAEAC,OAAOA,CAAA,EAAG;IACR,OAAO,IAAI,CAACC,MAAM,KAAK,CAAC;EAC1B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statistic-utills.js","names":["join","promises","fs","getAbsoluteFilePath","timeConverter","time","nanoSecondsInMillisecond","timeInSeconds","hours","Math","floor","minutes","seconds","milliseconds","result","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","slpkPath","stat","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"sources":["../../../../src/lib/utils/statistic-utills.ts"],"sourcesContent":["import {join} from 'path';\nimport {promises as fs} from 'fs';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function timeConverter(time) {\n const nanoSecondsInMillisecond = 1e6;\n let timeInSeconds = time[0];\n const hours = Math.floor(timeInSeconds / 3600);\n timeInSeconds = timeInSeconds - hours * 3600;\n const minutes = Math.floor(timeInSeconds / 60);\n timeInSeconds = timeInSeconds - minutes * 60;\n const seconds = Math.floor(timeInSeconds);\n const milliseconds = time[1] / nanoSecondsInMillisecond;\n let result = '';\n\n if (hours) {\n result += `${hours}h `;\n }\n\n if (minutes) {\n result += `${minutes}m `;\n }\n\n if (seconds) {\n result += `${seconds}s`;\n }\n\n if (!result) {\n result += `${milliseconds}ms`;\n }\n\n return result;\n}\n\nexport async function calculateFilesSize(params) {\n const {slpk, outputPath, tilesetName} = params;\n const fullOutputPath = getAbsoluteFilePath(outputPath);\n\n try {\n if (slpk) {\n const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);\n const stat = await fs.stat(slpkPath);\n return stat.size;\n }\n\n const directoryPath = join(fullOutputPath, tilesetName);\n const totalSize = await getTotalFilesSize(directoryPath);\n return totalSize;\n } catch (error) {\n console.log('Calculate file sizes error: ', error); // eslint-disable-line\n return null;\n }\n}\n\nasync function getTotalFilesSize(dirPath) {\n let totalFileSize = 0;\n\n const files = await fs.readdir(dirPath);\n\n for (const file of files) {\n const fileStat = await fs.stat(join(dirPath, file));\n if (fileStat.isDirectory()) {\n totalFileSize += await getTotalFilesSize(join(dirPath, file));\n } else {\n totalFileSize += fileStat.size;\n }\n }\n return totalFileSize;\n}\n"],"mappings":"AAAA,SAAQA,IAAI,QAAO,MAAM;AACzB,SAAQC,QAAQ,IAAIC,EAAE,QAAO,IAAI;AACjC,SAAQC,mBAAmB,QAAO,cAAc;AAEhD,OAAO,SAASC,
|
|
1
|
+
{"version":3,"file":"statistic-utills.js","names":["join","promises","fs","getAbsoluteFilePath","timeConverter","time","nanoSecondsInMillisecond","timeInSeconds","hours","Math","floor","minutes","seconds","milliseconds","result","concat","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","slpkPath","stat","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"sources":["../../../../src/lib/utils/statistic-utills.ts"],"sourcesContent":["import {join} from 'path';\nimport {promises as fs} from 'fs';\nimport {getAbsoluteFilePath} from './file-utils';\n\nexport function timeConverter(time) {\n const nanoSecondsInMillisecond = 1e6;\n let timeInSeconds = time[0];\n const hours = Math.floor(timeInSeconds / 3600);\n timeInSeconds = timeInSeconds - hours * 3600;\n const minutes = Math.floor(timeInSeconds / 60);\n timeInSeconds = timeInSeconds - minutes * 60;\n const seconds = Math.floor(timeInSeconds);\n const milliseconds = time[1] / nanoSecondsInMillisecond;\n let result = '';\n\n if (hours) {\n result += `${hours}h `;\n }\n\n if (minutes) {\n result += `${minutes}m `;\n }\n\n if (seconds) {\n result += `${seconds}s`;\n }\n\n if (!result) {\n result += `${milliseconds}ms`;\n }\n\n return result;\n}\n\nexport async function calculateFilesSize(params) {\n const {slpk, outputPath, tilesetName} = params;\n const fullOutputPath = getAbsoluteFilePath(outputPath);\n\n try {\n if (slpk) {\n const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);\n const stat = await fs.stat(slpkPath);\n return stat.size;\n }\n\n const directoryPath = join(fullOutputPath, tilesetName);\n const totalSize = await getTotalFilesSize(directoryPath);\n return totalSize;\n } catch (error) {\n console.log('Calculate file sizes error: ', error); // eslint-disable-line\n return null;\n }\n}\n\nasync function getTotalFilesSize(dirPath) {\n let totalFileSize = 0;\n\n const files = await fs.readdir(dirPath);\n\n for (const file of files) {\n const fileStat = await fs.stat(join(dirPath, file));\n if (fileStat.isDirectory()) {\n totalFileSize += await getTotalFilesSize(join(dirPath, file));\n } else {\n totalFileSize += fileStat.size;\n }\n }\n return totalFileSize;\n}\n"],"mappings":"AAAA,SAAQA,IAAI,QAAO,MAAM;AACzB,SAAQC,QAAQ,IAAIC,EAAE,QAAO,IAAI;AACjC,SAAQC,mBAAmB,QAAO,cAAc;AAEhD,OAAO,SAASC,aAAaA,CAACC,IAAI,EAAE;EAClC,MAAMC,wBAAwB,GAAG,GAAG;EACpC,IAAIC,aAAa,GAAGF,IAAI,CAAC,CAAC,CAAC;EAC3B,MAAMG,KAAK,GAAGC,IAAI,CAACC,KAAK,CAACH,aAAa,GAAG,IAAI,CAAC;EAC9CA,aAAa,GAAGA,aAAa,GAAGC,KAAK,GAAG,IAAI;EAC5C,MAAMG,OAAO,GAAGF,IAAI,CAACC,KAAK,CAACH,aAAa,GAAG,EAAE,CAAC;EAC9CA,aAAa,GAAGA,aAAa,GAAGI,OAAO,GAAG,EAAE;EAC5C,MAAMC,OAAO,GAAGH,IAAI,CAACC,KAAK,CAACH,aAAa,CAAC;EACzC,MAAMM,YAAY,GAAGR,IAAI,CAAC,CAAC,CAAC,GAAGC,wBAAwB;EACvD,IAAIQ,MAAM,GAAG,EAAE;EAEf,IAAIN,KAAK,EAAE;IACTM,MAAM,OAAAC,MAAA,CAAOP,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I,CAAC,CAAC;IACnD,IAAIC,QAAQ,CAACC,WAAW,CAAC,CAAC,EAAE;MAC1BL,aAAa,IAAI,MAAML,iBAAiB,CAAC3B,IAAI,CAAC+B,OAAO,EAAEI,IAAI,CAAC,CAAC;IAC/D,CAAC,MAAM;MACLH,aAAa,IAAII,QAAQ,CAACZ,IAAI;IAChC;EACF;EACA,OAAOQ,aAAa;AACtB"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { Queue } from './queue';
|
|
3
3
|
import process from 'process';
|
|
4
|
-
|
|
5
4
|
const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024;
|
|
6
|
-
|
|
7
5
|
export default class WriteQueue extends Queue {
|
|
8
6
|
constructor() {
|
|
9
7
|
let listeningInterval = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2000;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-queue.js","names":["Queue","process","MEMORY_LIMIT","WriteQueue","constructor","listeningInterval","writeConcurrency","enqueue","val","writeImmediately","archiveKey","writePromise","result","fileMap","memoryUsage","rss","startWrite","startListening","intervalId","setInterval","bind","stopListening","clearInterval","doWrite","finalize","
|
|
1
|
+
{"version":3,"file":"write-queue.js","names":["Queue","process","MEMORY_LIMIT","WriteQueue","constructor","listeningInterval","arguments","length","undefined","writeConcurrency","_defineProperty","enqueue","val","writeImmediately","archiveKey","writePromise","result","fileMap","memoryUsage","rss","startWrite","startListening","intervalId","setInterval","bind","stopListening","clearInterval","doWrite","finalize","promises","archiveKeys","i","item","dequeue","push","promise","writeResults","Promise","allSettled","updateFileMap","value"],"sources":["../../../../src/lib/utils/write-queue.ts"],"sourcesContent":["import {Queue} from './queue';\nimport process from 'process';\n\n/** Memory limit size is based on testing */\nconst MEMORY_LIMIT = 4 * 1024 * 1024 * 1024; // 4GB\n\nexport type WriteQueueItem = {\n archiveKey?: string;\n /**\n * writePromise() returns a Promise that will be awaited in Promise.allSettled(promises);\n * Arguments for this call are specified in writeQueue.enqueue call like this:\n * await writeQueue.enqueue({\n * archiveKey: `nodePages/xxx.json.gz`,\n * writePromise: () => writeFileForSlpk(slpkPath, data, `xxx.json`)\n * });\n * Note, a function like writeFileForSlpk should NOT be called when initializing the object for enqueue().\n * If he function is called, the promise will be created\n * and the function will allocate resources (file descriptors) for file writing.\n * It will be done for ALL items in the queue, which is not supposed to happen.\n * That's why the function should be passed as\n * writePromise: () => writeFileForSlpk(slpkPath, content, `xxx.json`)\n * instead of\n * writePromise: writeFileForSlpk(slpkPath, content, `xxx.json`) // INCORRECT !\n */\n writePromise: () => Promise<string | null>;\n};\n\nexport default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {\n private intervalId?: NodeJS.Timeout;\n public writePromise: Promise<void> | null = null;\n public fileMap: {[key: string]: string} = {};\n public listeningInterval: number;\n public writeConcurrency: number;\n\n constructor(listeningInterval: number = 2000, writeConcurrency: number = 400) {\n super();\n this.listeningInterval = listeningInterval;\n this.writeConcurrency = writeConcurrency;\n }\n\n async enqueue(val: T, writeImmediately: boolean = false) {\n if (writeImmediately) {\n const {archiveKey, writePromise} = val as WriteQueueItem;\n const result = await writePromise();\n if (archiveKey && result) {\n this.fileMap[archiveKey] = result;\n }\n } else {\n super.enqueue(val);\n /** https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_memoryusage */\n if (process.memoryUsage().rss > MEMORY_LIMIT) {\n await this.startWrite();\n }\n }\n }\n\n startListening() {\n this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);\n }\n\n stopListening() {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n }\n\n async startWrite(): Promise<void> {\n if (!this.writePromise) {\n this.writePromise = this.doWrite();\n }\n await this.writePromise;\n this.writePromise = null;\n }\n\n async finalize(): Promise<void> {\n this.stopListening();\n await this.startWrite();\n }\n\n private async doWrite(): Promise<void> {\n while (this.length) {\n const promises: Promise<string | null>[] = [];\n const archiveKeys: (string | undefined)[] = [];\n for (let i = 0; i < this.writeConcurrency; i++) {\n const item = this.dequeue();\n if (!item) {\n break;\n }\n const {archiveKey, writePromise} = item as WriteQueueItem;\n archiveKeys.push(archiveKey);\n const promise = writePromise();\n promises.push(promise);\n }\n const writeResults = await Promise.allSettled(promises);\n this.updateFileMap(archiveKeys, writeResults);\n }\n }\n\n private updateFileMap(\n archiveKeys: (string | undefined)[],\n writeResults: PromiseSettledResult<string | null>[]\n ) {\n for (let i = 0; i < archiveKeys.length; i++) {\n const archiveKey = archiveKeys[i];\n if (archiveKey && 'value' in writeResults[i]) {\n this.fileMap[archiveKey] = (writeResults[i] as PromiseFulfilledResult<string>).value;\n }\n }\n }\n}\n"],"mappings":";AAAA,SAAQA,KAAK,QAAO,SAAS;AAC7B,OAAOC,OAAO,MAAM,SAAS;AAG7B,MAAMC,YAAY,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI;AAuB3C,eAAe,MAAMC,UAAU,SAAmCH,KAAK,CAAI;EAOzEI,WAAWA,CAAA,EAAmE;IAAA,IAAlEC,iBAAyB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;IAAA,IAAEG,gBAAwB,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,GAAG;IAC1E,KAAK,CAAC,CAAC;IAACI,eAAA;IAAAA,eAAA,uBANkC,IAAI;IAAAA,eAAA,kBACN,CAAC,CAAC;IAAAA,eAAA;IAAAA,eAAA;IAM1C,IAAI,CAACL,iBAAiB,GAAGA,iBAAiB;IAC1C,IAAI,CAACI,gBAAgB,GAAGA,gBAAgB;EAC1C;EAEA,MAAME,OAAOA,CAACC,GAAM,EAAqC;IAAA,IAAnCC,gBAAyB,GAAAP,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;IACrD,IAAIO,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B,gBAAgB,EAAEsB,CAAC,EAAE,EAAE;QAC9C,MAAMC,IAAI,GAAG,IAAI,CAACC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAACD,IAAI,EAAE;UACT;QACF;QACA,MAAM;UAAClB,UAAU;UAAEC;QAAY,CAAC,GAAGiB,IAAsB;QACzDF,WAAW,CAACI,IAAI,CAACpB,UAAU,CAAC;QAC5B,MAAMqB,OAAO,GAAGpB,YAAY,CAAC,CAAC;QAC9Bc,QAAQ,CAACK,IAAI,CAACC,OAAO,CAAC;MACxB;MACA,MAAMC,YAAY,GAAG,MAAMC,OAAO,CAACC,UAAU,CAACT,QAAQ,CAAC;MACvD,IAAI,CAACU,aAAa,CAACT,WAAW,EAAEM,YAAY,CAAC;IAC/C;EACF;EAEQG,aAAaA,CACnBT,WAAmC,EACnCM,YAAmD,EACnD;IACA,KAAK,IAAIL,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,WAAW,CAACvB,MAAM,EAAEwB,CAAC,EAAE,EAAE;MAC3C,MAAMjB,UAAU,GAAGgB,WAAW,CAACC,CAAC,CAAC;MACjC,IAAIjB,UAAU,IAAI,OAAO,IAAIsB,YAAY,CAACL,CAAC,CAAC,EAAE;QAC5C,IAAI,CAACd,OAAO,CAACH,UAAU,CAAC,GAAIsB,YAAY,CAACL,CAAC,CAAC,CAAoCS,KAAK;MACtF;IACF;EACF;AACF"}
|
package/dist/esm/pgm-loader.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { parsePGM } from '@math.gl/geoid';
|
|
2
|
-
|
|
3
|
-
const VERSION = typeof "3.4.0-alpha.2" !== 'undefined' ? "3.4.0-alpha.2" : 'latest';
|
|
4
|
-
|
|
2
|
+
const VERSION = typeof "3.4.0-alpha.4" !== 'undefined' ? "3.4.0-alpha.4" : 'latest';
|
|
5
3
|
export const PGMLoader = {
|
|
6
4
|
name: 'PGM - Netpbm grayscale image format',
|
|
7
5
|
id: 'pgm',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgm-loader.js","names":["parsePGM","VERSION","PGMLoader","name","id","module","version","mimeTypes","parse","arrayBuffer","options","Uint8Array","extensions","cubic"],"sources":["../../src/pgm-loader.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {parsePGM} from '@math.gl/geoid';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Loader for PGM - Netpbm grayscale image format\n */\nexport const PGMLoader: LoaderWithParser = {\n name: 'PGM - Netpbm grayscale image format',\n id: 'pgm',\n module: 'tile-converter',\n version: VERSION,\n mimeTypes: ['image/x-portable-graymap'],\n // @ts-expect-error LoaderOptions does not have cubic parameter\n parse: async (arrayBuffer, options) => parsePGM(new Uint8Array(arrayBuffer), options),\n extensions: ['pgm'],\n options: {\n // TODO - use pgm namespace\n cubic: false\n }\n};\n"],"mappings":"AACA,SAAQA,QAAQ,QAAO,gBAAgB
|
|
1
|
+
{"version":3,"file":"pgm-loader.js","names":["parsePGM","VERSION","PGMLoader","name","id","module","version","mimeTypes","parse","arrayBuffer","options","Uint8Array","extensions","cubic"],"sources":["../../src/pgm-loader.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {parsePGM} from '@math.gl/geoid';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Loader for PGM - Netpbm grayscale image format\n */\nexport const PGMLoader: LoaderWithParser = {\n name: 'PGM - Netpbm grayscale image format',\n id: 'pgm',\n module: 'tile-converter',\n version: VERSION,\n mimeTypes: ['image/x-portable-graymap'],\n // @ts-expect-error LoaderOptions does not have cubic parameter\n parse: async (arrayBuffer, options) => parsePGM(new Uint8Array(arrayBuffer), options),\n extensions: ['pgm'],\n options: {\n // TODO - use pgm namespace\n cubic: false\n }\n};\n"],"mappings":"AACA,SAAQA,QAAQ,QAAO,gBAAgB;AAIvC,MAAMC,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAK3E,OAAO,MAAMC,SAA2B,GAAG;EACzCC,IAAI,EAAE,qCAAqC;EAC3CC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,gBAAgB;EACxBC,OAAO,EAAEL,OAAO;EAChBM,SAAS,EAAE,CAAC,0BAA0B,CAAC;EAEvCC,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEC,OAAO,KAAKV,QAAQ,CAAC,IAAIW,UAAU,CAACF,WAAW,CAAC,EAAEC,OAAO,CAAC;EACrFE,UAAU,EAAE,CAAC,KAAK,CAAC;EACnBF,OAAO,EAAE;IAEPG,KAAK,EAAE;EACT;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"3d-tiles-attributes-worker.js","names":["createWorker","B3dmConverter","b3dmConverter","data","options","convert","featureAttributes"],"sources":["../../../src/workers/3d-tiles-attributes-worker.ts"],"sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';\n\nconst b3dmConverter = new B3dmConverter();\n\ncreateWorker(async (data, options = {}) => b3dmConverter.convert(data, options.featureAttributes));\n"],"mappings":"AAAA,SAAQA,YAAY,QAAO,0BAA0B;AACrD,OAAOC,aAAa,MAAM,8CAA8C;AAExE,MAAMC,aAAa,GAAG,IAAID,aAAa,
|
|
1
|
+
{"version":3,"file":"3d-tiles-attributes-worker.js","names":["createWorker","B3dmConverter","b3dmConverter","data","options","arguments","length","undefined","convert","featureAttributes"],"sources":["../../../src/workers/3d-tiles-attributes-worker.ts"],"sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport B3dmConverter from '../3d-tiles-converter/helpers/b3dm-converter';\n\nconst b3dmConverter = new B3dmConverter();\n\ncreateWorker(async (data, options = {}) => b3dmConverter.convert(data, options.featureAttributes));\n"],"mappings":"AAAA,SAAQA,YAAY,QAAO,0BAA0B;AACrD,OAAOC,aAAa,MAAM,8CAA8C;AAExE,MAAMC,aAAa,GAAG,IAAID,aAAa,CAAC,CAAC;AAEzCD,YAAY,CAAC,gBAAOG,IAAI;EAAA,IAAEC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAAA,OAAKH,aAAa,CAACM,OAAO,CAACL,IAAI,EAAEC,OAAO,CAACK,iBAAiB,CAAC;AAAA,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i3s-attributes-worker.js","names":["createWorker","convertAttributes","data","options","materialAndTextureList","useCartesianPositions"],"sources":["../../../src/workers/i3s-attributes-worker.ts"],"sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport {convertAttributes} from '../i3s-converter/helpers/geometry-converter';\n\ncreateWorker(\n async (data, options = {}) =>\n await convertAttributes(data, options.materialAndTextureList, options.useCartesianPositions)\n);\n"],"mappings":"AAAA,SAAQA,YAAY,QAAO,0BAA0B;AACrD,SAAQC,iBAAiB,QAAO,6CAA6C;AAE7ED,YAAY,CACV,gBAAOE,IAAI;EAAA,IAAEC,OAAO,
|
|
1
|
+
{"version":3,"file":"i3s-attributes-worker.js","names":["createWorker","convertAttributes","data","options","arguments","length","undefined","materialAndTextureList","useCartesianPositions"],"sources":["../../../src/workers/i3s-attributes-worker.ts"],"sourcesContent":["import {createWorker} from '@loaders.gl/worker-utils';\nimport {convertAttributes} from '../i3s-converter/helpers/geometry-converter';\n\ncreateWorker(\n async (data, options = {}) =>\n await convertAttributes(data, options.materialAndTextureList, options.useCartesianPositions)\n);\n"],"mappings":"AAAA,SAAQA,YAAY,QAAO,0BAA0B;AACrD,SAAQC,iBAAiB,QAAO,6CAA6C;AAE7ED,YAAY,CACV,gBAAOE,IAAI;EAAA,IAAEC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAAA,OACvB,MAAMH,iBAAiB,CAACC,IAAI,EAAEC,OAAO,CAACI,sBAAsB,EAAEJ,OAAO,CAACK,qBAAqB,CAAC;AAAA,CAChG,CAAC"}
|