ImageMaterialProperty.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*global define*/
  2. define([
  3. '../Core/Cartesian2',
  4. '../Core/defined',
  5. '../Core/defineProperties',
  6. '../Core/Event',
  7. './createPropertyDescriptor',
  8. './Property'
  9. ], function(
  10. Cartesian2,
  11. defined,
  12. defineProperties,
  13. Event,
  14. createPropertyDescriptor,
  15. Property) {
  16. "use strict";
  17. var defaultRepeat = new Cartesian2(1, 1);
  18. /**
  19. * A {@link MaterialProperty} that maps to image {@link Material} uniforms.
  20. * @alias ImageMaterialProperty
  21. * @constructor
  22. */
  23. var ImageMaterialProperty = function() {
  24. this._definitionChanged = new Event();
  25. this._image = undefined;
  26. this._imageSubscription = undefined;
  27. this._repeat = undefined;
  28. this._repeatSubscription = undefined;
  29. };
  30. defineProperties(ImageMaterialProperty.prototype, {
  31. /**
  32. * Gets a value indicating if this property is constant. A property is considered
  33. * constant if getValue always returns the same result for the current definition.
  34. * @memberof ImageMaterialProperty.prototype
  35. *
  36. * @type {Boolean}
  37. * @readonly
  38. */
  39. isConstant : {
  40. get : function() {
  41. return Property.isConstant(this._image) && Property.isConstant(this._repeat);
  42. }
  43. },
  44. /**
  45. * Gets the event that is raised whenever the definition of this property changes.
  46. * The definition is considered to have changed if a call to getValue would return
  47. * a different result for the same time.
  48. * @memberof ImageMaterialProperty.prototype
  49. *
  50. * @type {Event}
  51. * @readonly
  52. */
  53. definitionChanged : {
  54. get : function() {
  55. return this._definitionChanged;
  56. }
  57. },
  58. /**
  59. * Gets or sets the Image, URL, or Canvas {@link Property} specifying the material's texture.
  60. * @memberof ImageMaterialProperty.prototype
  61. * @type {Property}
  62. */
  63. image : createPropertyDescriptor('image'),
  64. /**
  65. * Gets or sets the {@link Cartesian2} property which determines the number of times the image repeats in each direction.
  66. * @memberof ImageMaterialProperty.prototype
  67. * @type {Property}
  68. * @default new ConstantProperty(new Cartesian2(1, 1))
  69. */
  70. repeat : createPropertyDescriptor('repeat')
  71. });
  72. /**
  73. * Gets the {@link Material} type at the provided time.
  74. *
  75. * @param {JulianDate} time The time for which to retrieve the type.
  76. * @returns {String} The type of material.
  77. */
  78. ImageMaterialProperty.prototype.getType = function(time) {
  79. return 'Image';
  80. };
  81. /**
  82. * Gets the value of the property at the provided time.
  83. *
  84. * @param {JulianDate} time The time for which to retrieve the value.
  85. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  86. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  87. */
  88. ImageMaterialProperty.prototype.getValue = function(time, result) {
  89. if (!defined(result)) {
  90. result = {};
  91. }
  92. result.image = Property.getValueOrUndefined(this._image, time);
  93. result.repeat = Property.getValueOrClonedDefault(this._repeat, time, defaultRepeat, result.repeat);
  94. return result;
  95. };
  96. /**
  97. * Compares this property to the provided property and returns
  98. * <code>true</code> if they are equal, <code>false</code> otherwise.
  99. *
  100. * @param {Property} [other] The other property.
  101. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  102. */
  103. ImageMaterialProperty.prototype.equals = function(other) {
  104. return this === other || //
  105. (other instanceof ImageMaterialProperty && //
  106. Property.equals(this._image, other._image) && //
  107. Property.equals(this._repeat, other._repeat));
  108. };
  109. return ImageMaterialProperty;
  110. });