cesium-天际线

news2024/10/23 20:29:10

主要是两个着色器

let postProccessStage = new Cesium.PostProcessStage({
		//unform着色器对象 textureScale
		fragmentShader:
		// 声明一个纹理采样器 colorTexture 用于读取纹理颜色
			'uniform sampler2D colorTexture;' +
			// 声明一个纹理采样器 depthTexture 用于读取深度纹理
			'uniform sampler2D depthTexture;' +
			'in vec2 v_textureCoordinates;' +
			'out vec4 outColor;' +
			'void main(void)' +
			'{' +
			'float depth = czm_readDepth(depthTexture, v_textureCoordinates);' +
			'vec4 color = texture(colorTexture, v_textureCoordinates);' +
			'if(depth<1.0 - 0.000001){' +
			'outColor = color;' +
			'}' +
			'else{' +
			'outColor = vec4(1.0,0.0,0.0,1.0);' +
			'}' +
			'}'
	});
//PostProcessStage:要使用的片段着色器。默认sampler2D制服是colorTexture和depthTexture。
	let postProccesStage_1 = new Cesium.PostProcessStage({
		// name:obj.name+'_1',
		fragmentShader: 'uniform sampler2D colorTexture;' +
			'uniform sampler2D redTexture;' +
			'uniform sampler2D silhouetteTexture;' +
			'in vec2 v_textureCoordinates;' +
			'out vec4 outColor;' +
			'void main(void)' +
			'{' +
			'vec4 redcolor=texture(redTexture, v_textureCoordinates);' +
			'vec4 silhouetteColor = texture(silhouetteTexture, v_textureCoordinates);' +
			'vec4 color = texture(colorTexture, v_textureCoordinates);' +
			'if(redcolor.r == 1.0){' +
			'outColor = mix(color, vec4(5.0,0.0,0.0,1.0), silhouetteColor.a);' +
			'}' +
			'else{' +
			'outColor = color;' +
			'}' +
			'}',
		//uniform着色器对象
		uniforms: {
			redTexture: postProccessStage.name,
			silhouetteTexture: edgeDetection.name
		}
	});

全部代码

<template>
	<div id="cesiumContainer" style="height: 100vh;"></div>
	<div id="toolbar" style="position: fixed;top:20px;left:220px;">
		<el-breadcrumb :separator-icon="ArrowRight">
			<el-breadcrumb-item>三维分析</el-breadcrumb-item>
			<el-breadcrumb-item>天际线</el-breadcrumb-item>
		</el-breadcrumb>
		<el-row class="mb-4" style="margin-top: 15px">
			<el-button type="primary" @click="openSkylineAnay">打开</el-button>
			<el-button type="primary" @click="closeSkylineAnay">关闭</el-button>
		</el-row>
	</div>
</template>
<script setup>
import {ArrowRight} from '@element-plus/icons-vue'
import {onMounted, ref} from "vue";
import * as Cesium from "cesium";
import InitCesium from "../js/InitCesiumHide.js";

let viewer = null;
const clouds = new Cesium.CloudCollection();
let silhouette = null;
let skylineAnayStages = null;

onMounted(() => {
	let initCesium = new InitCesium('cesiumContainer');
	viewer = initCesium.initViewer({});
	flyToRight2();

})

