智慧水务管理系统 - 精河县供水工程综合管理平台

MaterialProperty.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import Color from "../Core/Color.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import JulianDate from "../Core/JulianDate.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. Object.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=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  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. const timeScratch = new JulianDate();
  77. /**
  78. * @private
  79. */
  80. MaterialProperty.getValue = function (time, materialProperty, material) {
  81. let type;
  82. if (!defined(time)) {
  83. time = JulianDate.now(timeScratch);
  84. }
  85. if (defined(materialProperty)) {
  86. type = materialProperty.getType(time);
  87. if (defined(type)) {
  88. if (!defined(material) || material.type !== type) {
  89. material = Material.fromType(type);
  90. }
  91. materialProperty.getValue(time, material.uniforms);
  92. return material;
  93. }
  94. }
  95. if (!defined(material) || material.type !== Material.ColorType) {
  96. material = Material.fromType(Material.ColorType);
  97. }
  98. Color.clone(Color.WHITE, material.uniforms.color);
  99. return material;
  100. };
  101. export default MaterialProperty;