PropertyAttributeProperty.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. /**
  5. * A property in a property attribute from EXT_structural_metadata.
  6. *
  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}
  9. * </p>
  10. *
  11. * @param {Object} options Object with the following properties:
  12. * @param {Object} options.property The property JSON object.
  13. * @param {MetadataClassProperty} options.classProperty The class property.
  14. *
  15. * @alias PropertyAttributeProperty
  16. * @constructor
  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. export default function PropertyAttributeProperty(options) {
  22. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  23. const property = options.property;
  24. const classProperty = options.classProperty;
  25. //>>includeStart('debug', pragmas.debug);
  26. Check.typeOf.object("options.property", property);
  27. Check.typeOf.object("options.classProperty", classProperty);
  28. //>>includeEnd('debug');
  29. this._attribute = property.attribute;
  30. this._classProperty = classProperty;
  31. this._min = property.min;
  32. this._max = property.max;
  33. let offset = property.offset;
  34. let scale = property.scale;
  35. // This needs to be set before handling default values
  36. const hasValueTransform =
  37. classProperty.hasValueTransform || defined(offset) || defined(scale);
  38. // If the property attribute does not define an offset/scale, it inherits from
  39. // the class property. The class property handles setting the default of
  40. // identity: (offset 0, scale 1) with the same scalar/vector/matrix types.
  41. // array types are disallowed by the spec.
  42. offset = defaultValue(offset, classProperty.offset);
  43. scale = defaultValue(scale, classProperty.scale);
  44. // offset and scale are applied on the GPU, so unpack the values
  45. // as math types we can use in uniform callbacks.
  46. offset = classProperty.unpackVectorAndMatrixTypes(offset);
  47. scale = classProperty.unpackVectorAndMatrixTypes(scale);
  48. this._offset = offset;
  49. this._scale = scale;
  50. this._hasValueTransform = hasValueTransform;
  51. this._extras = property.extras;
  52. this._extensions = property.extensions;
  53. }
  54. Object.defineProperties(PropertyAttributeProperty.prototype, {
  55. /**
  56. * The attribute semantic
  57. *
  58. * @memberof PropertyAttributeProperty.prototype
  59. * @type {String}
  60. * @readonly
  61. * @private
  62. */
  63. attribute: {
  64. get: function () {
  65. return this._attribute;
  66. },
  67. },
  68. /**
  69. * True if offset/scale should be applied. If both offset/scale were
  70. * undefined, they default to identity so this property is set false
  71. *
  72. * @memberof MetadataClassProperty.prototype
  73. * @type {Boolean}
  74. * @readonly
  75. * @private
  76. */
  77. hasValueTransform: {
  78. get: function () {
  79. return this._hasValueTransform;
  80. },
  81. },
  82. /**
  83. * The offset to be added to property values as part of the value transform.
  84. *
  85. * @memberof MetadataClassProperty.prototype
  86. * @type {Number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  87. * @readonly
  88. * @private
  89. */
  90. offset: {
  91. get: function () {
  92. return this._offset;
  93. },
  94. },
  95. /**
  96. * The scale to be multiplied to property values as part of the value transform.
  97. *
  98. * @memberof MetadataClassProperty.prototype
  99. * @type {Number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  100. * @readonly
  101. * @private
  102. */
  103. scale: {
  104. get: function () {
  105. return this._scale;
  106. },
  107. },
  108. /**
  109. * Extras in the JSON object.
  110. *
  111. * @memberof PropertyAttributeProperty.prototype
  112. * @type {*}
  113. * @readonly
  114. * @private
  115. */
  116. extras: {
  117. get: function () {
  118. return this._extras;
  119. },
  120. },
  121. /**
  122. * Extensions in the JSON object.
  123. *
  124. * @memberof PropertyAttributeProperty.prototype
  125. * @type {*}
  126. * @readonly
  127. * @private
  128. */
  129. extensions: {
  130. get: function () {
  131. return this._extensions;
  132. },
  133. },
  134. });