//打开天际线分析
function openSkylineAnay() {
	if (skylineAnayStages) {
		silhouette.enabled = true;
		return;
	}
	skylineAnayStages = viewer.scene.postProcessStages;
	let edgeDetection = Cesium.PostProcessStageLibrary.createEdgeDetectionStage();
	let postProccessStage = new Cesium.PostProcessStage({
		//unform着色器对象 textureScale
		fragmentShader:
		// 声明一个纹理采样器 colorTexture 用于读取纹理颜色
			'uniform sampler2D colorTexture;' +
			// 声明一个纹理采样器 depthTexture 用于读取深度纹理
			'uniform sampler2D depthTexture;' +
			'in vec2 v_textureCoordinates;' +
			'out vec4 outColor;' +
			'void main(void)' +
			'{' +
			'float depth = czm_readDepth(depthTexture, v_textureCoordinates);' +
			'vec4 color = texture(colorTexture, v_textureCoordinates);' +
			'if(depth<1.0 - 0.000001){' +
			'outColor = color;' +
			'}' +
			'else{' +
			'outColor = vec4(1.0,0.0,0.0,1.0);' +
			'}' +
			'}'
	});

	//PostProcessStage:要使用的片段着色器。默认sampler2D制服是colorTexture和depthTexture。
	let postProccesStage_1 = new Cesium.PostProcessStage({
		// name:obj.name+'_1',
		fragmentShader: 'uniform sampler2D colorTexture;' +
			'uniform sampler2D redTexture;' +
			'uniform sampler2D silhouetteTexture;' +
			'in vec2 v_textureCoordinates;' +
			'out vec4 outColor;' +
			'void main(void)' +
			'{' +
			'vec4 redcolor=texture(redTexture, v_textureCoordinates);' +
			'vec4 silhouetteColor = texture(silhouetteTexture, v_textureCoordinates);' +
			'vec4 color = texture(colorTexture, v_textureCoordinates);' +
			'if(redcolor.r == 1.0){' +
			'outColor = mix(color, vec4(5.0,0.0,0.0,1.0), silhouetteColor.a);' +
			'}' +
			'else{' +
			'outColor = color;' +
			'}' +
			'}',
		//uniform着色器对象
		uniforms: {
			redTexture: postProccessStage.name,
			silhouetteTexture: edgeDetection.name
		}
	});

	//如果inputPreviousStageTexture 是 true,则每个阶段输入是场景渲染到的输出纹理或之前执行阶段的输出纹理
	//如果inputPreviousStageTexture是false,则合成中每个阶段的输入纹理都是相同的
	silhouette = new Cesium.PostProcessStageComposite({
		//PostProcessStage要按顺序执行 的 s 或组合的数组。
		stages: [edgeDetection, postProccessStage, postProccesStage_1],
		//是否执行每个后处理阶段,其中一个阶段的输入是前一个阶段的输出。否则每个包含阶段的输入是组合之前执行的阶段的输出
		inputPreviousStageTexture: false,
		//后处理阶段制服的别名
		uniforms: edgeDetection.uniforms
	})
	skylineAnayStages.add(silhouette);
}

//关闭天际线分析
function closeSkylineAnay() {
	silhouette.enabled = false;
}

const flyToRight2 = async () => {
	let tileset = await Cesium.Cesium3DTileset.fromUrl('/src/assets/tileset/12/tileset.json', {});

	update3dtilesMaxtrix(tileset);
	viewer.scene.primitives.add(tileset);
	viewer.flyTo(tileset);

	/*viewer.camera.flyTo({
		destination: Cesium.Cartesian3.fromDegrees(113.05965738392063, 22.638603971034342, 300.0), // 设置位置
		orientation: {
			heading: Cesium.Math.toRadians(20.0), // 方向
			pitch: Cesium.Math.toRadians(-30.0),// 倾斜角度
			roll: 0
		},
		duration: 5, // 设置飞行持续时间,默认会根据距离来计算
		complete: function () {
			// 到达位置后执行的回调函数
		},
		cancle: function () {
			// 如果取消飞行则会调用此函数
		},
		pitchAdjustHeight: -90, // 如果摄像机飞越高于该值,则调整俯仰俯仰的俯仰角度,并将地球保持在视口中。
		maximumHeight: 5000, // 相机最大飞行高度
		flyOverLongitude: 100, // 如果到达目的地有2种方式,设置具体值后会强制选择方向飞过这个经度(这个,很好用)
	});*/
}

function update3dtilesMaxtrix(tileSet) {
	//调整参数
	let params = {
		tx: 113.06265738392063, //模型中心X轴坐标(经度,单位:十进制度)
		ty: 22.646603971034342, //模型中心Y轴坐标(纬度,单位:十进制度)
		tz: 45, //模型中心Z轴坐标(高程,单位:米)
		rx: 0, //X轴(经度)方向旋转角度(单位:度)
		ry: 0, //Y轴(纬度)方向旋转角度(单位:度)
		rz: 2, //Z轴(高程)方向旋转角度(单位:度)
		scale: 1.35, //缩放比例
	};
	//旋转
	const mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(params.rx));
	const my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(params.ry));
	const mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(params.rz));
	const rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
	const rotationY = Cesium.Matrix4.fromRotationTranslation(my);
	const rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
	//平移
	const position = Cesium.Cartesian3.fromDegrees(
		params.tx,
		params.ty,
		params.tz
	);
	const m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
	//旋转、平移矩阵相乘
	Cesium.Matrix4.multiply(m, rotationX, m);
	Cesium.Matrix4.multiply(m, rotationY, m);
	Cesium.Matrix4.multiply(m, rotationZ, m);
	//比例缩放
	const scale = Cesium.Matrix4.fromUniformScale(params.scale);
	Cesium.Matrix4.multiply(m, scale, m);
	// console.log("矩阵m:", m);
	//赋值给tileset
	tileSet._root.transform = m;
}
</script>
<style scoped>
#cesiumContainer {
	overflow: hidden;
}
</style>
<style>
.el-breadcrumb__inner, .el-breadcrumb__separator {
	color: #ffffff !important;
}
</style>

