PropertyTexture.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import PropertyTextureProperty from "./PropertyTextureProperty.js";
  5. /**
  6. * A property texture.
  7. * <p>
  8. * See the {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata|EXT_structural_metadata Extension} as well as the
  9. * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.
  10. * </p>
  11. *
  12. * @param {object} options Object with the following properties:
  13. * @param {string} [options.name] Optional human-readable name to describe the texture
  14. * @param {string|number} [options.id] A unique id to identify the property texture, useful for debugging. For <code>EXT_structural_metadata</code>, this is the array index in the property textures array, for <code>EXT_feature_metadata</code> this is the dictionary key in the property textures dictionary.
  15. * @param {object} options.propertyTexture The property texture JSON, following the EXT_structural_metadata schema.
  16. * @param {MetadataClass} options.class The class that properties conform to.
  17. * @param {Object<string, Texture>} options.textures An object mapping texture IDs to {@link Texture} objects.
  18. *
  19. * @alias PropertyTexture
  20. * @constructor
  21. *
  22. * @private
  23. * @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.
  24. */
  25. function PropertyTexture(options) {
  26. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  27. const propertyTexture = options.propertyTexture;
  28. const classDefinition = options.class;
  29. const textures = options.textures;
  30. //>>includeStart('debug', pragmas.debug);
  31. Check.typeOf.object("options.propertyTexture", propertyTexture);
  32. Check.typeOf.object("options.class", classDefinition);
  33. Check.typeOf.object("options.textures", textures);
  34. //>>includeEnd('debug');
  35. const extensions = propertyTexture.extensions;
  36. const extras = propertyTexture.extras;
  37. const properties = {};
  38. if (defined(propertyTexture.properties)) {
  39. for (const propertyId in propertyTexture.properties) {
  40. if (propertyTexture.properties.hasOwnProperty(propertyId)) {
  41. properties[propertyId] = new PropertyTextureProperty({
  42. property: propertyTexture.properties[propertyId],
  43. classProperty: classDefinition.properties[propertyId],
  44. textures: textures,
  45. });
  46. }
  47. }
  48. }
  49. this._name = options.name;
  50. this._id = options.id;
  51. this._class = classDefinition;
  52. this._properties = properties;
  53. this._extras = extras;
  54. this._extensions = extensions;
  55. }
  56. Object.defineProperties(PropertyTexture.prototype, {
  57. /**
  58. * A human-readable name for this texture
  59. *
  60. * @memberof PropertyTexture.prototype
  61. * @type {string}
  62. * @readonly
  63. * @private
  64. */
  65. name: {
  66. get: function () {
  67. return this._name;
  68. },
  69. },
  70. /**
  71. * An identifier for this texture. Useful for debugging.
  72. *
  73. * @memberof PropertyTexture.prototype
  74. * @type {string|number}
  75. * @readonly
  76. * @private
  77. */
  78. id: {
  79. get: function () {
  80. return this._id;
  81. },
  82. },
  83. /**
  84. * The class that properties conform to.
  85. *
  86. * @memberof PropertyTexture.prototype
  87. * @type {MetadataClass}
  88. * @readonly
  89. * @private
  90. */
  91. class: {
  92. get: function () {
  93. return this._class;
  94. },
  95. },
  96. /**
  97. * The properties in this property texture.
  98. *
  99. * @memberof PropertyTexture.prototype
  100. *
  101. * @type {PropertyTextureProperty}
  102. * @readonly
  103. * @private
  104. */
  105. properties: {
  106. get: function () {
  107. return this._properties;
  108. },
  109. },
  110. /**
  111. * Extra user-defined properties.
  112. *
  113. * @memberof PropertyTexture.prototype
  114. * @type {*}
  115. * @readonly
  116. * @private
  117. */
  118. extras: {
  119. get: function () {
  120. return this._extras;
  121. },
  122. },
  123. /**
  124. * An object containing extensions.
  125. *
  126. * @memberof PropertyTexture.prototype
  127. * @type {object}
  128. * @readonly
  129. * @private
  130. */
  131. extensions: {
  132. get: function () {
  133. return this._extensions;
  134. },
  135. },
  136. });
  137. /**
  138. * Gets the property with the given property ID.
  139. *
  140. * @param {string} propertyId The case-sensitive ID of the property.
  141. * @returns {PropertyTextureProperty|undefined} The property, or <code>undefined</code> if the property does not exist.
  142. * @private
  143. */
  144. PropertyTexture.prototype.getProperty = function (propertyId) {
  145. //>>includeStart('debug', pragmas.debug);
  146. Check.typeOf.string("propertyId", propertyId);
  147. //>>includeEnd('debug');
  148. return this._properties[propertyId];
  149. };
  150. export default PropertyTexture;