dynamicWallMaterialProperty.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @description:动态立体墙材质
  3. * @date: 2022-02-11
  4. */
  5. //动态墙材质
  6. function DynamicWallMaterialProperty(options) {
  7. // 默认参数设置
  8. this._definitionChanged = new Cesium.Event();
  9. this._color = undefined;
  10. this._colorSubscription = undefined;
  11. this.color = options.color;
  12. this.duration = options.duration;
  13. this.trailImage = options.trailImage;
  14. this._time = (new Date()).getTime();
  15. }
  16. Object.defineProperties(DynamicWallMaterialProperty.prototype, {
  17. isConstant: {
  18. get: function() {
  19. return false;
  20. }
  21. },
  22. definitionChanged: {
  23. get: function() {
  24. return this._definitionChanged;
  25. }
  26. },
  27. color: Cesium.createPropertyDescriptor('color')
  28. });
  29. DynamicWallMaterialProperty.prototype.getType = function(time) {
  30. return 'DynamicWall';
  31. };
  32. DynamicWallMaterialProperty.prototype.getValue = function(time, result) {
  33. if (!Cesium.defined(result)) {
  34. result = {};
  35. }
  36. result.color = Cesium.Property.getValueOrClonedDefault(this._color, time, Cesium.Color.WHITE, result.color);
  37. if (this.trailImage) {
  38. result.image = this.trailImage;
  39. } else {
  40. result.image = Cesium.Material.DynamicWallImage
  41. }
  42. if (this.duration) {
  43. result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration;
  44. }
  45. viewer.scene.requestRender();
  46. return result;
  47. };
  48. DynamicWallMaterialProperty.prototype.equals = function(other) {
  49. return this === other ||
  50. (other instanceof DynamicWallMaterialProperty &&
  51. Cesium.Property.equals(this._color, other._color))
  52. };
  53. Cesium.DynamicWallMaterialProperty = DynamicWallMaterialProperty;
  54. Cesium.Material.DynamicWallType = 'DynamicWall';
  55. // Cesium.Material.DynamicWallImage = "../images/overview/colors.png";
  56. Cesium.Material.DynamicWallImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAAgCAYAAABkS8DlAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAADSSURBVHja7NYxEoUgDEDBYM39z2qHtZViwMFxt1FJnF/98ZXWWkRE7LWWOOt5Lsm9q/vsbu9Zdtazs/J19O5bs1XPZrwze/6V31zxbOZs1n905Wt2p3f25GzE7ohv6q3nLQCA3xEAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAEAAAAACAAAQAACAAAAABAAAIAAAAAEAAAgAAEAAAAACAAAQAACAAAAA8g4AAAD//wMA4WEFTJOT5UIAAAAASUVORK5CYII=";
  57. Cesium.Material.DynamicWallSource = "czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  58. {\n\
  59. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  60. vec2 st = materialInput.st;\n\
  61. vec4 colorImage = texture2D(image, vec2(fract(st.t - time), st.t));\n\
  62. vec4 fragColor;\n\
  63. fragColor.rgb = color.rgb / 1.0;\n\
  64. fragColor = czm_gammaCorrect(fragColor);\n\
  65. material.alpha = colorImage.a * color.a;\n\
  66. material.diffuse = color.rgb;\n\
  67. material.emission = fragColor.rgb;\n\
  68. return material;\n\
  69. }";
  70. Cesium.Material._materialCache.addMaterial(Cesium.Material.DynamicWallType, {
  71. fabric: {
  72. type: Cesium.Material.DynamicWallType,
  73. uniforms: {
  74. color: new Cesium.Color(1.0, 1.0, 1.0, 1),
  75. image: Cesium.Material.DynamicWallImage,
  76. time: 0
  77. },
  78. source: Cesium.Material.DynamicWallSource
  79. },
  80. translucent: function(material) {
  81. return true;
  82. }
  83. });