效果图

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1498165.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

windows安装程序无法将windows配置为此计算机

目录 问题描述 问题原因 解决办法 方法一 方法二 方法三&#xff1a; 问题描述 重装系统时显示windows安装程序无法将windows配置在此计算机硬件上. 问题原因 安装介质已损坏 如果可引导的安装介质&#xff08;如DVD或USB驱动器&#xff09;损坏或损坏&#xff0c;安装过…

XXE-XML实体注入漏洞

目录 1.xml基础 1.1什么是xml 1.2xml文档结构 1.3 什么是DTD 1.4 什么是实体 1.5 什么是外部实体 2.xxe漏洞 2.1xxe漏洞基本介绍 2.2xxe漏洞的危害 经典漏洞案例分析 3.xxe漏洞挖掘和利用 3.1. 识别潜在的XML入口 3.2. 检查XML处理逻辑 3.3. 构造试探Payload 常…

CVE-2024-25600 WordPress Bricks Builder RCE-漏洞分析研究

本次代码审计项目为PHP语言&#xff0c;我将继续以漏洞挖掘者的视角来分析漏洞的产生&#xff0c;调用与利用..... 前方高能&#xff0c;小伙伴们要真正仔细看咯..... 漏洞简介 CVE-2024-25600 是一个严重的&#xff08;CVSS 评分 9.8&#xff09;远程代码执行 (RCE) 漏洞&am…

软件设计师13--进程调度

软件设计师13--进程调度 考点1&#xff1a;PV操作的概念进程的同步与互斥PV操作例题&#xff1a; 考点2&#xff1a;信号量与PV操作进程管理 - PV操作与互斥模型进程管理 - PV操作与同步模型进程管理 - 互斥与同步模型结合例题&#xff1a; 考点3&#xff1a;前趋图与PV操作进程…

爬虫(四)

