StructuralMetadata.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. /**
  5. * An object containing structural metadata.
  6. * <p>
  7. * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadatas|EXT_structural_metadata Extension} as well as the
  8. * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.
  9. * </p>
  10. *
  11. * @param {object} options Object with the following properties:
  12. * @param {MetadataSchema} options.schema The parsed schema.
  13. * @param {PropertyTable[]} [options.propertyTables] An array of property table objects. For the legacy <code>EXT_feature_metadata</code> extension, this is sorted by the key in the propertyTables dictionary
  14. * @param {PropertyTexture[]} [options.propertyTextures] An array of property texture objects. For the legacy <code>EXT_feature_metadata</code> extension, this is sorted by the key in the propertyTextures dictionary
  15. * @param {PropertyAttribute[]} [options.propertyAttributes] An array of property attribute objects. This is new in <code>EXT_structural_metadata</code>
  16. * @param {object} [options.statistics] Statistics about metadata
  17. * @param {object} [options.extras] Extra user-defined properties
  18. * @param {object} [options.extensions] An object containing extensions
  19. *
  20. * @alias StructuralMetadata
  21. * @constructor
  22. *
  23. * @private
  24. * @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.
  25. */
  26. function StructuralMetadata(options) {
  27. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  28. //>>includeStart('debug', pragmas.debug);
  29. Check.typeOf.object("options.schema", options.schema);
  30. //>>includeEnd('debug');
  31. this._schema = options.schema;
  32. const propertyTables = options.propertyTables;
  33. this._propertyTableCount = defined(propertyTables)
  34. ? propertyTables.length
  35. : 0;
  36. this._propertyTables = propertyTables;
  37. this._propertyTextures = options.propertyTextures;
  38. this._propertyAttributes = options.propertyAttributes;
  39. this._statistics = options.statistics;
  40. this._extras = options.extras;
  41. this._extensions = options.extensions;
  42. }
  43. Object.defineProperties(StructuralMetadata.prototype, {
  44. /**
  45. * Schema containing classes and enums.
  46. *
  47. * @memberof StructuralMetadata.prototype
  48. * @type {MetadataSchema}
  49. * @readonly
  50. * @private
  51. */
  52. schema: {
  53. get: function () {
  54. return this._schema;
  55. },
  56. },
  57. /**
  58. * Statistics about the metadata.
  59. * <p>
  60. * See the {@link https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata/schema/statistics.schema.json|statistics schema reference} for the full set of properties.
  61. * </p>
  62. *
  63. * @memberof StructuralMetadata.prototype
  64. * @type {object}
  65. * @readonly
  66. * @private
  67. */
  68. statistics: {
  69. get: function () {
  70. return this._statistics;
  71. },
  72. },
  73. /**
  74. * Extra user-defined properties.
  75. *
  76. * @memberof StructuralMetadata.prototype
  77. * @type {*}
  78. * @readonly
  79. * @private
  80. */
  81. extras: {
  82. get: function () {
  83. return this._extras;
  84. },
  85. },
  86. /**
  87. * An object containing extensions.
  88. *
  89. * @memberof StructuralMetadata.prototype
  90. * @type {object}
  91. * @readonly
  92. * @private
  93. */
  94. extensions: {
  95. get: function () {
  96. return this._extensions;
  97. },
  98. },
  99. /**
  100. * Number of property tables in the metadata.
  101. *
  102. * @memberof StructuralMetadata.prototype
  103. * @type {number}
  104. * @readonly
  105. * @private
  106. */
  107. propertyTableCount: {
  108. get: function () {
  109. return this._propertyTableCount;
  110. },
  111. },
  112. /**
  113. * The property tables in the metadata.
  114. *
  115. * @memberof StructuralMetadata.prototype
  116. * @type {PropertyTable[]}
  117. * @readonly
  118. * @private
  119. */
  120. propertyTables: {
  121. get: function () {
  122. return this._propertyTables;
  123. },
  124. },
  125. /**
  126. * The property textures in the metadata.
  127. *
  128. * @memberof StructuralMetadata.prototype
  129. * @type {PropertyTexture[]}
  130. * @readonly
  131. * @private
  132. */
  133. propertyTextures: {
  134. get: function () {
  135. return this._propertyTextures;
  136. },
  137. },
  138. /**
  139. * The property attributes from the structural metadata extension
  140. *
  141. * @memberof StructuralMetadata.prototype
  142. * @type {PropertyAttribute[]}
  143. * @readonly
  144. * @private
  145. */
  146. propertyAttributes: {
  147. get: function () {
  148. return this._propertyAttributes;
  149. },
  150. },
  151. /**
  152. * Total size in bytes across all property tables
  153. *
  154. * @memberof StructuralMetadata.prototype
  155. * @type {number}
  156. * @readonly
  157. * @private
  158. */
  159. propertyTablesByteLength: {
  160. get: function () {
  161. if (!defined(this._propertyTables)) {
  162. return 0;
  163. }
  164. let totalByteLength = 0;
  165. const length = this._propertyTables.length;
  166. for (let i = 0; i < length; i++) {
  167. totalByteLength += this._propertyTables[i].byteLength;
  168. }
  169. return totalByteLength;
  170. },
  171. },
  172. });
  173. /**
  174. * Gets the property table with the given ID.
  175. * <p>
  176. * For the legacy <code>EXT_feature_metadata</code>, textures are stored in an array sorted
  177. * by the key in the propertyTables dictionary.
  178. * </p>
  179. *
  180. * @param {number} propertyTableId The property table ID.
  181. * @returns {PropertyTable} The property table.
  182. * @private
  183. */
  184. StructuralMetadata.prototype.getPropertyTable = function (propertyTableId) {
  185. //>>includeStart('debug', pragmas.debug);
  186. Check.typeOf.number("propertyTableId", propertyTableId);
  187. //>>includeEnd('debug');
  188. return this._propertyTables[propertyTableId];
  189. };
  190. /**
  191. * Gets the property texture with the given ID.
  192. * <p>
  193. * For the legacy <code>EXT_feature_metadata</code>, textures are stored in an array sorted
  194. * by the key in the propertyTextures dictionary.
  195. * </p>
  196. *
  197. * @param {number} propertyTextureId The index into the property textures array.
  198. * @returns {PropertyTexture} The property texture
  199. * @private
  200. */
  201. StructuralMetadata.prototype.getPropertyTexture = function (propertyTextureId) {
  202. //>>includeStart('debug', pragmas.debug);
  203. Check.typeOf.number("propertyTextureId", propertyTextureId);
  204. //>>includeEnd('debug');
  205. return this._propertyTextures[propertyTextureId];
  206. };
  207. /**
  208. * Gets the property attribute with the given ID. This concept is new in
  209. * EXT_structural_metadata
  210. *
  211. * @param {number} propertyAttributeId The index into the property attributes array.
  212. * @returns {PropertyAttribute} The property attribute
  213. * @private
  214. */
  215. StructuralMetadata.prototype.getPropertyAttribute = function (
  216. propertyAttributeId
  217. ) {
  218. //>>includeStart('debug', pragmas.debug);
  219. Check.typeOf.number("propertyAttributeId", propertyAttributeId);
  220. //>>includeEnd('debug');
  221. return this._propertyAttributes[propertyAttributeId];
  222. };
  223. export default StructuralMetadata;