cesium.color
时间: 2023-11-21 07:53:15 浏览: 254
Cesium.Color是Cesium中用于表示颜色的类。它提供了多种设置颜色的方法,包括使用英文单词、rgba值、CSS色值、32位GRBA值以及随机颜色等。除此之外,Cesium.Color还有很多静态属性,可以直接通过类进行使用,例如Cesium.Color.RED表示红色,Cesium.Color.GRAY表示灰色等。Cesium.Color可以用于设置Cesium中的各种图形、材质、标签等的颜色。
相关问题
分析下面代码的作用:/* * @Description: 飞线效果(参考开源代码) * @Version: 1.0 * @Author: Julian * @Date: 2022-03-05 16:13:21 * @LastEditors: Julian * @LastEditTime: 2022-03-05 17:39:38 */ class LineFlowMaterialProperty { constructor(options) { this._definitionChanged = new Cesium.Event(); this._color = undefined; this._speed = undefined; this._percent = undefined; this._gradient = undefined; this.color = options.color; this.speed = options.speed; this.percent = options.percent; this.gradient = options.gradient; }; get isConstant() { return false; } get definitionChanged() { return this._definitionChanged; } getType(time) { return Cesium.Material.LineFlowMaterialType; } getValue(time, result) { if (!Cesium.defined(result)) { result = {}; } result.color = Cesium.Property.getValueOrDefault(this._color, time, Cesium.Color.RED, result.color); result.speed = Cesium.Property.getValueOrDefault(this._speed, time, 5.0, result.speed); result.percent = Cesium.Property.getValueOrDefault(this._percent, time, 0.1, result.percent); result.gradient = Cesium.Property.getValueOrDefault(this._gradient, time, 0.01, result.gradient); return result } equals(other) { return (this === other || (other instanceof LineFlowMaterialProperty && Cesium.Property.equals(this._color, other._color) && Cesium.Property.equals(this._speed, other._speed) && Cesium.Property.equals(this._percent, other._percent) && Cesium.Property.equals(this._gradient, other._gradient)) ) } } Object.defineProperties(LineFlowMaterialProperty.prototype, { color: Cesium.createPropertyDescriptor('color'), speed: Cesium.createPropertyDescriptor('speed'), percent: Cesium.createPropertyDescriptor('percent'), gradient: Cesium.createPropertyDescriptor('gradient'), }) Cesium.LineFlowMaterialProperty = LineFlowMaterialProperty; Cesium.Material.LineFlowMaterialProperty = 'LineFlowMaterialProperty'; Cesium.Material.LineFlowMaterialType = 'LineFlowMaterialType'; Cesium.Material.LineFlowMaterialSource = ` uniform vec4 color; uniform float speed; uniform float percent; uniform float gradient; czm_material czm_getMaterial(czm_materialInput materialInput){ czm_material material = czm_getDefaultMaterial(materialInput); vec2 st = materialInput.st; float t =fract(czm_frameNumber * speed / 1000.0); t *= (1.0 + percent); float alpha = smoothstep(t- percent, t, st.s) * step(-t, -st.s); alpha += gradient; material.diffuse = color.rgb; material.alpha = alpha; return material; } ` Cesium.Material._materialCache.addMaterial(Cesium.Material.LineFlowMaterialType, { fabric: { type: Cesium.Material.LineFlowMaterialType, uniforms: { color: new Cesium.Color(1.0, 0.0, 0.0, 1.0), speed: 10.0, percent: 0.1, gradient: 0.01 }, source: Cesium.Material.LineFlowMaterialSource }, translucent: function(material) { return true; } })
这段代码定义了一个名为LineFlowMaterialProperty的类,它包含了构造函数和一些成员函数。构造函数中传入一个options对象,包含color、speed、percent、gradient四个属性,这些属性被赋值给类的对应成员变量。成员函数中,getisConstant()返回false,getdefinitionChanged()返回一个Event对象,getType()返回LineFlowMaterialType枚举值,getValue()根据传入的时间参数返回一个对象,包含color、speed、percent、gradient四个属性。equals()函数用于判断两个LineFlowMaterialProperty对象是否相等。该类可能用于实现飞线效果。
/** * 流动纹理线 * @param {*} color 颜色 * @param {*} duration duration 持续时间 毫秒 */ function EllipsoidFadeMaterialProperty(color: string, duration: number) { this._definitionChanged = new Cesium.Event(); this._color = undefined; this._colorSubscription = undefined; this.color = color; this.duration = duration; this._time = new Date().getTime(); } Object.defineProperties(EllipsoidFadeMaterialProperty.prototype, { isConstant: { get: function () { return false; } }, definitionChanged: { get: function () { return this._definitionChanged; } }, color: Cesium.createPropertyDescriptor('color') }); EllipsoidFadeMaterialProperty.prototype.getType = function (time: number) { return 'EllipsoidFade'; }; EllipsoidFadeMaterialProperty.prototype.getValue = function ( time: number, result: any ) { if (!Cesium.defined(result)) { result = {}; } result.color = Cesium.Property.getValueOrClonedDefault( this._color, time, Cesium.Color.WHITE, result.color ); result.time = ((new Date().getTime() - this._time) % this.duration) / this.duration; return result; }; interface Other_tmp { _color: any; } EllipsoidFadeMaterialProperty.prototype.equals = function (other: Other_tmp) { const reData = this === other || (other instanceof EllipsoidFadeMaterialProperty && Cesium.Property.equals(this._color, other._color)); return reData; }; Cesium.EllipsoidFadeMaterialProperty = EllipsoidFadeMaterialProperty;
这是一段 TypeScript 代码,它定义了一个名为 EllipsoidFadeMaterialProperty 的类。这个类代表了一个流动纹理线的材质属性,它包含了颜色和持续时间两个属性。这个类实现了 Cesium 的 MaterialProperty 接口,其中包含了 getType 和 getValue 方法,用于获取材质类型和材质属性值。另外,这个类还实现了 equals 方法,用于判断两个 EllipsoidFadeMaterialProperty 实例是否相等。
阅读全文