@loaders.gl/tile-converter 3.4.10 → 3.4.12

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.
Files changed (53) hide show
  1. package/dist/3d-tiles-attributes-worker.js +1 -1
  2. package/dist/converter.min.js +58 -58
  3. package/dist/dist.min.js +12 -27
  4. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  5. package/dist/es5/deps-installer/deps-installer.js +1 -1
  6. package/dist/es5/i3s-attributes-worker.js +1 -1
  7. package/dist/es5/pgm-loader.js +1 -1
  8. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  9. package/dist/esm/deps-installer/deps-installer.js +1 -1
  10. package/dist/esm/i3s-attributes-worker.js +1 -1
  11. package/dist/esm/pgm-loader.js +1 -1
  12. package/package.json +15 -15
  13. package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -287
  14. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -282
  15. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
  16. package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -52
  17. package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
  18. package/dist/bundle.js +0 -5
  19. package/dist/constants.js +0 -4
  20. package/dist/converter-cli.js +0 -280
  21. package/dist/deps-installer/deps-installer.js +0 -63
  22. package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -141
  23. package/dist/i3s-converter/helpers/coordinate-converter.js +0 -124
  24. package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
  25. package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
  26. package/dist/i3s-converter/helpers/geometry-attributes.js +0 -202
  27. package/dist/i3s-converter/helpers/geometry-converter.js +0 -1195
  28. package/dist/i3s-converter/helpers/gltf-attributes.js +0 -88
  29. package/dist/i3s-converter/helpers/node-debug.js +0 -120
  30. package/dist/i3s-converter/helpers/node-index-document.js +0 -250
  31. package/dist/i3s-converter/helpers/node-pages.js +0 -316
  32. package/dist/i3s-converter/i3s-converter.js +0 -890
  33. package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
  34. package/dist/i3s-converter/json-templates/layers.js +0 -139
  35. package/dist/i3s-converter/json-templates/metadata.js +0 -25
  36. package/dist/i3s-converter/json-templates/node.js +0 -89
  37. package/dist/i3s-converter/json-templates/scene-server.js +0 -31
  38. package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
  39. package/dist/i3s-converter/json-templates/store.js +0 -103
  40. package/dist/i3s-converter/types.js +0 -2
  41. package/dist/i3s-server/app.js +0 -14
  42. package/dist/i3s-server/controllers/index-controller.js +0 -23
  43. package/dist/i3s-server/routes/index.js +0 -16
  44. package/dist/index.js +0 -10
  45. package/dist/lib/utils/compress-util.js +0 -257
  46. package/dist/lib/utils/file-utils.js +0 -138
  47. package/dist/lib/utils/lod-conversion-utils.js +0 -76
  48. package/dist/lib/utils/queue.js +0 -18
  49. package/dist/lib/utils/statistic-utills.js +0 -64
  50. package/dist/lib/utils/write-queue.js +0 -80
  51. package/dist/pgm-loader.js +0 -24
  52. package/dist/workers/3d-tiles-attributes-worker.js +0 -9
  53. package/dist/workers/i3s-attributes-worker.js +0 -5
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareDataForAttributesConversion = void 0;
4
- /**
5
- * Keep only values for B3DM attributes to pass data to worker thread.
6
- * @param attributes
7
- */
8
- function getB3DMAttributesWithoutBufferView(attributes) {
9
- const attributesWithoutBufferView = {};
10
- for (const attributeName in attributes) {
11
- attributesWithoutBufferView[attributeName] = {
12
- value: attributes[attributeName].value
13
- };
14
- }
15
- return attributesWithoutBufferView;
16
- }
17
- /**
18
- * Prepare attributes for conversion to avoid binary data breaking in worker thread.
19
- * @param tileContent
20
- * @returns
21
- */
22
- function prepareDataForAttributesConversion(tileContent) {
23
- let nodes = tileContent.gltf?.scene?.nodes ||
24
- tileContent.gltf?.scenes?.[0]?.nodes ||
25
- tileContent.gltf?.nodes ||
26
- [];
27
- const images = tileContent.gltf?.images?.map((imageObject) => {
28
- // Need data only for uncompressed images because we can't get batchIds from compressed textures.
29
- if (imageObject?.image?.compressed) {
30
- return {
31
- data: null,
32
- compressed: true
33
- };
34
- }
35
- else {
36
- const data = imageObject?.image?.data;
37
- const dataCopy = new Uint8Array(data.length);
38
- dataCopy.set(data);
39
- return {
40
- data: dataCopy,
41
- compressed: false,
42
- height: imageObject.image.height,
43
- width: imageObject.image.width,
44
- components: imageObject.image.components,
45
- mimeType: imageObject.mimeType
46
- };
47
- }
48
- }) || [];
49
- prepareNodes(nodes);
50
- const cartographicOrigin = tileContent.cartographicOrigin;
51
- const cartesianModelMatrix = tileContent.cartesianModelMatrix;
52
- return {
53
- nodes,
54
- images,
55
- cartographicOrigin,
56
- cartesianModelMatrix
57
- };
58
- }
59
- exports.prepareDataForAttributesConversion = prepareDataForAttributesConversion;
60
- /**
61
- * Traverse all nodes to replace all sensible data with copy to avoid data corruption in worker.
62
- * @param nodes
63
- */
64
- function prepareNodes(nodes) {
65
- for (let index = 0; index < nodes.length; index++) {
66
- const node = nodes[index];
67
- if (node.mesh) {
68
- nodes[index] = {
69
- ...node,
70
- mesh: {
71
- ...node.mesh,
72
- primitives: node.mesh?.primitives.map((primitive) => ({
73
- ...primitive,
74
- indices: { value: primitive?.indices?.value },
75
- attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),
76
- material: {
77
- id: primitive?.material?.id,
78
- uniqueId: primitive?.material?.uniqueId
79
- }
80
- }))
81
- }
82
- };
83
- }
84
- if (node.children) {
85
- prepareNodes(node.children);
86
- }
87
- }
88
- }
@@ -1,120 +0,0 @@
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 core_1 = require("@math.gl/core");
6
- const geospatial_1 = require("@math.gl/geospatial");
7
- // prettier-ignore
8
- const CUBE_POSITIONS = new Float32Array([
9
- -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1,
10
- -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1,
11
- -1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1,
12
- -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1,
13
- 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1,
14
- -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1
15
- ]);
16
- // TODO Unite Tile validation logic in i3s-17-and-debug with this code.
17
- /**
18
- * Do validation of bounding volumes for particular node.
19
- * Generates special warnings if there are some issues.
20
- * @param node
21
- */
22
- function validateNodeBoundingVolumes(node) {
23
- if (!node?.parentNode?.obb || !node?.parentNode?.mbs) {
24
- return [];
25
- }
26
- const tileWarnings = [];
27
- validateObb(tileWarnings, node);
28
- validateMbs(tileWarnings, node);
29
- return tileWarnings;
30
- }
31
- exports.validateNodeBoundingVolumes = validateNodeBoundingVolumes;
32
- /**
33
- * Check if child Obb fit into parent Obb.
34
- * @param tileWarnings
35
- * @param node
36
- */
37
- function validateObb(tileWarnings, node) {
38
- // @ts-expect-error
39
- const parentObb = createBoundingBoxFromTileObb(node.parentNode.obb);
40
- const tileVertices = getTileObbVertices(node);
41
- const isTileObbInsideParentObb = isAllVerticesInsideBoundingVolume(parentObb, tileVertices);
42
- if (isTileObbInsideParentObb) {
43
- return;
44
- }
45
- const title = `OBB of Tile (${node.id}) doesn't fit into Parent (${node.parentNode?.id}) tile OBB`;
46
- tileWarnings.push(title);
47
- }
48
- /**
49
- * Check if child Mbs fit into parent Mbs.
50
- * @param tileWarnings
51
- * @param node
52
- */
53
- function validateMbs(tileWarnings, node) {
54
- // @ts-expect-error
55
- const tileMbs = createBoundingSphereFromTileMbs(node.mbs);
56
- // @ts-expect-error
57
- const parentMbs = createBoundingSphereFromTileMbs(node.parentNode.mbs);
58
- const distanceBetweenCenters = tileMbs.center.distanceTo(parentMbs.center);
59
- if (distanceBetweenCenters + tileMbs.radius > parentMbs.radius) {
60
- const title = `MBS of Tile (${node.id}) doesn't fit into Parent (${node.parentNode?.id}) tile MBS`;
61
- tileWarnings.push(title);
62
- }
63
- }
64
- /**
65
- * Generates bounding sphere from mbs
66
- * @param mbs
67
- */
68
- function createBoundingSphereFromTileMbs(mbs) {
69
- return new culling_1.BoundingSphere([mbs[0], mbs[1], mbs[2]], mbs[3]);
70
- }
71
- /**
72
- * Generates oriented bounding box from tile obb
73
- * @param obb
74
- * @returns
75
- */
76
- function createBoundingBoxFromTileObb(obb) {
77
- const { center, halfSize, quaternion } = obb;
78
- return new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(center, halfSize, quaternion);
79
- }
80
- /**
81
- * Get vertices fromnode obb
82
- * TODO check if Obb generates properly
83
- * @param node
84
- */
85
- function getTileObbVertices(node) {
86
- // @ts-expect-error
87
- const halfSize = node.obb.halfSize;
88
- const positions = CUBE_POSITIONS;
89
- // @ts-expect-error
90
- const obbCenterCartesian = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);
91
- let vertices = [];
92
- for (let i = 0; i < positions.length; i += 3) {
93
- const positionsVector = new core_1.Vector3((positions[i] *= halfSize[0]), (positions[i + 1] *= halfSize[1]), (positions[i + 2] *= halfSize[2]));
94
- const rotatedPositions = positionsVector
95
- // @ts-expect-error
96
- .transformByQuaternion(node.obb.quaternion)
97
- .add(obbCenterCartesian);
98
- // @ts-expect-error
99
- vertices = vertices.concat(rotatedPositions);
100
- }
101
- return vertices;
102
- }
103
- /**
104
- * Check if all vertices inside bounding volume
105
- * @param boundingVolume
106
- * @param positions
107
- */
108
- function isAllVerticesInsideBoundingVolume(boundingVolume, positions) {
109
- let isVerticesInsideObb = true;
110
- for (let index = 0; index < positions.length / 3; index += 3) {
111
- const point = [positions[index], positions[index + 1], positions[index + 2]];
112
- const cartographicPoint = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(point);
113
- const distance = boundingVolume.distanceTo(cartographicPoint);
114
- if (distance > 0) {
115
- isVerticesInsideObb = false;
116
- break;
117
- }
118
- }
119
- return isVerticesInsideObb;
120
- }
@@ -1,250 +0,0 @@
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
- exports.NodeIndexDocument = void 0;
7
- const path_1 = require("path");
8
- const json_map_transform_1 = __importDefault(require("json-map-transform"));
9
- const uuid_1 = require("uuid");
10
- const file_utils_1 = require("../../lib/utils/file-utils");
11
- const node_1 = require("../json-templates/node");
12
- /**
13
- * Wrapper for https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md data
14
- * The class allows working with 3DNodeIndexDocument in 2 modes:
15
- * in memory: the data is stored in `data` field
16
- * on disk: the data is written on disk in a file. The file can be rewritten when new childrend or neighbors have to be added
17
- */
18
- class NodeIndexDocument {
19
- /**
20
- * Constructor
21
- * @param id - id of the node in node pages
22
- * @param converter - converter instance
23
- */
24
- constructor(id, converter) {
25
- /** 3DNodeIndexDocument data */
26
- this.data = null;
27
- /** children */
28
- this.children = [];
29
- this.inPageId = id;
30
- this.id = id === 0 ? 'root' : id.toString();
31
- this.converter = converter;
32
- }
33
- /**
34
- * Add Node3DIndexDocument data to the node
35
- * @param data Node3DIndexDocument data
36
- * @returns this NodeIndexDocument instance (to recurring with constructor)
37
- */
38
- async addData(data) {
39
- if (this.converter.options.instantNodeWriting) {
40
- await this.write(data);
41
- }
42
- else {
43
- this.data = data;
44
- }
45
- return this;
46
- }
47
- /**
48
- * Add child node references
49
- * @param childNodes - child NodeIndexDocument instances
50
- */
51
- async addChildren(childNodes) {
52
- const newChildren = [];
53
- for (const node of childNodes) {
54
- const nodeData = await node.load();
55
- newChildren.push({
56
- id: node.id,
57
- href: `../${node.id}`,
58
- obb: nodeData.obb,
59
- mbs: nodeData.mbs
60
- });
61
- }
62
- this.children = this.children.concat(childNodes);
63
- let data = this.data;
64
- if (this.converter.options.instantNodeWriting) {
65
- data = (await this.load());
66
- }
67
- if (data) {
68
- data.children = data.children ?? [];
69
- data.children = data.children.concat(newChildren);
70
- }
71
- if (this.converter.options.instantNodeWriting && data) {
72
- await this.write(data);
73
- }
74
- }
75
- /**
76
- * Add neighbors to child nodes of this node
77
- */
78
- async addNeighbors() {
79
- const nodeData = await this.load();
80
- for (const childNode of this.children) {
81
- const childNodeData = await childNode.load();
82
- childNodeData.neighbors = childNodeData.neighbors ?? [];
83
- // Don't do large amount of "neightbors" to avoid big memory consumption
84
- if (Number(nodeData?.children?.length) < 1000) {
85
- for (const neighbor of nodeData.children || []) {
86
- if (childNode.id === neighbor.id) {
87
- continue; // eslint-disable-line
88
- }
89
- childNodeData.neighbors.push({ ...neighbor });
90
- }
91
- }
92
- else {
93
- // eslint-disable-next-line no-console, no-undef
94
- console.warn(`Node ${childNode.id}: neighbors attribute is omited because of large number of neigbors`);
95
- delete childNodeData.neighbors;
96
- }
97
- if (this.converter.options.instantNodeWriting && childNodeData) {
98
- await childNode.write(childNodeData);
99
- }
100
- await childNode.save();
101
- // The save after adding neighbors is the last one. Flush the the node
102
- childNode.flush();
103
- }
104
- }
105
- /** Save 3DNodeIndexDocument in file on disk */
106
- async save() {
107
- if (this.data) {
108
- await this.write(this.data);
109
- }
110
- }
111
- /**
112
- * Write 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
113
- * @param node - Node3DIndexDocument object
114
- */
115
- async write(node) {
116
- const path = (0, path_1.join)(this.converter.layers0Path, 'nodes', this.id);
117
- if (this.converter.options.slpk) {
118
- await this.converter.writeQueue.enqueue({
119
- archiveKey: `nodes/${this.id}/3dNodeIndexDocument.json.gz`,
120
- writePromise: () => (0, file_utils_1.writeFileForSlpk)(path, JSON.stringify(node), '3dNodeIndexDocument.json', true, this.converter.compressList)
121
- }, true);
122
- }
123
- else {
124
- await this.converter.writeQueue.enqueue({ writePromise: () => (0, file_utils_1.writeFile)(path, JSON.stringify(node)) }, true);
125
- }
126
- }
127
- /**
128
- * Load 3DNodeIndexDocument data from file on disk
129
- * @returns 3DNodeIndexDocument object
130
- */
131
- async load() {
132
- if (this.data) {
133
- return this.data;
134
- }
135
- const path = this.id;
136
- const parentNodePath = (0, path_1.join)(this.converter.layers0Path, 'nodes', path);
137
- let parentNodeFileName = 'index.json';
138
- if (this.converter.options.slpk) {
139
- parentNodeFileName = '3dNodeIndexDocument.json';
140
- }
141
- return (await (0, file_utils_1.openJson)(parentNodePath, parentNodeFileName));
142
- }
143
- /**
144
- * Unload the Node data
145
- */
146
- flush() {
147
- this.data = null;
148
- }
149
- /**
150
- * Create root node of the tree
151
- * @param boundingVolumes - MBS and OOB bounding volumes data
152
- * @param converter - I3SConverter instance
153
- * @returns instance of NodeIndexDocument
154
- */
155
- static async createRootNode(boundingVolumes, converter) {
156
- const rootData = NodeIndexDocument.createRootNodeIndexDocument(boundingVolumes);
157
- const rootNode = await new NodeIndexDocument(0, converter).addData(rootData);
158
- return rootNode;
159
- }
160
- /**
161
- * Create NodeIndexDocument instance
162
- * @param parentNode - parent NodeIndexDocument
163
- * @param boundingVolumes - MBS and OOB bounding volumes data
164
- * @param lodSelection - LOD metrics data
165
- * @param nodeInPage - node data in node pages
166
- * @param resources - resources extracted from gltf/b3dm file
167
- * @param converter - I3SConverter instance
168
- * @returns NodeIndexDocument instance
169
- */
170
- static async createNode(parentNode, boundingVolumes, lodSelection, nodeInPage, resources, converter) {
171
- const data = await NodeIndexDocument.createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources);
172
- const node = await new NodeIndexDocument(nodeInPage.index, converter).addData(data);
173
- return node;
174
- }
175
- /**
176
- * Form 3DNodeIndexDocument data for the root node
177
- * @param boundingVolumes - mbs and obb data about node's bounding volume
178
- * @return 3DNodeIndexDocument data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
179
- */
180
- static createRootNodeIndexDocument(boundingVolumes) {
181
- const root0data = {
182
- version: `{${(0, uuid_1.v4)().toUpperCase()}}`,
183
- id: 'root',
184
- level: 0,
185
- lodSelection: [
186
- {
187
- metricType: 'maxScreenThresholdSQ',
188
- maxError: 0
189
- },
190
- {
191
- metricType: 'maxScreenThreshold',
192
- maxError: 0
193
- }
194
- ],
195
- ...boundingVolumes,
196
- children: []
197
- };
198
- return (0, json_map_transform_1.default)(root0data, (0, node_1.NODE)());
199
- }
200
- /**
201
- * Create a new Node3DIndexDocument
202
- * @param parentNode - 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md object of the parent node
203
- * @param boundingVolumes - Bounding volumes
204
- * @param lodSelection - Level of Details (LOD) metrics
205
- * @param nodeInPage - corresponding node object in a node page
206
- * @param resources - the node resources data
207
- * @param resources.texture - texture image
208
- * @param resources.attributes - feature attributes
209
- * @return 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md object
210
- */
211
- static async createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources) {
212
- const { texture, attributes } = resources;
213
- const nodeId = nodeInPage.index;
214
- const parentNodeData = await parentNode.load();
215
- const nodeData = {
216
- version: parentNodeData.version,
217
- id: nodeId.toString(),
218
- level: parentNodeData.level + 1,
219
- ...boundingVolumes,
220
- lodSelection,
221
- parentNode: {
222
- id: parentNode.id,
223
- href: `../${parentNode.id}`,
224
- mbs: parentNodeData.mbs,
225
- obb: parentNodeData.obb
226
- },
227
- children: [],
228
- neighbors: []
229
- };
230
- const node = (0, json_map_transform_1.default)(nodeData, (0, node_1.NODE)());
231
- if (nodeInPage.mesh) {
232
- node.geometryData = [{ href: './geometries/0' }];
233
- node.sharedResource = { href: './shared' };
234
- if (texture) {
235
- node.textureData = [{ href: './textures/0' }, { href: './textures/1' }];
236
- }
237
- if (attributes &&
238
- attributes.length &&
239
- parentNode.converter.layers0?.attributeStorageInfo?.length) {
240
- node.attributeData = [];
241
- for (let index = 0; index < attributes.length; index++) {
242
- const folderName = parentNode.converter.layers0.attributeStorageInfo[index].key;
243
- node.attributeData.push({ href: `./attributes/${folderName}/0` });
244
- }
245
- }
246
- }
247
- return node;
248
- }
249
- }
250
- exports.NodeIndexDocument = NodeIndexDocument;