WallDiffuseMaterialProperty.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * @Description: 动态扩散墙的墙体效果(参考开源代码)(不同高度透明度不同)
  3. * @Version: 1.0
  4. * @Author: Julian
  5. * @Date: 2022-03-07 19:50:46
  6. * @LastEditors: Julian
  7. * @LastEditTime: 2022-03-08 13:34:04
  8. */
  9. class WallDiffuseMaterialProperty {
  10. constructor(options) {
  11. this._definitionChanged = new Cesium.Event();
  12. this._color = undefined;
  13. this.color = options.color;
  14. };
  15. get isConstant() {
  16. return false;
  17. }
  18. get definitionChanged() {
  19. return this._definitionChanged;
  20. }
  21. getType(time) {
  22. return Cesium.Material.WallDiffuseMaterialType;
  23. }
  24. getValue(time, result) {
  25. if (!Cesium.defined(result)) {
  26. result = {};
  27. }
  28. result.color = Cesium.Property.getValueOrDefault(this._color, time, Cesium.Color.RED, result.color);
  29. return result
  30. }
  31. equals(other) {
  32. return (this === other ||
  33. (other instanceof WallDiffuseMaterialProperty &&
  34. Cesium.Property.equals(this._color, other._color))
  35. )
  36. }
  37. }
  38. Object.defineProperties(WallDiffuseMaterialProperty.prototype, {
  39. color: Cesium.createPropertyDescriptor('color'),
  40. })
  41. Cesium.WallDiffuseMaterialProperty = WallDiffuseMaterialProperty;
  42. Cesium.Material.WallDiffuseMaterialProperty = 'WallDiffuseMaterialProperty';
  43. Cesium.Material.WallDiffuseMaterialType = 'WallDiffuseMaterialType';
  44. Cesium.Material.WallDiffuseMaterialSource =
  45. `
  46. uniform vec4 color;
  47. czm_material czm_getMaterial(czm_materialInput materialInput){
  48. czm_material material = czm_getDefaultMaterial(materialInput);
  49. vec2 st = materialInput.st;
  50. material.diffuse = color.rgb * 2.0;
  51. material.alpha = color.a * (1.0 - fract(st.t)) * 0.8;
  52. return material;
  53. }
  54. `
  55. Cesium.Material._materialCache.addMaterial(Cesium.Material.WallDiffuseMaterialType, {
  56. fabric: {
  57. type: Cesium.Material.WallDiffuseMaterialType,
  58. uniforms: {
  59. color: new Cesium.Color(1.0, 0.0, 0.0, 1.0),
  60. },
  61. source: Cesium.Material.WallDiffuseMaterialSource
  62. },
  63. translucent: function(material) {
  64. return true;
  65. }
  66. })
  67. export default WallDiffuseMaterialProperty;