easy-three-utils 0.0.354 → 0.0.356

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.
@@ -5,6 +5,9 @@ const useCloud = (viewer: Cesium.Viewer) => {
5
5
 
6
6
  let cloudsCollection = []
7
7
 
8
+ let globalClouds
9
+ let cloudData = []
10
+
8
11
  const getRandomPoints = (polygonCartesian: Cesium.Cartesian3[], numPoints: number, h: number) => {
9
12
 
10
13
  const polygon = polygonCartesian.map(cartesian => {
@@ -87,6 +90,7 @@ const useCloud = (viewer: Cesium.Viewer) => {
87
90
  const width = Math.max(...points.map(p => p.x)) - Math.min(...points.map(p => p.x))
88
91
  const length = Math.max(...points.map(p => p.y)) - Math.min(...points.map(p => p.y))
89
92
  const num = Math.floor(width * length / (options.cloudLength * options.cloudWidth)) * options.density
93
+
90
94
  const _points = getRandomPoints(points, num, 5000 + (options.cloudLength + options.cloudWidth) / 2)
91
95
 
92
96
  _points.forEach(point => {
@@ -120,6 +124,97 @@ const useCloud = (viewer: Cesium.Viewer) => {
120
124
  })
121
125
  }
122
126
 
127
+ let angle = 0
128
+ let speedDegPerSec = 0.1
129
+ let prevTime = Cesium.JulianDate.clone(viewer.clock.currentTime)
130
+
131
+ const onTick = (clock) => {
132
+ const speed = Cesium.Math.toRadians(speedDegPerSec)
133
+
134
+ const now = clock.currentTime;
135
+ const dt = Cesium.JulianDate.secondsDifference(now, prevTime)
136
+ prevTime = Cesium.JulianDate.clone(now)
137
+
138
+ if (dt <= 0) return
139
+
140
+ angle += speed * dt
141
+ const rot = Cesium.Matrix3.fromRotationZ(angle)
142
+
143
+ for (const d of cloudData) {
144
+ const rotated = new Cesium.Cartesian3()
145
+ Cesium.Matrix3.multiplyByVector(rot, d.orig, rotated)
146
+ d.cloud.position = rotated
147
+ }
148
+ }
149
+
150
+ const enabledGlobalCloud = (options?: {
151
+ color?: string;
152
+ number?: number;
153
+ speed?: number;
154
+ }) => {
155
+
156
+ speedDegPerSec = options.speed ? options.speed : 0.1
157
+ globalClouds = viewer.scene.primitives.add(new Cesium.CloudCollection())
158
+ const maxLength = 3000000
159
+ const minLength = 2000000
160
+
161
+ const coords = [
162
+ { lon: -180, lat: -90 },
163
+ { lon: 180, lat: -90 },
164
+ { lon: 180, lat: 90 },
165
+ { lon: -180, lat: 90 },
166
+ { lon: -180, lat: -90 },
167
+ ];
168
+
169
+ const points = coords.map(c =>
170
+ Cesium.Cartesian3.fromDegrees(c.lon, c.lat)
171
+ )
172
+
173
+ const _points = getRandomPoints(points, (options && options.number) ? options.number : 500, Math.floor(Math.random() * (900000 - 700000 + 1)) + 700000)
174
+ _points.forEach(point => {
175
+ const r = Math.random()
176
+ const cloud = globalClouds.add({
177
+ show: true,
178
+ position: point,
179
+ maximumSize: new Cesium.Cartesian3(
180
+ 5 + r * 15,
181
+ 4 + r * 10,
182
+ 3 + r * 5
183
+ ),
184
+ scale: new Cesium.Cartesian2(maxLength, Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength),
185
+ slice: 0.2 + Math.random() * 0.3,
186
+ brightness: 0.8 + Math.random() * 0.4,
187
+ color: Cesium.Color.fromCssColorString((options && options.color) ? options.color : 'rgba(255, 255, 255)'),
188
+ noiseDetail: 3.0 + Math.random(),
189
+ noiseOffset: new Cesium.Cartesian3(
190
+ Math.random() * 100,
191
+ Math.random() * 100,
192
+ Math.random() * 100
193
+ ),
194
+ orientation: Cesium.Quaternion.fromAxisAngle(
195
+ Cesium.Cartesian3.UNIT_Z,
196
+ Math.random() * Cesium.Math.TWO_PI
197
+ )
198
+ })
199
+
200
+ cloudData.push({
201
+ cloud,
202
+ orig: Cesium.Cartesian3.clone(point)
203
+ })
204
+ })
205
+
206
+ viewer.clock.onTick.addEventListener(onTick)
207
+ }
208
+
209
+ const disabledGlobalCloud = () => {
210
+ if (globalClouds) {
211
+ globalClouds.removeAll()
212
+ globalClouds = null
213
+ }
214
+ cloudData = []
215
+ viewer.clock.onTick.removeEventListener(onTick)
216
+ }
217
+
123
218
  const removeAll = () => {
124
219
  cloudsCollection.forEach(item => item.clouds.removeAll())
125
220
  viewer.scene.primitives.removeAll()
@@ -128,6 +223,8 @@ const useCloud = (viewer: Cesium.Viewer) => {
128
223
 
129
224
  return {
130
225
  draw,
226
+ enabledGlobalCloud,
227
+ disabledGlobalCloud,
131
228
  removeAll
132
229
  }
133
230
  }
@@ -20,7 +20,7 @@ const useSeawater = (viewer: Cesium.Viewer) => {
20
20
  fabric: {
21
21
  type: 'Water',
22
22
  uniforms: {
23
- specularMap: __POLT__URL__ + '/assets/image/earthspec.jpg',
23
+ specularMap: (window as any).__POLT__URL__ + '/assets/image/earthspec.jpg',
24
24
  normalMap: Cesium.buildModuleUrl('Assets/Textures/waterNormals.jpg'),
25
25
  frequency: 10000.0,
26
26
  animationSpeed: 0.01,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-three-utils",
3
- "version": "0.0.354",
3
+ "version": "0.0.356",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -8,5 +8,5 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "types": "./index.d.ts",
11
- "description": "新增阳光控制器"
11
+ "description": "新增全球云(速度调节参数)"
12
12
  }