ColorMaterialProperty.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import Color from '../Core/Color.js';
  2. import defined from '../Core/defined.js';
  3. import defineProperties from '../Core/defineProperties.js';
  4. import Event from '../Core/Event.js';
  5. import createPropertyDescriptor from './createPropertyDescriptor.js';
  6. import Property from './Property.js';
  7. /**
  8. * A {@link MaterialProperty} that maps to solid color {@link Material} uniforms.
  9. *
  10. * @param {Property} [color=Color.WHITE] The {@link Color} Property to be used.
  11. *
  12. * @alias ColorMaterialProperty
  13. * @constructor
  14. */
  15. function ColorMaterialProperty(color) {
  16. this._definitionChanged = new Event();
  17. this._color = undefined;
  18. this._colorSubscription = undefined;
  19. this.color = color;
  20. }
  21. defineProperties(ColorMaterialProperty.prototype, {
  22. /**
  23. * Gets a value indicating if this property is constant. A property is considered
  24. * constant if getValue always returns the same result for the current definition.
  25. * @memberof ColorMaterialProperty.prototype
  26. *
  27. * @type {Boolean}
  28. * @readonly
  29. */
  30. isConstant : {
  31. get : function() {
  32. return Property.isConstant(this._color);
  33. }
  34. },
  35. /**
  36. * Gets the event that is raised whenever the definition of this property changes.
  37. * The definition is considered to have changed if a call to getValue would return
  38. * a different result for the same time.
  39. * @memberof ColorMaterialProperty.prototype
  40. *
  41. * @type {Event}
  42. * @readonly
  43. */
  44. definitionChanged : {
  45. get : function() {
  46. return this._definitionChanged;
  47. }
  48. },
  49. /**
  50. * Gets or sets the {@link Color} {@link Property}.
  51. * @memberof ColorMaterialProperty.prototype
  52. * @type {Property}
  53. * @default Color.WHITE
  54. */
  55. color : createPropertyDescriptor('color')
  56. });
  57. /**
  58. * Gets the {@link Material} type at the provided time.
  59. *
  60. * @param {JulianDate} time The time for which to retrieve the type.
  61. * @returns {String} The type of material.
  62. */
  63. ColorMaterialProperty.prototype.getType = function(time) {
  64. return 'Color';
  65. };
  66. /**
  67. * Gets the value of the property at the provided time.
  68. *
  69. * @param {JulianDate} time The time for which to retrieve the value.
  70. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  71. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  72. */
  73. ColorMaterialProperty.prototype.getValue = function(time, result) {
  74. if (!defined(result)) {
  75. result = {};
  76. }
  77. result.color = Property.getValueOrClonedDefault(this._color, time, Color.WHITE, result.color);
  78. return result;
  79. };
  80. /**
  81. * Compares this property to the provided property and returns
  82. * <code>true</code> if they are equal, <code>false</code> otherwise.
  83. *
  84. * @param {Property} [other] The other property.
  85. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  86. */
  87. ColorMaterialProperty.prototype.equals = function(other) {
  88. return this === other || //
  89. (other instanceof ColorMaterialProperty && //
  90. Property.equals(this._color, other._color));
  91. };
  92. export default ColorMaterialProperty;