@loaders.gl/tile-converter 4.0.0-alpha.4 → 4.0.0-alpha.5

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 (134) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +78 -0
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -0
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +9 -7
  4. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +78 -18
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -0
  7. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +19 -9
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  9. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +4 -7
  10. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts.map +1 -0
  11. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  12. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +9 -0
  13. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -0
  14. package/dist/3d-tiles-converter/helpers/texture-atlas.js +1 -1
  15. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  16. package/dist/3d-tiles-converter/json-templates/tileset.d.ts +15 -0
  17. package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -0
  18. package/dist/3d-tiles-converter/json-templates/tileset.js +12 -9
  19. package/dist/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  20. package/dist/bundle.d.ts +2 -0
  21. package/dist/bundle.d.ts.map +1 -0
  22. package/dist/converter.min.js +22 -22
  23. package/dist/deps-installer/deps-installer.d.ts.map +1 -0
  24. package/dist/deps-installer/deps-installer.js +2 -6
  25. package/dist/deps-installer/deps-installer.js.map +1 -1
  26. package/dist/dist.min.js +86527 -0
  27. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +41 -0
  28. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -0
  29. package/dist/i3s-converter/helpers/coordinate-converter.js +35 -3
  30. package/dist/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  31. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts +9 -0
  32. package/dist/i3s-converter/helpers/create-scene-server-path.d.ts.map +1 -0
  33. package/dist/i3s-converter/helpers/create-scene-server-path.js +2 -2
  34. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  35. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +23 -0
  36. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -0
  37. package/dist/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  38. package/dist/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  39. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -0
  40. package/dist/i3s-converter/helpers/geometry-converter.js +88 -42
  41. package/dist/i3s-converter/helpers/geometry-converter.js.map +1 -1
  42. package/dist/i3s-converter/helpers/node-debug.d.ts +2 -0
  43. package/dist/i3s-converter/helpers/node-debug.d.ts.map +1 -0
  44. package/dist/i3s-converter/helpers/node-debug.js +2 -4
  45. package/dist/i3s-converter/helpers/node-debug.js.map +1 -1
  46. package/dist/i3s-converter/helpers/node-pages.d.ts +83 -111
  47. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -0
  48. package/dist/i3s-converter/helpers/node-pages.js +15 -4
  49. package/dist/i3s-converter/helpers/node-pages.js.map +1 -1
  50. package/dist/i3s-converter/i3s-converter.d.ts +320 -0
  51. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -0
  52. package/dist/i3s-converter/i3s-converter.js +158 -65
  53. package/dist/i3s-converter/i3s-converter.js.map +1 -1
  54. package/dist/i3s-converter/json-templates/layers.d.ts +95 -0
  55. package/dist/i3s-converter/json-templates/layers.d.ts.map +1 -0
  56. package/dist/i3s-converter/json-templates/layers.js +37 -27
  57. package/dist/i3s-converter/json-templates/layers.js.map +1 -1
  58. package/dist/i3s-converter/json-templates/metadata.d.ts +22 -0
  59. package/dist/i3s-converter/json-templates/metadata.d.ts.map +1 -0
  60. package/dist/i3s-converter/json-templates/metadata.js +2 -2
  61. package/dist/i3s-converter/json-templates/metadata.js.map +1 -1
  62. package/dist/i3s-converter/json-templates/node.d.ts +61 -0
  63. package/dist/i3s-converter/json-templates/node.d.ts.map +1 -0
  64. package/dist/i3s-converter/json-templates/node.js +16 -12
  65. package/dist/i3s-converter/json-templates/node.js.map +1 -1
  66. package/dist/i3s-converter/json-templates/scene-server.d.ts +28 -0
  67. package/dist/i3s-converter/json-templates/scene-server.d.ts.map +1 -0
  68. package/dist/i3s-converter/json-templates/scene-server.js +2 -2
  69. package/dist/i3s-converter/json-templates/scene-server.js.map +1 -1
  70. package/dist/i3s-converter/json-templates/shared-resources.d.ts +14 -0
  71. package/dist/i3s-converter/json-templates/shared-resources.d.ts.map +1 -0
  72. package/dist/i3s-converter/json-templates/shared-resources.js +19 -14
  73. package/dist/i3s-converter/json-templates/shared-resources.js.map +1 -1
  74. package/dist/i3s-converter/json-templates/store.d.ts +95 -0
  75. package/dist/i3s-converter/json-templates/store.d.ts.map +1 -0
  76. package/dist/i3s-converter/json-templates/store.js.map +1 -1
  77. package/dist/i3s-converter/types.d.ts +14 -0
  78. package/dist/i3s-converter/types.d.ts.map +1 -0
  79. package/dist/i3s-converter/types.js +2 -0
  80. package/dist/i3s-converter/types.js.map +1 -0
  81. package/dist/i3s-server/app.d.ts +3 -0
  82. package/dist/i3s-server/app.d.ts.map +1 -0
  83. package/dist/i3s-server/controllers/index-controller.d.ts +2 -0
  84. package/dist/i3s-server/controllers/index-controller.d.ts.map +1 -0
  85. package/dist/i3s-server/routes/index.d.ts +3 -0
  86. package/dist/i3s-server/routes/index.d.ts.map +1 -0
  87. package/dist/index.d.ts +5 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  90. package/dist/lib/utils/compress-util.d.ts.map +1 -0
  91. package/dist/lib/utils/file-utils.d.ts.map +1 -0
  92. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -0
  93. package/dist/lib/utils/statistic-utills.d.ts.map +1 -0
  94. package/dist/pgm-loader.d.ts +6 -0
  95. package/dist/pgm-loader.d.ts.map +1 -0
  96. package/dist/pgm-loader.js +3 -3
  97. package/dist/pgm-loader.js.map +1 -1
  98. package/package.json +21 -19
  99. package/src/3d-tiles-converter/3d-tiles-converter.ts +25 -21
  100. package/src/3d-tiles-converter/helpers/{b3dm-converter.js → b3dm-converter.ts} +35 -11
  101. package/src/3d-tiles-converter/helpers/{i3s-obb-to-3d-tiles-obb.js → i3s-obb-to-3d-tiles-obb.ts} +16 -1
  102. package/src/3d-tiles-converter/helpers/texture-atlas.ts +4 -4
  103. package/src/3d-tiles-converter/json-templates/{tileset.js → tileset.ts} +9 -9
  104. package/src/deps-installer/deps-installer.js +2 -2
  105. package/src/i3s-converter/helpers/coordinate-converter.ts +62 -9
  106. package/src/i3s-converter/helpers/{create-scene-server-path.js → create-scene-server-path.ts} +2 -2
  107. package/src/i3s-converter/helpers/{geometry-attributes.js → geometry-attributes.ts} +4 -4
  108. package/src/i3s-converter/helpers/geometry-converter.d.ts +5 -1
  109. package/src/i3s-converter/helpers/geometry-converter.js +110 -33
  110. package/src/i3s-converter/helpers/{node-debug.js → node-debug.ts} +3 -2
  111. package/src/i3s-converter/helpers/{node-pages.js → node-pages.ts} +41 -26
  112. package/src/i3s-converter/i3s-converter.ts +214 -136
  113. package/src/i3s-converter/json-templates/{layers.js → layers.ts} +29 -27
  114. package/src/i3s-converter/json-templates/{metadata.js → metadata.ts} +2 -2
  115. package/src/i3s-converter/json-templates/{node.js → node.ts} +12 -12
  116. package/src/i3s-converter/json-templates/{scene-server.js → scene-server.ts} +2 -2
  117. package/src/i3s-converter/json-templates/{shared-resources.js → shared-resources.ts} +14 -14
  118. package/src/i3s-converter/json-templates/{store.js → store.ts} +0 -0
  119. package/src/i3s-converter/types.ts +14 -0
  120. package/src/lib/utils/{compress-utils.d.ts → compress-util.d.ts} +0 -0
  121. package/src/pgm-loader.ts +2 -2
  122. package/dist/lib/geoid-height-model.d.ts +0 -41
  123. package/dist/lib/geoid-height-model.js +0 -140
  124. package/dist/lib/geoid-height-model.js.map +0 -1
  125. package/dist/lib/pgm-parser.d.ts +0 -14
  126. package/dist/lib/pgm-parser.js +0 -183
  127. package/dist/lib/pgm-parser.js.map +0 -1
  128. package/src/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -23
  129. package/src/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.d.ts +0 -16
  130. package/src/i3s-converter/helpers/node-pages.d.ts +0 -144
  131. package/src/lib/geoid-height-model.d.ts +0 -41
  132. package/src/lib/geoid-height-model.js +0 -239
  133. package/src/lib/pgm-parser.d.ts +0 -14
  134. package/src/lib/pgm-parser.js +0 -179
