StripeMaterialProperty.js 6.3 KB

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