@loaders.gl/tile-converter 4.0.0-alpha.6 → 4.0.0-alpha.8

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 (176) hide show
  1. package/bin/converter.js +1 -1
  2. package/dist/3d-tiles-attributes-worker.js +2 -2
  3. package/dist/3d-tiles-attributes-worker.js.map +3 -3
  4. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  5. package/dist/3d-tiles-converter/3d-tiles-converter.js +4 -3
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -8
  7. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +2 -15
  9. package/dist/converter.min.js +75 -76
  10. package/dist/deps-installer/deps-installer.js +4 -4
  11. package/dist/dist.min.js +2529 -1884
  12. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  13. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +0 -3
  14. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  15. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +2 -10
  16. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  17. package/dist/es5/deps-installer/deps-installer.js +5 -5
  18. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  19. package/dist/es5/i3s-attributes-worker.js +1 -1
  20. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  21. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +4 -4
  22. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +6 -7
  24. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js +49 -30
  26. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  27. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +46 -16
  28. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  29. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +82 -0
  30. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  31. package/dist/es5/i3s-converter/helpers/node-index-document.js +74 -45
  32. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
  33. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +111 -0
  34. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  35. package/dist/es5/i3s-converter/helpers/tileset-traversal.js +82 -0
  36. package/dist/es5/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  37. package/dist/es5/i3s-converter/i3s-converter.js +545 -523
  38. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  39. package/dist/es5/i3s-converter/types.js +16 -0
  40. package/dist/es5/i3s-converter/types.js.map +1 -1
  41. package/dist/es5/i3s-server/README.md +19 -0
  42. package/dist/es5/i3s-server/app.js +10 -1
  43. package/dist/es5/i3s-server/app.js.map +1 -1
  44. package/dist/es5/i3s-server/controllers/slpk-controller.js +84 -0
  45. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -0
  46. package/dist/es5/i3s-server/routes/slpk-router.js +71 -0
  47. package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -0
  48. package/dist/es5/i3s-server/utils/create-scene-server.js +17 -0
  49. package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -0
  50. package/dist/es5/lib/utils/file-utils.js +1 -1
  51. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  52. package/dist/es5/lib/utils/geometry-utils.js +15 -0
  53. package/dist/es5/lib/utils/geometry-utils.js.map +1 -0
  54. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  55. package/dist/es5/pgm-loader.js +1 -1
  56. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  57. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +0 -3
  58. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  59. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +2 -8
  60. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  61. package/dist/esm/deps-installer/deps-installer.js +5 -5
  62. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  63. package/dist/esm/i3s-attributes-worker.js +1 -1
  64. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  65. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +4 -4
  66. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  67. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +6 -7
  68. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  69. package/dist/esm/i3s-converter/helpers/geometry-converter.js +37 -18
  70. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  71. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +50 -16
  72. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  73. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +35 -0
  74. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  75. package/dist/esm/i3s-converter/helpers/node-index-document.js +14 -1
  76. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
  77. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +48 -0
  78. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  79. package/dist/esm/i3s-converter/helpers/tileset-traversal.js +14 -0
  80. package/dist/esm/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  81. package/dist/esm/i3s-converter/i3s-converter.js +134 -127
  82. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  83. package/dist/esm/i3s-converter/types.js +10 -1
  84. package/dist/esm/i3s-converter/types.js.map +1 -1
  85. package/dist/esm/i3s-server/README.md +19 -0
  86. package/dist/esm/i3s-server/app.js +11 -1
  87. package/dist/esm/i3s-server/app.js.map +1 -1
  88. package/dist/esm/i3s-server/controllers/slpk-controller.js +36 -0
  89. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -0
  90. package/dist/esm/i3s-server/routes/slpk-router.js +33 -0
  91. package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -0
  92. package/dist/esm/i3s-server/utils/create-scene-server.js +16 -0
  93. package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -0
  94. package/dist/esm/lib/utils/file-utils.js +1 -1
  95. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  96. package/dist/esm/lib/utils/geometry-utils.js +8 -0
  97. package/dist/esm/lib/utils/geometry-utils.js.map +1 -0
  98. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  99. package/dist/esm/pgm-loader.js +1 -1
  100. package/dist/i3s-attributes-worker.d.ts +10 -2
  101. package/dist/i3s-attributes-worker.d.ts.map +1 -1
  102. package/dist/i3s-attributes-worker.js +2 -2
  103. package/dist/i3s-attributes-worker.js.map +3 -3
  104. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +4 -2
  105. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  106. package/dist/i3s-converter/helpers/batch-ids-extensions.js +4 -7
  107. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +3 -4
  108. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  109. package/dist/i3s-converter/helpers/coordinate-converter.js +8 -9
  110. package/dist/i3s-converter/helpers/geometry-converter.d.ts +9 -4
  111. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  112. package/dist/i3s-converter/helpers/geometry-converter.js +84 -54
  113. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +22 -3
  114. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  115. package/dist/i3s-converter/helpers/gltf-attributes.js +62 -22
  116. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +18 -0
  117. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -0
  118. package/dist/i3s-converter/helpers/load-3d-tiles.js +53 -0
  119. package/dist/i3s-converter/helpers/node-index-document.d.ts +8 -0
  120. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  121. package/dist/i3s-converter/helpers/node-index-document.js +20 -2
  122. package/dist/i3s-converter/helpers/node-pages.js +1 -1
  123. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +23 -0
  124. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -0
  125. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +76 -0
  126. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +25 -0
  127. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -0
  128. package/dist/i3s-converter/helpers/tileset-traversal.js +29 -0
  129. package/dist/i3s-converter/i3s-converter.d.ts +40 -40
  130. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  131. package/dist/i3s-converter/i3s-converter.js +150 -125
  132. package/dist/i3s-converter/types.d.ts +18 -0
  133. package/dist/i3s-converter/types.d.ts.map +1 -1
  134. package/dist/i3s-converter/types.js +15 -0
  135. package/dist/i3s-server/app.d.ts.map +1 -1
  136. package/dist/i3s-server/app.js +9 -1
  137. package/dist/i3s-server/controllers/slpk-controller.d.ts +3 -0
  138. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -0
  139. package/dist/i3s-server/controllers/slpk-controller.js +32 -0
  140. package/dist/i3s-server/routes/slpk-router.d.ts +3 -0
  141. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -0
  142. package/dist/i3s-server/routes/slpk-router.js +33 -0
  143. package/dist/i3s-server/utils/create-scene-server.d.ts +11 -0
  144. package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -0
  145. package/dist/i3s-server/utils/create-scene-server.js +14 -0
  146. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  147. package/dist/lib/utils/file-utils.js +2 -1
  148. package/dist/lib/utils/geometry-utils.d.ts +9 -0
  149. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  150. package/dist/lib/utils/geometry-utils.js +18 -0
  151. package/dist/lib/utils/lod-conversion-utils.d.ts +3 -2
  152. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  153. package/dist/lib/utils/lod-conversion-utils.js +1 -1
  154. package/package.json +15 -16
  155. package/src/3d-tiles-converter/3d-tiles-converter.ts +9 -8
  156. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +2 -16
  157. package/src/deps-installer/deps-installer.ts +4 -4
  158. package/src/i3s-attributes-worker.ts +11 -2
  159. package/src/i3s-converter/helpers/batch-ids-extensions.ts +15 -19
  160. package/src/i3s-converter/helpers/coordinate-converter.ts +11 -10
  161. package/src/i3s-converter/helpers/geometry-converter.ts +154 -95
  162. package/src/i3s-converter/helpers/gltf-attributes.ts +85 -25
  163. package/src/i3s-converter/helpers/load-3d-tiles.ts +68 -0
  164. package/src/i3s-converter/helpers/node-index-document.ts +22 -2
  165. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +81 -0
  166. package/src/i3s-converter/helpers/tileset-traversal.ts +51 -0
  167. package/src/i3s-converter/i3s-converter.ts +229 -178
  168. package/src/i3s-converter/types.ts +20 -0
  169. package/src/i3s-server/README.md +19 -0
  170. package/src/i3s-server/app.js +8 -1
  171. package/src/i3s-server/controllers/slpk-controller.js +38 -0
  172. package/src/i3s-server/routes/slpk-router.js +33 -0
  173. package/src/i3s-server/utils/create-scene-server.js +15 -0
  174. package/src/lib/utils/file-utils.ts +2 -1
  175. package/src/lib/utils/geometry-utils.ts +14 -0
  176. package/src/lib/utils/lod-conversion-utils.ts +6 -2
