@loaders.gl/tile-converter 3.1.0-beta.7 → 3.1.3

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 (153) hide show
  1. package/dist/converter.min.js +20 -20
  2. package/dist/{bundle.js → dist.min.js} +2228 -1482
  3. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +429 -189
  4. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  5. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +306 -209
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  7. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +8 -4
  8. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  9. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +13 -13
  10. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  11. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +51 -32
  12. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  13. package/dist/es5/bundle.js +1 -1
  14. package/dist/es5/bundle.js.map +1 -1
  15. package/dist/es5/deps-installer/deps-installer.js +61 -17
  16. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +55 -16
  18. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  19. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +33 -9
  20. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  21. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +103 -93
  22. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  24. package/dist/es5/i3s-converter/helpers/geometry-converter.js +547 -336
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/node-debug.js +27 -31
  27. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/node-pages.js +209 -101
  29. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  30. package/dist/es5/i3s-converter/i3s-converter.js +1645 -700
  31. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/json-templates/layers.js +213 -177
  33. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  34. package/dist/es5/i3s-converter/json-templates/metadata.js +24 -20
  35. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  36. package/dist/es5/i3s-converter/json-templates/node.js +92 -74
  37. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  38. package/dist/es5/i3s-converter/json-templates/scene-server.js +34 -28
  39. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  40. package/dist/es5/i3s-converter/json-templates/shared-resources.js +162 -107
  41. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  42. package/dist/es5/i3s-converter/json-templates/store.js +4 -2
  43. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  44. package/dist/es5/i3s-converter/types.js +2 -0
  45. package/dist/es5/i3s-converter/types.js.map +1 -0
  46. package/dist/es5/i3s-server/app.js +6 -6
  47. package/dist/es5/i3s-server/app.js.map +1 -1
  48. package/dist/es5/i3s-server/controllers/index-controller.js +60 -20
  49. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  50. package/dist/es5/i3s-server/routes/index.js +41 -14
  51. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  52. package/dist/es5/index.js +4 -4
  53. package/dist/es5/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  54. package/dist/es5/lib/utils/compress-util.js +345 -123
  55. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  56. package/dist/es5/lib/utils/file-utils.js +98 -20
  57. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  58. package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
  59. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  60. package/dist/es5/lib/utils/statistic-utills.js +152 -41
  61. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  62. package/dist/es5/pgm-loader.js +31 -4
  63. package/dist/es5/pgm-loader.js.map +1 -1
  64. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +7 -6
  65. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  66. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +7 -0
  67. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  68. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  69. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +1 -1
  70. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  71. package/dist/esm/3d-tiles-converter/json-templates/tileset.js +12 -9
  72. package/dist/esm/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  73. package/dist/esm/deps-installer/deps-installer.js +2 -6
  74. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  75. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +35 -3
  76. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  77. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js +2 -2
  78. package/dist/esm/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  79. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  80. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  81. package/dist/esm/i3s-converter/helpers/geometry-converter.js +50 -16
  82. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  83. package/dist/esm/i3s-converter/helpers/node-debug.js +2 -4
  84. package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
  85. package/dist/esm/i3s-converter/helpers/node-pages.js +15 -4
  86. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  87. package/dist/esm/i3s-converter/i3s-converter.js +147 -62
  88. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  89. package/dist/esm/i3s-converter/json-templates/layers.js +37 -27
  90. package/dist/esm/i3s-converter/json-templates/layers.js.map +1 -1
  91. package/dist/esm/i3s-converter/json-templates/metadata.js +2 -2
  92. package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
  93. package/dist/esm/i3s-converter/json-templates/node.js +16 -12
  94. package/dist/esm/i3s-converter/json-templates/node.js.map +1 -1
  95. package/dist/esm/i3s-converter/json-templates/scene-server.js +2 -2
  96. package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
  97. package/dist/esm/i3s-converter/json-templates/shared-resources.js +19 -14
  98. package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
  99. package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
  100. package/dist/esm/i3s-converter/types.js +2 -0
  101. package/dist/esm/i3s-converter/types.js.map +1 -0
  102. package/dist/esm/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  103. package/dist/esm/pgm-loader.js +3 -3
  104. package/dist/esm/pgm-loader.js.map +1 -1
  105. package/package.json +17 -15
  106. package/src/3d-tiles-converter/3d-tiles-converter.ts +21 -20
  107. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +19 -2
  108. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  109. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  110. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  111. package/src/deps-installer/deps-installer.js +2 -2
  112. package/src/i3s-converter/helpers/coordinate-converter.ts +62 -9
  113. package/src/i3s-converter/helpers/{create-scene-server-path.js → create-scene-server-path.ts} +2 -2
  114. package/src/i3s-converter/helpers/{geometry-attributes.js → geometry-attributes.ts} +4 -4
  115. package/src/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  116. package/src/i3s-converter/helpers/geometry-converter.js +63 -13
  117. package/src/i3s-converter/helpers/{node-debug.js → node-debug.ts} +3 -2
  118. package/src/i3s-converter/helpers/{node-pages.js → node-pages.ts} +41 -26
  119. package/src/i3s-converter/i3s-converter.ts +204 -133
  120. package/src/i3s-converter/json-templates/{layers.js → layers.ts} +29 -27
  121. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  122. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  123. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  124. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +14 -14
  125. package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  126. package/src/i3s-converter/types.ts +14 -0
  127. package/src/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  128. package/src/pgm-loader.ts +2 -2
  129. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  130. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  131. package/dist/es5/i3s-converter/helpers/node-pages.d.ts +0 -144
  132. package/dist/es5/lib/geoid-height-model.d.ts +0 -41
  133. package/dist/es5/lib/geoid-height-model.js +0 -149
  134. package/dist/es5/lib/geoid-height-model.js.map +0 -1
  135. package/dist/es5/lib/pgm-parser.d.ts +0 -14
  136. package/dist/es5/lib/pgm-parser.js +0 -192
  137. package/dist/es5/lib/pgm-parser.js.map +0 -1
  138. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  139. package/dist/esm/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  140. package/dist/esm/i3s-converter/helpers/node-pages.d.ts +0 -144
  141. package/dist/esm/lib/geoid-height-model.d.ts +0 -41
  142. package/dist/esm/lib/geoid-height-model.js +0 -140
  143. package/dist/esm/lib/geoid-height-model.js.map +0 -1
  144. package/dist/esm/lib/pgm-parser.d.ts +0 -14
  145. package/dist/esm/lib/pgm-parser.js +0 -183
  146. package/dist/esm/lib/pgm-parser.js.map +0 -1
  147. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  148. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  149. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  150. package/src/lib/geoid-height-model.d.ts +0 -41
  151. package/src/lib/geoid-height-model.js +0 -239
  152. package/src/lib/pgm-parser.d.ts +0 -14
  153. package/src/lib/pgm-parser.js +0 -179
