GridMaterialProperty.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*global define*/
  2. define([
  3. '../Core/Cartesian2',
  4. '../Core/Color',
  5. '../Core/defined',
  6. '../Core/defineProperties',
  7. '../Core/Event',
  8. './createPropertyDescriptor',
  9. './Property'
  10. ], function(
  11. Cartesian2,
  12. Color,
  13. defined,
  14. defineProperties,
  15. Event,
  16. createPropertyDescriptor,
  17. Property) {
  18. "use strict";
  19. var defaultColor = Color.WHITE;
  20. var defaultCellAlpha = 0.1;
  21. var defaultLineCount = new Cartesian2(8, 8);
  22. var defaultLineOffset = new Cartesian2(0, 0);
  23. var defaultLineThickness = new Cartesian2(1, 1);
  24. /**
  25. * A {@link MaterialProperty} that maps to grid {@link Material} uniforms.
  26. * @alias GridMaterialProperty
  27. * @constructor
  28. */
  29. var GridMaterialProperty = function() {
  30. this._definitionChanged = new Event();
  31. this._color = undefined;
  32. this._colorSubscription = undefined;
  33. this._cellAlpha = undefined;
  34. this._cellAlphaSubscription = undefined;
  35. this._lineCount = undefined;
  36. this._lineCountSubscription = undefined;
  37. this._lineThickness = undefined;
  38. this._lineThicknessSubscription = undefined;
  39. this._lineOffset = undefined;
  40. this._lineOffsetSubscription = undefined;
  41. this.color = undefined;
  42. this.cellAlpha = undefined;
  43. this.lineCount = undefined;
  44. this.lineThickness = undefined;
  45. this.lineOffset = undefined;
  46. };
  47. defineProperties(GridMaterialProperty.prototype, {
  48. /**
  49. * Gets a value indicating if this property is constant. A property is considered
  50. * constant if getValue always returns the same result for the current definition.
  51. * @memberof GridMaterialProperty.prototype
  52. *
  53. * @type {Boolean}
  54. * @readonly
  55. */
  56. isConstant : {
  57. get : function() {
  58. return Property.isConstant(this._color) &&
  59. Property.isConstant(this._cellAlpha) &&
  60. Property.isConstant(this._lineCount) &&
  61. Property.isConstant(this._lineThickness) &&
  62. Property.isConstant(this._lineOffset);
  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 GridMaterialProperty.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 {@link Color} property which determines the grid's color.
  81. * @memberof GridMaterialProperty.prototype
  82. * @type {Property}
  83. */
  84. color : createPropertyDescriptor('color'),
  85. /**
  86. * Gets or sets the numeric property which determines the grid cells alpha value, when combined with the color alpha.
  87. * @memberof GridMaterialProperty.prototype
  88. * @type {Property}
  89. */
  90. cellAlpha : createPropertyDescriptor('cellAlpha'),
  91. /**
  92. * Gets or sets the {@link Cartesian2} property which determines the number of rows and columns in the grid.
  93. * @memberof GridMaterialProperty.prototype
  94. * @type {Property}
  95. */
  96. lineCount : createPropertyDescriptor('lineCount'),
  97. /**
  98. * Gets or sets the {@link Cartesian2} property which determines the thickness of rows and columns in the grid.
  99. * @memberof GridMaterialProperty.prototype
  100. * @type {Property}
  101. */
  102. lineThickness : createPropertyDescriptor('lineThickness'),
  103. /**
  104. * Gets or sets the {@link Cartesian2} property which determines the offset of rows and columns in the grid.
  105. * @memberof GridMaterialProperty.prototype
  106. * @type {Property}
  107. */
  108. lineOffset : createPropertyDescriptor('lineOffset')
  109. });
  110. /**
  111. * Gets the {@link Material} type at the provided time.
  112. *
  113. * @param {JulianDate} time The time for which to retrieve the type.
  114. * @returns {String} The type of material.
  115. */
  116. GridMaterialProperty.prototype.getType = function(time) {
  117. return 'Grid';
  118. };
  119. /**
  120. * Gets the value of the property at the provided time.
  121. *
  122. * @param {JulianDate} time The time for which to retrieve the value.
  123. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  124. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  125. */
  126. GridMaterialProperty.prototype.getValue = function(time, result) {
  127. if (!defined(result)) {
  128. result = {};
  129. }
  130. result.color = Property.getValueOrClonedDefault(this._color, time, defaultColor, result.color);
  131. result.cellAlpha = Property.getValueOrDefault(this._cellAlpha, time, defaultCellAlpha);
  132. result.lineCount = Property.getValueOrClonedDefault(this._lineCount, time, defaultLineCount, result.lineCount);
  133. result.lineThickness = Property.getValueOrClonedDefault(this._lineThickness, time, defaultLineThickness, result.lineThickness);
  134. result.lineOffset = Property.getValueOrClonedDefault(this._lineOffset, time, defaultLineOffset, result.lineOffset);
  135. return result;
  136. };
  137. /**
  138. * Compares this property to the provided property and returns
  139. * <code>true</code> if they are equal, <code>false</code> otherwise.
  140. *
  141. * @param {Property} [other] The other property.
  142. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  143. */
  144. GridMaterialProperty.prototype.equals = function(other) {
  145. return this === other || //
  146. (other instanceof GridMaterialProperty && //
  147. Property.equals(this._color, other._color) && //
  148. Property.equals(this._cellAlpha, other._cellAlpha) && //
  149. Property.equals(this._lineCount, other._lineCount) && //
  150. Property.equals(this._lineThickness, other._lineThickness) && //
  151. Property.equals(this._lineOffset, other._lineOffset));
  152. };
  153. return GridMaterialProperty;
  154. });