// 创建相机
createLightCamera () {
this.lightCamera = new Cesium.Camera(this.viewer.scene);
this.lightCamera.position = this.viewPosition;
// if (this.viewPositionEnd) {
// let direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(this.viewPositionEnd, this.viewPosition, new Cesium.Cartesian3()), new Cesium.Cartesian3());
// this.lightCamera.direction = direction; // direction是相机面向的方向
// }
this.lightCamera.frustum.near = this.viewDistance * 0.00001;
this.lightCamera.frustum.far = this.viewDistance;
const hr = Cesium.Math.toRadians(this.horizontalViewAngle);
const vr = Cesium.Math.toRadians(this.verticalViewAngle);
// 视锥的宽度与高度的纵横比
const aspectRatio =
(this.viewDistance * Math.tan(hr / 2) * 2) /
(this.viewDistance * Math.tan(vr / 2) * 2);
this.lightCamera.frustum.aspectRatio = aspectRatio;
if (hr > vr) {
this.lightCamera.frustum.fov = hr;
} else {
this.lightCamera.frustum.fov = vr;
}
this.lightCamera.setView({
destination: this.viewPosition,
orientation: {
heading: Cesium.Math.toRadians(this.viewHeading || 0),
pitch: Cesium.Math.toRadians(this.viewPitch || 0),
roll: 0
}
});
}
// 创建阴影贴图
createShadowMap () {
this.shadowMap = new Cesium.ShadowMap({
context: (this.viewer.scene).context,
lightCamera: this.lightCamera,
enabled: this.enabled,
isPointLight: true,
pointLightRadius: this.viewDistance,
cascadesEnabled: false,
size: this.size,
softShadows: true,
normalOffset: false,
fromLightSource: false
});
this.viewer.scene.shadowMap = this.shadowMap
this.viewer.scene.globe.shadows = Cesium.ShadowMode.ENABLED
this.viewer.scene.globe.depthTestAgainstTerrain = true
}
// 创建视网椎体
drawWedge () {
this.Wedge = this.viewer.entities.add({
name: “Wedge”,
position: this.viewPosition,
orientation: new Cesium.CallbackProperty(() => {
return Cesium.Transforms.headingPitchRollQuaternion(
this.viewPosition,
Cesium.HeadingPitchRoll.fromDegrees(this.viewHeading - this.horizontalViewAngle, this.viewPitch, 0.5)
)
}, false),
ellipsoid: {
radii: new Cesium.CallbackProperty(() => {
return new Cesium.Cartesian3(this.viewDistance,
this.viewDistance,
this.viewDistance)
}, false),
// new Cesium.Cartesian3(this.viewDistance,
// this.viewDistance,
// this.viewDistance),
innerRadii: new Cesium.Cartesian3(1.0, 1.0, 1.0),
minimumClock: Cesium.Math.toRadians(-this.horizontalViewAngle / 2),
maximumClock: Cesium.Math.toRadians(this.horizontalViewAngle / 2),
minimumCone: Cesium.Math.toRadians(this.verticalViewAngle + 7.75),
maximumCone: Cesium.Math.toRadians(180 - this.verticalViewAngle - 7.75),
material: Cesium.Color.DARKCYAN.withAlpha(0.3),
outline: true,
outlineColor: Cesium.Color.YELLOWGREEN
},
});
this.sketch = this.viewer.entities.add({
name: “sketch”,
position: this.viewPosition,
orientation: new Cesium.CallbackProperty(() => {
return Cesium.Transforms.headingPitchRollQuaternion(
this.viewPosition,
Cesium.HeadingPitchRoll.fromDegrees(this.viewHeading - this.horizontalViewAngle, this.viewPitch, 0.0)
)
}, false),
ellipsoid: {
radii: new Cesium.CallbackProperty(() => {
return new Cesium.Cartesian3(this.viewDistance,
this.viewDistance,
this.viewDistance)
}, false),
minimumClock: Cesium.Math.toRadians(-this.horizontalViewAngle / 2),
maximumClock: Cesium.Math.toRadians(this.horizontalViewAngle / 2),
minimumCone: Cesium.Math.toRadians(this.verticalViewAngle + 7.75),
maximumCone: Cesium.Math.toRadians(180 - this.verticalViewAngle - 7.75),
material: Cesium.Color.DARKCYAN.withAlpha(0.3),
outline: true,
subdivisions: 256,
stackPartitions: 64,
slicePartitions: 64,
outlineColor: Cesium.Color.YELLOWGREEN
},
});
/* this.sketch = this.viewer.entities.add({
name: ‘sketch’,
position: this.viewPosition,
orientation: Cesium.Transforms.headingPitchRollQuaternion(
this.viewPosition,
Cesium.HeadingPitchRoll.fromDegrees(this.viewHeading - this.horizontalViewAngle, this.viewPitch, 0.0)
),
ellipsoid: {
radii: new Cesium.Cartesian3(
this.viewDistance,
this.viewDistance,
this.viewDistance
),
// innerRadii: new Cesium.Cartesian3(2.0, 2.0, 2.0),
minimumClock: Cesium.Math.toRadians(-this.horizontalViewAngle / 2),
maximumClock: Cesium.Math.toRadians(this.horizontalViewAngle / 2),
minimumCone: Cesium.Math.toRadians(this.verticalViewAngle + 7.75),
maximumCone: Cesium.Math.toRadians(180 - this.verticalViewAngle - 7.75),
fill: false,
outline: true,
subdivisions: 256,
stackPartitions: 64,
slicePartitions: 64,
outlineColor: Cesium.Color.YELLOWGREEN
}
}); */
}
// 创建PostStage
createPostStage () {
const glsl = `
#define USE_CUBE_MAP_SHADOW true
uniform sampler2D colorTexture;
// 深度纹理
uniform sampler2D depthTexture;
// 纹理坐标
varying vec2 v_textureCoordinates;

    uniform mat4 camera_projection_matrix;uniform mat4 camera_view_matrix;// 观测距离uniform float far;//阴影uniform samplerCube shadowMap_textureCube;uniform mat4 shadowMap_matrix;uniform vec4 shadowMap_lightPositionEC;uniform vec4 shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness;uniform vec4 shadowMap_texelSizeDepthBiasAndNormalShadingSmooth;struct zx_shadowParameters{vec3 texCoords;float depthBias;float depth;float nDotL;vec2 texelStepSize;float normalShadingSmooth;float darkness;};float czm_shadowVisibility(samplerCube shadowMap, zx_shadowParameters shadowParameters){float depthBias = shadowParameters.depthBias;float depth = shadowParameters.depth;float nDotL = shadowParameters.nDotL;float normalShadingSmooth = shadowParameters.normalShadingSmooth;float darkness = shadowParameters.darkness;vec3 uvw = shadowParameters.texCoords;depth -= depthBias;float visibility = czm_shadowDepthCompare(shadowMap, uvw, depth);return czm_private_shadowVisibility(visibility, nDotL, normalShadingSmooth, darkness);}vec4 getPositionEC(){return czm_windowToEyeCoordinates(gl_FragCoord);}vec3 getNormalEC(){return vec3(1.);}vec4 toEye(in vec2 uv,in float depth){vec2 xy=vec2((uv.x*2.-1.),(uv.y*2.-1.));vec4 posInCamera=czm_inverseProjection*vec4(xy,depth,1.);posInCamera=posInCamera/posInCamera.w;return posInCamera;}vec3 pointProjectOnPlane(in vec3 planeNormal,in vec3 planeOrigin,in vec3 point){vec3 v01=point-planeOrigin;float d=dot(planeNormal,v01);return(point-planeNormal*d);}float getDepth(in vec4 depth){float z_window=czm_unpackDepth(depth);z_window=czm_reverseLogDepth(z_window);float n_range=czm_depthRange.near;float f_range=czm_depthRange.far;return(2.*z_window-n_range-f_range)/(f_range-n_range);}float shadow( in vec4 positionEC ){vec3 normalEC=getNormalEC();zx_shadowParameters shadowParameters;shadowParameters.texelStepSize=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.xy;shadowParameters.depthBias=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.z;shadowParameters.normalShadingSmooth=shadowMap_texelSizeDepthBiasAndNormalShadingSmooth.w;shadowParameters.darkness=shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness.w;vec3 directionEC=positionEC.xyz-shadowMap_lightPositionEC.xyz;float distance=length(directionEC);directionEC=normalize(directionEC);float radius=shadowMap_lightPositionEC.w;if(distance>radius){return 2.0;}vec3 directionWC=czm_inverseViewRotation*directionEC;shadowParameters.depth=distance/radius-0.0003;shadowParameters.nDotL=clamp(dot(normalEC,-directionEC),0.,1.);shadowParameters.texCoords=directionWC;float visibility=czm_shadowVisibility(shadowMap_textureCube,shadowParameters);return visibility;}bool visible(in vec4 result){result.x/=result.w;result.y/=result.w;result.z/=result.w;return result.x>=-1.&&result.x<=1.&&result.y>=-1.&&result.y<=1.&&result.z>=-1.&&result.z<=1.;}void main(){// 得到釉色 = 结构二维(彩色纹理,纹理坐标)gl_FragColor=texture2D(colorTexture,v_textureCoordinates);// 深度 = (釉色 = 结构二维(深度纹理,纹理坐标))float depth=getDepth(texture2D(depthTexture,v_textureCoordinates));// 视角 = (纹理坐标,深度)vec4 viewPos=toEye(v_textureCoordinates,depth);//世界坐标vec4 wordPos=czm_inverseView*viewPos;// 虚拟相机中坐标vec4 vcPos=camera_view_matrix*wordPos;float near=.001*far;float dis=length(vcPos.xyz);if(dis>near&&dis<far){//透视投影vec4 posInEye=camera_projection_matrix*vcPos;// 可视区颜色vec4 v_color=vec4(0.,1.,0.,.5);vec4 inv_color=vec4(1.,0.,0.,.5);if(visible(posInEye)){float vis=shadow(viewPos);if(vis>0.3){gl_FragColor=mix(gl_FragColor,v_color,.5);} else {gl_FragColor=mix(gl_FragColor,inv_color,.5);}}}}`;const fs = glslconst postStage = new Cesium.PostProcessStage({fragmentShader: fs,uniforms: {camera_projection_matrix: this.lightCamera.frustum.projectionMatrix,camera_view_matrix: this.lightCamera.viewMatrix,shadowMap: this.shadowMap,far: () => {return this.viewDistance;},shadowMap_textureCube: () => {this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));return Reflect.get(this.shadowMap, "_shadowMapTexture");},shadowMap_matrix: () => {this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));return Reflect.get(this.shadowMap, "_shadowMapMatrix");},shadowMap_lightPositionEC: () => {this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));return Reflect.get(this.shadowMap, "_lightPositionEC");},shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness: () => {this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));const bias = this.shadowMap._pointBias;return Cesium.Cartesian4.fromElements(bias.normalOffsetScale,this.shadowMap._distance,this.shadowMap.maximumDistance,0.0,new Cesium.Cartesian4());},shadowMap_texelSizeDepthBiasAndNormalShadingSmooth: () => {this.shadowMap.update(Reflect.get(this.viewer.scene, "_frameState"));const bias = this.shadowMap._pointBias;const scratchTexelStepSize = new Cesium.Cartesian2();const texelStepSize = scratchTexelStepSize;texelStepSize.x = 1.0 / this.shadowMap._textureSize.x;texelStepSize.y = 1.0 / this.shadowMap._textureSize.y;return Cesium.Cartesian4.fromElements(texelStepSize.x,texelStepSize.y,bias.depthBias,bias.normalShadingSmooth,new Cesium.Cartesian4());}}});this.postStage = this.viewer.scene.postProcessStages.add(postStage);
}