@@ -2,9 +2,13 @@ import type {BoundingVolumes, Extent, Mbs, Obb} from '@loaders.gl/i3s';
2
2
 
3
3
  import {Matrix3, Quaternion, Vector3} from '@math.gl/core';
4
4
  import {Ellipsoid} from '@math.gl/geospatial';
5
- import {OrientedBoundingBox} from '@math.gl/culling';
5
+ import {
6
+ OrientedBoundingBox,
7
+ makeOrientedBoundingBoxFromPoints,
8
+ makeBoundingSphereFromPoints
9
+ } from '@math.gl/culling';
6
10
  import TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';
7
- import {GeoidHeightModel} from '../../lib/geoid-height-model';
11
+ import {Geoid} from '@math.gl/geoid';
8
12
  import {Tileset3D} from '@loaders.gl/tiles';
9
13
 
10
14
  /**
@@ -13,10 +17,7 @@ import {Tileset3D} from '@loaders.gl/tiles';
13
17
  * @param geoidHeightModel
14
18
  * @returns - Bounding volumes object
15
19
  */
16
- export function createBoundingVolumes(
17
- tile: TileHeader,
18
- geoidHeightModel: GeoidHeightModel
19
- ): BoundingVolumes {
20
+ export function createBoundingVolumes(tile: TileHeader, geoidHeightModel: Geoid): BoundingVolumes {
20
21
  let radius;
21
22
  let halfSize;
22
23
  let quaternion;
@@ -51,14 +52,66 @@ export function createBoundingVolumes(
51
52
  };
52
53
  }
53
54
 
55
+ /**
56
+ * Generates bounding volumes from geometry positions
57
+ * @param cartesianPositions
58
+ * @param geoidHeightModel
59
+ */
60
+ export function createBoundingVolumesFromGeometry(
61
+ cartesianPositions: Float32Array,
62
+ geoidHeightModel: Geoid
63
+ ): {mbs: Mbs; obb: Obb} {
64
+ const positionVectors = convertPositionsToVectors(cartesianPositions);
65
+
66
+ const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);
67
+ const geometryMbs = makeBoundingSphereFromPoints(positionVectors);
68
+
69
+ let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());
70
+ let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());
71
+
72
+ mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);
73
+ obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);
74
+
75
+ return {
76
+ mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],
77
+ obb: {
78
+ center: obbCenter,
79
+ halfSize: geometryObb.halfSize,
80
+ quaternion: geometryObb.quaternion
81
+ }
82
+ };
83
+ }
84
+
85
+ /**
86
+ * Create array of posisitons where each vertex is vector
87
+ * @param {array} positions
88
+ * @returns {Vector3[]}
89
+ */
90
+ export function convertPositionsToVectors(positions: Float32Array): Vector3[] {
91
+ const result: Vector3[] = [];
92
+
93
+ for (let i = 0; i < positions.length; i += 3) {
94
+ // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.
95
+ // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors
96
+ const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);
97
+ result.push(positionVector);
98
+ }
99
+
100
+ return result;
101
+ }
102
+
54
103
  /**
55
104
  * Convert common coordinate to extent coordinate
56
105
  * @param tileset
57
106
  * @returns - Extent
107
+ * @todo why lodMetricValue is radius? need to check this function
58
108
  */
