init
This commit is contained in:
123
src/Obj/Materail/LineTextureMaterialProperty.js
Normal file
123
src/Obj/Materail/LineTextureMaterialProperty.js
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* @Description: 流动线
|
||||
*/
|
||||
function LineTexture() {
|
||||
class LineTextureMaterialProperty {
|
||||
constructor(options) {
|
||||
this._definitionChanged = new Cesium.Event();
|
||||
this._image = undefined;
|
||||
this._color = undefined;
|
||||
this._speed = undefined;
|
||||
this._repeat = undefined;
|
||||
this.image = options.image || "";
|
||||
this.color = new Cesium.Color.fromCssColorString(options.color || "rgba(255,255,255,1)");
|
||||
this.speed = options.speed != undefined ? options.speed : 1.0;
|
||||
this.repeat = options.repeat || new Cesium.Cartesian2(1.0, 1.0);
|
||||
}
|
||||
|
||||
get isConstant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
get definitionChanged() {
|
||||
return this._definitionChanged;
|
||||
}
|
||||
|
||||
getType(time) {
|
||||
return Cesium.Material.LineTextureMaterialType;
|
||||
}
|
||||
|
||||
getValue(time, result) {
|
||||
if (!Cesium.defined(result)) {
|
||||
result = {};
|
||||
}
|
||||
result.image = Cesium.Property.getValueOrDefault(
|
||||
this._image,
|
||||
time,
|
||||
"",
|
||||
result.image
|
||||
);
|
||||
result.color = Cesium.Property.getValueOrDefault(
|
||||
this._color,
|
||||
time,
|
||||
Cesium.Color.RED,
|
||||
result.color
|
||||
);
|
||||
result.speed = Cesium.Property.getValueOrDefault(
|
||||
this._speed,
|
||||
time,
|
||||
1.0,
|
||||
result.speed
|
||||
);
|
||||
result.repeat = Cesium.Property.getValueOrDefault(
|
||||
this._repeat,
|
||||
time,
|
||||
new Cesium.Cartesian2(1.0, 1.0),
|
||||
result.repeat
|
||||
);
|
||||
result.frameNumber = Cesium.getTimestamp();
|
||||
return result;
|
||||
}
|
||||
|
||||
equals(other) {
|
||||
return (
|
||||
this === other ||
|
||||
(other instanceof LineTextureMaterialProperty &&
|
||||
Cesium.Property.equals(this._image, other._image) &&
|
||||
Cesium.Property.equals(this._color, other._color) &&
|
||||
Cesium.Property.equals(this._imageW, other._imageW) &&
|
||||
Cesium.Property.equals(this._speed, other._speed))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperties(LineTextureMaterialProperty.prototype, {
|
||||
image: Cesium.createPropertyDescriptor("image"),
|
||||
color: Cesium.createPropertyDescriptor("color"),
|
||||
speed: Cesium.createPropertyDescriptor("speed"),
|
||||
repeat: Cesium.createPropertyDescriptor("repeat"),
|
||||
});
|
||||
|
||||
Cesium.LineTextureMaterialProperty = LineTextureMaterialProperty;
|
||||
Cesium.Material.LineTextureMaterialProperty = "LineTextureMaterialProperty";
|
||||
Cesium.Material.LineTextureMaterialType = "LineTextureMaterialType";
|
||||
Cesium.Material.LineTextureMaterialSource = `
|
||||
uniform vec4 color;
|
||||
uniform sampler2D image;
|
||||
uniform float speed;
|
||||
// uniform float repeat;
|
||||
czm_material czm_getMaterial(czm_materialInput materialInput)
|
||||
{
|
||||
czm_material material = czm_getDefaultMaterial(materialInput);
|
||||
vec2 st = materialInput.st;
|
||||
st.s *= repeat.x; // 关键:通过repeat控制纹理密度
|
||||
// vec4 colorImage = texture2D(image, vec2(fract(st.s + speed*czm_frameNumber* 0.01), st.t));
|
||||
vec4 colorImage = speed==0.0?texture2D(image, vec2(fract(st.s), st.t)):texture2D(image, vec2(fract(st.s + frameNumber / 1000.0 / speed * repeat.x / repeat.y ), st.t));
|
||||
material.alpha = colorImage.a * color.a;
|
||||
material.diffuse = color.rgb;
|
||||
return material;
|
||||
}
|
||||
`;
|
||||
Cesium.Material._materialCache.addMaterial(
|
||||
Cesium.Material.LineTextureMaterialType,
|
||||
{
|
||||
fabric: {
|
||||
type: Cesium.Material.LineTextureMaterialType,
|
||||
uniforms: {
|
||||
color: new Cesium.Color(1.0, 1.0, 1.0, 1.0),
|
||||
image: '',
|
||||
repeat: new Cesium.Cartesian2(1.0, 1.0),
|
||||
speed: 1.0,
|
||||
frameNumber: Cesium.getTimestamp(),
|
||||
uTime: 1
|
||||
},
|
||||
source: Cesium.Material.LineTextureMaterialSource,
|
||||
},
|
||||
translucent: function (material) {
|
||||
return true;
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export { LineTexture }
|
||||
Reference in New Issue
Block a user