MaterialProperty.js 3.7 KB

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