StructuralMetadata.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. * Extras in the JSON object.
  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. * Extensions in the JSON object.
  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. /**
  153. * Gets the property table with the given ID.
  154. * <p>
  155. * For the legacy <code>EXT_feature_metadata</code>, textures are stored in an array sorted
  156. * by the key in the propertyTables dictionary.
  157. * </p>
  158. *
  159. * @param {Number} propertyTableId The property table ID.
  160. * @returns {PropertyTable} The property table.
  161. * @private
  162. */
  163. StructuralMetadata.prototype.getPropertyTable = function (propertyTableId) {
  164. //>>includeStart('debug', pragmas.debug);
  165. Check.typeOf.number("propertyTableId", propertyTableId);
  166. //>>includeEnd('debug');
  167. return this._propertyTables[propertyTableId];
  168. };
  169. /**
  170. * Gets the property texture with the given ID.
  171. * <p>
  172. * For the legacy <code>EXT_feature_metadata</code>, textures are stored in an array sorted
  173. * by the key in the propertyTextures dictionary.
  174. * </p>
  175. *
  176. * @param {Number} propertyTextureId The index into the property textures array.
  177. * @returns {PropertyTexture} The property texture
  178. * @private
  179. */
  180. StructuralMetadata.prototype.getPropertyTexture = function (propertyTextureId) {
  181. //>>includeStart('debug', pragmas.debug);
  182. Check.typeOf.number("propertyTextureId", propertyTextureId);
  183. //>>includeEnd('debug');
  184. return this._propertyTextures[propertyTextureId];
  185. };
  186. /**
  187. * Gets the property attribute with the given ID. This concept is new in
  188. * EXT_structural_metadata
  189. *
  190. * @param {Number} propertyAttributeId The index into the property attributes array.
  191. * @returns {PropertyAttribute} The property attribute
  192. * @private
  193. */
  194. StructuralMetadata.prototype.getPropertyAttribute = function (
  195. propertyAttributeId
  196. ) {
  197. //>>includeStart('debug', pragmas.debug);
  198. Check.typeOf.number("propertyAttributeId", propertyAttributeId);
  199. //>>includeEnd('debug');
  200. return this._propertyAttributes[propertyAttributeId];
  201. };
  202. export default StructuralMetadata;