easy-three-utils 0.0.350 → 0.0.351
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/cesium/index.ts +7 -1
- package/cesium/plot/usePlot.d.ts +2 -0
- package/cesium/utils/index.ts +2 -0
- package/cesium/utils/useCustomCollection.ts +3 -0
- package/cesium/utils/useProfileAnalysis.ts +7 -6
- package/cesium/utils/useViewshedAnalysis.ts +303 -0
- package/package.json +2 -2
- package/cesium/utils/useDrawTools.ts +0 -50
- package/cesium/utils/useViewShed.ts +0 -199
package/cesium/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ type TCesiumUtilsType = {
|
|
|
15
15
|
measure: ReturnType<typeof hooks.useMeasure>;
|
|
16
16
|
slope: ReturnType<typeof hooks.useSlope>;
|
|
17
17
|
profileAnalysis: ReturnType<typeof hooks.useProfileAnalysis>;
|
|
18
|
+
viewshedAnalysis: ReturnType<typeof hooks.useViewshedAnalysis>;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
let config;
|
|
@@ -100,6 +101,10 @@ const useCesium = () => {
|
|
|
100
101
|
const profileAnalysis = hooks.useProfileAnalysis(viewer, {
|
|
101
102
|
collection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.PROFILEANALYSIS)
|
|
102
103
|
})
|
|
104
|
+
const viewshedAnalysis = hooks.useViewshedAnalysis(viewer, {
|
|
105
|
+
collection: customCollection.addCollection(hooks.dict.ECollectionWhiteListNames.VIEWSHEDANALYSIS)
|
|
106
|
+
})
|
|
107
|
+
|
|
103
108
|
|
|
104
109
|
if (config.controllerStyle === cesiumConfigDict.EControllerStyle.THREE) {
|
|
105
110
|
updateController(viewer)
|
|
@@ -113,7 +118,8 @@ const useCesium = () => {
|
|
|
113
118
|
weather,
|
|
114
119
|
measure,
|
|
115
120
|
slope,
|
|
116
|
-
profileAnalysis
|
|
121
|
+
profileAnalysis,
|
|
122
|
+
viewshedAnalysis
|
|
117
123
|
})
|
|
118
124
|
|
|
119
125
|
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
|
package/cesium/plot/usePlot.d.ts
CHANGED
package/cesium/utils/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { useWeather, EWeatherType } from './useWeather'
|
|
|
5
5
|
import { useMeasure } from './useMeasure'
|
|
6
6
|
import { useSlope } from './useSlope'
|
|
7
7
|
import { useProfileAnalysis } from './useProfileAnalysis'
|
|
8
|
+
import { useViewshedAnalysis } from './useViewshedAnalysis'
|
|
8
9
|
|
|
9
10
|
const dict = {
|
|
10
11
|
ECollectionWhiteListNames,
|
|
@@ -19,6 +20,7 @@ export {
|
|
|
19
20
|
useMeasure,
|
|
20
21
|
useSlope,
|
|
21
22
|
useProfileAnalysis,
|
|
23
|
+
useViewshedAnalysis,
|
|
22
24
|
|
|
23
25
|
dict
|
|
24
26
|
}
|
|
@@ -8,7 +8,9 @@ enum ECollectionWhiteListNames {
|
|
|
8
8
|
MEASURE_HEIGHT = 'measure_height',
|
|
9
9
|
MEASURE_AREA = 'measure_area',
|
|
10
10
|
MEASURE_ALTITUDE = 'measure_altitude',
|
|
11
|
+
|
|
11
12
|
PROFILEANALYSIS = 'profileAnalysis',
|
|
13
|
+
VIEWSHEDANALYSIS = 'viewshedAnalysis',
|
|
12
14
|
|
|
13
15
|
SLOPE = 'slope'
|
|
14
16
|
}
|
|
@@ -24,6 +26,7 @@ const useCustomCollection = (viewer: Cesium.Viewer) => {
|
|
|
24
26
|
'measure_area',
|
|
25
27
|
'measure_altitude',
|
|
26
28
|
'profileAnalysis',
|
|
29
|
+
'viewshedAnalysis',
|
|
27
30
|
'slope'
|
|
28
31
|
]
|
|
29
32
|
|
|
@@ -110,13 +110,14 @@ const useProfileAnalysis = (viewer: Cesium.Viewer, options: {
|
|
|
110
110
|
},
|
|
111
111
|
label: {
|
|
112
112
|
text: textDisance,
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
scale: 0.5,
|
|
114
|
+
font: "normal 28px MicroSoft YaHei",
|
|
115
115
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
heightReference: Cesium.HeightReference.
|
|
116
|
+
pixelOffset: new Cesium.Cartesian2(0, -30),
|
|
117
|
+
outlineWidth: 9,
|
|
118
|
+
outlineColor: Cesium.Color.WHITE,
|
|
119
|
+
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
|
|
120
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY
|
|
120
121
|
}
|
|
121
122
|
})
|
|
122
123
|
}) as Cesium.ScreenSpaceEventHandler.PositionedEventCallback, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import * as Cesium from 'cesium'
|
|
2
|
+
import glsl from "../glsl/viewable"
|
|
3
|
+
|
|
4
|
+
const useViewshedAnalysis = (viewer: Cesium.Viewer, options: {
|
|
5
|
+
collection: Cesium.CustomDataSource
|
|
6
|
+
}) => {
|
|
7
|
+
|
|
8
|
+
let i = 0
|
|
9
|
+
let handler: Cesium.ScreenSpaceEventHandler | null = null
|
|
10
|
+
let viewPosition = null
|
|
11
|
+
let viewDistance = 100.0
|
|
12
|
+
let viewHeading = 0.0
|
|
13
|
+
let viewPitch = 0.0
|
|
14
|
+
let horizontalViewAngle = 90.0
|
|
15
|
+
let verticalViewAngle = 60.0
|
|
16
|
+
let visibleAreaColor = Cesium.Color.GREEN
|
|
17
|
+
let invisibleAreaColor = Cesium.Color.RED
|
|
18
|
+
let enabled = true
|
|
19
|
+
let softShadows = true
|
|
20
|
+
let size = 2048
|
|
21
|
+
let lightCamera = null
|
|
22
|
+
let shadowMap = null
|
|
23
|
+
let sketch = null
|
|
24
|
+
let postStage = null
|
|
25
|
+
let frustumOutline = null
|
|
26
|
+
|
|
27
|
+
const add = () => {
|
|
28
|
+
createLightCamera()
|
|
29
|
+
createShadowMap()
|
|
30
|
+
drawFrustumOutline()
|
|
31
|
+
drawSketch()
|
|
32
|
+
createPostStage()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const update = () => {
|
|
36
|
+
removeAll()
|
|
37
|
+
add()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const removeAll = () => {
|
|
41
|
+
stopDraw()
|
|
42
|
+
|
|
43
|
+
if (sketch) {
|
|
44
|
+
options.collection.entities.remove(sketch)
|
|
45
|
+
sketch = null
|
|
46
|
+
}
|
|
47
|
+
if (postStage) {
|
|
48
|
+
viewer.scene.postProcessStages.remove(postStage)
|
|
49
|
+
postStage = null
|
|
50
|
+
}
|
|
51
|
+
if (frustumOutline) {
|
|
52
|
+
viewer.scene.primitives.remove(frustumOutline)
|
|
53
|
+
frustumOutline = null
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const updatePosition = (position) => {
|
|
58
|
+
viewDistance = Cesium.Cartesian3.distance(viewPosition, position)
|
|
59
|
+
viewHeading = getHeading(viewPosition, position)
|
|
60
|
+
viewPitch = getPitch(viewPosition, position)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const createLightCamera = () => {
|
|
64
|
+
const camera = new Cesium.Camera(viewer.scene)
|
|
65
|
+
camera.position = viewPosition
|
|
66
|
+
camera.frustum.near = viewDistance * 0.001
|
|
67
|
+
camera.frustum.far = viewDistance
|
|
68
|
+
|
|
69
|
+
const hr = Cesium.Math.toRadians(horizontalViewAngle)
|
|
70
|
+
const vr = Cesium.Math.toRadians(verticalViewAngle)
|
|
71
|
+
const aspectRatio = (viewDistance * Math.tan(hr / 2) * 2) / (viewDistance * Math.tan(vr / 2) * 2);
|
|
72
|
+
(camera.frustum as any).aspectRatio = aspectRatio;
|
|
73
|
+
(camera.frustum as any).fov = Math.max(hr, vr)
|
|
74
|
+
|
|
75
|
+
camera.setView({
|
|
76
|
+
destination: viewPosition,
|
|
77
|
+
orientation: {
|
|
78
|
+
heading: Cesium.Math.toRadians(viewHeading || 0),
|
|
79
|
+
pitch: Cesium.Math.toRadians(viewPitch || 0),
|
|
80
|
+
roll: 0
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
lightCamera = camera
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const createShadowMap = () => {
|
|
87
|
+
const shadow = new (Cesium.ShadowMap as any)({
|
|
88
|
+
context: (viewer.scene as any).context,
|
|
89
|
+
lightCamera: lightCamera,
|
|
90
|
+
enabled: enabled,
|
|
91
|
+
isPointLight: true,
|
|
92
|
+
pointLightRadius: viewDistance,
|
|
93
|
+
cascadesEnabled: false,
|
|
94
|
+
size: size,
|
|
95
|
+
softShadows: softShadows,
|
|
96
|
+
normalOffset: false,
|
|
97
|
+
fromLightSource: false
|
|
98
|
+
})
|
|
99
|
+
viewer.scene.shadowMap = shadow
|
|
100
|
+
shadowMap = shadow
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const createPostStage = () => {
|
|
104
|
+
const fs = glsl
|
|
105
|
+
const cutomPostStage = new Cesium.PostProcessStage({
|
|
106
|
+
fragmentShader: fs,
|
|
107
|
+
uniforms: {
|
|
108
|
+
shadowMap_textureCube: () => {
|
|
109
|
+
shadowMap.update(Reflect.get(viewer.scene, '_frameState'))
|
|
110
|
+
return Reflect.get(shadowMap, '_shadowMapTexture')
|
|
111
|
+
},
|
|
112
|
+
shadowMap_matrix: () => {
|
|
113
|
+
shadowMap.update(Reflect.get(viewer.scene, '_frameState'))
|
|
114
|
+
return Reflect.get(shadowMap, '_shadowMapMatrix')
|
|
115
|
+
},
|
|
116
|
+
shadowMap_lightPositionEC: () => {
|
|
117
|
+
shadowMap.update(Reflect.get(viewer.scene, '_frameState'))
|
|
118
|
+
return Reflect.get(shadowMap, '_lightPositionEC')
|
|
119
|
+
},
|
|
120
|
+
shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness: () => {
|
|
121
|
+
shadowMap.update(Reflect.get(viewer.scene, '_frameState'))
|
|
122
|
+
const bias = shadowMap._pointBias
|
|
123
|
+
return Cesium.Cartesian4.fromElements(
|
|
124
|
+
bias.normalOffsetScale,
|
|
125
|
+
shadowMap._distance,
|
|
126
|
+
shadowMap.maximumDistance,
|
|
127
|
+
0.0,
|
|
128
|
+
new Cesium.Cartesian4()
|
|
129
|
+
)
|
|
130
|
+
},
|
|
131
|
+
shadowMap_texelSizeDepthBiasAndNormalShadingSmooth: () => {
|
|
132
|
+
shadowMap.update(Reflect.get(viewer.scene, '_frameState'))
|
|
133
|
+
const bias = shadowMap._pointBias
|
|
134
|
+
const texelStepSize = new Cesium.Cartesian2(
|
|
135
|
+
1.0 / shadowMap._textureSize.x,
|
|
136
|
+
1.0 / shadowMap._textureSize.y
|
|
137
|
+
)
|
|
138
|
+
return Cesium.Cartesian4.fromElements(
|
|
139
|
+
texelStepSize.x,
|
|
140
|
+
texelStepSize.y,
|
|
141
|
+
bias.depthBias,
|
|
142
|
+
bias.normalShadingSmooth,
|
|
143
|
+
new Cesium.Cartesian4()
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
camera_projection_matrix: lightCamera.frustum.projectionMatrix,
|
|
147
|
+
camera_view_matrix: lightCamera.viewMatrix,
|
|
148
|
+
helsing_viewDistance: () => viewDistance,
|
|
149
|
+
helsing_visibleAreaColor: visibleAreaColor,
|
|
150
|
+
helsing_invisibleAreaColor: invisibleAreaColor
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
postStage = viewer.scene.postProcessStages.add(cutomPostStage)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const drawFrustumOutline = () => {
|
|
157
|
+
const direction = lightCamera.directionWC
|
|
158
|
+
const up = lightCamera.upWC
|
|
159
|
+
const right = Cesium.Cartesian3.negate(lightCamera.rightWC, new Cesium.Cartesian3())
|
|
160
|
+
const rotation = Cesium.Matrix3.setColumn(
|
|
161
|
+
new Cesium.Matrix3(),
|
|
162
|
+
0,
|
|
163
|
+
right,
|
|
164
|
+
new Cesium.Matrix3()
|
|
165
|
+
)
|
|
166
|
+
Cesium.Matrix3.setColumn(rotation, 1, up, rotation)
|
|
167
|
+
Cesium.Matrix3.setColumn(rotation, 2, direction, rotation)
|
|
168
|
+
const orientation = Cesium.Quaternion.fromRotationMatrix(rotation, new Cesium.Quaternion())
|
|
169
|
+
|
|
170
|
+
const instance = new Cesium.GeometryInstance({
|
|
171
|
+
geometry: new Cesium.FrustumOutlineGeometry({
|
|
172
|
+
frustum: lightCamera.frustum,
|
|
173
|
+
origin: viewPosition,
|
|
174
|
+
orientation
|
|
175
|
+
}),
|
|
176
|
+
attributes: {
|
|
177
|
+
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.YELLOWGREEN),
|
|
178
|
+
show: new Cesium.ShowGeometryInstanceAttribute(true)
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
frustumOutline = viewer.scene.primitives.add(
|
|
183
|
+
new Cesium.Primitive({
|
|
184
|
+
geometryInstances: [instance],
|
|
185
|
+
appearance: new Cesium.PerInstanceColorAppearance({
|
|
186
|
+
flat: true,
|
|
187
|
+
translucent: false
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const drawSketch = () => {
|
|
194
|
+
sketch = options.collection.entities.add({
|
|
195
|
+
name: 'sketch',
|
|
196
|
+
position: viewPosition,
|
|
197
|
+
orientation: new Cesium.CallbackProperty(() => {
|
|
198
|
+
return Cesium.Transforms.headingPitchRollQuaternion(
|
|
199
|
+
viewPosition,
|
|
200
|
+
Cesium.HeadingPitchRoll.fromDegrees(
|
|
201
|
+
viewHeading - horizontalViewAngle,
|
|
202
|
+
viewPitch,
|
|
203
|
+
0.5
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
}, false),
|
|
207
|
+
ellipsoid: {
|
|
208
|
+
radii: new Cesium.CallbackProperty(
|
|
209
|
+
() => new Cesium.Cartesian3(viewDistance, viewDistance, viewDistance),
|
|
210
|
+
false
|
|
211
|
+
),
|
|
212
|
+
innerRadii: new Cesium.Cartesian3(2.0, 2.0, 2.0),
|
|
213
|
+
minimumClock: Cesium.Math.toRadians(-horizontalViewAngle / 2),
|
|
214
|
+
maximumClock: Cesium.Math.toRadians(horizontalViewAngle / 2),
|
|
215
|
+
minimumCone: Cesium.Math.toRadians(verticalViewAngle + 7.75),
|
|
216
|
+
maximumCone: Cesium.Math.toRadians(180 - verticalViewAngle - 7.75),
|
|
217
|
+
fill: false,
|
|
218
|
+
outline: true,
|
|
219
|
+
subdivisions: 256,
|
|
220
|
+
stackPartitions: 64,
|
|
221
|
+
slicePartitions: 64,
|
|
222
|
+
outlineColor: Cesium.Color.YELLOWGREEN
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const getHeading = (from, to) => {
|
|
228
|
+
const result = new Cesium.Cartesian3()
|
|
229
|
+
const matrix4 = Cesium.Matrix4.inverse(Cesium.Transforms.eastNorthUpToFixedFrame(from), new Cesium.Matrix4())
|
|
230
|
+
Cesium.Matrix4.multiplyByPoint(matrix4, to, result)
|
|
231
|
+
Cesium.Cartesian3.normalize(result, result)
|
|
232
|
+
return Cesium.Math.toDegrees(Math.atan2(result.x, result.y))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const getPitch = (from, to) => {
|
|
236
|
+
const result = new Cesium.Cartesian3()
|
|
237
|
+
const matrix4 = Cesium.Matrix4.inverse(Cesium.Transforms.eastNorthUpToFixedFrame(from), new Cesium.Matrix4())
|
|
238
|
+
Cesium.Matrix4.multiplyByPoint(matrix4, to, result)
|
|
239
|
+
Cesium.Cartesian3.normalize(result, result)
|
|
240
|
+
return Cesium.Math.toDegrees(Math.asin(result.z))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const leftClickEvent = () => {
|
|
244
|
+
handler.setInputAction(((movement) => {
|
|
245
|
+
i++
|
|
246
|
+
if (i === 1) {
|
|
247
|
+
let startPosition = viewer.scene.pickPosition(movement.position)
|
|
248
|
+
if (!startPosition) return
|
|
249
|
+
viewPosition = startPosition
|
|
250
|
+
mouseMoveEvent()
|
|
251
|
+
}
|
|
252
|
+
if (i === 2) {
|
|
253
|
+
i = 0
|
|
254
|
+
let endPosition = viewer.scene.pickPosition(movement.position)
|
|
255
|
+
updatePosition(endPosition)
|
|
256
|
+
update()
|
|
257
|
+
stopDraw()
|
|
258
|
+
}
|
|
259
|
+
}) as Cesium.ScreenSpaceEventHandler.PositionedEventCallback, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const mouseMoveEvent = () => {
|
|
263
|
+
handler.setInputAction(((movement) => {
|
|
264
|
+
const endPosition = viewer.scene.pickPosition(movement.endPosition)
|
|
265
|
+
if (!endPosition) return
|
|
266
|
+
updatePosition(endPosition)
|
|
267
|
+
if (!sketch) {
|
|
268
|
+
drawSketch()
|
|
269
|
+
}
|
|
270
|
+
}) as Cesium.ScreenSpaceEventHandler.MotionEventCallback, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const draw = () => {
|
|
274
|
+
if (handler) {
|
|
275
|
+
console.log('请先结束上次测量!')
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
|
|
279
|
+
leftClickEvent()
|
|
280
|
+
viewer.scene.camera.frustum.near = 100.0
|
|
281
|
+
viewer.scene.logarithmicDepthBuffer = true
|
|
282
|
+
viewer.scene.globe.enableLighting = false
|
|
283
|
+
viewer.scene.globe.showGroundAtmosphere = false
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const stopDraw = () => {
|
|
287
|
+
if (handler) {
|
|
288
|
+
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
|
289
|
+
handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)
|
|
290
|
+
handler.destroy()
|
|
291
|
+
handler = null
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
draw,
|
|
297
|
+
removeAll
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export {
|
|
302
|
+
useViewshedAnalysis
|
|
303
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-three-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.351",
|
|
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
|
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as Cesium from 'cesium'
|
|
2
|
-
|
|
3
|
-
enum ECollectionWhiteListNames {
|
|
4
|
-
POLYGON = 'polygon',
|
|
5
|
-
POLYGON_NODE = 'polygon_node'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const useCustomCollection = (viewer: Cesium.Viewer) => {
|
|
9
|
-
|
|
10
|
-
let collectionNames: string[] = ([])
|
|
11
|
-
let whiteList: string[] = ['polygon', 'polygon_node']
|
|
12
|
-
|
|
13
|
-
const addCollection = (name: string) => {
|
|
14
|
-
const index = collectionNames.findIndex(item => item === name)
|
|
15
|
-
if (index !== -1) return
|
|
16
|
-
collectionNames.push(name)
|
|
17
|
-
const dataSource = new Cesium.CustomDataSource(name);
|
|
18
|
-
viewer.dataSources.add(dataSource);
|
|
19
|
-
return dataSource
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const getCollection = (name: ECollectionWhiteListNames | string) => {
|
|
23
|
-
const collection = viewer.dataSources.getByName(name)
|
|
24
|
-
if (collection.length) {
|
|
25
|
-
return collection[0]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const removeCollection = (name: string) => {
|
|
30
|
-
const collection = viewer.dataSources.getByName(name)
|
|
31
|
-
viewer.dataSources.remove(collection[0], false)
|
|
32
|
-
collectionNames = collectionNames.filter(item => item !== name && !whiteList.includes(item))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const getCollectionNames = () => {
|
|
36
|
-
return collectionNames.filter(item => !whiteList.includes(item))
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
addCollection,
|
|
41
|
-
getCollection,
|
|
42
|
-
removeCollection,
|
|
43
|
-
getCollectionNames
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export {
|
|
48
|
-
ECollectionWhiteListNames,
|
|
49
|
-
useCustomCollection
|
|
50
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import glsl from "../glsl/viewable";
|
|
2
|
-
import * as Cesium from 'cesium'
|
|
3
|
-
|
|
4
|
-
export default class viewShader {
|
|
5
|
-
constructor(viewer, options) {
|
|
6
|
-
this.viewer = viewer;
|
|
7
|
-
this.viewPosition = options.viewPosition;
|
|
8
|
-
this.viewPositionEnd = options.viewPositionEnd;
|
|
9
|
-
this.viewDistance = this.viewPositionEnd ? Cesium.Cartesian3.distance(this.viewPosition, this.viewPositionEnd) : (options.viewDistance || 100.0);
|
|
10
|
-
this.viewHeading = this.viewPositionEnd ? this.getHeading(this.viewPosition, this.viewPositionEnd) : (options.viewHeading || 0.0);
|
|
11
|
-
this.viewPitch = this.viewPositionEnd ? this.getPitch(this.viewPosition, this.viewPositionEnd) : (options.viewPitch || 0.0);
|
|
12
|
-
this.horizontalViewAngle = options.horizontalViewAngle || 90.0;
|
|
13
|
-
this.verticalViewAngle = options.verticalViewAngle || 60.0;
|
|
14
|
-
this.visibleAreaColor = options.visibleAreaColor || Cesium.Color.GREEN;
|
|
15
|
-
this.invisibleAreaColor = options.invisibleAreaColor || Cesium.Color.RED;
|
|
16
|
-
this.enabled = (typeof options.enabled === "boolean") ? options.enabled : true;
|
|
17
|
-
this.softShadows = (typeof options.softShadows === "boolean") ? options.softShadows : true;
|
|
18
|
-
this.size = options.size || 2048;
|
|
19
|
-
|
|
20
|
-
this.update();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
add() {
|
|
24
|
-
this.createLightCamera();
|
|
25
|
-
this.createShadowMap();
|
|
26
|
-
this.createPostStage();
|
|
27
|
-
this.drawSketch();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
update() {
|
|
31
|
-
this.clear();
|
|
32
|
-
this.add();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
updatePosition(viewPositionEnd) {
|
|
36
|
-
this.viewPositionEnd = viewPositionEnd
|
|
37
|
-
this.viewDistance = Cesium.Cartesian3.distance(this.viewPosition, this.viewPositionEnd)
|
|
38
|
-
this.viewHeading = this.getHeading(this.viewPosition, this.viewPositionEnd)
|
|
39
|
-
this.viewPitch = this.getPitch(this.viewPosition, this.viewPositionEnd)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
clear() {
|
|
43
|
-
if (this.sketch) {
|
|
44
|
-
this.viewer.entities.removeById(this.sketch.id);
|
|
45
|
-
this.sketch = null;
|
|
46
|
-
}
|
|
47
|
-
if (this.postStage) {
|
|
48
|
-
this.viewer.scene.postProcessStages.remove(this.postStage);
|
|
49
|
-
this.postStage = null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
createLightCamera() {
|
|
54
|
-
this.lightCamera = new Cesium.Camera(this.viewer.scene);
|
|
55
|
-
this.lightCamera.position = this.viewPosition;
|
|
56
|
-
if (this.viewDistance == 0) {
|
|
57
|
-
this.viewDistance = 1
|
|
58
|
-
}
|
|
59
|
-
this.lightCamera.frustum.near = this.viewDistance * 0.001;
|
|
60
|
-
this.lightCamera.frustum.far = this.viewDistance;
|
|
61
|
-
const hr = Cesium.Math.toRadians(this.horizontalViewAngle);
|
|
62
|
-
const vr = Cesium.Math.toRadians(this.verticalViewAngle);
|
|
63
|
-
const aspectRatio =
|
|
64
|
-
(this.viewDistance * Math.tan(hr / 2) * 2) /
|
|
65
|
-
(this.viewDistance * Math.tan(vr / 2) * 2);
|
|
66
|
-
this.lightCamera.frustum.aspectRatio = aspectRatio;
|
|
67
|
-
if (hr > vr) {
|
|
68
|
-
this.lightCamera.frustum.fov = hr;
|
|
69
|
-
} else {
|
|
70
|
-
this.lightCamera.frustum.fov = vr;
|
|
71
|
-
}
|
|
72
|
-
this.lightCamera.setView({
|
|
73
|
-
destination: this.viewPosition,
|
|
74
|
-
orientation: {
|
|
75
|
-
heading: Cesium.Math.toRadians(this.viewHeading || 0),
|
|
76
|
-
pitch: Cesium.Math.toRadians(this.viewPitch || 0),
|
|
77
|
-
roll: 0
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
createShadowMap() {
|
|
83
|
-
this.shadowMap = new Cesium.ShadowMap({
|
|
84
|
-
context: (this.viewer.scene).context,
|
|
85
|
-
lightCamera: this.lightCamera,
|
|
86
|
-
enabled: this.enabled,
|
|
87
|
-
isPointLight: true,
|
|
88
|
-
pointLightRadius: this.viewDistance,
|
|
89
|
-
cascadesEnabled: false,
|
|
90
|
-
size: this.size,
|
|
91
|
-
softShadows: this.softShadows,
|
|
92
|
-
normalOffset: false,
|
|
93
|
-
fromLightSource: false
|
|
94
|
-
});
|
|
95
|
-
this.viewer.scene.shadowMap = this.shadowMap;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
createPostStage() {
|
|
99
|
-
const postStage = new Cesium.PostProcessStage({
|
|
100
|
-
fragmentShader: glsl,
|
|
101
|
-
uniforms: {
|
|
102
|
-
shadowMap_textureCube: () => {
|
|
103
|
-
this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));
|
|
104
|
-
return Reflect.get(this.shadowMap, "_shadowMapTexture");
|
|
105
|
-
},
|
|
106
|
-
shadowMap_matrix: () => {
|
|
107
|
-
this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));
|
|
108
|
-
return Reflect.get(this.shadowMap, "_shadowMapMatrix");
|
|
109
|
-
},
|
|
110
|
-
shadowMap_lightPositionEC: () => {
|
|
111
|
-
this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));
|
|
112
|
-
return Reflect.get(this.shadowMap, "_lightPositionEC");
|
|
113
|
-
},
|
|
114
|
-
shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness: () => {
|
|
115
|
-
this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));
|
|
116
|
-
const bias = this.shadowMap._pointBias;
|
|
117
|
-
return Cesium.Cartesian4.fromElements(
|
|
118
|
-
bias.normalOffsetScale,
|
|
119
|
-
this.shadowMap._distance,
|
|
120
|
-
this.shadowMap.maximumDistance,
|
|
121
|
-
0.0,
|
|
122
|
-
new Cesium.Cartesian4()
|
|
123
|
-
);
|
|
124
|
-
},
|
|
125
|
-
shadowMap_texelSizeDepthBiasAndNormalShadingSmooth: () => {
|
|
126
|
-
this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));
|
|
127
|
-
const bias = this.shadowMap._pointBias;
|
|
128
|
-
const scratchTexelStepSize = new Cesium.Cartesian2();
|
|
129
|
-
const texelStepSize = scratchTexelStepSize;
|
|
130
|
-
texelStepSize.x = 1.0 / this.shadowMap._textureSize.x;
|
|
131
|
-
texelStepSize.y = 1.0 / this.shadowMap._textureSize.y;
|
|
132
|
-
|
|
133
|
-
return Cesium.Cartesian4.fromElements(
|
|
134
|
-
texelStepSize.x,
|
|
135
|
-
texelStepSize.y,
|
|
136
|
-
bias.depthBias,
|
|
137
|
-
bias.normalShadingSmooth,
|
|
138
|
-
new Cesium.Cartesian4()
|
|
139
|
-
);
|
|
140
|
-
},
|
|
141
|
-
camera_projection_matrix: this.lightCamera.frustum.projectionMatrix,
|
|
142
|
-
camera_view_matrix: this.lightCamera.viewMatrix,
|
|
143
|
-
helsing_viewDistance: () => {
|
|
144
|
-
return this.viewDistance;
|
|
145
|
-
},
|
|
146
|
-
helsing_visibleAreaColor: this.visibleAreaColor,
|
|
147
|
-
helsing_invisibleAreaColor: this.invisibleAreaColor,
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
this.postStage = this.viewer.scene.postProcessStages.add(postStage);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
drawSketch() {
|
|
155
|
-
this.sketch = this.viewer.entities.add({
|
|
156
|
-
name: 'sketch',
|
|
157
|
-
position: this.viewPosition,
|
|
158
|
-
orientation: Cesium.Transforms.headingPitchRollQuaternion(
|
|
159
|
-
this.viewPosition,
|
|
160
|
-
Cesium.HeadingPitchRoll.fromDegrees(this.viewHeading - this.horizontalViewAngle, this.viewPitch, 0.0)
|
|
161
|
-
),
|
|
162
|
-
ellipsoid: {
|
|
163
|
-
radii: new Cesium.Cartesian3(
|
|
164
|
-
this.viewDistance,
|
|
165
|
-
this.viewDistance,
|
|
166
|
-
this.viewDistance
|
|
167
|
-
),
|
|
168
|
-
minimumClock: Cesium.Math.toRadians(-this.horizontalViewAngle / 2),
|
|
169
|
-
maximumClock: Cesium.Math.toRadians(this.horizontalViewAngle / 2),
|
|
170
|
-
minimumCone: Cesium.Math.toRadians(this.verticalViewAngle + 7.75),
|
|
171
|
-
maximumCone: Cesium.Math.toRadians(180 - this.verticalViewAngle - 7.75),
|
|
172
|
-
fill: false,
|
|
173
|
-
outline: true,
|
|
174
|
-
subdivisions: 256,
|
|
175
|
-
stackPartitions: 64,
|
|
176
|
-
slicePartitions: 64,
|
|
177
|
-
outlineColor: Cesium.Color.YELLOWGREEN
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
getHeading(fromPosition, toPosition) {
|
|
183
|
-
let finalPosition = new Cesium.Cartesian3();
|
|
184
|
-
let matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
|
|
185
|
-
Cesium.Matrix4.inverse(matrix4, matrix4);
|
|
186
|
-
Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
|
|
187
|
-
Cesium.Cartesian3.normalize(finalPosition, finalPosition);
|
|
188
|
-
return Cesium.Math.toDegrees(Math.atan2(finalPosition.x, finalPosition.y));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
getPitch(fromPosition, toPosition) {
|
|
192
|
-
let finalPosition = new Cesium.Cartesian3();
|
|
193
|
-
let matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(fromPosition);
|
|
194
|
-
Cesium.Matrix4.inverse(matrix4, matrix4);
|
|
195
|
-
Cesium.Matrix4.multiplyByPoint(matrix4, toPosition, finalPosition);
|
|
196
|
-
Cesium.Cartesian3.normalize(finalPosition, finalPosition);
|
|
197
|
-
return Cesium.Math.toDegrees(Math.asin(finalPosition.z));
|
|
198
|
-
}
|
|
199
|
-
}
|