当前存在问题,相机视角变化时,地形可视域显示会变化,是因为lod记载的问题,建筑物则不会出现该情况,但需要在修改获取点的监听方式。

【cesium】可视域分析相关推荐

  1. Cesium 可视域分析代码段(源码)补充

    很抱歉之前的博客里的代码段是贴的截图:关于可视域分析的实现_总要学点什么的博客-CSDN博客_可视域分析 功能优化后的完整demo: Cesium功能集 之 034-可视域分析(纯前端)完整版 现在将 ...

  2. Cesium可视域分析

    继续开始Cesium的学习之旅. 文章目录 一.简介 二.代码实现 2.1相关参数 2.2实现过程 一.简介 因为也没查到关于可视域分析的明确定义,所以就按自己的话来说一下了.对三维空间而言,可视域分 ...

  3. Cesium 可视域分析(未改源码)

    嘿嘿嘿,出来了. 此功能未修改cesium的源码,可动态调节夹角.颜色及距离等因素. 一下晒出部分代码: //创建一个点光源this._shadowMap = new Cesium.ShadowMap ...

  4. Cesium可视域分析 不用修改源码

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 目录 前言 一.先看效果? 二.实现步骤 1.实现原理 2.用到的核心接口说明<

  5. vue3+SuperMap iClient3D for Cesium实现可视域分析功能

    本人小白一枚,文章如有问题还请各位大神评论区指出.整体实现是参考SuperMap iClient3D for Cesium的可视域分析功能源码~ 文章目录 前言 一.主要功能 二.使用步骤 1.HTM ...

  6. Cesium深入浅出之可视域分析

    引子 万众瞩目的可视域分析功能终于来了!上一篇做这个预告的时候,压根还没开始碰这块东西,还有点小忐忑呢,万一弄不出来不就打脸了么,不过好在我脸转的快没打着. 预期效果 效果还可以吧,除了上面星星点点的 ...

  7. supermap iobjects学习——三维通视分析,可视域分析 (1)

    三维可视分析包括通视分析和可视域分析.前者用来判断两点之间是否通视,后者用于对观察点的可视范围进行分析. 涉及到的控件: sceneControl相关事件:Tracking,Tracked Scene ...

  8. 三维分析之可视域分析

    三维可视域分析是在场景的地形或模型数据表面,相对于某个观察点,基于一定的水平视角.垂直视角及指定范围半径,分析该区域内所有通视点的集合.分析结果用绿色区域表示在观察点处可见,红色区域表示在观察点处不可 ...

  9. [cesium] | 视域分析 | 基于cesium的可视域效果

    效果 说明 基于cesium的可视域 有需要的自提 插件地址:传送门 在线访问:传送门2

