cesium_dev_kit 1.0.50 → 1.0.51
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/dist/index.js +13582 -68
- package/dist/index.min.js +1 -0
- package/index.js +2 -2
- package/package.json +15 -9
- package/.babelrc +0 -13
- package/dist/ColorDeal.js +0 -59
- package/dist/common.js +0 -40
- package/dist/initConf.js +0 -188
- package/dist/libs/Analysis.js +0 -779
- package/dist/libs/Base.js +0 -950
- package/dist/libs/ChartLayer.js +0 -24
- package/dist/libs/Control.js +0 -947
- package/dist/libs/CustomCesiumPlugin.js +0 -92
- package/dist/libs/DomUtil.js +0 -105
- package/dist/libs/Draw.js +0 -704
- package/dist/libs/Graphics.js +0 -734
- package/dist/libs/MapvLayer.js +0 -26
- package/dist/libs/Material.js +0 -590
- package/dist/libs/Math2d.js +0 -559
- package/dist/libs/Math3d.js +0 -646
- package/dist/libs/PassEffect.js +0 -154
- package/dist/libs/Plugin.js +0 -751
- package/dist/libs/Primitive.js +0 -1559
- package/dist/libs/Shaders.js +0 -298
- package/dist/libs/ThreeJs.js +0 -190
- package/dist/libs/cesium-plugin.js +0 -3387
- package/dist/libs/index.js +0 -117
- package/dist/libs/plot/AttackArrow.js +0 -266
- package/dist/libs/plot/BasePlot.js +0 -41
- package/dist/libs/plot/PincerArrow.js +0 -278
- package/dist/libs/plot/StraightArrow.js +0 -244
- package/dist/libs/plot/algorithm.js +0 -315
- package/dist/libs/plot/index.js +0 -19
- package/dist/libs/plot/plotUtil.js +0 -242
package/dist/libs/Shaders.js
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Shaders = Shaders;
|
|
7
|
-
/**
|
|
8
|
-
* 着色器模块
|
|
9
|
-
* @param {*} viewer
|
|
10
|
-
*/
|
|
11
|
-
function Shaders() {}
|
|
12
|
-
Shaders.prototype = {
|
|
13
|
-
// 流动线
|
|
14
|
-
_getFlowLineShader: function () {
|
|
15
|
-
return 'uniform vec4 color;\n\
|
|
16
|
-
uniform float duration;\n\
|
|
17
|
-
\n\
|
|
18
|
-
czm_material czm_getMaterial(czm_materialInput materialInput){\n\
|
|
19
|
-
czm_material material = czm_getDefaultMaterial(materialInput);\n\
|
|
20
|
-
vec2 st = materialInput.st;\n\
|
|
21
|
-
float t =fract(czm_frameNumber / duration);\n\
|
|
22
|
-
t *= 1.03;\n\
|
|
23
|
-
float alpha = smoothstep(t- 0.03, t, st.s) * step(-t, -st.s);\n\
|
|
24
|
-
alpha += 0.1;\n\
|
|
25
|
-
vec4 fragColor;\n\
|
|
26
|
-
fragColor.rgb = (color.rgb) / 0.5;\n\
|
|
27
|
-
fragColor = czm_gammaCorrect(fragColor);\n\
|
|
28
|
-
material.diffuse = fragColor.rgb;\n\
|
|
29
|
-
material.alpha = alpha;\n\
|
|
30
|
-
material.emission = fragColor.rgb;\n\
|
|
31
|
-
return material;\n\
|
|
32
|
-
}\n\
|
|
33
|
-
';
|
|
34
|
-
},
|
|
35
|
-
// 动态线
|
|
36
|
-
_getDynamicLineShader: function (options) {
|
|
37
|
-
if (options && options.get) {
|
|
38
|
-
return 'czm_material czm_getMaterial(czm_materialInput materialInput)\n\
|
|
39
|
-
{\n\
|
|
40
|
-
czm_material material = czm_getDefaultMaterial(materialInput);\n\
|
|
41
|
-
vec2 st = materialInput.st;\n\
|
|
42
|
-
\n\
|
|
43
|
-
if(texture2D(image, vec2(0.0, 0.0)).a == 1.0){\n\
|
|
44
|
-
discard;\n\
|
|
45
|
-
}else{\n\
|
|
46
|
-
material.alpha = texture2D(image, vec2(1.0 - fract(time - st.s), st.t)).a * color.a;\n\
|
|
47
|
-
}\n\
|
|
48
|
-
\n\
|
|
49
|
-
material.diffuse = max(color.rgb * material.alpha * 3.0, color.rgb);\n\
|
|
50
|
-
\n\
|
|
51
|
-
return material;\n\
|
|
52
|
-
}\n\
|
|
53
|
-
';
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
// 动态泛光线
|
|
57
|
-
_getDynamicLightLineShader: function (options) {
|
|
58
|
-
if (options && options.get) {
|
|
59
|
-
return 'czm_material czm_getMaterial(czm_materialInput materialInput)\n\
|
|
60
|
-
{\n\
|
|
61
|
-
czm_material material = czm_getDefaultMaterial(materialInput);\n\
|
|
62
|
-
vec2 st = materialInput.st;\n\
|
|
63
|
-
\n\
|
|
64
|
-
vec4 colorImage = texture2D(image, vec2(fract(1.0 *st.s - time), fract(st.t)));\n\
|
|
65
|
-
\n\
|
|
66
|
-
vec4 fragColor;\n\
|
|
67
|
-
fragColor.rgb = (colorImage.rgb+color.rgb) / 1.0;\n\
|
|
68
|
-
fragColor = czm_gammaCorrect(fragColor);\n\
|
|
69
|
-
material.diffuse = colorImage.rgb;\n\
|
|
70
|
-
material.alpha = colorImage.a;\n\
|
|
71
|
-
material.emission = fragColor.rgb;\n\
|
|
72
|
-
\n\
|
|
73
|
-
return material;\n\
|
|
74
|
-
}\n\
|
|
75
|
-
';
|
|
76
|
-
// material.diffuse = max(color.rgb * material.alpha * 3.0, color.rgb);\n\
|
|
77
|
-
// material.alpha = texture2D(image, vec2(1.0 - fract(time - st.s), st.t)).a * color.a;\n\
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 带方向的墙体
|
|
83
|
-
* @param {*} options
|
|
84
|
-
*/
|
|
85
|
-
_getDirectionWallShader: function (options) {
|
|
86
|
-
if (options && options.get) {
|
|
87
|
-
var materail = 'czm_material czm_getMaterial(czm_materialInput materialInput)\n\
|
|
88
|
-
{\n\
|
|
89
|
-
czm_material material = czm_getDefaultMaterial(materialInput);\n\
|
|
90
|
-
vec2 st = materialInput.st;\n\
|
|
91
|
-
\n ';
|
|
92
|
-
if (options.freely == 'vertical') {
|
|
93
|
-
//(由下到上)
|
|
94
|
-
|
|
95
|
-
materail += 'vec4 colorImage = texture2D(image, vec2(fract(float(' + options.count + ')*st.t ' + options.direction + ' time), fract(st.s)));\n ';
|
|
96
|
-
} else {
|
|
97
|
-
//(逆时针)
|
|
98
|
-
|
|
99
|
-
materail += 'vec4 colorImage = texture2D(image, vec2(fract(float(' + options.count + ')*st.s ' + options.direction + ' time), fract(st.t)));\n ';
|
|
100
|
-
}
|
|
101
|
-
//泛光
|
|
102
|
-
materail += 'vec4 fragColor;\n\
|
|
103
|
-
fragColor.rgb = (colorImage.rgb+color.rgb) / 1.0;\n\
|
|
104
|
-
fragColor = czm_gammaCorrect(fragColor);\n ';
|
|
105
|
-
materail += ' material.diffuse = colorImage.rgb;\n\
|
|
106
|
-
material.alpha = colorImage.a;\n\
|
|
107
|
-
material.emission = fragColor.rgb;\n\
|
|
108
|
-
\n\
|
|
109
|
-
return material;\n\
|
|
110
|
-
}\n\
|
|
111
|
-
';
|
|
112
|
-
return materail;
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
_getCircleFadeShader: function (options) {
|
|
116
|
-
if (options && options.get) {
|
|
117
|
-
return `czm_material czm_getMaterial(czm_materialInput materialInput)\n
|
|
118
|
-
{\n
|
|
119
|
-
czm_material material = czm_getDefaultMaterial(materialInput);\n
|
|
120
|
-
material.diffuse = 1.5 * color.rgb;\n
|
|
121
|
-
vec2 st = materialInput.st;\n
|
|
122
|
-
float dis = distance(st, vec2(0.5, 0.5));\n
|
|
123
|
-
float per = fract(time);\n
|
|
124
|
-
if(dis > per * 0.5){\n
|
|
125
|
-
//material.alpha = 0.0;\n
|
|
126
|
-
discard;\n
|
|
127
|
-
}else {\n
|
|
128
|
-
material.alpha = color.a * dis / per / 2.0;\n
|
|
129
|
-
}\n
|
|
130
|
-
return material;\n
|
|
131
|
-
}`;
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
// 波动圆
|
|
135
|
-
_getDynamicCircleShader: function (options) {
|
|
136
|
-
if (options && options.get) {
|
|
137
|
-
return 'uniform vec4 color;\n\
|
|
138
|
-
uniform float duration;\n\
|
|
139
|
-
uniform float count;\n\
|
|
140
|
-
uniform float gradient;\n\
|
|
141
|
-
\n\
|
|
142
|
-
czm_material czm_getMaterial(czm_materialInput materialInput)\n\
|
|
143
|
-
{\n\
|
|
144
|
-
czm_material material = czm_getDefaultMaterial(materialInput);\n\
|
|
145
|
-
material.diffuse = 1.5 * color.rgb;\n\
|
|
146
|
-
vec2 st = materialInput.st;\n\
|
|
147
|
-
vec3 str = materialInput.str;\n\
|
|
148
|
-
float dis = distance(st, vec2(0.5, 0.5));\n\
|
|
149
|
-
float per = fract(czm_frameNumber / duration);\n\
|
|
150
|
-
if(abs(str.z) > 0.001){\n\
|
|
151
|
-
discard;\n\
|
|
152
|
-
}\n\
|
|
153
|
-
if(dis > 0.5){\n\
|
|
154
|
-
discard;\n\
|
|
155
|
-
} else {\n\
|
|
156
|
-
float perDis = 0.5 / count;\n\
|
|
157
|
-
float disNum;\n\
|
|
158
|
-
float bl = .0;\n\
|
|
159
|
-
for (int i = 0; i <= 10; i++) {\n\
|
|
160
|
-
if (float(i) <= count) {\n\
|
|
161
|
-
disNum = perDis * float(i) - dis + per / count;\n\
|
|
162
|
-
if (disNum > 0.0) {\n\
|
|
163
|
-
if (disNum < perDis) {\n\
|
|
164
|
-
bl = 1.0 - disNum / perDis;\n\
|
|
165
|
-
} else if (disNum - perDis < perDis) {\n\
|
|
166
|
-
bl = 1.0 - abs(1.0 - disNum / perDis);\n\
|
|
167
|
-
}\n\
|
|
168
|
-
material.alpha = pow(bl, gradient);\n\
|
|
169
|
-
}\n\
|
|
170
|
-
}\n\
|
|
171
|
-
}\n\
|
|
172
|
-
}\n\
|
|
173
|
-
return material;\n\
|
|
174
|
-
}\n\
|
|
175
|
-
';
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
// 雷达扫描
|
|
179
|
-
_getRadarScanShader: function (options) {
|
|
180
|
-
if (options && options.get) {
|
|
181
|
-
return 'uniform sampler2D colorTexture;\n\
|
|
182
|
-
uniform sampler2D depthTexture;\n\
|
|
183
|
-
varying vec2 v_textureCoordinates;\n\
|
|
184
|
-
uniform vec4 u_scanCenterEC;\n\
|
|
185
|
-
uniform vec3 u_scanPlaneNormalEC;\n\
|
|
186
|
-
uniform vec3 u_scanLineNormalEC;\n\
|
|
187
|
-
uniform float u_radius;\n\
|
|
188
|
-
uniform vec4 u_scanColor;\n\
|
|
189
|
-
\n\
|
|
190
|
-
vec4 toEye(in vec2 uv, in float depth){\n\
|
|
191
|
-
vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));\n\
|
|
192
|
-
vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);\n\
|
|
193
|
-
posInCamera =posInCamera / posInCamera.w;\n\
|
|
194
|
-
return posInCamera;\n\
|
|
195
|
-
}\n\
|
|
196
|
-
\n\
|
|
197
|
-
bool isPointOnLineRight(in vec3 ptOnLine, in vec3 lineNormal, in vec3 testPt){\n\
|
|
198
|
-
vec3 v01 = testPt - ptOnLine;\n\
|
|
199
|
-
normalize(v01);\n\
|
|
200
|
-
vec3 temp = cross(v01, lineNormal);\n\
|
|
201
|
-
float d = dot(temp, u_scanPlaneNormalEC);\n\
|
|
202
|
-
return d > 0.5;\n\
|
|
203
|
-
}\n\
|
|
204
|
-
\n\
|
|
205
|
-
vec3 pointProjectOnPlane(in vec3 planeNormal, in vec3 planeOrigin, in vec3 point){\n\
|
|
206
|
-
vec3 v01 = point -planeOrigin;\n\
|
|
207
|
-
float d = dot(planeNormal, v01) ;\n\
|
|
208
|
-
return (point - planeNormal * d);\n\
|
|
209
|
-
}\n\
|
|
210
|
-
\n\
|
|
211
|
-
float distancePointToLine(in vec3 ptOnLine, in vec3 lineNormal, in vec3 testPt){\n\
|
|
212
|
-
vec3 tempPt = pointProjectOnPlane(lineNormal, ptOnLine, testPt);\n\
|
|
213
|
-
return length(tempPt - ptOnLine);\n\
|
|
214
|
-
}\n\
|
|
215
|
-
\n\
|
|
216
|
-
float getDepth(in vec4 depth){\n\
|
|
217
|
-
float z_window = czm_unpackDepth(depth);\n\
|
|
218
|
-
z_window = czm_reverseLogDepth(z_window);\n\
|
|
219
|
-
float n_range = czm_depthRange.near;\n\
|
|
220
|
-
float f_range = czm_depthRange.far;\n\
|
|
221
|
-
return (2.0 * z_window - n_range - f_range) / (f_range - n_range);\n\
|
|
222
|
-
}\n\
|
|
223
|
-
\n\
|
|
224
|
-
void main(){\n\
|
|
225
|
-
gl_FragColor = texture2D(colorTexture, v_textureCoordinates);\n\
|
|
226
|
-
float depth = getDepth( texture2D(depthTexture, v_textureCoordinates));\n\
|
|
227
|
-
vec4 viewPos = toEye(v_textureCoordinates, depth);\n\
|
|
228
|
-
vec3 prjOnPlane = pointProjectOnPlane(u_scanPlaneNormalEC.xyz, u_scanCenterEC.xyz, viewPos.xyz);\n\
|
|
229
|
-
float dis = length(prjOnPlane.xyz - u_scanCenterEC.xyz);\n\
|
|
230
|
-
float twou_radius = u_radius * 2.0;\n\
|
|
231
|
-
if(dis < u_radius){\n\
|
|
232
|
-
float f0 = 1.0 -abs(u_radius - dis) / u_radius;\n\
|
|
233
|
-
f0 = pow(f0, 64.0);\n\
|
|
234
|
-
vec3 lineEndPt = vec3(u_scanCenterEC.xyz) + u_scanLineNormalEC * u_radius;\n\
|
|
235
|
-
float f = 0.0;\n\
|
|
236
|
-
if(isPointOnLineRight(u_scanCenterEC.xyz, u_scanLineNormalEC.xyz, prjOnPlane.xyz)){\n\
|
|
237
|
-
float dis1= length(prjOnPlane.xyz - lineEndPt);\n\
|
|
238
|
-
f = abs(twou_radius -dis1) / twou_radius;\n\
|
|
239
|
-
f = pow(f, float(' + options.width + '));\n\
|
|
240
|
-
}\n\
|
|
241
|
-
if(float(' + options.border + ') > 0.0){\n\
|
|
242
|
-
gl_FragColor = mix(gl_FragColor, u_scanColor, f + f0);\n\
|
|
243
|
-
} else {\n\
|
|
244
|
-
gl_FragColor = mix(gl_FragColor, u_scanColor, f);\n\
|
|
245
|
-
}\n\
|
|
246
|
-
}\n\
|
|
247
|
-
}\n\
|
|
248
|
-
';
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
// 圆形扫描
|
|
252
|
-
_getCircleScanShader: function (options) {
|
|
253
|
-
if (options && options.get) {
|
|
254
|
-
return 'uniform sampler2D colorTexture;\n\
|
|
255
|
-
uniform sampler2D depthTexture;\n\
|
|
256
|
-
varying vec2 v_textureCoordinates;\n\
|
|
257
|
-
uniform vec4 u_scanCenterEC;\n\
|
|
258
|
-
uniform vec3 u_scanPlaneNormalEC;\n\
|
|
259
|
-
uniform float u_radius;\n\
|
|
260
|
-
uniform vec4 u_scanColor;\n\
|
|
261
|
-
\n\
|
|
262
|
-
vec4 toEye(in vec2 uv, in float depth){\n\
|
|
263
|
-
vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));\n\
|
|
264
|
-
vec4 posInCamera = czm_inverseProjection * vec4(xy, depth, 1.0);\n\
|
|
265
|
-
posInCamera =posInCamera / posInCamera.w;\n\
|
|
266
|
-
return posInCamera;\n\
|
|
267
|
-
}\n\
|
|
268
|
-
\n\
|
|
269
|
-
vec3 pointProjectOnPlane(in vec3 planeNormal, in vec3 planeOrigin, in vec3 point){\n\
|
|
270
|
-
vec3 v01 = point - planeOrigin;\n\
|
|
271
|
-
float d = dot(planeNormal, v01) ;\n\
|
|
272
|
-
return (point - planeNormal * d);\n\
|
|
273
|
-
}\n\
|
|
274
|
-
\n\
|
|
275
|
-
float getDepth(in vec4 depth){\n\
|
|
276
|
-
float z_window = czm_unpackDepth(depth);\n\
|
|
277
|
-
z_window = czm_reverseLogDepth(z_window);\n\
|
|
278
|
-
float n_range = czm_depthRange.near;\n\
|
|
279
|
-
float f_range = czm_depthRange.far;\n\
|
|
280
|
-
return (2.0 * z_window - n_range - f_range) / (f_range - n_range);\n\
|
|
281
|
-
}\n\
|
|
282
|
-
\n\
|
|
283
|
-
void main(){\n\
|
|
284
|
-
gl_FragColor = texture2D(colorTexture, v_textureCoordinates);\n\
|
|
285
|
-
float depth = getDepth(texture2D(depthTexture, v_textureCoordinates));\n\
|
|
286
|
-
vec4 viewPos = toEye(v_textureCoordinates, depth);\n\
|
|
287
|
-
vec3 prjOnPlane = pointProjectOnPlane(u_scanPlaneNormalEC.xyz, u_scanCenterEC.xyz, viewPos.xyz);\n\
|
|
288
|
-
float dis = length(prjOnPlane.xyz - u_scanCenterEC.xyz);\n\
|
|
289
|
-
if(dis < u_radius){\n\
|
|
290
|
-
float f = 1.0 - abs(u_radius - dis) / u_radius;\n\
|
|
291
|
-
f = pow(f, float(' + options.border + '));\n\
|
|
292
|
-
gl_FragColor = mix(gl_FragColor, u_scanColor, f);\n\
|
|
293
|
-
}\n\
|
|
294
|
-
}\n\
|
|
295
|
-
';
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
};
|
package/dist/libs/ThreeJs.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 基于three的融合
|
|
5
|
-
*
|
|
6
|
-
* cesium 需要关闭自带的循环渲染
|
|
7
|
-
* useDefaultRenderLoop: false
|
|
8
|
-
* @param {*} viewer
|
|
9
|
-
*/
|
|
10
|
-
function ThreeJs(viewer) {
|
|
11
|
-
if (viewer) {
|
|
12
|
-
this._initContainer();
|
|
13
|
-
this._initThree();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
ThreeJs.prototype = {
|
|
17
|
-
/**
|
|
18
|
-
* 初始化容器
|
|
19
|
-
*/
|
|
20
|
-
_initContainer: function () {
|
|
21
|
-
this.cesiumContainer = undefined;
|
|
22
|
-
this.threeContainer = undefined;
|
|
23
|
-
this.cesiumContainer = document.getElementById('cesiumContainer');
|
|
24
|
-
this.threeContainer = document.getElementById('threeContainer');
|
|
25
|
-
|
|
26
|
-
//元素都已经创建默认集成
|
|
27
|
-
if (this.cesiumContainer && this.threeContainer) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (!this.cesiumContainer) {
|
|
31
|
-
alert('未获取到 cesiumContainer 容器!');
|
|
32
|
-
return false;
|
|
33
|
-
} else {
|
|
34
|
-
//是否符合
|
|
35
|
-
if (this.cesiumContainer.style.position !== 'absolute') {
|
|
36
|
-
// 重写样式
|
|
37
|
-
this.cesiumContainer.style.position = 'absolute';
|
|
38
|
-
this.cesiumContainer.style.top = 0;
|
|
39
|
-
this.cesiumContainer.style.left = 0;
|
|
40
|
-
this.cesiumContainer.style.height = '100%';
|
|
41
|
-
this.cesiumContainer.style.width = '100%';
|
|
42
|
-
this.cesiumContainer.style.margin = 0;
|
|
43
|
-
this.cesiumContainer.style.overflow = 'hidden';
|
|
44
|
-
this.cesiumContainer.style.padding = 0;
|
|
45
|
-
this.cesiumContainer.style.fontFamily = 'sans-serif';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
//no create
|
|
49
|
-
if (!this.threeContainer) {
|
|
50
|
-
var body = document.getElementsByTagName('body')[0];
|
|
51
|
-
if (body) {
|
|
52
|
-
this.threeContainer = document.createElement('div');
|
|
53
|
-
this.threeContainer.id = 'threeContainer';
|
|
54
|
-
this.threeContainer.style.position = 'absolute';
|
|
55
|
-
this.threeContainer.style.top = 0;
|
|
56
|
-
this.threeContainer.style.left = 0;
|
|
57
|
-
this.threeContainer.style.height = '100%';
|
|
58
|
-
this.threeContainer.style.width = '100%';
|
|
59
|
-
this.threeContainer.style.margin = 0;
|
|
60
|
-
this.threeContainer.style.overflow = 'hidden';
|
|
61
|
-
this.threeContainer.style.padding = 0;
|
|
62
|
-
this.threeContainer.style.fontFamily = 'sans-serif';
|
|
63
|
-
this.threeContainer.style.pointerEvents = 'none';
|
|
64
|
-
body.appendChild(this.threeContainer);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
/**
|
|
69
|
-
* 初始化three
|
|
70
|
-
*/
|
|
71
|
-
_initThree: function () {
|
|
72
|
-
var fov = 45,
|
|
73
|
-
width = window.innerWidth,
|
|
74
|
-
height = window.innerHeight,
|
|
75
|
-
aspect = width / height,
|
|
76
|
-
near = 1,
|
|
77
|
-
far = 10 * 1000 * 1000;
|
|
78
|
-
this._three = {
|
|
79
|
-
renderer: null,
|
|
80
|
-
camera: null,
|
|
81
|
-
scene: null
|
|
82
|
-
};
|
|
83
|
-
this._three.scene = new THREE.Scene();
|
|
84
|
-
this._three.camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
|
|
85
|
-
this._three.renderer = new THREE.WebGLRenderer({
|
|
86
|
-
alpha: true
|
|
87
|
-
});
|
|
88
|
-
if (this.threeContainer) {
|
|
89
|
-
this.threeContainer.appendChild(this._three.renderer.domElement);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
/**
|
|
93
|
-
* threeObjects 对象
|
|
94
|
-
*
|
|
95
|
-
* 用于实例化到cesium球上
|
|
96
|
-
*/
|
|
97
|
-
createThreeObject: function () {
|
|
98
|
-
function _3DObject() {
|
|
99
|
-
this.threeMesh = null;
|
|
100
|
-
this.minWGS84 = null;
|
|
101
|
-
this.maxWGS84 = null;
|
|
102
|
-
}
|
|
103
|
-
return new _3DObject();
|
|
104
|
-
},
|
|
105
|
-
/**
|
|
106
|
-
* 添加three obj对象
|
|
107
|
-
*/
|
|
108
|
-
addThreeObjects: function (objects) {
|
|
109
|
-
if (objects && objects.length > 0) {
|
|
110
|
-
this._3Dobjects = objects;
|
|
111
|
-
//注册
|
|
112
|
-
this._renderCesium();
|
|
113
|
-
this._renderThreeObj();
|
|
114
|
-
this._loop();
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
/**
|
|
118
|
-
* 开始渲染cesium和three
|
|
119
|
-
*/
|
|
120
|
-
_loop: function () {
|
|
121
|
-
window.loop = function () {
|
|
122
|
-
//循环渲染
|
|
123
|
-
requestAnimationFrame(window.loop);
|
|
124
|
-
//渲染cesium
|
|
125
|
-
window.renderCesium();
|
|
126
|
-
//渲染three
|
|
127
|
-
window.renderThreeObj();
|
|
128
|
-
};
|
|
129
|
-
window.loop();
|
|
130
|
-
},
|
|
131
|
-
/**
|
|
132
|
-
* 渲染cesium
|
|
133
|
-
*/
|
|
134
|
-
_renderCesium: function () {
|
|
135
|
-
var $this = this;
|
|
136
|
-
window.renderCesium = function () {
|
|
137
|
-
$this._viewer && $this._viewer.render();
|
|
138
|
-
};
|
|
139
|
-
},
|
|
140
|
-
/**
|
|
141
|
-
* 渲染three
|
|
142
|
-
*/
|
|
143
|
-
_renderThreeObj: function () {
|
|
144
|
-
var $this = this;
|
|
145
|
-
window.renderThreeObj = function () {
|
|
146
|
-
var cartToVec = function (cart) {
|
|
147
|
-
return new THREE.Vector3(cart.x, cart.y, cart.z);
|
|
148
|
-
};
|
|
149
|
-
if ($this._three && $this._viewer && $this._3Dobjects) {
|
|
150
|
-
//同步相机事件
|
|
151
|
-
$this._three.camera.fov = Cesium.Math.toDegrees($this._viewer.camera.frustum.fovy);
|
|
152
|
-
$this._three.camera.updateProjectionMatrix();
|
|
153
|
-
|
|
154
|
-
// 同步位置 Configure Three.js meshes to stand against globe center position up direction
|
|
155
|
-
for (var id in $this._3Dobjects) {
|
|
156
|
-
var minWGS84 = $this._3Dobjects[id].minWGS84,
|
|
157
|
-
maxWGS84 = $this._3Dobjects[id].maxWGS84,
|
|
158
|
-
// convert lat/long center position to Cartesian3
|
|
159
|
-
center = Cesium.Cartesian3.fromDegrees((minWGS84[0] + maxWGS84[0]) / 2, (minWGS84[1] + maxWGS84[1]) / 2),
|
|
160
|
-
// get forward direction for orienting model
|
|
161
|
-
centerHigh = Cesium.Cartesian3.fromDegrees((minWGS84[0] + maxWGS84[0]) / 2, (minWGS84[1] + maxWGS84[1]) / 2, 1);
|
|
162
|
-
// use direction from bottom left to top left as up-vector
|
|
163
|
-
var bottomLeft = cartToVec(Cesium.Cartesian3.fromDegrees(minWGS84[0], minWGS84[1]));
|
|
164
|
-
var topLeft = cartToVec(Cesium.Cartesian3.fromDegrees(minWGS84[0], maxWGS84[1]));
|
|
165
|
-
var latDir = new THREE.Vector3().subVectors(bottomLeft, topLeft).normalize();
|
|
166
|
-
// configure entity position and orientation
|
|
167
|
-
$this._3Dobjects[id].threeMesh.position.copy(center);
|
|
168
|
-
$this._3Dobjects[id].threeMesh.lookAt(centerHigh);
|
|
169
|
-
$this._3Dobjects[id].threeMesh.up.copy(latDir);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Clone Cesium Camera projection position so the
|
|
173
|
-
// Three.js Object will appear to be at the same place as above the Cesium Globe
|
|
174
|
-
$this._three.camera.matrixAutoUpdate = false;
|
|
175
|
-
var cvm = $this._viewer.camera.viewMatrix,
|
|
176
|
-
civm = $this._viewer.camera.inverseViewMatrix;
|
|
177
|
-
$this._three.camera.matrixWorld.set(civm[0], civm[4], civm[8], civm[12], civm[1], civm[5], civm[9], civm[13], civm[2], civm[6], civm[10], civm[14], civm[3], civm[7], civm[11], civm[15]);
|
|
178
|
-
$this._three.camera.matrixWorldInverse.set(cvm[0], cvm[4], cvm[8], cvm[12], cvm[1], cvm[5], cvm[9], cvm[13], cvm[2], cvm[6], cvm[10], cvm[14], cvm[3], cvm[7], cvm[11], cvm[15]);
|
|
179
|
-
$this._three.camera.lookAt(new THREE.Vector3(0, 0, 0));
|
|
180
|
-
var width = $this.threeContainer.clientWidth,
|
|
181
|
-
height = $this.threeContainer.clientHeight,
|
|
182
|
-
aspect = width / height;
|
|
183
|
-
$this._three.camera.aspect = aspect;
|
|
184
|
-
$this._three.camera.updateProjectionMatrix();
|
|
185
|
-
$this._three.renderer.setSize(width, height);
|
|
186
|
-
$this._three.renderer.render($this._three.scene, $this._three.camera);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
};
|