@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,915 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _core = require("@loaders.gl/core");
|
|
13
|
+
|
|
14
|
+
var _tiles = require("@loaders.gl/tiles");
|
|
15
|
+
|
|
16
|
+
var _dTiles = require("@loaders.gl/3d-tiles");
|
|
17
|
+
|
|
18
|
+
var _path = require("path");
|
|
19
|
+
|
|
20
|
+
var _uuid = require("uuid");
|
|
21
|
+
|
|
22
|
+
var _process = _interopRequireDefault(require("process"));
|
|
23
|
+
|
|
24
|
+
var _jsonMapTransform = _interopRequireDefault(require("json-map-transform"));
|
|
25
|
+
|
|
26
|
+
var _md = _interopRequireDefault(require("md5"));
|
|
27
|
+
|
|
28
|
+
var _nodePages = _interopRequireDefault(require("./helpers/node-pages"));
|
|
29
|
+
|
|
30
|
+
var _fileUtils = require("../lib/utils/file-utils");
|
|
31
|
+
|
|
32
|
+
var _compressUtil = require("../lib/utils/compress-util");
|
|
33
|
+
|
|
34
|
+
var _statisticUtills = require("../lib/utils/statistic-utills");
|
|
35
|
+
|
|
36
|
+
var _geometryConverter = _interopRequireDefault(require("./helpers/geometry-converter"));
|
|
37
|
+
|
|
38
|
+
var _coordinateConverter = require("./helpers/coordinate-converter");
|
|
39
|
+
|
|
40
|
+
var _createSceneServerPath = require("./helpers/create-scene-server-path");
|
|
41
|
+
|
|
42
|
+
var _lodConversionUtils = require("../lib/utils/lod-conversion-utils");
|
|
43
|
+
|
|
44
|
+
var _pgmLoader = require("../pgm-loader");
|
|
45
|
+
|
|
46
|
+
var _layers = require("./json-templates/layers");
|
|
47
|
+
|
|
48
|
+
var _node = require("./json-templates/node");
|
|
49
|
+
|
|
50
|
+
var _sharedResources = require("./json-templates/shared-resources");
|
|
51
|
+
|
|
52
|
+
var _nodeDebug = require("./helpers/node-debug");
|
|
53
|
+
|
|
54
|
+
var _textures = require("@loaders.gl/textures");
|
|
55
|
+
|
|
56
|
+
const ION_DEFAULT_TOKEN = _process.default.env.IonToken || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYWMxMzcyYy0zZjJkLTQwODctODNlNi01MDRkZmMzMjIxOWIiLCJpZCI6OTYyMCwic2NvcGVzIjpbImFzbCIsImFzciIsImdjIl0sImlhdCI6MTU2Mjg2NjI3M30.1FNiClUyk00YH_nWfSGpiQAjR5V2OvREDq1PJ5QMjWQ';
|
|
57
|
+
const HARDCODED_NODES_PER_PAGE = 64;
|
|
58
|
+
const _3D_TILES = '3DTILES';
|
|
59
|
+
const _3D_OBJECT_LAYER_TYPE = '3DObject';
|
|
60
|
+
const STRING_TYPE = 'string';
|
|
61
|
+
const SHORT_INT_TYPE = 'Int32';
|
|
62
|
+
const DOUBLE_TYPE = 'double';
|
|
63
|
+
const OBJECT_ID_TYPE = 'OBJECTID';
|
|
64
|
+
const REFRESH_TOKEN_TIMEOUT = 1800;
|
|
65
|
+
const CESIUM_DATASET_PREFIX = 'https://';
|
|
66
|
+
|
|
67
|
+
class I3SConverter {
|
|
68
|
+
constructor() {
|
|
69
|
+
(0, _defineProperty2.default)(this, "nodePages", void 0);
|
|
70
|
+
(0, _defineProperty2.default)(this, "fileMap", void 0);
|
|
71
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
72
|
+
(0, _defineProperty2.default)(this, "layers0Path", void 0);
|
|
73
|
+
(0, _defineProperty2.default)(this, "materialMap", void 0);
|
|
74
|
+
(0, _defineProperty2.default)(this, "materialDefinitions", void 0);
|
|
75
|
+
(0, _defineProperty2.default)(this, "vertexCounter", void 0);
|
|
76
|
+
(0, _defineProperty2.default)(this, "layers0", void 0);
|
|
77
|
+
(0, _defineProperty2.default)(this, "featuresHashArray", void 0);
|
|
78
|
+
(0, _defineProperty2.default)(this, "refinementCounter", void 0);
|
|
79
|
+
(0, _defineProperty2.default)(this, "validate", void 0);
|
|
80
|
+
(0, _defineProperty2.default)(this, "boundingVolumeWarnings", void 0);
|
|
81
|
+
(0, _defineProperty2.default)(this, "conversionStartTime", void 0);
|
|
82
|
+
(0, _defineProperty2.default)(this, "refreshTokenTime", void 0);
|
|
83
|
+
(0, _defineProperty2.default)(this, "sourceTileset", void 0);
|
|
84
|
+
(0, _defineProperty2.default)(this, "geoidHeightModel", void 0);
|
|
85
|
+
(0, _defineProperty2.default)(this, "Loader", _dTiles.Tiles3DLoader);
|
|
86
|
+
this.nodePages = new _nodePages.default(_fileUtils.writeFile, HARDCODED_NODES_PER_PAGE);
|
|
87
|
+
this.fileMap = {};
|
|
88
|
+
this.options = {};
|
|
89
|
+
this.layers0Path = '';
|
|
90
|
+
this.materialMap = new Map();
|
|
91
|
+
this.materialDefinitions = [];
|
|
92
|
+
this.vertexCounter = 0;
|
|
93
|
+
this.layers0 = null;
|
|
94
|
+
this.featuresHashArray = [];
|
|
95
|
+
this.refinementCounter = {
|
|
96
|
+
tilesCount: 0,
|
|
97
|
+
tilesWithAddRefineCount: 0
|
|
98
|
+
};
|
|
99
|
+
this.validate = false;
|
|
100
|
+
this.boundingVolumeWarnings = null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async convert(options) {
|
|
104
|
+
this.conversionStartTime = _process.default.hrtime();
|
|
105
|
+
const {
|
|
106
|
+
tilesetName,
|
|
107
|
+
slpk,
|
|
108
|
+
egmFilePath,
|
|
109
|
+
inputUrl,
|
|
110
|
+
validate,
|
|
111
|
+
outputPath,
|
|
112
|
+
draco,
|
|
113
|
+
sevenZipExe,
|
|
114
|
+
maxDepth,
|
|
115
|
+
token
|
|
116
|
+
} = options;
|
|
117
|
+
this.options = {
|
|
118
|
+
maxDepth,
|
|
119
|
+
slpk,
|
|
120
|
+
sevenZipExe,
|
|
121
|
+
egmFilePath,
|
|
122
|
+
draco,
|
|
123
|
+
token,
|
|
124
|
+
inputUrl
|
|
125
|
+
};
|
|
126
|
+
this.validate = validate;
|
|
127
|
+
this.Loader = inputUrl.indexOf(CESIUM_DATASET_PREFIX) !== -1 ? _dTiles.CesiumIonLoader : _dTiles.Tiles3DLoader;
|
|
128
|
+
console.log('Loading egm file...');
|
|
129
|
+
this.geoidHeightModel = await (0, _core.load)(egmFilePath, _pgmLoader.PGMLoader);
|
|
130
|
+
console.log('Loading egm file completed!');
|
|
131
|
+
|
|
132
|
+
if (slpk) {
|
|
133
|
+
this.nodePages.useWriteFunction(_fileUtils.writeFileForSlpk);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const preloadOptions = await this._fetchPreloadOptions();
|
|
137
|
+
const tilesetOptions = {
|
|
138
|
+
loadOptions: {}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
if (preloadOptions.headers) {
|
|
142
|
+
tilesetOptions.loadOptions.fetch = {
|
|
143
|
+
headers: preloadOptions.headers
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
Object.assign(tilesetOptions, preloadOptions);
|
|
148
|
+
const sourceTilesetJson = await (0, _core.load)(inputUrl, this.Loader, tilesetOptions.loadOptions);
|
|
149
|
+
this.sourceTileset = new _tiles.Tileset3D(sourceTilesetJson, tilesetOptions);
|
|
150
|
+
await this._createAndSaveTileset(outputPath, tilesetName);
|
|
151
|
+
await this._finishConversion({
|
|
152
|
+
slpk,
|
|
153
|
+
outputPath,
|
|
154
|
+
tilesetName
|
|
155
|
+
});
|
|
156
|
+
return sourceTilesetJson;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async _createAndSaveTileset(outputPath, tilesetName) {
|
|
160
|
+
const tilesetPath = (0, _path.join)("".concat(outputPath), "".concat(tilesetName));
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
await (0, _fileUtils.removeDir)(tilesetPath);
|
|
164
|
+
} catch (e) {}
|
|
165
|
+
|
|
166
|
+
this.layers0Path = (0, _path.join)(tilesetPath, 'SceneServer', 'layers', '0');
|
|
167
|
+
|
|
168
|
+
this._formLayers0(tilesetName);
|
|
169
|
+
|
|
170
|
+
this.materialDefinitions = [];
|
|
171
|
+
this.materialMap = new Map();
|
|
172
|
+
const sourceRootTile = this.sourceTileset.root;
|
|
173
|
+
const boundingVolumes = (0, _coordinateConverter.createBoundingVolumes)(sourceRootTile, this.geoidHeightModel);
|
|
174
|
+
const parentId = this.nodePages.push({
|
|
175
|
+
lodThreshold: 0,
|
|
176
|
+
obb: boundingVolumes.obb,
|
|
177
|
+
children: []
|
|
178
|
+
});
|
|
179
|
+
const isCreateSlpk = this.options.slpk;
|
|
180
|
+
|
|
181
|
+
const root0 = this._formRootNodeIndexDocument(boundingVolumes);
|
|
182
|
+
|
|
183
|
+
await this._convertNodesTree(root0, sourceRootTile, parentId, boundingVolumes);
|
|
184
|
+
this.layers0.materialDefinitions = this.materialDefinitions;
|
|
185
|
+
await this._writeLayers0();
|
|
186
|
+
(0, _createSceneServerPath.createSceneServerPath)(tilesetName, this.layers0, tilesetPath);
|
|
187
|
+
await this._writeNodeIndexDocument(root0, 'root', (0, _path.join)(this.layers0Path, 'nodes', 'root'));
|
|
188
|
+
await this.nodePages.save(this.layers0Path, this.fileMap, isCreateSlpk);
|
|
189
|
+
await this._createSlpk(tilesetPath);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
_formLayers0(tilesetName) {
|
|
193
|
+
const extent = (0, _coordinateConverter.convertCommonToI3SExtentCoordinate)(this.sourceTileset);
|
|
194
|
+
const layers0data = {
|
|
195
|
+
version: "{".concat((0, _uuid.v4)().toUpperCase(), "}"),
|
|
196
|
+
id: 0,
|
|
197
|
+
name: tilesetName,
|
|
198
|
+
href: './layers/0',
|
|
199
|
+
store: {
|
|
200
|
+
id: "{".concat((0, _uuid.v4)().toUpperCase(), "}"),
|
|
201
|
+
extent
|
|
202
|
+
},
|
|
203
|
+
nodePages: {
|
|
204
|
+
nodesPerPage: HARDCODED_NODES_PER_PAGE
|
|
205
|
+
},
|
|
206
|
+
compressGeometry: this.options.draco
|
|
207
|
+
};
|
|
208
|
+
this.layers0 = (0, _jsonMapTransform.default)(layers0data, _layers.LAYERS);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
_formRootNodeIndexDocument(boundingVolumes) {
|
|
212
|
+
const root0data = {
|
|
213
|
+
version: "{".concat((0, _uuid.v4)().toUpperCase(), "}"),
|
|
214
|
+
id: 'root',
|
|
215
|
+
level: 0,
|
|
216
|
+
lodSelection: [{
|
|
217
|
+
metricType: 'maxScreenThresholdSQ',
|
|
218
|
+
maxError: 0
|
|
219
|
+
}, {
|
|
220
|
+
metricType: 'maxScreenThreshold',
|
|
221
|
+
maxError: 0
|
|
222
|
+
}],
|
|
223
|
+
...boundingVolumes,
|
|
224
|
+
children: []
|
|
225
|
+
};
|
|
226
|
+
return (0, _jsonMapTransform.default)(root0data, _node.NODE);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async _convertNodesTree(root0, sourceRootTile, parentId, boundingVolumes) {
|
|
230
|
+
await this.sourceTileset._loadTile(sourceRootTile);
|
|
231
|
+
|
|
232
|
+
if (sourceRootTile.content && sourceRootTile.content.type === 'b3dm') {
|
|
233
|
+
root0.children.push({
|
|
234
|
+
id: '1',
|
|
235
|
+
href: './1',
|
|
236
|
+
...boundingVolumes
|
|
237
|
+
});
|
|
238
|
+
const [child] = await this._createNode(root0, sourceRootTile, parentId, 0);
|
|
239
|
+
const childPath = (0, _path.join)(this.layers0Path, 'nodes', child.path);
|
|
240
|
+
|
|
241
|
+
if (this.options.slpk) {
|
|
242
|
+
this.fileMap['nodes/1/3dNodeIndexDocument.json.gz'] = await (0, _fileUtils.writeFileForSlpk)(childPath, JSON.stringify(child), '3dNodeIndexDocument.json');
|
|
243
|
+
} else {
|
|
244
|
+
await (0, _fileUtils.writeFile)(childPath, JSON.stringify(child));
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
await this._addChildrenWithNeighborsAndWriteFile({
|
|
248
|
+
parentNode: root0,
|
|
249
|
+
sourceTiles: sourceRootTile.children,
|
|
250
|
+
parentId,
|
|
251
|
+
level: 1
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
await sourceRootTile.unloadContent();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async _writeLayers0() {
|
|
259
|
+
if (this.options.slpk) {
|
|
260
|
+
this.fileMap['3dSceneLayer.json.gz'] = await (0, _fileUtils.writeFileForSlpk)(this.layers0Path, JSON.stringify(this.layers0), '3dSceneLayer.json');
|
|
261
|
+
} else {
|
|
262
|
+
await (0, _fileUtils.writeFile)(this.layers0Path, JSON.stringify(this.layers0));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async _writeNodeIndexDocument(root0, nodePath, rootPath) {
|
|
267
|
+
if (this.options.slpk) {
|
|
268
|
+
this.fileMap["nodes/".concat(nodePath, "/3dNodeIndexDocument.json.gz")] = await (0, _fileUtils.writeFileForSlpk)(rootPath, JSON.stringify(root0), '3dNodeIndexDocument.json');
|
|
269
|
+
} else {
|
|
270
|
+
await (0, _fileUtils.writeFile)(rootPath, JSON.stringify(root0));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async _createSlpk(tilesetPath) {
|
|
275
|
+
if (this.options.slpk) {
|
|
276
|
+
const slpkTilesetPath = (0, _path.join)(tilesetPath, 'SceneServer', 'layers', '0');
|
|
277
|
+
const slpkFileName = "".concat(tilesetPath, ".slpk");
|
|
278
|
+
await (0, _compressUtil.compressWithChildProcess)(slpkTilesetPath, slpkFileName, 0, '.', this.options.sevenZipExe);
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
await (0, _fileUtils.removeDir)(tilesetPath);
|
|
282
|
+
} catch (e) {}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async _addChildrenWithNeighborsAndWriteFile(data) {
|
|
287
|
+
const childNodes = [];
|
|
288
|
+
await this._addChildren({ ...data,
|
|
289
|
+
childNodes
|
|
290
|
+
});
|
|
291
|
+
await this._addNeighborsAndWriteFile(data.parentNode, childNodes);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async _addChildren(data) {
|
|
295
|
+
const {
|
|
296
|
+
childNodes,
|
|
297
|
+
sourceTiles,
|
|
298
|
+
parentNode,
|
|
299
|
+
parentId,
|
|
300
|
+
level
|
|
301
|
+
} = data;
|
|
302
|
+
|
|
303
|
+
if (this.options.maxDepth && level > this.options.maxDepth) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
for (const sourceTile of sourceTiles) {
|
|
308
|
+
if (sourceTile.type === 'json') {
|
|
309
|
+
await this.sourceTileset._loadTile(sourceTile);
|
|
310
|
+
await this._addChildren({
|
|
311
|
+
parentNode,
|
|
312
|
+
sourceTiles: sourceTile.children,
|
|
313
|
+
childNodes,
|
|
314
|
+
parentId,
|
|
315
|
+
level: level + 1
|
|
316
|
+
});
|
|
317
|
+
await sourceTile.unloadContent();
|
|
318
|
+
} else {
|
|
319
|
+
const boundingVolumes = (0, _coordinateConverter.createBoundingVolumes)(sourceTile, this.geoidHeightModel);
|
|
320
|
+
const children = await this._createNode(parentNode, sourceTile, parentId, level);
|
|
321
|
+
|
|
322
|
+
for (const child of children) {
|
|
323
|
+
parentNode.children.push({
|
|
324
|
+
id: child.id,
|
|
325
|
+
href: "../".concat(child.path),
|
|
326
|
+
...boundingVolumes
|
|
327
|
+
});
|
|
328
|
+
childNodes.push(child);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (sourceTile.id) {
|
|
333
|
+
console.log(sourceTile.id);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async _addNeighborsAndWriteFile(parentNode, childNodes) {
|
|
339
|
+
for (const node of childNodes) {
|
|
340
|
+
const childPath = (0, _path.join)(this.layers0Path, 'nodes', node.path);
|
|
341
|
+
const nodePath = node.path;
|
|
342
|
+
delete node.path;
|
|
343
|
+
|
|
344
|
+
if (parentNode.children.length < 1000) {
|
|
345
|
+
for (const neighbor of parentNode.children) {
|
|
346
|
+
if (node.id === neighbor.id) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
node.neighbors.push({ ...neighbor
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
console.warn("Node ".concat(node.id, ": neighbors attribute is omited because of large number of neigbors"));
|
|
355
|
+
delete node.neighbors;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
await this._writeNodeIndexDocument(node, nodePath, childPath);
|
|
359
|
+
node.neighbors = [];
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async _createNode(parentTile, sourceTile, parentId, level) {
|
|
364
|
+
var _sourceTile$content;
|
|
365
|
+
|
|
366
|
+
if (this.validate) {
|
|
367
|
+
this._checkAddRefinementTypeForTile(sourceTile);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
await this._updateTilesetOptions();
|
|
371
|
+
await this.sourceTileset._loadTile(sourceTile);
|
|
372
|
+
const boundingVolumes = (0, _coordinateConverter.createBoundingVolumes)(sourceTile, this.geoidHeightModel);
|
|
373
|
+
const lodSelection = (0, _lodConversionUtils.convertGeometricErrorToScreenThreshold)(sourceTile, boundingVolumes);
|
|
374
|
+
const maxScreenThresholdSQ = lodSelection.find(val => val.metricType === 'maxScreenThresholdSQ') || {
|
|
375
|
+
maxError: 0
|
|
376
|
+
};
|
|
377
|
+
const batchTable = sourceTile === null || sourceTile === void 0 ? void 0 : (_sourceTile$content = sourceTile.content) === null || _sourceTile$content === void 0 ? void 0 : _sourceTile$content.batchTableJson;
|
|
378
|
+
|
|
379
|
+
if (batchTable) {
|
|
380
|
+
this._convertAttributeStorageInfo(sourceTile.content);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const resourcesData = await this._convertResources(sourceTile);
|
|
384
|
+
const nodes = [];
|
|
385
|
+
const emptyResources = {
|
|
386
|
+
geometry: null,
|
|
387
|
+
compressedGeometry: null,
|
|
388
|
+
texture: null,
|
|
389
|
+
sharedResources: null,
|
|
390
|
+
meshMaterial: null,
|
|
391
|
+
vertexCount: null,
|
|
392
|
+
attributes: null,
|
|
393
|
+
featureCount: null
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
for (const resources of resourcesData || [emptyResources]) {
|
|
397
|
+
const nodeInPage = this._createNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentId, resources);
|
|
398
|
+
|
|
399
|
+
const node = this._createNodeIndexDocument(parentTile, boundingVolumes, lodSelection, nodeInPage, resources);
|
|
400
|
+
|
|
401
|
+
if (nodeInPage.mesh) {
|
|
402
|
+
await this._writeResources(resources, node.path);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (this.validate) {
|
|
406
|
+
this.boundingVolumeWarnings = (0, _nodeDebug.validateNodeBoundingVolumes)(node);
|
|
407
|
+
|
|
408
|
+
if (this.boundingVolumeWarnings && this.boundingVolumeWarnings.length) {
|
|
409
|
+
console.warn('Bounding Volume Warnings: ', ...this.boundingVolumeWarnings);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
nodes.push(node);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
sourceTile.unloadContent();
|
|
417
|
+
const firstNode = nodes[0];
|
|
418
|
+
await this._addChildrenWithNeighborsAndWriteFile({
|
|
419
|
+
parentNode: firstNode,
|
|
420
|
+
sourceTiles: sourceTile.children,
|
|
421
|
+
parentId: firstNode.id,
|
|
422
|
+
level: level + 1
|
|
423
|
+
});
|
|
424
|
+
return nodes;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
_convertAttributeStorageInfo(sourceTileContent) {
|
|
428
|
+
const batchTable = sourceTileContent && sourceTileContent.batchTableJson;
|
|
429
|
+
|
|
430
|
+
if (batchTable && !this.layers0.attributeStorageInfo.length) {
|
|
431
|
+
this._convertBatchTableInfoToNodeAttributes(batchTable);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async _convertResources(sourceTile) {
|
|
436
|
+
if (!sourceTile.content || sourceTile.content.type !== 'b3dm') {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const resourcesData = await (0, _geometryConverter.default)(sourceTile.content, Number(this.nodePages.nodesCounter), this.featuresHashArray, this.layers0.attributeStorageInfo, this.options.draco);
|
|
441
|
+
return resourcesData;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
_createNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentId, resources) {
|
|
445
|
+
const {
|
|
446
|
+
meshMaterial,
|
|
447
|
+
texture,
|
|
448
|
+
vertexCount,
|
|
449
|
+
featureCount,
|
|
450
|
+
geometry
|
|
451
|
+
} = resources;
|
|
452
|
+
const nodeInPage = {
|
|
453
|
+
lodThreshold: maxScreenThresholdSQ.maxError,
|
|
454
|
+
obb: boundingVolumes.obb,
|
|
455
|
+
children: [],
|
|
456
|
+
mesh: null
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
if (geometry && sourceTile.content && sourceTile.content.type === 'b3dm') {
|
|
460
|
+
nodeInPage.mesh = {
|
|
461
|
+
geometry: {
|
|
462
|
+
definition: texture ? 0 : 1
|
|
463
|
+
},
|
|
464
|
+
attribute: {}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const nodeId = this.nodePages.push(nodeInPage, parentId);
|
|
469
|
+
|
|
470
|
+
if (meshMaterial) {
|
|
471
|
+
this.nodePages.updateMaterialByNodeId(nodeId, this._findOrCreateMaterial(meshMaterial));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (texture) {
|
|
475
|
+
const texelCountHint = texture.image.height * texture.image.width;
|
|
476
|
+
this.nodePages.updateTexelCountHintByNodeId(nodeId, texelCountHint);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (vertexCount) {
|
|
480
|
+
this.vertexCounter += vertexCount;
|
|
481
|
+
this.nodePages.updateVertexCountByNodeId(nodeId, vertexCount);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
this.nodePages.updateNodeAttributeByNodeId(nodeId);
|
|
485
|
+
|
|
486
|
+
if (featureCount) {
|
|
487
|
+
this.nodePages.updateFeatureCountByNodeId(nodeId, featureCount);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return nodeInPage;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
_createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources) {
|
|
494
|
+
const {
|
|
495
|
+
texture,
|
|
496
|
+
attributes
|
|
497
|
+
} = resources;
|
|
498
|
+
const nodeId = nodeInPage.index;
|
|
499
|
+
const nodeData = {
|
|
500
|
+
version: parentNode.version,
|
|
501
|
+
id: nodeId.toString(),
|
|
502
|
+
path: nodeId.toString(),
|
|
503
|
+
level: parentNode.level + 1,
|
|
504
|
+
...boundingVolumes,
|
|
505
|
+
lodSelection,
|
|
506
|
+
parentNode: {
|
|
507
|
+
id: parentNode.id,
|
|
508
|
+
href: "../".concat(parentNode.id),
|
|
509
|
+
mbs: parentNode.mbs,
|
|
510
|
+
obb: parentNode.obb
|
|
511
|
+
},
|
|
512
|
+
children: [],
|
|
513
|
+
neighbors: []
|
|
514
|
+
};
|
|
515
|
+
const node = (0, _jsonMapTransform.default)(nodeData, _node.NODE);
|
|
516
|
+
|
|
517
|
+
if (nodeInPage.mesh) {
|
|
518
|
+
node.geometryData = [{
|
|
519
|
+
href: './geometries/0'
|
|
520
|
+
}];
|
|
521
|
+
node.sharedResource = {
|
|
522
|
+
href: './shared'
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
if (texture) {
|
|
526
|
+
node.textureData = [{
|
|
527
|
+
href: './textures/0'
|
|
528
|
+
}, {
|
|
529
|
+
href: './textures/1'
|
|
530
|
+
}];
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (attributes && attributes.length && this.layers0.attributeStorageInfo && this.layers0.attributeStorageInfo.length) {
|
|
534
|
+
node.attributeData = [];
|
|
535
|
+
|
|
536
|
+
for (let index = 0; index < attributes.length; index++) {
|
|
537
|
+
const folderName = this.layers0.attributeStorageInfo[index].key;
|
|
538
|
+
node.attributeData.push({
|
|
539
|
+
href: "./attributes/".concat(folderName, "/0")
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return node;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
async _writeResources(resources, nodePath) {
|
|
549
|
+
const {
|
|
550
|
+
geometry: geometryBuffer,
|
|
551
|
+
compressedGeometry,
|
|
552
|
+
texture,
|
|
553
|
+
sharedResources,
|
|
554
|
+
attributes
|
|
555
|
+
} = resources;
|
|
556
|
+
const childPath = (0, _path.join)(this.layers0Path, 'nodes', nodePath);
|
|
557
|
+
const slpkChildPath = (0, _path.join)('nodes', nodePath);
|
|
558
|
+
await this._writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath);
|
|
559
|
+
await this._writeShared(sharedResources, childPath, slpkChildPath, nodePath);
|
|
560
|
+
await this._writeTexture(texture, childPath, slpkChildPath);
|
|
561
|
+
await this._writeAttributes(attributes, childPath, slpkChildPath);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
async _writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath) {
|
|
565
|
+
if (this.options.slpk) {
|
|
566
|
+
const slpkGeometryPath = (0, _path.join)(childPath, 'geometries');
|
|
567
|
+
this.fileMap["".concat(slpkChildPath, "/geometries/0.bin.gz")] = await (0, _fileUtils.writeFileForSlpk)(slpkGeometryPath, geometryBuffer, '0.bin');
|
|
568
|
+
} else {
|
|
569
|
+
const geometryPath = (0, _path.join)(childPath, 'geometries/0/');
|
|
570
|
+
await (0, _fileUtils.writeFile)(geometryPath, geometryBuffer, 'index.bin');
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (this.options.draco) {
|
|
574
|
+
if (this.options.slpk) {
|
|
575
|
+
const slpkCompressedGeometryPath = (0, _path.join)(childPath, 'geometries');
|
|
576
|
+
this.fileMap["".concat(slpkChildPath, "/geometries/1.bin.gz")] = await (0, _fileUtils.writeFileForSlpk)(slpkCompressedGeometryPath, compressedGeometry, '1.bin');
|
|
577
|
+
} else {
|
|
578
|
+
const compressedGeometryPath = (0, _path.join)(childPath, 'geometries/1/');
|
|
579
|
+
await (0, _fileUtils.writeFile)(compressedGeometryPath, compressedGeometry, 'index.bin');
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
async _writeShared(sharedResources, childPath, slpkChildPath, nodePath) {
|
|
585
|
+
sharedResources.nodePath = nodePath;
|
|
586
|
+
const sharedData = (0, _jsonMapTransform.default)(sharedResources, _sharedResources.SHARED_RESOURCES_TEMPLATE);
|
|
587
|
+
const sharedDataStr = JSON.stringify(sharedData);
|
|
588
|
+
|
|
589
|
+
if (this.options.slpk) {
|
|
590
|
+
const slpkSharedPath = (0, _path.join)(childPath, 'shared');
|
|
591
|
+
this.fileMap["".concat(slpkChildPath, "/shared/sharedResource.json.gz")] = await (0, _fileUtils.writeFileForSlpk)(slpkSharedPath, sharedDataStr, 'sharedResource.json');
|
|
592
|
+
} else {
|
|
593
|
+
const sharedPath = (0, _path.join)(childPath, 'shared/');
|
|
594
|
+
await (0, _fileUtils.writeFile)(sharedPath, sharedDataStr);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
async _writeTexture(texture, childPath, slpkChildPath) {
|
|
599
|
+
if (texture) {
|
|
600
|
+
const format = this._getFormatByMimeType(texture.mimeType);
|
|
601
|
+
|
|
602
|
+
if (!this.layers0.textureSetDefinitions.length) {
|
|
603
|
+
this.layers0.textureSetDefinitions.push({
|
|
604
|
+
formats: [{
|
|
605
|
+
name: '0',
|
|
606
|
+
format
|
|
607
|
+
}, {
|
|
608
|
+
name: '1',
|
|
609
|
+
format: 'ktx2'
|
|
610
|
+
}]
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const textureData = texture.bufferView.data;
|
|
615
|
+
const ktx2TextureData = await (0, _core.encode)(texture.image, _textures.KTX2BasisUniversalTextureWriter);
|
|
616
|
+
|
|
617
|
+
if (this.options.slpk) {
|
|
618
|
+
const slpkTexturePath = (0, _path.join)(childPath, 'textures');
|
|
619
|
+
const compress = false;
|
|
620
|
+
this.fileMap["".concat(slpkChildPath, "/textures/0.").concat(format)] = await (0, _fileUtils.writeFileForSlpk)(slpkTexturePath, textureData, "0.".concat(format), compress);
|
|
621
|
+
this.fileMap["".concat(slpkChildPath, "/textures/1.ktx2")] = await (0, _fileUtils.writeFileForSlpk)(slpkTexturePath, ktx2TextureData, "1.ktx2", compress);
|
|
622
|
+
} else {
|
|
623
|
+
const texturePath = (0, _path.join)(childPath, 'textures/0/');
|
|
624
|
+
await (0, _fileUtils.writeFile)(texturePath, textureData, "index.".concat(format));
|
|
625
|
+
const ktx2TexturePath = (0, _path.join)(childPath, 'textures/1/');
|
|
626
|
+
await (0, _fileUtils.writeFile)(ktx2TexturePath, ktx2TextureData, "index.ktx2");
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
async _writeAttributes(attributes, childPath, slpkChildPath) {
|
|
632
|
+
if (attributes.length && this.layers0.attributeStorageInfo && this.layers0.attributeStorageInfo.length) {
|
|
633
|
+
for (let index = 0; index < attributes.length; index++) {
|
|
634
|
+
const folderName = this.layers0.attributeStorageInfo[index].key;
|
|
635
|
+
const fileBuffer = new Uint8Array(attributes[index]);
|
|
636
|
+
|
|
637
|
+
if (this.options.slpk) {
|
|
638
|
+
const slpkAttributesPath = (0, _path.join)(childPath, 'attributes', folderName);
|
|
639
|
+
this.fileMap["".concat(slpkChildPath, "/attributes/").concat(folderName, ".bin.gz")] = await (0, _fileUtils.writeFileForSlpk)(slpkAttributesPath, fileBuffer, '0.bin');
|
|
640
|
+
} else {
|
|
641
|
+
const attributesPath = (0, _path.join)(childPath, "attributes/".concat(folderName, "/0"));
|
|
642
|
+
await (0, _fileUtils.writeFile)(attributesPath, fileBuffer, 'index.bin');
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
_getFormatByMimeType(mimeType) {
|
|
649
|
+
switch (mimeType) {
|
|
650
|
+
case 'image/jpeg':
|
|
651
|
+
return 'jpg';
|
|
652
|
+
|
|
653
|
+
case 'image/png':
|
|
654
|
+
return 'png';
|
|
655
|
+
|
|
656
|
+
default:
|
|
657
|
+
return 'jpg';
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
_findOrCreateMaterial(material) {
|
|
662
|
+
const hash = (0, _md.default)(JSON.stringify(material));
|
|
663
|
+
|
|
664
|
+
if (this.materialMap.has(hash)) {
|
|
665
|
+
return this.materialMap.get(hash);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const newMaterialId = this.materialDefinitions.push(material) - 1;
|
|
669
|
+
this.materialMap.set(hash, newMaterialId);
|
|
670
|
+
return newMaterialId;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
_createdStorageAttribute(attributeIndex, key, attributeType) {
|
|
674
|
+
const storageAttribute = {
|
|
675
|
+
key: "f_".concat(attributeIndex),
|
|
676
|
+
name: key,
|
|
677
|
+
ordering: ['attributeValues'],
|
|
678
|
+
header: [{
|
|
679
|
+
property: 'count',
|
|
680
|
+
valueType: 'UInt32'
|
|
681
|
+
}],
|
|
682
|
+
attributeValues: {
|
|
683
|
+
valueType: 'Int32',
|
|
684
|
+
valuesPerElement: 1
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
switch (attributeType) {
|
|
689
|
+
case OBJECT_ID_TYPE:
|
|
690
|
+
this._setupIdAttribute(storageAttribute);
|
|
691
|
+
|
|
692
|
+
break;
|
|
693
|
+
|
|
694
|
+
case STRING_TYPE:
|
|
695
|
+
this._setupStringAttribute(storageAttribute);
|
|
696
|
+
|
|
697
|
+
break;
|
|
698
|
+
|
|
699
|
+
case DOUBLE_TYPE:
|
|
700
|
+
this._setupDoubleAttribute(storageAttribute);
|
|
701
|
+
|
|
702
|
+
break;
|
|
703
|
+
|
|
704
|
+
case SHORT_INT_TYPE:
|
|
705
|
+
break;
|
|
706
|
+
|
|
707
|
+
default:
|
|
708
|
+
this._setupStringAttribute(storageAttribute);
|
|
709
|
+
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
return storageAttribute;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
getAttributeType(key, attribute) {
|
|
716
|
+
if (key === OBJECT_ID_TYPE) {
|
|
717
|
+
return OBJECT_ID_TYPE;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
if (typeof attribute === STRING_TYPE) {
|
|
721
|
+
return STRING_TYPE;
|
|
722
|
+
} else if (typeof attribute === 'number') {
|
|
723
|
+
return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return STRING_TYPE;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
_setupStringAttribute(storageAttribute) {
|
|
730
|
+
storageAttribute.ordering.unshift('attributeByteCounts');
|
|
731
|
+
storageAttribute.header.push({
|
|
732
|
+
property: 'attributeValuesByteCount',
|
|
733
|
+
valueType: 'UInt32'
|
|
734
|
+
});
|
|
735
|
+
storageAttribute.attributeValues = {
|
|
736
|
+
valueType: 'String',
|
|
737
|
+
encoding: 'UTF-8',
|
|
738
|
+
valuesPerElement: 1
|
|
739
|
+
};
|
|
740
|
+
storageAttribute.attributeByteCounts = {
|
|
741
|
+
valueType: 'UInt32',
|
|
742
|
+
valuesPerElement: 1
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
_setupIdAttribute(storageAttribute) {
|
|
747
|
+
storageAttribute.attributeValues = {
|
|
748
|
+
valueType: 'Oid32',
|
|
749
|
+
valuesPerElement: 1
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
_setupDoubleAttribute(storageAttribute) {
|
|
754
|
+
storageAttribute.attributeValues = {
|
|
755
|
+
valueType: 'Float64',
|
|
756
|
+
valuesPerElement: 1
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
_createFieldAttribute(key, fieldAttributeType) {
|
|
761
|
+
return {
|
|
762
|
+
name: key,
|
|
763
|
+
type: fieldAttributeType,
|
|
764
|
+
alias: key
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
_convertBatchTableInfoToNodeAttributes(batchTable) {
|
|
769
|
+
let attributeIndex = 0;
|
|
770
|
+
const batchTableWithObjectId = {
|
|
771
|
+
OBJECTID: [0],
|
|
772
|
+
...batchTable
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
for (const key in batchTableWithObjectId) {
|
|
776
|
+
const firstAttribute = batchTableWithObjectId[key][0];
|
|
777
|
+
const attributeType = this.getAttributeType(key, firstAttribute);
|
|
778
|
+
|
|
779
|
+
const storageAttribute = this._createdStorageAttribute(attributeIndex, key, attributeType);
|
|
780
|
+
|
|
781
|
+
const fieldAttributeType = this._getFieldAttributeType(attributeType);
|
|
782
|
+
|
|
783
|
+
const fieldAttribute = this._createFieldAttribute(key, fieldAttributeType);
|
|
784
|
+
|
|
785
|
+
const popupInfo = this._createPopupInfo(batchTableWithObjectId);
|
|
786
|
+
|
|
787
|
+
this.layers0.attributeStorageInfo.push(storageAttribute);
|
|
788
|
+
this.layers0.fields.push(fieldAttribute);
|
|
789
|
+
this.layers0.popupInfo = popupInfo;
|
|
790
|
+
this.layers0.layerType = _3D_OBJECT_LAYER_TYPE;
|
|
791
|
+
attributeIndex += 1;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
_getFieldAttributeType(attributeType) {
|
|
796
|
+
switch (attributeType) {
|
|
797
|
+
case OBJECT_ID_TYPE:
|
|
798
|
+
return 'esriFieldTypeOID';
|
|
799
|
+
|
|
800
|
+
case STRING_TYPE:
|
|
801
|
+
return 'esriFieldTypeString';
|
|
802
|
+
|
|
803
|
+
case SHORT_INT_TYPE:
|
|
804
|
+
return 'esriFieldTypeInteger';
|
|
805
|
+
|
|
806
|
+
case DOUBLE_TYPE:
|
|
807
|
+
return 'esriFieldTypeDouble';
|
|
808
|
+
|
|
809
|
+
default:
|
|
810
|
+
return 'esriFieldTypeString';
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
_createPopupInfo(batchTable) {
|
|
815
|
+
const title = '{OBJECTID}';
|
|
816
|
+
const mediaInfos = [];
|
|
817
|
+
const fieldInfos = [];
|
|
818
|
+
const popupElements = [];
|
|
819
|
+
const expressionInfos = [];
|
|
820
|
+
|
|
821
|
+
for (const key in batchTable) {
|
|
822
|
+
fieldInfos.push({
|
|
823
|
+
fieldName: key,
|
|
824
|
+
visible: true,
|
|
825
|
+
isEditable: false,
|
|
826
|
+
label: key
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
popupElements.push({
|
|
831
|
+
fieldInfos,
|
|
832
|
+
type: 'fields'
|
|
833
|
+
});
|
|
834
|
+
return {
|
|
835
|
+
title,
|
|
836
|
+
mediaInfos,
|
|
837
|
+
popupElements,
|
|
838
|
+
fieldInfos,
|
|
839
|
+
expressionInfos
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
async _finishConversion(params) {
|
|
844
|
+
const {
|
|
845
|
+
tilesCount,
|
|
846
|
+
tilesWithAddRefineCount
|
|
847
|
+
} = this.refinementCounter;
|
|
848
|
+
const addRefinementPercentage = tilesWithAddRefineCount ? tilesWithAddRefineCount / tilesCount * 100 : 0;
|
|
849
|
+
const filesSize = await (0, _statisticUtills.calculateFilesSize)(params);
|
|
850
|
+
|
|
851
|
+
const diff = _process.default.hrtime(this.conversionStartTime);
|
|
852
|
+
|
|
853
|
+
const conversionTime = (0, _statisticUtills.timeConverter)(diff);
|
|
854
|
+
console.log("------------------------------------------------");
|
|
855
|
+
console.log("Finishing conversion of ".concat(_3D_TILES));
|
|
856
|
+
console.log("Total conversion time: ".concat(conversionTime));
|
|
857
|
+
console.log("Vertex count: ", this.vertexCounter);
|
|
858
|
+
console.log("File(s) size: ", filesSize, ' bytes');
|
|
859
|
+
console.log("Percentage of tiles with \"ADD\" refinement type:", addRefinementPercentage, '%');
|
|
860
|
+
console.log("------------------------------------------------");
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
async _fetchPreloadOptions() {
|
|
864
|
+
if (!this.Loader.preload) {
|
|
865
|
+
return {};
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
const options = {
|
|
869
|
+
'cesium-ion': {
|
|
870
|
+
accessToken: this.options.token || ION_DEFAULT_TOKEN
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
const preloadOptions = await this.Loader.preload(this.options.inputUrl, options);
|
|
874
|
+
this.refreshTokenTime = _process.default.hrtime();
|
|
875
|
+
return { ...options,
|
|
876
|
+
...preloadOptions
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
async _updateTilesetOptions() {
|
|
881
|
+
const diff = _process.default.hrtime(this.refreshTokenTime);
|
|
882
|
+
|
|
883
|
+
if (diff[0] < REFRESH_TOKEN_TIMEOUT) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
this.refreshTokenTime = _process.default.hrtime();
|
|
888
|
+
const preloadOptions = await this._fetchPreloadOptions();
|
|
889
|
+
this.sourceTileset.options = { ...this.sourceTileset.options,
|
|
890
|
+
...preloadOptions
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
if (preloadOptions.headers) {
|
|
894
|
+
this.sourceTileset.loadOptions.fetch = { ...this.sourceTileset.loadOptions.fetch,
|
|
895
|
+
headers: preloadOptions.headers
|
|
896
|
+
};
|
|
897
|
+
console.log('Authorization Bearer token has been updated');
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
_checkAddRefinementTypeForTile(tile) {
|
|
902
|
+
const ADD_TILE_REFINEMENT = 1;
|
|
903
|
+
|
|
904
|
+
if (tile.refine === ADD_TILE_REFINEMENT) {
|
|
905
|
+
this.refinementCounter.tilesWithAddRefineCount += 1;
|
|
906
|
+
console.warn('This tile uses "ADD" type of refinement');
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
this.refinementCounter.tilesCount += 1;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
exports.default = I3SConverter;
|
|
915
|
+
//# sourceMappingURL=i3s-converter.js.map
|