parseBoundingVolumeSemantics.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. /**
  4. * Parse the bounding volume-related semantics such as
  5. * <code>TILE_BOUNDING_BOX</code> and <code>CONTENT_BOUNDING_REGION</code> from
  6. * implicit tile metadata. Results are returned as a JSON object for use when
  7. * transcoding tiles (see {@link Implicit3DTileContent}).
  8. * <p>
  9. * Bounding volumes are checked in the order box, region, then sphere. Only
  10. * the first valid bounding volume is returned.
  11. * </p>
  12. *
  13. * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata/Semantics|3D Metadata Semantic Reference} for the various bounding volumes and minimum/maximum heights.
  14. *
  15. * @param {TileMetadata} tileMetadata The metadata object for looking up values by semantic. In practice, this will typically be a {@link ImplicitMetadataView}
  16. * @return {object} An object containing a <code>tile</code> property and a <code>content</code> property. These contain the bounding volume, and any minimum or maximum height.
  17. *
  18. * @private
  19. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  20. */
  21. function parseBoundingVolumeSemantics(tileMetadata) {
  22. //>>includeStart('debug', pragmas.debug);
  23. Check.typeOf.object("tileMetadata", tileMetadata);
  24. //>>includeEnd('debug');
  25. return {
  26. tile: {
  27. boundingVolume: parseBoundingVolume("TILE", tileMetadata),
  28. minimumHeight: parseMinimumHeight("TILE", tileMetadata),
  29. maximumHeight: parseMaximumHeight("TILE", tileMetadata),
  30. },
  31. content: {
  32. boundingVolume: parseBoundingVolume("CONTENT", tileMetadata),
  33. minimumHeight: parseMinimumHeight("CONTENT", tileMetadata),
  34. maximumHeight: parseMaximumHeight("CONTENT", tileMetadata),
  35. },
  36. };
  37. }
  38. /**
  39. * Parse the bounding volume from a tile metadata. If the metadata specify
  40. * multiple bounding volumes, only the first one is returned. Bounding volumes
  41. * are checked in the order box, region, then sphere.
  42. *
  43. * This handles both tile and content bounding volumes, as the only difference
  44. * is the prefix. e.g. <code>TILE_BOUNDING_BOX</code> and
  45. * <code>CONTENT_BOUNDING_BOX</code> have the same memory layout.
  46. *
  47. * @param {string} prefix Either "TILE" or "CONTENT"
  48. * @param {TileMetadata} tileMetadata The tileMetadata for looking up values
  49. * @return {object} An object representing the JSON description of the tile metadata
  50. * @private
  51. */
  52. function parseBoundingVolume(prefix, tileMetadata) {
  53. const boundingBoxSemantic = `${prefix}_BOUNDING_BOX`;
  54. const boundingBox = tileMetadata.getPropertyBySemantic(boundingBoxSemantic);
  55. if (defined(boundingBox)) {
  56. return {
  57. box: boundingBox,
  58. };
  59. }
  60. const boundingRegionSemantic = `${prefix}_BOUNDING_REGION`;
  61. const boundingRegion = tileMetadata.getPropertyBySemantic(
  62. boundingRegionSemantic
  63. );
  64. if (defined(boundingRegion)) {
  65. return {
  66. region: boundingRegion,
  67. };
  68. }
  69. const boundingSphereSemantic = `${prefix}_BOUNDING_SPHERE`;
  70. const boundingSphere = tileMetadata.getPropertyBySemantic(
  71. boundingSphereSemantic
  72. );
  73. if (defined(boundingSphere)) {
  74. // ARRAY with 4 elements is automatically converted to a Cartesian4
  75. return {
  76. sphere: boundingSphere,
  77. };
  78. }
  79. return undefined;
  80. }
  81. /**
  82. * Parse the minimum height from tile metadata. This is used for making tighter
  83. * quadtree bounds for implicit tiling. This works for both
  84. * <code>TILE_MINIMUM_HEIGHT</code> and <code>CONTENT_MINIMUM_HEIGHT</code>
  85. *
  86. * @param {string} prefix Either "TILE" or "CONTENT"
  87. * @param {TileMetadata} tileMetadata The tileMetadata for looking up values
  88. * @return {number} The minimum height
  89. * @private
  90. */
  91. function parseMinimumHeight(prefix, tileMetadata) {
  92. const minimumHeightSemantic = `${prefix}_MINIMUM_HEIGHT`;
  93. return tileMetadata.getPropertyBySemantic(minimumHeightSemantic);
  94. }
  95. /**
  96. * Parse the maximum height from tile metadata. This is used for making tighter
  97. * quadtree bounds for implicit tiling. This works for both
  98. * <code>TILE_MAXIMUM_HEIGHT</code> and <code>CONTENT_MAXIMUM_HEIGHT</code>
  99. *
  100. * @param {string} prefix Either "TILE" or "CONTENT"
  101. * @param {TileMetadata} tileMetadata The tileMetadata for looking up values
  102. * @return {number} The maximum height
  103. * @private
  104. */
  105. function parseMaximumHeight(prefix, tileMetadata) {
  106. const maximumHeightSemantic = `${prefix}_MAXIMUM_HEIGHT`;
  107. return tileMetadata.getPropertyBySemantic(maximumHeightSemantic);
  108. }
  109. export default parseBoundingVolumeSemantics;