class Circle {
constructor(options) {
this._definitionChanged = new Cesium.Event();
this._speed = undefined;
this._color = undefined;
this._bgcolor = undefined;
this._offset = undefined;
this._repeat = undefined;
this._thickness = undefined;
this.speed = options.speed;
this.color = options.color;
this.bgcolor = options.bgcolor;
this.offset = options.offset;
this.repeat = options.repeat;
this.thickness = options.thickness;
}
get isConstant() {
//必备模板
return false;
}
get definitionChanged() {
//必备模板
return this._definitionChanged;
}
getType() {
//负责类型必备的给着色器
return Cesium.Material.CircleType;
}
//entity用getvalue
//privat不用getvalue
getValue(time, result) {
//负责取值给着色器
if (!Cesium.defined(result)) {
result = {};
}
result.color = Cesium.Property.getValueOrDefault(
this._color,
time,
Cesium.Color.RED,
result.color
);
result.bgcolor = Cesium.Property.getValueOrDefault(
this._bgcolor,
time,
Cesium.Color.RED,
result.bgcolor
);
result.offset = Cesium.Property.getValueOrDefault(
this._offset,
time,
0.0,
result.offset
);
result.repeat = Cesium.Property.getValueOrDefault(
this._repeat,
time,
30.0,
result.repeat
);
result.speed = Cesium.Property.getValueOrDefault(
this._speed,
time,
10.0,
result.speed
);
result.thickness = Cesium.Property.getValueOrDefault(
this._thickness,
time,
0.3,
result.thickness
);
return result;
}
equals(other) {
return (
this === other ||
(other instanceof Circle &&
Cesium.Property.equals(this._color, other._color) &&
Cesium.Property.equals(this._speed, other._speed) &&
Cesium.Property.equals(this._bgcolor, other._bgcolor) &&
Cesium.Property.equals(this._thickness, other._thickness) &&
Cesium.Property.equals(this._repeat, other._repeat) &&
Cesium.Property.equals(this._offset, other._offset))
);
}
}
Object.defineProperties(Circle.prototype, {
//添加属性或修改cirtcle对象的color和speed 参数
color: Cesium.createPropertyDescriptor("color"),
//一直监视color函数发生变化
speed: Cesium.createPropertyDescriptor("speed"),
bgcolor: Cesium.createPropertyDescriptor("bgcolor"),
offset: Cesium.createPropertyDescriptor("offset"),
thickness: Cesium.createPropertyDescriptor("thickness"),
repeat: Cesium.createPropertyDescriptor("repeat")
});
Cesium.Circle = Circle; //entity 引入方式
Cesium.Material.Circle = "Circle";
Cesium.Material.CircleType = "CircleType"; //图元引入方式
Cesium.Material.Source = `
uniform vec4 color;
uniform vec4 bgColor;
uniform float repeat;
uniform float offset;
uniform float speed;
uniform float thickness;
czm_material czm_getMaterial(czm_materialInput materialInput)
{
czm_material material = czm_getDefaultMaterial(materialInput);
float sp = 1.0/repeat;
vec2 st = materialInput.st;
float dis = distance(st, vec2(0.5));
float m = mod(dis + offset, sp);
float a = step(sp*(1.0-thickness), m);
float time = czm_frameNumber * speed / 1000.0;
vec2 scrPt = st * 2.0 -1.0;
vec3 col = vec3(0.0);
mat2 rot;
float theta = -time * 1.0 * 3.14 -2.2;
float cosTheta = cos(theta);
float sinTheta = sin(theta);
rot[0][0] = cosTheta;
rot[0][1] = -sinTheta;
rot[1][0] = sinTheta;
rot[1][1] = cosTheta;
vec2 scrPtRot = rot * scrPt;
float angle = 1.0 - (atan(scrPtRot.y,scrPtRot.x)/6.2831 + 0.5);
float falloff = length(scrPtRot);
material.alpha = pow(length(col + vec3(0.5)),0.25) ;
material.diffuse = (0.5+pow(angle,2.0)*falloff) * color.rgb;
return material;
}
`;
Cesium.Material._materialCache.addMaterial(Cesium.Material.CircleType, {
fabric: {
type: Cesium.Material.CircleType,
uniforms: {
color: new Cesium.Color(1.0, 1.0, 0.0, 0.2),
bgColor: new Cesium.Color(1.0, 0.0, 0.0, 0.2),
repeat: 30.0,
offset: 0.0,
thickness: 0.3,
speed: 10.0
},
source: Cesium.Material.Source
},
translucent: function(material) {
return true;
}
});
03-20
5153
03-27
3910
03-14
4837
03-08
4049
03-21
6674
03-06
2449
03-09
4867
03-04
3319
03-28
9760
03-07
2875
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交