@ino-cesium/material 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.MD ADDED
@@ -0,0 +1,3 @@
1
+ # ino-cesium 自定义材质
2
+
3
+ 自定义材质
@@ -0,0 +1,282 @@
1
+ import * as Cesium from 'cesium';
2
+ import { Material } from 'cesium';
3
+ import { BaseMaterialProperty } from '@ino-cesium/common';
4
+
5
+ interface IPolylineTrailMaterialOptions {
6
+ name?: string;
7
+ color?: string;
8
+ speed?: number;
9
+ image: string;
10
+ }
11
+ interface IPolylineFlowMaterialOptions {
12
+ /**
13
+ * 颜色
14
+ */
15
+ color?: string;
16
+ speed?: number;
17
+ image: string;
18
+ repeatCount?: number;
19
+ blendColor?: boolean;
20
+ }
21
+ interface ICircleWaveMaterialOptions {
22
+ name?: string;
23
+ color?: string;
24
+ speed?: number;
25
+ count?: number;
26
+ gradient?: number;
27
+ }
28
+ interface ICircleRaderWaveMaterialOptions {
29
+ name?: string;
30
+ color?: string;
31
+ speed?: number;
32
+ }
33
+ interface ICircleRaderFanMaterialOptions {
34
+ name?: string;
35
+ color?: string;
36
+ speed?: number;
37
+ }
38
+ interface ILightWallMaterialOptions {
39
+ image: string;
40
+ color?: string;
41
+ count?: number;
42
+ /**
43
+ * 时间 单位为秒
44
+ */
45
+ duration?: number;
46
+ /**
47
+ * 0为水平 1为垂直 默认为1
48
+ */
49
+ vertical?: number;
50
+ /**
51
+ * 1由下到上 0由上到下 默认为0
52
+ */
53
+ direction?: number;
54
+ }
55
+ interface ICircleApertureMaterialOptions {
56
+ color?: string;
57
+ /**
58
+ * 速度
59
+ */
60
+ speed?: number;
61
+ }
62
+ /**
63
+ * 电弧球体
64
+ */
65
+ interface IEllipsoidElectricMaterialOptions {
66
+ color?: string;
67
+ /**
68
+ * 速度
69
+ */
70
+ speed?: number;
71
+ }
72
+ /**
73
+ * 雷达扫描材质
74
+ * @param selectColor 选中颜色
75
+ * @param bgColor 背景颜色
76
+ * @param width 宽度
77
+ * @param count 光圈个数
78
+ * @param offset 光晕偏移量
79
+ */
80
+ interface IRadarScanMaterialOptions {
81
+ /**
82
+ * 扇区颜色
83
+ */
84
+ sectorColor?: string;
85
+ /**
86
+ * 扇区宽度
87
+ */
88
+ width?: number;
89
+ /**
90
+ * 背景颜色
91
+ */
92
+ bgColor?: string;
93
+ /**
94
+ * 光圈个数
95
+ */
96
+ count?: number;
97
+ /**
98
+ * 光晕偏移量
99
+ */
100
+ offset?: number;
101
+ }
102
+ interface ICorridorMaterialOptions {
103
+ }
104
+
105
+ type types_ICircleApertureMaterialOptions = ICircleApertureMaterialOptions;
106
+ type types_ICircleRaderFanMaterialOptions = ICircleRaderFanMaterialOptions;
107
+ type types_ICircleRaderWaveMaterialOptions = ICircleRaderWaveMaterialOptions;
108
+ type types_ICircleWaveMaterialOptions = ICircleWaveMaterialOptions;
109
+ type types_ICorridorMaterialOptions = ICorridorMaterialOptions;
110
+ type types_IEllipsoidElectricMaterialOptions = IEllipsoidElectricMaterialOptions;
111
+ type types_ILightWallMaterialOptions = ILightWallMaterialOptions;
112
+ type types_IPolylineFlowMaterialOptions = IPolylineFlowMaterialOptions;
113
+ type types_IPolylineTrailMaterialOptions = IPolylineTrailMaterialOptions;
114
+ type types_IRadarScanMaterialOptions = IRadarScanMaterialOptions;
115
+ declare namespace types {
116
+ export type { types_ICircleApertureMaterialOptions as ICircleApertureMaterialOptions, types_ICircleRaderFanMaterialOptions as ICircleRaderFanMaterialOptions, types_ICircleRaderWaveMaterialOptions as ICircleRaderWaveMaterialOptions, types_ICircleWaveMaterialOptions as ICircleWaveMaterialOptions, types_ICorridorMaterialOptions as ICorridorMaterialOptions, types_IEllipsoidElectricMaterialOptions as IEllipsoidElectricMaterialOptions, types_ILightWallMaterialOptions as ILightWallMaterialOptions, types_IPolylineFlowMaterialOptions as IPolylineFlowMaterialOptions, types_IPolylineTrailMaterialOptions as IPolylineTrailMaterialOptions, types_IRadarScanMaterialOptions as IRadarScanMaterialOptions };
117
+ }
118
+
119
+ /**
120
+ * 尾迹线材质类
121
+ */
122
+ declare class PolylineTrailMaterialProperty extends BaseMaterialProperty {
123
+ private speed;
124
+ private color;
125
+ private name;
126
+ private image;
127
+ constructor(options: IPolylineTrailMaterialOptions);
128
+ get isConstant(): boolean;
129
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
130
+ getType(): string;
131
+ getValue(time: Cesium.JulianDate, result: any): any;
132
+ equals(other: PolylineTrailMaterialProperty): any;
133
+ init(): void;
134
+ createPropertyDescriptors(): void;
135
+ }
136
+ declare const createTrailMaterial: (options: IPolylineTrailMaterialOptions) => Cesium.Material;
137
+
138
+ /**
139
+ * 线流动材质
140
+ * @classdesc 线流动材质
141
+ * @param {IPolylineFlowMaterialOptions} options - 线流动材质参数
142
+ */
143
+ declare class PolylineFlowMaterialProperty extends BaseMaterialProperty {
144
+ private repeatCount;
145
+ private image;
146
+ private speed;
147
+ private color;
148
+ private blend;
149
+ private name;
150
+ constructor(options: IPolylineFlowMaterialOptions);
151
+ get isConstant(): boolean;
152
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
153
+ getType(): string;
154
+ getValue(time: Cesium.JulianDate, result: any): any;
155
+ equals(other: PolylineFlowMaterialProperty): boolean;
156
+ init(): void;
157
+ createPropertyDescriptors(): void;
158
+ }
159
+ declare const createPoylineFlowMaterial: (options: IPolylineFlowMaterialOptions) => Cesium.Material;
160
+
161
+ /**
162
+ * 波浪圆
163
+ */
164
+ declare class CircleWaveMaterialProperty extends BaseMaterialProperty {
165
+ private count;
166
+ private speed;
167
+ private gradient;
168
+ private color;
169
+ private name;
170
+ constructor(options?: ICircleWaveMaterialOptions);
171
+ get isConstant(): boolean;
172
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
173
+ getType(): string;
174
+ getValue(time: Cesium.JulianDate, result: any): any;
175
+ equals(other: CircleWaveMaterialProperty): any;
176
+ init(): void;
177
+ }
178
+ declare const createCircleWaveMaterial: (options?: ICircleWaveMaterialOptions) => {
179
+ material: Cesium.Material;
180
+ };
181
+
182
+ /**
183
+ *雷达波纹圆
184
+ */
185
+ declare class CircleRaderWaveMaterialProperty extends BaseMaterialProperty {
186
+ private speed;
187
+ private color;
188
+ private name;
189
+ constructor(options: ICircleRaderWaveMaterialOptions);
190
+ get isConstant(): boolean;
191
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
192
+ getType(): string;
193
+ getValue(time: Cesium.JulianDate, result: any): any;
194
+ equals(other: CircleRaderWaveMaterialProperty): boolean;
195
+ init(): void;
196
+ }
197
+ declare const createRaderWaveMaterial: (options: ICircleRaderWaveMaterialOptions) => {
198
+ material: Cesium.Material;
199
+ };
200
+
201
+ /**
202
+ * 雷达扇形扫描
203
+ */
204
+ declare class CircleRaderFanMaterialProperty extends BaseMaterialProperty {
205
+ private speed;
206
+ private color;
207
+ private name;
208
+ constructor(options: ICircleRaderFanMaterialOptions);
209
+ get isConstant(): boolean;
210
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
211
+ getType(): string;
212
+ getValue(time: Cesium.JulianDate, result: any): any;
213
+ equals(other: CircleRaderFanMaterialProperty): boolean;
214
+ init(): void;
215
+ }
216
+ declare const createCircleRaderFanMaterial: (options: ICircleRaderFanMaterialOptions) => {
217
+ material: Cesium.Material;
218
+ };
219
+
220
+ /**
221
+ * 波浪圆
222
+ */
223
+ declare class CircleApertureMaterialProperty extends BaseMaterialProperty {
224
+ private speed;
225
+ private color;
226
+ private name;
227
+ constructor(options?: ICircleApertureMaterialOptions);
228
+ get isConstant(): boolean;
229
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
230
+ getType(): string;
231
+ getValue(time: Cesium.JulianDate, result: any): any;
232
+ equals(other: CircleApertureMaterialProperty): any;
233
+ init(): void;
234
+ }
235
+ declare const createCircleApertureMaterial: (options?: ICircleApertureMaterialOptions) => Cesium.Material;
236
+
237
+ declare const createScanRadarMaterial: (options?: IRadarScanMaterialOptions) => Material;
238
+
239
+ /**
240
+ * 光墙材质
241
+ */
242
+ declare class LightWallMaterialProperty extends BaseMaterialProperty {
243
+ private duration;
244
+ private count;
245
+ private vertical;
246
+ private direction;
247
+ private color;
248
+ private _time;
249
+ private image;
250
+ private name;
251
+ constructor(options: ILightWallMaterialOptions);
252
+ get isConstant(): boolean;
253
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
254
+ getType(): string;
255
+ getValue(time: Cesium.JulianDate, result: any): any;
256
+ equals(other: LightWallMaterialProperty): any;
257
+ init(): void;
258
+ }
259
+ declare const createLightWallMaterial: (options: ILightWallMaterialOptions) => {
260
+ material: Cesium.Material;
261
+ };
262
+
263
+ /**
264
+ * 雷达扇形扫描
265
+ */
266
+ declare class EllipsoidElectricMaterialProperty extends BaseMaterialProperty {
267
+ private speed;
268
+ private color;
269
+ private name;
270
+ constructor(options: IEllipsoidElectricMaterialOptions);
271
+ get isConstant(): boolean;
272
+ get definitionChanged(): Cesium.Event<(...args: any[]) => void>;
273
+ getType(): string;
274
+ getValue(time: Cesium.JulianDate, result: any): any;
275
+ equals(other: EllipsoidElectricMaterialProperty): boolean;
276
+ init(): void;
277
+ }
278
+ declare const createEllipsoidElectricMaterial: (options: IEllipsoidElectricMaterialOptions) => {
279
+ material: Cesium.Material;
280
+ };
281
+
282
+ export { CircleApertureMaterialProperty, CircleRaderFanMaterialProperty, CircleRaderWaveMaterialProperty, CircleWaveMaterialProperty, EllipsoidElectricMaterialProperty, LightWallMaterialProperty, types as Material, PolylineFlowMaterialProperty, PolylineTrailMaterialProperty, createCircleApertureMaterial, createCircleRaderFanMaterial, createCircleWaveMaterial, createEllipsoidElectricMaterial, createLightWallMaterial, createPoylineFlowMaterial, createRaderWaveMaterial, createScanRadarMaterial, createTrailMaterial };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import*as e from"cesium";import{Material as t,Color as r}from"cesium";import{BaseMaterialProperty as a,numberId as n}from"@ino-cesium/common";var i=Object.freeze({__proto__:null});const o={PolylineFlow:"PolylineFlow",PolylineTrail:"PolylineTrail",CircleWave:"CircleWave",CircleRaderWave:"CircleRaderWave",CircleRaderFan:"CircleRaderFan",LightWall:"LightWallMater",CircleAperture:"CircleAperture",RadarScanCircle:"RadarScanCircle",EllipsoidElectric:"EllipsoidElectric",Corridor:"Corridor"};(()=>{for(const t in o)e.Material[t]=o[t]})();const s={color:"rgba(255,255,255,1)",speed:6*Math.random()};class l extends a{speed;color;name="";image="";constructor(t){super(),this.createPropertyDescriptors();const r={...s,...t};this.image=r.image,this.name=`${o.PolylineTrail}-${n()}`,this.color=e.Color.fromCssColorString(r.color),this.speed=r.speed,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return this.name}getValue(t,r){return e.defined(r)||(r={}),r.color=e.Property.getValueOrClonedDefault(this.color,t,e.Color.WHITE,r.color),r.speed=this.speed,r.image=this.image,r}equals(t){return this===t||t instanceof l&&this.speed===t.speed&&e.Property.equals(this.color,t.color)&&this.name===t.name}init(){e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(this.name,{fabric:{type:this.name,uniforms:{image:this.image,color:e.Color.fromCssColorString("#ff0000"),speed:this.speed},source:m},translucent:()=>!0})}createPropertyDescriptors(){Object.defineProperties(this,{color:e.createPropertyDescriptor("color")})}}const c=t=>{const r={...s,...t};return new e.Material({fabric:{type:`${o.PolylineTrail}-${n()}`,uniforms:{color:e.Color.fromCssColorString(r.color),image:r.image,speed:r.speed},source:m},translucent:!0})},m="\n uniform sampler2D image;\n uniform vec4 color;\n uniform float speed;\n czm_material czm_getMaterial(czm_materialInput materialInput){\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n float time = fract(czm_frameNumber * speed / 1000.0);\n vec4 colorImage = texture(image,st);\n vec3 fragColor = color.rgb;\n if(st.t > 0.45 && st.t < 0.55 ) {\n fragColor = vec3(1.0);\n }\n if(color.a == 0.0){\n material.alpha = colorImage.a * 1.5 * fract(st.s - time);\n material.diffuse = colorImage.rgb;\n }else{\n material.alpha = colorImage.a * color.a * 1.5 * smoothstep(.0,1., fract(st.s - time));\n material.diffuse = max(fragColor.rgb * material.alpha , fragColor.rgb);\n }\n return material;\n }\n\n",u={color:"rgba(255,255,255,1)",speed:6,repeatCount:4,blendColor:!0};class d extends a{repeatCount;image;speed;color;blend;name="";constructor(t){super(),this.createPropertyDescriptors();const r={...u,...t};this.name=`${o.PolylineFlow}-${n()}`,this.color=e.Color.fromCssColorString(r.color),this.speed=r.speed,this.image=r.image,this.repeatCount=r.repeatCount,this.blend=r.blendColor?1:0,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return this.name}getValue(t,r){return e.defined(r)||(r={}),r.color=e.Property.getValueOrClonedDefault(this.color,t,e.Color.WHITE,r.color),r.image=this.image,r.blend=this.blend,r.speed=this.speed,r.repeatCount=this.repeatCount,r}equals(e){return this===e||e instanceof d&&this.speed===e.speed&&this.repeatCount===e.repeatCount&&this.name===e.name}init(){e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(this.name,{fabric:{type:this.name,uniforms:{color:e.Color.fromCssColorString("#ffffff"),image:"",speed:this.speed,count:this.repeatCount,blend:this.blend},source:f},translucent:()=>!0})}createPropertyDescriptors(){Object.defineProperties(this,{color:e.createPropertyDescriptor("color")})}}const p=t=>{const r={...u,...t};return new e.Material({fabric:{type:o.PolylineFlow+n(),uniforms:{color:e.Color.fromCssColorString(r.color),image:r.image,speed:r.speed,count:r.repeatCount,blend:r.blendColor?1:0},source:f},translucent:!0})},f="\n uniform vec4 color;\n czm_material czm_getMaterial(czm_materialInput materialInput){\n czm_material material = czm_getDefaultMaterial(materialInput);\n float time = fract(czm_frameNumber * speed / 1000.0);\n vec2 st = materialInput.st;\n vec4 colorImage = texture(image, vec2(fract( count * st.s - time),fract(st.t)));\n material.alpha = colorImage.a * color.a;\n if(blend > 0.5) {\n material.diffuse = (colorImage.rgb + color.rgb) * 2.0;\n } else {\n material.diffuse = color.rgb * 2.0 ;\n }\n return material;\n }\n",h={color:"rgba(255,255,0,0.3)",speed:8,count:5,gradient:.3};class g extends a{count;speed;gradient;color;name="";constructor(t){super(),t||(t={});const r={...h,...t};this.name=`${o.CircleWave}-${n()}`,this.color=e.Color.fromCssColorString(r.color),this.speed=r.speed,this.count=r.count,this.gradient=r.gradient,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return`${this.name}`}getValue(t,r){return e.defined(r)||(r={}),r.color=this.color,r.speed=this.speed,r.repeatCount=this.count||h.count,r}equals(t){return this===t||t instanceof g&&e.Property.equals(this.color,t.color)&&this.speed===t.speed&&this.count===t.count&&this.name===t.name}init(){e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(this.name,{fabric:{type:this.name,uniforms:{color:new e.Color(1,0,0,.5),speed:this.speed,count:this.count,gradient:this.gradient},source:v},translucent:()=>!0})}}const C=t=>{const r={...h,...t};return{material:new e.Material({fabric:{type:`${o.CircleWave}-${n()}`,uniforms:{color:e.Color.fromCssColorString(r.color),speed:r.speed,count:r.count,gradient:r.gradient},source:v},translucent:!0})}},v="\n uniform vec4 color;\n uniform float speed;\n uniform float count;\n uniform float gradient;\n\n czm_material czm_getMaterial(czm_materialInput materialInput)\n {\n czm_material material = czm_getDefaultMaterial(materialInput);\n material.diffuse = 1.5 * color.rgb;\n vec2 st = materialInput.st;\n float dis = distance(st, vec2(0.5, 0.5));\n float per = fract(czm_frameNumber * speed / 1000.0);\n if(count == 1.0){\n if(dis > per * 0.5){\n discard;\n }else {\n material.alpha = color.a * dis / per / 2.0;\n }\n } else {\n vec3 str = materialInput.str;\n if(abs(str.z) > 0.001){\n discard;\n }\n if(dis > 0.5){\n discard;\n } else {\n float perDis = 0.5 / count;\n float disNum;\n float bl = 0.0;\n for(int i = 0; i <= 999; i++){\n if(float(i) <= count){\n disNum = perDis * float(i) - dis + per / count;\n if(disNum > 0.0){\n if(disNum < perDis){\n bl = 1.0 - disNum / perDis;\n }\n else if(disNum - perDis < perDis){\n bl = 1.0 - abs(1.0 - disNum / perDis);\n }\n material.alpha = pow(bl,(1.0 + 10.0 * (1.0 - gradient)));\n }\n }\n }\n }\n }\n return material;\n }\n",b={color:"rgba(255,255,255,1)",speed:8};class y extends a{speed;color;name="";constructor(t){super();const r={...b,...t};this.name=`${o.CircleRaderWave}-${n()}`,this.color=e.Color.fromCssColorString(r.color),this.speed=r.speed,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return`${this.name}`}getValue(t,r){return e.defined(r)||(r={}),r.speed=this.speed,r}equals(e){return this===e||e instanceof y&&this.speed===e.speed&&this.name===e.name}init(){e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(this.name,{fabric:{type:this.name,uniforms:{color:this.color,speed:6},source:x},translucent:()=>!0})}}const _=t=>{const r={...b,...t};return{material:new e.Material({fabric:{type:`${o.CircleRaderWave}-${n()}`,uniforms:{color:e.Color.fromCssColorString(r.color),speed:r.speed},source:x},translucent:!0})}},x="\n uniform vec4 color;\n uniform float speed;\n #define PI 3.14159265359\n float rand(vec2 co){\n return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);\n }\n\n czm_material czm_getMaterial(czm_materialInput materialInput){\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n vec2 pos = st - vec2(0.5);\n float time = czm_frameNumber * speed / 1000.0 ;\n float r = length(pos);\n float t = atan(pos.y, pos.x) - time * 2.5;\n float a = (atan(sin(t), cos(t)) + PI)/(2.0*PI);\n float ta = 0.5;\n float v = smoothstep(ta-0.05,ta+0.05,a) * smoothstep(ta+0.05,ta-0.05,a);\n vec3 flagColor = color.rgb * v;\n float blink = pow(sin(time*1.5)*0.5+0.5, 0.8);\n flagColor = color.rgb * pow(a, 4.0*(.2+blink))*(sin(r*500.0)*.5+.5) ;\n flagColor = flagColor * pow(r, 0.4);\n material.alpha = length(flagColor) * 1.3;\n material.diffuse = flagColor * 3.0;\n return material;\n }\n",z={name:"circle-fan",color:"rgba(255,255,255,1)",speed:8};class I extends a{speed;color;name="";constructor(t){super();const r={...z,...t};this.name=`${o.CircleRaderFan}-${n()}`,this.color=e.Color.fromCssColorString(r.color),this.speed=r.speed,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return`${this.name}`}getValue(t,r){return e.defined(r)||(r={}),r.speed=this.speed,r}equals(e){return this===e||e instanceof I&&this.speed===e.speed&&this.name===e.name}init(){e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(this.name,{fabric:{type:this.name,uniforms:{color:this.color,speed:6},source:$},translucent:()=>!0})}}const M=t=>{const r={...z,...t};return{material:new e.Material({fabric:{type:`${o.CircleRaderFan}-${n()}`,uniforms:{color:e.Color.fromCssColorString(r.color),speed:r.speed},source:$},translucent:!0})}},$="\n uniform vec4 color;\n uniform float speed;\n #define PI 3.14159265359\n czm_material czm_getMaterial(czm_materialInput materialInput){\n czm_material material = czm_getDefaultMaterial(materialInput);\n\n // 绘制边线\n float dis = distance(materialInput.st, vec2(0.5));\n float alpha = step((0.5- 0.01), dis);\n\n material.alpha = alpha;\n material.diffuse = color.rgb;\n\n // 绘制扇区\n vec2 xy = materialInput.st;\n float rx = xy.x - 0.5;\n float ry = xy.y - 0.5;\n float at = atan(ry, rx);\n float per = czm_frameNumber * speed / PI * 3.0 / 200.0;\n // 半径\n float radius = sqrt(rx * rx + ry * ry);\n // 扇区叠加旋转角度\n float current_radians = at + per;\n xy = vec2(cos(current_radians) * radius, sin(current_radians) * radius);\n xy = vec2(xy.x + 0.5, xy.y + 0.5);\n // 扇区渐变色渲染\n if (xy.y - xy.x < 0.0 && xy.x > 0.5 && xy.y > 0.5){\n material.alpha = (alpha + color.a) * dis;\n material.diffuse = color.rgb;\n }\n return material;\n }\n",w={color:"rgba(255,255,0,0.3)",speed:8};class P extends a{speed;color;name="";constructor(t){super(),t||(t={});const r={...w,...t};this.name=`${o.CircleAperture}-${n()}`,this.color=e.Color.fromCssColorString(r.color),this.speed=r.speed,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return`${this.name}`}getValue(t,r){return e.defined(r)||(r={}),r.color=this.color,r.speed=this.speed,r}equals(t){return this===t||t instanceof P&&e.Property.equals(this.color,t.color)&&this.speed===t.speed&&this.name===t.name}init(){e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(this.name,{fabric:{type:this.name,uniforms:{color:new e.Color(1,0,0,.5),speed:this.speed},source:S},translucent:()=>!0})}}const D=t=>{const r={...w,...t};return new e.Material({fabric:{type:`${o.CircleAperture}-${n()}`,uniforms:{color:e.Color.fromCssColorString(r.color),speed:r.speed},source:S},translucent:!0})},S="\n uniform vec4 color;\n uniform float speed;\n\n czm_material czm_getMaterial(czm_materialInput materialInput)\n {\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n float d = distance(st, vec2(0.5, 0.5));\n float alpha = step(.15, d) * step(d, .17) + step(.49, d) * step(d, 0.5) + d * d * step(d, 0.5);\n float movingCircleD = fract(czm_frameNumber * speed / 1000.0);\n alpha += step(movingCircleD, d) * step(d, movingCircleD + .015);\n material.diffuse = color.rgb;\n material.alpha = alpha;\n return material;\n }\n",N=e=>{e||(e={});return new t({fabric:{type:`${o.RadarScanCircle}-${n()}`,uniforms:{radians:3*Math.PI/8,bgColor:r.fromCssColorString(e.bgColor||"rgba(0,255,0,0.2)"),sectorColor:r.fromCssColorString(e.sectorColor||"rgba(152,18,8,.1)"),width:e.width||.003,offset:e.offset||0,count:e.count||3},source:T},translucent:!0})},T="\n uniform vec4 bgColor;\n uniform vec4 sectorColor;\n uniform float count;\n uniform float radians;\n uniform float width;\n uniform float offset;\n czm_material czm_getMaterial(czm_materialInput materialInput)\n {\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n float dis = distance(st, vec2(0.5));\n\n float alpha;\n vec3 diffuse;\n // 绘制圆圈\n float sp = 1.0 / count / 2.0;\n float m = mod(dis, sp);\n alpha = step(sp * (1.0 - width * 10.0), m);\n // alpha = clamp(alpha, 0.2, 1.0);\n if (alpha < bgColor.a){\n alpha = bgColor.a;\n diffuse = bgColor.rgb;\n } else {\n diffuse = bgColor.rgb;\n }\n material.alpha = alpha;\n material.diffuse = diffuse;\n // 绘制十字线\n if ((st.s > 0.5 - width / 2.0 && st.s < 0.5 + width / 2.0) || (st.t > 0.5 - width / 2.0 && st.t < 0.5 + width / 2.0)) {\n material.alpha = 0.8;\n material.diffuse = bgColor.rgb;\n return material;\n }\n // 绘制光晕\n float ma = mod(dis + offset, 0.5);\n if (ma < 0.25){\n alpha = ma * 3.0 + alpha;\n } else{\n alpha = 3.0 * (0.5 - ma) + alpha;\n }\n material.alpha = alpha;\n material.diffuse = bgColor.rgb;\n // 绘制扇区\n vec2 xy = materialInput.st;\n float rx = xy.x - 0.5;\n float ry = xy.y - 0.5;\n float at = atan(ry, rx);\n // 半径\n float radius = sqrt(rx * rx + ry * ry);\n // 扇区叠加旋转角度\n float current_radians = at + radians;\n xy = vec2(cos(current_radians) * radius, sin(current_radians) * radius);\n xy = vec2(xy.x + 0.5, xy.y + 0.5);\n // 扇区渐变色渲染\n if (xy.y - xy.x < 0.0 && xy.x > 0.5 && xy.y > 0.5){\n material.alpha = alpha + sectorColor.a;\n material.diffuse = sectorColor.rgb;\n }\n return material;\n }\n",W={color:"rgba(255,255,255,1)",count:3,duration:1500};class q extends a{duration;count;vertical;direction;color;_time;image;name="";constructor(t){super();const r={...W,...t};Object.prototype.hasOwnProperty.call(r,"vertical")||(r.vertical=1),console.log(r.color),this.name=o.LightWall,this._time=(new Date).getTime(),this.color=e.Color.fromCssColorString(r.color),this.duration=r.duration,this.count=r.count,this.vertical=r.vertical,this.image=r.image,this.direction=r.direction,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return this.name}getValue(t,r){return e.defined(r)||(r={}),r.color=this.color,r.image=this.image,r.vertical=this.vertical,r.direction=this.direction,r.count=this.count,r.duration=this.duration,this.duration&&(r.time=((new Date).getTime()-this._time)%this.duration/this.duration),r}equals(t){return this===t||t instanceof q&&e.Property.equals(this.color,t.color)&&this.name===t.name&&this.image===t.image&&this.vertical===t.vertical&&this.direction===t.direction&&this.count===t.count&&this.duration===t.duration}init(){const t=E({count:this.count,vertical:this.vertical,direction:this.direction});e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(o.LightWall,{fabric:{type:o.LightWall,uniforms:{color:this.color,duration:this.duration,vertical:this.vertical,image:this.image,count:this.count,time:-20},source:t},translucent:()=>!0})}}const R=t=>{const r={...W,...t};return{material:new e.Material({fabric:{type:o.LightWall,uniforms:{color:e.Color.fromCssColorString(r.color),duration:r.duration,vertical:r.vertical,image:r.image,count:r.count,time:-20},source:E({count:r.count,vertical:r.vertical,direction:r.direction})}})}},E=e=>{const t=e.vertical?"vertical":"standard",r=e.direction?"+":"-";let a="czm_material czm_getMaterial(czm_materialInput materialInput)\n {\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;";return a+="vertical"===t?`vec4 colorImage = texture(image, vec2(fract(st.s), fract(float(${e.count})*st.t${r} time)));\n `:`vec4 colorImage = texture(image, vec2(fract(float(${e.count})*st.s ${r} time), fract(st.t)));\n `,a+="vec4 fragColor;\n fragColor.rgb = (colorImage.rgb+color.rgb) / 1.0;\n fragColor = czm_gammaCorrect(fragColor);\n material.diffuse = colorImage.rgb;\n material.alpha = colorImage.a * color.a;\n material.emission = fragColor.rgb;\n return material;\n }",a},V={name:"circle-fan",color:"rgba(255,255,255,1)",speed:8};class F extends a{speed;color;name="";constructor(t){super();const r={...V,...t};this.name=`${o.EllipsoidElectric}-${n()}`,this.color=e.Color.fromCssColorString(r.color),this.speed=r.speed,this.init()}get isConstant(){return!1}get definitionChanged(){return this._definitionChanged}getType(){return`${this.name}`}getValue(t,r){return e.defined(r)||(r={}),r.speed=this.speed,r}equals(e){return this===e||e instanceof F&&this.speed===e.speed&&this.name===e.name}init(){e.Material[this.name]=this.name,e.Material._materialCache.addMaterial(this.name,{fabric:{type:this.name,uniforms:{color:this.color,speed:6},source:L},translucent:()=>!0})}}const O=t=>{const r={...V,...t};return{material:new e.Material({fabric:{type:`${o.EllipsoidElectric}-${n()}`,uniforms:{color:e.Color.fromCssColorString(r.color),speed:r.speed},source:L},translucent:!0})}},L="\n uniform vec4 color;\n uniform float speed;\n #define pi 3.1415926535\n #define PI2RAD 0.01745329252\n #define TWO_PI (2. * PI)\n\n float rands(float p){\n return fract(sin(p) * 10000.0);\n }\n\n float noise(vec2 p){\n float time = fract( czm_frameNumber * speed / 1000.0);\n float t = time / 20000.0;\n\n if(t > 1.0) t -= floor(t);\n return rands(p.x * 14. + p.y * sin(t) * 0.5);\n }\n\n vec2 sw(vec2 p){\n return vec2(floor(p.x), floor(p.y));\n }\n\n vec2 se(vec2 p){\n return vec2(ceil(p.x), floor(p.y));\n }\n\n vec2 nw(vec2 p){\n return vec2(floor(p.x), ceil(p.y));\n }\n\n vec2 ne(vec2 p){\n return vec2(ceil(p.x), ceil(p.y));\n }\n\n float smoothNoise(vec2 p){\n vec2 inter = smoothstep(0.0, 1.0, fract(p));\n float s = mix(noise(sw(p)), noise(se(p)), inter.x);\n float n = mix(noise(nw(p)), noise(ne(p)), inter.x);\n return mix(s, n, inter.y);\n }\n\n float fbm(vec2 p){\n float z = 2.0;\n float rz = 0.0;\n vec2 bp = p;\n for(float i = 1.0; i < 6.0; i++){\n rz += abs((smoothNoise(p) - 0.5)* 2.0) / z;\n z *= 2.0;\n p *= 2.0;\n }\n return rz;\n }\n\n czm_material czm_getMaterial(czm_materialInput materialInput)\n {\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n vec2 st2 = materialInput.st;\n float time = fract( czm_frameNumber * speed / 1000.0);\n if (st.t < 0.5) {\n discard;\n }\n st *= 4.;\n float rz = fbm(st);\n st /= exp(mod( time * 2.0, pi));\n rz *= pow(15., 0.9);\n vec4 temp = vec4(0);\n temp = mix( color / rz, vec4(color.rgb, 0.1), 0.2);\n if (st2.s < 0.05) {\n temp = mix(vec4(color.rgb, 0.1), temp, st2.s / 0.05);\n }\n if (st2.s > 0.95){\n temp = mix(temp, vec4(color.rgb, 0.1), (st2.s - 0.95) / 0.05);\n }\n material.diffuse = temp.rgb;\n material.alpha = temp.a * 2.0;\n return material;\n }\n";export{P as CircleApertureMaterialProperty,I as CircleRaderFanMaterialProperty,y as CircleRaderWaveMaterialProperty,g as CircleWaveMaterialProperty,F as EllipsoidElectricMaterialProperty,q as LightWallMaterialProperty,i as Material,d as PolylineFlowMaterialProperty,l as PolylineTrailMaterialProperty,D as createCircleApertureMaterial,M as createCircleRaderFanMaterial,C as createCircleWaveMaterial,O as createEllipsoidElectricMaterial,R as createLightWallMaterial,p as createPoylineFlowMaterial,_ as createRaderWaveMaterial,N as createScanRadarMaterial,c as createTrailMaterial};
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@ino-cesium/material",
3
+ "type": "module",
4
+ "version": "0.0.2",
5
+ "author": "koino",
6
+ "keywords": [
7
+ "cesium",
8
+ "ino-cesium",
9
+ "ino-cesium-material"
10
+ ],
11
+ "exports": {
12
+ ".": "./src/index.js"
13
+ },
14
+ "typesVersions": {
15
+ "*": {
16
+ "*": [
17
+ "./src/*"
18
+ ]
19
+ }
20
+ },
21
+ "files": [
22
+ "dist/*.d.ts",
23
+ "dist/*.js",
24
+ "README.MD"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "peerDependencies": {
30
+ "cesium": "*"
31
+ },
32
+ "dependencies": {
33
+ "@ino-cesium/common": "0.0.2"
34
+ },
35
+ "scripts": {
36
+ "build": "rimraf dist && rollup -c",
37
+ "clean": "rimraf dist",
38
+ "release": "pnpm publish --no-git-checks --access public ",
39
+ "unpublish": "pnpm unpublish @ino-cesium/material --force "
40
+ }
41
+ }