最新文章

  1. 用Access的iif代替SQL中的IsNull()
  2. 宝马520自动挡的右边前轮处响声
  3. 读书笔记《单核工作法》1
  4. Qt Creator使用外部工具
  5. JUC原子类-引用类型(四)
  6. React开发(273):异步调用的方式
  7. 带滚动条html转pdf只有一页,关于html页面导出pdf滚动条以下显示不全的问题
  8. MySQL5.7安装教程(windows .zip)
  9. Mybatis 动态传入order by 参数排序无效
  10. 阿里云SDK手册之java SDK
  11. matlab遥感代码,遥感融合定量评价matlab程序代码
  12. linux dd tar 整盘备份,tar(压缩,打包,备份),dd(备份,建档),cpio
  13. python编程和excel_Excel Vs. Python?为Excel正名
  14. 【企业微信】h5调试面板
  15. #舍得Share#创业你必须知道的事-创业融资实战
  16. ggplot绘制时间相关性折线图和面积图(2)
  17. 【优化理论】 共轭梯度下降算法实现
  18. Marvell宣战博通网络交换芯片,一大波饿狼扑食而来
  19. 线上科技展厅vr全景展厅设计 广交会布展
  20. P1247 取火柴游戏 (博弈论)

热门文章

  1. 如何实现表格行列冻结
  2. 关于Windows聚焦一直保持一个图不变或者不显示
  3. SpringBoot整合dubbo详解(阿里官方dubbo-spring-boot-starter)
  4. 打造跳跃音波播音乐放器(Electron+Nodejs+React)
  5. GNSS-ITRS_GCRS_J2000坐标系的相互转换
  6. python杀毒软件程序_使用Python Shells绕过杀毒软件
  7. 原生小程序 之引入 icon字体图标
  8. 安装MySQL 5.7.11版本,64位绿色版安装【亲测可用】
  9. 飞鱼CRM是什么?巨量引擎线索如何自动同步至CRM系统
  10. Android中指南针的实现