59
- export function convertCommonToI3SExtentCoordinate(tileset: Tileset3D): Extent {
60
- const cartesianCenter = tileset.cartesianCenter;
61
- const radius = tileset.lodMetricValue;
109
+ export function convertCommonToI3SExtentCoordinate(tileset: Tileset3D | null): Extent | null {
110
+ const cartesianCenter = tileset?.cartesianCenter;
111
+ if (!cartesianCenter) {
112
+ return null;
113
+ }
114
+ const radius = tileset?.lodMetricValue;
62
115
  const rightTop = Ellipsoid.WGS84.cartesianToCartographic(
63
116
  new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]),
64
117
  new Vector3()
@@ -2,7 +2,7 @@ import {v4 as uuidv4} from 'uuid';
2
2
  import transform from 'json-map-transform';
3
3
  import {join} from 'path';
4
4
 
5
- import {SCENE_SERVER_TEMPLATE} from '../json-templates/scene-server';
5
+ import {SCENE_SERVER as sceneServerTemplate} from '../json-templates/scene-server';
6
6
  import {writeFile} from '../../lib/utils/file-utils';
7
7
 
8
8
  /**
@@ -19,7 +19,7 @@ export async function createSceneServerPath(layerName, layers0, rootPath) {
19
19
  layers0
20
20
  };
21
21
 
22
- const sceneServer = transform(sceneServerData, SCENE_SERVER_TEMPLATE);
22
+ const sceneServer = transform(sceneServerData, sceneServerTemplate());
23
23
  const nodePagePath = join(rootPath, 'SceneServer');
24
24
  await writeFile(nodePagePath, JSON.stringify(sceneServer));
25
25
  }
@@ -41,8 +41,8 @@ function calculateFaceRangesAndFeaturesCount(featureIndices) {
41
41
  let rangeIndex = 1;
42
42
  let featureIndex = 1;
43
43
  let currentFeatureId = featureIndices[0];
44
- const faceRangeList = [];
45
- const featureIds = [];
44
+ const faceRangeList: any[] = [];
45
+ const featureIds: any[] = [];
46
46
  const uniqueFeatureIds = [currentFeatureId];
47
47
 
48
48
  faceRangeList[0] = 0;
@@ -79,7 +79,7 @@ function calculateFaceRangesAndFeaturesCount(featureIndices) {
79
79
  */
80
80
  function makeAttributeObjects(attributes) {
81
81
  const {featureIds, positions, normals, colors, texCoords, faceRange} = attributes;
82
- const groupedData = [];
82
+ const groupedData: any[] = [];
83
83
 
84
84
  let positionsList = new Float32Array(positions);
85
85
  let normalsList = new Float32Array(normals);
@@ -149,7 +149,7 @@ function getSliceAttributeCount(attributeName, startIndex, endIndex) {
149
149
  * @returns {Array} - unique list of objects
150
150
  */
151
151
  function unifyObjectsByFeatureId(sortedData) {
152
- const uniqueObjects = [];
152
+ const uniqueObjects: any[] = [];
153
153
 
154
154
  for (let index = 0; index < sortedData.length; index++) {
155
155
  const currentObject = sortedData[index];
@@ -1,4 +1,5 @@
1
1
  import {Vector3, Matrix4} from '@math.gl/core';
2
+ import {GeoidHeightModel} from '../../lib/geoid-height-model';
2
3
  /**
3
4
  * Convert binary data from b3dm file to i3s resources
4
5
  *
@@ -25,7 +26,9 @@ export default function convertB3dmToI3sGeometry(
25
26
  nodeId: number,
26
27
  featuresHashArray: any,
27
28
  attributeStorageInfo: any,
28
- draco: boolean
29
+ draco: boolean,
30
+ generateBoundingVolumes: boolean,
31
+ geoidHeightModel: GeoidHeightModel
29
32
  ): Promise<
30
33
  {
31
34
  geometry: ArrayBuffer;
@@ -36,5 +39,6 @@ export default function convertB3dmToI3sGeometry(
36
39
  vertexCount: number;
37
40
  attributes: any;
38
41
  featureCount: number;
42
+ boundingVolumes: any;
39
43
  }[]
40
44
  >;
@@ -6,6 +6,7 @@ import {encode, assert} from '@loaders.gl/core';
6
6
  import {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';
7
7
  import md5 from 'md5';
8
8
  import {generateAttributes} from './geometry-attributes';
9
+ import {createBoundingVolumesFromGeometry} from './coordinate-converter';
9
10
 
10
11
  const VALUES_PER_VERTEX = 3;
11
12
  const VALUES_PER_TEX_COORD = 2;
@@ -22,15 +23,24 @@ const OBJECT_ID_TYPE = 'Oid32';
22
23
  */
23
24
  const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
24
25
 
26
+ let scratchVector = new Vector3();
27
+
25
28
  export default async function convertB3dmToI3sGeometry(
26
29
  tileContent,
27
30
  nodeId,
28
31
  featuresHashArray,
29
32
  attributeStorageInfo,
30
- draco
33
+ draco,
34
+ generateBoundingVolumes,
35
+ geoidHeightModel
31
36
  ) {
37
+ const useCartesianPositions = generateBoundingVolumes;
32
38
  const materialAndTextureList = convertMaterials(tileContent);
33
- const convertedAttributesMap = convertAttributes(tileContent);
39
+ const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);
40
+
41
+ if (generateBoundingVolumes) {
42
+ _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
43
+ }
34
44
 
35
45
  if (convertedAttributesMap.has('default')) {
36
46
  materialAndTextureList.push({
@@ -41,7 +51,7 @@ export default async function convertB3dmToI3sGeometry(
41
51
  const result = [];
42
52
  let nodesCounter = nodeId;
43
53
  let {materials = []} = tileContent.gltf;
44
- if (!materials.length === 0) {
54
+ if (!materials?.length) {
45
55
  materials.push({id: 'default'});
46
56
  }
47
57
  for (let i = 0; i < materials.length; i++) {
@@ -72,6 +82,32 @@ export default async function convertB3dmToI3sGeometry(
72
82
  return result;
73
83
  }
74
84
 
85
+ /**
86
+ * Create bounding volumes based on positions
87
+ * @param convertedAttributesMap
88
+ * @param geoidHeightModel
89
+ */
90
+ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
91
+ for (const attributes of convertedAttributesMap.values()) {
92
+ const boundingVolumes = createBoundingVolumesFromGeometry(
93
+ attributes.positions,
94
+ geoidHeightModel
95
+ );
96
+
97
+ attributes.boundingVolumes = boundingVolumes;
98
+ const cartographicOrigin = boundingVolumes.obb.center;
99
+
100
+ for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
101
+ const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
102
+ Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
103
+ scratchVector[2] =
104
+ scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
105
+ scratchVector = scratchVector.subtract(cartographicOrigin);
106
+ attributes.positions.set(scratchVector, index);
107
+ }
108
+ }
109
+ }
110
+
75
111
  async function _makeNodeResources({
76
112
  convertedAttributes,
77
113
  material,
@@ -82,6 +118,7 @@ async function _makeNodeResources({
82
118
  attributeStorageInfo,
83
119
  draco
84
120
  }) {
121
+ const boundingVolumes = convertedAttributes.boundingVolumes;
85
122
  const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
86
123
  const triangleCount = vertexCount / 3;
87
124
  const {faceRange, featureIds, positions, normals, colors, texCoords, featureCount} =
@@ -136,7 +173,8 @@ async function _makeNodeResources({
136
173
  meshMaterial: material,
137
174
  vertexCount,
138
175
  attributes,
139
- featureCount
176
+ featureCount,
177
+ boundingVolumes
140
178
  };
141
179
  }
142
180
 
@@ -152,7 +190,7 @@ async function _makeNodeResources({
152
190
  * }>
153
191
  * @todo implement colors support (if applicable for gltf format)
154
192
  */
155
- function convertAttributes(tileContent) {
193
+ function convertAttributes(tileContent, useCartesianPositions) {
156
194
  const attributesMap = new Map();
157
195
 
158
196
  for (const material of tileContent.gltf.materials || [{id: 'default'}]) {
@@ -161,12 +199,13 @@ function convertAttributes(tileContent) {
161
199
  normals: new Float32Array(0),
162
200
  texCoords: new Float32Array(0),
163
201
  colors: new Uint8Array(0),
164
- featureIndices: []
202
+ featureIndices: [],
203
+ boundingVolumes: null
165
204
  });
166
205
  }
167
206
 
168
207
  const nodes = (tileContent.gltf.scene || tileContent.gltf.scenes?.[0] || tileContent.gltf).nodes;
169
- convertNodes(nodes, tileContent, attributesMap);
208
+ convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);
170
209
 
171
210
  for (const attrKey of attributesMap.keys()) {
172
211
  const attributes = attributesMap.get(attrKey);
@@ -194,11 +233,12 @@ function convertNodes(
194
233
  nodes,
195
234
  tileContent,
196
235
  attributesMap,
236
+ useCartesianPositions,
197
237
  matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
198
238
  ) {
199
239
  if (nodes) {
200
240
  for (const node of nodes) {
201
- convertNode(node, tileContent, attributesMap, matrix);
241
+ convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);
202
242
  }
203
243
  }
204
244
  }
@@ -216,6 +256,7 @@ function convertNode(
216
256
  node,
217
257
  tileContent,
218
258
  attributesMap,
259
+ useCartesianPositions,
219
260
  matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
220
261
  ) {
221
262
  const nodeMatrix = node.matrix;
@@ -223,10 +264,10 @@ function convertNode(
223
264
 
224
265
  const mesh = node.mesh;
225
266
  if (mesh) {
226
- convertMesh(mesh, tileContent, attributesMap, compositeMatrix);
267
+ convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, compositeMatrix);
227
268
  }
228
269
 
229
- convertNodes(node.children, tileContent, attributesMap, compositeMatrix);
270
+ convertNodes(node.children, tileContent, attributesMap, useCartesianPositions, compositeMatrix);
230
271
  }
231
272
 
232
273
  /**
@@ -242,6 +283,7 @@ function convertMesh(
242
283
  mesh,
243
284
  content,
244
285
  attributesMap,
286
+ useCartesianPositions = false,
245
287
  matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
246
288
  ) {
247
289
  for (const primitive of mesh.primitives) {
@@ -262,7 +304,8 @@ function convertMesh(
262
304
  cartesianModelMatrix: content.cartesianModelMatrix,
263
305
  nodeMatrix: matrix,
264
306
  indices: primitive.indices.value,
265
- attributeSpecificTransformation: transformVertexPositions
307
+ attributeSpecificTransformation: transformVertexPositions,
308
+ useCartesianPositions
266
309
  })
267
310
  );
268
311
  outputAttributes.normals = concatenateTypedArrays(
@@ -273,7 +316,8 @@ function convertMesh(
273
316
  cartesianModelMatrix: content.cartesianModelMatrix,
274
317
  nodeMatrix: matrix,
275
318
  indices: primitive.indices.value,
276
- attributeSpecificTransformation: transformVertexNormals
319
+ attributeSpecificTransformation: transformVertexNormals,
320
+ useCartesianPositions: false
277
321
  })
278
322
  );
279
323
  outputAttributes.texCoords = concatenateTypedArrays(
@@ -304,6 +348,7 @@ function convertMesh(
304
348
  * @param {Matrix4} args.nodeMatrix - a gltf node transformation matrix - cumulative transformation matrix formed from all parent node matrices
305
349
  * @param {Uint8Array} args.indices - gltf primitive indices
306
350
  * @param {Function} args.attributeSpecificTransformation - function to do attribute - specific transformations
351
+ * @param {Boolean} args.useCartesianPositions - use coordinates as it is.
307
352
  * @returns {Float32Array}
308
353
  */
309
354
  function transformVertexArray(args) {
@@ -327,13 +372,18 @@ function transformVertexArray(args) {
327
372
  }
328
373
 
329
374
  function transformVertexPositions(vertexVector, calleeArgs) {
330
- const {cartesianModelMatrix, cartographicOrigin, nodeMatrix} = calleeArgs;
375
+ const {cartesianModelMatrix, cartographicOrigin, nodeMatrix, useCartesianPositions} = calleeArgs;
331
376
 
332
377
  if (nodeMatrix) {
333
378
  vertexVector = vertexVector.transform(nodeMatrix);
334
379
  }
335
380
 
336
381
  vertexVector = vertexVector.transform(cartesianModelMatrix);
382
+
383
+ if (useCartesianPositions) {
384
+ return vertexVector;
385
+ }
386
+
337
387
  Ellipsoid.WGS84.cartesianToCartographic(
338
388
  [vertexVector[0], vertexVector[1], vertexVector[2]],
339
389
  vertexVector
@@ -6,7 +6,7 @@ import {Ellipsoid} from '@math.gl/geospatial';
6
6
  // TODO Unite Tile validation logic in i3s-17-and-debug with this code.
7
7
  export function validateNodeBoundingVolumes(node) {
8
8
  if (!node.parentNode.obb || !node.parentNode.mbs) {
9
- return null;
9
+ return [];
10
10
  }
11
11
  const tileWarnings = [];
12
12
 
@@ -53,7 +53,7 @@ function createBoundingBoxFromTileObb(obb) {
53
53
  function getTileObbVertices(node) {
54
54
  const geometry = new CubeGeometry();
55
55
  const halfSize = node.obb.halfSize;
56
- const {attributes} = geometry;
56
+ const attributes = geometry.getAttributes();
57
57
  const positions = new Float32Array(attributes.POSITION.value);
58
58
  const obbCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(node.obb.center);
59
59
 
@@ -68,6 +68,7 @@ function getTileObbVertices(node) {
68
68
  const rotatedPositions = positionsVector
69
69
  .transformByQuaternion(node.obb.quaternion)
70
70
  .add(obbCenterCartesian);
71
+ // @ts-expect-error
71
72
  vertices = vertices.concat(rotatedPositions);
72
73
  }
73
74
 
@@ -1,7 +1,9 @@
1
1
  import {join} from 'path';
2
2
  import transform from 'json-map-transform';
3
3
  import {METADATA as metadataTemplate} from '../json-templates/metadata';
4
+ import {NodeInPage} from '@loaders.gl/i3s';
4
5
 
6
+ // @ts-nocheck
5
7
  /**
6
8
  * class NodePages - wrapper of nodePages array
7
9
  *
@@ -35,6 +37,11 @@ import {METADATA as metadataTemplate} from '../json-templates/metadata';
35
37
  * await this.nodePages.save(layers0path);
36
38
  */
37
39
  export default class NodePages {
40
+ readonly nodesPerPage: number;
41
+ nodesCounter: number;
42
+ writeFile: Function;
43
+ readonly nodePages: {nodes: NodeInPage[]}[];
44
+
38
45
  /**
39
46
  * @constructs
40
47
  * Create a nodePages instance.
@@ -44,21 +51,26 @@ export default class NodePages {
44
51
  constructor(writeFileFunc, nodesPerPage) {
45
52
  this.nodesPerPage = nodesPerPage;
46
53
  this.nodesCounter = 0;
54
+ // @ts-expect-error
47
55
  this.nodePages = [{}];
48
56
  this.nodePages[0].nodes = [];
49
57
  this.writeFile = writeFileFunc;
50
58
  }
51
59
 
52
- useWriteFunction(func) {
60
+ /**
61
+ * Setup function to save node pages
62
+ * @param func - function which should be used to save node pages
63
+ */
64
+ useWriteFunction(func: Function): void {
53
65
  this.writeFile = func;
54
66
  }
55
67
 
56
68
  /**
57
69
  * Get the node by its end-to-end index
58
- * @param {number} id - end-to-end index of the node
59
- * @return {object} the node object
70
+ * @param id - end-to-end index of the node
71
+ * @return the node object
60
72
  */
61
- getNodeById(id) {
73
+ getNodeById(id: number): NodeInPage {
62
74
  const pageIndex = Math.floor(id / this.nodesPerPage);
63
75
  const nodeIndex = id % this.nodesPerPage;
64
76
  return this.nodePages[pageIndex].nodes[nodeIndex];
@@ -69,7 +81,7 @@ export default class NodePages {
69
81
  * @param id - end-to-end index of the node
70
82
  * @param materialId - id from scene layer materialDefinitions
71
83
  */
72
- updateMaterialByNodeId(id, materialId) {
84
+ updateMaterialByNodeId(id: number, materialId: number): void {
73
85
  const node = this.getNodeById(id);
74
86
  if (!node.mesh) {
75
87
  return;
@@ -85,7 +97,7 @@ export default class NodePages {
85
97
  * @param id - end-to-end index of the node
86
98
  * @param vertexCount - vertex count for particular node
87
99
  */
88
- updateVertexCountByNodeId(id, vertexCount) {
100
+ updateVertexCountByNodeId(id: number, vertexCount: number): void {
89
101
  const node = this.getNodeById(id);
90
102
  if (!node.mesh) {
91
103
  return;
@@ -97,7 +109,7 @@ export default class NodePages {
97
109
  * Update resource in node.mesh.attribute object by node id
98
110
  * @param id - end-to-end index of the node
99
111
  */
100
- updateNodeAttributeByNodeId(id) {
112
+ updateNodeAttributeByNodeId(id: number): void {
101
113
  const node = this.getNodeById(id);
102
114
  if (!node.mesh) {
103
115
  return;
@@ -110,7 +122,7 @@ export default class NodePages {
110
122
  * @param id - end-to-end index of the node
111
123
  * @param featureCount - features count of the node
112
124
  */
113
- updateFeatureCountByNodeId(id, featureCount) {
125
+ updateFeatureCountByNodeId(id: number, featureCount: number): void {
114
126
  const node = this.getNodeById(id);
115
127
  if (!node.mesh) {
116
128
  return;
@@ -118,7 +130,12 @@ export default class NodePages {
118
130
  node.mesh.geometry.featureCount = featureCount;
119
131
  }
120
132
 
121
- updateTexelCountHintByNodeId(id, texelCountHint) {
133
+ /**
134
+ * Update texelCountHint in node.mesh.material object by node id
135
+ * @param id - end-to-end index of the node
136
+ * @param texelCountHint - texelCountHint of particular node
137
+ */
138
+ updateTexelCountHintByNodeId(id: number, texelCountHint: number): void {
122
139
  const node = this.getNodeById(id);
123
140
  if (!node.mesh || !node.mesh.material) {
124
141
  return;
@@ -128,24 +145,22 @@ export default class NodePages {
128
145
 
129
146
  /**
130
147
  * Add a child id into the parent node.children array
131
- * @param {number | null} parentId - end-to-end parent node index
132
- * @param {number} childId - end-to-end child node index
133
- * @return {void}
148
+ * @param parentId - end-to-end parent node index
149
+ * @param childId - end-to-end child node index
134
150
  */
135
- addChildRelation(parentId, childId) {
136
- if (parentId === null) {
151
+ addChildRelation(parentId: number | undefined, childId: number): void {
152
+ if (parentId === null || parentId === undefined) {
137
153
  return;
138
154
  }
139
155
  const parentNode = this.getNodeById(parentId);
140
- parentNode.children.push(childId);
156
+ parentNode.children?.push(childId);
141
157
  }
142
158
 
143
159
  /**
144
160
  * Update resource index in node.mesh object
145
- * @param {object} node - node object
146
- * @return {void}
161
+ * @param node - node object
147
162
  */
148
- updateResourceInMesh(node) {
163
+ updateResourceInMesh(node: NodeInPage): void {
149
164
  if (node.mesh) {
150
165
  node.mesh.geometry.resource = node.index;
151
166
  }
@@ -153,11 +168,11 @@ export default class NodePages {
153
168
 
154
169
  /**
155
170
  * Put new node in nodePages array
156
- * @param {object} node - node object
157
- * @param {number | null} parentId - index of parent node
158
- * @return {number}
171
+ * @param node - node object
172
+ * @param parentId - index of parent node
173
+ * @return
159
174
  */
160
- push(node, parentId = null) {
175
+ push(node: NodeInPage, parentId?: number): number {
161
176
  let currentNodePage = this.nodePages[this.nodePages.length - 1];
162
177
  if (currentNodePage.nodes.length === this.nodesPerPage) {
163
178
  currentNodePage = {nodes: []};
@@ -174,12 +189,12 @@ export default class NodePages {
174
189
  * Save all the node pages
175
190
  * Run this method when all nodes is pushed in nodePages
176
191
  * @param {string} layers0Path - path of layer
177
- * @param {Object} fileMap
192
+ * @param {Object} fileMap - fileMap which keep info for slpk archive
178
193
  * @param {boolean} slpk
179
194
  * @return {promise}
180
195
  */
181
- async save(layers0Path, fileMap, slpk = false) {
182
- const promises = [];
196
+ async save(layers0Path: string, fileMap: Object, slpk: boolean = false): Promise<void> {
197
+ const promises: Promise<any>[] = [];
183
198
  if (slpk) {
184
199
  for (const [index, nodePage] of this.nodePages.entries()) {
185
200
  const nodePageStr = JSON.stringify(nodePage);
@@ -187,7 +202,7 @@ export default class NodePages {
187
202
  promises.push(this.writeFile(slpkPath, nodePageStr, `${index.toString()}.json`));
188
203
  fileMap[`nodePages/${index.toString()}.json.gz`] = `${slpkPath}.json.gz`;
189
204
  }
190
- const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate);
205
+ const metadata = transform({nodeCount: this.nodesCounter}, metadataTemplate());
191
206
  const compress = false;
192
207
  fileMap['metadata.json'] = await this.writeFile(
193
208
  layers0Path,