1.图片验证码 import requestsres requests.get(https://www.gushiwen.cn/RandCode.ashx)with open("code.png", "wb") as f:f.write(res.content)2.打码平台 网址&#xff1a;http://www.ttshitu.com/&#xff0c;找到开发文档点击Python,没有钱了要用我…

如何在Linux中安装ARM交叉环境编译链

安装ARM交叉环境编译链过程如下&#xff1a; 首先创建一个文件夹如下&#xff1a; mkdir -p Linux_ALPHA/toolcahin然后将arm交叉编译工具链安装包拖到Linux中如下&#xff1a; 先输入mv 拖入的安装包即可 mv /var/run/vmblock-fuse/blockdir/pXeysK/gcc-4.6.4.tar.xz .直接…

-bash: unzip: 未找到命令的解决方案

遇到 -bash: unzip: 未找到命令 这样的错误信息&#xff0c;表示你的系统中没有安装 unzip 工具。unzip 是一个常用的解压工具&#xff0c;用于解压缩 .zip 文件。你可以通过系统的包管理器安装它。 根据你使用的 Linux 发行版&#xff0c;安装 unzip 的命令会有所不同。下面是…

动态内存管理-c语言

目录 1.为什么要有动态内存分配 2.malloc函数和free函数 malloc 函数原型 栗子 free 函数原型 栗子 3.calloc和***realloc*** 3.1calloc函数 原型如下&#xff1a; 栗子 3.2***recalloc*** 第一种情况 第二种情况 第三种情况 recalloc模拟实现calloc函数 4.六…

基于springboot+vue的球队训练信息管理系统

博主主页&#xff1a;猫头鹰源码 博主简介&#xff1a;Java领域优质创作者、CSDN博客专家、阿里云专家博主、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战&#xff0c;欢迎高校老师\讲师\同行交流合作 ​主要内容&#xff1a;毕业设计(Javaweb项目|小程序|Pyt…

“揭秘网络握手与挥别:TCP三次握手和四次挥手全解析“

前言 在计算机网络中&#xff0c;TCP&#xff08;传输控制协议&#xff09;是一种重要的通信协议&#xff0c;用于在网络中的两台计算机之间建立可靠的连接并交换数据。TCP协议通过“三次握手”和“四次挥手”的过程来建立和终止连接&#xff0c;确保数据的准确传输。 一、三…

2024年腾讯云优惠政策_腾讯云服务器特价购买活动入口

腾讯云优惠活动2024新春采购节活动上线&#xff0c;云服务器价格已经出来了&#xff0c;云服务器61元一年起&#xff0c;配置和价格基本上和上个月没什么变化&#xff0c;但是新增了8888元代金券和会员续费优惠&#xff0c;腾讯云百科txybk.com整理腾讯云最新优惠活动云服务器配…

数据结构(八)——初识单链表

&#x1f600;前言 单链表是数据结构中最基本的一种链表结构&#xff0c;它由一系列节点组成&#xff0c;每个节点包含数据和指向下一个节点的指针。单链表具有灵活性和动态性&#xff0c;可以根据需要插入、删除和查找元素&#xff0c;适用于各种场景和问题的解决。 在本篇文章…

网络编程 · 代码笔记1

目录 前言1、编程环境2、编译命令3、标题名前缀解释4、注意事项 0011客户端读取服务端字符_服务端0012客户端读取服务端字符_客户端0021回声测试_服务端0022回声测试_客户端0030启动端口复用解决端口绑定失败问题0041服务器不间断进行侦听通信_服务端0042服务器不间断进行侦听通…

liunx操作系统 环境变量

环境变量 main函数参数 命令行参数环境变量 环境变量的查看环境变量的获取 main函数参数 命令行参数 main函数是有参数的&#xff0c;只是我们一般不适用 这是main函数从bash中读取进程数据使用的一个基本入口。 下面进行简单演示。 o 好oo都是我们输入的命令行参数。其实&a…

如何查看前端的vue项目是vue2还是vue3项目

1. 检查package.json文件 在项目的根目录下&#xff0c;打开package.json文件&#xff0c;查找dependencies或devDependencies部分中的vue条目。版本号将告诉你是Vue 2还是Vue 3。例如&#xff1a; Vue 2.x: "vue": "^2.x.x"Vue 3.x: "vue": &…

【Linux基础(二)】进程管理

学习分享 1、程序和进程1.1、程序1.2、进程和进程ID 2、Linux下的进程结构3、init进程4、获取进程标识5、fork系统调用5.1、fork函数实例分析 6、进程的特性7、在Linux下进程指令7.1、终止进程指令7.2、查看进程指令&#xff1a;7.3、以树状图列出进程 8、多进程运行异常情况8.…

判断连续数据同意特征的方法:插旗法

bool isMonotonic(int* nums, int numsSize) {int flag 2;for (int i 1; i < numsSize; i) {if (nums[i-1] > nums[i]) {if (flag 0)return false;flag 1;}else if (nums[i-1] < nums[i]) {if (flag 1)return false;flag 0;}}return true; }此代码较为简单&…

Vue中如何处理组件间的耦合问题?

在Vue中处理组件间的耦合问题是前端开发中常见的挑战之一。耦合问题指的是组件之间的依赖关系过于紧密&#xff0c;一旦某个组件发生改动&#xff0c;则可能导致其它组件也需要作出相应调整。为了解决这个问题&#xff0c;我们可以采取以下几种方法&#xff1a; 使用事件总线&…

牛客每日一题之 前缀和

目录 题目介绍&#xff1a; 算法原理&#xff1a; 前缀和&#xff1a; 代码实现&#xff1a; 题目介绍&#xff1a; 题目链接&#xff1a;【模板】前缀和_牛客题霸_牛客网 算法原理&#xff1a; 先讲讲暴力解法每次求出数组下标r之前元素的和&#xff0c;再减去数组下标l-…

Docker容器的操作

目录 运行容器 查看容器 查看容器详细信息 删除容器 启动容器 停止容器 重启容器 暂停容器 激活容器 杀死容器 进入容器 常用 查看容器的日志 拷贝容器的文件到本地 容器改名 查看容器资源 查看容器内部的进程 监测容器发生的事件 检测容器停止以后的反回值…