MaterialProperty.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*global define*/
  2. define([
  3. '../Core/Color',
  4. '../Core/defined',
  5. '../Core/defineProperties',
  6. '../Core/DeveloperError',
  7. '../Scene/Material'
  8. ], function(
  9. Color,
  10. defined,
  11. defineProperties,
  12. DeveloperError,
  13. Material) {
  14. "use strict";
  15. /**
  16. * The interface for all {@link Property} objects that represent {@link Material} uniforms.
  17. * This type defines an interface and cannot be instantiated directly.
  18. *
  19. * @alias MaterialProperty
  20. * @constructor
  21. *
  22. * @see ColorMaterialProperty
  23. * @see CompositeMaterialProperty
  24. * @see GridMaterialProperty
  25. * @see ImageMaterialProperty
  26. * @see PolylineGlowMaterialProperty
  27. * @see PolylineOutlineMaterialProperty
  28. * @see StripeMaterialProperty
  29. */
  30. var MaterialProperty = function() {
  31. DeveloperError.throwInstantiationError();
  32. };
  33. defineProperties(MaterialProperty.prototype, {
  34. /**
  35. * Gets a value indicating if this property is constant. A property is considered
  36. * constant if getValue always returns the same result for the current definition.
  37. * @memberof MaterialProperty.prototype
  38. *
  39. * @type {Boolean}
  40. * @readonly
  41. */
  42. isConstant : {
  43. get : DeveloperError.throwInstantiationError
  44. },
  45. /**
  46. * Gets the event that is raised whenever the definition of this property changes.
  47. * The definition is considered to have changed if a call to getValue would return
  48. * a different result for the same time.
  49. * @memberof MaterialProperty.prototype
  50. *
  51. * @type {Event}
  52. * @readonly
  53. */
  54. definitionChanged : {
  55. get : DeveloperError.throwInstantiationError
  56. }
  57. });
  58. /**
  59. * Gets the {@link Material} type at the provided time.
  60. * @function
  61. *
  62. * @param {JulianDate} time The time for which to retrieve the type.
  63. * @returns {String} The type of material.
  64. */
  65. MaterialProperty.prototype.getType = DeveloperError.throwInstantiationError;
  66. /**
  67. * Gets the value of the property at the provided time.
  68. * @function
  69. *
  70. * @param {JulianDate} time The time for which to retrieve the value.
  71. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  72. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  73. */
  74. MaterialProperty.prototype.getValue = DeveloperError.throwInstantiationError;
  75. /**
  76. * Compares this property to the provided property and returns
  77. * <code>true</code> if they are equal, <code>false</code> otherwise.
  78. *
  79. * @param {Property} [other] The other property.
  80. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  81. */
  82. MaterialProperty.prototype.equals = DeveloperError.throwInstantiationError;
  83. /**
  84. * @private
  85. */
  86. MaterialProperty.getValue = function(time, materialProperty, material) {
  87. var type;
  88. if (defined(materialProperty)) {
  89. type = materialProperty.getType(time);
  90. if (defined(type)) {
  91. if (!defined(material) || (material.type !== type)) {
  92. material = Material.fromType(type);
  93. }
  94. materialProperty.getValue(time, material.uniforms);
  95. return material;
  96. }
  97. }
  98. if (!defined(material) || (material.type !== Material.ColorType)) {
  99. material = Material.fromType(Material.ColorType);
  100. }
  101. Color.clone(Color.WHITE, material.uniforms.color);
  102. return material;
  103. };
  104. return MaterialProperty;
  105. });