@@ -0,0 +1,41 @@
1
+ import type { BoundingVolumes, Extent, Mbs, Obb } from '@loaders.gl/i3s';
2
+ import { Vector3 } from '@math.gl/core';
3
+ import TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';
4
+ import { Geoid } from '@math.gl/geoid';
5
+ import { Tileset3D } from '@loaders.gl/tiles';
6
+ /**
7
+ * Create bounding volumes object from tile and geoid height model.
8
+ * @param tile
9
+ * @param geoidHeightModel
10
+ * @returns - Bounding volumes object
11
+ */
12
+ export declare function createBoundingVolumes(tile: TileHeader, geoidHeightModel: Geoid): BoundingVolumes;
13
+ /**
14
+ * Generates bounding volumes from geometry positions
15
+ * @param cartesianPositions
16
+ * @param geoidHeightModel
17
+ */
18
+ export declare function createBoundingVolumesFromGeometry(cartesianPositions: Float32Array, geoidHeightModel: Geoid): {
19
+ mbs: Mbs;
20
+ obb: Obb;
21
+ };
22
+ /**
23
+ * Create array of posisitons where each vertex is vector
24
+ * @param {array} positions
25
+ * @returns {Vector3[]}
26
+ */
27
+ export declare function convertPositionsToVectors(positions: Float32Array): Vector3[];
28
+ /**
29
+ * Convert common coordinate to extent coordinate
30
+ * @param tileset
31
+ * @returns - Extent
32
+ * @todo why lodMetricValue is radius? need to check this function
33
+ */
34
+ export declare function convertCommonToI3SExtentCoordinate(tileset: Tileset3D | null): Extent | null;
35
+ /**
36
+ * Creates oriented boundinb box from mbs.
37
+ * @param mbs - Minimum Bounding Sphere
38
+ * @returns - Oriented BOunding Box
39
+ */
40
+ export declare function createObbFromMbs(mbs: Mbs): Obb;
41
+ //# sourceMappingURL=coordinate-converter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coordinate-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAsB,OAAO,EAAC,MAAM,eAAe,CAAC;AAO3D,OAAO,UAAU,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,GAAG,eAAe,CAiChG;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,kBAAkB,EAAE,YAAY,EAChC,gBAAgB,EAAE,KAAK,GACtB;IAAC,GAAG,EAAE,GAAG,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAC,CAoBtB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,EAAE,CAW5E;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAuB3F;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAK9C"}
@@ -1,6 +1,6 @@
1
1
  import { Matrix3, Quaternion, Vector3 } from '@math.gl/core';
2
2
  import { Ellipsoid } from '@math.gl/geospatial';
3
- import { OrientedBoundingBox } from '@math.gl/culling';
3
+ import { OrientedBoundingBox, makeOrientedBoundingBoxFromPoints, makeBoundingSphereFromPoints } from '@math.gl/culling';
4
4
  export function createBoundingVolumes(tile, geoidHeightModel) {
5
5
  let radius;
6
6
  let halfSize;
@@ -28,9 +28,41 @@ export function createBoundingVolumes(tile, geoidHeightModel) {
28
28
  }
29
29
  };
30
30
  }
31
+ export function createBoundingVolumesFromGeometry(cartesianPositions, geoidHeightModel) {
32
+ const positionVectors = convertPositionsToVectors(cartesianPositions);
33
+ const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);
34
+ const geometryMbs = makeBoundingSphereFromPoints(positionVectors);
35
+ let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());
36
+ let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());
37
+ mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);
38
+ obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);
39
+ return {
40
+ mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],
41
+ obb: {
42
+ center: obbCenter,
43
+ halfSize: geometryObb.halfSize,
44
+ quaternion: geometryObb.quaternion
45
+ }
46
+ };
47
+ }
48
+ export function convertPositionsToVectors(positions) {
49
+ const result = [];
50
+
51
+ for (let i = 0; i < positions.length; i += 3) {
52
+ const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);
53
+ result.push(positionVector);
54
+ }
55
+
56
+ return result;
57
+ }
31
58
  export function convertCommonToI3SExtentCoordinate(tileset) {
32
- const cartesianCenter = tileset.cartesianCenter;
33
- const radius = tileset.lodMetricValue;
59
+ const cartesianCenter = tileset === null || tileset === void 0 ? void 0 : tileset.cartesianCenter;
60
+
61
+ if (!cartesianCenter) {
62
+ return null;
63
+ }
64
+
65
+ const radius = tileset === null || tileset === void 0 ? void 0 : tileset.lodMetricValue;
34
66
  const rightTop = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]), new Vector3());
35
67
  const leftBottom = Ellipsoid.WGS84.cartesianToCartographic(new Vector3(cartesianCenter[0] - radius, cartesianCenter[1] - radius, cartesianCenter[2]), new Vector3());
