MaterialProperty.js 3.2 KB

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