@loaders.gl/tile-converter 3.1.7 → 3.1.8
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/converter.min.js +1 -1
- package/dist/dist.min.js +2 -5
- package/dist/es5/i3s-converter/helpers/node-pages.js +78 -35
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/esm/i3s-converter/helpers/node-pages.js +2 -7
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/package.json +14 -14
- package/src/i3s-converter/helpers/node-pages.ts +6 -6
package/dist/dist.min.js
CHANGED
|
@@ -84200,13 +84200,11 @@ var NodePages = class {
|
|
|
84200
84200
|
return node2.index;
|
|
84201
84201
|
}
|
|
84202
84202
|
async save(layers0Path, fileMap, slpk = false) {
|
|
84203
|
-
const promises = [];
|
|
84204
84203
|
if (slpk) {
|
|
84205
84204
|
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
84206
84205
|
const nodePageStr = JSON.stringify(nodePage);
|
|
84207
84206
|
const slpkPath = (0, import_path2.join)(layers0Path, "nodepages");
|
|
84208
|
-
|
|
84209
|
-
fileMap[`nodePages/${index.toString()}.json.gz`] = `${slpkPath}.json.gz`;
|
|
84207
|
+
fileMap[`nodePages/${index.toString()}.json.gz`] = await this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`);
|
|
84210
84208
|
}
|
|
84211
84209
|
const metadata = (0, import_json_map_transform.default)({ nodeCount: this.nodesCounter }, METADATA());
|
|
84212
84210
|
const compress = false;
|
|
@@ -84215,10 +84213,9 @@ var NodePages = class {
|
|
|
84215
84213
|
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
84216
84214
|
const nodePageStr = JSON.stringify(nodePage);
|
|
84217
84215
|
const nodePagePath = (0, import_path2.join)(layers0Path, "nodepages", index.toString());
|
|
84218
|
-
|
|
84216
|
+
await this.writeFile(nodePagePath, nodePageStr);
|
|
84219
84217
|
}
|
|
84220
84218
|
}
|
|
84221
|
-
await Promise.all(promises);
|
|
84222
84219
|
}
|
|
84223
84220
|
};
|
|
84224
84221
|
|
|
@@ -157,7 +157,6 @@ var NodePages = function () {
|
|
|
157
157
|
value: function () {
|
|
158
158
|
var _save = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(layers0Path, fileMap) {
|
|
159
159
|
var slpk,
|
|
160
|
-
promises,
|
|
161
160
|
_iterator,
|
|
162
161
|
_step,
|
|
163
162
|
_step$value,
|
|
@@ -181,67 +180,111 @@ var NodePages = function () {
|
|
|
181
180
|
switch (_context.prev = _context.next) {
|
|
182
181
|
case 0:
|
|
183
182
|
slpk = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
|
|
184
|
-
promises = [];
|
|
185
183
|
|
|
186
184
|
if (!slpk) {
|
|
187
|
-
_context.next =
|
|
185
|
+
_context.next = 29;
|
|
188
186
|
break;
|
|
189
187
|
}
|
|
190
188
|
|
|
191
189
|
_iterator = _createForOfIteratorHelper(this.nodePages.entries());
|
|
190
|
+
_context.prev = 3;
|
|
192
191
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = "".concat(slpkPath, ".json.gz");
|
|
200
|
-
}
|
|
201
|
-
} catch (err) {
|
|
202
|
-
_iterator.e(err);
|
|
203
|
-
} finally {
|
|
204
|
-
_iterator.f();
|
|
192
|
+
_iterator.s();
|
|
193
|
+
|
|
194
|
+
case 5:
|
|
195
|
+
if ((_step = _iterator.n()).done) {
|
|
196
|
+
_context.next = 14;
|
|
197
|
+
break;
|
|
205
198
|
}
|
|
206
199
|
|
|
200
|
+
_step$value = (0, _slicedToArray2.default)(_step.value, 2), index = _step$value[0], nodePage = _step$value[1];
|
|
201
|
+
nodePageStr = JSON.stringify(nodePage);
|
|
202
|
+
slpkPath = (0, _path.join)(layers0Path, 'nodepages');
|
|
203
|
+
_context.next = 11;
|
|
204
|
+
return this.writeFile(slpkPath, nodePageStr, "".concat(index.toString(), ".json"));
|
|
205
|
+
|
|
206
|
+
case 11:
|
|
207
|
+
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = _context.sent;
|
|
208
|
+
|
|
209
|
+
case 12:
|
|
210
|
+
_context.next = 5;
|
|
211
|
+
break;
|
|
212
|
+
|
|
213
|
+
case 14:
|
|
214
|
+
_context.next = 19;
|
|
215
|
+
break;
|
|
216
|
+
|
|
217
|
+
case 16:
|
|
218
|
+
_context.prev = 16;
|
|
219
|
+
_context.t0 = _context["catch"](3);
|
|
220
|
+
|
|
221
|
+
_iterator.e(_context.t0);
|
|
222
|
+
|
|
223
|
+
case 19:
|
|
224
|
+
_context.prev = 19;
|
|
225
|
+
|
|
226
|
+
_iterator.f();
|
|
227
|
+
|
|
228
|
+
return _context.finish(19);
|
|
229
|
+
|
|
230
|
+
case 22:
|
|
207
231
|
metadata = (0, _jsonMapTransform.default)({
|
|
208
232
|
nodeCount: this.nodesCounter
|
|
209
233
|
}, (0, _metadata.METADATA)());
|
|
210
234
|
compress = false;
|
|
211
|
-
_context.next =
|
|
235
|
+
_context.next = 26;
|
|
212
236
|
return this.writeFile(layers0Path, JSON.stringify(metadata), 'metadata.json', compress);
|
|
213
237
|
|
|
214
|
-
case
|
|
238
|
+
case 26:
|
|
215
239
|
fileMap['metadata.json'] = _context.sent;
|
|
216
|
-
_context.next =
|
|
240
|
+
_context.next = 48;
|
|
217
241
|
break;
|
|
218
242
|
|
|
219
|
-
case
|
|
243
|
+
case 29:
|
|
220
244
|
_iterator2 = _createForOfIteratorHelper(this.nodePages.entries());
|
|
245
|
+
_context.prev = 30;
|
|
221
246
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
} catch (err) {
|
|
230
|
-
_iterator2.e(err);
|
|
231
|
-
} finally {
|
|
232
|
-
_iterator2.f();
|
|
247
|
+
_iterator2.s();
|
|
248
|
+
|
|
249
|
+
case 32:
|
|
250
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
251
|
+
_context.next = 40;
|
|
252
|
+
break;
|
|
233
253
|
}
|
|
234
254
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
255
|
+
_step2$value = (0, _slicedToArray2.default)(_step2.value, 2), _index = _step2$value[0], _nodePage = _step2$value[1];
|
|
256
|
+
_nodePageStr = JSON.stringify(_nodePage);
|
|
257
|
+
nodePagePath = (0, _path.join)(layers0Path, 'nodepages', _index.toString());
|
|
258
|
+
_context.next = 38;
|
|
259
|
+
return this.writeFile(nodePagePath, _nodePageStr);
|
|
238
260
|
|
|
239
|
-
case
|
|
261
|
+
case 38:
|
|
262
|
+
_context.next = 32;
|
|
263
|
+
break;
|
|
264
|
+
|
|
265
|
+
case 40:
|
|
266
|
+
_context.next = 45;
|
|
267
|
+
break;
|
|
268
|
+
|
|
269
|
+
case 42:
|
|
270
|
+
_context.prev = 42;
|
|
271
|
+
_context.t1 = _context["catch"](30);
|
|
272
|
+
|
|
273
|
+
_iterator2.e(_context.t1);
|
|
274
|
+
|
|
275
|
+
case 45:
|
|
276
|
+
_context.prev = 45;
|
|
277
|
+
|
|
278
|
+
_iterator2.f();
|
|
279
|
+
|
|
280
|
+
return _context.finish(45);
|
|
281
|
+
|
|
282
|
+
case 48:
|
|
240
283
|
case "end":
|
|
241
284
|
return _context.stop();
|
|
242
285
|
}
|
|
243
286
|
}
|
|
244
|
-
}, _callee, this);
|
|
287
|
+
}, _callee, this, [[3, 16, 19, 22], [30, 42, 45, 48]]);
|
|
245
288
|
}));
|
|
246
289
|
|
|
247
290
|
function save(_x, _x2) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/node-pages.ts"],"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","undefined","parentNode","children","push","currentNodePage","length","addChildRelation","updateResourceInMesh","layers0Path","fileMap","slpk","promises","entries","nodePage","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","compress","nodePagePath","Promise","all"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;IAoCqBA,S;AAYnB,qBAAYC,aAAZ,EAA2BC,YAA3B,EAAyC;AAAA;AAAA;AAAA;AAAA;AAAA;AACvC,SAAKA,YAAL,GAAoBA,YAApB;AACA,SAAKC,YAAL,GAAoB,CAApB;AAEA,SAAKC,SAAL,GAAiB,CAAC,EAAD,CAAjB;AACA,SAAKA,SAAL,CAAe,CAAf,EAAkBC,KAAlB,GAA0B,EAA1B;AACA,SAAKC,SAAL,GAAiBL,aAAjB;AACD;;;;WAMD,0BAAiBM,IAAjB,EAAuC;AACrC,WAAKD,SAAL,GAAiBC,IAAjB;AACD;;;WAOD,qBAAYC,EAAZ,EAAoC;AAClC,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,EAAmCK,UAAnC,EAA6D;AAC3D,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;AA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;AAAA;AAAA;AAAA;AAAA,O","sourcesContent":["import {join} from 'path';\nimport transform from 'json-map-transform';\nimport {METADATA as metadataTemplate} from '../json-templates/metadata';\nimport {NodeInPage} from '@loaders.gl/i3s';\n\n// @ts-nocheck\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 readonly nodesPerPage: number;\n nodesCounter: number;\n writeFile: Function;\n readonly nodePages: {nodes: NodeInPage[]}[];\n\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 // @ts-expect-error\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n /**\n * Setup function to save node pages\n * @param func - function which should be used to save node pages\n */\n useWriteFunction(func: Function): void {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param id - end-to-end index of the node\n * @return the node object\n */\n getNodeById(id: number): NodeInPage {\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: number, materialId: number): void {\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: number, vertexCount: number): void {\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: number): void {\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: number, featureCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n /**\n * Update texelCountHint in node.mesh.material object by node id\n * @param id - end-to-end index of the node\n * @param texelCountHint - texelCountHint of particular node\n */\n updateTexelCountHintByNodeId(id: number, texelCountHint: number): void {\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 parentId - end-to-end parent node index\n * @param childId - end-to-end child node index\n */\n addChildRelation(parentId: number | undefined, childId: number): void {\n if (parentId === null || parentId === undefined) {\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 node - node object\n */\n updateResourceInMesh(node: NodeInPage): void {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param node - node object\n * @param parentId - index of parent node\n * @return\n */\n push(node: NodeInPage, parentId?: number): number {\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 - fileMap which keep info for slpk archive\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {\n const promises: Promise<any>[] = [];\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.ts"],"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","undefined","parentNode","children","push","currentNodePage","length","addChildRelation","updateResourceInMesh","layers0Path","fileMap","slpk","entries","nodePage","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","compress","nodePagePath"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;IAoCqBA,S;AAYnB,qBAAYC,aAAZ,EAA2BC,YAA3B,EAAyC;AAAA;AAAA;AAAA;AAAA;AAAA;AACvC,SAAKA,YAAL,GAAoBA,YAApB;AACA,SAAKC,YAAL,GAAoB,CAApB;AAEA,SAAKC,SAAL,GAAiB,CAAC,EAAD,CAAjB;AACA,SAAKA,SAAL,CAAe,CAAf,EAAkBC,KAAlB,GAA0B,EAA1B;AACA,SAAKC,SAAL,GAAiBL,aAAjB;AACD;;;;WAMD,0BAAiBM,IAAjB,EAAuC;AACrC,WAAKD,SAAL,GAAiBC,IAAjB;AACD;;;WAOD,qBAAYC,EAAZ,EAAoC;AAClC,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,EAAmCK,UAAnC,EAA6D;AAC3D,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,EAAsCa,WAAtC,EAAiE;AAC/D,UAAMP,IAAI,GAAG,KAAKC,WAAL,CAAiBP,EAAjB,CAAb;;AACA,UAAI,CAACM,IAAI,CAACE,IAAV,EAAgB;AACd;AACD;;AACDF,MAAAA,IAAI,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AFuD,YAGpDrB,KAAK,CAACyB,QAAN,EAHoD,WAL/D;;AAAA;AAKMR,gBAAAA,OAAO,qBAAcjB,KAAK,CAACyB,QAAN,EAAd,cALb;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAWUC,gBAAAA,QAXV,GAWqB,+BAAU;AAACC,kBAAAA,SAAS,EAAE,KAAK5C;AAAjB,iBAAV,EAA0C,yBAA1C,CAXrB;AAYU6C,gBAAAA,QAZV,GAYqB,KAZrB;AAAA;AAAA,uBAaqC,KAAK1C,SAAL,CAC/B8B,WAD+B,EAE/BM,IAAI,CAACC,SAAL,CAAeG,QAAf,CAF+B,EAG/B,eAH+B,EAI/BE,QAJ+B,CAbrC;;AAAA;AAaIX,gBAAAA,OAAO,CAAC,eAAD,CAbX;AAAA;AAAA;;AAAA;AAAA,wDAoBoC,KAAKjC,SAAL,CAAemC,OAAf,EApBpC;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,8EAoBgBnB,MApBhB,oBAoBuBoB,SApBvB;AAqBYC,gBAAAA,YArBZ,GAqB0BC,IAAI,CAACC,SAAL,CAAeH,SAAf,CArB1B;AAsBYS,gBAAAA,YAtBZ,GAsB2B,gBAAKb,WAAL,EAAkB,WAAlB,EAA+BhB,MAAK,CAACyB,QAAN,EAA/B,CAtB3B;AAAA;AAAA,uBAuBY,KAAKvC,SAAL,CAAe2C,YAAf,EAA6BR,YAA7B,CAvBZ;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;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';\nimport {NodeInPage} from '@loaders.gl/i3s';\n\n// @ts-nocheck\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 readonly nodesPerPage: number;\n nodesCounter: number;\n writeFile: Function;\n readonly nodePages: {nodes: NodeInPage[]}[];\n\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 // @ts-expect-error\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n /**\n * Setup function to save node pages\n * @param func - function which should be used to save node pages\n */\n useWriteFunction(func: Function): void {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param id - end-to-end index of the node\n * @return the node object\n */\n getNodeById(id: number): NodeInPage {\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: number, materialId: number): void {\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: number, vertexCount: number): void {\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: number): void {\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: number, featureCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n /**\n * Update texelCountHint in node.mesh.material object by node id\n * @param id - end-to-end index of the node\n * @param texelCountHint - texelCountHint of particular node\n */\n updateTexelCountHintByNodeId(id: number, texelCountHint: number): void {\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 parentId - end-to-end parent node index\n * @param childId - end-to-end child node index\n */\n addChildRelation(parentId: number | undefined, childId: number): void {\n if (parentId === null || parentId === undefined) {\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 node - node object\n */\n updateResourceInMesh(node: NodeInPage): void {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param node - node object\n * @param parentId - index of parent node\n * @return\n */\n push(node: NodeInPage, parentId?: number): number {\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 - fileMap which keep info for slpk archive\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {\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 fileMap[`nodePages/${index.toString()}.json.gz`] = await this.writeFile(\n slpkPath,\n nodePageStr,\n `${index.toString()}.json`\n );\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 await this.writeFile(nodePagePath, nodePageStr);\n }\n }\n }\n}\n"],"file":"node-pages.js"}
|
package/dist/es5/pgm-loader.js
CHANGED
|
@@ -13,7 +13,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
13
13
|
|
|
14
14
|
var _geoid = require("@math.gl/geoid");
|
|
15
15
|
|
|
16
|
-
var VERSION = typeof "3.1.
|
|
16
|
+
var VERSION = typeof "3.1.8" !== 'undefined' ? "3.1.8" : 'latest';
|
|
17
17
|
var PGMLoader = {
|
|
18
18
|
name: 'PGM - Netpbm grayscale image format',
|
|
19
19
|
id: 'pgm',
|
|
@@ -117,14 +117,11 @@ export default class NodePages {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
async save(layers0Path, fileMap, slpk = false) {
|
|
120
|
-
const promises = [];
|
|
121
|
-
|
|
122
120
|
if (slpk) {
|
|
123
121
|
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
124
122
|
const nodePageStr = JSON.stringify(nodePage);
|
|
125
123
|
const slpkPath = join(layers0Path, 'nodepages');
|
|
126
|
-
|
|
127
|
-
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = "".concat(slpkPath, ".json.gz");
|
|
124
|
+
fileMap["nodePages/".concat(index.toString(), ".json.gz")] = await this.writeFile(slpkPath, nodePageStr, "".concat(index.toString(), ".json"));
|
|
128
125
|
}
|
|
129
126
|
|
|
130
127
|
const metadata = transform({
|
|
@@ -136,11 +133,9 @@ export default class NodePages {
|
|
|
136
133
|
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
137
134
|
const nodePageStr = JSON.stringify(nodePage);
|
|
138
135
|
const nodePagePath = join(layers0Path, 'nodepages', index.toString());
|
|
139
|
-
|
|
136
|
+
await this.writeFile(nodePagePath, nodePageStr);
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
|
-
|
|
143
|
-
await Promise.all(promises);
|
|
144
139
|
}
|
|
145
140
|
|
|
146
141
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/i3s-converter/helpers/node-pages.ts"],"names":["join","transform","METADATA","metadataTemplate","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","undefined","parentNode","children","push","updateResourceInMesh","currentNodePage","length","save","layers0Path","fileMap","slpk","promises","nodePage","entries","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","compress","nodePagePath","Promise","all"],"mappings":";AAAA,SAAQA,IAAR,QAAmB,MAAnB;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AAC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C+B,QAAN,EAAd,cAAP,aAAsDD,QAAtD;AACD;;AACD,YAAME,QAAQ,GAAG1D,SAAS,CAAC;AAAC2D,QAAAA,SAAS,EAAE,KAAKpD;AAAjB,OAAD,EAAiCL,gBAAgB,EAAjD,CAA1B;AACA,YAAM0D,QAAQ,GAAG,KAAjB;AACAZ,MAAAA,OAAO,CAAC,eAAD,CAAP,GAA2B,MAAM,KAAKtC,SAAL,CAC/BqC,WAD+B,EAE/BO,IAAI,CAACC,SAAL,CAAeG,QAAf,CAF+B,EAG/B,eAH+B,EAI/BE,QAJ+B,CAAjC;AAMD,KAfD,MAeO;AACL,WAAK,MAAM,CAAClC,KAAD,EAAQyB,QAAR,CAAX,IAAgC,KAAK3C,SAAL,CAAe4C,OAAf,EAAhC,EAA0D;AACxD,cAAMC,WAAW,GAAGC,IAAI,CAACC,SAAL,CAAeJ,QAAf,CAApB;AACA,cAAMU,YAAY,GAAG9D,IAAI,CAACgD,WAAD,EAAc,WAAd,EAA2BrB,KAAK,CAAC+B,QAAN,EAA3B,CAAzB;AACAP,QAAAA,QAAQ,CAACR,IAAT,CAAc,KAAKhC,SAAL,CAAemD,YAAf,EAA6BR,WAA7B,CAAd;AACD;AACF;;AAED,UAAMS,OAAO,CAACC,GAAR,CAAYb,QAAZ,CAAN;AACD;;AAvL4B","sourcesContent":["import {join} from 'path';\nimport transform from 'json-map-transform';\nimport {METADATA as metadataTemplate} from '../json-templates/metadata';\nimport {NodeInPage} from '@loaders.gl/i3s';\n\n// @ts-nocheck\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 readonly nodesPerPage: number;\n nodesCounter: number;\n writeFile: Function;\n readonly nodePages: {nodes: NodeInPage[]}[];\n\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 // @ts-expect-error\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n /**\n * Setup function to save node pages\n * @param func - function which should be used to save node pages\n */\n useWriteFunction(func: Function): void {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param id - end-to-end index of the node\n * @return the node object\n */\n getNodeById(id: number): NodeInPage {\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: number, materialId: number): void {\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: number, vertexCount: number): void {\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: number): void {\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: number, featureCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n /**\n * Update texelCountHint in node.mesh.material object by node id\n * @param id - end-to-end index of the node\n * @param texelCountHint - texelCountHint of particular node\n */\n updateTexelCountHintByNodeId(id: number, texelCountHint: number): void {\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 parentId - end-to-end parent node index\n * @param childId - end-to-end child node index\n */\n addChildRelation(parentId: number | undefined, childId: number): void {\n if (parentId === null || parentId === undefined) {\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 node - node object\n */\n updateResourceInMesh(node: NodeInPage): void {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param node - node object\n * @param parentId - index of parent node\n * @return\n */\n push(node: NodeInPage, parentId?: number): number {\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 - fileMap which keep info for slpk archive\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {\n const promises: Promise<any>[] = [];\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.ts"],"names":["join","transform","METADATA","metadataTemplate","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","undefined","parentNode","children","push","updateResourceInMesh","currentNodePage","length","save","layers0Path","fileMap","slpk","nodePage","entries","nodePageStr","JSON","stringify","slpkPath","toString","metadata","nodeCount","compress","nodePagePath"],"mappings":";AAAA,SAAQA,IAAR,QAAmB,MAAnB;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AACA,SAAQC,QAAQ,IAAIC,gBAApB,QAA2C,4BAA3C;AAoCA,eAAe,MAAMC,SAAN,CAAgB;AAY7BC,EAAAA,WAAW,CAACC,aAAD,EAAgBC,YAAhB,EAA8B;AAAA;;AAAA;;AAAA;;AAAA;;AACvC,SAAKA,YAA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tC,SAAL,CAC/BqC,WAD+B,EAE/BM,IAAI,CAACC,SAAL,CAAeG,QAAf,CAF+B,EAG/B,eAH+B,EAI/BE,QAJ+B,CAAjC;AAMD,KAlBD,MAkBO;AACL,WAAK,MAAM,CAACjC,KAAD,EAAQwB,QAAR,CAAX,IAAgC,KAAK1C,SAAL,CAAe2C,OAAf,EAAhC,EAA0D;AACxD,cAAMC,WAAW,GAAGC,IAAI,CAACC,SAAL,CAAeJ,QAAf,CAApB;AACA,cAAMU,YAAY,GAAG7D,IAAI,CAACgD,WAAD,EAAc,WAAd,EAA2BrB,KAAK,CAAC8B,QAAN,EAA3B,CAAzB;AACA,cAAM,KAAK9C,SAAL,CAAekD,YAAf,EAA6BR,WAA7B,CAAN;AACD;AACF;AACF;;AAvL4B","sourcesContent":["import {join} from 'path';\nimport transform from 'json-map-transform';\nimport {METADATA as metadataTemplate} from '../json-templates/metadata';\nimport {NodeInPage} from '@loaders.gl/i3s';\n\n// @ts-nocheck\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 readonly nodesPerPage: number;\n nodesCounter: number;\n writeFile: Function;\n readonly nodePages: {nodes: NodeInPage[]}[];\n\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 // @ts-expect-error\n this.nodePages = [{}];\n this.nodePages[0].nodes = [];\n this.writeFile = writeFileFunc;\n }\n\n /**\n * Setup function to save node pages\n * @param func - function which should be used to save node pages\n */\n useWriteFunction(func: Function): void {\n this.writeFile = func;\n }\n\n /**\n * Get the node by its end-to-end index\n * @param id - end-to-end index of the node\n * @return the node object\n */\n getNodeById(id: number): NodeInPage {\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: number, materialId: number): void {\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: number, vertexCount: number): void {\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: number): void {\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: number, featureCount: number): void {\n const node = this.getNodeById(id);\n if (!node.mesh) {\n return;\n }\n node.mesh.geometry.featureCount = featureCount;\n }\n\n /**\n * Update texelCountHint in node.mesh.material object by node id\n * @param id - end-to-end index of the node\n * @param texelCountHint - texelCountHint of particular node\n */\n updateTexelCountHintByNodeId(id: number, texelCountHint: number): void {\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 parentId - end-to-end parent node index\n * @param childId - end-to-end child node index\n */\n addChildRelation(parentId: number | undefined, childId: number): void {\n if (parentId === null || parentId === undefined) {\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 node - node object\n */\n updateResourceInMesh(node: NodeInPage): void {\n if (node.mesh) {\n node.mesh.geometry.resource = node.index;\n }\n }\n\n /**\n * Put new node in nodePages array\n * @param node - node object\n * @param parentId - index of parent node\n * @return\n */\n push(node: NodeInPage, parentId?: number): number {\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 - fileMap which keep info for slpk archive\n * @param {boolean} slpk\n * @return {promise}\n */\n async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {\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 fileMap[`nodePages/${index.toString()}.json.gz`] = await this.writeFile(\n slpkPath,\n nodePageStr,\n `${index.toString()}.json`\n );\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 await this.writeFile(nodePagePath, nodePageStr);\n }\n }\n }\n}\n"],"file":"node-pages.js"}
|
package/dist/esm/pgm-loader.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/tile-converter",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.8",
|
|
4
4
|
"description": "Converter",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"build-bin": "BABEL_ENV=es5 babel scripts --config-file ../../babel.config.js --out-dir dist/scripts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@loaders.gl/3d-tiles": "3.1.
|
|
44
|
-
"@loaders.gl/crypto": "3.1.
|
|
45
|
-
"@loaders.gl/draco": "3.1.
|
|
46
|
-
"@loaders.gl/gltf": "3.1.
|
|
47
|
-
"@loaders.gl/i3s": "3.1.
|
|
48
|
-
"@loaders.gl/images": "3.1.
|
|
49
|
-
"@loaders.gl/loader-utils": "3.1.
|
|
50
|
-
"@loaders.gl/polyfills": "3.1.
|
|
51
|
-
"@loaders.gl/textures": "3.1.
|
|
52
|
-
"@loaders.gl/tiles": "3.1.
|
|
53
|
-
"@loaders.gl/worker-utils": "3.1.
|
|
54
|
-
"@loaders.gl/zip": "3.1.
|
|
43
|
+
"@loaders.gl/3d-tiles": "3.1.8",
|
|
44
|
+
"@loaders.gl/crypto": "3.1.8",
|
|
45
|
+
"@loaders.gl/draco": "3.1.8",
|
|
46
|
+
"@loaders.gl/gltf": "3.1.8",
|
|
47
|
+
"@loaders.gl/i3s": "3.1.8",
|
|
48
|
+
"@loaders.gl/images": "3.1.8",
|
|
49
|
+
"@loaders.gl/loader-utils": "3.1.8",
|
|
50
|
+
"@loaders.gl/polyfills": "3.1.8",
|
|
51
|
+
"@loaders.gl/textures": "3.1.8",
|
|
52
|
+
"@loaders.gl/tiles": "3.1.8",
|
|
53
|
+
"@loaders.gl/worker-utils": "3.1.8",
|
|
54
|
+
"@loaders.gl/zip": "3.1.8",
|
|
55
55
|
"@luma.gl/engine": "^8.5.4",
|
|
56
56
|
"@math.gl/core": "^3.5.1",
|
|
57
57
|
"@math.gl/culling": "^3.5.1",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@loaders.gl/core": "^3.1.0"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "0ef07b4e9fc20f5a882224cf241c6fd1bad898d8"
|
|
75
75
|
}
|
|
@@ -194,13 +194,15 @@ export default class NodePages {
|
|
|
194
194
|
* @return {promise}
|
|
195
195
|
*/
|
|
196
196
|
async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {
|
|
197
|
-
const promises: Promise<any>[] = [];
|
|
198
197
|
if (slpk) {
|
|
199
198
|
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
200
199
|
const nodePageStr = JSON.stringify(nodePage);
|
|
201
200
|
const slpkPath = join(layers0Path, 'nodepages');
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
fileMap[`nodePages/${index.toString()}.json.gz`] = await this.writeFile(
|
|
202
|
+
slpkPath,
|
|
203
|
+
nodePageStr,
|
|
204
|
+
`${index.toString()}.json`
|
|
205
|
+
);
|
|
204
206
|
}
|
|
205
207
|
const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate());
|
|
206
208
|
const compress = false;
|
|
@@ -214,10 +216,8 @@ export default class NodePages {
|
|
|
214
216
|
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
215
217
|
const nodePageStr = JSON.stringify(nodePage);
|
|
216
218
|
const nodePagePath = join(layers0Path, 'nodepages', index.toString());
|
|
217
|
-
|
|
219
|
+
await this.writeFile(nodePagePath, nodePageStr);
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
|
-
|
|
221
|
-
await Promise.all(promises);
|
|
222
222
|
}
|
|
223
223
|
}
|