easy-three-utils 0.0.331 → 0.0.333
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/cameraRecord.ts +187 -0
- package/cesium/glsl/viewable.ts +122 -0
- package/cesium/glsl/weather.ts +78 -0
- package/cesium/index.ts +188 -0
- package/cesium/js/lib/CreatePolygonOnGround.js +191 -0
- package/cesium/js/lib/ReminderTip.js +71 -0
- package/cesium/js/measure.js +753 -0
- package/cesium/js/measure1.ts +194 -0
- package/cesium/js/slope.js +379 -0
- package/cesium/utils/index.ts +20 -0
- package/cesium/utils/useClipping.ts +90 -0
- package/cesium/utils/useCustomCollection.ts +50 -0
- package/cesium/utils/useDrawPolygon.ts +118 -0
- package/cesium/utils/useMeasure.ts +152 -0
- package/cesium/utils/useViewShed.ts +199 -0
- package/cesium/utils/useWeather.ts +127 -0
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as Cesium from 'cesium'
|
|
2
|
+
|
|
3
|
+
const useDrawPolygon = (viewer: Cesium.Viewer, options: {
|
|
4
|
+
nodeCollection: Cesium.CustomDataSource
|
|
5
|
+
polygonCollection: Cesium.CustomDataSource
|
|
6
|
+
}) => {
|
|
7
|
+
|
|
8
|
+
const addHandler: Cesium.ScreenSpaceEventHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
|
|
9
|
+
const finHandler: Cesium.ScreenSpaceEventHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
|
|
10
|
+
const moveHandler: Cesium.ScreenSpaceEventHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
|
|
11
|
+
let pointPosData: Cesium.Cartesian3[][] = []
|
|
12
|
+
|
|
13
|
+
const start = () => {
|
|
14
|
+
|
|
15
|
+
const points: Cesium.Cartesian3[] = []
|
|
16
|
+
|
|
17
|
+
addHandler.setInputAction((event => {
|
|
18
|
+
const ray = viewer.camera.getPickRay(event.position)
|
|
19
|
+
const cartesian = viewer.scene.globe.pick(ray!, viewer.scene)
|
|
20
|
+
|
|
21
|
+
if (Cesium.defined(cartesian)) {
|
|
22
|
+
options.nodeCollection.entities.add(createNodePoint(cartesian))
|
|
23
|
+
if (points.length === 0) {
|
|
24
|
+
points.push(cartesian)
|
|
25
|
+
}
|
|
26
|
+
if (points.length === 2) {
|
|
27
|
+
const dynamicPositions = new Cesium.CallbackProperty(() => new Cesium.PolygonHierarchy(points), false)
|
|
28
|
+
options.polygonCollection.entities.add(createNormalPolygon(dynamicPositions))
|
|
29
|
+
}
|
|
30
|
+
points.push(cartesian)
|
|
31
|
+
}
|
|
32
|
+
}) as Cesium.ScreenSpaceEventHandler.PositionedEventCallback, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
|
33
|
+
|
|
34
|
+
moveHandler.setInputAction((event => {
|
|
35
|
+
const ray = viewer.camera.getPickRay(event.endPosition)
|
|
36
|
+
const cartesian = viewer.scene.globe.pick(ray!, viewer.scene)
|
|
37
|
+
if (Cesium.defined(cartesian) && points.length > 0) {
|
|
38
|
+
points.pop()
|
|
39
|
+
points.push(cartesian)
|
|
40
|
+
}
|
|
41
|
+
}) as Cesium.ScreenSpaceEventHandler.MotionEventCallback, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
|
|
42
|
+
|
|
43
|
+
finHandler.setInputAction(() => {
|
|
44
|
+
if (points.length < 2) {
|
|
45
|
+
alert('请至少选3个点')
|
|
46
|
+
} else if (points.length < 3) {
|
|
47
|
+
alert('请至少选3个点')
|
|
48
|
+
options.nodeCollection.entities.remove(options.nodeCollection.entities.values[options.nodeCollection.entities.values.length - 1])
|
|
49
|
+
options.polygonCollection.entities.remove(options.polygonCollection.entities.values[options.polygonCollection.entities.values.length - 1])
|
|
50
|
+
} else if (points.length < 4) {
|
|
51
|
+
alert('请至少选3个点')
|
|
52
|
+
options.nodeCollection.entities.remove(options.nodeCollection.entities.values[options.nodeCollection.entities.values.length - 1])
|
|
53
|
+
options.nodeCollection.entities.remove(options.nodeCollection.entities.values[options.nodeCollection.entities.values.length - 1])
|
|
54
|
+
options.polygonCollection.entities.remove(options.polygonCollection.entities.values[options.polygonCollection.entities.values.length - 1])
|
|
55
|
+
options.polygonCollection.entities.remove(options.polygonCollection.entities.values[options.polygonCollection.entities.values.length - 1])
|
|
56
|
+
}
|
|
57
|
+
points.pop()
|
|
58
|
+
|
|
59
|
+
stop()
|
|
60
|
+
start()
|
|
61
|
+
|
|
62
|
+
pointPosData.push(points)
|
|
63
|
+
|
|
64
|
+
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const stop = () => {
|
|
68
|
+
addHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
|
69
|
+
moveHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)
|
|
70
|
+
finHandler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const createNodePoint = (cartesian: Cesium.Cartesian3) => {
|
|
74
|
+
return new Cesium.Entity({
|
|
75
|
+
position: cartesian,
|
|
76
|
+
point: {
|
|
77
|
+
pixelSize: 8,
|
|
78
|
+
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
|
79
|
+
color: Cesium.Color.fromCssColorString("rgb(51, 153, 255)"),
|
|
80
|
+
disableDepthTestDistance: Number.POSITIVE_INFINITY
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const createNormalPolygon = (hierarchy: Cesium.CallbackProperty) => {
|
|
86
|
+
return new Cesium.Entity({
|
|
87
|
+
polygon: {
|
|
88
|
+
hierarchy,
|
|
89
|
+
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
|
90
|
+
material: new Cesium.ColorMaterialProperty(
|
|
91
|
+
Cesium.Color.fromCssColorString("rgba(51, 153, 255,.4)")
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const destroy = () => {
|
|
98
|
+
pointPosData = []
|
|
99
|
+
stop()
|
|
100
|
+
options.nodeCollection.entities.removeAll()
|
|
101
|
+
options.polygonCollection.entities.removeAll()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const getPointPositionData = () => {
|
|
105
|
+
return pointPosData
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
start,
|
|
110
|
+
stop,
|
|
111
|
+
destroy,
|
|
112
|
+
getPointPositionData
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
useDrawPolygon
|
|
118
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import * as Cesium from 'cesium'
|
|
2
|
+
|
|
3
|
+
const useMeasure = (viewer: Cesium.Viewer) => {
|
|
4
|
+
|
|
5
|
+
const angleMeasurement = () => {
|
|
6
|
+
let anglePoints = []
|
|
7
|
+
let angleEntities = []
|
|
8
|
+
let angleLines = []
|
|
9
|
+
let angleLabels = []
|
|
10
|
+
let angleMeasurementHandler = null
|
|
11
|
+
|
|
12
|
+
const draw = () => {
|
|
13
|
+
if (angleMeasurementHandler) {
|
|
14
|
+
angleMeasurementHandler.destroy()
|
|
15
|
+
angleMeasurementHandler = null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
angleMeasurementHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
|
19
|
+
|
|
20
|
+
angleMeasurementHandler.setInputAction((movement) => {
|
|
21
|
+
const ray = viewer.camera.getPickRay(movement.position);
|
|
22
|
+
const cartesian = viewer.scene.globe.pick(ray, viewer.scene);
|
|
23
|
+
|
|
24
|
+
if (cartesian) {
|
|
25
|
+
anglePoints.push(cartesian);
|
|
26
|
+
|
|
27
|
+
const pointEntity = viewer.entities.add({
|
|
28
|
+
position: cartesian,
|
|
29
|
+
point: {
|
|
30
|
+
color: Cesium.Color.fromCssColorString("rgb(249, 157, 11)"),
|
|
31
|
+
outlineColor: Cesium.Color.WHITE,
|
|
32
|
+
outlineWidth: 2,
|
|
33
|
+
pixelSize: 10,
|
|
34
|
+
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
angleEntities.push(pointEntity)
|
|
38
|
+
|
|
39
|
+
if (anglePoints.length >= 2) {
|
|
40
|
+
const lineEntity = viewer.entities.add({
|
|
41
|
+
polyline: {
|
|
42
|
+
positions: [anglePoints[anglePoints.length - 2], anglePoints[anglePoints.length - 1]],
|
|
43
|
+
width: 2,
|
|
44
|
+
material: Cesium.Color.fromCssColorString("rgb(249, 157, 11)"),
|
|
45
|
+
clampToGround: true
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
angleLines.push(lineEntity)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (anglePoints.length === 3) {
|
|
52
|
+
calculateAndDisplayAngle()
|
|
53
|
+
anglePoints = []
|
|
54
|
+
draw()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
|
58
|
+
|
|
59
|
+
angleMeasurementHandler.setInputAction(function (movement) {
|
|
60
|
+
if (anglePoints.length > 0 && anglePoints.length < 3) {
|
|
61
|
+
const ray = viewer.camera.getPickRay(movement.endPosition)
|
|
62
|
+
const cartesian = viewer.scene.globe.pick(ray, viewer.scene)
|
|
63
|
+
|
|
64
|
+
if (cartesian) {
|
|
65
|
+
if (angleLines.length < anglePoints.length) {
|
|
66
|
+
const lineEntity = viewer.entities.add({
|
|
67
|
+
polyline: {
|
|
68
|
+
positions: [anglePoints[anglePoints.length - 1], cartesian],
|
|
69
|
+
width: 2,
|
|
70
|
+
material: Cesium.Color.fromCssColorString("rgb(249, 157, 11)"),
|
|
71
|
+
clampToGround: true
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
angleLines.push(lineEntity)
|
|
75
|
+
} else {
|
|
76
|
+
const line = angleLines[angleLines.length - 1]
|
|
77
|
+
line.polyline.positions = [anglePoints[anglePoints.length - 1], cartesian]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const calculateAndDisplayAngle = () => {
|
|
85
|
+
const p1 = anglePoints[0]
|
|
86
|
+
const p2 = anglePoints[1]
|
|
87
|
+
const p3 = anglePoints[2]
|
|
88
|
+
|
|
89
|
+
const v1 = Cesium.Cartesian3.subtract(p1, p2, new Cesium.Cartesian3())
|
|
90
|
+
const v2 = Cesium.Cartesian3.subtract(p3, p2, new Cesium.Cartesian3())
|
|
91
|
+
|
|
92
|
+
Cesium.Cartesian3.normalize(v1, v1)
|
|
93
|
+
Cesium.Cartesian3.normalize(v2, v2)
|
|
94
|
+
|
|
95
|
+
const dot = Cesium.Cartesian3.dot(v1, v2)
|
|
96
|
+
|
|
97
|
+
let angleRad = Math.acos(dot)
|
|
98
|
+
|
|
99
|
+
let angleDeg = Cesium.Math.toDegrees(angleRad)
|
|
100
|
+
|
|
101
|
+
const angleLabel = viewer.entities.add({
|
|
102
|
+
position: p2,
|
|
103
|
+
label: {
|
|
104
|
+
text: angleDeg.toFixed(2) + '°',
|
|
105
|
+
font: 'normal 22px MicroSoft YaHei',
|
|
106
|
+
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
107
|
+
fillColor: Cesium.Color.WHITE,
|
|
108
|
+
verticalOrigin: Cesium.VerticalOrigin.CENTER,
|
|
109
|
+
pixelOffset: new Cesium.Cartesian2(20, 0),
|
|
110
|
+
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
angleLabels.push(angleLabel)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const resetAngleMeasurement = () => {
|
|
117
|
+
if (angleMeasurementHandler) {
|
|
118
|
+
angleMeasurementHandler.destroy()
|
|
119
|
+
angleMeasurementHandler = null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
anglePoints = []
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const clear = () => {
|
|
126
|
+
resetAngleMeasurement()
|
|
127
|
+
|
|
128
|
+
angleEntities.forEach(entity => viewer.entities.remove(entity))
|
|
129
|
+
angleLines.forEach(entity => viewer.entities.remove(entity))
|
|
130
|
+
angleLabels.forEach(entity => viewer.entities.remove(entity))
|
|
131
|
+
|
|
132
|
+
angleEntities = []
|
|
133
|
+
angleLines = []
|
|
134
|
+
angleLabels = []
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
draw,
|
|
139
|
+
clear
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const angle = angleMeasurement()
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
angle
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
useMeasure
|
|
152
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as Cesium from 'cesium'
|
|
2
|
+
import { rainShader, snowShader, fogShader } from '../glsl/weather'
|
|
3
|
+
|
|
4
|
+
enum EWeatherType {
|
|
5
|
+
RAIN = 'rain',
|
|
6
|
+
SNOW = 'snow',
|
|
7
|
+
FOG = 'fog',
|
|
8
|
+
CLEAR = 'clear'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const useWeather = (viewer: Cesium.Viewer) => {
|
|
12
|
+
|
|
13
|
+
let stage: Cesium.PostProcessStage;
|
|
14
|
+
|
|
15
|
+
const rain = (options: {
|
|
16
|
+
tiltAngle: number;
|
|
17
|
+
rainSize: number;
|
|
18
|
+
rainSpeed: number;
|
|
19
|
+
} = {
|
|
20
|
+
tiltAngle: -.6,
|
|
21
|
+
rainSize: 0.6,
|
|
22
|
+
rainSpeed: 120.0
|
|
23
|
+
}) => {
|
|
24
|
+
|
|
25
|
+
if (stage) {
|
|
26
|
+
viewer.scene.postProcessStages.remove(stage);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const tiltAngle = Cesium.defaultValue(options.tiltAngle, -.6);
|
|
30
|
+
const rainSize = Cesium.defaultValue(options.rainSize, 0.3);
|
|
31
|
+
const rainSpeed = Cesium.defaultValue(options.rainSpeed, 60.0);
|
|
32
|
+
|
|
33
|
+
stage = new Cesium.PostProcessStage({
|
|
34
|
+
name: 'rain',
|
|
35
|
+
fragmentShader: rainShader,
|
|
36
|
+
uniforms: {
|
|
37
|
+
tiltAngle: () => {
|
|
38
|
+
return tiltAngle;
|
|
39
|
+
},
|
|
40
|
+
rainSize: () => {
|
|
41
|
+
return rainSize;
|
|
42
|
+
},
|
|
43
|
+
rainSpeed: () => {
|
|
44
|
+
return rainSpeed;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
viewer.scene.postProcessStages.add(stage);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const snow = (options: {
|
|
52
|
+
snowSize: number;
|
|
53
|
+
snowSpeed: number;
|
|
54
|
+
} = {
|
|
55
|
+
snowSize: 0.02,
|
|
56
|
+
snowSpeed: 60.0
|
|
57
|
+
}) => {
|
|
58
|
+
|
|
59
|
+
if (stage) {
|
|
60
|
+
viewer.scene.postProcessStages.remove(stage);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const snowSize = Cesium.defaultValue(options.snowSize, 0.02)
|
|
64
|
+
const snowSpeed = Cesium.defaultValue(options.snowSpeed, 60.0)
|
|
65
|
+
|
|
66
|
+
stage = new Cesium.PostProcessStage({
|
|
67
|
+
name: 'snow',
|
|
68
|
+
fragmentShader: snowShader,
|
|
69
|
+
uniforms: {
|
|
70
|
+
snowSize: () => {
|
|
71
|
+
return snowSize;
|
|
72
|
+
},
|
|
73
|
+
snowSpeed: () => {
|
|
74
|
+
return snowSpeed;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
viewer.scene.postProcessStages.add(stage);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const fog = (options: {
|
|
82
|
+
visibility: number;
|
|
83
|
+
color: Cesium.Color;
|
|
84
|
+
} = {
|
|
85
|
+
visibility: 0.2,
|
|
86
|
+
color: new Cesium.Color(0.8, 0.8, 0.8, 0.3)
|
|
87
|
+
}) => {
|
|
88
|
+
|
|
89
|
+
if (stage) {
|
|
90
|
+
viewer.scene.postProcessStages.remove(stage);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const visibility = Cesium.defaultValue(options.visibility, 0.1);
|
|
94
|
+
const color = Cesium.defaultValue(options.color, new Cesium.Color(0.8, 0.8, 0.8, 0.5));
|
|
95
|
+
|
|
96
|
+
stage = new Cesium.PostProcessStage({
|
|
97
|
+
name: 'fog',
|
|
98
|
+
fragmentShader: fogShader,
|
|
99
|
+
uniforms: {
|
|
100
|
+
visibility: () => {
|
|
101
|
+
return visibility;
|
|
102
|
+
},
|
|
103
|
+
fogColor: () => {
|
|
104
|
+
return color;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
viewer.scene.postProcessStages.add(stage);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const clear = () => {
|
|
112
|
+
viewer.scene.postProcessStages.remove(stage);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
rain,
|
|
117
|
+
snow,
|
|
118
|
+
fog,
|
|
119
|
+
clear
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
useWeather,
|
|
125
|
+
|
|
126
|
+
EWeatherType
|
|
127
|
+
}
|