@@ -1,4 +1,6 @@
1
- import { GLTFAccessorPostprocessed, GLTFImagePostprocessed, GLTFMeshPrimitivePostprocessed } from '@loaders.gl/gltf';
1
+ import { GLTFAccessorPostprocessed, GLTFMeshPrimitivePostprocessed } from '@loaders.gl/gltf';
2
+ import type { NumericArray } from '@loaders.gl/loader-utils';
3
+ import { TextureImageProperties } from '../../i3s-attributes-worker';
2
4
  /**
3
5
  * Getting batchIds from 3DTilesNext extensions.
4
6
  * @param attributes - gltf accessors
@@ -7,5 +9,5 @@ import { GLTFAccessorPostprocessed, GLTFImagePostprocessed, GLTFMeshPrimitivePos
7
9
  */
8
10
  export declare function handleBatchIdsExtensions(attributes: {
9
11
  [key: string]: GLTFAccessorPostprocessed;
10
- }, primitive: GLTFMeshPrimitivePostprocessed, images: GLTFImagePostprocessed[]): number[];
12
+ }, primitive: GLTFMeshPrimitivePostprocessed, images: (TextureImageProperties | null)[]): NumericArray;
11
13
  //# sourceMappingURL=batch-ids-extensions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"batch-ids-extensions.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,kBAAkB,CAAC;AAS1B;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAAC;CAC1C,EACD,SAAS,EAAE,8BAA8B,EACzC,MAAM,EAAE,sBAAsB,EAAE,GAC/B,MAAM,EAAE,CAwBV"}
1
+ {"version":3,"file":"batch-ids-extensions.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/batch-ids-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAE,8BAA8B,EAAC,MAAM,kBAAkB,CAAC;AAC3F,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAM3D,OAAO,EAAC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AAKnE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAAC;CAC1C,EACD,SAAS,EAAE,8BAA8B,EACzC,MAAM,EAAE,CAAC,sBAAsB,GAAG,IAAI,CAAC,EAAE,GACxC,YAAY,CAwBd"}
@@ -57,12 +57,9 @@ function handleExtFeatureMetadataExtension(attributes, extFeatureMetadata, image
57
57
  }
58
58
  // Take only first extension texture to get batchIds from the root EXT_feature_metadata object.
59
59
  const featureTexture = extFeatureMetadata?.featureTextures && extFeatureMetadata?.featureTextures[0];
60
- /**
61
- * TODO need to get batchIds from root extension
62
- */
63
60
  if (featureTexture) {
64
- console.warn("EXT_feature_metadata doesn't yet support featureTextures in primitive");
65
- return [];
61
+ const batchIdsAttribute = attributes[featureTexture];
62
+ return batchIdsAttribute.value;
66
63
  }
67
64
  return [];
68
65
  }
@@ -115,7 +112,7 @@ function generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, image
115
112
  const image = images[textureIndex];
116
113
  const batchIds = [];
117
114
  const channels = CHANNELS_MAP[featureChannel];