36
68
  const isFirstRight = rightTop[0] < leftBottom[0];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["Matrix3","Quaternion","Vector3","Ellipsoid","OrientedBoundingBox","createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","WGS84","cartesianToCartographic","center","getHeight","len","fromMatrix3","normalize","mbs","obb","convertCommonToI3SExtentCoordinate","tileset","cartesianCenter","lodMetricValue","rightTop","leftBottom","isFirstRight","isFirstTop","createObbFromMbs","halfAxex"],"mappings":"AAEA,SAAQA,OAAR,EAAiBC,UAAjB,EAA6BC,OAA7B,QAA2C,eAA3C;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,mBAAR,QAAkC,kBAAlC;AAWA,OAAO,SAASC,qBAAT,CACLC,IADK,EAELC,gBAFK,EAGY;AACjB,MAAIC,MAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,UAAJ;AAEA,QAAMC,cAAc,GAAGL,IAAI,CAACK,cAA5B;AACA,QAAMC,kBAAkB,GAAGT,SAAS,CAACU,KAAV,CAAgBC,uBAAhB,CACzBH,cAAc,CAACI,MADU,EAEzB,IAAIb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,CAAC,CAAD,CAJhC,CAAP;AAMD;AAOD,OAAO,SAASI,gBAAT,CAA0BV,GAA1B,EAAyC;AAC9C,QAAMZ,MAAM,GAAGY,GAAG,CAAC,CAAD,CAAlB;AACA,QAAML,MAAM,GAAG,IAAIb,OAAJ,CAAYkB,GAAG,CAAC,CAAD,CAAf,EAAoBA,GAAG,CAAC,CAAD,CAAvB,EAA4BA,GAAG,CAAC,CAAD,CAA/B,CAAf;AACA,QAAMW,QAAQ,GAAG,IAAI/B,OAAJ,CAAY,CAACQ,MAAD,EAAS,CAAT,EAAY,CAAZ,EAAe,CAAf,EAAkBA,MAAlB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmCA,MAAnC,CAAZ,CAAjB;AACA,SAAO,IAAIJ,mBAAJ,CAAwBW,MAAxB,EAAgCgB,QAAhC,CAAP;AACD","sourcesContent":["import type {BoundingVolumes, Extent, Mbs, Obb} from '@loaders.gl/i3s';\n\nimport {Matrix3, Quaternion, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {OrientedBoundingBox} from '@math.gl/culling';\nimport TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';\nimport {GeoidHeightModel} from '../../lib/geoid-height-model';\nimport {Tileset3D} from '@loaders.gl/tiles';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(\n tile: TileHeader,\n geoidHeightModel: GeoidHeightModel\n): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Convert common coordinate to extent coordinate\n * @param tileset\n * @returns - Extent\n */\nexport function convertCommonToI3SExtentCoordinate(tileset: Tileset3D): Extent {\n const cartesianCenter = tileset.cartesianCenter;\n const radius = tileset.lodMetricValue;\n const rightTop = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]),\n new Vector3()\n );\n const leftBottom = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] - radius, cartesianCenter[1] - radius, cartesianCenter[2]),\n new Vector3()\n );\n const isFirstRight = rightTop[0] < leftBottom[0];\n const isFirstTop = rightTop[1] < leftBottom[1];\n\n return [\n isFirstRight ? rightTop[0] : leftBottom[0],\n isFirstTop ? rightTop[1] : leftBottom[1],\n isFirstRight ? leftBottom[0] : rightTop[0],\n isFirstTop ? leftBottom[1] : rightTop[1]\n ];\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
1
+ {"version":3,"sources":["../../../src/i3s-converter/helpers/coordinate-converter.ts"],"names":["Matrix3","Quaternion","Vector3","Ellipsoid","OrientedBoundingBox","makeOrientedBoundingBoxFromPoints","makeBoundingSphereFromPoints","createBoundingVolumes","tile","geoidHeightModel","radius","halfSize","quaternion","boundingVolume","cartographicCenter","WGS84","cartesianToCartographic","center","getHeight","len","fromMatrix3","normalize","mbs","obb","createBoundingVolumesFromGeometry","cartesianPositions","positionVectors","convertPositionsToVectors","geometryObb","geometryMbs","mbsCenter","obbCenter","positions","result","i","length","positionVector","push","convertCommonToI3SExtentCoordinate","tileset","cartesianCenter","lodMetricValue","rightTop","leftBottom","isFirstRight","isFirstTop","createObbFromMbs","halfAxex"],"mappings":"AAEA,SAAQA,OAAR,EAAiBC,UAAjB,EAA6BC,OAA7B,QAA2C,eAA3C;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SACEC,mBADF,EAEEC,iCAFF,EAGEC,4BAHF,QAIO,kBAJP;AAeA,OAAO,SAASC,qBAAT,CAA+BC,IAA/B,EAAiDC,gBAAjD,EAA2F;AAChG,MAAIC,MAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,UAAJ;AAEA,QAAMC,cAAc,GAAGL,IAAI,CAACK,cAA5B;AACA,QAAMC,kBAAkB,GAAGX,SAAS,CAACY,KAAV,CAAgBC,uBAAhB,CACzBH,cAAc,CAACI,MADU,EAEzB,IAAIf,OAAJ,EAFyB,CAA3B;AAIAY,EAAAA,kBAAkB,CAAC,CAAD,CAAlB,GACEA,kBAAkB,CAAC,CAAD,CAAlB,GACAL,gBAAgB,CAACS,SAAjB,CAA2BJ,kBAAkB,CAAC,CAAD,CAA7C,EAAkDA,kBAAkB,CAAC,CAAD,CAApE,CAFF;;AAGA,MAAID,cAAc,YAAYT,mBAA9B,EAAmD;AACjDO,IAAAA,QAAQ,GAAGE,cAAc,CAACF,QAA1B;AACAD,IAAAA,MAAM,GAAG,IAAIR,OAAJ,CAAYS,QAAQ,CAAC,CAAD,CAApB,EAAyBA,QAAQ,CAAC,CAAD,CAAjC,EAAsCA,QAAQ,CAAC,C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AAC,CAAD,CAHlC,EAILG,UAAU,GAAGF,UAAU,CAAC,CAAD,CAAb,GAAmBD,QAAQ,CAAC,CAAD,CAJhC,CAAP;AAMD;AAOD,OAAO,SAASI,gBAAT,CAA0BxB,GAA1B,EAAyC;AAC9C,QAAMZ,MAAM,GAAGY,GAAG,CAAC,CAAD,CAAlB;AACA,QAAML,MAAM,GAAG,IAAIf,OAAJ,CAAYoB,GAAG,CAAC,CAAD,CAAf,EAAoBA,GAAG,CAAC,CAAD,CAAvB,EAA4BA,GAAG,CAAC,CAAD,CAA/B,CAAf;AACA,QAAMyB,QAAQ,GAAG,IAAI/C,OAAJ,CAAY,CAACU,MAAD,EAAS,CAAT,EAAY,CAAZ,EAAe,CAAf,EAAkBA,MAAlB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgC,CAAhC,EAAmCA,MAAnC,CAAZ,CAAjB;AACA,SAAO,IAAIN,mBAAJ,CAAwBa,MAAxB,EAAgC8B,QAAhC,CAAP;AACD","sourcesContent":["import type {BoundingVolumes, Extent, Mbs, Obb} from '@loaders.gl/i3s';\n\nimport {Matrix3, Quaternion, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {\n OrientedBoundingBox,\n makeOrientedBoundingBoxFromPoints,\n makeBoundingSphereFromPoints\n} from '@math.gl/culling';\nimport TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';\nimport {Geoid} from '@math.gl/geoid';\nimport {Tileset3D} from '@loaders.gl/tiles';\n\n/**\n * Create bounding volumes object from tile and geoid height model.\n * @param tile\n * @param geoidHeightModel\n * @returns - Bounding volumes object\n */\nexport function createBoundingVolumes(tile: TileHeader, geoidHeightModel: Geoid): BoundingVolumes {\n let radius;\n let halfSize;\n let quaternion;\n\n const boundingVolume = tile.boundingVolume;\n const cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(\n boundingVolume.center,\n new Vector3()\n );\n cartographicCenter[2] =\n cartographicCenter[2] -\n geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);\n if (boundingVolume instanceof OrientedBoundingBox) {\n halfSize = boundingVolume.halfSize;\n radius = new Vector3(halfSize[0], halfSize[1], halfSize[2]).len();\n quaternion = boundingVolume.quaternion;\n } else {\n radius = tile.boundingVolume.radius;\n halfSize = [radius, radius, radius];\n quaternion = new Quaternion()\n .fromMatrix3(new Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))\n .normalize();\n }\n\n return {\n mbs: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2], radius],\n obb: {\n center: [cartographicCenter[0], cartographicCenter[1], cartographicCenter[2]],\n halfSize,\n quaternion\n }\n };\n}\n\n/**\n * Generates bounding volumes from geometry positions\n * @param cartesianPositions\n * @param geoidHeightModel\n */\nexport function createBoundingVolumesFromGeometry(\n cartesianPositions: Float32Array,\n geoidHeightModel: Geoid\n): {mbs: Mbs; obb: Obb} {\n const positionVectors = convertPositionsToVectors(cartesianPositions);\n\n const geometryObb = makeOrientedBoundingBoxFromPoints(positionVectors);\n const geometryMbs = makeBoundingSphereFromPoints(positionVectors);\n\n let mbsCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new Vector3());\n let obbCenter = Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new Vector3());\n\n mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);\n obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);\n\n return {\n mbs: [mbsCenter[0], mbsCenter[1], mbsCenter[2], geometryMbs.radius],\n obb: {\n center: obbCenter,\n halfSize: geometryObb.halfSize,\n quaternion: geometryObb.quaternion\n }\n };\n}\n\n/**\n * Create array of posisitons where each vertex is vector\n * @param {array} positions\n * @returns {Vector3[]}\n */\nexport function convertPositionsToVectors(positions: Float32Array): Vector3[] {\n const result: Vector3[] = [];\n\n for (let i = 0; i < positions.length; i += 3) {\n // TODO: (perf) new Vector3 is not optimal but required in `makeOrientedBoundingBoxFromPoints`.\n // modify `makeOrientedBoundingBoxFromPoints` to use scratch vectors\n const positionVector = new Vector3([positions[i], positions[i + 1], positions[i + 2]]);\n result.push(positionVector);\n }\n\n return result;\n}\n\n/**\n * Convert common coordinate to extent coordinate\n * @param tileset\n * @returns - Extent\n * @todo why lodMetricValue is radius? need to check this function\n */\nexport function convertCommonToI3SExtentCoordinate(tileset: Tileset3D | null): Extent | null {\n const cartesianCenter = tileset?.cartesianCenter;\n if (!cartesianCenter) {\n return null;\n }\n const radius = tileset?.lodMetricValue;\n const rightTop = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]),\n new Vector3()\n );\n const leftBottom = Ellipsoid.WGS84.cartesianToCartographic(\n new Vector3(cartesianCenter[0] - radius, cartesianCenter[1] - radius, cartesianCenter[2]),\n new Vector3()\n );\n const isFirstRight = rightTop[0] < leftBottom[0];\n const isFirstTop = rightTop[1] < leftBottom[1];\n\n return [\n isFirstRight ? rightTop[0] : leftBottom[0],\n isFirstTop ? rightTop[1] : leftBottom[1],\n isFirstRight ? leftBottom[0] : rightTop[0],\n isFirstTop ? leftBottom[1] : rightTop[1]\n ];\n}\n\n/**\n * Creates oriented boundinb box from mbs.\n * @param mbs - Minimum Bounding Sphere\n * @returns - Oriented BOunding Box\n */\nexport function createObbFromMbs(mbs: Mbs): Obb {\n const radius = mbs[3];\n const center = new Vector3(mbs[0], mbs[1], mbs[2]);\n const halfAxex = new Matrix3([radius, 0, 0, 0, radius, 0, 0, 0, radius]);\n return new OrientedBoundingBox(center, halfAxex);\n}\n"],"file":"coordinate-converter.js"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Form and save sceneServer meta data into a file
3
+ * @param {string} layerName - layer name to display
4
+ * @param {object} layers0 - layer object embedded into sceneServer meta data
5
+ * @param {string} rootPath - root path of new converted tileset
6
+ * @return {promise}
7
+ */
8
+ export declare function createSceneServerPath(layerName: any, layers0: any, rootPath: any): Promise<void>;
9
+ //# sourceMappingURL=create-scene-server-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-scene-server-path.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/create-scene-server-path.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,SAAS,KAAA,EAAE,OAAO,KAAA,EAAE,QAAQ,KAAA,iBAUvE"}
@@ -1,7 +1,7 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import transform from 'json-map-transform';
3
3
  import { join } from 'path';
4
- import { SCENE_SERVER_TEMPLATE } from '../json-templates/scene-server';
4
+ import { SCENE_SERVER as sceneServerTemplate } from '../json-templates/scene-server';
5
5
  import { writeFile } from '../../lib/utils/file-utils';
6
6
  export async function createSceneServerPath(layerName, layers0, rootPath) {
7
7
  const sceneServerData = {
@@ -9,7 +9,7 @@ export async function createSceneServerPath(layerName, layers0, rootPath) {
9
9
  layerName,
10
10
  layers0
11
11
  };
12
- const sceneServer = transform(sceneServerData, SCENE_SERVER_TEMPLATE);
12
+ const sceneServer = transform(sceneServerData, sceneServerTemplate());
13
13
  const nodePagePath = join(rootPath, 'SceneServer');
14
14
  await writeFile(nodePagePath, JSON.stringify(sceneServer));
15
15
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/i3s-converter/helpers/create-scene-server-path.js"],"names":["v4","uuidv4","transform","join","SCENE_SERVER_TEMPLATE","writeFile","createSceneServerPath","layerName","layers0","rootPath","sceneServerData","serviceItemId","replace","sceneServer","nodePagePath","JSON","stringify"],"mappings":"AAAA,SAAQA,EAAE,IAAIC,MAAd,QAA2B,MAA3B;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAEA,SAAQC,qBAAR,QAAoC,gCAApC;AACA,SAAQC,SAAR,QAAwB,4BAAxB;AASA,OAAO,eAAeC,qBAAf,CAAqCC,SAArC,EAAgDC,OAAhD,EAAyDC,QAAzD,EAAmE;AACxE,QAAMC,eAAe,GAAG;AACtBC,IAAAA,aAAa,EAAEV,MAAM,GAAGW,OAAT,CAAiB,KAAjB,EAAwB,EAAxB,CADO;AAEtBL,IAAAA,SAFsB;AAGtBC,IAAAA;AAHsB,GAAxB;AAMA,QAAMK,WAAW,GAAGX,SAAS,CAACQ,eAAD,EAAkBN,qBAAlB,CAA7B;AACA,QAAMU,YAAY,GAAGX,IAAI,CAACM,QAAD,EAAW,aAAX,CAAzB;AACA,QAAMJ,SAAS,CAACS,YAAD,EAAeC,IAAI,CAACC,SAAL,CAAeH,WAAf,CAAf,CAAf;AACD","sourcesContent":["import {v4 as uuidv4} from 'uuid';\nimport transform from 'json-map-transform';\nimport {join} from 'path';\n\nimport {SCENE_SERVER_TEMPLATE} from '../json-templates/scene-server';\nimport {writeFile} from '../../lib/utils/file-utils';\n\n/**\n * Form and save sceneServer meta data into a file\n * @param {string} layerName - layer name to display\n * @param {object} layers0 - layer object embedded into sceneServer meta data\n * @param {string} rootPath - root path of new converted tileset\n * @return {promise}\n */\nexport async function createSceneServerPath(layerName, layers0, rootPath) {\n const sceneServerData = {\n serviceItemId: uuidv4().replace(/-/gi, ''),\n layerName,\n layers0\n };\n\n const sceneServer = transform(sceneServerData, SCENE_SERVER_TEMPLATE);\n const nodePagePath = join(rootPath, 'SceneServer');\n await writeFile(nodePagePath, JSON.stringify(sceneServer));\n}\n"],"file":"create-scene-server-path.js"}
1
+ {"version":3,"sources":["../../../src/i3s-converter/helpers/create-scene-server-path.ts"],"names":["v4","uuidv4","transform","join","SCENE_SERVER","sceneServerTemplate","writeFile","createSceneServerPath","layerName","layers0","rootPath","sceneServerData","serviceItemId","replace","sceneServer","nodePagePath","JSON","stringify"],"mappings":"AAAA,SAAQA,EAAE,IAAIC,MAAd,QAA2B,MAA3B;AACA,OAAOC,SAAP,MAAsB,oBAAtB;AACA,SAAQC,IAAR,QAAmB,MAAnB;AAEA,SAAQC,YAAY,IAAIC,mBAAxB,QAAkD,gCAAlD;AACA,SAAQC,SAAR,QAAwB,4BAAxB;AASA,OAAO,eAAeC,qBAAf,CAAqCC,SAArC,EAAgDC,OAAhD,EAAyDC,QAAzD,EAAmE;AACxE,QAAMC,eAAe,GAAG;AACtBC,IAAAA,aAAa,EAAEX,MAAM,GAAGY,OAAT,CAAiB,KAAjB,EAAwB,EAAxB,CADO;AAEtBL,IAAAA,SAFsB;AAGtBC,IAAAA;AAHsB,GAAxB;AAMA,QAAMK,WAAW,GAAGZ,SAAS,CAACS,eAAD,EAAkBN,mBAAmB,EAArC,CAA7B;AACA,QAAMU,YAAY,GAAGZ,IAAI,CAACO,QAAD,EAAW,aAAX,CAAzB;AACA,QAAMJ,SAAS,CAACS,YAAD,EAAeC,IAAI,CAACC,SAAL,CAAeH,WAAf,CAAf,CAAf;AACD","sourcesContent":["import {v4 as uuidv4} from 'uuid';\nimport transform from 'json-map-transform';\nimport {join} from 'path';\n\nimport {SCENE_SERVER as sceneServerTemplate} from '../json-templates/scene-server';\nimport {writeFile} from '../../lib/utils/file-utils';\n\n/**\n * Form and save sceneServer meta data into a file\n * @param {string} layerName - layer name to display\n * @param {object} layers0 - layer object embedded into sceneServer meta data\n * @param {string} rootPath - root path of new converted tileset\n * @return {promise}\n */\nexport async function createSceneServerPath(layerName, layers0, rootPath) {\n const sceneServerData = {\n serviceItemId: uuidv4().replace(/-/gi, ''),\n layerName,\n layers0\n };\n\n const sceneServer = transform(sceneServerData, sceneServerTemplate());\n const nodePagePath = join(rootPath, 'SceneServer');\n await writeFile(nodePagePath, JSON.stringify(sceneServer));\n}\n"],"file":"create-scene-server-path.js"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Generate geometry attributes with faceRange and featureCount
3
+ * @param {Object} attributes
4
+ * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.
5
+ */
6
+ export declare function generateAttributes(attributes: any): {
7
+ faceRange: Uint32Array;
8
+ featureIds: number[];
9
+ featureCount: number;
10
+ positions: any;
11
+ normals: any;
12
+ texCoords: any;
13
+ colors: any;
14
+ } | {
15
+ faceRange: Uint32Array;
16
+ featureIds: any[];
17
+ positions: Float32Array;
18
+ normals: Float32Array;
19
+ colors: Uint8Array;
20
+ texCoords: Float32Array;
21
+ featureCount: number;
22
+ };
23
+ //# sourceMappingURL=geometry-attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry-attributes.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,KAAA;;;;;;;;;;;;;;;;EAsB5C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/i3s-converter/helpers/geometry-attributes.js"],"names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":"AAAA,SAAQA,sBAAR,QAAqC,0BAArC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,kCAAkC,GAAG,CAA3C;AAOA,OAAO,SAASC,kBAAT,CAA4BC,UAA5B,EAAwC;AAC7C,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J,CAAgBmD,KAAhB,CAAlB;AACA,SAAO;AAACpD,IAAAA,SAAD;AAAYE,IAAAA,UAAZ;AAAwBT,IAAAA,SAAxB;AAAmCC,IAAAA,OAAnC;AAA4CE,IAAAA,MAA5C;AAAoDD,IAAAA;AAApD,GAAP;AACD","sourcesContent":["import {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param {Object} attributes\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nexport function generateAttributes(attributes) {\n const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const {faceRange, featureCount, featureIds} = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({faceRange, featureIds, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds\n );\n return {featureCount, ...groupedAttributes};\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param {Object} featureIndices\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices) {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList = [];\n const featureIds = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param {Object} attributes\n * @returns {Array} sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes) {\n const {featureIds, positions, normals, colors, texCoords, faceRange} = attributes;\n const groupedData = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param {String} attributeName\n * @param {Number} startIndex\n * @param {Number} endIndex\n * @returns {Number} - sliced count\n */\nfunction getSliceAttributeCount(attributeName, startIndex, endIndex) {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param {Array} sortedData\n * @returns {Array} - unique list of objects\n */\nfunction unifyObjectsByFeatureId(sortedData) {\n const uniqueObjects = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param {Array} unifiedObjects\n * @returns {Object} - ugenerated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(unifiedObjects) {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords};\n}\n"],"file":"geometry-attributes.js"}
1
+ {"version":3,"sources":["../../../src/i3s-converter/helpers/geometry-attributes.ts"],"names":["concatenateTypedArrays","VALUES_PER_VERTEX","POSITIONS_AND_NORMALS_PER_TRIANGLE","generateAttributes","attributes","positions","normals","texCoords","colors","featureIndices","triangleCount","length","faceRange","Uint32Array","featureIds","featureCount","calculateFaceRangesAndFeaturesCount","attributeObjects","makeAttributeObjects","unifiedAttributeObjectsByFeatureIds","unifyObjectsByFeatureId","groupedAttributes","groupAttributesAndRangesByFeatureId","rangeIndex","featureIndex","currentFeatureId","faceRangeList","uniqueFeatureIds","index","includes","push","groupedData","positionsList","Float32Array","normalsList","colorsList","Uint8Array","texCoordsList","faceRangeIndex","startIndex","endIndex","positionsCount","getSliceAttributeCount","normalsCount","colorsCount","texCoordsCount","featureId","slice","sort","first","second","attributeName","colorsPerVertex","texCoordsPerVertex","trianglesCount","vertexCount","sortedData","uniqueObjects","currentObject","existedObject","find","obj","unifiedObjects","firstAttributeObject","range","objIndex","sum","currentAttributesObject","groupedObject"],"mappings":"AAAA,SAAQA,sBAAR,QAAqC,0BAArC;AAEA,MAAMC,iBAAiB,GAAG,CAA1B;AACA,MAAMC,kCAAkC,GAAG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V,GAAmBT,kCAAnB,GAAwD,CAAnE;AAEA,QAAMU,SAAS,GAAG,IAAIC,WAAJ,CAAgBmD,KAAhB,CAAlB;AACA,SAAO;AAACpD,IAAAA,SAAD;AAAYE,IAAAA,UAAZ;AAAwBT,IAAAA,SAAxB;AAAmCC,IAAAA,OAAnC;AAA4CE,IAAAA,MAA5C;AAAoDD,IAAAA;AAApD,GAAP;AACD","sourcesContent":["import {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nconst VALUES_PER_VERTEX = 3;\nconst POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;\n\n/**\n * Generate geometry attributes with faceRange and featureCount\n * @param {Object} attributes\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nexport function generateAttributes(attributes) {\n const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;\n\n if (!featureIndices.length) {\n return {\n faceRange: new Uint32Array([0, triangleCount - 1]),\n featureIds: [0],\n featureCount: 1,\n positions,\n normals,\n texCoords,\n colors\n };\n }\n\n const {faceRange, featureCount, featureIds} = calculateFaceRangesAndFeaturesCount(featureIndices);\n const attributeObjects = makeAttributeObjects({faceRange, featureIds, ...attributes});\n const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);\n const groupedAttributes = groupAttributesAndRangesByFeatureId(\n unifiedAttributeObjectsByFeatureIds\n );\n return {featureCount, ...groupedAttributes};\n}\n\n/**\n * Calculates face Ranges and feature count based on featureIndices.\n * @param {Object} featureIndices\n * @returns {Object} Object with featureCount, reordered attributes and changed faceRange.\n */\nfunction calculateFaceRangesAndFeaturesCount(featureIndices) {\n let rangeIndex = 1;\n let featureIndex = 1;\n let currentFeatureId = featureIndices[0];\n const faceRangeList: any[] = [];\n const featureIds: any[] = [];\n const uniqueFeatureIds = [currentFeatureId];\n\n faceRangeList[0] = 0;\n featureIds[0] = currentFeatureId;\n\n for (let index = 1; index < featureIndices.length; index++) {\n if (currentFeatureId !== featureIndices[index]) {\n faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;\n faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;\n featureIds[featureIndex] = featureIndices[index];\n\n if (!uniqueFeatureIds.includes(featureIndices[index])) {\n uniqueFeatureIds.push(featureIndices[index]);\n }\n\n rangeIndex += 2;\n featureIndex += 1;\n }\n currentFeatureId = featureIndices[index];\n }\n\n faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;\n\n const faceRange = new Uint32Array(faceRangeList);\n const featureCount = uniqueFeatureIds.length;\n\n return {faceRange, featureCount, featureIds};\n}\n\n/**\n * Generate list of attribute object grouped by feature ids.\n * @param {Object} attributes\n * @returns {Array} sorted list of attribute objects.\n */\nfunction makeAttributeObjects(attributes) {\n const {featureIds, positions, normals, colors, texCoords, faceRange} = attributes;\n const groupedData: any[] = [];\n\n let positionsList = new Float32Array(positions);\n let normalsList = new Float32Array(normals);\n let colorsList = new Uint8Array(colors);\n let texCoordsList = new Float32Array(texCoords);\n\n let faceRangeIndex = 0;\n\n for (let index = 0; index < featureIds.length; index++) {\n const startIndex = faceRange[index + faceRangeIndex];\n const endIndex = faceRange[index + faceRangeIndex + 1];\n\n const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);\n const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);\n const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);\n const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);\n\n groupedData.push({\n featureId: featureIds[index],\n positions: positionsList.slice(0, positionsCount),\n normals: normalsList.slice(0, normalsCount),\n colors: colorsList.slice(0, colorsCount),\n texCoords: texCoordsList.slice(0, texCoordsCount)\n });\n\n positionsList = positionsList.slice(positionsCount);\n normalsList = normalsList.slice(normalsCount);\n colorsList = colorsList.slice(colorsCount);\n texCoordsList = texCoordsList.slice(texCoordsCount);\n\n faceRangeIndex += 1;\n }\n\n return groupedData.sort((first, second) => first.featureId - second.featureId);\n}\n\n/**\n * Generate sliced count for generating attribute objects depends on attribute name and range.\n * @param {String} attributeName\n * @param {Number} startIndex\n * @param {Number} endIndex\n * @returns {Number} - sliced count\n */\nfunction getSliceAttributeCount(attributeName, startIndex, endIndex) {\n const colorsPerVertex = 4;\n const texCoordsPerVertex = 2;\n\n const trianglesCount = endIndex - startIndex + 1;\n const vertexCount = trianglesCount * 3;\n\n switch (attributeName) {\n case 'positions':\n case 'normals':\n return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;\n case 'colors':\n return vertexCount * colorsPerVertex;\n case 'texCoords':\n return vertexCount * texCoordsPerVertex;\n default:\n return 0;\n }\n}\n\n/**\n * Generates unique object list depends on feature ids and concantenate their attributes.\n * @param {Array} sortedData\n * @returns {Array} - unique list of objects\n */\nfunction unifyObjectsByFeatureId(sortedData) {\n const uniqueObjects: any[] = [];\n\n for (let index = 0; index < sortedData.length; index++) {\n const currentObject = sortedData[index];\n const existedObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);\n\n if (existedObject) {\n existedObject.positions = concatenateTypedArrays(\n existedObject.positions,\n currentObject.positions\n );\n existedObject.normals = concatenateTypedArrays(existedObject.normals, currentObject.normals);\n existedObject.colors = concatenateTypedArrays(existedObject.colors, currentObject.colors);\n existedObject.texCoords = concatenateTypedArrays(\n existedObject.texCoords,\n currentObject.texCoords\n );\n } else {\n uniqueObjects.push(currentObject);\n }\n }\n\n return uniqueObjects;\n}\n\n/**\n * Generates attribute objects with new faceRange and reordered attributes.\n * @param {Array} unifiedObjects\n * @returns {Object} - ugenerated attributes with new faceRange.\n */\nfunction groupAttributesAndRangesByFeatureId(unifiedObjects) {\n const firstAttributeObject = unifiedObjects[0];\n const featureIds = [firstAttributeObject.featureId];\n\n let positions = new Float32Array(firstAttributeObject.positions);\n let normals = new Float32Array(firstAttributeObject.normals);\n let colors = new Uint8Array(firstAttributeObject.colors);\n let texCoords = new Float32Array(firstAttributeObject.texCoords);\n const range = [0];\n\n let objIndex = 0;\n let sum = 0;\n\n for (let index = 1; index < unifiedObjects.length; index++) {\n const currentAttributesObject = unifiedObjects[index];\n featureIds.push(currentAttributesObject.featureId);\n\n positions = concatenateTypedArrays(positions, currentAttributesObject.positions);\n normals = concatenateTypedArrays(normals, currentAttributesObject.normals);\n colors = concatenateTypedArrays(colors, currentAttributesObject.colors);\n texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);\n\n const groupedObject = unifiedObjects[objIndex];\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);\n range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);\n\n sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;\n objIndex += 1;\n }\n\n range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);\n\n const faceRange = new Uint32Array(range);\n return {faceRange, featureIds, positions, normals, colors, texCoords};\n}\n"],"file":"geometry-attributes.js"}
@@ -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
  >;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-converter.js"],"names":[],"mappings":"AA2BA;;;;;;;;;;YAuDC"}
@@ -5,6 +5,7 @@ import { encode, assert } from '@loaders.gl/core';
5
5
  import { concatenateArrayBuffers, concatenateTypedArrays } from '@loaders.gl/loader-utils';
6
6
  import md5 from 'md5';
7
7
  import { generateAttributes } from './geometry-attributes';
8
+ import { createBoundingVolumesFromGeometry } from './coordinate-converter';
8
9
  const VALUES_PER_VERTEX = 3;
9
10
  const VALUES_PER_TEX_COORD = 2;
10
11
  const VALUES_PER_COLOR_ELEMENT = 4;
@@ -13,9 +14,15 @@ const SHORT_INT_TYPE = 'Int32';
13
14
  const DOUBLE_TYPE = 'Float64';
14
15
  const OBJECT_ID_TYPE = 'Oid32';
15
16
  const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
16
- export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco) {
17
+ let scratchVector = new Vector3();
18
+ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel) {
19
+ const useCartesianPositions = generateBoundingVolumes;
17
20
  const materialAndTextureList = convertMaterials(tileContent);
18
- const convertedAttributesMap = convertAttributes(tileContent);
21
+ const convertedAttributesMap = convertAttributes(tileContent, useCartesianPositions);
22
+
23
+ if (generateBoundingVolumes) {
24
+ _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
25
+ }
19
26
 
20
27
  if (convertedAttributesMap.has('default')) {
21
28
  materialAndTextureList.push({
@@ -29,7 +36,7 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
29
36
  materials = []
30
37
  } = tileContent.gltf;
31
38
 
32
- if (!materials.length === 0) {
39
+ if (!(materials !== null && materials !== void 0 && materials.length)) {
33
40
  materials.push({
34
41
  id: 'default'
35
42
  });
@@ -67,6 +74,22 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
67
74
  return result;
68
75
  }
69
76
 
77
+ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
78
+ for (const attributes of convertedAttributesMap.values()) {
79
+ const boundingVolumes = createBoundingVolumesFromGeometry(attributes.positions, geoidHeightModel);
80
+ attributes.boundingVolumes = boundingVolumes;
81
+ const cartographicOrigin = boundingVolumes.obb.center;
82
+
83
+ for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
84
+ const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
85
+ Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
86
+ scratchVector[2] = scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
87
+ scratchVector = scratchVector.subtract(cartographicOrigin);
88
+ attributes.positions.set(scratchVector, index);
89
+ }
90
+ }
91
+ }
92
+
70
93
  async function _makeNodeResources({
71
94
  convertedAttributes,
72
95
  material,
@@ -77,6 +100,7 @@ async function _makeNodeResources({
77
100
  attributeStorageInfo,
78
101
  draco
79
102
  }) {
103
+ const boundingVolumes = convertedAttributes.boundingVolumes;
80
104
  const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
81
105
  const triangleCount = vertexCount / 3;
82
106
  const {
@@ -117,11 +141,12 @@ async function _makeNodeResources({
117
141
  meshMaterial: material,
118
142
  vertexCount,
119
143
  attributes,
120
- featureCount
144
+ featureCount,
145
+ boundingVolumes
121
146
  };
122
147
  }
123
148
 
124
- function convertAttributes(tileContent) {
149
+ function convertAttributes(tileContent, useCartesianPositions) {
125
150
  var _tileContent$gltf$sce;
126
151
 
127
152
  const attributesMap = new Map();
@@ -134,12 +159,13 @@ function convertAttributes(tileContent) {
134
159
  normals: new Float32Array(0),
135
160
  texCoords: new Float32Array(0),
136
161
  colors: new Uint8Array(0),
137
- featureIndices: []
162
+ featureIndices: [],
163
+ boundingVolumes: null
138
164
  });
139
165
  }
140
166
 
141
167
  const nodes = (tileContent.gltf.scene || ((_tileContent$gltf$sce = tileContent.gltf.scenes) === null || _tileContent$gltf$sce === void 0 ? void 0 : _tileContent$gltf$sce[0]) || tileContent.gltf).nodes;
142
- convertNodes(nodes, tileContent, attributesMap);
168
+ convertNodes(nodes, tileContent, attributesMap, useCartesianPositions);
143
169
 
144
170
  for (const attrKey of attributesMap.keys()) {
145
171
  const attributes = attributesMap.get(attrKey);
@@ -149,51 +175,60 @@ function convertAttributes(tileContent) {
149
175
  continue;
150
176
  }
151
177
 
152
- const vertexCount = attributes.positions.length / VALUES_PER_VERTEX;
153
-
154
- if (!attributes.colors.length) {
155
- attributes.colors = new Uint8Array(vertexCount * VALUES_PER_COLOR_ELEMENT);
156
-
157
- for (let index = 0; index < attributes.colors.length; index += 4) {
158
- attributes.colors.set([255, 255, 255, 255], index);
159
- }
160
- }
161
-
162
- if (!attributes.texCoords.length) {
163
- attributes.texCoords = new Float32Array(vertexCount * VALUES_PER_TEX_COORD);
164
-
165
- for (let index = 0; index < attributes.texCoords.length; index += 2) {
166
- attributes.texCoords.set([1, 1], index);
167
- }
168
- }
169
-
170
178
  attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
171
179
  }
172
180
 
173
181
  return attributesMap;
174
182
  }
175
183
 
176
- function convertNodes(nodes, tileContent, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
184
+ function convertNodes(nodes, tileContent, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
177
185
  if (nodes) {
178
186
  for (const node of nodes) {
179
- convertNode(node, tileContent, attributesMap, matrix);
187
+ convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix);
180
188
  }
181
189
  }
182
190
  }
183
191
 
184
- function convertNode(node, tileContent, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
185
- const nodeMatrix = node.matrix;
186
- const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
192
+ function getCompositeTransformationMatrix(node, matrix) {
193
+ let transformationMatrix = matrix;
194
+ const {
195
+ matrix: nodeMatrix,
196
+ rotation,
197
+ scale,
198
+ translation
199
+ } = node;
200
+
201
+ if (nodeMatrix) {
202
+ transformationMatrix = matrix.multiplyRight(nodeMatrix);
203
+ }
204
+
205
+ if (rotation) {
206
+ transformationMatrix = transformationMatrix.rotateXYZ(rotation);
207
+ }
208
+
209
+ if (scale) {
210
+ transformationMatrix = transformationMatrix.scale(scale);
211
+ }
212
+
213
+ if (translation) {
214
+ transformationMatrix = transformationMatrix.translate(translation);
215
+ }
216
+
217
+ return transformationMatrix;
218
+ }
219
+
220
+ function convertNode(node, tileContent, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
221
+ const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
187
222
  const mesh = node.mesh;
188
223
 
189
224
  if (mesh) {
190
- convertMesh(mesh, tileContent, attributesMap, compositeMatrix);
225
+ convertMesh(mesh, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
191
226
  }
192
227
 
193
- convertNodes(node.children, tileContent, attributesMap, compositeMatrix);
228
+ convertNodes(node.children, tileContent, attributesMap, useCartesianPositions, transformationMatrix);
194
229
  }
195
230
 
196
- function convertMesh(mesh, content, attributesMap, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
231
+ function convertMesh(mesh, content, attributesMap, useCartesianPositions = false, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
197
232
  for (const primitive of mesh.primitives) {
198
233
  let outputAttributes = null;
199
234
 
@@ -211,7 +246,8 @@ function convertMesh(mesh, content, attributesMap, matrix = new Matrix4([1, 0, 0
211
246
  cartesianModelMatrix: content.cartesianModelMatrix,
212
247
  nodeMatrix: matrix,
213
248
  indices: primitive.indices.value,
214
- attributeSpecificTransformation: transformVertexPositions
249
+ attributeSpecificTransformation: transformVertexPositions,
250
+ useCartesianPositions
215
251
  }));
216
252
  outputAttributes.normals = concatenateTypedArrays(outputAttributes.normals, transformVertexArray({
217
253
  vertices: attributes.NORMAL && attributes.NORMAL.value,
@@ -219,7 +255,8 @@ function convertMesh(mesh, content, attributesMap, matrix = new Matrix4([1, 0, 0
219
255
  cartesianModelMatrix: content.cartesianModelMatrix,
220
256
  nodeMatrix: matrix,
221
257
  indices: primitive.indices.value,
222
- attributeSpecificTransformation: transformVertexNormals
258
+ attributeSpecificTransformation: transformVertexNormals,
259
+ useCartesianPositions: false
223
260
  }));
224
261
  outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
225
262
  outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
@@ -256,7 +293,8 @@ function transformVertexPositions(vertexVector, calleeArgs) {
256
293
  const {
257
294
  cartesianModelMatrix,
258
295
  cartographicOrigin,
259
- nodeMatrix
296
+ nodeMatrix,
297
+ useCartesianPositions
260
298
  } = calleeArgs;
261
299
 
262
300
  if (nodeMatrix) {
@@ -264,6 +302,11 @@ function transformVertexPositions(vertexVector, calleeArgs) {
264
302
  }
265
303
 
266
304
  vertexVector = vertexVector.transform(cartesianModelMatrix);
305
+
306
+ if (useCartesianPositions) {
307
+ return vertexVector;
308
+ }
309
+
267
310
  Ellipsoid.WGS84.cartesianToCartographic([vertexVector[0], vertexVector[1], vertexVector[2]], vertexVector);
268
311
  vertexVector = vertexVector.subtract(cartographicOrigin);
269
312
  return vertexVector;
@@ -284,12 +327,13 @@ function transformVertexNormals(vertexVector, calleeArgs) {
284
327
  }
285
328
 
286
329
  function flattenTexCoords(texCoords, indices) {
330
+ const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
331
+
287
332
  if (!texCoords) {
288
- return new Float32Array(0);
333
+ newTexCoords.fill(1);
334
+ return newTexCoords;
289
335
  }
290
336
 
291
- const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
292
-
293
337
  for (let i = 0; i < indices.length; i++) {
294
338
  const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
295
339
  const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
@@ -301,13 +345,15 @@ function flattenTexCoords(texCoords, indices) {
301
345
  }
302
346
 
303
347
  function flattenColors(colorsAttribute, indices) {
348
+ const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
349
+ const newColors = new Uint8Array(indices.length * components);
350
+
304
351
  if (!colorsAttribute) {
305
- return new Uint8Array(0);
352
+ newColors.fill(255);
353
+ return newColors;
306
354
  }
307
355
 
308
- const components = colorsAttribute.components;
309
356
  const colors = colorsAttribute.value;
310
- const newColors = new Uint8Array(indices.length * components);
311
357
 
312
358
  for (let i = 0; i < indices.length; i++) {
313
359
  const colorIndex = indices[i] * components;