智慧水务管理系统 - 精河县供水工程综合管理平台

PropertyTextureProperty.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import Check from "../Core/Check.js";
  2. import Frozen from "../Core/Frozen.js";
  3. import defined from "../Core/defined.js";
  4. import GltfLoaderUtil from "./GltfLoaderUtil.js";
  5. /**
  6. * A property in a property texture.
  7. *
  8. * <p>
  9. * 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
  10. * previous {@link https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata|EXT_feature_metadata Extension} for glTF.
  11. * </p>
  12. *
  13. * @param {object} options Object with the following properties:
  14. * @param {object} options.property The property JSON object.
  15. * @param {MetadataClassProperty} options.classProperty The class property.
  16. * @param {Object<number, Texture>} options.textures An object mapping texture IDs to {@link Texture} objects.
  17. *
  18. * @alias PropertyTextureProperty
  19. * @constructor
  20. *
  21. * @private
  22. * @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.
  23. */
  24. function PropertyTextureProperty(options) {
  25. options = options ?? Frozen.EMPTY_OBJECT;
  26. const property = options.property;
  27. const classProperty = options.classProperty;
  28. const textures = options.textures;
  29. //>>includeStart('debug', pragmas.debug);
  30. Check.typeOf.object("options.property", property);
  31. Check.typeOf.object("options.classProperty", classProperty);
  32. Check.typeOf.object("options.textures", textures);
  33. //>>includeEnd('debug');
  34. // in EXT_structural_metadata, the property is a valid glTF textureInfo
  35. const channels = defined(property.channels) ? property.channels : [0];
  36. const textureInfo = property;
  37. const textureReader = GltfLoaderUtil.createModelTextureReader({
  38. textureInfo: textureInfo,
  39. channels: reformatChannels(channels),
  40. texture: textures[textureInfo.index],
  41. });
  42. this._min = property.min;
  43. this._max = property.max;
  44. let offset = property.offset;
  45. let scale = property.scale;
  46. // This needs to be set before handling default values
  47. const hasValueTransform =
  48. classProperty.hasValueTransform || defined(offset) || defined(scale);
  49. // If the property attribute does not define an offset/scale, it inherits from
  50. // the class property. The class property handles setting the default of
  51. // identity: (offset 0, scale 1) with the same scalar/vector/matrix types.
  52. // array types are disallowed by the spec.
  53. offset = offset ?? classProperty.offset;
  54. scale = scale ?? classProperty.scale;
  55. // offset and scale are applied on the GPU, so unpack the values
  56. // as math types we can use in uniform callbacks.
  57. offset = classProperty.unpackVectorAndMatrixTypes(offset);
  58. scale = classProperty.unpackVectorAndMatrixTypes(scale);
  59. this._offset = offset;
  60. this._scale = scale;
  61. this._hasValueTransform = hasValueTransform;
  62. this._textureReader = textureReader;
  63. this._classProperty = classProperty;
  64. this._extras = property.extras;
  65. this._extensions = property.extensions;
  66. }
  67. Object.defineProperties(PropertyTextureProperty.prototype, {
  68. /**
  69. * The texture reader.
  70. *
  71. * @memberof PropertyTextureProperty.prototype
  72. * @type {ModelComponents.TextureReader}
  73. * @readonly
  74. * @private
  75. */
  76. textureReader: {
  77. get: function () {
  78. return this._textureReader;
  79. },
  80. },
  81. /**
  82. * True if offset/scale should be applied. If both offset/scale were
  83. * undefined, they default to identity so this property is set false
  84. *
  85. * @memberof PropertyTextureProperty.prototype
  86. * @type {boolean}
  87. * @readonly
  88. * @private
  89. */
  90. hasValueTransform: {
  91. get: function () {
  92. return this._hasValueTransform;
  93. },
  94. },
  95. /**
  96. * The offset to be added to property values as part of the value transform.
  97. *
  98. * This is always defined, even when `hasValueTransform` is `false`. If
  99. * the property JSON itself did not define it, then it will inherit the
  100. * value from the `MetadataClassProperty`. There, it also is always
  101. * defined, and initialized to the default value if it was not contained
  102. * in the class property JSON.
  103. *
  104. * @memberof PropertyTextureProperty.prototype
  105. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  106. * @readonly
  107. * @private
  108. */
  109. offset: {
  110. get: function () {
  111. return this._offset;
  112. },
  113. },
  114. /**
  115. * The scale to be multiplied to property values as part of the value transform.
  116. *
  117. * This is always defined, even when `hasValueTransform` is `false`. If
  118. * the property JSON itself did not define it, then it will inherit the
  119. * value from the `MetadataClassProperty`. There, it also is always
  120. * defined, and initialized to the default value if it was not contained
  121. * in the class property JSON.
  122. *
  123. * @memberof PropertyTextureProperty.prototype
  124. * @type {number|Cartesian2|Cartesian3|Cartesian4|Matrix2|Matrix3|Matrix4}
  125. * @readonly
  126. * @private
  127. */
  128. scale: {
  129. get: function () {
  130. return this._scale;
  131. },
  132. },
  133. /**
  134. * The properties inherited from this property's class
  135. *
  136. * @memberof PropertyTextureProperty.prototype
  137. * @type {MetadataClassProperty}
  138. * @readonly
  139. * @private
  140. */
  141. classProperty: {
  142. get: function () {
  143. return this._classProperty;
  144. },
  145. },
  146. /**
  147. * Extra user-defined properties.
  148. *
  149. * @memberof PropertyTextureProperty.prototype
  150. * @type {*}
  151. * @readonly
  152. * @private
  153. */
  154. extras: {
  155. get: function () {
  156. return this._extras;
  157. },
  158. },
  159. /**
  160. * An object containing extensions.
  161. *
  162. * @memberof PropertyTextureProperty.prototype
  163. * @type {*}
  164. * @readonly
  165. * @private
  166. */
  167. extensions: {
  168. get: function () {
  169. return this._extensions;
  170. },
  171. },
  172. });
  173. /**
  174. * Reformat from an array of channel indices like <code>[0, 1]</code> to a
  175. * string of channels as would be used in GLSL swizzling (e.g. "rg")
  176. *
  177. * @param {number[]} channels the channel indices
  178. * @return {string} The channels as a string of "r", "g", "b" or "a" characters.
  179. * @private
  180. */
  181. function reformatChannels(channels) {
  182. return channels
  183. .map(function (channelIndex) {
  184. return "rgba".charAt(channelIndex);
  185. })
  186. .join("");
  187. }
  188. export default PropertyTextureProperty;