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

CheckerboardMaterialProperty.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import Cartesian2 from "../Core/Cartesian2.js";
  2. import Color from "../Core/Color.js";
  3. import Frozen from "../Core/Frozen.js";
  4. import defined from "../Core/defined.js";
  5. import Event from "../Core/Event.js";
  6. import JulianDate from "../Core/JulianDate.js";
  7. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  8. import Property from "./Property.js";
  9. const defaultEvenColor = Color.WHITE;
  10. const defaultOddColor = Color.BLACK;
  11. const defaultRepeat = new Cartesian2(2.0, 2.0);
  12. /**
  13. * A {@link MaterialProperty} that maps to checkerboard {@link Material} uniforms.
  14. * @alias CheckerboardMaterialProperty
  15. * @constructor
  16. *
  17. * @param {object} [options] Object with the following properties:
  18. * @param {Property|Color} [options.evenColor=Color.WHITE] A Property specifying the first {@link Color}.
  19. * @param {Property|Color} [options.oddColor=Color.BLACK] A Property specifying the second {@link Color}.
  20. * @param {Property|Cartesian2} [options.repeat=new Cartesian2(2.0, 2.0)] A {@link Cartesian2} Property specifying how many times the tiles repeat in each direction.
  21. */
  22. function CheckerboardMaterialProperty(options) {
  23. options = options ?? Frozen.EMPTY_OBJECT;
  24. this._definitionChanged = new Event();
  25. this._evenColor = undefined;
  26. this._evenColorSubscription = undefined;
  27. this._oddColor = undefined;
  28. this._oddColorSubscription = undefined;
  29. this._repeat = undefined;
  30. this._repeatSubscription = undefined;
  31. this.evenColor = options.evenColor;
  32. this.oddColor = options.oddColor;
  33. this.repeat = options.repeat;
  34. }
  35. Object.defineProperties(CheckerboardMaterialProperty.prototype, {
  36. /**
  37. * Gets a value indicating if this property is constant. A property is considered
  38. * constant if getValue always returns the same result for the current definition.
  39. * @memberof CheckerboardMaterialProperty.prototype
  40. *
  41. * @type {boolean}
  42. * @readonly
  43. */
  44. isConstant: {
  45. get: function () {
  46. return (
  47. Property.isConstant(this._evenColor) && //
  48. Property.isConstant(this._oddColor) && //
  49. Property.isConstant(this._repeat)
  50. );
  51. },
  52. },
  53. /**
  54. * Gets the event that is raised whenever the definition of this property changes.
  55. * The definition is considered to have changed if a call to getValue would return
  56. * a different result for the same time.
  57. * @memberof CheckerboardMaterialProperty.prototype
  58. *
  59. * @type {Event}
  60. * @readonly
  61. */
  62. definitionChanged: {
  63. get: function () {
  64. return this._definitionChanged;
  65. },
  66. },
  67. /**
  68. * Gets or sets the Property specifying the first {@link Color}.
  69. * @memberof CheckerboardMaterialProperty.prototype
  70. * @type {Property|undefined}
  71. * @default Color.WHITE
  72. */
  73. evenColor: createPropertyDescriptor("evenColor"),
  74. /**
  75. * Gets or sets the Property specifying the second {@link Color}.
  76. * @memberof CheckerboardMaterialProperty.prototype
  77. * @type {Property|undefined}
  78. * @default Color.BLACK
  79. */
  80. oddColor: createPropertyDescriptor("oddColor"),
  81. /**
  82. * Gets or sets the {@link Cartesian2} Property specifying how many times the tiles repeat in each direction.
  83. * @memberof CheckerboardMaterialProperty.prototype
  84. * @type {Property|undefined}
  85. * @default new Cartesian2(2.0, 2.0)
  86. */
  87. repeat: createPropertyDescriptor("repeat"),
  88. });
  89. /**
  90. * Gets the {@link Material} type at the provided time.
  91. *
  92. * @param {JulianDate} time The time for which to retrieve the type.
  93. * @returns {string} The type of material.
  94. */
  95. CheckerboardMaterialProperty.prototype.getType = function (time) {
  96. return "Checkerboard";
  97. };
  98. const timeScratch = new JulianDate();
  99. /**
  100. * Gets the value of the property at the provided time.
  101. *
  102. * @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  103. * @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  104. * @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
  105. */
  106. CheckerboardMaterialProperty.prototype.getValue = function (time, result) {
  107. if (!defined(time)) {
  108. time = JulianDate.now(timeScratch);
  109. }
  110. if (!defined(result)) {
  111. result = {};
  112. }
  113. result.lightColor = Property.getValueOrClonedDefault(
  114. this._evenColor,
  115. time,
  116. defaultEvenColor,
  117. result.lightColor,
  118. );
  119. result.darkColor = Property.getValueOrClonedDefault(
  120. this._oddColor,
  121. time,
  122. defaultOddColor,
  123. result.darkColor,
  124. );
  125. result.repeat = Property.getValueOrDefault(this._repeat, time, defaultRepeat);
  126. return result;
  127. };
  128. /**
  129. * Compares this property to the provided property and returns
  130. * <code>true</code> if they are equal, <code>false</code> otherwise.
  131. *
  132. * @param {Property} [other] The other property.
  133. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  134. */
  135. CheckerboardMaterialProperty.prototype.equals = function (other) {
  136. return (
  137. this === other || //
  138. (other instanceof CheckerboardMaterialProperty && //
  139. Property.equals(this._evenColor, other._evenColor) && //
  140. Property.equals(this._oddColor, other._oddColor) && //
  141. Property.equals(this._repeat, other._repeat))
  142. );
  143. };
  144. export default CheckerboardMaterialProperty;