@loaders.gl/tile-converter 3.1.0-alpha.3 → 3.1.0-beta.2
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/bin/converter.js +1 -1
- package/dist/bundle.js +85947 -4
- package/dist/converter.min.js +292 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +267 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
- package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/b3dm-converter.d.ts +0 -0
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +269 -0
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
- package/dist/{3d-tiles-converter → es5/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -0
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +22 -0
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +40 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +48 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -0
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/{deps-installer → es5/deps-installer}/deps-installer.d.ts +0 -0
- package/dist/es5/deps-installer/deps-installer.js +39 -0
- package/dist/es5/deps-installer/deps-installer.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +65 -0
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +30 -0
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +208 -0
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -0
- package/dist/{i3s-converter → es5/i3s-converter}/helpers/geometry-converter.d.ts +0 -0
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +700 -0
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -0
- package/dist/es5/i3s-converter/helpers/node-debug.js +103 -0
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -0
- package/dist/{i3s-converter → es5/i3s-converter}/helpers/node-pages.d.ts +0 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js +150 -0
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -0
- package/dist/es5/i3s-converter/i3s-converter.js +915 -0
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/layers.js +203 -0
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/metadata.js +29 -0
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/node.js +91 -0
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/scene-server.js +35 -0
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +141 -0
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -0
- package/dist/es5/i3s-converter/json-templates/store.js +105 -0
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -0
- package/dist/es5/i3s-server/app.js +23 -0
- package/dist/es5/i3s-server/app.js.map +1 -0
- package/dist/{i3s-server → es5/i3s-server}/bin/www +0 -0
- package/dist/{i3s-server → es5/i3s-server}/certs/cert.pem +0 -0
- package/dist/{i3s-server → es5/i3s-server}/certs/key.pem +0 -0
- package/dist/es5/i3s-server/controllers/index-controller.js +33 -0
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -0
- package/dist/es5/i3s-server/routes/index.js +22 -0
- package/dist/es5/i3s-server/routes/index.js.map +1 -0
- package/dist/es5/index.js +40 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/{lib → es5/lib}/geoid-height-model.d.ts +0 -0
- package/dist/es5/lib/geoid-height-model.js +149 -0
- package/dist/es5/lib/geoid-height-model.js.map +1 -0
- package/dist/{lib → es5/lib}/pgm-parser.d.ts +0 -0
- package/dist/es5/lib/pgm-parser.js +192 -0
- package/dist/es5/lib/pgm-parser.js.map +1 -0
- package/dist/es5/lib/utils/compress-util.js +202 -0
- package/dist/es5/lib/utils/compress-util.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/compress-utils.d.ts +0 -0
- package/dist/{lib → es5/lib}/utils/file-utils.d.ts +0 -0
- package/dist/es5/lib/utils/file-utils.js +59 -0
- package/dist/es5/lib/utils/file-utils.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/lod-conversion-utils.d.ts +0 -0
- package/dist/es5/lib/utils/lod-conversion-utils.js +52 -0
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -0
- package/dist/{lib → es5/lib}/utils/statistic-utills.d.ts +0 -0
- package/dist/es5/lib/utils/statistic-utills.js +85 -0
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -0
- package/dist/es5/pgm-loader.js +24 -0
- package/dist/es5/pgm-loader.js.map +1 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/3d-tiles-converter.js +19 -13
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +23 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/b3dm-converter.js +19 -8
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +16 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.js +0 -0
- package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/json-templates/tileset.js +0 -0
- package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/deps-installer/deps-installer.d.ts +10 -0
- package/dist/{deps-installer → esm/deps-installer}/deps-installer.js +0 -0
- package/dist/esm/deps-installer/deps-installer.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/coordinate-converter.js +0 -0
- package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/create-scene-server-path.js +0 -0
- package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-attributes.js +0 -0
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +40 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/geometry-converter.js +29 -31
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-debug.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/node-pages.d.ts +144 -0
- package/dist/{i3s-converter → esm/i3s-converter}/helpers/node-pages.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/i3s-converter.js +50 -31
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/layers.js +0 -0
- package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/metadata.js +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/node.js +0 -0
- package/dist/esm/i3s-converter/json-templates/node.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/scene-server.js +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/shared-resources.js +2 -2
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -0
- package/dist/{i3s-converter → esm/i3s-converter}/json-templates/store.js +2 -2
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -0
- package/dist/{i3s-server → esm/i3s-server}/app.js +0 -0
- package/dist/esm/i3s-server/app.js.map +1 -0
- package/dist/esm/i3s-server/bin/www +102 -0
- package/dist/esm/i3s-server/certs/cert.pem +19 -0
- package/dist/esm/i3s-server/certs/key.pem +27 -0
- package/dist/{i3s-server → esm/i3s-server}/controllers/index-controller.js +2 -2
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -0
- package/dist/{i3s-server → esm/i3s-server}/routes/index.js +0 -0
- package/dist/esm/i3s-server/routes/index.js.map +1 -0
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/geoid-height-model.d.ts +41 -0
- package/dist/{lib → esm/lib}/geoid-height-model.js +0 -0
- package/dist/esm/lib/geoid-height-model.js.map +1 -0
- package/dist/esm/lib/pgm-parser.d.ts +14 -0
- package/dist/{lib → esm/lib}/pgm-parser.js +0 -0
- package/dist/esm/lib/pgm-parser.js.map +1 -0
- package/dist/{lib → esm/lib}/utils/compress-util.js +13 -13
- package/dist/esm/lib/utils/compress-util.js.map +1 -0
- package/dist/esm/lib/utils/compress-utils.d.ts +53 -0
- package/dist/esm/lib/utils/file-utils.d.ts +43 -0
- package/dist/{lib → esm/lib}/utils/file-utils.js +1 -1
- package/dist/esm/lib/utils/file-utils.js.map +1 -0
- package/dist/esm/lib/utils/lod-conversion-utils.d.ts +32 -0
- package/dist/{lib → esm/lib}/utils/lod-conversion-utils.js +0 -0
- package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -0
- package/dist/esm/lib/utils/statistic-utills.d.ts +25 -0
- package/dist/{lib → esm/lib}/utils/statistic-utills.js +5 -5
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -0
- package/dist/{pgm-loader.js → esm/pgm-loader.js} +1 -1
- package/dist/esm/pgm-loader.js.map +1 -0
- package/package.json +24 -21
- package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
- package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
- package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
- package/src/i3s-converter/helpers/geometry-converter.js +21 -22
- package/src/i3s-converter/i3s-converter.ts +32 -7
- package/src/i3s-converter/json-templates/metadata.js +1 -1
- package/src/i3s-converter/json-templates/scene-server.js +1 -1
- package/src/i3s-converter/json-templates/store.js +2 -2
- package/src/i3s-server/controllers/index-controller.js +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/bundle.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/dist.min.js +0 -94
- package/dist/dist.min.js.map +0 -1
- package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/layers.js.map +0 -1
- package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
- package/dist/i3s-converter/json-templates/node.js.map +0 -1
- package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
- package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
- package/dist/i3s-converter/json-templates/store.js.map +0 -1
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/geoid-height-model.js.map +0 -1
- package/dist/lib/pgm-parser.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/scripts/converter.js +0 -274
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.timeConverter = timeConverter;
|
|
7
|
+
exports.calculateFilesSize = calculateFilesSize;
|
|
8
|
+
|
|
9
|
+
var _path = require("path");
|
|
10
|
+
|
|
11
|
+
var _fs = require("fs");
|
|
12
|
+
|
|
13
|
+
var _fileUtils = require("./file-utils");
|
|
14
|
+
|
|
15
|
+
function timeConverter(time) {
|
|
16
|
+
const nanoSecondsInMillisecond = 1e6;
|
|
17
|
+
let timeInSeconds = time[0];
|
|
18
|
+
const hours = Math.floor(timeInSeconds / 3600);
|
|
19
|
+
timeInSeconds = timeInSeconds - hours * 3600;
|
|
20
|
+
const minutes = Math.floor(timeInSeconds / 60);
|
|
21
|
+
timeInSeconds = timeInSeconds - minutes * 60;
|
|
22
|
+
const seconds = Math.floor(timeInSeconds);
|
|
23
|
+
const milliseconds = time[1] / nanoSecondsInMillisecond;
|
|
24
|
+
let result = '';
|
|
25
|
+
|
|
26
|
+
if (hours) {
|
|
27
|
+
result += "".concat(hours, "h ");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (minutes) {
|
|
31
|
+
result += "".concat(minutes, "m ");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (seconds) {
|
|
35
|
+
result += "".concat(seconds, "s");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!result) {
|
|
39
|
+
result += "".concat(milliseconds, "ms");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function calculateFilesSize(params) {
|
|
46
|
+
const {
|
|
47
|
+
slpk,
|
|
48
|
+
outputPath,
|
|
49
|
+
tilesetName
|
|
50
|
+
} = params;
|
|
51
|
+
const fullOutputPath = (0, _fileUtils.getAbsoluteFilePath)(outputPath);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
if (slpk) {
|
|
55
|
+
const slpkPath = (0, _path.join)(fullOutputPath, "".concat(tilesetName, ".slpk"));
|
|
56
|
+
const stat = await _fs.promises.stat(slpkPath);
|
|
57
|
+
return stat.size;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const directoryPath = (0, _path.join)(fullOutputPath, tilesetName);
|
|
61
|
+
const totalSize = await getTotalFilesSize(directoryPath);
|
|
62
|
+
return totalSize;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.log('Calculate file sizes error: ', error);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function getTotalFilesSize(dirPath) {
|
|
70
|
+
let totalFileSize = 0;
|
|
71
|
+
const files = await _fs.promises.readdir(dirPath);
|
|
72
|
+
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
const fileStat = await _fs.promises.stat((0, _path.join)(dirPath, file));
|
|
75
|
+
|
|
76
|
+
if (fileStat.isDirectory()) {
|
|
77
|
+
totalFileSize += await getTotalFilesSize((0, _path.join)(dirPath, file));
|
|
78
|
+
} else {
|
|
79
|
+
totalFileSize += fileStat.size;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return totalFileSize;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=statistic-utills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/statistic-utills.js"],"names":["timeConverter","time","nanoSecondsInMillisecond","timeInSeconds","hours","Math","floor","minutes","seconds","milliseconds","result","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","slpkPath","stat","fs","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AAEO,SAASA,aAAT,CAAuBC,IAAvB,EAA6B;AAClC,QAAMC,wBAAwB,GAAG,GAAjC;AACA,MAAIC,aAAa,GAAGF,IAAI,CAAC,CAAD,CAAxB;AACA,QAAMG,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAWH,aAAa,GAAG,IAA3B,CAAd;AACAA,EAAAA,aAAa,GAAGA,aAAa,GAAGC,KAAK,GAAG,IAAxC;AACA,QAAMG,OAAO,GAAGF,IAAI,CAACC,KAAL,CAAWH,aAAa,GAAG,EAA3B,CAAhB;AACAA,EAAAA,aAAa,GAAGA,aAAa,GAAGI,OAAO,GAAG,EAA1C;AACA,QAAMC,OAAO,GAAGH,IAAI,CAACC,KAAL,CAAWH,aAAX,CAAhB;AACA,QAAMM,YAAY,GAAGR,IAAI,CAAC,CAAD,CAAJ,GAAUC,wBAA/B;AACA,MAAIQ,MAAM,GAAG,EAAb;;AAEA,MAAIN,KAAJ,EAAW;AACTM,IAAAA,MAAM,cAAON,KAAP,OAAN;AACD;;AAED,MAAIG,OAAJ,EAAa;AACXG,IAAAA,MAAM,cAAOH,OAAP,OAAN;AACD;;AAED,MAAIC,OAAJ,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LH,MAAAA,aAAa,IAAII,QAAQ,CAACZ,IAA1B;AACD;AACF;;AACD,SAAOQ,aAAP;AACD","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"],"file":"statistic-utills.js"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PGMLoader = void 0;
|
|
7
|
+
|
|
8
|
+
var _pgmParser = require("./lib/pgm-parser");
|
|
9
|
+
|
|
10
|
+
const VERSION = typeof "3.1.0-beta.2" !== 'undefined' ? "3.1.0-beta.2" : 'latest';
|
|
11
|
+
const PGMLoader = {
|
|
12
|
+
name: 'PGM - Netpbm grayscale image format',
|
|
13
|
+
id: 'pgm',
|
|
14
|
+
module: 'tile-converter',
|
|
15
|
+
version: VERSION,
|
|
16
|
+
mimeTypes: ['image/x-portable-graymap'],
|
|
17
|
+
parse: (arrayBuffer, options) => (0, _pgmParser.parsePgm)(new Uint8Array(arrayBuffer), options),
|
|
18
|
+
extensions: ['pgm'],
|
|
19
|
+
options: {
|
|
20
|
+
cubic: false
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.PGMLoader = PGMLoader;
|
|
24
|
+
//# sourceMappingURL=pgm-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/pgm-loader.ts"],"names":["VERSION","PGMLoader","name","id","module","version","mimeTypes","parse","arrayBuffer","options","Uint8Array","extensions","cubic"],"mappings":";;;;;;;AAMA;;AAFA,MAAMA,OAAO,GAAG,0BAAuB,WAAvB,oBAAmD,QAAnE;AAOO,MAAMC,SAA2B,GAAG;AACzCC,EAAAA,IAAI,EAAE,qCADmC;AAEzCC,EAAAA,EAAE,EAAE,KAFqC;AAGzCC,EAAAA,MAAM,EAAE,gBAHiC;AAIzCC,EAAAA,OAAO,EAAEL,OAJgC;AAKzCM,EAAAA,SAAS,EAAE,CAAC,0BAAD,CAL8B;AAMzCC,EAAAA,KAAK,EAAE,CAACC,WAAD,EAAcC,OAAd,KAA0B,yBAAS,IAAIC,UAAJ,CAAeF,WAAf,CAAT,EAAsCC,OAAtC,CANQ;AAOzCE,EAAAA,UAAU,EAAE,CAAC,KAAD,CAP6B;AAQzCF,EAAAA,OAAO,EAAE;AAEPG,IAAAA,KAAK,EAAE;AAFA;AARgC,CAApC","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\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\nimport {parsePgm} from './lib/pgm-parser';\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 parse: (arrayBuffer, options) => parsePgm(new Uint8Array(arrayBuffer), options),\n extensions: ['pgm'],\n options: {\n // TODO - use pgm namespace\n cubic: false\n }\n};\n"],"file":"pgm-loader.js"}
|
|
@@ -3,7 +3,7 @@ import { join } from 'path';
|
|
|
3
3
|
import process from 'process';
|
|
4
4
|
import transform from 'json-map-transform';
|
|
5
5
|
import { load } from '@loaders.gl/core';
|
|
6
|
-
import { I3SLoader, I3SAttributeLoader } from '@loaders.gl/i3s';
|
|
6
|
+
import { I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM } from '@loaders.gl/i3s';
|
|
7
7
|
import { Tileset3D, Tile3D } from '@loaders.gl/tiles';
|
|
8
8
|
import { PGMLoader } from '../pgm-loader';
|
|
9
9
|
import { i3sObbTo3dTilesObb } from './helpers/i3s-obb-to-3d-tiles-obb';
|
|
@@ -55,13 +55,19 @@ export default class Tiles3DConverter {
|
|
|
55
55
|
this.geoidHeightModel = await load(egmFilePath, PGMLoader);
|
|
56
56
|
console.log('Loading egm file completed!');
|
|
57
57
|
const sourceTilesetJson = await load(inputUrl, I3SLoader, {});
|
|
58
|
-
this.sourceTileset = new Tileset3D(sourceTilesetJson, {
|
|
58
|
+
this.sourceTileset = new Tileset3D(sourceTilesetJson, {
|
|
59
|
+
loadOptions: {
|
|
60
|
+
i3s: {
|
|
61
|
+
coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
59
65
|
|
|
60
66
|
if (!this.sourceTileset.root.header.obb) {
|
|
61
67
|
this.sourceTileset.root.header.obb = createObbFromMbs(this.sourceTileset.root.header.mbs);
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
this.tilesetPath = join(
|
|
70
|
+
this.tilesetPath = join("".concat(outputPath), "".concat(tilesetName));
|
|
65
71
|
this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;
|
|
66
72
|
|
|
67
73
|
try {
|
|
@@ -120,10 +126,10 @@ export default class Tiles3DConverter {
|
|
|
120
126
|
};
|
|
121
127
|
const b3dm = await new B3dmConverter().convert(sourceChild, attributes);
|
|
122
128
|
child.content = {
|
|
123
|
-
uri:
|
|
129
|
+
uri: "".concat(sourceChild.id, ".b3dm"),
|
|
124
130
|
boundingVolume
|
|
125
131
|
};
|
|
126
|
-
await writeFile(this.tilesetPath, new Uint8Array(b3dm),
|
|
132
|
+
await writeFile(this.tilesetPath, new Uint8Array(b3dm), "".concat(sourceChild.id, ".b3dm"));
|
|
127
133
|
parentNode.children.push(child);
|
|
128
134
|
sourceChild.unloadContent();
|
|
129
135
|
await this._addChildren(sourceChild, child, level + 1);
|
|
@@ -137,7 +143,7 @@ export default class Tiles3DConverter {
|
|
|
137
143
|
let header;
|
|
138
144
|
|
|
139
145
|
if (this.sourceTileset.tileset.nodePages) {
|
|
140
|
-
console.log(
|
|
146
|
+
console.log("Node conversion: ".concat(childNodeInfo.id));
|
|
141
147
|
header = await this.sourceTileset.tileset.nodePagesTile.formTileFromNodePages(childNodeInfo.id);
|
|
142
148
|
} else {
|
|
143
149
|
const {
|
|
@@ -152,7 +158,7 @@ export default class Tiles3DConverter {
|
|
|
152
158
|
loadContent: false
|
|
153
159
|
}
|
|
154
160
|
};
|
|
155
|
-
console.log(
|
|
161
|
+
console.log("Node conversion: ".concat(nodeUrl));
|
|
156
162
|
header = await load(nodeUrl, loader, options);
|
|
157
163
|
}
|
|
158
164
|
|
|
@@ -227,12 +233,12 @@ export default class Tiles3DConverter {
|
|
|
227
233
|
const filesSize = await calculateFilesSize(params);
|
|
228
234
|
const diff = process.hrtime(this.conversionStartTime);
|
|
229
235
|
const conversionTime = timeConverter(diff);
|
|
230
|
-
console.log(
|
|
231
|
-
console.log(
|
|
232
|
-
console.log(
|
|
233
|
-
console.log(
|
|
234
|
-
console.log(
|
|
235
|
-
console.log(
|
|
236
|
+
console.log("------------------------------------------------");
|
|
237
|
+
console.log("Finish conversion of ".concat(I3S));
|
|
238
|
+
console.log("Total conversion time: ".concat(conversionTime));
|
|
239
|
+
console.log("Vertex count: ", this.vertexCounter);
|
|
240
|
+
console.log("File(s) size: ", filesSize, ' bytes');
|
|
241
|
+
console.log("------------------------------------------------");
|
|
236
242
|
}
|
|
237
243
|
|
|
238
244
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/3d-tiles-converter/3d-tiles-converter.ts"],"names":["join","process","transform","load","I3SLoader","I3SAttributeLoader","COORDINATE_SYSTEM","Tileset3D","Tile3D","PGMLoader","i3sObbTo3dTilesObb","convertScreenThresholdToGeometricError","writeFile","removeDir","calculateFilesSize","timeConverter","TILESET","tilesetTemplate","B3dmConverter","createObbFromMbs","I3S","Tiles3DConverter","constructor","options","tilesetPath","vertexCounter","conversionStartTime","geoidHeightModel","sourceTileset","attributeStorageInfo","convert","inputUrl","outputPath","tilesetName","maxDepth","egmFilePath","hrtime","console","log","sourceTilesetJson","loadOptions","i3s","coordinateSystem","LNGLAT_OFFSETS","root","header","obb","mbs","e","rootTile","boundingVolume","box","geometricError","children","_addChildren","tileset","JSON","stringify","_finishConversion","slpk","parentSourceNode","parentNode","level","childNodeInfo","sourceChild","_loadChildNode","push","contentUrl","_loadTile","content","vertexCount","attributes","_loadChildAttributes","child","b3dm","uri","id","Uint8Array","unloadContent","nodePages","nodePagesTile","formTileFromNodePages","loader","nodeUrl","_relativeUrlToFullUrl","url","href","isTileHeader","loadContent","baseUrl","relativeUrl","resultArray","split","relativeUrlArray","folder","slice","promises","attributeUrls","index","length","attribute","attributeName","name","attributeType","_getAttributeType","attributesList","Promise","all","_replaceNestedArrays","Object","assign","attributeValues","valueType","objectIds","attributeObject","key","Array","from","params","filesSize","diff","conversionTime"],"mappings":";AAGA,SAAQA,IAAR,QAAmB,MAAnB;AACA,OAAOC,OAAP,MAAoB,SAApB;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AACA,SAAQC,IAAR,QAAmB,kBAAnB;AACA,SAAQC,SAAR,EAAmBC,kBAAnB,EAAuCC,iBAAvC,QAA+D,iBAA/D;AACA,SAAQC,SAAR,EAAmBC,MAAnB,QAAgC,mBAAhC;AAEA,SAAQC,SAAR,QAAwB,eAAxB;AACA,SAAQC,kBAAR,QAAiC,mCAAjC;AACA,SAAQC,sCAAR,QAAqD,mCAArD;AACA,SAAQC,SAAR,EAAmBC,SAAnB,QAAmC,yBAAnC;AACA,SAAQC,kBAAR,EAA4BC,aAA5B,QAAgD,+BAAhD;AACA,SAAQC,OAAO,IAAIC,eAAnB,QAAyC,0BAAzC;AACA,OAAOC,aAAP,MAA0B,0BAA1B;AACA,SAAQC,gBAAR,QAA+B,+CAA/B;AAGA,MAAMC,GAAG,GAAG,KAAZ;AAKA,eAAe,MAAMC,gBAAN,CAAuB;AASpCC,EAAAA,WAAW,GAAG;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACZ,SAAKC,OAAL,GAAe,EAAf;AACA,SAAKC,WAAL,GAAmB,EAAnB;AACA,SAAKC,aAAL,GAAqB,CAArB;AACA,SAAKC,mBAAL,GAA2B,CAAC,CAAD,EAAI,CAAJ,CAA3B;AACA,SAAKC,gBAAL,GAAwB,IAAxB;AACA,SAAKC,aAAL,GAAqB,IAArB;AACA,SAAKC,oBAAL,GAA4B,IAA5B;AACD;;AAWoB,QAAPC,OAAO,CAACP,OAAD,EAMJ;AACf,UAAM;AAACQ,MAAAA,QAAD;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;AACD,KAFD,MAEO,IAAIZ,SAAS,CAACa,SAAd,EAAyB;AAC9B,aAAO,OAAP;AACD;;AACD,WAAO,EAAP;AACD;;AAMOL,EAAAA,oBAAoB,CAACH,cAAD,EAA2C;AACrE,SAAK,IAAIP,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGO,cAAc,CAACN,MAA3C,EAAmDD,KAAK,EAAxD,EAA4D;AAC1D,YAAMgB,eAAe,GAAGT,cAAc,CAACP,KAAD,CAAtC;;AAEA,WAAK,MAAMiB,GAAX,IAAkBD,eAAlB,EAAmC;AACjCA,QAAAA,eAAe,CAACC,GAAD,CAAf,GAAuBC,KAAK,CAACC,IAAN,CAAWH,eAAe,CAACC,GAAD,CAA1B,CAAvB;AACD;AACF;AACF;;AAM8B,QAAjBzD,iBAAiB,CAAC4D,MAAD,EAIb;AAChB,UAAMC,SAAS,GAAG,MAAMzG,kBAAkB,CAACwG,MAAD,CAA1C;AACA,UAAME,IAAI,GAAGvH,OAAO,CAACmC,MAAR,CAAe,KAAKV,mBAApB,CAAb;AACA,UAAM+F,cAAc,GAAG1G,aAAa,CAACyG,IAAD,CAApC;AAEAnF,IAAAA,OAAO,CAACC,GAAR;AACAD,IAAAA,OAAO,CAACC,GAAR,gCAAoClB,GAApC;AACAiB,IAAAA,OAAO,CAACC,GAAR,kCAAsCmF,cAAtC;AACApF,IAAAA,OAAO,CAACC,GAAR,mBAA8B,KAAKb,aAAnC;AACAY,IAAAA,OAAO,CAACC,GAAR,mBAA8BiF,SAA9B,EAAyC,QAAzC;AACAlF,IAAAA,OAAO,CAACC,GAAR;AACD;;AAtQmC","sourcesContent":["import type {AttributeStorageInfo, FeatureAttribute, NodeReference} from '@loaders.gl/i3s';\nimport type {Node3D} from '@loaders.gl/3d-tiles';\n\nimport {join} from 'path';\nimport process from 'process';\nimport transform from 'json-map-transform';\nimport {load} from '@loaders.gl/core';\nimport {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';\nimport {Tileset3D, Tile3D} from '@loaders.gl/tiles';\n\nimport {PGMLoader} from '../pgm-loader';\nimport {i3sObbTo3dTilesObb} from './helpers/i3s-obb-to-3d-tiles-obb';\nimport {convertScreenThresholdToGeometricError} from '../lib/utils/lod-conversion-utils';\nimport {writeFile, removeDir} from '../lib/utils/file-utils';\nimport {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';\nimport {TILESET as tilesetTemplate} from './json-templates/tileset';\nimport B3dmConverter from './helpers/b3dm-converter';\nimport {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';\nimport {GeoidHeightModel} from '../lib/geoid-height-model';\n\nconst I3S = 'I3S';\n\n/**\n * Converter from i3s to 3d-tiles\n */\nexport default class Tiles3DConverter {\n options: any;\n tilesetPath: string;\n vertexCounter: number;\n conversionStartTime: [number, number];\n geoidHeightModel: GeoidHeightModel;\n sourceTileset: Tileset3D;\n attributeStorageInfo: AttributeStorageInfo;\n\n constructor() {\n this.options = {};\n this.tilesetPath = '';\n this.vertexCounter = 0;\n this.conversionStartTime = [0, 0];\n this.geoidHeightModel = null;\n this.sourceTileset = null;\n this.attributeStorageInfo = null;\n }\n\n /**\n * Convert i3s format data to 3dTiles\n * @param options\n * @param options.inputUrl the url to read the tileset from\n * @param options.outputPath the output filename\n * @param options.tilesetName the output name of the tileset\n * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format\n * @param options.maxDepth The max tree depth of conversion\n */\n private async convert(options: {\n inputUrl: string;\n outputPath: string;\n tilesetName: string;\n maxDepth: number;\n egmFilePath: string;\n }): Promise<any> {\n const {inputUrl, outputPath, tilesetName, maxDepth, egmFilePath} = options;\n this.conversionStartTime = process.hrtime();\n this.options = {maxDepth};\n\n console.log('Loading egm file...'); // eslint-disable-line\n this.geoidHeightModel = await load(egmFilePath, PGMLoader);\n console.log('Loading egm file completed!'); // eslint-disable-line\n\n const sourceTilesetJson = await load(inputUrl, I3SLoader, {});\n this.sourceTileset = new Tileset3D(sourceTilesetJson, {\n loadOptions: {i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS}}\n });\n\n if (!this.sourceTileset.root.header.obb) {\n this.sourceTileset.root.header.obb = createObbFromMbs(this.sourceTileset.root.header.mbs);\n }\n\n this.tilesetPath = join(`${outputPath}`, `${tilesetName}`);\n this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;\n // Removing the tilesetPath needed to exclude erroneous files after conversion\n try {\n await removeDir(this.tilesetPath);\n } catch (e) {\n // do nothing\n }\n\n const rootTile: Node3D = {\n boundingVolume: {\n box: i3sObbTo3dTilesObb(this.sourceTileset.root.header.obb, this.geoidHeightModel)\n },\n geometricError: convertScreenThresholdToGeometricError(this.sourceTileset.root),\n children: []\n };\n\n await this._addChildren(this.sourceTileset.root, rootTile, 1);\n\n const tileset = transform({root: rootTile}, tilesetTemplate);\n await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');\n\n this._finishConversion({slpk: false, outputPath, tilesetName});\n }\n\n /**\n * The recursive function of traversal of a nodes tree\n * @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param parentNode object in resulting tileset\n * @param level a current level of a tree depth\n */\n private async _addChildren(\n parentSourceNode: Tile3D,\n parentNode: Node3D,\n level: number\n ): Promise<void> {\n if (this.options.maxDepth && level > this.options.maxDepth) {\n return;\n }\n for (const childNodeInfo of parentSourceNode.header.children || []) {\n const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);\n parentSourceNode.children.push(sourceChild);\n if (sourceChild.contentUrl) {\n await this.sourceTileset._loadTile(sourceChild);\n this.vertexCounter += sourceChild.content.vertexCount;\n\n let attributes = null;\n if (this.attributeStorageInfo) {\n attributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);\n }\n\n if (!sourceChild.header.obb) {\n sourceChild.header.obb = createObbFromMbs(sourceChild.header.mbs);\n }\n\n const boundingVolume = {\n box: i3sObbTo3dTilesObb(sourceChild.header.obb, this.geoidHeightModel)\n };\n const child: Node3D = {\n boundingVolume,\n geometricError: convertScreenThresholdToGeometricError(sourceChild),\n children: []\n };\n\n const b3dm = await new B3dmConverter().convert(sourceChild, attributes);\n child.content = {\n uri: `${sourceChild.id}.b3dm`,\n boundingVolume\n };\n await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);\n parentNode.children.push(child);\n\n sourceChild.unloadContent();\n await this._addChildren(sourceChild, child, level + 1);\n } else {\n await this._addChildren(sourceChild, parentNode, level + 1);\n }\n }\n }\n\n /**\n * Load a child node having information from the node header\n * @param parentNode a parent node tile object (@loaders.gl/tiles/Tile3D)\n * @param childNodeInfo child information from 3DNodeIndexDocument\n * (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodeReference.cmn.md)\n */\n private async _loadChildNode(parentNode: Tile3D, childNodeInfo: NodeReference): Promise<Tile3D> {\n let header;\n if (this.sourceTileset.tileset.nodePages) {\n console.log(`Node conversion: ${childNodeInfo.id}`); // eslint-disable-line no-console,no-undef\n header = await this.sourceTileset.tileset.nodePagesTile.formTileFromNodePages(\n childNodeInfo.id\n );\n } else {\n const {loader} = this.sourceTileset;\n const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href);\n // load metadata\n const options = {\n i3s: {\n ...this.sourceTileset.loadOptions,\n isTileHeader: true,\n loadContent: false\n }\n };\n\n console.log(`Node conversion: ${nodeUrl}`); // eslint-disable-line no-console,no-undef\n header = await load(nodeUrl, loader, options);\n }\n return new Tile3D(this.sourceTileset, header, parentNode);\n }\n\n /**\n * Make an url of a resource from its relative url having the base url\n * @param baseUrl the base url. A resulting url will be related from this url\n * @param relativeUrl a realtive url of a resource\n */\n private _relativeUrlToFullUrl(baseUrl: string, relativeUrl: string): string {\n let resultArray = baseUrl.split('/');\n const relativeUrlArray = relativeUrl.split('/');\n for (const folder of relativeUrlArray) {\n switch (folder) {\n case '.':\n continue; // eslint-disable-line no-continue\n case '..':\n resultArray = resultArray.slice(0, -1);\n break;\n default:\n resultArray.push(folder);\n }\n }\n return resultArray.join('/');\n }\n\n /**\n * Do loading all attributes related to particular node.\n * @param sourceChild\n * @param attributeStorageInfo\n * @returns Promise of attributes object.\n */\n private async _loadChildAttributes(\n sourceChild: Tile3D,\n attributeStorageInfo: AttributeStorageInfo\n ): Promise<FeatureAttribute> {\n const promises = [];\n const {attributeUrls} = sourceChild.header;\n\n for (let index = 0; index < attributeUrls.length; index++) {\n const inputUrl = attributeUrls[index];\n const attribute = attributeStorageInfo[index];\n const options = {\n attributeName: attribute.name,\n attributeType: this._getAttributeType(attribute)\n };\n\n promises.push(load(inputUrl, I3SAttributeLoader, options));\n }\n const attributesList = await Promise.all(promises);\n this._replaceNestedArrays(attributesList);\n return Object.assign({}, ...attributesList);\n }\n\n /**\n * Returns attribute type for loading attributes\n * @param attribute\n * Workaround for I3S v1.6. There is no attribute.attributeValues.valueType field in attribute.\n * There is an 'Oid32' type if attribute has objectIds property.\n * Doc: https://github.com/Esri/i3s-spec/blob/master/docs/1.6/attributeStorageInfo.cmn.md\n */\n private _getAttributeType(attribute: AttributeStorageInfo): string {\n if (attribute.attributeValues) {\n return attribute.attributeValues.valueType;\n } else if (attribute.objectIds) {\n return 'Oid32';\n }\n return '';\n }\n\n /**\n * Make simple arrays from attribute typed arrays.\n * @param attributesList\n */\n private _replaceNestedArrays(attributesList: FeatureAttribute[]): void {\n for (let index = 0; index < attributesList.length; index++) {\n const attributeObject = attributesList[index];\n\n for (const key in attributeObject) {\n attributeObject[key] = Array.from(attributeObject[key]);\n }\n }\n }\n\n /**\n * Print statistics in the end of conversion\n * @param params - output files data\n */\n private async _finishConversion(params: {\n slpk: boolean;\n outputPath: string;\n tilesetName: string;\n }): Promise<void> {\n const filesSize = await calculateFilesSize(params);\n const diff = process.hrtime(this.conversionStartTime);\n const conversionTime = timeConverter(diff);\n\n console.log(`------------------------------------------------`); // eslint-disable-line\n console.log(`Finish conversion of ${I3S}`); // eslint-disable-line\n console.log(`Total conversion time: ${conversionTime}`); // eslint-disable-line\n console.log(`Vertex count: `, this.vertexCounter); // eslint-disable-line\n console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line\n console.log(`------------------------------------------------`); // eslint-disable-line\n }\n}\n"],"file":"3d-tiles-converter.js"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts content of an I3S node to *.b3dm's file content
|
|
3
|
+
*/
|
|
4
|
+
export default class B3dmConverter {
|
|
5
|
+
rtcCenter: Float32Array;
|
|
6
|
+
i3sTile: any;
|
|
7
|
+
|
|
8
|
+
constructor();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The starter of content conversion
|
|
12
|
+
* @param i3sTile - Tile3D instance for I3S node
|
|
13
|
+
* @returns - encoded content
|
|
14
|
+
*/
|
|
15
|
+
convert(i3sTile: Object, attributes?: any): ArrayBuffer;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Build and encode gltf
|
|
19
|
+
* @param i3sTile - Tile3D instance for I3S node
|
|
20
|
+
* @returns - encoded glb content
|
|
21
|
+
*/
|
|
22
|
+
buildGltf(i3sTile): ArrayBuffer;
|
|
23
|
+
}
|
|
@@ -3,7 +3,10 @@ import { GLTFScenegraph, GLTFWriter } from '@loaders.gl/gltf';
|
|
|
3
3
|
import { Tile3DWriter } from '@loaders.gl/3d-tiles';
|
|
4
4
|
import { ImageWriter } from '@loaders.gl/images';
|
|
5
5
|
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
6
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
7
|
+
import { convertTextureAtlas } from './texture-atlas';
|
|
6
8
|
const Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
|
|
9
|
+
const scratchVector = new Vector3();
|
|
7
10
|
export default class B3dmConverter {
|
|
8
11
|
async convert(i3sTile, attributes = null) {
|
|
9
12
|
this.i3sTile = i3sTile;
|
|
@@ -22,7 +25,9 @@ export default class B3dmConverter {
|
|
|
22
25
|
material,
|
|
23
26
|
attributes,
|
|
24
27
|
indices: originalIndices,
|
|
25
|
-
cartesianOrigin
|
|
28
|
+
cartesianOrigin,
|
|
29
|
+
cartographicOrigin,
|
|
30
|
+
modelMatrix
|
|
26
31
|
} = i3sTile.content;
|
|
27
32
|
const gltfBuilder = new GLTFScenegraph();
|
|
28
33
|
const textureIndex = await this._addI3sTextureToGltf(i3sTile, gltfBuilder);
|
|
@@ -32,7 +37,12 @@ export default class B3dmConverter {
|
|
|
32
37
|
const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
|
|
33
38
|
const positions = attributes.positions;
|
|
34
39
|
const positionsValue = positions.value;
|
|
35
|
-
|
|
40
|
+
|
|
41
|
+
if (attributes.uvRegions && attributes.texCoords) {
|
|
42
|
+
attributes.texCoords.value = convertTextureAtlas(attributes.texCoords.value, attributes.uvRegions.value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
attributes.positions.value = this._normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix);
|
|
36
46
|
|
|
37
47
|
if (attributes.normals && !this._checkNormals(attributes.normals.value)) {
|
|
38
48
|
delete attributes.normals;
|
|
@@ -93,14 +103,15 @@ export default class B3dmConverter {
|
|
|
93
103
|
return textureIndex;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
|
-
_normalizePositions(positionsValue, cartesianOrigin) {
|
|
106
|
+
_normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {
|
|
97
107
|
const newPositionsValue = new Float32Array(positionsValue.length);
|
|
98
108
|
|
|
99
109
|
for (let index = 0; index < positionsValue.length; index += 3) {
|
|
100
110
|
const vertex = positionsValue.subarray(index, index + 3);
|
|
101
|
-
const
|
|
102
|
-
let vertexVector = new Vector3(Array.from(vertex));
|
|
103
|
-
vertexVector
|
|
111
|
+
const cartesianOriginVector = new Vector3(cartesianOrigin);
|
|
112
|
+
let vertexVector = new Vector3(Array.from(vertex)).transform(modelMatrix).add(cartographicOrigin);
|
|
113
|
+
Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);
|
|
114
|
+
vertexVector = scratchVector.subtract(cartesianOriginVector);
|
|
104
115
|
newPositionsValue.set(vertexVector, index);
|
|
105
116
|
}
|
|
106
117
|
|
|
@@ -149,7 +160,7 @@ export default class B3dmConverter {
|
|
|
149
160
|
return 'image/png';
|
|
150
161
|
|
|
151
162
|
default:
|
|
152
|
-
console.warn(
|
|
163
|
+
console.warn("Unexpected texture format in I3S: ".concat(format));
|
|
153
164
|
return 'image/jpeg';
|
|
154
165
|
}
|
|
155
166
|
}
|
|
@@ -228,7 +239,7 @@ export default class B3dmConverter {
|
|
|
228
239
|
}
|
|
229
240
|
|
|
230
241
|
const firstKey = Object.keys(attributes)[0];
|
|
231
|
-
return attributes[firstKey].length;
|
|
242
|
+
return firstKey ? attributes[firstKey].length : 0;
|
|
232
243
|
}
|
|
233
244
|
|
|
234
245
|
_checkNormals(normals) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/3d-tiles-converter/helpers/b3dm-converter.js"],"names":["encode","encodeSync","GLTFScenegraph","GLTFWriter","Tile3DWriter","ImageWriter","Matrix4","Vector3","Ellipsoid","convertTextureAtlas","Z_UP_TO_Y_UP_MATRIX","scratchVector","B3dmConverter","convert","i3sTile","attributes","gltf","buildGltf","b3dm","gltfEncoded","Uint8Array","type","featuresLength","_getFeaturesLength","batchTable","material","indices","originalIndices","cartesianOrigin","cartographicOrigin","modelMatrix","content","gltfBuilder","textureIndex","_addI3sTextureToGltf","pbrMaterialInfo","_convertI3sMaterialToGltfMaterial","materialIndex","addMaterial","positions","positionsValue","value","uvRegions","texCoords","_normalizePositions","normals","_checkNormals","_generateSynteticIndices","length","size","meshIndex","addMesh","transformMatrix","_generateTransformMatrix","nodeIndex","addNode","matrix","sceneIndex","addScene","nodeIndices","setDefaultScene","createBinaryChunk","gltfBuffer","texture","header","textureFormat","selectedTexture","pbrMetallicRoughness","baseColorTexture","source","image","mimeType","_deduceMimeTypeFromFormat","imageBuffer","imageIndex","addImage","addTexture","colors","newPositionsValue","Float32Array","index","vertex","subarray","cartesianOriginVector","vertexVector","Array","from","transform","add","WGS84","cartographicToCartesian","subtract","set","translateOriginMatrix","translate","result","multiplyLeft","_generateBatchId","faceRanges","batchIdArraySize","batchId","rangeIndex","currentBatchId","fromIndex","untilPosition","fill","vertexCount","Uint32Array","format","console","warn","isTextureIndexExists","alphaMode","doubleSided","metallicFactor","roughnessFactor","texCoord","baseColorFactor","_setGltfTexture","materialDefinition","emissiveTexture","metallicRoughnessTexture","normalTexture","occlusionTexture","firstKey","Object","keys","find"],"mappings":"AAAA,SAAQA,MAAR,EAAgBC,UAAhB,QAAiC,kBAAjC;AACA,SAAQC,cAAR,EAAwBC,UAAxB,QAAyC,kBAAzC;AACA,SAAQC,YAAR,QAA2B,sBAA3B;AACA,SAAQC,WAAR,QAA0B,oBAA1B;AACA,SAAQC,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,mBAAR,QAAkC,iBAAlC;AAEA,MAAMC,mBAAmB,GAAG,IAAIJ,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAC,CAApB,EAAuB,CAAvB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmC,CAAnC,EAAsC,CAAtC,EAAyC,CAAzC,EAA4C,CAA5C,EAA+C,CAA/C,CAAZ,CAA5B;AACA,MAAMK,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AAEA,eAAe,MAAMK,aAAN,CAAoB;AACpB,QAAPC,OAAO,CAACC,OAAD,EAAUC,UAAU,GAAG,IAAvB,EAA6B;AACxC,SAAKD,OAAL,GAAeA,OAAf;AACA,UAAME,IA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,MAKA,IAAIG,kBAAkB,CAACI,gBAAvB,EAAyC;AAC9ClG,MAAAA,QAAQ,CAACkG,gBAAT,GAA4B;AAC1B3C,QAAAA,KAAK,EAAE/C,YADmB;AAE1BmF,QAAAA,QAAQ,EAAE;AAFgB,OAA5B;AAID;;AACD,WAAO3F,QAAP;AACD;;AAODF,EAAAA,kBAAkB,CAACR,UAAD,EAAa;AAC7B,QAAI,CAACA,UAAL,EAAiB;AACf,aAAO,CAAP;AACD;;AACD,UAAM6G,QAAQ,GAAGC,MAAM,CAACC,IAAP,CAAY/G,UAAZ,EAAwB,CAAxB,CAAjB;AACA,WAAO6G,QAAQ,GAAG7G,UAAU,CAAC6G,QAAD,CAAV,CAAqB5E,MAAxB,GAAiC,CAAhD;AACD;;AAMDF,EAAAA,aAAa,CAACD,OAAD,EAAU;AAErB,WAAOA,OAAO,CAACkF,IAAR,CAActF,KAAD,IAAWA,KAAxB,CAAP;AACD;;AAxSgC","sourcesContent":["import {encode, encodeSync} from '@loaders.gl/core';\nimport {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';\nimport {Tile3DWriter} from '@loaders.gl/3d-tiles';\nimport {ImageWriter} from '@loaders.gl/images';\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {convertTextureAtlas} from './texture-atlas';\n\nconst Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1]);\nconst scratchVector = new Vector3();\n\nexport default class B3dmConverter {\n async convert(i3sTile, attributes = null) {\n this.i3sTile = i3sTile;\n const gltf = await this.buildGltf(i3sTile);\n const b3dm = encodeSync(\n {\n gltfEncoded: new Uint8Array(gltf),\n type: 'b3dm',\n featuresLength: this._getFeaturesLength(attributes),\n batchTable: attributes\n },\n Tile3DWriter\n );\n return b3dm;\n }\n\n async buildGltf(i3sTile) {\n const {\n material,\n attributes,\n indices: originalIndices,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n } = i3sTile.content;\n const gltfBuilder = new GLTFScenegraph();\n\n const textureIndex = await this._addI3sTextureToGltf(i3sTile, gltfBuilder);\n const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);\n const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);\n\n const positions = attributes.positions;\n const positionsValue = positions.value;\n\n if (attributes.uvRegions && attributes.texCoords) {\n attributes.texCoords.value = convertTextureAtlas(\n attributes.texCoords.value,\n attributes.uvRegions.value\n );\n }\n\n attributes.positions.value = this._normalizePositions(\n positionsValue,\n cartesianOrigin,\n cartographicOrigin,\n modelMatrix\n );\n if (attributes.normals && !this._checkNormals(attributes.normals.value)) {\n delete attributes.normals;\n }\n const indices =\n originalIndices || this._generateSynteticIndices(positionsValue.length / positions.size);\n const meshIndex = gltfBuilder.addMesh({\n attributes,\n indices,\n material: materialIndex\n });\n const transformMatrix = this._generateTransformMatrix(cartesianOrigin);\n const nodeIndex = gltfBuilder.addNode({meshIndex, matrix: transformMatrix});\n const sceneIndex = gltfBuilder.addScene({nodeIndices: [nodeIndex]});\n gltfBuilder.setDefaultScene(sceneIndex);\n\n gltfBuilder.createBinaryChunk();\n\n const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);\n\n return gltfBuffer;\n }\n\n /**\n * Update gltfBuilder with texture from I3S tile\n * @param {object} i3sTile - Tile3D object\n * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF\n * @returns {Promise<number | null>} - GLTF texture index\n */\n async _addI3sTextureToGltf(i3sTile, gltfBuilder) {\n const {\n content: {texture, material, attributes},\n header: {textureFormat}\n } = i3sTile;\n let textureIndex = null;\n let selectedTexture = texture;\n if (!texture && material) {\n selectedTexture =\n material.pbrMetallicRoughness &&\n material.pbrMetallicRoughness.baseColorTexture &&\n material.pbrMetallicRoughness.baseColorTexture.texture.source.image;\n }\n if (selectedTexture) {\n const mimeType = this._deduceMimeTypeFromFormat(textureFormat);\n const imageBuffer = await encode(selectedTexture, ImageWriter);\n const imageIndex = gltfBuilder.addImage(imageBuffer, mimeType);\n textureIndex = gltfBuilder.addTexture({imageIndex});\n delete attributes.colors;\n }\n return textureIndex;\n }\n\n /**\n * Generate a positions array which is correct for 3DTiles/GLTF format\n * @param {Float64Array} positionsValue - the input geometry positions array\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @param {number[]} cartographicOrigin - the tile center in the cartographic coordinate system\n * @param {number[]} modelMatrix - the model matrix of geometry\n * @returns {Float32Array} - the output geometry positions array\n */\n _normalizePositions(positionsValue, cartesianOrigin, cartographicOrigin, modelMatrix) {\n const newPositionsValue = new Float32Array(positionsValue.length);\n for (let index = 0; index < positionsValue.length; index += 3) {\n const vertex = positionsValue.subarray(index, index + 3);\n const cartesianOriginVector = new Vector3(cartesianOrigin);\n let vertexVector = new Vector3(Array.from(vertex))\n .transform(modelMatrix)\n .add(cartographicOrigin);\n Ellipsoid.WGS84.cartographicToCartesian(vertexVector, scratchVector);\n vertexVector = scratchVector.subtract(cartesianOriginVector);\n newPositionsValue.set(vertexVector, index);\n }\n return newPositionsValue;\n }\n\n /**\n * Generate the transformation matrix for GLTF node:\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-node\n * 1. Create the translate transformation from cartesianOrigin (the positions array stores offsets from this cartesianOrigin)\n * 2. Create the rotation transformation to rotate model from z-up coordinates (I3S specific) to y-up coordinates (GLTF specific)\n * @param {number[]} cartesianOrigin - the tile center in the cartesian coordinate system\n * @returns {Matrix4} - an array of 16 numbers (4x4 matrix)\n */\n _generateTransformMatrix(cartesianOrigin) {\n const translateOriginMatrix = new Matrix4().translate(cartesianOrigin);\n const result = translateOriginMatrix.multiplyLeft(Z_UP_TO_Y_UP_MATRIX);\n return result;\n }\n\n /**\n * Generate batchId attribute from faceRanges.\n * @param {Uint32Array} faceRanges - the source array\n * @returns {Float32Array} batchId list.\n */\n _generateBatchId(faceRanges) {\n const batchIdArraySize = (faceRanges[faceRanges.length - 1] + 1) * 3;\n const batchId = new Float32Array(batchIdArraySize);\n let rangeIndex = 0;\n let currentBatchId = 0;\n\n for (let index = 0; index < faceRanges.length / 2; index++) {\n const fromIndex = faceRanges[rangeIndex] * 3;\n const untilPosition = (faceRanges[rangeIndex + 1] + 1) * 3;\n\n batchId.fill(currentBatchId, fromIndex, untilPosition);\n rangeIndex += 2;\n currentBatchId += 1;\n }\n return batchId;\n }\n\n /**\n * luma.gl can not work without indices now:\n * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115\n * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]\n * @param {number} vertexCount - vertex count in the geometry\n * @returns {Uint32Array} indices array.\n */\n _generateSynteticIndices(vertexCount) {\n const result = new Uint32Array(vertexCount);\n for (let index = 0; index < vertexCount; index++) {\n result.set([index], index);\n }\n return result;\n }\n\n /**\n * Deduce mime type by format from `textureSetDefinition.formats[0].format`\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n * @param {string} format - format name\n * @returns {string} mime type.\n */\n _deduceMimeTypeFromFormat(format) {\n switch (format) {\n case 'jpg':\n return 'image/jpeg';\n case 'png':\n return 'image/png';\n default:\n console.warn(`Unexpected texture format in I3S: ${format}`); // eslint-disable-line no-console, no-undef\n return 'image/jpeg';\n }\n }\n\n /**\n * Convert i3s material to GLTF compatible material\n * @param {object} material - i3s material definition\n * @param {number | null} textureIndex - texture index in GLTF\n * @returns {object} GLTF material\n */\n _convertI3sMaterialToGltfMaterial(material, textureIndex) {\n const isTextureIndexExists = textureIndex !== null;\n\n if (!material) {\n material = {\n alphaMode: 'OPAQUE',\n doubleSided: false,\n pbrMetallicRoughness: {\n metallicFactor: 0,\n roughnessFactor: 1\n }\n };\n\n if (isTextureIndexExists) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else {\n material.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];\n }\n\n return material;\n }\n\n if (textureIndex !== null) {\n material = this._setGltfTexture(material, textureIndex);\n }\n\n return material;\n }\n\n /**\n * Set texture properties in material with GLTF textureIndex\n * @param {object} materialDefinition - i3s material definition\n * @param {number} textureIndex - texture index in GLTF\n * @returns {void}\n */\n _setGltfTexture(materialDefinition, textureIndex) {\n const material = {\n ...materialDefinition,\n pbrMetallicRoughness: {...materialDefinition.pbrMetallicRoughness}\n };\n // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of\n // properties defined in materialDefinition\n if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.baseColorTexture\n ) {\n material.pbrMetallicRoughness.baseColorTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.emissiveTexture) {\n material.emissiveTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.metallicRoughnessTexture\n ) {\n material.pbrMetallicRoughness.metallicRoughnessTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.normalTexture) {\n material.normalTexture = {\n index: textureIndex,\n texCoord: 0\n };\n } else if (materialDefinition.occlusionTexture) {\n material.occlusionTexture = {\n index: textureIndex,\n texCoord: 0\n };\n }\n return material;\n }\n\n /*\n * Returns Features length based on attribute array in attribute object.\n * @param {Object} attributes\n * @returns {Number} Features length .\n */\n _getFeaturesLength(attributes) {\n if (!attributes) {\n return 0;\n }\n const firstKey = Object.keys(attributes)[0];\n return firstKey ? attributes[firstKey].length : 0;\n }\n\n /* Checks that normals buffer is correct\n * @param {TypedArray} normals\n * @returns {boolean} true - normals are correct; false - normals are incorrect\n */\n _checkNormals(normals) {\n // If all normals === 0, the resulting tileset is all in black colors on Cesium\n return normals.find((value) => value);\n }\n}\n"],"file":"b3dm-converter.js"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {GeoidHeightModel} from '@loaders.gl/tile-converter/lib/geoid-height-model';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert quaternion-based OBB to half-axes-based OBB
|
|
5
|
+
* @param i3SObb quaternion based OBB
|
|
6
|
+
* @param geoidHeightModel the Earth Gravity Model instance
|
|
7
|
+
* @returns number[12] 3DTiles OBB https://github.com/CesiumGS/3d-tiles/tree/master/specification#box
|
|
8
|
+
*/
|
|
9
|
+
export function i3sObbTo3dTilesObb(
|
|
10
|
+
i3SObb: {
|
|
11
|
+
center: number[];
|
|
12
|
+
halfSize: number[];
|
|
13
|
+
quaternion: number[];
|
|
14
|
+
},
|
|
15
|
+
geoidHeightModel: GeoidHeightModel
|
|
16
|
+
): number[];
|
package/dist/{3d-tiles-converter → esm/3d-tiles-converter}/helpers/i3s-obb-to-3d-tiles-obb.js
RENAMED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js"],"names":["Vector3","Ellipsoid","OrientedBoundingBox","i3sObbTo3dTilesObb","i3SObb","geoidHeightModel","tiles3DCenter","center","getHeight","cartesianCenter","WGS84","cartographicToCartesian","tiles3DObb","fromCenterHalfSizeQuaternion","halfSize","quaternion","halfAxes","toArray"],"mappings":"AAAA,SAAQA,OAAR,QAAsB,eAAtB;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,mBAAR,QAAkC,kBAAlC;AAEA,OAAO,SAASC,kBAAT,CAA4BC,MAA5B,EAAoCC,gBAApC,EAAsD;AAC3D,QAAMC,aAAa,GAAG,CACpBF,MAAM,CAACG,MAAP,CAAc,CAAd,CADoB,EAEpBH,MAAM,CAACG,MAAP,CAAc,CAAd,CAFoB,EAGpBH,MAAM,CAACG,MAAP,CAAc,CAAd,IAAmBF,gBAAgB,CAACG,SAAjB,CAA2BJ,MAAM,CAACG,MAAP,CAAc,CAAd,CAA3B,EAA6CH,MAAM,CAACG,MAAP,CAAc,CAAd,CAA7C,CAHC,CAAtB;AAKA,QAAME,eAAe,GAAGR,SAAS,CAACS,KAAV,CAAgBC,uBAAhB,CAAwCL,aAAxC,EAAuD,IAAIN,OAAJ,EAAvD,CAAxB;AACA,QAAMY,UAAU,GAAG,IAAIV,mBAAJ,GAA0BW,4BAA1B,CACjBJ,eADiB,EAEjBL,MAAM,CAACU,QAFU,EAGjBV,MAAM,CAACW,UAHU,CAAnB;AAKA,SAAO,CAAC,GAAGH,UAAU,CAACL,MAAf,EAAuB,GAAGK,UAAU,CAACI,QAAX,CAAoBC,OAApB,EAA1B,CAAP;AACD","sourcesContent":["import {Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {OrientedBoundingBox} from '@math.gl/culling';\n\nexport function i3sObbTo3dTilesObb(i3SObb, geoidHeightModel) {\n const tiles3DCenter = [\n i3SObb.center[0],\n i3SObb.center[1],\n i3SObb.center[2] + geoidHeightModel.getHeight(i3SObb.center[1], i3SObb.center[0])\n ];\n const cartesianCenter = Ellipsoid.WGS84.cartographicToCartesian(tiles3DCenter, new Vector3());\n const tiles3DObb = new OrientedBoundingBox().fromCenterHalfSizeQuaternion(\n cartesianCenter,\n i3SObb.halfSize,\n i3SObb.quaternion\n );\n return [...tiles3DObb.center, ...tiles3DObb.halfAxes.toArray()];\n}\n"],"file":"i3s-obb-to-3d-tiles-obb.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function convertTextureAtlas(texCoords, uvRegions) {
|
|
2
|
+
const convertedTexCoords = new Float32Array(texCoords.length);
|
|
3
|
+
const normalisedRegions = normalizeRegions(uvRegions);
|
|
4
|
+
|
|
5
|
+
for (let index = 0; index < texCoords.length; index += 2) {
|
|
6
|
+
const uv = texCoords.subarray(index, index + 2);
|
|
7
|
+
const regions = normalisedRegions.slice(index * 2, index * 2 + 4);
|
|
8
|
+
const fractatedUV = fract(uv);
|
|
9
|
+
const subtracted = [regions[2] - regions[0], regions[3] - regions[1]];
|
|
10
|
+
const multiplicationResult = [fractatedUV[0] * subtracted[0], fractatedUV[1] * subtracted[1]];
|
|
11
|
+
const convertedUV = [multiplicationResult[0] + regions[0], multiplicationResult[1] + regions[1]];
|
|
12
|
+
convertedTexCoords[index] = convertedUV[0];
|
|
13
|
+
convertedTexCoords[index + 1] = convertedUV[1];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return convertedTexCoords;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function fract(uv) {
|
|
20
|
+
return [uv[0] - Math.floor(uv[0]), uv[1] - Math.floor(uv[1])];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function normalizeRegions(regions) {
|
|
24
|
+
const MAX_UINT_16_VALUE = 65535;
|
|
25
|
+
const normalizedRegions = [];
|
|
26
|
+
|
|
27
|
+
for (let index = 0; index < regions.length; index++) {
|
|
28
|
+
normalizedRegions[index] = regions[index] / MAX_UINT_16_VALUE;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return normalizedRegions;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=texture-atlas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/3d-tiles-converter/helpers/texture-atlas.ts"],"names":["convertTextureAtlas","texCoords","uvRegions","convertedTexCoords","Float32Array","length","normalisedRegions","normalizeRegions","index","uv","subarray","regions","slice","fractatedUV","fract","subtracted","multiplicationResult","convertedUV","Math","floor","MAX_UINT_16_VALUE","normalizedRegions"],"mappings":"AAOA,OAAO,SAASA,mBAAT,CAA6BC,SAA7B,EAAsDC,SAAtD,EAA4F;AACjG,QAAMC,kBAAkB,GAAG,IAAIC,YAAJ,CAAiBH,SAAS,CAACI,MAA3B,CAA3B;AACA,QAAMC,iBAAiB,GAAGC,gBAAgB,CAACL,SAAD,CAA1C;;AAEA,OAAK,IAAIM,KAAK,GAAG,CAAjB,EAAoBA,KAAK,G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D,CAAb,CAApC,CAAP;AACD;;AAMD,SAASF,gBAAT,CAA0BI,OAA1B,EAA2D;AACzD,QAAMS,iBAAiB,GAAG,KAA1B;AACA,QAAMC,iBAAiB,GAAG,EAA1B;;AAEA,OAAK,IAAIb,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGG,OAAO,CAACN,MAApC,EAA4CG,KAAK,EAAjD,EAAqD;AACnDa,IAAAA,iBAAiB,CAACb,KAAD,CAAjB,GAA2BG,OAAO,CAACH,KAAD,CAAP,GAAiBY,iBAA5C;AACD;;AAED,SAAOC,iBAAP;AACD","sourcesContent":["/**\n * Apply uvRegions to texture coordinates.\n * Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md\n * Shader formula vec2 uv = fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;\n * @param texCoords\n * @param uvRegions\n */\nexport function convertTextureAtlas(texCoords: Float32Array, uvRegions: Uint16Array): Float32Array {\n const convertedTexCoords = new Float32Array(texCoords.length);\n const normalisedRegions = normalizeRegions(uvRegions);\n\n for (let index = 0; index < texCoords.length; index += 2) {\n const uv = texCoords.subarray(index, index + 2);\n const regions = normalisedRegions.slice(index * 2, index * 2 + 4);\n // fract(texCoords)\n const fractatedUV = fract(uv);\n // (uvRegions.zw - uvRegions.xy)\n const subtracted = [regions[2] - regions[0], regions[3] - regions[1]];\n // fract(texCoords) * (uvRegions.zw - uvRegions.xy)\n const multiplicationResult = [fractatedUV[0] * subtracted[0], fractatedUV[1] * subtracted[1]];\n // fract(texCoords) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;\n const convertedUV = [\n multiplicationResult[0] + regions[0],\n multiplicationResult[1] + regions[1]\n ];\n\n convertedTexCoords[index] = convertedUV[0];\n convertedTexCoords[index + 1] = convertedUV[1];\n }\n\n return convertedTexCoords;\n}\n\n/**\n * Do fractation of UV array.\n * @param uv\n */\nfunction fract(uv: number[2]): number[2] {\n return [uv[0] - Math.floor(uv[0]), uv[1] - Math.floor(uv[1])];\n}\n\n/**\n * Normalize uvRegions by dividing by the maximum Uint16 value\n * @param regions\n */\nfunction normalizeRegions(regions: Uint16Array): number[4] {\n const MAX_UINT_16_VALUE = 65535;\n const normalizedRegions = [];\n\n for (let index = 0; index < regions.length; index++) {\n normalizedRegions[index] = regions[index] / MAX_UINT_16_VALUE;\n }\n\n return normalizedRegions;\n}\n"],"file":"texture-atlas.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/3d-tiles-converter/json-templates/tileset.js"],"names":["transform","ASSET","version","path","default","TILE","boundingVolume","geometricError","content","children","val","map","tile","TILESET","asset","root"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,oBAAtB;AAEA,MAAMC,KAAK,GAAG;AACZC,EAAAA,OAAO,EAAE;AACPC,IAAAA,IAAI,EAAE,SADC;AAEPC,IAAAA,OAAO,EAAE;AAFF;AADG,CAAd;AAOA,MAAMC,IAAI,GAAG;AACXC,EAAAA,cAAc,EAAE;AACdH,IAAAA,IAAI,EAAE;AADQ,GADL;AAIXI,EAAAA,cAAc,EAAE;AACdJ,IAAAA,IAAI,EAAE;AADQ,GAJL;AAOXK,EAAAA,OAAO,EAAE;AACPL,IAAAA,IAAI,EAAE;AADC,GAPE;AAUXM,EAAAA,QAAQ,EAAE;AACRN,IAAAA,IAAI,EAAE,UADE;AAERH,IAAAA,SAAS,EAAGU,GAAD,IAASA,GAAG,CAACC,GAAJ,CAASC,IAAD,IAAUZ,SAAS,CAACY,IAAD,EAAOP,IAAP,CAA3B;AAFZ;AAVC,CAAb;AAgBA,OAAO,MAAMQ,OAAO,GAAG;AACrBC,EAAAA,KAAK,EAAE;AACLX,IAAAA,IAAI,EAAE,OADD;AAELH,IAAAA,SAAS,EAAGU,GAAD,IAASV,SAAS,CAACU,GAAD,EAAMT,KAAN;AAFxB,GADc;AAKrBM,EAAAA,cAAc,EAAE;AACdJ,IAAAA,IAAI,EAAE,MADQ;AAEdH,IAAAA,SAAS,EAAGU,GAAD,IAASA,GAAG,CAACH;AAFV,GALK;AASrBQ,EAAAA,IAAI,EAAE;AACJZ,IAAAA,IAAI,EAAE,MADF;AAEJH,IAAAA,SAAS,EAAGU,GAAD,IAASV,SAAS,CAACU,GAAD,EAAML,IAAN;AAFzB;AATe,CAAhB","sourcesContent":["import transform from 'json-map-transform';\n\nconst ASSET = {\n version: {\n path: 'version',\n default: '1.0'\n }\n};\n\nconst TILE = {\n boundingVolume: {\n path: 'boundingVolume'\n },\n geometricError: {\n path: 'geometricError'\n },\n content: {\n path: 'content'\n },\n children: {\n path: 'children',\n transform: (val) => val.map((tile) => transform(tile, TILE))\n }\n};\n\nexport const TILESET = {\n asset: {\n path: 'asset',\n transform: (val) => transform(val, ASSET)\n },\n geometricError: {\n path: 'root',\n transform: (val) => val.geometricError\n },\n root: {\n path: 'root',\n transform: (val) => transform(val, TILE)\n }\n};\n"],"file":"tileset.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install external dependencies for converter:
|
|
3
|
+
* * PGM file (implemented);
|
|
4
|
+
* * Draco library (not implemented);
|
|
5
|
+
* * 7z archiver (not implemented);
|
|
6
|
+
*/
|
|
7
|
+
export class DepsInstaller {
|
|
8
|
+
// Run installation
|
|
9
|
+
install(path?: string): Promise<void>;
|
|
10
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/deps-installer/deps-installer.js"],"names":["load","ZipLoader","writeFile","join","PGM_LINK","DepsInstaller","install","path","console","log","fileMap","fetch","followRedirect","depsPath","process","cwd","Uint8Array"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,kBAAnB;AACA,SAAQC,SAAR,QAAwB,iBAAxB;AACA,SAAQC,SAAR,QAAwB,yBAAxB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAEA,MAAMC,QAAQ,GAAG,oEAAjB;AAEA,OAAO,MAAMC,aAAN,CAAoB;AACZ,QAAPC,OAAO,CAACC,IAAI,GAAG,EAAR,EAAY;AACvBC,IAAAA,OAAO,CAACC,GAAR,CAAY,iCAAZ;AACA,UAAMC,OAAO,GAAG,MAAMV,IAAI,CAACI,QAAD,EAAWH,SAAX,EAAsB;AAACU,MAAAA,KAAK,EAAE;AAACC,QAAAA,cAAc,EAAE;AAAjB;AAAR,KAAtB,CAA1B;AAEA,QAAIC,QAAQ,GAAGC,OAAO,CAACC,GAAR,EAAf;;AACA,QAAIR,IAAJ,EAAU;AACRM,MAAAA,QAAQ,GAAGV,IAAI,CAACU,QAAD,EAAWN,IAAX,CAAf;AACD;;AAED,UAAML,SAAS,CAACW,QAAD,EAAW,IAAIG,UAAJ,CAAeN,OAAO,CAAC,sBAAD,CAAtB,CAAX,EAA4D,eAA5D,CAAf;AAEAF,IAAAA,OAAO,CAACC,GAAR,CAAY,8CAAZ;AACD;;AAbwB","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {ZipLoader} from '@loaders.gl/zip';\nimport {writeFile} from '../lib/utils/file-utils';\nimport {join} from 'path';\n\nconst PGM_LINK = 'https://github.com/visgl/deck.gl-data/raw/master/egm/egm2008-5.zip';\n\nexport class DepsInstaller {\n async install(path = '') {\n console.log('Installing \"EGM2008-5\" model...'); // eslint-disable-line no-console\n const fileMap = await load(PGM_LINK, ZipLoader, {fetch: {followRedirect: true}});\n\n let depsPath = process.cwd();\n if (path) {\n depsPath = join(depsPath, path);\n }\n\n await writeFile(depsPath, new Uint8Array(fileMap['geoids/egm2008-5.pgm']), 'egm2008-5.pgm');\n\n console.log('All dependencies were installed succesfully.'); // eslint-disable-line no-console\n }\n}\n"],"file":"deps-installer.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["Matrix3","Quaternion","Vector3","Ellipsoid","OrientedBoundingBox","createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","WGS84","cartesianToCartographic","center","getHeight","len","fromMatrix3","normalize","mbs","obb","convertCommonToI3SExtentCoordinate","tileset","cartesianCenter","lodMetricValue","rightTop","leftBottom","isFirstRight","isFirstTop","createObbFromMbs","halfAxex"],"mappings":"AAEA,SAAQA,OAAR,EAAiBC,UAAjB,EAA6BC,OAA7B,QAA2C,eAA3C;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,mBAAR,QAAkC,kBAAlC;AAWA,OAAO,SAASC,qBAAT,CACLC,IADK,EAELC,gBAFK,EAGY;AACjB,MAAIC,MAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,UAAJ;AAEA,QAAMC,cAAc,GAAGL,IAAI,CAACK,cAA5B;AACA,QAAMC,kBAAkB,GAAGT,SAAS,CAACU,KAAV,CAAgBC,uBAAhB,CACzBH,cAAc,CAACI,MADU,EAEzB,IAAIb,OAAJ,EAFyB,CAA3B;AAIAU,EAAAA,kBAAkB,CAAC,CAAD,CAAlB,GACEA,kBAAkB,CAAC,CAAD,CAAlB,GACAL,gBAAgB,CAACS,SAAjB,CAA2BJ,kBAAkB,CAAC,CAAD,CAA7C,EAAkDA,kBAAkB,CAAC,CAAD,CAApE,CAFF;;AAGA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A,GAAG,CAAC,CAAD,CAAvB,EAA4BA,GAAG,CAAC,CAAD,CAA/B,CAAf;AACA,QAAMW,QAAQ,GAAG,IAAI/B,OAAJ,CAAY,CAACQ,MAAD,EAAS,CAAT,EAAY,CAAZ,EAAe,CAAf,EAAkBA,MAAlB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmCA,MAAnC,CAAZ,CAAjB;AACA,SAAO,IAAIJ,mBAAJ,CAAwBW,MAAxB,EAAgCgB,QAAhC,CAAP;AACD","sourcesContent":["import type {BoundingVolumes, Extent, Mbs, Obb} from '@loaders.gl/i3s';\n\nimport {Matrix3, Quaternion, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {OrientedBoundingBox} from '@math.gl/culling';\nimport TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';\nimport {GeoidHeightModel} from '../../lib/geoid-height-model';\nimport {Tileset3D} from '@loaders.gl/tiles';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(\n tile: TileHeader,\n geoidHeightModel: GeoidHeightModel\n): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Convert common coordinate to extent coordinate\n * @param tileset\n * @returns - Extent\n */\nexport function convertCommonToI3SExtentCoordinate(tileset: Tileset3D): Extent {\n const cartesianCenter = tileset.cartesianCenter;\n const radius = tileset.lodMetricValue;\n const rightTop = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]),\n new Vector3()\n );\n const leftBottom = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] - radius, cartesianCenter[1] - radius, cartesianCenter[2]),\n new Vector3()\n );\n const isFirstRight = rightTop[0] < leftBottom[0];\n const isFirstTop = rightTop[1] < leftBottom[1];\n\n return [\n isFirstRight ? rightTop[0] : leftBottom[0],\n isFirstTop ? rightTop[1] : leftBottom[1],\n isFirstRight ? leftBottom[0] : rightTop[0],\n isFirstTop ? leftBottom[1] : rightTop[1]\n ];\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/create-scene-server-path.js"],"names":["v4","uuidv4","transform","join","SCENE_SERVER_TEMPLATE","writeFile","createSceneServerPath","layerName","layers0","rootPath","sceneServerData","serviceItemId","replace","sceneServer","nodePagePath","JSON","stringify"],"mappings":"AAAA,SAAQA,EAAE,IAAIC,MAAd,QAA2B,MAA3B;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAEA,SAAQC,qBAAR,QAAoC,gCAApC;AACA,SAAQC,SAAR,QAAwB,4BAAxB;AASA,OAAO,eAAeC,qBAAf,CAAqCC,SAArC,EAAgDC,OAAhD,EAAyDC,QAAzD,EAAmE;AACxE,QAAMC,eAAe,GAAG;AACtBC,IAAAA,aAAa,EAAEV,MAAM,GAAGW,OAAT,CAAiB,KAAjB,EAAwB,EAAxB,CADO;AAEtBL,IAAAA,SAFsB;AAGtBC,IAAAA;AAHsB,GAAxB;AAMA,QAAMK,WAAW,GAAGX,SAAS,CAACQ,eAAD,EAAkBN,qBAAlB,CAA7B;AACA,QAAMU,YAAY,GAAGX,IAAI,CAACM,QAAD,EAAW,aAAX,CAAzB;AACA,QAAMJ,SAAS,CAACS,YAAD,EAAeC,IAAI,CAACC,SAAL,CAAeH,WAAf,CAAf,CAAf;AACD","sourcesContent":["import {v4 as uuidv4} from 'uuid';\nimport transform from 'json-map-transform';\nimport {join} from 'path';\n\nimport {SCENE_SERVER_TEMPLATE} from '../json-templates/scene-server';\nimport {writeFile} from '../../lib/utils/file-utils';\n\n/**\n * Form and save sceneServer meta data into a file\n * @param {string} layerName - layer name to display\n * @param {object} layers0 - layer object embedded into sceneServer meta data\n * @param {string} rootPath - root path of new converted tileset\n * @return {promise}\n */\nexport async function createSceneServerPath(layerName, layers0, rootPath) {\n const sceneServerData = {\n serviceItemId: uuidv4().replace(/-/gi, ''),\n layerName,\n layers0\n };\n\n const sceneServer = transform(sceneServerData, SCENE_SERVER_TEMPLATE);\n const nodePagePath = join(rootPath, 'SceneServer');\n await writeFile(nodePagePath, JSON.stringify(sceneServer));\n}\n"],"file":"create-scene-server-path.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/geometry-attributes.js"],"names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":"AAAA,SAAQA,sBAAR,QAAqC,0BAArC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAOA,OAAO,SAASC,kBAAT,CAA4BC,UAA5B,EAAwC;AAC7C,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,OAAZ;AAAqBC,IAAAA,SAArB;AAAgCC,IAAAA,MAAhC;AAAwCC,IAAAA,cAAxC;AAAwDC,IAAAA;AAAxD,MAAyEN,UAA/E;;AAEA,MAAI,CAACK,cAAc,CAACE,MAApB,EAA4B;AAC1B,WAAO;AACLC,MAAAA,SAAS,EAAE,IAAIC,WAAJ,CAAgB,CAAC,CAAD,EAAIH,aAAa,GAAG,CAApB,CAAhB,CADN;AAELI,MAAAA,UAAU,EAAE,CAAC,CAAD,CAFP;AAGLC,MAAAA,YAAY,EAAE,CAHT;AAILV,MAAAA,SAJK;AAKLC,MAAAA,OALK;AAMLC,MAAAA,SANK;AAOLC,MAAAA;AAPK,KAAP;AASD;;AAED,QAAM;AAACI,IAAAA,SAAD;AAAYG,IAAAA,YAAZ;AAA0BD,IAAAA;AAA1B,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R,sBAAsB,CAACQ,MAAD,EAAS2D,uBAAuB,CAAC3D,MAAjC,CAA/B;AACAD,IAAAA,SAAS,GAAGP,sBAAsB,CAACO,SAAD,EAAY4D,uBAAuB,CAAC5D,SAApC,CAAlC;AAEA,UAAM6D,aAAa,GAAGN,cAAc,CAACG,QAAD,CAApC;AACAD,IAAAA,KAAK,CAAClC,IAAN,CAAWsC,aAAa,CAAC/D,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAjC,GAAsE,CAAtE,GAA0EgE,GAArF;AACAF,IAAAA,KAAK,CAAClC,IAAN,CAAWsC,aAAa,CAAC/D,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAjC,GAAsEgE,GAAjF;AAEAA,IAAAA,GAAG,IAAIE,aAAa,CAAC/D,SAAd,CAAwBM,MAAxB,GAAiCT,kCAAxC;AACA+D,IAAAA,QAAQ,IAAI,CAAZ;AACD;;AAEDD,EAAAA,KAAK,CAAClC,IAAN,CAAWzB,SAAS,CAACM,MAAV,GAAmBT,kCAAnB,GAAwD,CAAnE;AAEA,QAAMU,SAAS,GAAG,IAAIC,WAAJ,CAAgBmD,KAAhB,CAAlB;AACA,SAAO;AAACpD,IAAAA,SAAD;AAAYE,IAAAA,UAAZ;AAAwBT,IAAAA,SAAxB;AAAmCC,IAAAA,OAAnC;AAA4CE,IAAAA,MAA5C;AAAoDD,IAAAA;AAApD,GAAP;AACD","sourcesContent":["import {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param {Object} attributes\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nexport function generateAttributes(attributes) {\n const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const {faceRange, featureCount, featureIds} = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({faceRange, featureIds, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds\n );\n return {featureCount, ...groupedAttributes};\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param {Object} featureIndices\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices) {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList = [];\n const featureIds = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param {Object} attributes\n * @returns {Array} sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes) {\n const {featureIds, positions, normals, colors, texCoords, faceRange} = attributes;\n const groupedData = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param {String} attributeName\n * @param {Number} startIndex\n * @param {Number} endIndex\n * @returns {Number} - sliced count\n */\nfunction getSliceAttributeCount(attributeName, startIndex, endIndex) {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param {Array} sortedData\n * @returns {Array} - unique list of objects\n */\nfunction unifyObjectsByFeatureId(sortedData) {\n const uniqueObjects = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param {Array} unifiedObjects\n * @returns {Object} - ugenerated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(unifiedObjects) {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords};\n}\n"],"file":"geometry-attributes.js"}
|