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

StripeMaterialProperty.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import Color from "../Core/Color.js";
  2. import Frozen from "../Core/Frozen.js";
  3. import defined from "../Core/defined.js";
  4. import Event from "../Core/Event.js";
  5. import JulianDate from "../Core/JulianDate.js";
  6. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  7. import Property from "./Property.js";
  8. import StripeOrientation from "./StripeOrientation.js";
  9. const defaultOrientation = StripeOrientation.HORIZONTAL;
  10. const defaultEvenColor = Color.WHITE;
  11. const defaultOddColor = Color.BLACK;
  12. const defaultOffset = 0;
  13. const defaultRepeat = 1;
  14. /**
  15. * A {@link MaterialProperty} that maps to stripe {@link Material} uniforms.
  16. * @alias StripeMaterialProperty
  17. * @constructor
  18. *
  19. * @param {object} [options] Object with the following properties:
  20. * @param {Property|StripeOrientation} [options.orientation=StripeOrientation.HORIZONTAL] A Property specifying the {@link StripeOrientation}.
  21. * @param {Property|Color} [options.evenColor=Color.WHITE] A Property specifying the first {@link Color}.
  22. * @param {Property|Color} [options.oddColor=Color.BLACK] A Property specifying the second {@link Color}.
  23. * @param {Property|number} [options.offset=0] A numeric Property specifying how far into the pattern to start the material.
  24. * @param {Property|number} [options.repeat=1] A numeric Property specifying how many times the stripes repeat.
  25. */
  26. function StripeMaterialProperty(options) {
  27. options = options ?? Frozen.EMPTY_OBJECT;
  28. this._definitionChanged = new Event();
  29. this._orientation = undefined;
  30. this._orientationSubscription = undefined;
  31. this._evenColor = undefined;
  32. this._evenColorSubscription = undefined;
  33. this._oddColor = undefined;
  34. this._oddColorSubscription = undefined;
  35. this._offset = undefined;
  36. this._offsetSubscription = undefined;
  37. this._repeat = undefined;
  38. this._repeatSubscription = undefined;
  39. this.orientation = options.orientation;
  40. this.evenColor = options.evenColor;
  41. this.oddColor = options.oddColor;
  42. this.offset = options.offset;
  43. this.repeat = options.repeat;
  44. }
  45. Object.defineProperties(StripeMaterialProperty.prototype, {
  46. /**
  47. * Gets a value indicating if this property is constant. A property is considered
  48. * constant if getValue always returns the same result for the current definition.
  49. * @memberof StripeMaterialProperty.prototype
  50. *
  51. * @type {boolean}
  52. * @readonly
  53. */
  54. isConstant: {
  55. get: function () {
  56. return (
  57. Property.isConstant(this._orientation) && //
  58. Property.isConstant(this._evenColor) && //
  59. Property.isConstant(this._oddColor) && //
  60. Property.isConstant(this._offset) && //
  61. Property.isConstant(this._repeat)
  62. );
  63. },
  64. },
  65. /**
  66. * Gets the event that is raised whenever the definition of this property changes.
  67. * The definition is considered to have changed if a call to getValue would return
  68. * a different result for the same time.
  69. * @memberof StripeMaterialProperty.prototype
  70. *
  71. * @type {Event}
  72. * @readonly
  73. */
  74. definitionChanged: {
  75. get: function () {
  76. return this._definitionChanged;
  77. },
  78. },
  79. /**
  80. * Gets or sets the Property specifying the {@link StripeOrientation}/
  81. * @memberof StripeMaterialProperty.prototype
  82. * @type {Property|undefined}
  83. * @default StripeOrientation.HORIZONTAL
  84. */
  85. orientation: createPropertyDescriptor("orientation"),
  86. /**
  87. * Gets or sets the Property specifying the first {@link Color}.
  88. * @memberof StripeMaterialProperty.prototype
  89. * @type {Property|undefined}
  90. * @default Color.WHITE
  91. */
  92. evenColor: createPropertyDescriptor("evenColor"),
  93. /**
  94. * Gets or sets the Property specifying the second {@link Color}.
  95. * @memberof StripeMaterialProperty.prototype
  96. * @type {Property|undefined}
  97. * @default Color.BLACK
  98. */
  99. oddColor: createPropertyDescriptor("oddColor"),
  100. /**
  101. * Gets or sets the numeric Property specifying the point into the pattern
  102. * to begin drawing; with 0.0 being the beginning of the even color, 1.0 the beginning
  103. * of the odd color, 2.0 being the even color again, and any multiple or fractional values
  104. * being in between.
  105. * @memberof StripeMaterialProperty.prototype
  106. * @type {Property|undefined}
  107. * @default 0.0
  108. */
  109. offset: createPropertyDescriptor("offset"),
  110. /**
  111. * Gets or sets the numeric Property specifying how many times the stripes repeat.
  112. * @memberof StripeMaterialProperty.prototype
  113. * @type {Property|undefined}
  114. * @default 1.0
  115. */
  116. repeat: createPropertyDescriptor("repeat"),
  117. });
  118. /**
  119. * Gets the {@link Material} type at the provided time.
  120. *
  121. * @param {JulianDate} time The time for which to retrieve the type.
  122. * @returns {string} The type of material.
  123. */
  124. StripeMaterialProperty.prototype.getType = function (time) {
  125. return "Stripe";
  126. };
  127. const timeScratch = new JulianDate();
  128. /**
  129. * Gets the value of the property at the provided time.
  130. *
  131. * @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  132. * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  133. * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
  134. */
  135. StripeMaterialProperty.prototype.getValue = function (time, result) {
  136. if (!defined(time)) {
  137. time = JulianDate.now(timeScratch);
  138. }
  139. if (!defined(result)) {
  140. result = {};
  141. }
  142. result.horizontal =
  143. Property.getValueOrDefault(this._orientation, time, defaultOrientation) ===
  144. StripeOrientation.HORIZONTAL;
  145. result.evenColor = Property.getValueOrClonedDefault(
  146. this._evenColor,
  147. time,
  148. defaultEvenColor,
  149. result.evenColor,
  150. );
  151. result.oddColor = Property.getValueOrClonedDefault(
  152. this._oddColor,
  153. time,
  154. defaultOddColor,
  155. result.oddColor,
  156. );
  157. result.offset = Property.getValueOrDefault(this._offset, time, defaultOffset);
  158. result.repeat = Property.getValueOrDefault(this._repeat, time, defaultRepeat);
  159. return result;
  160. };
  161. /**
  162. * Compares this property to the provided property and returns
  163. * <code>true</code> if they are equal, <code>false</code> otherwise.
  164. *
  165. * @param {Property} [other] The other property.
  166. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  167. */
  168. StripeMaterialProperty.prototype.equals = function (other) {
  169. return (
  170. this === other || //
  171. (other instanceof StripeMaterialProperty && //
  172. Property.equals(this._orientation, other._orientation) && //
  173. Property.equals(this._evenColor, other._evenColor) && //
  174. Property.equals(this._oddColor, other._oddColor) && //
  175. Property.equals(this._offset, other._offset) && //
  176. Property.equals(this._repeat, other._repeat))
  177. );
  178. };
  179. export default StripeMaterialProperty;