@loaders.gl/tile-converter 3.0.13 → 3.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.es5.min.js +3 -3
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +11 -11
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +422 -184
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +299 -202
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +8 -4
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +17 -7
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +65 -17
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +16 -16
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +33 -9
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +103 -93
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +505 -344
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +26 -30
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +203 -102
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +1510 -680
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js +25 -15
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +21 -12
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +4 -2
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +55 -15
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js +4 -2
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-server/app.js +6 -6
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +60 -20
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +41 -14
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +4 -4
- package/dist/es5/lib/geoid-height-model.js +114 -100
- package/dist/es5/lib/geoid-height-model.js.map +1 -1
- package/dist/es5/lib/pgm-parser.js +122 -68
- package/dist/es5/lib/pgm-parser.js.map +1 -1
- package/dist/es5/lib/utils/compress-util.js +345 -123
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +98 -20
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +152 -41
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/pgm-loader.js +5 -3
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +11 -3
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/scripts/converter.js +134 -71
- package/package.json +14 -14
- package/src/i3s-converter/i3s-converter.ts +10 -3
|
@@ -7,14 +7,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
+
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
|
|
10
20
|
var _path = require("path");
|
|
11
21
|
|
|
12
22
|
var _jsonMapTransform = _interopRequireDefault(require("json-map-transform"));
|
|
13
23
|
|
|
14
24
|
var _metadata = require("../json-templates/metadata");
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
27
|
+
|
|
28
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
+
|
|
30
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
31
|
+
|
|
32
|
+
var NodePages = function () {
|
|
33
|
+
function NodePages(writeFileFunc, nodesPerPage) {
|
|
34
|
+
(0, _classCallCheck2.default)(this, NodePages);
|
|
18
35
|
this.nodesPerPage = nodesPerPage;
|
|
19
36
|
this.nodesCounter = 0;
|
|
20
37
|
this.nodePages = [{}];
|
|
@@ -22,129 +39,213 @@ class NodePages {
|
|
|
22
39
|
this.writeFile = writeFileFunc;
|
|
23
40
|
}
|
|
24
41
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
getNodeById(id) {
|
|
30
|
-
const pageIndex = Math.floor(id / this.nodesPerPage);
|
|
31
|
-
const nodeIndex = id % this.nodesPerPage;
|
|
32
|
-
return this.nodePages[pageIndex].nodes[nodeIndex];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
updateMaterialByNodeId(id, materialId) {
|
|
36
|
-
const node = this.getNodeById(id);
|
|
37
|
-
|
|
38
|
-
if (!node.mesh) {
|
|
39
|
-
return;
|
|
42
|
+
(0, _createClass2.default)(NodePages, [{
|
|
43
|
+
key: "useWriteFunction",
|
|
44
|
+
value: function useWriteFunction(func) {
|
|
45
|
+
this.writeFile = func;
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
updateVertexCountByNodeId(id, vertexCount) {
|
|
49
|
-
const node = this.getNodeById(id);
|
|
50
|
-
|
|
51
|
-
if (!node.mesh) {
|
|
52
|
-
return;
|
|
47
|
+
}, {
|
|
48
|
+
key: "getNodeById",
|
|
49
|
+
value: function getNodeById(id) {
|
|
50
|
+
var pageIndex = Math.floor(id / this.nodesPerPage);
|
|
51
|
+
var nodeIndex = id % this.nodesPerPage;
|
|
52
|
+
return this.nodePages[pageIndex].nodes[nodeIndex];
|
|
53
53
|
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "updateMaterialByNodeId",
|
|
56
|
+
value: function updateMaterialByNodeId(id, materialId) {
|
|
57
|
+
var node = this.getNodeById(id);
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
updateNodeAttributeByNodeId(id) {
|
|
59
|
-
const node = this.getNodeById(id);
|
|
60
|
-
|
|
61
|
-
if (!node.mesh) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
node.mesh.attribute.resource = node.index;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
updateFeatureCountByNodeId(id, featureCount) {
|
|
69
|
-
const node = this.getNodeById(id);
|
|
59
|
+
if (!node.mesh) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
node.mesh.material = {
|
|
64
|
+
definition: materialId,
|
|
65
|
+
resource: node.index
|
|
66
|
+
};
|
|
73
67
|
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "updateVertexCountByNodeId",
|
|
70
|
+
value: function updateVertexCountByNodeId(id, vertexCount) {
|
|
71
|
+
var node = this.getNodeById(id);
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
updateTexelCountHintByNodeId(id, texelCountHint) {
|
|
79
|
-
const node = this.getNodeById(id);
|
|
73
|
+
if (!node.mesh) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
80
76
|
|
|
81
|
-
|
|
82
|
-
return;
|
|
77
|
+
node.mesh.geometry.vertexCount = vertexCount;
|
|
83
78
|
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "updateNodeAttributeByNodeId",
|
|
81
|
+
value: function updateNodeAttributeByNodeId(id) {
|
|
82
|
+
var node = this.getNodeById(id);
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
if (!node.mesh) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
if (parentId === null) {
|
|
90
|
-
return;
|
|
88
|
+
node.mesh.attribute.resource = node.index;
|
|
91
89
|
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "updateFeatureCountByNodeId",
|
|
92
|
+
value: function updateFeatureCountByNodeId(id, featureCount) {
|
|
93
|
+
var node = this.getNodeById(id);
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
if (!node.mesh) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
if (node.mesh) {
|
|
99
|
-
node.mesh.geometry.resource = node.index;
|
|
99
|
+
node.mesh.geometry.featureCount = featureCount;
|
|
100
100
|
}
|
|
101
|
-
}
|
|
101
|
+
}, {
|
|
102
|
+
key: "updateTexelCountHintByNodeId",
|
|
103
|
+
value: function updateTexelCountHintByNodeId(id, texelCountHint) {
|
|
104
|
+
var node = this.getNodeById(id);
|
|
102
105
|
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
if (!node.mesh || !node.mesh.material) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
currentNodePage = {
|
|
108
|
-
nodes: []
|
|
109
|
-
};
|
|
110
|
-
this.nodePages.push(currentNodePage);
|
|
110
|
+
node.mesh.material.texelCountHint = texelCountHint;
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return node.index;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async save(layers0Path, fileMap, slpk = false) {
|
|
121
|
-
const promises = [];
|
|
122
|
-
|
|
123
|
-
if (slpk) {
|
|
124
|
-
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
125
|
-
const nodePageStr = JSON.stringify(nodePage);
|
|
126
|
-
const slpkPath = (0, _path.join)(layers0Path, 'nodepages');
|
|
127
|
-
promises.push(this.writeFile(slpkPath, nodePageStr, "".concat(index.toString(), ".json")));
|
|
128
|
-
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = "".concat(slpkPath, ".json.gz");
|
|
112
|
+
}, {
|
|
113
|
+
key: "addChildRelation",
|
|
114
|
+
value: function addChildRelation(parentId, childId) {
|
|
115
|
+
if (parentId === null) {
|
|
116
|
+
return;
|
|
129
117
|
}
|
|
130
118
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const nodePagePath = (0, _path.join)(layers0Path, 'nodepages', index.toString());
|
|
140
|
-
promises.push(this.writeFile(nodePagePath, nodePageStr));
|
|
119
|
+
var parentNode = this.getNodeById(parentId);
|
|
120
|
+
parentNode.children.push(childId);
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "updateResourceInMesh",
|
|
124
|
+
value: function updateResourceInMesh(node) {
|
|
125
|
+
if (node.mesh) {
|
|
126
|
+
node.mesh.geometry.resource = node.index;
|
|
141
127
|
}
|
|
142
128
|
}
|
|
129
|
+
}, {
|
|
130
|
+
key: "push",
|
|
131
|
+
value: function push(node) {
|
|
132
|
+
var parentId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
133
|
+
var currentNodePage = this.nodePages[this.nodePages.length - 1];
|
|
134
|
+
|
|
135
|
+
if (currentNodePage.nodes.length === this.nodesPerPage) {
|
|
136
|
+
currentNodePage = {
|
|
137
|
+
nodes: []
|
|
138
|
+
};
|
|
139
|
+
this.nodePages.push(currentNodePage);
|
|
140
|
+
}
|
|
143
141
|
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
node.index = this.nodesCounter++;
|
|
143
|
+
currentNodePage.nodes.push(node);
|
|
144
|
+
this.addChildRelation(parentId, node.index);
|
|
145
|
+
this.updateResourceInMesh(node);
|
|
146
|
+
return node.index;
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
key: "save",
|
|
150
|
+
value: function () {
|
|
151
|
+
var _save = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(layers0Path, fileMap) {
|
|
152
|
+
var slpk,
|
|
153
|
+
promises,
|
|
154
|
+
_iterator,
|
|
155
|
+
_step,
|
|
156
|
+
_step$value,
|
|
157
|
+
index,
|
|
158
|
+
nodePage,
|
|
159
|
+
nodePageStr,
|
|
160
|
+
slpkPath,
|
|
161
|
+
metadata,
|
|
162
|
+
compress,
|
|
163
|
+
_iterator2,
|
|
164
|
+
_step2,
|
|
165
|
+
_step2$value,
|
|
166
|
+
_index,
|
|
167
|
+
_nodePage,
|
|
168
|
+
_nodePageStr,
|
|
169
|
+
nodePagePath,
|
|
170
|
+
_args = arguments;
|
|
171
|
+
|
|
172
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
173
|
+
while (1) {
|
|
174
|
+
switch (_context.prev = _context.next) {
|
|
175
|
+
case 0:
|
|
176
|
+
slpk = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
|
|
177
|
+
promises = [];
|
|
178
|
+
|
|
179
|
+
if (!slpk) {
|
|
180
|
+
_context.next = 12;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_iterator = _createForOfIteratorHelper(this.nodePages.entries());
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
188
|
+
_step$value = (0, _slicedToArray2.default)(_step.value, 2), index = _step$value[0], nodePage = _step$value[1];
|
|
189
|
+
nodePageStr = JSON.stringify(nodePage);
|
|
190
|
+
slpkPath = (0, _path.join)(layers0Path, 'nodepages');
|
|
191
|
+
promises.push(this.writeFile(slpkPath, nodePageStr, "".concat(index.toString(), ".json")));
|
|
192
|
+
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = "".concat(slpkPath, ".json.gz");
|
|
193
|
+
}
|
|
194
|
+
} catch (err) {
|
|
195
|
+
_iterator.e(err);
|
|
196
|
+
} finally {
|
|
197
|
+
_iterator.f();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
metadata = (0, _jsonMapTransform.default)({
|
|
201
|
+
nodeCount: this.nodesCounter
|
|
202
|
+
}, _metadata.METADATA);
|
|
203
|
+
compress = false;
|
|
204
|
+
_context.next = 9;
|
|
205
|
+
return this.writeFile(layers0Path, JSON.stringify(metadata), 'metadata.json', compress);
|
|
206
|
+
|
|
207
|
+
case 9:
|
|
208
|
+
fileMap['metadata.json'] = _context.sent;
|
|
209
|
+
_context.next = 14;
|
|
210
|
+
break;
|
|
211
|
+
|
|
212
|
+
case 12:
|
|
213
|
+
_iterator2 = _createForOfIteratorHelper(this.nodePages.entries());
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
217
|
+
_step2$value = (0, _slicedToArray2.default)(_step2.value, 2), _index = _step2$value[0], _nodePage = _step2$value[1];
|
|
218
|
+
_nodePageStr = JSON.stringify(_nodePage);
|
|
219
|
+
nodePagePath = (0, _path.join)(layers0Path, 'nodepages', _index.toString());
|
|
220
|
+
promises.push(this.writeFile(nodePagePath, _nodePageStr));
|
|
221
|
+
}
|
|
222
|
+
} catch (err) {
|
|
223
|
+
_iterator2.e(err);
|
|
224
|
+
} finally {
|
|
225
|
+
_iterator2.f();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
case 14:
|
|
229
|
+
_context.next = 16;
|
|
230
|
+
return Promise.all(promises);
|
|
231
|
+
|
|
232
|
+
case 16:
|
|
233
|
+
case "end":
|
|
234
|
+
return _context.stop();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}, _callee, this);
|
|
238
|
+
}));
|
|
239
|
+
|
|
240
|
+
function save(_x, _x2) {
|
|
241
|
+
return _save.apply(this, arguments);
|
|
242
|
+
}
|
|
146
243
|
|
|
147
|
-
|
|
244
|
+
return save;
|
|
245
|
+
}()
|
|
246
|
+
}]);
|
|
247
|
+
return NodePages;
|
|
248
|
+
}();
|
|
148
249
|
|
|
149
250
|
exports.default = NodePages;
|
|
150
251
|
//# sourceMappingURL=node-pages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/node-pages.js"],"names":["NodePages","constructor","writeFileFunc","nodesPerPage","nodesCounter","nodePages","nodes","writeFile","useWriteFunction","func","getNodeById","id","pageIndex","Math","floor","nodeIndex","updateMaterialByNodeId","materialId","node","mesh","material","definition","resource","index","updateVertexCountByNodeId","vertexCount","geometry","updateNodeAttributeByNodeId","attribute","updateFeatureCountByNodeId","featureCount","updateTexelCountHintByNodeId","texelCountHint","addChildRelation","parentId","childId","parentNode","children","push","updateResourceInMesh","currentNodePage","length","save","layers0Path","fileMap","slpk","promises","nodePage","entries","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","metadataTemplate","compress","nodePagePath","Promise","all"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAkCe,MAAMA,SAAN,CAAgB;AAO7BC,EAAAA,WAAW,CAACC,aAAD,EAAgBC,YAAhB,EAA8B;AACvC,SAAKA,YAAL,GAAoBA,YAApB;AACA,SAAKC,YAAL,GAAoB,CAApB;AACA,SAAKC,SAAL,G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,CAAeG,QAAf,CAF+B,EAG/B,eAH+B,EAI/BG,QAJ+B,CAAjC;AAMD,KAfD,MAeO;AACL,WAAK,MAAM,CAAClC,KAAD,EAAQwB,QAAR,CAAX,IAAgC,KAAK1C,SAAL,CAAe2C,OAAf,EAAhC,EAA0D;AACxD,cAAMC,WAAW,GAAGC,IAAI,CAACC,SAAL,CAAeJ,QAAf,CAApB;AACA,cAAMW,YAAY,GAAG,gBAAKf,WAAL,EAAkB,WAAlB,EAA+BpB,KAAK,CAAC8B,QAAN,EAA/B,CAArB;AACAP,QAAAA,QAAQ,CAACR,IAAT,CAAc,KAAK/B,SAAL,CAAemD,YAAf,EAA6BT,WAA7B,CAAd;AACD;AACF;;AAED,UAAMU,OAAO,CAACC,GAAR,CAAYd,QAAZ,CAAN;AACD;;AA1K4B","sourcesContent":["import {join} from 'path';\nimport transform from 'json-map-transform';\nimport {METADATA as metadataTemplate} from '../json-templates/metadata';\n\n/**\n * class NodePages - wrapper of nodePages array\n *\n * @example\n * import {writeFile} from './helpers/write-file';\n *\n * // create an instance of the class\n * const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);\n * ...\n * // push root node\n * const parentId = nodePages.push({\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: []\n });\n * ...\n * // push node with parent relation\n * const nodeInPage = {\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: [],\n mesh: {\n geometry: {\n definition: 0\n }\n }\n };\n * const nodeId = this.nodePages.push(nodeInPage, parentId);\n * ...\n * // save all the nodePages in the end of pushing all the nodes\n * await this.nodePages.save(layers0path);\n */\nexport default class NodePages {\n /**\n * @constructs\n * Create a nodePages instance.\n * @param writeFileFunc - function to save one nodePage into a file\n * @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met\n */\n constructor(writeFileFunc, nodesPerPage) {\n this.nodesPerPage = nodesPerPage;\n this.nodesCounter = 0;\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n useWriteFunction(func) {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param {number} id - end-to-end index of the node\n * @return {object} the node object\n */\n getNodeById(id) {\n const pageIndex = Math.floor(id / this.nodesPerPage);\n const nodeIndex = id % this.nodesPerPage;\n return this.nodePages[pageIndex].nodes[nodeIndex];\n }\n\n /**\n * Update material in node.mesh object by node id\n * @param id - end-to-end index of the node\n * @param materialId - id from scene layer materialDefinitions\n */\n updateMaterialByNodeId(id, materialId) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.material = {\n definition: materialId,\n resource: node.index\n };\n }\n\n /**\n * Update vertexCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param vertexCount - vertex count for particular node\n */\n updateVertexCountByNodeId(id, vertexCount) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.vertexCount = vertexCount;\n }\n\n /**\n * Update resource in node.mesh.attribute object by node id\n * @param id - end-to-end index of the node\n */\n updateNodeAttributeByNodeId(id) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.attribute.resource = node.index;\n }\n\n /**\n * Update featureCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param featureCount - features count of the node\n */\n updateFeatureCountByNodeId(id, featureCount) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n updateTexelCountHintByNodeId(id, texelCountHint) {\n const node = this.getNodeById(id);\n if (!node.mesh || !node.mesh.material) {\n return;\n }\n node.mesh.material.texelCountHint = texelCountHint;\n }\n\n /**\n * Add a child id into the parent node.children array\n * @param {number | null} parentId - end-to-end parent node index\n * @param {number} childId - end-to-end child node index\n * @return {void}\n */\n addChildRelation(parentId, childId) {\n if (parentId === null) {\n return;\n }\n const parentNode = this.getNodeById(parentId);\n parentNode.children.push(childId);\n }\n\n /**\n * Update resource index in node.mesh object\n * @param {object} node - node object\n * @return {void}\n */\n updateResourceInMesh(node) {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param {object} node - node object\n * @param {number | null} parentId - index of parent node\n * @return {number}\n */\n push(node, parentId = null) {\n let currentNodePage = this.nodePages[this.nodePages.length - 1];\n if (currentNodePage.nodes.length === this.nodesPerPage) {\n currentNodePage = {nodes: []};\n this.nodePages.push(currentNodePage);\n }\n node.index = this.nodesCounter++;\n currentNodePage.nodes.push(node);\n this.addChildRelation(parentId, node.index);\n this.updateResourceInMesh(node);\n return node.index;\n }\n\n /**\n * Save all the node pages\n * Run this method when all nodes is pushed in nodePages\n * @param {string} layers0Path - path of layer\n * @param {Object} fileMap\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path, fileMap, slpk = false) {\n const promises = [];\n if (slpk) {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const slpkPath = join(layers0Path, 'nodepages');\n promises.push(this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`));\n fileMap[`nodePages/${index.toString()}.json.gz`] = `${slpkPath}.json.gz`;\n }\n const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate);\n const compress = false;\n fileMap['metadata.json'] = await this.writeFile(\n layers0Path,\n JSON.stringify(metadata),\n 'metadata.json',\n compress\n );\n } else {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const nodePagePath = join(layers0Path, 'nodepages', index.toString());\n promises.push(this.writeFile(nodePagePath, nodePageStr));\n }\n }\n\n await Promise.all(promises);\n }\n}\n"],"file":"node-pages.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/i3s-converter/helpers/node-pages.js"],"names":["NodePages","writeFileFunc","nodesPerPage","nodesCounter","nodePages","nodes","writeFile","func","id","pageIndex","Math","floor","nodeIndex","materialId","node","getNodeById","mesh","material","definition","resource","index","vertexCount","geometry","attribute","featureCount","texelCountHint","parentId","childId","parentNode","children","push","currentNodePage","length","addChildRelation","updateResourceInMesh","layers0Path","fileMap","slpk","promises","entries","nodePage","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","metadataTemplate","compress","nodePagePath","Promise","all"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;IAkCqBA,S;AAOnB,qBAAYC,aAAZ,EAA2BC,YAA3B,EAAyC;AAAA;AACvC,SAAKA,YAAL,GAAoBA,YAApB;AACA,SAAKC,YAAL,GAAoB,CAApB;AACA,SAAKC,SAAL,GAAiB,CAAC,EAAD,CAAjB;AACA,SAAKA,SAAL,CAAe,CAAf,EAAkBC,KAAlB,GAA0B,EAA1B;AACA,SAAKC,SAAL,GAAiBL,aAAjB;AACD;;;;WAED,0BAAiBM,IAAjB,EAAuB;AACrB,WAAKD,SAAL,GAAiBC,IAAjB;AACD;;;WAOD,qBAAYC,EAAZ,EAAgB;AACd,UAAMC,SAAS,GAAGC,IAAI,CAACC,KAAL,CAAWH,EAAE,GAAG,KAAKN,YAArB,CAAlB;AACA,UAAMU,SAAS,GAAGJ,EAAE,GAAG,KAAKN,YAA5B;AACA,aAAO,KAAKE,SAAL,CAAeK,SAAf,EAA0BJ,KAA1B,CAAgCO,SAAhC,CAAP;AACD;;;WAOD,gCAAuBJ,EAAvB,EAA2BK,UAA3B,EAAuC;AACrC,UAAMC,IAAI,GAAG,KAAKC,WAAL,CAAiBP,EAAjB,CAAb;;AACA,UAAI,CAACM,IAAI,CAACE,IAAV,EAAgB;AACd;AACD;;AACDF,MAAAA,IAAI,CAACE,IAAL,CAAUC,QAAV,GAAqB;AACnBC,QAAAA,UAAU,EAAEL,UADO;AAEnBM,QAAAA,QAAQ,EAAEL,IAAI,CAACM;AAFI,OAArB;AAID;;;WAOD,mCAA0BZ,EAA1B,EAA8Ba,WAA9B,EAA2C;AACzC,UAAMP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,QAFkD,GAEvC,gBAAKT,WAAL,EAAkB,WAAlB,CAFuC;AAGxDG,oBAAAA,QAAQ,CAACR,IAAT,CAAc,KAAKxB,SAAL,CAAesC,QAAf,EAAyBH,WAAzB,YAAyCrB,KAAK,CAACyB,QAAN,EAAzC,WAAd;AACAT,oBAAAA,OAAO,qBAAchB,KAAK,CAACyB,QAAN,EAAd,cAAP,aAAsDD,QAAtD;AACD;AARL;AAAA;AAAA;AAAA;AAAA;;AASUE,gBAAAA,QATV,GASqB,+BAAU;AAACC,kBAAAA,SAAS,EAAE,KAAK5C;AAAjB,iBAAV,EAA0C6C,kBAA1C,CATrB;AAUUC,gBAAAA,QAVV,GAUqB,KAVrB;AAAA;AAAA,uBAWqC,KAAK3C,SAAL,CAC/B6B,WAD+B,EAE/BO,IAAI,CAACC,SAAL,CAAeG,QAAf,CAF+B,EAG/B,eAH+B,EAI/BG,QAJ+B,CAXrC;;AAAA;AAWIb,gBAAAA,OAAO,CAAC,eAAD,CAXX;AAAA;AAAA;;AAAA;AAAA,wDAkBoC,KAAKhC,SAAL,CAAemC,OAAf,EAlBpC;;AAAA;AAkBI,yEAA0D;AAAA,kFAA9CnB,MAA8C,oBAAvCoB,SAAuC;AAClDC,oBAAAA,YADkD,GACpCC,IAAI,CAACC,SAAL,CAAeH,SAAf,CADoC;AAElDU,oBAAAA,YAFkD,GAEnC,gBAAKf,WAAL,EAAkB,WAAlB,EAA+Bf,MAAK,CAACyB,QAAN,EAA/B,CAFmC;AAGxDP,oBAAAA,QAAQ,CAACR,IAAT,CAAc,KAAKxB,SAAL,CAAe4C,YAAf,EAA6BT,YAA7B,CAAd;AACD;AAtBL;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,uBAyBQU,OAAO,CAACC,GAAR,CAAYd,QAAZ,CAzBR;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O","sourcesContent":["import {join} from 'path';\nimport transform from 'json-map-transform';\nimport {METADATA as metadataTemplate} from '../json-templates/metadata';\n\n/**\n * class NodePages - wrapper of nodePages array\n *\n * @example\n * import {writeFile} from './helpers/write-file';\n *\n * // create an instance of the class\n * const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);\n * ...\n * // push root node\n * const parentId = nodePages.push({\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: []\n });\n * ...\n * // push node with parent relation\n * const nodeInPage = {\n lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,\n obb: coordinates.obb,\n children: [],\n mesh: {\n geometry: {\n definition: 0\n }\n }\n };\n * const nodeId = this.nodePages.push(nodeInPage, parentId);\n * ...\n * // save all the nodePages in the end of pushing all the nodes\n * await this.nodePages.save(layers0path);\n */\nexport default class NodePages {\n /**\n * @constructs\n * Create a nodePages instance.\n * @param writeFileFunc - function to save one nodePage into a file\n * @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met\n */\n constructor(writeFileFunc, nodesPerPage) {\n this.nodesPerPage = nodesPerPage;\n this.nodesCounter = 0;\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n useWriteFunction(func) {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param {number} id - end-to-end index of the node\n * @return {object} the node object\n */\n getNodeById(id) {\n const pageIndex = Math.floor(id / this.nodesPerPage);\n const nodeIndex = id % this.nodesPerPage;\n return this.nodePages[pageIndex].nodes[nodeIndex];\n }\n\n /**\n * Update material in node.mesh object by node id\n * @param id - end-to-end index of the node\n * @param materialId - id from scene layer materialDefinitions\n */\n updateMaterialByNodeId(id, materialId) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.material = {\n definition: materialId,\n resource: node.index\n };\n }\n\n /**\n * Update vertexCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param vertexCount - vertex count for particular node\n */\n updateVertexCountByNodeId(id, vertexCount) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.vertexCount = vertexCount;\n }\n\n /**\n * Update resource in node.mesh.attribute object by node id\n * @param id - end-to-end index of the node\n */\n updateNodeAttributeByNodeId(id) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.attribute.resource = node.index;\n }\n\n /**\n * Update featureCount in node.mesh.geometry object by node id\n * @param id - end-to-end index of the node\n * @param featureCount - features count of the node\n */\n updateFeatureCountByNodeId(id, featureCount) {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n updateTexelCountHintByNodeId(id, texelCountHint) {\n const node = this.getNodeById(id);\n if (!node.mesh || !node.mesh.material) {\n return;\n }\n node.mesh.material.texelCountHint = texelCountHint;\n }\n\n /**\n * Add a child id into the parent node.children array\n * @param {number | null} parentId - end-to-end parent node index\n * @param {number} childId - end-to-end child node index\n * @return {void}\n */\n addChildRelation(parentId, childId) {\n if (parentId === null) {\n return;\n }\n const parentNode = this.getNodeById(parentId);\n parentNode.children.push(childId);\n }\n\n /**\n * Update resource index in node.mesh object\n * @param {object} node - node object\n * @return {void}\n */\n updateResourceInMesh(node) {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param {object} node - node object\n * @param {number | null} parentId - index of parent node\n * @return {number}\n */\n push(node, parentId = null) {\n let currentNodePage = this.nodePages[this.nodePages.length - 1];\n if (currentNodePage.nodes.length === this.nodesPerPage) {\n currentNodePage = {nodes: []};\n this.nodePages.push(currentNodePage);\n }\n node.index = this.nodesCounter++;\n currentNodePage.nodes.push(node);\n this.addChildRelation(parentId, node.index);\n this.updateResourceInMesh(node);\n return node.index;\n }\n\n /**\n * Save all the node pages\n * Run this method when all nodes is pushed in nodePages\n * @param {string} layers0Path - path of layer\n * @param {Object} fileMap\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path, fileMap, slpk = false) {\n const promises = [];\n if (slpk) {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const slpkPath = join(layers0Path, 'nodepages');\n promises.push(this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`));\n fileMap[`nodePages/${index.toString()}.json.gz`] = `${slpkPath}.json.gz`;\n }\n const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate);\n const compress = false;\n fileMap['metadata.json'] = await this.writeFile(\n layers0Path,\n JSON.stringify(metadata),\n 'metadata.json',\n compress\n );\n } else {\n for (const [index, nodePage] of this.nodePages.entries()) {\n const nodePageStr = JSON.stringify(nodePage);\n const nodePagePath = join(layers0Path, 'nodepages', index.toString());\n promises.push(this.writeFile(nodePagePath, nodePageStr));\n }\n }\n\n await Promise.all(promises);\n }\n}\n"],"file":"node-pages.js"}
|