118
- if (!image.compressed) {
115
+ if (image && image?.width && image?.height && image?.components) {
119
116
  for (let index = 0; index < textureCoordinates.length; index += 2) {
120
117
  const u = textureCoordinates[index];
121
118
  const v = textureCoordinates[index + 1];
@@ -127,7 +124,7 @@ function generateBatchIdsFromTexture(featureIdTexture, textureCoordinates, image
127
124
  }
128
125
  }
129
126
  else {
130
- console.warn(`Can't get batch Ids from ${image.mimeType} compressed texture`);
127
+ console.warn(`Can't get batch Ids from ${image?.mimeType || ''} compressed texture`);
131
128
  }
132
129
  return batchIds;
133
130
  }
@@ -1,15 +1,14 @@
1
1
  import type { BoundingVolumes, FullExtent, Mbs, Obb } from '@loaders.gl/i3s';
2
2
  import { Vector3 } from '@math.gl/core';
3
3
  import { OrientedBoundingBox, BoundingSphere } from '@math.gl/culling';
4
- import { Tile3D } from '@loaders.gl/tiles';
5
4
  import { Geoid } from '@math.gl/geoid';
6
5
  /**
7
6
  * Create bounding volumes object from tile and geoid height model.
8
- * @param tile
9
- * @param geoidHeightModel
7
+ * @param sourceBoundingVolume - initialized bounding volume of the source tile
8
+ * @param geoidHeightModel - instance of Geoid class that converts elevation from geoidal to ellipsoidal and back
10
9
  * @returns - Bounding volumes object
11
10
  */
12
- export declare function createBoundingVolumes(tile: Tile3D, geoidHeightModel: Geoid): BoundingVolumes;
11
+ export declare function createBoundingVolumes(sourceBoundingVolume: OrientedBoundingBox | BoundingSphere, geoidHeightModel: Geoid): BoundingVolumes;
13
12
  /**
14
13
  * Generates bounding volumes from geometry positions
15
14
  * @param cartesianPositions
@@ -1 +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,UAAU,EAAE,GAAG,EAAE,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAE3E,OAAO,EAAsB,OAAO,EAAC,MAAM,eAAe,CAAC;AAE3D,OAAO,EACL,mBAAmB,EAGnB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAErC;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,GAAG,eAAe,CAiC5F;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,oCAAoC,CAClD,cAAc,EAAE,mBAAmB,GAAG,cAAc,GACnD,UAAU,CA4BZ;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAK9C"}
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,UAAU,EAAE,GAAG,EAAE,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAE3E,OAAO,EAAsB,OAAO,EAAC,MAAM,eAAe,CAAC;AAE3D,OAAO,EACL,mBAAmB,EAGnB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAErC;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,oBAAoB,EAAE,mBAAmB,GAAG,cAAc,EAC1D,gBAAgB,EAAE,KAAK,GACtB,eAAe,CAgCjB;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,oCAAoC,CAClD,cAAc,EAAE,mBAAmB,GAAG,cAAc,GACnD,UAAU,CA4BZ;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAK9C"}
@@ -6,26 +6,25 @@ const geospatial_1 = require("@math.gl/geospatial");
6
6
  const culling_1 = require("@math.gl/culling");
7
7
  /**
8
8
  * Create bounding volumes object from tile and geoid height model.
9
- * @param tile
10
- * @param geoidHeightModel
9
+ * @param sourceBoundingVolume - initialized bounding volume of the source tile
10
+ * @param geoidHeightModel - instance of Geoid class that converts elevation from geoidal to ellipsoidal and back
11
11
  * @returns - Bounding volumes object
12
12
  */
13
- function createBoundingVolumes(tile, geoidHeightModel) {
13
+ function createBoundingVolumes(sourceBoundingVolume, geoidHeightModel) {
14
14
  let radius;
15
15
  let halfSize;
16
16
  let quaternion;
17
- const boundingVolume = tile.boundingVolume;
18
- const cartographicCenter = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(boundingVolume.center, new core_1.Vector3());
17
+ const cartographicCenter = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(sourceBoundingVolume.center, new core_1.Vector3());
19
18
  cartographicCenter[2] =
20
19
  cartographicCenter[2] -
21
20
  geoidHeightModel.getHeight(cartographicCenter[1], cartographicCenter[0]);
22
- if (boundingVolume instanceof culling_1.OrientedBoundingBox) {
23
- halfSize = boundingVolume.halfSize;
21
+ if (sourceBoundingVolume instanceof culling_1.OrientedBoundingBox) {
22
+ halfSize = sourceBoundingVolume.halfSize;
24
23
  radius = new core_1.Vector3(halfSize[0], halfSize[1], halfSize[2]).len();
25
- quaternion = boundingVolume.quaternion;
24
+ quaternion = sourceBoundingVolume.quaternion;
26
25
  }
27
26
  else {
28
- radius = tile.boundingVolume.radius;
27
+ radius = sourceBoundingVolume.radius;
29
28
  halfSize = [radius, radius, radius];
30
29
  quaternion = new core_1.Quaternion()
31
30
  .fromMatrix3(new core_1.Matrix3([halfSize[0], 0, 0, 0, halfSize[1], 0, 0, 0, halfSize[2]]))
@@ -1,13 +1,18 @@
1
- import type { B3DMContent, FeatureTableJson } from '@loaders.gl/3d-tiles';
1
+ import type { FeatureTableJson, Tiles3DTileContent } from '@loaders.gl/3d-tiles';
2
+ import { Matrix4 } from '@math.gl/core';
2
3
  import { ConvertedAttributes, I3SConvertedResources, I3SMaterialWithTexture } from '../types';
3
4
  import { AttributeStorageInfo } from '@loaders.gl/i3s';
4
5
  import { Geoid } from '@math.gl/geoid';
5
6
  /** Usage of worker here brings more overhead than advantage */
6
7
  import { B3DMAttributesData } from '../../i3s-attributes-worker';
8
+ import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
7
9
  /**
8
10
  * Convert binary data from b3dm file to i3s resources
9
11
  *
10
12
  * @param tileContent - 3d tile content
13
+ * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
14
+ * transform of all parent tiles and transform of the current tile
15
+ * @param tileBoundingVolume - initialized bounding volume of the source tile
11
16
  * @param addNodeToNodePage - function to add new node to node pages
12
17
  * @param propertyTable - batch table (corresponding to feature attributes data)
13
18
  * @param featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
@@ -19,7 +24,7 @@ import { B3DMAttributesData } from '../../i3s-attributes-worker';
19
24
  * @param workerSource - source code of used workers
20
25
  * @returns Array of node resources to create one or more i3s nodes
21
26
  */
22
- export default function convertB3dmToI3sGeometry(tileContent: B3DMContent, addNodeToNodePage: () => Promise<number>, propertyTable: FeatureTableJson | null, featuresHashArray: string[], attributeStorageInfo: AttributeStorageInfo[] | undefined, draco: boolean, generateBoundingVolumes: boolean, shouldMergeMaterials: boolean, geoidHeightModel: Geoid, workerSource: {
27
+ export default function convertB3dmToI3sGeometry(tileContent: Tiles3DTileContent, tileTransform: Matrix4, tileBoundingVolume: OrientedBoundingBox | BoundingSphere, addNodeToNodePage: () => Promise<number>, propertyTable: FeatureTableJson | null, featuresHashArray: string[], attributeStorageInfo: AttributeStorageInfo[] | undefined, draco: boolean, generateBoundingVolumes: boolean, shouldMergeMaterials: boolean, geoidHeightModel: Geoid, workerSource: {
23
28
  [key: string]: string;
24
29
  }): Promise<I3SConvertedResources[] | null>;
25
30
  /**
@@ -34,8 +39,8 @@ export declare function convertAttributes(attributesData: B3DMAttributesData, ma
34
39
  /**
35
40
  * Find property table in tile
36
41
  * For example it can be batchTable for b3dm files or property table in gLTF extension.
37
- * @param sourceTile
42
+ * @param tileContent - 3DTiles tile content
38
43
  * @return batch table from b3dm / feature properties from EXT_FEATURE_METADATA
39
44
  */
40
- export declare function getPropertyTable(tileContent: B3DMContent): FeatureTableJson | null;
45
+ export declare function getPropertyTable(tileContent: Tiles3DTileContent | null): FeatureTableJson | null;
41
46
  //# sourceMappingURL=geometry-converter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAsBxE,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AACrC,+DAA+D;AAC/D,OAAO,EAAC,kBAAkB,EAAsC,MAAM,6BAA6B,CAAC;AAsCpG;;;;;;;;;;;;;;GAcG;AACH,wBAA8B,wBAAwB,CACpD,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACxC,aAAa,EAAE,gBAAgB,GAAG,IAAI,EACtC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,SAAS,EACxD,KAAK,EAAE,OAAO,EACd,uBAAuB,EAAE,OAAO,EAChC,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,EAAE,KAAK,EACvB,YAAY,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GACpC,OAAO,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CA0DzC;AA6ID;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,cAAc,EAAE,kBAAkB,EAClC,sBAAsB,EAAE,sBAAsB,EAAE,EAChD,qBAAqB,EAAE,OAAO,GAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAgD3C;AAkoCD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI,CAoBlF"}
1
+ {"version":3,"file":"geometry-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAY/E,OAAO,EAAU,OAAO,EAAU,MAAM,eAAe,CAAC;AAUxD,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AACrC,+DAA+D;AAC/D,OAAO,EACL,kBAAkB,EAEnB,MAAM,6BAA6B,CAAC;AAarC,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AA0BrE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAA8B,wBAAwB,CACpD,WAAW,EAAE,kBAAkB,EAC/B,aAAa,EAAE,OAAO,EACtB,kBAAkB,EAAE,mBAAmB,GAAG,cAAc,EACxD,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACxC,aAAa,EAAE,gBAAgB,GAAG,IAAI,EACtC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,SAAS,EACxD,KAAK,EAAE,OAAO,EACd,uBAAuB,EAAE,OAAO,EAChC,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,EAAE,KAAK,EACvB,YAAY,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,GACpC,OAAO,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CA8DzC;AA6ID;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,cAAc,EAAE,kBAAkB,EAClC,sBAAsB,EAAE,sBAAsB,EAAE,EAChD,qBAAqB,EAAE,OAAO,GAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAgD3C;AA4pCD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI,GAAG,gBAAgB,GAAG,IAAI,CAwBhG"}
@@ -40,6 +40,7 @@ const gltf_attributes_1 = require("./gltf-attributes");
40
40
  const batch_ids_extensions_1 = require("./batch-ids-extensions");
41
41
  const feature_attributes_1 = require("./feature-attributes");
42
42
  const math_1 = require("@loaders.gl/math");
43
+ const geometry_utils_1 = require("../../lib/utils/geometry-utils");
43
44
  // Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md
44
45
  const DEFAULT_ROUGHNESS_FACTOR = 1;
45
46
  const DEFAULT_METALLIC_FACTOR = 1;
@@ -63,6 +64,9 @@ let scratchVector = new core_1.Vector3();
63
64
  * Convert binary data from b3dm file to i3s resources
64
65
  *
65
66
  * @param tileContent - 3d tile content
67
+ * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
68
+ * transform of all parent tiles and transform of the current tile
69
+ * @param tileBoundingVolume - initialized bounding volume of the source tile
66
70
  * @param addNodeToNodePage - function to add new node to node pages
67
71
  * @param propertyTable - batch table (corresponding to feature attributes data)
68
72
  * @param featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
@@ -74,10 +78,10 @@ let scratchVector = new core_1.Vector3();
74
78
  * @param workerSource - source code of used workers
75
79
  * @returns Array of node resources to create one or more i3s nodes
76
80
  */
77
- async function convertB3dmToI3sGeometry(tileContent, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
81
+ async function convertB3dmToI3sGeometry(tileContent, tileTransform, tileBoundingVolume, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
78
82
  const useCartesianPositions = generateBoundingVolumes;
79
83
  const materialAndTextureList = await convertMaterials(tileContent.gltf?.materials, shouldMergeMaterials);
80
- const dataForAttributesConversion = (0, gltf_attributes_1.prepareDataForAttributesConversion)(tileContent);
84
+ const dataForAttributesConversion = (0, gltf_attributes_1.prepareDataForAttributesConversion)(tileContent, tileTransform, tileBoundingVolume);
81
85
  const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions);
82
86
  /** Usage of worker here brings more overhead than advantage */
83
87
  // const convertedAttributesMap: Map<string, ConvertedAttributes> =
@@ -147,7 +151,7 @@ function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeigh
147
151
  * @param params.convertedAttributes - Converted geometry attributes
148
152
  * @param params.material - I3S PBR-like material definition
149
153
  * @param params.texture - texture content
150
- * @param params.tileContent - B3DM decoded content
154
+ * @param params.tileContent - 3DTiles decoded content
151
155
  * @param params.nodeId - new node ID
152
156
  * @param params.featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
153
157
  * @param params.propertyTable - batch table (corresponding to feature attributes data)
@@ -324,18 +328,23 @@ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, att
324
328
  let outputAttributes = null;
325
329
  let materialUvRegion;
326
330
  if (primitive.material) {
327
- outputAttributes = attributesMap.get(primitive.material.uniqueId);
328
- materialUvRegion = outputAttributes?.mergedMaterials.find(({ originalMaterialId }) => originalMaterialId === primitive.material?.uniqueId)?.uvRegion;
331
+ outputAttributes = attributesMap.get(primitive.material.id);
332
+ materialUvRegion = outputAttributes?.mergedMaterials.find(({ originalMaterialId }) => originalMaterialId === primitive.material?.id)?.uvRegion;
329
333
  }
330
334
  else if (attributesMap.has('default')) {
331
335
  outputAttributes = attributesMap.get('default');
332
336
  }
333
337
  (0, core_2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
338
+ // Per the spec https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_mesh_primitive_mode
339
+ // GL.TRIANGLES is default. So in case `mode` is `undefined`, it is 'TRIANGLES'
340
+ (0, core_2.assert)(primitive.mode === undefined ||
341
+ primitive.mode === math_1.GL.TRIANGLES ||
342
+ primitive.mode === math_1.GL.TRIANGLE_STRIP, `Primitive - unsupported mode ${primitive.mode}`);
334
343
  const attributes = primitive.attributes;
335
344
  if (!outputAttributes) {
336
345
  continue;
337
346
  }
338
- const indices = getIndices(primitive);
347
+ const indices = normalizeIndices(primitive);
339
348
  outputAttributes.positions = (0, loader_utils_1.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
340
349
  vertices: attributes.POSITION.value,
341
350
  cartographicOrigin,
@@ -365,11 +374,15 @@ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, att
365
374
  }
366
375
  /**
367
376
  * Converts TRIANGLE-STRIPS to independent TRIANGLES
368
- * @param {MeshPrimitive} primitive - the primitive to get the indices from
377
+ * @param primitive - the primitive to get the indices from
369
378
  * @returns indices of vertices of the independent triangles
370
379
  */
371
- function getIndices(primitive) {
380
+ function normalizeIndices(primitive) {
372
381
  let indices = primitive.indices?.value;
382
+ if (!indices) {
383
+ const positions = primitive.attributes.POSITION.value;
384
+ return (0, geometry_utils_1.generateSyntheticIndices)(positions.length / VALUES_PER_VERTEX);
385
+ }
373
386
  if (indices && primitive.mode === math_1.GL.TRIANGLE_STRIP) {
374
387
  /*
375
388
  TRIANGLE_STRIP geometry contains n+2 vertices for n triangles;
@@ -409,7 +422,7 @@ function getIndices(primitive) {
409
422
  * @param args.indices - gltf primitive indices
410
423
  * @param args.attributeSpecificTransformation - function to do attribute - specific transformations
411
424
  * @param args.useCartesianPositions - use coordinates as it is.
412
- * @returns {Float32Array}
425
+ * @returns
413
426
  */
414
427
  function transformVertexArray(args) {
415
428
  const { vertices, indices, attributeSpecificTransformation } = args;
@@ -700,9 +713,8 @@ function convertMaterial(sourceMaterial) {
700
713
  textureSetDefinitionId: 0
701
714
  };
702
715
  }
703
- const uniqueId = (0, uuid_1.v4)();
704
- sourceMaterial.uniqueId = uniqueId;
705
- let mergedMaterials = [{ originalMaterialId: uniqueId }];
716
+ sourceMaterial.id = Number.isFinite(sourceMaterial.id) ? sourceMaterial.id : (0, uuid_1.v4)();
717
+ let mergedMaterials = [{ originalMaterialId: sourceMaterial.id }];
706
718
  if (!texture) {
707
719
  // Should use default baseColorFactor if it is not present in source material
708
720
  // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness
@@ -845,7 +857,7 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
845
857
  // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md
846
858
  id: generateImageId(texture, nodeId),
847
859
  size: texture.source?.image.width,
848
- length: [texture.source?.image.data.length]
860
+ length: texture.source?.image.data.length ? [texture.source?.image.data.length] : undefined
849
861
  }
850
862
  ]
851
863
  };
@@ -858,7 +870,10 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
858
870
  * @returns calculate image ID according to the spec
859
871
  */
860
872
  function generateImageId(texture, nodeId) {
861
- const { width, height } = texture.source?.image;
873
+ const { width, height } = texture.source?.image || {};
874
+ if (!width || !height) {
875
+ return '';
876
+ }
862
877
  const levelCountOfTexture = 1;
863
878
  const indexOfLevel = 0;
864
879
  const indexOfTextureInStore = nodeId + 1;
@@ -887,10 +902,10 @@ function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, bat
887
902
  }
888
903
  /**
889
904
  * Generate replace map to make featureIds unique.
890
- * @param {Array} featureIds
891
- * @param {Object} batchTable
892
- * @param {Array} featuresHashArray
893
- * @returns {Object}
905
+ * @param featureIds
906
+ * @param batchTable
907
+ * @param featuresHashArray
908
+ * @returns
894
909
  */
895
910
  function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
896
911
  const featureMap = {};
@@ -903,9 +918,9 @@ function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
903
918
  }
904
919
  /**
905
920
  * Generates string for unique batch id creation.
906
- * @param {Object} batchTable
907
- * @param {Number} index
908
- * @returns {String}
921
+ * @param batchTable
922
+ * @param index
923
+ * @returns
909
924
  */
910
925
  function generateStringFromBatchTableByIndex(batchTable, index) {
911
926
  let str = '';
@@ -916,10 +931,10 @@ function generateStringFromBatchTableByIndex(batchTable, index) {
916
931
  }
917
932
  /**
918
933
  * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.
919
- * @param {Number} index
920
- * @param {Object} batchTable
921
- * @param {Array} featuresHashArray
922
- * @returns {Number}
934
+ * @param index
935
+ * @param batchTable
936
+ * @param featuresHashArray
937
+ * @returns
923
938
  */
924
939
  function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
925
940
  const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
@@ -931,9 +946,9 @@ function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
931
946
  }
932
947
  /**
933
948
  * Do replacement of indices for making them unique through all nodes.
934
- * @param {Array} indicesArray
935
- * @param {Object} featureMap
936
- * @returns {void}
949
+ * @param indicesArray
950
+ * @param featureMap
951
+ * @returns
937
952
  */
938
953
  function replaceIndicesByUnique(indicesArray, featureMap) {
939
954
  for (let index = 0; index < indicesArray.length; index++) {
@@ -942,10 +957,10 @@ function replaceIndicesByUnique(indicesArray, featureMap) {
942
957
  }
943
958
  /**
944
959
  * Convert property table data to attribute buffers.
945
- * @param {Array} featureIds
946
- * @param {Object} propertyTable - table with metadata for particular feature.
947
- * @param {Array} attributeStorageInfo
948
- * @returns {Array} - Array of file buffers.
960
+ * @param featureIds
961
+ * @param propertyTable - table with metadata for particular feature.
962
+ * @param attributeStorageInfo
963
+ * @returns - Array of file buffers.
949
964
  */
950
965
  function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
951
966
  const attributeBuffers = [];
@@ -990,9 +1005,9 @@ function generateAttributeBuffer(type, value) {
990
1005
  }
991
1006
  /**
992
1007
  * Return attribute type.
993
- * @param {String} key
994
- * @param {Array} attributeStorageInfo
995
- * @returns {String} attribute type.
1008
+ * @param key
1009
+ * @param attributeStorageInfo
1010
+ * @returns attribute type.
996
1011
  */
997
1012
  function getAttributeType(key, attributeStorageInfo) {
998
1013
  const attribute = attributeStorageInfo.find((attr) => attr.name === key);
@@ -1000,8 +1015,8 @@ function getAttributeType(key, attributeStorageInfo) {
1000
1015
  }
1001
1016
  /**
1002
1017
  * Convert short integer to attribute arrayBuffer.
1003
- * @param {Array} featureIds
1004
- * @returns {ArrayBuffer} - Buffer with objectId data.
1018
+ * @param featureIds
1019
+ * @returns - Buffer with objectId data.
1005
1020
  */
1006
1021
  function generateShortIntegerAttributeBuffer(featureIds) {
1007
1022
  const count = new Uint32Array([featureIds.length]);
@@ -1010,8 +1025,8 @@ function generateShortIntegerAttributeBuffer(featureIds) {
1010
1025
  }
1011
1026
  /**
1012
1027
  * Convert double to attribute arrayBuffer.
1013
- * @param {Array} featureIds
1014
- * @returns {ArrayBuffer} - Buffer with objectId data.
1028
+ * @param featureIds
1029
+ * @returns - Buffer with objectId data.
1015
1030
  */
1016
1031
  function generateDoubleAttributeBuffer(featureIds) {
1017
1032
  const count = new Uint32Array([featureIds.length]);
@@ -1021,8 +1036,8 @@ function generateDoubleAttributeBuffer(featureIds) {
1021
1036
  }
1022
1037
  /**
1023
1038
  * Convert batch table attributes to array buffer with batch table data.
1024
- * @param {Array} batchAttributes
1025
- * @returns {ArrayBuffer} - Buffer with batch table data.
1039
+ * @param batchAttributes
1040
+ * @returns - Buffer with batch table data.
1026
1041
  */
1027
1042
  function generateStringAttributeBuffer(batchAttributes) {
1028
1043
  const stringCountArray = new Uint32Array([batchAttributes.length]);
@@ -1042,8 +1057,8 @@ function generateStringAttributeBuffer(batchAttributes) {
1042
1057
  }
1043
1058
  /**
1044
1059
  * Convert featureIds to BigUint64Array.
1045
- * @param {Array} featureIds
1046
- * @returns {BigUint64Array} - Array of feature ids in BigUint64 format.
1060
+ * @param featureIds
1061
+ * @returns - Array of feature ids in BigUint64 format.
1047
1062
  */
1048
1063
  function generateBigUint64Array(featureIds) {
1049
1064
  const typedFeatureIds = new BigUint64Array(featureIds.length);
@@ -1102,9 +1117,9 @@ async function generateCompressedGeometry(vertexCount, convertedAttributes, attr
1102
1117
  }
1103
1118
  /**
1104
1119
  * Generates ordered feature indices based on face range
1105
- * @param {Uint32Array} featureIndex
1106
- * @param {Uint32Array} faceRange
1107
- * @returns {Uint32Array}
1120
+ * @param featureIndex
1121
+ * @param faceRange
1122
+ * @returns
1108
1123
  */
1109
1124
  function generateFeatureIndexAttribute(featureIndex, faceRange) {
1110
1125
  const orderedFeatureIndices = new Uint32Array(featureIndex.length);
@@ -1121,10 +1136,13 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
1121
1136
  /**
1122
1137
  * Find property table in tile
1123
1138
  * For example it can be batchTable for b3dm files or property table in gLTF extension.
1124
- * @param sourceTile
1139
+ * @param tileContent - 3DTiles tile content
1125
1140
  * @return batch table from b3dm / feature properties from EXT_FEATURE_METADATA
1126
1141
  */
1127
1142
  function getPropertyTable(tileContent) {
1143
+ if (!tileContent) {
1144
+ return null;
1145
+ }
1128
1146
  const batchTableJson = tileContent?.batchTableJson;
1129
1147
  if (batchTableJson) {
1130
1148
  return batchTableJson;
@@ -1145,7 +1163,7 @@ function getPropertyTable(tileContent) {
1145
1163
  exports.getPropertyTable = getPropertyTable;
1146
1164
  /**
1147
1165
  * Check extensions which can be with property table inside.
1148
- * @param sourceTile
1166
+ * @param tileContent - 3DTiles tile content
1149
1167
  */
1150
1168
  function getPropertyTableExtension(tileContent) {
1151
1169
  const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
@@ -1166,13 +1184,8 @@ function getPropertyTableExtension(tileContent) {
1166
1184
  /**
1167
1185
  * Handle EXT_feature_metadata to get property table
1168
1186
  * @param extension
1169
- * TODO add EXT_feature_metadata feature textures support.
1170
1187
  */
1171
1188
  function getPropertyTableFromExtFeatureMetadata(extension) {
1172
- if (extension?.featureTextures) {
1173
- console.warn('The I3S converter does not yet support the EXT_feature_metadata feature textures');
1174
- return null;
1175
- }
1176
1189
  if (extension?.featureTables) {
1177
1190
  /**
1178
1191
  * Take only first feature table to generate attributes storage info object.
@@ -1190,6 +1203,23 @@ function getPropertyTableFromExtFeatureMetadata(extension) {
1190
1203
  return propertyTable;
1191
1204
  }
1192
1205
  }
1193
- console.warn("The I3S converter couldn't handle EXT_feature_metadata extension");
1206
+ if (extension?.featureTextures) {
1207
+ /**
1208
+ * Take only first feature texture to generate attributes storage info object.
1209
+ * TODO: Think about getting data from all feature textures?
1210
+ * It can be tricky just because 3dTiles is able to have multiple featureTextures.
1211
+ * In I3S we should decide which featureTextures will be passed to geometry data.
1212
+ */
1213
+ const firstTextureName = Object.keys(extension.featureTextures)?.[0];
1214
+ if (firstTextureName) {
1215
+ const featureTable = extension?.featureTextures[firstTextureName];
1216
+ const propertyTable = {};
1217
+ for (const propertyName in featureTable.properties) {
1218
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
1219
+ }
1220
+ return propertyTable;
1221
+ }
1222
+ }
1223
+ console.warn("The I3S converter couldn't handle EXT_feature_metadata extension: There is neither featureTables, no featureTextures in the extension.");
1194
1224
  return null;
1195
1225
  }
@@ -1,9 +1,28 @@
1
- import type { B3DMContent } from '@loaders.gl/3d-tiles';
1
+ import type { Tiles3DTileContent } from '@loaders.gl/3d-tiles';
2
2
  import type { B3DMAttributesData } from '../../i3s-attributes-worker';
3
+ import { Matrix4, Vector3 } from '@math.gl/core';
4
+ import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
3
5
  /**
4
6
  * Prepare attributes for conversion to avoid binary data breaking in worker thread.
5
- * @param tileContent
7
+ * @param tileContent - 3DTiles tile content
8
+ * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
9
+ * transform of all parent tiles and transform of the current tile
10
+ * @param boundingVolume - initialized bounding volume of the source tile
6
11
  * @returns
7
12
  */
8
- export declare function prepareDataForAttributesConversion(tileContent: B3DMContent): B3DMAttributesData;
13
+ export declare function prepareDataForAttributesConversion(tileContent: Tiles3DTileContent, tileTransform: Matrix4, boundingVolume: OrientedBoundingBox | BoundingSphere): B3DMAttributesData;
14
+ /**
15
+ * Calculate transformation properties to transform vertex attributes (POSITION, NORMAL, etc.)
16
+ * from METER_OFFSET coorditantes to LNGLAT_OFFSET coordinates
17
+ * @param tileContent - 3DTiles tile content
18
+ * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
19
+ * transform of all parent tiles and transform of the current tile
20
+ * @param boundingVolume - initialized bounding volume of the source tile
21
+ * @returns modelMatrix - transformation matrix to transform coordinates to cartographic coordinates
22
+ * cartographicOrigin - tile origin coordinates to calculate offsets
23
+ */
24
+ export declare function calculateTransformProps(tileContent: Tiles3DTileContent, tileTransform: Matrix4, boundingVolume: OrientedBoundingBox | BoundingSphere): {
25
+ modelMatrix: Matrix4;
26
+ cartographicOrigin: Vector3;
27
+ };
9
28
  //# sourceMappingURL=gltf-attributes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gltf-attributes.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/gltf-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAsBpE;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,WAAW,EAAE,WAAW,GAAG,kBAAkB,CAyC/F"}
1
+ {"version":3,"file":"gltf-attributes.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/gltf-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAOrE;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,WAAW,EAAE,kBAAkB,EAC/B,aAAa,EAAE,OAAO,EACtB,cAAc,EAAE,mBAAmB,GAAG,cAAc,GACnD,kBAAkB,CAyCpB;AAkBD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,kBAAkB,EAC/B,aAAa,EAAE,OAAO,EACtB,cAAc,EAAE,mBAAmB,GAAG,cAAc,GACnD;IAAC,WAAW,EAAE,OAAO,CAAC;IAAC,kBAAkB,EAAE,OAAO,CAAA;CAAC,CAkCrD"}
@@ -1,25 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareDataForAttributesConversion = void 0;
4
- /**
5
- * Keep only values for B3DM attributes to pass data to worker thread.
6
- * @param attributes
7
- */
8
- function getB3DMAttributesWithoutBufferView(attributes) {
9
- const attributesWithoutBufferView = {};
10
- for (const attributeName in attributes) {
11
- attributesWithoutBufferView[attributeName] = {
12
- value: attributes[attributeName].value
13
- };
14
- }
15
- return attributesWithoutBufferView;
16
- }
3
+ exports.calculateTransformProps = exports.prepareDataForAttributesConversion = void 0;
4
+ const core_1 = require("@math.gl/core");
5
+ const geospatial_1 = require("@math.gl/geospatial");
17
6
  /**
18
7
  * Prepare attributes for conversion to avoid binary data breaking in worker thread.
19
- * @param tileContent
8
+ * @param tileContent - 3DTiles tile content
9
+ * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
10
+ * transform of all parent tiles and transform of the current tile
11
+ * @param boundingVolume - initialized bounding volume of the source tile
20
12
  * @returns
21
13
  */
22
- function prepareDataForAttributesConversion(tileContent) {
14
+ function prepareDataForAttributesConversion(tileContent, tileTransform, boundingVolume) {
23
15
  let nodes = tileContent.gltf?.scene?.nodes ||
24
16
  tileContent.gltf?.scenes?.[0]?.nodes ||
25
17
  tileContent.gltf?.nodes ||
@@ -27,10 +19,7 @@ function prepareDataForAttributesConversion(tileContent) {
27
19
  const images = tileContent.gltf?.images?.map((imageObject) => {
28
20
  // Need data only for uncompressed images because we can't get batchIds from compressed textures.
29
21
  if (imageObject?.image?.compressed) {
30
- return {
31
- data: null,
32
- compressed: true
33
- };
22
+ return null;
34
23
  }
35
24
  else {
36
25
  const data = imageObject?.image?.data;
@@ -47,8 +36,7 @@ function prepareDataForAttributesConversion(tileContent) {
47
36
  }
48
37
  }) || [];
49
38
  prepareNodes(nodes);
50
- const cartographicOrigin = tileContent.cartographicOrigin;
51
- const cartesianModelMatrix = tileContent.cartesianModelMatrix;
39
+ const { cartographicOrigin, modelMatrix: cartesianModelMatrix } = calculateTransformProps(tileContent, tileTransform, boundingVolume);
52
40
  return {
53
41
  nodes,
54
42
  images,
@@ -57,6 +45,58 @@ function prepareDataForAttributesConversion(tileContent) {
57
45
  };
58
46
  }
59
47
  exports.prepareDataForAttributesConversion = prepareDataForAttributesConversion;
48
+ /**
49
+ * Keep only values for glTF attributes to pass data to worker thread.
50
+ * @param attributes - geometry attributes
51
+ */
52
+ function getB3DMAttributesWithoutBufferView(attributes) {
53
+ const attributesWithoutBufferView = {};
54
+ for (const attributeName in attributes) {
55
+ attributesWithoutBufferView[attributeName] = {
56
+ value: attributes[attributeName].value
57
+ };
58
+ }
59
+ return attributesWithoutBufferView;
60
+ }
61
+ /**
62
+ * Calculate transformation properties to transform vertex attributes (POSITION, NORMAL, etc.)
63
+ * from METER_OFFSET coorditantes to LNGLAT_OFFSET coordinates
64
+ * @param tileContent - 3DTiles tile content
65
+ * @param tileTransform - transformation matrix of the tile, calculated recursively multiplying
66
+ * transform of all parent tiles and transform of the current tile
67
+ * @param boundingVolume - initialized bounding volume of the source tile
68
+ * @returns modelMatrix - transformation matrix to transform coordinates to cartographic coordinates
69
+ * cartographicOrigin - tile origin coordinates to calculate offsets
70
+ */
71
+ function calculateTransformProps(tileContent, tileTransform, boundingVolume) {
72
+ const { rtcCenter, gltfUpAxis } = tileContent;
73
+ const { center } = boundingVolume;
74
+ let modelMatrix = new core_1.Matrix4(tileTransform);
75
+ // Translate if appropriate
76
+ if (rtcCenter) {
77
+ modelMatrix.translate(rtcCenter);
78
+ }
79
+ // glTF models need to be rotated from Y to Z up
80
+ // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
81
+ switch (gltfUpAxis) {
82
+ case 'Z':
83
+ break;
84
+ case 'Y':
85
+ const rotationY = new core_1.Matrix4().rotateX(Math.PI / 2);
86
+ modelMatrix = modelMatrix.multiplyRight(rotationY);
87
+ break;
88
+ case 'X':
89
+ const rotationX = new core_1.Matrix4().rotateY(-Math.PI / 2);
90
+ modelMatrix = modelMatrix.multiplyRight(rotationX);
91
+ break;
92
+ default:
93
+ break;
94
+ }
95
+ const cartesianOrigin = new core_1.Vector3(center);
96
+ const cartographicOrigin = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new core_1.Vector3());
97
+ return { modelMatrix, cartographicOrigin };
98
+ }
99
+ exports.calculateTransformProps = calculateTransformProps;
60
100
  /**
61
101
  * Traverse all nodes to replace all sensible data with copy to avoid data corruption in worker.
62
102
  * @param nodes