@loaders.gl/tile-converter 4.0.0-alpha.22 → 4.0.0-alpha.24

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 (137) hide show
  1. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
  2. package/dist/constants.d.ts +0 -2
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/converter.min.js +106 -106
  5. package/dist/dist.min.js +1883 -1241
  6. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
  7. package/dist/es5/constants.js +1 -5
  8. package/dist/es5/constants.js.map +1 -1
  9. package/dist/es5/deps-installer/deps-installer.js +1 -1
  10. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +26 -11
  11. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  12. package/dist/es5/i3s-converter/helpers/feature-attributes.js +7 -17
  13. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  14. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -44
  15. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  16. package/dist/es5/i3s-converter/helpers/geometry-converter.js +70 -17
  17. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  18. package/dist/es5/i3s-converter/helpers/node-index-document.js +3 -2
  19. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
  20. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +1 -2
  21. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  22. package/dist/es5/i3s-converter/i3s-converter.js +36 -26
  23. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  24. package/dist/es5/i3s-converter/types.js.map +1 -1
  25. package/dist/es5/i3s-server/controllers/slpk-controller.js +2 -2
  26. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
  27. package/dist/es5/pgm-loader.js +11 -3
  28. package/dist/es5/pgm-loader.js.map +1 -1
  29. package/dist/es5/slpk-extractor/slpk-extractor.js +1 -1
  30. package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -1
  31. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
  32. package/dist/esm/constants.js +0 -2
  33. package/dist/esm/constants.js.map +1 -1
  34. package/dist/esm/deps-installer/deps-installer.js +1 -1
  35. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +21 -6
  36. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  37. package/dist/esm/i3s-converter/helpers/feature-attributes.js +9 -7
  38. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  39. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +76 -34
  40. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  41. package/dist/esm/i3s-converter/helpers/geometry-converter.js +66 -13
  42. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  43. package/dist/esm/i3s-converter/helpers/node-index-document.js +2 -1
  44. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
  45. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +1 -1
  46. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  47. package/dist/esm/i3s-converter/i3s-converter.js +20 -17
  48. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  49. package/dist/esm/i3s-converter/types.js.map +1 -1
  50. package/dist/esm/i3s-server/bin/i3s-server.min.js +71 -71
  51. package/dist/esm/i3s-server/controllers/slpk-controller.js +1 -1
  52. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
  53. package/dist/esm/pgm-loader.js +7 -4
  54. package/dist/esm/pgm-loader.js.map +1 -1
  55. package/dist/esm/slpk-extractor/slpk-extractor.js +2 -1
  56. package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -1
  57. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  58. package/dist/i3s-converter/helpers/feature-attributes.d.ts +6 -6
  59. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  60. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  61. package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
  62. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  63. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  64. package/dist/i3s-converter/i3s-converter.d.ts +1 -1
  65. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  66. package/dist/i3s-converter/types.d.ts +7 -4
  67. package/dist/i3s-converter/types.d.ts.map +1 -1
  68. package/dist/pgm-loader.d.ts +9 -2
  69. package/dist/pgm-loader.d.ts.map +1 -1
  70. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
  71. package/dist/slpk-extractor.min.js +38 -38
  72. package/package.json +14 -14
  73. package/src/3d-tiles-converter/helpers/load-i3s.ts +1 -0
  74. package/src/constants.ts +0 -3
  75. package/src/i3s-converter/helpers/batch-ids-extensions.ts +53 -14
  76. package/src/i3s-converter/helpers/feature-attributes.ts +20 -15
  77. package/src/i3s-converter/helpers/geometry-attributes.ts +80 -50
  78. package/src/i3s-converter/helpers/geometry-converter.ts +153 -21
  79. package/src/i3s-converter/helpers/node-index-document.ts +5 -1
  80. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +1 -1
  81. package/src/i3s-converter/i3s-converter.ts +42 -17
  82. package/src/i3s-converter/types.ts +8 -4
  83. package/src/i3s-server/controllers/slpk-controller.ts +1 -1
  84. package/src/pgm-loader.ts +15 -7
  85. package/src/slpk-extractor/slpk-extractor.ts +2 -1
  86. package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -279
  87. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -271
  88. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
  89. package/dist/3d-tiles-converter/helpers/load-i3s.js +0 -42
  90. package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -54
  91. package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
  92. package/dist/bundle.js +0 -5
  93. package/dist/constants.js +0 -6
  94. package/dist/converter-cli.js +0 -222
  95. package/dist/deps-installer/deps-installer.js +0 -89
  96. package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -158
  97. package/dist/i3s-converter/helpers/coordinate-converter.js +0 -122
  98. package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
  99. package/dist/i3s-converter/helpers/feature-attributes.js +0 -216
  100. package/dist/i3s-converter/helpers/geometry-attributes.js +0 -203
  101. package/dist/i3s-converter/helpers/geometry-converter.js +0 -1240
  102. package/dist/i3s-converter/helpers/gltf-attributes.js +0 -129
  103. package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -99
  104. package/dist/i3s-converter/helpers/node-debug.js +0 -120
  105. package/dist/i3s-converter/helpers/node-index-document.js +0 -268
  106. package/dist/i3s-converter/helpers/node-pages.js +0 -316
  107. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -100
  108. package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
  109. package/dist/i3s-converter/i3s-converter.js +0 -945
  110. package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
  111. package/dist/i3s-converter/json-templates/layers.js +0 -139
  112. package/dist/i3s-converter/json-templates/metadata.js +0 -25
  113. package/dist/i3s-converter/json-templates/node.js +0 -89
  114. package/dist/i3s-converter/json-templates/scene-server.js +0 -31
  115. package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
  116. package/dist/i3s-converter/json-templates/store.js +0 -103
  117. package/dist/i3s-converter/types.js +0 -17
  118. package/dist/i3s-server/app.js +0 -29
  119. package/dist/i3s-server/bin/www.js +0 -37
  120. package/dist/i3s-server/controllers/index-controller.js +0 -31
  121. package/dist/i3s-server/controllers/slpk-controller.js +0 -33
  122. package/dist/i3s-server/routes/index.js +0 -20
  123. package/dist/i3s-server/routes/slpk-router.js +0 -34
  124. package/dist/i3s-server/utils/create-scene-server.js +0 -22
  125. package/dist/i3s-server/utils/server-utils.js +0 -66
  126. package/dist/index.js +0 -10
  127. package/dist/lib/utils/cli-utils.js +0 -82
  128. package/dist/lib/utils/compress-util.js +0 -257
  129. package/dist/lib/utils/file-utils.js +0 -139
  130. package/dist/lib/utils/geometry-utils.js +0 -18
  131. package/dist/lib/utils/lod-conversion-utils.js +0 -76
  132. package/dist/lib/utils/queue.js +0 -18
  133. package/dist/lib/utils/statistic-utills.js +0 -64
  134. package/dist/lib/utils/write-queue.js +0 -80
  135. package/dist/pgm-loader.js +0 -24
  136. package/dist/slpk-extractor/slpk-extractor.js +0 -74
  137. package/dist/slpk-extractor-cli.js +0 -102
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateTransformProps = exports.prepareDataForAttributesConversion = void 0;
4
- const core_1 = require("@math.gl/core");
5
- const geospatial_1 = require("@math.gl/geospatial");
6
- /**
7
- * Prepare attributes for conversion to avoid binary data breaking in worker thread.
8
- * @param tileContent - 3DTiles tile content
9
- * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
10
- * transform of all parent tiles and transform of the current tile
11
- * @param boundingVolume - initialized bounding volume of the source tile
12
- * @returns 3DTiles content data, prepared for conversion
13
- */
14
- function prepareDataForAttributesConversion(tileContent, tileTransform, boundingVolume) {
15
- let nodes = tileContent.gltf?.scene?.nodes ||
16
- tileContent.gltf?.scenes?.[0]?.nodes ||
17
- tileContent.gltf?.nodes ||
18
- [];
19
- const images = tileContent.gltf?.images?.map((imageObject) => {
20
- // Need data only for uncompressed images because we can't get batchIds from compressed textures.
21
- if (imageObject?.image?.compressed) {
22
- return null;
23
- }
24
- else {
25
- const data = imageObject?.image?.data;
26
- const dataCopy = new Uint8Array(data.length);
27
- dataCopy.set(data);
28
- return {
29
- data: dataCopy,
30
- compressed: false,
31
- height: imageObject.image.height,
32
- width: imageObject.image.width,
33
- components: imageObject.image.components,
34
- mimeType: imageObject.mimeType
35
- };
36
- }
37
- }) || [];
38
- prepareNodes(nodes);
39
- const { cartographicOrigin, modelMatrix: cartesianModelMatrix } = calculateTransformProps(tileContent, tileTransform, boundingVolume);
40
- return {
41
- nodes,
42
- images,
43
- cartographicOrigin,
44
- cartesianModelMatrix
45
- };
46
- }
47
- exports.prepareDataForAttributesConversion = prepareDataForAttributesConversion;
48
- /**
49
- * Keep only values for glTF attributes to pass data to worker thread.
50
- * @param attributes - geometry attributes
51
- * @returns attributes with only `value` item
52
- */
53
- function getB3DMAttributesWithoutBufferView(attributes) {
54
- const attributesWithoutBufferView = {};
55
- for (const attributeName in attributes) {
56
- attributesWithoutBufferView[attributeName] = {
57
- value: attributes[attributeName].value
58
- };
59
- }
60
- return attributesWithoutBufferView;
61
- }
62
- /**
63
- * Calculate transformation properties to transform vertex attributes (POSITION, NORMAL, etc.)
64
- * from METER_OFFSET coorditantes to LNGLAT_OFFSET coordinates
65
- * @param tileContent - 3DTiles tile content
66
- * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
67
- * transform of all parent tiles and transform of the current tile
68
- * @param boundingVolume - initialized bounding volume of the source tile
69
- * @returns modelMatrix - transformation matrix to transform coordinates to cartographic coordinates
70
- * cartographicOrigin - tile origin coordinates to calculate offsets
71
- */
72
- function calculateTransformProps(tileContent, tileTransform, boundingVolume) {
73
- const { rtcCenter, gltfUpAxis } = tileContent;
74
- const { center } = boundingVolume;
75
- let modelMatrix = new core_1.Matrix4(tileTransform);
76
- // Translate if appropriate
77
- if (rtcCenter) {
78
- modelMatrix.translate(rtcCenter);
79
- }
80
- // glTF models need to be rotated from Y to Z up
81
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
82
- switch (gltfUpAxis) {
83
- case 'Z':
84
- break;
85
- case 'Y':
86
- const rotationY = new core_1.Matrix4().rotateX(Math.PI / 2);
87
- modelMatrix = modelMatrix.multiplyRight(rotationY);
88
- break;
89
- case 'X':
90
- const rotationX = new core_1.Matrix4().rotateY(-Math.PI / 2);
91
- modelMatrix = modelMatrix.multiplyRight(rotationX);
92
- break;
93
- default:
94
- break;
95
- }
96
- const cartesianOrigin = new core_1.Vector3(center);
97
- const cartographicOrigin = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new core_1.Vector3());
98
- return { modelMatrix, cartographicOrigin };
99
- }
100
- exports.calculateTransformProps = calculateTransformProps;
101
- /**
102
- * Traverse all nodes to replace all sensible data with copy to avoid data corruption in worker.
103
- * @param nodes
104
- */
105
- function prepareNodes(nodes) {
106
- for (let index = 0; index < nodes.length; index++) {
107
- const node = nodes[index];
108
- if (node.mesh) {
109
- nodes[index] = {
110
- ...node,
111
- mesh: {
112
- ...node.mesh,
113
- primitives: node.mesh?.primitives.map((primitive) => ({
114
- ...primitive,
115
- indices: { value: primitive?.indices?.value },
116
- attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),
117
- material: {
118
- id: primitive?.material?.id,
119
- uniqueId: primitive?.material?.uniqueId
120
- }
121
- }))
122
- }
123
- };
124
- }
125
- if (node.children) {
126
- prepareNodes(node.children);
127
- }
128
- }
129
- }
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNestedTileset = exports.loadFromArchive = exports.loadTile3DContent = exports.loadNestedTileset = void 0;
4
- const _3d_tiles_1 = require("@loaders.gl/3d-tiles");
5
- const core_1 = require("@loaders.gl/core");
6
- /**
7
- * Load nested 3DTiles tileset. If the sourceTile is not nested tileset - do nothing
8
- * @param sourceTileset - source root tileset JSON
9
- * @param sourceTile - source tile JSON that is supposed to has link to nested tileset
10
- * @param tilesetLoadOptions - load options for Tiles3DLoader
11
- * @returns nothing
12
- */
13
- const loadNestedTileset = async (sourceTileset, sourceTile, tilesetLoadOptions) => {
14
- const isTileset = isNestedTileset(sourceTile);
15
- if (!sourceTileset || !sourceTile.contentUrl || !isTileset) {
16
- return;
17
- }
18
- const loadOptions = {
19
- ...tilesetLoadOptions,
20
- [sourceTileset.loader.id]: {
21
- isTileset,
22
- assetGltfUpAxis: (sourceTileset.asset && sourceTileset.asset.gltfUpAxis) || 'Y'
23
- }
24
- };
25
- const tileContent = await loadFromArchive(sourceTile.contentUrl, sourceTileset.loader, loadOptions);
26
- if (tileContent.root) {
27
- sourceTile.children = [tileContent.root];
28
- }
29
- };
30
- exports.loadNestedTileset = loadNestedTileset;
31
- /**
32
- * Load 3DTiles tile content, that includes glTF object
33
- * @param sourceTileset - source root tileset JSON
34
- * @param sourceTile - source tile JSON that has link to content data
35
- * @param tilesetLoadOptions - load options for Tiles3DLoader
36
- * @returns - 3DTiles tile content or null
37
- */
38
- const loadTile3DContent = async (sourceTileset, sourceTile, tilesetLoadOptions) => {
39
- const isTileset = isNestedTileset(sourceTile);
40
- if (!sourceTileset || !sourceTile.contentUrl || isTileset) {
41
- return null;
42
- }
43
- const loadOptions = {
44
- ...tilesetLoadOptions,
45
- [sourceTileset.loader.id]: {
46
- ...(tilesetLoadOptions[sourceTileset.loader.id] || {}),
47
- isTileset,
48
- assetGltfUpAxis: (sourceTileset.asset && sourceTileset.asset.gltfUpAxis) || 'Y'
49
- }
50
- };
51
- const tileContent = await loadFromArchive(sourceTile.contentUrl, sourceTileset.loader, loadOptions);
52
- return tileContent;
53
- };
54
- exports.loadTile3DContent = loadTile3DContent;
55
- /**
56
- * Load a resource with load options and .3tz format support
57
- * @param url - resource URL
58
- * @param loader - loader to parse data (Tiles3DLoader / CesiumIonLoader)
59
- * @param loadOptions - 3d-tiles loader options
60
- * @returns 3d-tiles resource
61
- */
62
- async function loadFromArchive(url, loader, loadOptions) {
63
- const tz3UrlParts = url.split('.3tz');
64
- let filename;
65
- // No '.3tz'. The file will be loaded with global fetch function
66
- if (tz3UrlParts.length === 1) {
67
- filename = null;
68
- }
69
- else if (tz3UrlParts.length === 2) {
70
- filename = tz3UrlParts[1].slice(1);
71
- if (filename === '') {
72
- filename = 'tileset.json';
73
- }
74
- }
75
- else {
76
- throw new Error('Unexpected URL format');
77
- }
78
- if (filename) {
79
- const tz3Path = `${tz3UrlParts[0]}.3tz`;
80
- const fileSystem = new _3d_tiles_1.Tiles3DArchiveFileSystem(tz3Path);
81
- const content = await (0, core_1.load)(filename, loader, {
82
- ...loadOptions,
83
- fetch: fileSystem.fetch.bind(fileSystem)
84
- });
85
- await fileSystem.destroy();
86
- return content;
87
- }
88
- return await (0, core_1.load)(url, loader, loadOptions);
89
- }
90
- exports.loadFromArchive = loadFromArchive;
91
- /**
92
- * Check if tile is nested tileset
93
- * @param tile - 3DTiles header data
94
- * @returns true if tile is nested tileset
95
- */
96
- function isNestedTileset(tile) {
97
- return tile?.type === 'json' || tile?.type === '3tz';
98
- }
99
- exports.isNestedTileset = isNestedTileset;
@@ -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,268 +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
- get finalized() {
20
- return this._finalized;
21
- }
22
- /**
23
- * Constructor
24
- * @param id - id of the node in node pages
25
- * @param converter - converter instance
26
- */
27
- constructor(id, converter) {
28
- /** 3DNodeIndexDocument data */
29
- this.data = null;
30
- /** children */
31
- this.children = [];
32
- /**
33
- * Finalized property. It means that all child nodes are saved and their data
34
- * is unloaded
35
- */
36
- this._finalized = false;
37
- this.inPageId = id;
38
- this.id = id === 0 ? 'root' : id.toString();
39
- this.converter = converter;
40
- }
41
- /**
42
- * Add Node3DIndexDocument data to the node
43
- * @param data Node3DIndexDocument data
44
- * @returns this NodeIndexDocument instance (to recurring with constructor)
45
- */
46
- async addData(data) {
47
- if (this.converter.options.instantNodeWriting) {
48
- await this.write(data);
49
- }
50
- else {
51
- this.data = data;
52
- }
53
- return this;
54
- }
55
- /**
56
- * Add child node references
57
- * @param childNodes - child NodeIndexDocument instances
58
- */
59
- async addChildren(childNodes) {
60
- const newChildren = [];
61
- for (const node of childNodes) {
62
- const nodeData = await node.load();
63
- newChildren.push({
64
- id: node.id,
65
- href: `../${node.id}`,
66
- obb: nodeData.obb,
67
- mbs: nodeData.mbs
68
- });
69
- }
70
- this.children = this.children.concat(childNodes);
71
- let data = this.data;
72
- if (this.converter.options.instantNodeWriting) {
73
- data = (await this.load());
74
- }
75
- if (data) {
76
- data.children = data.children ?? [];
77
- data.children = data.children.concat(newChildren);
78
- }
79
- if (this.converter.options.instantNodeWriting && data) {
80
- await this.write(data);
81
- }
82
- }
83
- /**
84
- * Add neighbors to child nodes of this node
85
- */
86
- async addNeighbors() {
87
- if (this.finalized) {
88
- return;
89
- }
90
- const nodeData = await this.load();
91
- for (const childNode of this.children) {
92
- const childNodeData = await childNode.load();
93
- childNodeData.neighbors = childNodeData.neighbors ?? [];
94
- // Don't do large amount of "neightbors" to avoid big memory consumption
95
- if (Number(nodeData?.children?.length) < 1000) {
96
- for (const neighbor of nodeData.children || []) {
97
- if (childNode.id === neighbor.id) {
98
- continue; // eslint-disable-line
99
- }
100
- childNodeData.neighbors.push({ ...neighbor });
101
- }
102
- }
103
- else {
104
- // eslint-disable-next-line no-console, no-undef
105
- console.warn(`Node ${childNode.id}: neighbors attribute is omited because of large number of neigbors`);
106
- delete childNodeData.neighbors;
107
- }
108
- if (this.converter.options.instantNodeWriting && childNodeData) {
109
- await childNode.write(childNodeData);
110
- }
111
- await childNode.save();
112
- }
113
- // The save after adding neighbors is the last one. Finalize the the node
114
- this.finalize();
115
- }
116
- /** Save 3DNodeIndexDocument in file on disk */
117
- async save() {
118
- if (this.data) {
119
- await this.write(this.data);
120
- }
121
- }
122
- /** Finalize the node */
123
- finalize() {
124
- this._finalized = true;
125
- for (const child of this.children) {
126
- child.flush();
127
- }
128
- }
129
- /**
130
- * Write 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
131
- * @param node - Node3DIndexDocument object
132
- */
133
- async write(node) {
134
- const path = (0, path_1.join)(this.converter.layers0Path, 'nodes', this.id);
135
- if (this.converter.options.slpk) {
136
- await this.converter.writeQueue.enqueue({
137
- archiveKey: `nodes/${this.id}/3dNodeIndexDocument.json.gz`,
138
- writePromise: () => (0, file_utils_1.writeFileForSlpk)(path, JSON.stringify(node), '3dNodeIndexDocument.json', true, this.converter.compressList)
139
- }, true);
140
- }
141
- else {
142
- await this.converter.writeQueue.enqueue({ writePromise: () => (0, file_utils_1.writeFile)(path, JSON.stringify(node)) }, true);
143
- }
144
- }
145
- /**
146
- * Load 3DNodeIndexDocument data from file on disk
147
- * @returns 3DNodeIndexDocument object
148
- */
149
- async load() {
150
- if (this.data) {
151
- return this.data;
152
- }
153
- const path = this.id;
154
- const parentNodePath = (0, path_1.join)(this.converter.layers0Path, 'nodes', path);
155
- let parentNodeFileName = 'index.json';
156
- if (this.converter.options.slpk) {
157
- parentNodeFileName = '3dNodeIndexDocument.json';
158
- }
159
- return (await (0, file_utils_1.openJson)(parentNodePath, parentNodeFileName));
160
- }
161
- /**
162
- * Unload the Node data
163
- */
164
- flush() {
165
- this.data = null;
166
- }
167
- /**
168
- * Create root node of the tree
169
- * @param boundingVolumes - MBS and OOB bounding volumes data
170
- * @param converter - I3SConverter instance
171
- * @returns instance of NodeIndexDocument
172
- */
173
- static async createRootNode(boundingVolumes, converter) {
174
- const rootData = NodeIndexDocument.createRootNodeIndexDocument(boundingVolumes);
175
- const rootNode = await new NodeIndexDocument(0, converter).addData(rootData);
176
- return rootNode;
177
- }
178
- /**
179
- * Create NodeIndexDocument instance
180
- * @param parentNode - parent NodeIndexDocument
181
- * @param boundingVolumes - MBS and OOB bounding volumes data
182
- * @param lodSelection - LOD metrics data
183
- * @param nodeInPage - node data in node pages
184
- * @param resources - resources extracted from gltf/b3dm file
185
- * @param converter - I3SConverter instance
186
- * @returns NodeIndexDocument instance
187
- */
188
- static async createNode(parentNode, boundingVolumes, lodSelection, nodeInPage, resources, converter) {
189
- const data = await NodeIndexDocument.createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources);
190
- const node = await new NodeIndexDocument(nodeInPage.index, converter).addData(data);
191
- return node;
192
- }
193
- /**
194
- * Form 3DNodeIndexDocument data for the root node
195
- * @param boundingVolumes - mbs and obb data about node's bounding volume
196
- * @return 3DNodeIndexDocument data https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
197
- */
198
- static createRootNodeIndexDocument(boundingVolumes) {
199
- const root0data = {
200
- version: `{${(0, uuid_1.v4)().toUpperCase()}}`,
201
- id: 'root',
202
- level: 0,
203
- lodSelection: [
204
- {
205
- metricType: 'maxScreenThresholdSQ',
206
- maxError: 0
207
- },
208
- {
209
- metricType: 'maxScreenThreshold',
210
- maxError: 0
211
- }
212
- ],
213
- ...boundingVolumes,
214
- children: []
215
- };
216
- return (0, json_map_transform_1.default)(root0data, (0, node_1.NODE)());
217
- }
218
- /**
219
- * Create a new Node3DIndexDocument
220
- * @param parentNode - 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md object of the parent node
221
- * @param boundingVolumes - Bounding volumes
222
- * @param lodSelection - Level of Details (LOD) metrics
223
- * @param nodeInPage - corresponding node object in a node page
224
- * @param resources - the node resources data
225
- * @param resources.texture - texture image
226
- * @param resources.attributes - feature attributes
227
- * @return 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md object
228
- */
229
- static async createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources) {
230
- const { texture, attributes } = resources;
231
- const nodeId = nodeInPage.index;
232
- const parentNodeData = await parentNode.load();
233
- const nodeData = {
234
- version: parentNodeData.version,
235
- id: nodeId.toString(),
236
- level: parentNodeData.level + 1,
237
- ...boundingVolumes,
238
- lodSelection,
239
- parentNode: {
240
- id: parentNode.id,
241
- href: `../${parentNode.id}`,
242
- mbs: parentNodeData.mbs,
243
- obb: parentNodeData.obb
244
- },
245
- children: [],
246
- neighbors: []
247
- };
248
- const node = (0, json_map_transform_1.default)(nodeData, (0, node_1.NODE)());
249
- if (nodeInPage.mesh) {
250
- node.geometryData = [{ href: './geometries/0' }];
251
- node.sharedResource = { href: './shared' };
252
- if (texture) {
253
- node.textureData = [{ href: './textures/0' }, { href: './textures/1' }];
254
- }
255
- if (attributes &&
256
- attributes.length &&
257
- parentNode.converter.layers0?.attributeStorageInfo?.length) {
258
- node.attributeData = [];
259
- for (let index = 0; index < attributes.length; index++) {
260
- const folderName = parentNode.converter.layers0.attributeStorageInfo[index].key;
261
- node.attributeData.push({ href: `./attributes/${folderName}/0` });
262
- }
263
- }
264
- }
265
- return node;
266
- }
267
- }
268
- exports.NodeIndexDocument = NodeIndexDocument;