@loaders.gl/tile-converter 3.1.8 → 3.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +78 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.js +242 -0
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +83 -0
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +278 -0
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +13 -0
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +23 -0
- package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
- package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +52 -0
- package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
- package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
- package/dist/3d-tiles-converter/json-templates/tileset.js +43 -0
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +5 -0
- package/dist/converter.min.js +19 -19
- package/dist/deps-installer/deps-installer.d.ts +4 -0
- package/dist/deps-installer/deps-installer.d.ts.map +1 -0
- package/dist/deps-installer/deps-installer.js +21 -0
- package/dist/dist.min.js +304 -494
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +2 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +14 -21
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +35 -25
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +2 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +7 -5
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +10 -0
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
- package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/coordinate-converter.js +118 -0
- package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
- package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/create-scene-server-path.js +28 -0
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts +8 -0
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/geometry-attributes.js +176 -0
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +12 -0
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/geometry-converter.js +791 -0
- package/dist/i3s-converter/helpers/node-debug.d.ts +8 -0
- package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-debug.js +114 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts +116 -0
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
- package/dist/i3s-converter/helpers/node-pages.js +203 -0
- package/dist/i3s-converter/i3s-converter.d.ts +321 -0
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
- package/dist/i3s-converter/i3s-converter.js +994 -0
- package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
- package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/layers.js +199 -0
- package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
- package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/metadata.js +25 -0
- package/dist/i3s-converter/json-templates/node.d.ts +61 -0
- package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/node.js +89 -0
- package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
- package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/scene-server.js +31 -0
- package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
- package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/shared-resources.js +129 -0
- package/dist/i3s-converter/json-templates/store.d.ts +95 -0
- package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
- package/dist/i3s-converter/json-templates/store.js +103 -0
- package/dist/i3s-converter/types.d.ts +39 -0
- package/dist/i3s-converter/types.d.ts.map +1 -0
- package/dist/i3s-converter/types.js +2 -0
- package/dist/i3s-server/app.d.ts +3 -0
- package/dist/i3s-server/app.d.ts.map +1 -0
- package/dist/i3s-server/app.js +14 -0
- package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
- package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
- package/dist/i3s-server/controllers/index-controller.js +23 -0
- package/dist/i3s-server/routes/index.d.ts +3 -0
- package/dist/i3s-server/routes/index.d.ts.map +1 -0
- package/dist/i3s-server/routes/index.js +16 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/lib/utils/compress-util.d.ts +6 -0
- package/dist/lib/utils/compress-util.d.ts.map +1 -0
- package/dist/lib/utils/compress-util.js +190 -0
- package/dist/lib/utils/file-utils.d.ts +6 -0
- package/dist/lib/utils/file-utils.d.ts.map +1 -0
- package/dist/lib/utils/file-utils.js +42 -0
- package/dist/lib/utils/lod-conversion-utils.d.ts +20 -0
- package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
- package/dist/lib/utils/lod-conversion-utils.js +57 -0
- package/dist/lib/utils/statistic-utills.d.ts +3 -0
- package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
- package/dist/lib/utils/statistic-utills.js +64 -0
- package/dist/pgm-loader.d.ts +6 -0
- package/dist/pgm-loader.d.ts.map +1 -0
- package/dist/pgm-loader.js +23 -0
- package/package.json +16 -17
- package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -1
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +6 -5
- package/src/i3s-converter/i3s-converter.ts +12 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Node3DIndexDocument } from '@loaders.gl/i3s';
|
|
2
|
+
/**
|
|
3
|
+
* Do validation of bounding volumes for particular node.
|
|
4
|
+
* Generates special warnings if there are some issues.
|
|
5
|
+
* @param node
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateNodeBoundingVolumes(node: Node3DIndexDocument): string[];
|
|
8
|
+
//# sourceMappingURL=node-debug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-debug.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/node-debug.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAM,mBAAmB,EAAM,MAAM,iBAAiB,CAAC;AASnE;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,EAAE,CAW/E"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateNodeBoundingVolumes = void 0;
|
|
4
|
+
const culling_1 = require("@math.gl/culling");
|
|
5
|
+
const engine_1 = require("@luma.gl/engine");
|
|
6
|
+
const core_1 = require("@math.gl/core");
|
|
7
|
+
const geospatial_1 = require("@math.gl/geospatial");
|
|
8
|
+
// TODO Unite Tile validation logic in i3s-17-and-debug with this code.
|
|
9
|
+
/**
|
|
10
|
+
* Do validation of bounding volumes for particular node.
|
|
11
|
+
* Generates special warnings if there are some issues.
|
|
12
|
+
* @param node
|
|
13
|
+
*/
|
|
14
|
+
function validateNodeBoundingVolumes(node) {
|
|
15
|
+
if (!node?.parentNode?.obb || !node?.parentNode?.mbs) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const tileWarnings = [];
|
|
19
|
+
validateObb(tileWarnings, node);
|
|
20
|
+
validateMbs(tileWarnings, node);
|
|
21
|
+
return tileWarnings;
|
|
22
|
+
}
|
|
23
|
+
exports.validateNodeBoundingVolumes = validateNodeBoundingVolumes;
|
|
24
|
+
/**
|
|
25
|
+
* Check if child Obb fit into parent Obb.
|
|
26
|
+
* @param tileWarnings
|
|
27
|
+
* @param node
|
|
28
|
+
*/
|
|
29
|
+
function validateObb(tileWarnings, node) {
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);
|
|
32
|
+
const tileVertices = getTileObbVertices(node);
|
|
33
|
+
const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);
|
|
34
|
+
if (isTileObbInsideParentObb) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode?.id}) tile OBB`;
|
|
38
|
+
tileWarnings.push(title);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if child Mbs fit into parent Mbs.
|
|
42
|
+
* @param tileWarnings
|
|
43
|
+
* @param node
|
|
44
|
+
*/
|
|
45
|
+
function validateMbs(tileWarnings, node) {
|
|
46
|
+
// @ts-expect-error
|
|
47
|
+
const tileMbs = createBoundingSphereFromTileMbs(node.mbs);
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);
|
|
50
|
+
const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);
|
|
51
|
+
if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {
|
|
52
|
+
const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode?.id}) tile MBS`;
|
|
53
|
+
tileWarnings.push(title);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generates bounding sphere from mbs
|
|
58
|
+
* @param mbs
|
|
59
|
+
*/
|
|
60
|
+
function createBoundingSphereFromTileMbs(mbs) {
|
|
61
|
+
return new culling_1.BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Generates oriented bounding box from tile obb
|
|
65
|
+
* @param obb
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
function createBoundingBoxFromTileObb(obb) {
|
|
69
|
+
const { center, halfSize, quaternion } = obb;
|
|
70
|
+
return new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get vertices fromnode obb
|
|
74
|
+
* TODO check if Obb generates properly
|
|
75
|
+
* @param node
|
|
76
|
+
*/
|
|
77
|
+
function getTileObbVertices(node) {
|
|
78
|
+
const geometry = new engine_1.CubeGeometry();
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
const halfSize = node.obb.halfSize;
|
|
81
|
+
const attributes = geometry.getAttributes();
|
|
82
|
+
const positions = new Float32Array(attributes.POSITION.value);
|
|
83
|
+
// @ts-expect-error
|
|
84
|
+
const obbCenterCartesian = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);
|
|
85
|
+
let vertices = [];
|
|
86
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
87
|
+
const positionsVector = new core_1.Vector3((positions[i] *= halfSize[0]), (positions[i + 1] *= halfSize[1]), (positions[i + 2] *= halfSize[2]));
|
|
88
|
+
const rotatedPositions = positionsVector
|
|
89
|
+
// @ts-expect-error
|
|
90
|
+
.transformByQuaternion(node.obb.quaternion)
|
|
91
|
+
.add(obbCenterCartesian);
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
vertices = vertices.concat(rotatedPositions);
|
|
94
|
+
}
|
|
95
|
+
return vertices;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if all vertices inside bounding volume
|
|
99
|
+
* @param boundingVolume
|
|
100
|
+
* @param positions
|
|
101
|
+
*/
|
|
102
|
+
function isAllVerticesInsideBoundingVolume(boundingVolume, positions) {
|
|
103
|
+
let isVerticesInsideObb = true;
|
|
104
|
+
for (let index = 0; index < positions.length / 3; index += 3) {
|
|
105
|
+
const point = [positions[index], positions[index + 1], positions[index + 2]];
|
|
106
|
+
const cartographicPoint = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(point);
|
|
107
|
+
const distance = boundingVolume.distanceTo(cartographicPoint);
|
|
108
|
+
if (distance > 0) {
|
|
109
|
+
isVerticesInsideObb = false;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return isVerticesInsideObb;
|
|
114
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { NodeInPage } from '@loaders.gl/i3s';
|
|
2
|
+
/**
|
|
3
|
+
* class NodePages - wrapper of nodePages array
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import {writeFile} from './helpers/write-file';
|
|
7
|
+
*
|
|
8
|
+
* // create an instance of the class
|
|
9
|
+
* const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);
|
|
10
|
+
* ...
|
|
11
|
+
* // push root node
|
|
12
|
+
* const parentId = nodePages.push({
|
|
13
|
+
lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,
|
|
14
|
+
obb: coordinates.obb,
|
|
15
|
+
children: []
|
|
16
|
+
});
|
|
17
|
+
* ...
|
|
18
|
+
* // push node with parent relation
|
|
19
|
+
* const nodeInPage = {
|
|
20
|
+
lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,
|
|
21
|
+
obb: coordinates.obb,
|
|
22
|
+
children: [],
|
|
23
|
+
mesh: {
|
|
24
|
+
geometry: {
|
|
25
|
+
definition: 0
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
* const nodeId = this.nodePages.push(nodeInPage, parentId);
|
|
30
|
+
* ...
|
|
31
|
+
* // save all the nodePages in the end of pushing all the nodes
|
|
32
|
+
* await this.nodePages.save(layers0path);
|
|
33
|
+
*/
|
|
34
|
+
export default class NodePages {
|
|
35
|
+
readonly nodesPerPage: number;
|
|
36
|
+
nodesCounter: number;
|
|
37
|
+
writeFile: Function;
|
|
38
|
+
readonly nodePages: {
|
|
39
|
+
nodes: NodeInPage[];
|
|
40
|
+
}[];
|
|
41
|
+
/**
|
|
42
|
+
* @constructs
|
|
43
|
+
* Create a nodePages instance.
|
|
44
|
+
* @param writeFileFunc - function to save one nodePage into a file
|
|
45
|
+
* @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met
|
|
46
|
+
*/
|
|
47
|
+
constructor(writeFileFunc: any, nodesPerPage: any);
|
|
48
|
+
/**
|
|
49
|
+
* Setup function to save node pages
|
|
50
|
+
* @param func - function which should be used to save node pages
|
|
51
|
+
*/
|
|
52
|
+
useWriteFunction(func: Function): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get the node by its end-to-end index
|
|
55
|
+
* @param id - end-to-end index of the node
|
|
56
|
+
* @return the node object
|
|
57
|
+
*/
|
|
58
|
+
getNodeById(id: number): NodeInPage;
|
|
59
|
+
/**
|
|
60
|
+
* Update material in node.mesh object by node id
|
|
61
|
+
* @param id - end-to-end index of the node
|
|
62
|
+
* @param materialId - id from scene layer materialDefinitions
|
|
63
|
+
*/
|
|
64
|
+
updateMaterialByNodeId(id: number, materialId: number): void;
|
|
65
|
+
/**
|
|
66
|
+
* Update vertexCount in node.mesh.geometry object by node id
|
|
67
|
+
* @param id - end-to-end index of the node
|
|
68
|
+
* @param vertexCount - vertex count for particular node
|
|
69
|
+
*/
|
|
70
|
+
updateVertexCountByNodeId(id: number, vertexCount: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Update resource in node.mesh.attribute object by node id
|
|
73
|
+
* @param id - end-to-end index of the node
|
|
74
|
+
*/
|
|
75
|
+
updateNodeAttributeByNodeId(id: number): void;
|
|
76
|
+
/**
|
|
77
|
+
* Update featureCount in node.mesh.geometry object by node id
|
|
78
|
+
* @param id - end-to-end index of the node
|
|
79
|
+
* @param featureCount - features count of the node
|
|
80
|
+
*/
|
|
81
|
+
updateFeatureCountByNodeId(id: number, featureCount: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* Update texelCountHint in node.mesh.material object by node id
|
|
84
|
+
* @param id - end-to-end index of the node
|
|
85
|
+
* @param texelCountHint - texelCountHint of particular node
|
|
86
|
+
*/
|
|
87
|
+
updateTexelCountHintByNodeId(id: number, texelCountHint: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* Add a child id into the parent node.children array
|
|
90
|
+
* @param parentId - end-to-end parent node index
|
|
91
|
+
* @param childId - end-to-end child node index
|
|
92
|
+
*/
|
|
93
|
+
addChildRelation(parentId: number | undefined, childId: number): void;
|
|
94
|
+
/**
|
|
95
|
+
* Update resource index in node.mesh object
|
|
96
|
+
* @param node - node object
|
|
97
|
+
*/
|
|
98
|
+
updateResourceInMesh(node: NodeInPage): void;
|
|
99
|
+
/**
|
|
100
|
+
* Put new node in nodePages array
|
|
101
|
+
* @param node - node object
|
|
102
|
+
* @param parentId - index of parent node
|
|
103
|
+
* @return
|
|
104
|
+
*/
|
|
105
|
+
push(node: NodeInPage, parentId?: number): number;
|
|
106
|
+
/**
|
|
107
|
+
* Save all the node pages
|
|
108
|
+
* Run this method when all nodes is pushed in nodePages
|
|
109
|
+
* @param {string} layers0Path - path of layer
|
|
110
|
+
* @param {Object} fileMap - fileMap which keep info for slpk archive
|
|
111
|
+
* @param {boolean} slpk
|
|
112
|
+
* @return {promise}
|
|
113
|
+
*/
|
|
114
|
+
save(layers0Path: string, fileMap: Object, slpk?: boolean): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=node-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-pages.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/node-pages.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE;QAAC,KAAK,EAAE,UAAU,EAAE,CAAA;KAAC,EAAE,CAAC;IAE5C;;;;;OAKG;gBACS,aAAa,KAAA,EAAE,YAAY,KAAA;IASvC;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAItC;;;;OAIG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU;IAMnC;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAW5D;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAQhE;;;OAGG;IACH,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAQ7C;;;;OAIG;IACH,0BAA0B,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAQlE;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI;IAQtE;;;;OAIG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAQrE;;;OAGG;IACH,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAM5C;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAajD;;;;;;;OAOG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BvF"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const json_map_transform_1 = __importDefault(require("json-map-transform"));
|
|
8
|
+
const metadata_1 = require("../json-templates/metadata");
|
|
9
|
+
// @ts-nocheck
|
|
10
|
+
/**
|
|
11
|
+
* class NodePages - wrapper of nodePages array
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import {writeFile} from './helpers/write-file';
|
|
15
|
+
*
|
|
16
|
+
* // create an instance of the class
|
|
17
|
+
* const nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE);
|
|
18
|
+
* ...
|
|
19
|
+
* // push root node
|
|
20
|
+
* const parentId = nodePages.push({
|
|
21
|
+
lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,
|
|
22
|
+
obb: coordinates.obb,
|
|
23
|
+
children: []
|
|
24
|
+
});
|
|
25
|
+
* ...
|
|
26
|
+
* // push node with parent relation
|
|
27
|
+
* const nodeInPage = {
|
|
28
|
+
lodThreshold: HARDCODED_MAX_SCREEN_THRESHOLD_SQ,
|
|
29
|
+
obb: coordinates.obb,
|
|
30
|
+
children: [],
|
|
31
|
+
mesh: {
|
|
32
|
+
geometry: {
|
|
33
|
+
definition: 0
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
* const nodeId = this.nodePages.push(nodeInPage, parentId);
|
|
38
|
+
* ...
|
|
39
|
+
* // save all the nodePages in the end of pushing all the nodes
|
|
40
|
+
* await this.nodePages.save(layers0path);
|
|
41
|
+
*/
|
|
42
|
+
class NodePages {
|
|
43
|
+
/**
|
|
44
|
+
* @constructs
|
|
45
|
+
* Create a nodePages instance.
|
|
46
|
+
* @param writeFileFunc - function to save one nodePage into a file
|
|
47
|
+
* @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met
|
|
48
|
+
*/
|
|
49
|
+
constructor(writeFileFunc, nodesPerPage) {
|
|
50
|
+
this.nodesPerPage = nodesPerPage;
|
|
51
|
+
this.nodesCounter = 0;
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
this.nodePages = [{}];
|
|
54
|
+
this.nodePages[0].nodes = [];
|
|
55
|
+
this.writeFile = writeFileFunc;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Setup function to save node pages
|
|
59
|
+
* @param func - function which should be used to save node pages
|
|
60
|
+
*/
|
|
61
|
+
useWriteFunction(func) {
|
|
62
|
+
this.writeFile = func;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the node by its end-to-end index
|
|
66
|
+
* @param id - end-to-end index of the node
|
|
67
|
+
* @return the node object
|
|
68
|
+
*/
|
|
69
|
+
getNodeById(id) {
|
|
70
|
+
const pageIndex = Math.floor(id / this.nodesPerPage);
|
|
71
|
+
const nodeIndex = id % this.nodesPerPage;
|
|
72
|
+
return this.nodePages[pageIndex].nodes[nodeIndex];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Update material in node.mesh object by node id
|
|
76
|
+
* @param id - end-to-end index of the node
|
|
77
|
+
* @param materialId - id from scene layer materialDefinitions
|
|
78
|
+
*/
|
|
79
|
+
updateMaterialByNodeId(id, materialId) {
|
|
80
|
+
const node = this.getNodeById(id);
|
|
81
|
+
if (!node.mesh) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
node.mesh.material = {
|
|
85
|
+
definition: materialId,
|
|
86
|
+
resource: node.index
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Update vertexCount in node.mesh.geometry object by node id
|
|
91
|
+
* @param id - end-to-end index of the node
|
|
92
|
+
* @param vertexCount - vertex count for particular node
|
|
93
|
+
*/
|
|
94
|
+
updateVertexCountByNodeId(id, vertexCount) {
|
|
95
|
+
const node = this.getNodeById(id);
|
|
96
|
+
if (!node.mesh) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
node.mesh.geometry.vertexCount = vertexCount;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Update resource in node.mesh.attribute object by node id
|
|
103
|
+
* @param id - end-to-end index of the node
|
|
104
|
+
*/
|
|
105
|
+
updateNodeAttributeByNodeId(id) {
|
|
106
|
+
const node = this.getNodeById(id);
|
|
107
|
+
if (!node.mesh) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
node.mesh.attribute.resource = node.index;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Update featureCount in node.mesh.geometry object by node id
|
|
114
|
+
* @param id - end-to-end index of the node
|
|
115
|
+
* @param featureCount - features count of the node
|
|
116
|
+
*/
|
|
117
|
+
updateFeatureCountByNodeId(id, featureCount) {
|
|
118
|
+
const node = this.getNodeById(id);
|
|
119
|
+
if (!node.mesh) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
node.mesh.geometry.featureCount = featureCount;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Update texelCountHint in node.mesh.material object by node id
|
|
126
|
+
* @param id - end-to-end index of the node
|
|
127
|
+
* @param texelCountHint - texelCountHint of particular node
|
|
128
|
+
*/
|
|
129
|
+
updateTexelCountHintByNodeId(id, texelCountHint) {
|
|
130
|
+
const node = this.getNodeById(id);
|
|
131
|
+
if (!node.mesh || !node.mesh.material) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
node.mesh.material.texelCountHint = texelCountHint;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Add a child id into the parent node.children array
|
|
138
|
+
* @param parentId - end-to-end parent node index
|
|
139
|
+
* @param childId - end-to-end child node index
|
|
140
|
+
*/
|
|
141
|
+
addChildRelation(parentId, childId) {
|
|
142
|
+
if (parentId === null || parentId === undefined) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const parentNode = this.getNodeById(parentId);
|
|
146
|
+
parentNode.children?.push(childId);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Update resource index in node.mesh object
|
|
150
|
+
* @param node - node object
|
|
151
|
+
*/
|
|
152
|
+
updateResourceInMesh(node) {
|
|
153
|
+
if (node.mesh) {
|
|
154
|
+
node.mesh.geometry.resource = node.index;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Put new node in nodePages array
|
|
159
|
+
* @param node - node object
|
|
160
|
+
* @param parentId - index of parent node
|
|
161
|
+
* @return
|
|
162
|
+
*/
|
|
163
|
+
push(node, parentId) {
|
|
164
|
+
let currentNodePage = this.nodePages[this.nodePages.length - 1];
|
|
165
|
+
if (currentNodePage.nodes.length === this.nodesPerPage) {
|
|
166
|
+
currentNodePage = { nodes: [] };
|
|
167
|
+
this.nodePages.push(currentNodePage);
|
|
168
|
+
}
|
|
169
|
+
node.index = this.nodesCounter++;
|
|
170
|
+
currentNodePage.nodes.push(node);
|
|
171
|
+
this.addChildRelation(parentId, node.index);
|
|
172
|
+
this.updateResourceInMesh(node);
|
|
173
|
+
return node.index;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Save all the node pages
|
|
177
|
+
* Run this method when all nodes is pushed in nodePages
|
|
178
|
+
* @param {string} layers0Path - path of layer
|
|
179
|
+
* @param {Object} fileMap - fileMap which keep info for slpk archive
|
|
180
|
+
* @param {boolean} slpk
|
|
181
|
+
* @return {promise}
|
|
182
|
+
*/
|
|
183
|
+
async save(layers0Path, fileMap, slpk = false) {
|
|
184
|
+
if (slpk) {
|
|
185
|
+
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
186
|
+
const nodePageStr = JSON.stringify(nodePage);
|
|
187
|
+
const slpkPath = (0, path_1.join)(layers0Path, 'nodepages');
|
|
188
|
+
fileMap[`nodePages/${index.toString()}.json.gz`] = await this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`);
|
|
189
|
+
}
|
|
190
|
+
const metadata = (0, json_map_transform_1.default)({ nodeCount: this.nodesCounter }, (0, metadata_1.METADATA)());
|
|
191
|
+
const compress = false;
|
|
192
|
+
fileMap['metadata.json'] = await this.writeFile(layers0Path, JSON.stringify(metadata), 'metadata.json', compress);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
for (const [index, nodePage] of this.nodePages.entries()) {
|
|
196
|
+
const nodePageStr = JSON.stringify(nodePage);
|
|
197
|
+
const nodePagePath = (0, path_1.join)(layers0Path, 'nodepages', index.toString());
|
|
198
|
+
await this.writeFile(nodePagePath, nodePageStr);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.default = NodePages;
|